From f778292d8e7c3a11cc5b7e013f6f7a31ba6d50c4 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 16 Dec 2020 10:56:32 +0100 Subject: [PATCH] working parameter getting and setting of p60dock --- README.md | 8 ++ bsp_linux/comIF/CspComIF.cpp | 17 ++-- mission/devices/P60DockHandler.cpp | 64 ++++++++++++--- .../devicedefinitions/GomSpacePackets.h | 81 ++++++++++--------- tmtc | 2 +- 5 files changed, 119 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index b70e1cd6..f4d5c5f5 100644 --- a/README.md +++ b/README.md @@ -339,4 +339,12 @@ x values: 1,2 or 4 param table x ```` Table 4 lists HK parameters +Changing parameters +First switch to table where parameter shall be changed (here table id is 1) +```` +p60-dock # param mem 1 +p60-dock # param set out_en[0] 1 +p60-dock # param get out_en[0] +GET out_en[0] = 1 +```` diff --git a/bsp_linux/comIF/CspComIF.cpp b/bsp_linux/comIF/CspComIF.cpp index e7616bba..00f11c7e 100644 --- a/bsp_linux/comIF/CspComIF.cpp +++ b/bsp_linux/comIF/CspComIF.cpp @@ -157,13 +157,18 @@ ReturnValue_t CspComIF::cspTransfer(uint8_t cspAddress, uint8_t cspPort, csp_conn_t * conn = csp_connect(CSP_PRIO_HIGH, cspAddress, cspPort, 0, CSP_O_NONE); - querySize = 14; - int receivedBytes = csp_transaction_persistent(conn, timeout_ms, + int result = csp_transaction_persistent(conn, timeout_ms, tmpCmdBuffer, cmdBufferLen, replyBuffer, querySize); - if(receivedBytes != querySize){ - sif::error << "CSP transfer failed to receive all requested bytes " - << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; + if(querySize != 0){ + if(result != querySize){ + sif::error << "CSP transfer failed to receive all requested bytes " + << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + } else { + if(result != 1){ + sif::error << "CSP transfer failed" << std::endl; + } } csp_close(conn); diff --git a/mission/devices/P60DockHandler.cpp b/mission/devices/P60DockHandler.cpp index f1950f50..8263165b 100644 --- a/mission/devices/P60DockHandler.cpp +++ b/mission/devices/P60DockHandler.cpp @@ -37,6 +37,50 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand( break; } case(PARAM_SET):{ + SetParamMessageUnpacker setParamMessageUnpacker(commandData, + commandDataLen); + uint8_t tableId = setParamMessageUnpacker.getTableId(); + uint16_t address = EndianConverter::convertLittleEndian( + setParamMessageUnpacker.getAddress()); + 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(); + uint32_t parameter; + parameter = *parameterPtr; + switch(parameterSize) { + case(sizeof(uint16_t)): { + parameter = EndianConverter::convertLittleEndian( + (uint16_t)parameter); + break; + } + case(sizeof(uint32_t)): { + parameter = EndianConverter::convertLittleEndian( + parameter); + break; + } + default: + break; + } + uint16_t payloadlength = EndianConverter::convertLittleEndian( + sizeof(address) + parameterSize); + CspSetParamCommand setParamCmd(querySize, PARAM_SET, tableId, payloadlength, + checksum, seq, total, address, (uint8_t*) ¶meter, + 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; break; } case(PARAM_GET):{ @@ -50,7 +94,7 @@ ReturnValue_t P60DockHandler::buildCommandFromCommand( uint16_t checksum = GOMSPACE::IGNORE_CHECKSUM; uint16_t seq = 0; uint16_t total = 0; - uint16_t querySize = getParamMessage.getQuerySize() + uint16_t querySize = getParamMessage.getParameterSize() + CspGetParamCommand::GS_HDR_LENGTH; /* Generate the CSP command to send to the P60 Dock */ CspGetParamCommand getParamCmd(querySize, PARAM_GET, tableId, length, @@ -110,19 +154,19 @@ ReturnValue_t P60DockHandler::interpretDeviceReply(DeviceCommandId_t id, break; } case(PARAM_GET): { - uint16_t payloadLength = *(packet + 2); + // -2 to subtract address size from gomspace parameter reply packet + uint16_t payloadLength = (*(packet + 2) << 8 | *(packet + 3)) - 2; uint8_t tempPayloadBuffer[payloadLength]; CspGetParamReply cspGetParamReply(tempPayloadBuffer, payloadLength); - uint8_t action = cspGetParamReply.getAction(); - uint8_t tableId = cspGetParamReply.getTableId(); - uint16_t length = cspGetParamReply.getLength(); - uint16_t address = cspGetParamReply.getAddress(); size_t size = CspGetParamReply::GS_HDR_LENGTH + payloadLength; cspGetParamReply.deSerialize(&packet, &size, - SerializeIF::Endianness::LITTLE); - ParamReply paramReply(action, tableId, address, length, tempPayloadBuffer, - payloadLength); - handleDeviceTM(¶mReply, id, true, true); + SerializeIF::Endianness::BIG); + uint8_t action = cspGetParamReply.getAction(); + uint8_t tableId = cspGetParamReply.getTableId(); + uint16_t address = cspGetParamReply.getAddress(); + ParamReply paramReply(action, tableId, address, payloadLength, + tempPayloadBuffer); + handleDeviceTM(¶mReply, id, true); break; } default: diff --git a/mission/devices/devicedefinitions/GomSpacePackets.h b/mission/devices/devicedefinitions/GomSpacePackets.h index 025beeb8..4da31b08 100644 --- a/mission/devices/devicedefinitions/GomSpacePackets.h +++ b/mission/devices/devicedefinitions/GomSpacePackets.h @@ -64,13 +64,17 @@ private: */ class CspSetParamCommand : public SerialLinkedListAdapter { public: - CspSetParamCommand(uint8_t action_, uint8_t tableId_, - uint16_t addresslength_, uint16_t checksum_, uint16_t seq_, - uint16_t total_, uint16_t addr_, const uint8_t* parameters_, + + 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_) : - action(action_), tableId(tableId_), addresslength(addresslength_), checksum( - checksum_), seq(seq_), total(total_), addr(addr_), parameters( - parameters_, parameterCount_) { + querySize(querySize_), action(action_), tableId(tableId_), payloadlength( + payloadlength_), checksum(checksum_), seq(seq_), total( + total_), addr(addr_), parameter(parameter_, + parameterCount_) { setLinks(); } @@ -81,23 +85,24 @@ private: cspPort.setNext(&querySize); querySize.setNext(&action); action.setNext(&tableId); - tableId.setNext(&addresslength); - addresslength.setNext(&checksum); + tableId.setNext(&payloadlength); + payloadlength.setNext(&checksum); checksum.setNext(&seq); - seq.setNext(&addr); - addr.setNext(¶meters); + seq.setNext(&total); + total.setNext(&addr); + addr.setNext(¶meter); } SerializeElement cspPort = GOMSPACE::PARAM_PORT; - /* Only parameters are set. No data will be queried with this command */ - SerializeElement querySize = 0; + /* Only a parameter will be set. No data will be queried with this command */ + SerializeElement querySize; SerializeElement action; SerializeElement tableId; - SerializeElement addresslength; + SerializeElement payloadlength; SerializeElement checksum; SerializeElement seq; SerializeElement total; SerializeElement addr; - SerializeElement> parameters; + SerializeElement> parameter; }; @@ -196,13 +201,17 @@ private: void setLinks() { setStart(&action); action.setNext(&tableId); - seq.setNext(&addr); + tableId.setNext(&length); + length.setNext(&checksum); + checksum.setNext(&seq); + seq.setNext(&total); + total.setNext(&addr); addr.setNext(&payload); } SerializeElement action; SerializeElement tableId; - SerializeElement length; //length of payload data + SerializeElement length; //length of address field + payload data SerializeElement checksum; SerializeElement seq; SerializeElement total; @@ -226,8 +235,9 @@ public: * data will be stored. */ ParamReply(uint8_t action_, uint8_t tableId_, uint16_t addr_, - uint16_t length_, uint8_t* payloadBuffer_, uint8_t payloadBufferSz_) : - payload(payloadBuffer_, payloadBufferSz_) { + uint16_t payloadLength_, uint8_t* payloadBuffer_) : + action(action_), tableId(tableId_), addr(addr_), payloadLength( + payloadLength_), payload(payloadBuffer_, payloadLength) { setLinks(); } @@ -237,14 +247,14 @@ private: setStart(&action); action.setNext(&tableId); tableId.setNext(&addr); - addr.setNext(&length); - length.setNext(&payload); + addr.setNext(&payloadLength); + payloadLength.setNext(&payload); } SerializeElement action; SerializeElement tableId; SerializeElement addr; - SerializeElement length; - SerializeElement> payload; + SerializeElement payloadLength; + SerializeElement> payload; }; @@ -261,8 +271,8 @@ public: SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&address, &commandData, &commandDataLen, SerializeIF::Endianness::BIG); - parameterBuffer = commandData; - parameterCount = commandDataLen; + parameter = commandData; + parameterSize = commandDataLen; } uint8_t getTableId() const { @@ -273,12 +283,12 @@ public: return address; } - const uint8_t* getParameters() { - return parameterBuffer; + const uint8_t* getParameter() { + return parameter; } - uint8_t getParameterCount(){ - return parameterCount; + uint8_t getParameterSize(){ + return parameterSize; } @@ -286,10 +296,8 @@ private: SetParamMessageUnpacker(const SetParamMessageUnpacker &message); uint8_t tableId; uint16_t address; - /* Parameter buffer holds the values of the parameters to set while the - * address points to the location of a parameter. */ - const uint8_t * parameterBuffer; - uint8_t parameterCount; + const uint8_t * parameter; + uint8_t parameterSize; }; @@ -306,7 +314,7 @@ public: SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&address, &commandData, &commandDataLen, SerializeIF::Endianness::BIG); - SerializeAdapter::deSerialize(&querySize, &commandData, &commandDataLen, + SerializeAdapter::deSerialize(¶meterSize, &commandData, &commandDataLen, SerializeIF::Endianness::BIG); } @@ -318,8 +326,8 @@ public: return address; } - uint8_t getQuerySize(){ - return querySize; + uint8_t getParameterSize(){ + return parameterSize; } @@ -327,7 +335,8 @@ private: GetParamMessageUnpacker(const GetParamMessageUnpacker &message); uint8_t tableId; uint16_t address; //The memory address offset within the table - uint8_t querySize; //defines number of bytes to query + /* The size of the requested value (e.g. temperature is a uint16_t value) */ + uint8_t parameterSize; }; diff --git a/tmtc b/tmtc index 0c0e0595..1bfde844 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 0c0e0595f177b8fe4100902058a10e8d5ad34663 +Subproject commit 1bfde84450f47a028ca831a4dfa8c84cbd4d1fab