401 lines
11 KiB
C++
401 lines
11 KiB
C++
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_GOMSPACEPACKETS_H_
|
|
#define MISSION_DEVICES_DEVICEDEFINITIONS_GOMSPACEPACKETS_H_
|
|
|
|
#include "fsfw/serialize/SerialBufferAdapter.h"
|
|
#include "fsfw/serialize/SerializeElement.h"
|
|
#include "fsfw/serialize/SerialLinkedListAdapter.h"
|
|
|
|
namespace GOMSPACE{
|
|
static const uint16_t IGNORE_CHECKSUM = 0xbb0;
|
|
/* CSP port to ping gomspace devices. */
|
|
static const uint8_t PING_PORT = 1;
|
|
static const uint8_t REBOOT_PORT = 4;
|
|
/* CSP port of gomspace devices to request or set parameters */
|
|
static const uint8_t PARAM_PORT = 7;
|
|
}
|
|
|
|
/**
|
|
* @brief A serial linked list adapter implementation to generate ping
|
|
* commands for devices supporting the CSP protocol. This command can
|
|
* be sent to the CspComIF which will send out the ping request.
|
|
*
|
|
* @details A ping request simply sends back the received data provided by the
|
|
* data buffer. cspPort and querySize are only informations required
|
|
* by the CspComI and other than the data array not physically
|
|
* transmitted to the target device.
|
|
*/
|
|
class CspPingCommand : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
/**
|
|
* @brief Constructor
|
|
*
|
|
* @param querySize_ The size of bytes replied by the ping request.
|
|
* Amounts to the number of bytes send.
|
|
* @param parameters_ Pointer to data which should be sent to the device.
|
|
* All data will be sent back by the ping target.
|
|
*/
|
|
CspPingCommand(uint16_t querySize_, const uint8_t* parameters_) :
|
|
querySize(querySize_), data(parameters_, querySize_) {
|
|
setLinks();
|
|
}
|
|
|
|
private:
|
|
CspPingCommand(const CspPingCommand &command);
|
|
void setLinks() {
|
|
setStart(&cspPort);
|
|
cspPort.setNext(&querySize);
|
|
querySize.setNext(&data);
|
|
}
|
|
SerializeElement<uint8_t> cspPort = GOMSPACE::PING_PORT;
|
|
SerializeElement<uint16_t> querySize;
|
|
SerializeElement<SerialBufferAdapter<uint8_t>> data;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief A serial linked list adapter implementation of the gs_rparam_query_t
|
|
* struct defined in rparam.h. Can be used to build the message to set
|
|
* a parameter in gomspace devices.
|
|
*
|
|
* @note cspPort and querySize will not be sent with the CSP packet to the
|
|
* gomspace device but are required for the CspComIF to get the port
|
|
* and the size to query.
|
|
*/
|
|
class CspSetParamCommand : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
|
|
static const uint8_t GS_HDR_LENGTH = 12;
|
|
|
|
CspSetParamCommand(uint16_t querySize_, uint8_t action_, uint8_t tableId_,
|
|
uint16_t payloadlength_, uint16_t checksum_, uint16_t seq_,
|
|
uint16_t total_, uint16_t addr_, const uint8_t* parameter_,
|
|
uint8_t parameterCount_) :
|
|
querySize(querySize_), action(action_), tableId(tableId_), payloadlength(
|
|
payloadlength_), checksum(checksum_), seq(seq_), total(
|
|
total_), addr(addr_), parameter(parameter_,
|
|
parameterCount_) {
|
|
setLinks();
|
|
}
|
|
|
|
private:
|
|
CspSetParamCommand(const CspSetParamCommand &command);
|
|
void setLinks() {
|
|
setStart(&cspPort);
|
|
cspPort.setNext(&querySize);
|
|
querySize.setNext(&action);
|
|
action.setNext(&tableId);
|
|
tableId.setNext(&payloadlength);
|
|
payloadlength.setNext(&checksum);
|
|
checksum.setNext(&seq);
|
|
seq.setNext(&total);
|
|
total.setNext(&addr);
|
|
addr.setNext(¶meter);
|
|
}
|
|
SerializeElement<uint8_t> cspPort = GOMSPACE::PARAM_PORT;
|
|
/* Only a parameter will be set. No data will be queried with this command */
|
|
SerializeElement<uint16_t> querySize;
|
|
SerializeElement<uint8_t> action;
|
|
SerializeElement<uint8_t> tableId;
|
|
SerializeElement<uint16_t> payloadlength;
|
|
SerializeElement<uint16_t> checksum;
|
|
SerializeElement<uint16_t> seq;
|
|
SerializeElement<uint16_t> total;
|
|
SerializeElement<uint16_t> addr;
|
|
SerializeElement<SerialBufferAdapter<uint8_t>> parameter;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief This class can be used to generate a get param command for the
|
|
* gomspace devices which will be sent to the device communication
|
|
* interface object.
|
|
*
|
|
* @note cspPort and querySize only serve as information for the CspComIF
|
|
* and will not be transmitted physically to the target device.
|
|
*/
|
|
class CspGetParamCommand : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
/* The size of the header of a gomspace CSP packet. */
|
|
static const uint8_t GS_HDR_LENGTH = 12;
|
|
|
|
CspGetParamCommand(uint16_t querySize_, uint8_t action_, uint8_t tableId_,
|
|
uint16_t addresslength_, uint16_t checksum_, uint16_t seq_,
|
|
uint16_t total_, uint16_t addr_) :
|
|
querySize(querySize_), action(action_), tableId(tableId_), addresslength(
|
|
addresslength_), checksum(checksum_), seq(seq_), total(
|
|
total_), addr(addr_) {
|
|
fixedValuesInit();
|
|
setLinks();
|
|
}
|
|
|
|
private:
|
|
CspGetParamCommand(const CspGetParamCommand &command);
|
|
void setLinks() {
|
|
setStart(&cspPort);
|
|
cspPort.setNext(&querySize);
|
|
querySize.setNext(&action);
|
|
action.setNext(&tableId);
|
|
tableId.setNext(&addresslength);
|
|
addresslength.setNext(&checksum);
|
|
checksum.setNext(&seq);
|
|
seq.setNext(&total);
|
|
total.setNext(&addr);
|
|
}
|
|
void fixedValuesInit(){
|
|
cspPort.entry = GOMSPACE::PARAM_PORT;
|
|
}
|
|
SerializeElement<uint8_t> cspPort;
|
|
SerializeElement<uint16_t> querySize; // size of bytes to query
|
|
/* Following information will also be physically transmitted to the target
|
|
* device*/
|
|
SerializeElement<uint8_t> action;
|
|
SerializeElement<uint8_t> tableId;
|
|
SerializeElement<uint16_t> addresslength; // size of address
|
|
SerializeElement<uint16_t> checksum;
|
|
SerializeElement<uint16_t> seq;
|
|
SerializeElement<uint16_t> total;
|
|
SerializeElement<uint16_t> addr;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief This class can be used to deserialize replies from gomspace devices
|
|
* and extract the relevant data.
|
|
*/
|
|
class CspGetParamReply : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
/* The size of the header of a gomspace CSP packet. */
|
|
static const uint8_t GS_HDR_LENGTH = 12;
|
|
/**
|
|
* @brief Constructor
|
|
*
|
|
* @param payloadBuffer Pointer to a buffer to store the payload data of
|
|
* the CSP packet.
|
|
* @param payloadBufferSz The size of the payload buffer where the payload
|
|
* data will be stored.
|
|
*/
|
|
CspGetParamReply(uint8_t* payloadBuffer_, uint8_t payloadBufferSz_) :
|
|
payload(payloadBuffer_, payloadBufferSz_) {
|
|
setLinks();
|
|
}
|
|
|
|
uint8_t getAction(){
|
|
return action;
|
|
}
|
|
|
|
uint8_t getTableId(){
|
|
return tableId;
|
|
}
|
|
|
|
uint16_t getLength(){
|
|
return length;
|
|
}
|
|
|
|
uint16_t getAddress(){
|
|
return addr;
|
|
}
|
|
|
|
private:
|
|
CspGetParamReply(const CspGetParamReply &reply);
|
|
void setLinks() {
|
|
setStart(&action);
|
|
action.setNext(&tableId);
|
|
tableId.setNext(&length);
|
|
length.setNext(&checksum);
|
|
checksum.setNext(&seq);
|
|
seq.setNext(&total);
|
|
total.setNext(&addr);
|
|
addr.setNext(&payload);
|
|
}
|
|
|
|
SerializeElement<uint8_t> action;
|
|
SerializeElement<uint8_t> tableId;
|
|
SerializeElement<uint16_t> length; //length of address field + payload data
|
|
SerializeElement<uint16_t> checksum;
|
|
SerializeElement<uint16_t> seq;
|
|
SerializeElement<uint16_t> total;
|
|
SerializeElement<uint16_t> addr;
|
|
SerializeElement<SerialBufferAdapter<uint8_t>> payload;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief This class generates telemetry packets containing data from
|
|
* CSP get-parameter-replies.
|
|
*/
|
|
class ParamReply : public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
/**
|
|
* @brief Constructor
|
|
*
|
|
* @param payloadBuffer Pointer to a buffer to store the payload data of
|
|
* the CSP packet.
|
|
* @param payloadBufferSz The size of the payload buffer where the payload
|
|
* data will be stored.
|
|
*/
|
|
ParamReply(uint8_t action_, uint8_t tableId_, uint16_t addr_,
|
|
uint16_t payloadLength_, uint8_t* payloadBuffer_) :
|
|
action(action_), tableId(tableId_), addr(addr_), payloadLength(
|
|
payloadLength_), payload(payloadBuffer_, payloadLength) {
|
|
setLinks();
|
|
}
|
|
|
|
private:
|
|
ParamReply(const CspGetParamReply &reply);
|
|
void setLinks() {
|
|
setStart(&action);
|
|
action.setNext(&tableId);
|
|
tableId.setNext(&addr);
|
|
addr.setNext(&payloadLength);
|
|
payloadLength.setNext(&payload);
|
|
}
|
|
SerializeElement<uint8_t> action;
|
|
SerializeElement<uint8_t> tableId;
|
|
SerializeElement<uint16_t> addr;
|
|
SerializeElement<uint16_t> payloadLength;
|
|
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
|
|
* to set a parameter in gomspace devices. The action message can be
|
|
* for example received from the PUS Service 8.
|
|
*/
|
|
class SetParamMessageUnpacker: public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
|
|
SetParamMessageUnpacker(const uint8_t* commandData, size_t commandDataLen) {
|
|
SerializeAdapter::deSerialize(&tableId, &commandData, &commandDataLen,
|
|
SerializeIF::Endianness::BIG);
|
|
SerializeAdapter::deSerialize(&address, &commandData, &commandDataLen,
|
|
SerializeIF::Endianness::BIG);
|
|
parameter = commandData;
|
|
parameterSize = commandDataLen;
|
|
}
|
|
|
|
uint8_t getTableId() const {
|
|
return tableId;
|
|
}
|
|
|
|
uint16_t getAddress() const {
|
|
return address;
|
|
}
|
|
|
|
const uint8_t* getParameter() {
|
|
return parameter;
|
|
}
|
|
|
|
uint8_t getParameterSize(){
|
|
return parameterSize;
|
|
}
|
|
|
|
|
|
private:
|
|
SetParamMessageUnpacker(const SetParamMessageUnpacker &message);
|
|
uint8_t tableId;
|
|
uint16_t address;
|
|
const uint8_t * parameter;
|
|
uint8_t parameterSize;
|
|
};
|
|
|
|
|
|
/**
|
|
* @brief This class helps to unpack information from an action message
|
|
* to get a parameter from gomspace devices. The action message can be
|
|
* for example received from the PUS Service 8.
|
|
*/
|
|
class GetParamMessageUnpacker: public SerialLinkedListAdapter<SerializeIF> {
|
|
public:
|
|
|
|
GetParamMessageUnpacker(const uint8_t* commandData, size_t commandDataLen) {
|
|
SerializeAdapter::deSerialize(&tableId, &commandData, &commandDataLen,
|
|
SerializeIF::Endianness::BIG);
|
|
SerializeAdapter::deSerialize(&address, &commandData, &commandDataLen,
|
|
SerializeIF::Endianness::BIG);
|
|
SerializeAdapter::deSerialize(¶meterSize, &commandData, &commandDataLen,
|
|
SerializeIF::Endianness::BIG);
|
|
}
|
|
|
|
uint8_t getTableId() const {
|
|
return tableId;
|
|
}
|
|
|
|
uint16_t getAddress() const {
|
|
return address;
|
|
}
|
|
|
|
uint8_t getParameterSize(){
|
|
return parameterSize;
|
|
}
|
|
|
|
|
|
private:
|
|
GetParamMessageUnpacker(const GetParamMessageUnpacker &message);
|
|
uint8_t tableId;
|
|
uint16_t address; //The memory address offset within the table
|
|
/* The size of the requested value (e.g. temperature is a uint16_t value) */
|
|
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_ */
|