2020-12-04 14:14:08 +01:00
|
|
|
#include <mission/devices/P60DockHandler.h>
|
2020-12-14 08:42:48 +01:00
|
|
|
#include <mission/devices/devicedefinitions/GomSpacePackets.h>
|
2020-12-04 14:14:08 +01:00
|
|
|
|
|
|
|
P60DockHandler::P60DockHandler(object_id_t objectId, object_id_t comIF,
|
|
|
|
CookieIF * comCookie):DeviceHandlerBase(objectId, comIF, comCookie) {
|
2020-12-09 12:00:24 +01:00
|
|
|
mode = MODE_NORMAL;
|
|
|
|
if(comCookie == NULL){
|
|
|
|
sif::error << "P60DockHandler invalid com cookie" << std::endl;
|
|
|
|
}
|
2020-12-04 14:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
P60DockHandler::~P60DockHandler() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void P60DockHandler::doStartUp(){
|
|
|
|
}
|
|
|
|
|
|
|
|
void P60DockHandler::doShutDown(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t P60DockHandler::buildNormalDeviceCommand(DeviceCommandId_t * id){
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t P60DockHandler::buildTransitionDeviceCommand(
|
|
|
|
DeviceCommandId_t * id){
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t P60DockHandler::buildCommandFromCommand(
|
|
|
|
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
|
|
|
|
size_t commandDataLen) {
|
|
|
|
switch(deviceCommand) {
|
2020-12-10 10:01:45 +01:00
|
|
|
case(PING): {
|
2020-12-17 13:26:00 +01:00
|
|
|
const uint8_t* pingData = commandData;
|
|
|
|
uint8_t pingDataSz = commandDataLen;
|
|
|
|
CspPingCommand cspPingCommand(pingData, pingDataSz);
|
2020-12-16 15:17:10 +01:00
|
|
|
size_t cspPacketLen = 0;
|
|
|
|
uint8_t* buffer = cspPacket;
|
|
|
|
cspPingCommand.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
|
|
|
|
SerializeIF::Endianness::BIG);
|
|
|
|
if(cspPacketLen > MAX_PACKET_LEN){
|
|
|
|
sif::error << "P60DockHandler: Received invalid ping message"
|
|
|
|
<< std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
rawPacket = cspPacket;
|
|
|
|
rawPacketLen = cspPacketLen;
|
|
|
|
rememberCommandId = PING;
|
2020-12-10 10:01:45 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-17 13:26:00 +01:00
|
|
|
case(REBOOT): {
|
|
|
|
uint8_t cspPort = GOMSPACE::REBOOT_PORT;
|
|
|
|
uint16_t querySize = 0;
|
|
|
|
*cspPacket = GOMSPACE::REBOOT_PORT;
|
|
|
|
*(cspPacket + 1) = querySize;
|
|
|
|
size_t cspPacketLen = sizeof(cspPort) + sizeof(cspPacketLen);
|
|
|
|
rawPacket = cspPacket;
|
|
|
|
rawPacketLen = cspPacketLen;
|
|
|
|
break;
|
|
|
|
}
|
2020-12-14 08:42:48 +01:00
|
|
|
case(PARAM_SET):{
|
2020-12-16 10:56:32 +01:00
|
|
|
SetParamMessageUnpacker setParamMessageUnpacker(commandData,
|
|
|
|
commandDataLen);
|
|
|
|
uint8_t tableId = setParamMessageUnpacker.getTableId();
|
2020-12-16 11:02:49 +01:00
|
|
|
uint16_t address = setParamMessageUnpacker.getAddress();
|
2020-12-16 10:56:32 +01:00
|
|
|
uint16_t checksum = GOMSPACE::IGNORE_CHECKSUM;
|
|
|
|
uint16_t seq = 0;
|
|
|
|
uint16_t total = 0;
|
|
|
|
/* Reply only comprises the transaction state */
|
|
|
|
uint16_t querySize = 1;
|
|
|
|
const uint8_t* parameterPtr = setParamMessageUnpacker.getParameter();
|
|
|
|
uint8_t parameterSize = setParamMessageUnpacker.getParameterSize();
|
2020-12-16 11:02:49 +01:00
|
|
|
uint16_t payloadlength = sizeof(address) + parameterSize;
|
2020-12-16 10:56:32 +01:00
|
|
|
CspSetParamCommand setParamCmd(querySize, PARAM_SET, tableId, payloadlength,
|
2020-12-16 11:02:49 +01:00
|
|
|
checksum, seq, total, address, parameterPtr,
|
2020-12-16 10:56:32 +01:00
|
|
|
parameterSize);
|
|
|
|
size_t cspPacketLen = 0;
|
|
|
|
uint8_t* buffer = cspPacket;
|
|
|
|
setParamCmd.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
|
|
|
|
SerializeIF::Endianness::BIG);
|
|
|
|
if(cspPacketLen > MAX_PACKET_LEN){
|
|
|
|
sif::error << "P60DockHandler: Received invalid set parameter "
|
|
|
|
"command" << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
rawPacket = cspPacket;
|
|
|
|
rawPacketLen = cspPacketLen;
|
2020-12-16 15:17:10 +01:00
|
|
|
rememberRequestedSize = querySize;
|
|
|
|
rememberCommandId = PARAM_SET;
|
2020-12-09 12:00:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-14 08:42:48 +01:00
|
|
|
case(PARAM_GET):{
|
|
|
|
/* Unpack the received action message */
|
|
|
|
GetParamMessageUnpacker getParamMessage(commandData, commandDataLen);
|
|
|
|
uint8_t tableId = getParamMessage.getTableId();
|
2020-12-16 15:17:10 +01:00
|
|
|
uint16_t address = getParamMessage.getAddress();
|
|
|
|
uint16_t length = sizeof(address);
|
2020-12-14 08:42:48 +01:00
|
|
|
uint16_t checksum = GOMSPACE::IGNORE_CHECKSUM;
|
|
|
|
uint16_t seq = 0;
|
|
|
|
uint16_t total = 0;
|
2020-12-16 10:56:32 +01:00
|
|
|
uint16_t querySize = getParamMessage.getParameterSize()
|
2020-12-14 09:46:59 +01:00
|
|
|
+ CspGetParamCommand::GS_HDR_LENGTH;
|
2020-12-14 08:42:48 +01:00
|
|
|
/* Generate the CSP command to send to the P60 Dock */
|
|
|
|
CspGetParamCommand getParamCmd(querySize, PARAM_GET, tableId, length,
|
|
|
|
checksum, seq, total, address);
|
|
|
|
size_t cspPacketLen = 0;
|
|
|
|
uint8_t* buffer = cspPacket;
|
|
|
|
getParamCmd.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
|
|
|
|
SerializeIF::Endianness::BIG);
|
|
|
|
if(cspPacketLen > MAX_PACKET_LEN){
|
|
|
|
sif::error << "P60DockHandler: Received invalid get parameter "
|
|
|
|
"command" << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
rawPacket = cspPacket;
|
|
|
|
rawPacketLen = cspPacketLen;
|
|
|
|
rememberRequestedSize = querySize;
|
|
|
|
rememberCommandId = PARAM_GET;
|
2020-12-04 14:14:08 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-17 13:26:00 +01:00
|
|
|
case(GNDWDT_RESET): {
|
|
|
|
WatchdogResetCommand watchdogResetCommand;
|
|
|
|
size_t cspPacketLen = 0;
|
|
|
|
uint8_t* buffer = cspPacket;
|
|
|
|
watchdogResetCommand.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
|
|
|
|
SerializeIF::Endianness::BIG);
|
|
|
|
if(cspPacketLen > MAX_PACKET_LEN){
|
|
|
|
sif::error << "P60DockHandler: Received invalid ground watchdog"
|
|
|
|
"reset command" << std::endl;
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
rawPacket = cspPacket;
|
|
|
|
rawPacketLen = cspPacketLen;
|
|
|
|
rememberRequestedSize = 0; // No bytes will be queried with the ground
|
|
|
|
// watchdog command.
|
|
|
|
rememberCommandId = GNDWDT_RESET;
|
|
|
|
}
|
2020-12-04 14:14:08 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void P60DockHandler::fillCommandAndReplyMap(){
|
2020-12-10 10:01:45 +01:00
|
|
|
this->insertInCommandAndReplyMap(PING, 3);
|
2020-12-17 13:26:00 +01:00
|
|
|
this->insertInCommandMap(REBOOT);
|
2020-12-14 08:42:48 +01:00
|
|
|
this->insertInCommandAndReplyMap(PARAM_SET, 3);
|
|
|
|
this->insertInCommandAndReplyMap(PARAM_GET, 3);
|
2020-12-17 13:26:00 +01:00
|
|
|
this->insertInCommandMap(GNDWDT_RESET);
|
2020-12-04 14:14:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start,
|
|
|
|
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
|
2020-12-14 08:42:48 +01:00
|
|
|
switch(rememberCommandId) {
|
2020-12-10 10:01:45 +01:00
|
|
|
case(PING):
|
|
|
|
*foundId = PING;
|
2020-12-16 15:17:10 +01:00
|
|
|
*foundLen = PING_REPLY_SIZE;
|
2020-12-14 08:42:48 +01:00
|
|
|
rememberCommandId = NONE;
|
2020-12-04 14:14:08 +01:00
|
|
|
break;
|
2020-12-14 08:42:48 +01:00
|
|
|
case(PARAM_GET): {
|
|
|
|
*foundId = PARAM_GET;
|
|
|
|
*foundLen = rememberRequestedSize + CspGetParamReply::GS_HDR_LENGTH;
|
|
|
|
rememberCommandId = NONE;
|
2020-12-09 12:00:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-16 15:17:10 +01:00
|
|
|
case(PARAM_SET): {
|
|
|
|
*foundId = PARAM_SET;
|
|
|
|
*foundLen = rememberRequestedSize;
|
|
|
|
rememberCommandId = NONE;
|
|
|
|
break;
|
|
|
|
}
|
2020-12-04 14:14:08 +01:00
|
|
|
default:
|
|
|
|
return IGNORE_REPLY_DATA;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|
|
|
const uint8_t *packet) {
|
|
|
|
switch(id) {
|
2020-12-14 08:42:48 +01:00
|
|
|
case(PING): {
|
2020-12-17 13:26:00 +01:00
|
|
|
SerializeElement<uint32_t> replyTime = *packet;
|
|
|
|
handleDeviceTM(&replyTime, id, true);
|
2020-12-04 14:14:08 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-14 08:42:48 +01:00
|
|
|
case(PARAM_GET): {
|
2020-12-16 10:56:32 +01:00
|
|
|
// -2 to subtract address size from gomspace parameter reply packet
|
|
|
|
uint16_t payloadLength = (*(packet + 2) << 8 | *(packet + 3)) - 2;
|
2020-12-14 08:42:48 +01:00
|
|
|
uint8_t tempPayloadBuffer[payloadLength];
|
2020-12-16 15:17:10 +01:00
|
|
|
/* Extract information from received data */
|
2020-12-14 08:42:48 +01:00
|
|
|
CspGetParamReply cspGetParamReply(tempPayloadBuffer, payloadLength);
|
2020-12-16 10:56:32 +01:00
|
|
|
size_t size = CspGetParamReply::GS_HDR_LENGTH + payloadLength;
|
|
|
|
cspGetParamReply.deSerialize(&packet, &size,
|
|
|
|
SerializeIF::Endianness::BIG);
|
2020-12-14 08:42:48 +01:00
|
|
|
uint8_t action = cspGetParamReply.getAction();
|
|
|
|
uint8_t tableId = cspGetParamReply.getTableId();
|
|
|
|
uint16_t address = cspGetParamReply.getAddress();
|
2020-12-16 15:17:10 +01:00
|
|
|
/* Pack relevant information into a tm reply packet */
|
2020-12-16 10:56:32 +01:00
|
|
|
ParamReply paramReply(action, tableId, address, payloadLength,
|
|
|
|
tempPayloadBuffer);
|
|
|
|
handleDeviceTM(¶mReply, id, true);
|
2020-12-09 12:00:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-12-16 15:17:10 +01:00
|
|
|
case(PARAM_SET): {
|
|
|
|
/* When setting a parameter, the p60dock sends back the state of the
|
|
|
|
* operation */
|
|
|
|
if(*packet != PARAM_SET_OK){
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2020-12-04 14:14:08 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-04 20:08:58 +01:00
|
|
|
void P60DockHandler::setNormalDatapoolEntriesInvalid(){
|
2020-12-04 14:14:08 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|