working pdu2handler

This commit is contained in:
Jakob Meier 2020-12-20 17:35:03 +01:00
parent 23fd408e08
commit c9fbd2c048
11 changed files with 113 additions and 67 deletions

View File

@ -21,8 +21,9 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) {
if(cspCookie == nullptr) {
return NULLPOINTER;
}
char* canInterface = cspCookie->getCanIf();
int bitrate = cspCookie->getBitrate();
/* Perform CAN and CSP initialization only once */
if(cspDeviceMap.empty()){
/* Define the memory to allocate for the CSP stack */
int buf_count = 10;
int buf_size = 300;
@ -56,6 +57,7 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF *cookie) {
sif::error << "Failed to start csp route task" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
}
uint8_t cspAddress = cspCookie->getCspAddress();
uint16_t maxReplyLength = cspCookie->getMaxReplyLength();

View File

@ -10,10 +10,10 @@
#include <unordered_map>
/**
* @brief This class is serves as the communication interface to devices
* supporting the CSP protocol. For now as physical interface only
* CAN is supported by this CSP implementation.
* @author Jakob Meier
* @brief This class serves as the communication interface to devices
* supporting the CSP protocol. As physical layer can0 is used
* in this implementation.
* @author J. Meier
*/
class CspComIF: public DeviceCommunicationIF, public SystemObject {
public:
@ -70,6 +70,9 @@ private:
/* Interface struct for csp protocol stack */
csp_iface_t csp_if;
char canInterface[5] = "can0";
int bitrate = 1000;
/**
* @brief Function to extract the csp port and the query size from the
* command buffer.

View File

@ -14,11 +14,3 @@ uint16_t CspCookie::getMaxReplyLength(){
uint8_t CspCookie::getCspAddress(){
return cspAddress;
}
char* CspCookie::getCanIf(){
return canInterface;
}
int CspCookie::getBitrate(){
return bitrate;
}

View File

@ -17,15 +17,11 @@ public:
uint16_t getMaxReplyLength();
uint8_t getCspAddress();
char* getCanIf();
int getBitrate();
private:
uint16_t maxReplyLength;
char canInterface[5] = "can0";
uint8_t cspAddress;
int bitrate = 1000;
};
#endif /* BSP_LINUX_COMIF_COOKIES_CSPCOOKIE_H_ */

View File

@ -35,7 +35,8 @@ namespace objects {
/* 0x44 ('D') for device handlers */
P60DOCK_HANDLER = 0x44000001,
PDU2_HANDLER = 0x44000002
PDU1_HANDLER = 0x44000002,
PDU2_HANDLER = 0x44000003
};
}

View File

@ -34,15 +34,31 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK;

View File

@ -1,6 +1,6 @@
CSRC += $(wildcard $(CURRENTPATH)/src/drivers/can/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/*.c)
CSRC += $(wildcard $(CURRENTPATH)/libcsp/src/interfaces/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/interfaces/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/rtable/csp_rtable_cidr.c)
CSRC += $(wildcard $(CURRENTPATH)/src/crypto/*.c)
CSRC += $(wildcard $(CURRENTPATH)/src/arch/posix/*.c)

View File

@ -88,6 +88,10 @@ void ObjectFactory::produceGenericObjects() {
/* Cookies */
CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH,
addresses::P60DOCK);
CspCookie* pdu1CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH,
addresses::PDU1);
CspCookie* pdu2CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH,
addresses::PDU2);
/* Communication interfaces */
new CspComIF(objects::CSP_COM_IF);
@ -96,6 +100,12 @@ void ObjectFactory::produceGenericObjects() {
new GomspaceDeviceHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF,
p60DockCspCookie, P60Dock::MAX_CONFIGTABLE_ADDRESS,
P60Dock::MAX_HKTABLE_ADDRESS);
new GomspaceDeviceHandler(objects::PDU1_HANDLER, objects::CSP_COM_IF,
pdu1CspCookie, PDU::MAX_CONFIGTABLE_ADDRESS,
PDU::MAX_HKTABLE_ADDRESS);
new GomspaceDeviceHandler(objects::PDU2_HANDLER, objects::CSP_COM_IF,
pdu2CspCookie, PDU::MAX_CONFIGTABLE_ADDRESS,
PDU::MAX_HKTABLE_ADDRESS);
/* Test Device Handler */
#if ADD_TEST_CODE == 1

View File

@ -112,7 +112,6 @@ ReturnValue_t GomspaceDeviceHandler::scanForReply(const uint8_t *start,
ReturnValue_t GomspaceDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch(id) {
//todo: check replies
case(PING): {
SerializeElement<uint32_t> replyTime = *packet;
handleDeviceTM(&replyTime, id, true);
@ -121,6 +120,11 @@ ReturnValue_t GomspaceDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
case(PARAM_GET): {
// -2 to subtract address size from gomspace parameter reply packet
uint16_t payloadLength = (*(packet + 2) << 8 | *(packet + 3)) - 2;
if(payloadLength > sizeof(uint32_t)){
sif::error << "GomspaceDeviceHandler: PARAM_GET: Invalid payload "
<< "size in reply" << std::endl;
return INVALID_PAYLOAD_SIZE;
}
uint8_t tempPayloadBuffer[payloadLength];
/* Extract information from received data */
CspGetParamReply cspGetParamReply(tempPayloadBuffer, payloadLength);
@ -129,12 +133,13 @@ ReturnValue_t GomspaceDeviceHandler::interpretDeviceReply(DeviceCommandId_t id,
SerializeIF::Endianness::BIG);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "GomspaceDeviceHandler: Failed to deserialize get parameter"
<< "message" << std::endl;
<< "reply" << std::endl;
return result;
}
uint8_t action = cspGetParamReply.getAction();
uint8_t tableId = cspGetParamReply.getTableId();
uint16_t address = cspGetParamReply.getAddress();
/* Pack relevant information into a tm reply packet */
/* Pack relevant information into a tm packet */
ParamReply paramReply(action, tableId, address, payloadLength,
tempPayloadBuffer);
handleDeviceTM(&paramReply, id, true);
@ -166,7 +171,7 @@ ReturnValue_t GomspaceDeviceHandler::generateSetParamCommand(
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "GomspaceDeviceHandler: Failed to deserialize set parameter "
"message" << std::endl;
return FAILED_DESERIALIZATION;
return result;
}
/* Get and check address */
uint16_t address = setParamMessageUnpacker.getAddress();
@ -195,7 +200,7 @@ ReturnValue_t GomspaceDeviceHandler::generateSetParamCommand(
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "GomspaceDeviceHandler: Failed to serialize command for "
<< "CspComIF" << std::endl;
return FAILED_SERIALIZATION;
return result;
}
if(cspPacketLen > MAX_PACKET_LEN){
sif::error << "GomspaceDeviceHandler: Invalid length of set parameter "
@ -219,12 +224,13 @@ ReturnValue_t GomspaceDeviceHandler::generateGetParamCommand(
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "Failed to deserialize message to extract information "
"from get parameter message" << std::endl;
return FAILED_SERIALIZATION;
return result;
}
/* Get an check table id to read from */
uint8_t tableId = getParamMessage.getTableId();
if(CONFIG_TABLE_ID != 1 && HK_TABLE_ID != 4){
sif::error << "GomspaceDeviceHandler: Invalid table id received "
<< "for getting a paramter" << std::endl;
if(tableId != CONFIG_TABLE_ID && tableId != HK_TABLE_ID){
sif::error << "GomspaceDeviceHandler: Invalid table id in get parameter"
" message" << std::endl;
return INVALID_TABLE_ID;
}
/* Get and check address */
@ -243,8 +249,13 @@ ReturnValue_t GomspaceDeviceHandler::generateGetParamCommand(
uint16_t checksum = GOMSPACE::IGNORE_CHECKSUM;
uint16_t seq = 0;
uint16_t total = 0;
uint16_t querySize = getParamMessage.getParameterSize()
+ CspGetParamCommand::GS_HDR_LENGTH;
uint8_t parameterSize = getParamMessage.getParameterSize();
if(parameterSize > sizeof(uint32_t)) {
sif::error << "GomspaceDeviceHandler: GET_PARAM: Invalid parameter "
<< "size" << std::endl;
return INVALID_PARAM_SIZE;
}
uint16_t querySize = parameterSize + CspGetParamCommand::GS_HDR_LENGTH;
/* Generate the CSP command to send to the P60 Dock */
CspGetParamCommand getParamCmd(querySize, tableId, length,
@ -280,7 +291,7 @@ ReturnValue_t GomspaceDeviceHandler::generatePingCommand(
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "GomspaceDeviceHandler: Failed to serialize ping command"
<< std::endl;
return FAILED_SERIALIZATION;
return result;
}
if(cspPacketLen > MAX_PACKET_LEN){
sif::error << "GomspaceDeviceHandler: Received invalid ping message"
@ -312,7 +323,7 @@ ReturnValue_t GomspaceDeviceHandler::generateResetWatchdogCmd(){
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "GomspaceDeviceHandler: Failed to serialize watchdog reset "
<< "command" << std::endl;
return FAILED_SERIALIZATION;
return result;
}
rawPacket = cspPacket;
rawPacketLen = cspPacketLen;

View File

@ -14,11 +14,11 @@
class GomspaceDeviceHandler: public DeviceHandlerBase {
public:
static const ReturnValue_t FAILED_DESERIALIZATION = MAKE_RETURN_CODE(0xE0);
static const ReturnValue_t FAILED_SERIALIZATION = MAKE_RETURN_CODE(0xE1);
static const ReturnValue_t PACKET_TOO_LONG = MAKE_RETURN_CODE(0xE2);
static const ReturnValue_t INVALID_TABLE_ID = MAKE_RETURN_CODE(0xE3);
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0xE4);
static const ReturnValue_t PACKET_TOO_LONG = MAKE_RETURN_CODE(0xE0);
static const ReturnValue_t INVALID_TABLE_ID = MAKE_RETURN_CODE(0xE1);
static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0xE2);
static const ReturnValue_t INVALID_PARAM_SIZE = MAKE_RETURN_CODE(0xE3);
static const ReturnValue_t INVALID_PAYLOAD_SIZE = MAKE_RETURN_CODE(0xE4);
/**
* @brief Constructor

View File

@ -21,4 +21,19 @@ namespace P60Dock{
}
namespace PDU{
/* When retrieving full configuration parameter table */
static const uint16_t MAX_REPLY_LENGTH = 318;
static const uint16_t MAX_CONFIGTABLE_ADDRESS = 316;
static const uint16_t MAX_HKTABLE_ADDRESS = 140;
}
namespace ACU{
/* When receiving full houskeeping (telemetry) table */
static const uint16_t MAX_REPLY_LENGTH = 124;
static const uint16_t MAX_CONFIGTABLE_ADDRESS = 26;
static const uint16_t MAX_HKTABLE_ADDRESS = 120;
}
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_GOMSPACEDEFINITIONS_H_ */