p60 dock handler completed

This commit is contained in:
Jakob Meier 2020-12-17 13:26:00 +01:00
parent 28eb6333f5
commit 771adb3743
5 changed files with 91 additions and 76 deletions

View File

@ -86,7 +86,8 @@ ReturnValue_t CspComIF::sendMessage(CookieIF *cookie,
SerializeAdapter::deSerialize(&querySize, &sendData, &sendLen, SerializeAdapter::deSerialize(&querySize, &sendData, &sendLen,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
uint8_t cspAddress = cspCookie->getCspAddress(); uint8_t cspAddress = cspCookie->getCspAddress();
if(cspPort == csp_reserved_ports_e::CSP_PING){ switch(cspPort) {
case(Ports::CSP_PING): {
uint32_t timeout = 1000; // ms uint32_t timeout = 1000; // ms
unsigned int pingSize = 100; // 100 bytes unsigned int pingSize = 100; // 100 bytes
uint32_t replyTime = csp_ping(cspAddress, timeout, pingSize, uint32_t replyTime = csp_ping(cspAddress, timeout, pingSize,
@ -96,11 +97,15 @@ ReturnValue_t CspComIF::sendMessage(CookieIF *cookie,
/* Store reply time in reply buffer * */ /* Store reply time in reply buffer * */
uint8_t* replyBuffer = cspDeviceMap[cspAddress].data(); uint8_t* replyBuffer = cspDeviceMap[cspAddress].data();
memcpy(replyBuffer, &replyTime, sizeof(replyTime)); memcpy(replyBuffer, &replyTime, sizeof(replyTime));
replySize = sizeof(replyTime);
break;
} }
else if(cspPort == csp_reserved_ports_e::CSP_REBOOT){ case(Ports::CSP_REBOOT): {
csp_reboot(cspCookie->getCspAddress()); csp_reboot(cspAddress);
break;
} }
else{ case(Ports::P60_PORT_GNDWDT_RESET):
case(Ports::P60_PORT_RPARAM): {
/* No CSP fixed port was selected. Send data to the specified port and /* No CSP fixed port was selected. Send data to the specified port and
* wait for querySize number of bytes */ * wait for querySize number of bytes */
result = cspTransfer(cspAddress, cspPort, sendData, sendLen, result = cspTransfer(cspAddress, cspPort, sendData, sendLen,
@ -108,7 +113,12 @@ ReturnValue_t CspComIF::sendMessage(CookieIF *cookie,
if(result != HasReturnvaluesIF::RETURN_OK){ if(result != HasReturnvaluesIF::RETURN_OK){
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
rememberQuerySize = querySize; replySize = querySize;
break;
}
default:
sif::error << "CspComIF: Invalid port specified" << std::endl;
break;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -135,7 +145,7 @@ ReturnValue_t CspComIF::readReceivedMessage(CookieIF *cookie,
uint8_t cspAddress = cspCookie->getCspAddress(); uint8_t cspAddress = cspCookie->getCspAddress();
*buffer = cspDeviceMap[cspAddress].data(); *buffer = cspDeviceMap[cspAddress].data();
*size = rememberQuerySize; *size = replySize;
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -46,6 +46,14 @@ private:
ReturnValue_t cspTransfer(uint8_t cspAddress, uint8_t cspPort, ReturnValue_t cspTransfer(uint8_t cspAddress, uint8_t cspPort,
const uint8_t* cmdBuffer, int cmdBufferLen, uint16_t querySize); const uint8_t* cmdBuffer, int cmdBufferLen, uint16_t querySize);
enum Ports {
CSP_PING = 1,
CSP_REBOOT = 4,
P60_PORT_RPARAM = 7,
P60_PORT_GNDWDT_RESET = 9
};
typedef uint8_t node_t; typedef uint8_t node_t;
using vectorBuffer = std::vector<uint8_t>; using vectorBuffer = std::vector<uint8_t>;
using VectorBufferMap = std::unordered_map<node_t, vectorBuffer>; using VectorBufferMap = std::unordered_map<node_t, vectorBuffer>;
@ -54,7 +62,7 @@ private:
/* In this map assigns reply buffers to a CSP device */ /* In this map assigns reply buffers to a CSP device */
VectorBufferMap cspDeviceMap; VectorBufferMap cspDeviceMap;
uint16_t rememberQuerySize = 0; uint16_t replySize = 0;
/* This is the CSP address of the OBC. */ /* This is the CSP address of the OBC. */
node_t cspClientAddress = 1; node_t cspClientAddress = 1;

View File

@ -34,10 +34,9 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
size_t commandDataLen) { size_t commandDataLen) {
switch(deviceCommand) { switch(deviceCommand) {
case(PING): { case(PING): {
PingMessageUnpacker pingMessageUnpacker(commandData, commandDataLen); const uint8_t* pingData = commandData;
const uint8_t* pingData = pingMessageUnpacker.getPingData(); uint8_t pingDataSz = commandDataLen;
uint8_t pingDataSz = pingMessageUnpacker.getPingDataSz(); CspPingCommand cspPingCommand(pingData, pingDataSz);
CspPingCommand cspPingCommand(pingDataSz, pingData);
size_t cspPacketLen = 0; size_t cspPacketLen = 0;
uint8_t* buffer = cspPacket; uint8_t* buffer = cspPacket;
cspPingCommand.serialize(&buffer, &cspPacketLen, sizeof(cspPacket), cspPingCommand.serialize(&buffer, &cspPacketLen, sizeof(cspPacket),
@ -52,6 +51,16 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
rememberCommandId = PING; rememberCommandId = PING;
break; break;
} }
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;
}
case(PARAM_SET):{ case(PARAM_SET):{
SetParamMessageUnpacker setParamMessageUnpacker(commandData, SetParamMessageUnpacker setParamMessageUnpacker(commandData,
commandDataLen); commandDataLen);
@ -112,6 +121,23 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
rememberCommandId = PARAM_GET; rememberCommandId = PARAM_GET;
break; break;
} }
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;
}
default: default:
break; break;
} }
@ -120,8 +146,10 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand(
void P60DockHandler::fillCommandAndReplyMap(){ void P60DockHandler::fillCommandAndReplyMap(){
this->insertInCommandAndReplyMap(PING, 3); this->insertInCommandAndReplyMap(PING, 3);
this->insertInCommandMap(REBOOT);
this->insertInCommandAndReplyMap(PARAM_SET, 3); this->insertInCommandAndReplyMap(PARAM_SET, 3);
this->insertInCommandAndReplyMap(PARAM_GET, 3); this->insertInCommandAndReplyMap(PARAM_GET, 3);
this->insertInCommandMap(GNDWDT_RESET);
} }
ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start, ReturnValue_t P60DockHandler::scanForReply(const uint8_t *start,
@ -154,8 +182,8 @@ ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) { const uint8_t *packet) {
switch(id) { switch(id) {
case(PING): { case(PING): {
PingReply pingReply(*packet, *(packet + 1)); SerializeElement<uint32_t> replyTime = *packet;
handleDeviceTM(&pingReply, id, true, true); handleDeviceTM(&replyTime, id, true);
break; break;
} }
case(PARAM_GET): { case(PARAM_GET): {

View File

@ -39,6 +39,8 @@ private:
/* Device commands are derived from the rparam.h of the gomspace lib */ /* Device commands are derived from the rparam.h of the gomspace lib */
static const DeviceCommandId_t PING = 0x1; //!< [EXPORT] : [COMMAND] static const DeviceCommandId_t PING = 0x1; //!< [EXPORT] : [COMMAND]
static const DeviceCommandId_t NONE = 0x2; // Set when no command is pending static const DeviceCommandId_t NONE = 0x2; // Set when no command is pending
static const DeviceCommandId_t REBOOT = 0x4; //!< [EXPORT] : [COMMAND]
static const DeviceCommandId_t GNDWDT_RESET = 0x9; //!< [EXPORT] : [COMMAND]
static const DeviceCommandId_t PARAM_GET = 0x00; //!< [EXPORT] : [COMMAND] static const DeviceCommandId_t PARAM_GET = 0x00; //!< [EXPORT] : [COMMAND]
static const DeviceCommandId_t PARAM_SET = 0xFF; //!< [EXPORT] : [COMMAND] static const DeviceCommandId_t PARAM_SET = 0xFF; //!< [EXPORT] : [COMMAND]

View File

@ -12,8 +12,35 @@ namespace GOMSPACE{
static const uint8_t REBOOT_PORT = 4; static const uint8_t REBOOT_PORT = 4;
/* CSP port of gomspace devices to request or set parameters */ /* CSP port of gomspace devices to request or set parameters */
static const uint8_t PARAM_PORT = 7; static const uint8_t PARAM_PORT = 7;
static const uint8_t P60_PORT_GNDWDT_RESET = 9;
} }
/**
* @brief This class can be used to generated the command for the CspComIF
* to reset the watchdog in a gomspace device.
*/
class WatchdogResetCommand : public SerialLinkedListAdapter<SerializeIF> {
public:
WatchdogResetCommand() {
setLinks();
}
private:
WatchdogResetCommand(const WatchdogResetCommand &command);
void setLinks() {
setStart(&cspPort);
cspPort.setNext(&querySize);
querySize.setNext(&magic);
}
SerializeElement<uint8_t> cspPort = GOMSPACE::P60_PORT_GNDWDT_RESET;
SerializeElement<uint16_t> querySize = 1;
/* Sending 0x78 to port 9 of a gomspace device resets the ground watchdog */
SerializeElement<uint8_t> magic = 0x78;
};
/** /**
* @brief A serial linked list adapter implementation to generate ping * @brief A serial linked list adapter implementation to generate ping
* commands for devices supporting the CSP protocol. This command can * commands for devices supporting the CSP protocol. This command can
@ -31,11 +58,11 @@ public:
* *
* @param querySize_ The size of bytes replied by the ping request. * @param querySize_ The size of bytes replied by the ping request.
* Amounts to the number of bytes send. * Amounts to the number of bytes send.
* @param parameters_ Pointer to data which should be sent to the device. * @param data_ Pointer to data which should be sent to the device.
* All data will be sent back by the ping target. * All data will be sent back by the ping target.
*/ */
CspPingCommand(uint16_t querySize_, const uint8_t* parameters_) : CspPingCommand(const uint8_t* data_, uint16_t querySize_) :
querySize(querySize_), data(parameters_, querySize_) { querySize(querySize_), data(data_, querySize_) {
setLinks(); setLinks();
} }
@ -256,29 +283,6 @@ private:
SerializeElement<SerialBufferAdapter<uint16_t>> payload; SerializeElement<SerialBufferAdapter<uint16_t>> payload;
}; };
/**
* @brief This class generates telemetry packets containing data from
* CSP get-parameter-replies.
*/
class PingReply : public SerialLinkedListAdapter<SerializeIF> {
public:
PingReply(uint8_t action_, uint8_t replyTime_) :
action(action_), replyTime(replyTime_) {
setLinks();
}
private:
PingReply(const PingReply &reply);
void setLinks() {
setStart(&action);
action.setNext(&replyTime);
}
SerializeElement<uint8_t> action;
SerializeElement<uint32_t> replyTime;
};
/** /**
* @brief This class helps to unpack information from an action messages * @brief This class helps to unpack information from an action messages
* to set a parameter in gomspace devices. The action message can be * to set a parameter in gomspace devices. The action message can be
@ -360,41 +364,4 @@ private:
uint8_t parameterSize; uint8_t parameterSize;
}; };
/**
* @brief This class helps to extract the information of a message received
* from an other software component (e.g. the service 8) to generate
* a ping request for gomspace devices.
*/
class PingMessageUnpacker: public SerialLinkedListAdapter<SerializeIF> {
public:
PingMessageUnpacker(const uint8_t* commandData, size_t commandDataLen) {
SerializeAdapter::deSerialize(&action, &commandData, &commandDataLen,
SerializeIF::Endianness::BIG);
pingData = commandData;
pingDataSz = commandDataLen;
}
uint8_t getAction() const {
return action;
}
const uint8_t* getPingData() {
return pingData;
}
uint8_t getPingDataSz(){
return pingDataSz;
}
private:
PingMessageUnpacker(const PingMessageUnpacker &message);
uint8_t action;
const uint8_t * pingData;
uint8_t pingDataSz;
};
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GOMSPACEPACKETS_H_ */ #endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GOMSPACEPACKETS_H_ */