diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a8f1021..3f159cc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -466,6 +466,7 @@ endif() if(ADD_GOMSPACE_CLIENTS) target_link_libraries(${OBSW_NAME} PRIVATE ${LIB_GOMSPACE_CLIENTS}) + target_link_libraries(${LIB_EIVE_MISSION} PRIVATE ${LIB_GOMSPACE_CLIENTS}) endif() if(EIVE_ADD_ETL_LIB) diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index 208e5aed..9c349b59 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 3ac765ff..34586450 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -158,10 +158,10 @@ void ObjectFactory::createCommunicationInterfaces(LinuxLibgpioIF** gpioComIF, Ua } void ObjectFactory::createPcduComponents(LinuxLibgpioIF* gpioComIF, PowerSwitchIF** pwrSwitcher) { - 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); - CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, addresses::ACU); + CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, addresses::P60DOCK, 500); + CspCookie* pdu1CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, addresses::PDU1, 500); + CspCookie* pdu2CspCookie = new CspCookie(PDU::MAX_REPLY_LENGTH, addresses::PDU2, 500); + CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, addresses::ACU, 500); auto p60Fdir = new GomspacePowerFdir(objects::P60DOCK_HANDLER); P60DockHandler* p60dockhandler = diff --git a/linux/csp/CspComIF.cpp b/linux/csp/CspComIF.cpp index 9f346405..ee515b9a 100644 --- a/linux/csp/CspComIF.cpp +++ b/linux/csp/CspComIF.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "CspCookie.h" @@ -65,44 +67,56 @@ ReturnValue_t CspComIF::initializeInterface(CookieIF* cookie) { /* Insert device information in CSP map */ cspDeviceMap.emplace(cspAddress, vectorBuffer(maxReplyLength)); } - return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t CspComIF::sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) { int result; - if (cookie == NULL) { + if (cookie == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } CspCookie* cspCookie = dynamic_cast(cookie); - if (cspCookie == NULL) { + if (cspCookie == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - /* Extract csp port and bytes to query from command buffer */ uint8_t cspPort; uint16_t querySize = 0; - result = getPortAndQuerySize(&sendData, &sendLen, &cspPort, &querySize); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; + if(cspCookie->getRequest() == CspCookie::SpecialRequestTypes::DEFAULT_COM_IF) { + /* Extract csp port and bytes to query from command buffer */ + result = getPortAndQuerySize(&sendData, &sendLen, &cspPort, &querySize); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } else { + cspPort = cspCookie->getCspPort(); + querySize = cspCookie->getReplyLen(); } uint8_t cspAddress = cspCookie->getCspAddress(); switch (cspPort) { - case (Ports::CSP_PING): { + case (GOMSPACE::CspPorts::CSP_PING): { initiatePingRequest(cspAddress, querySize); break; } - case (Ports::CSP_REBOOT): { + case (GOMSPACE::CspPorts::CSP_REBOOT): { csp_reboot(cspAddress); break; } - case (Ports::P60_PORT_GNDWDT_RESET): - case (Ports::P60_PORT_RPARAM): { - /* No CSP fixed port was selected. Send data to the specified port and - * wait for querySize number of bytes */ - result = cspTransfer(cspAddress, cspPort, sendData, sendLen, querySize); - if (result != HasReturnvaluesIF::RETURN_OK) { - return HasReturnvaluesIF::RETURN_FAILED; + case (GOMSPACE::CspPorts::P60_PORT_GNDWDT_RESET_ENUM): + case (GOMSPACE::CspPorts::P60_PORT_RPARAM_ENUM): { + if(cspCookie->getRequest() == CspCookie::SpecialRequestTypes::GET_PDU_HK) { + param_index_t requestStruct{}; + requestStruct.physaddr = cspDeviceMap[cspAddress].data(); + if(!p60pdu_get_hk(&requestStruct, cspAddress, cspCookie->getTimeout())) { + return HasReturnvaluesIF::RETURN_FAILED; + } + } else { + /* No CSP fixed port was selected. Send data to the specified port and + * wait for querySize number of bytes */ + result = cspTransfer(cspAddress, cspPort, sendData, sendLen, querySize); + if (result != HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_FAILED; + } } replySize = querySize; break; diff --git a/linux/csp/CspComIF.h b/linux/csp/CspComIF.h index d36bbf4f..7a54fa6e 100644 --- a/linux/csp/CspComIF.h +++ b/linux/csp/CspComIF.h @@ -42,8 +42,6 @@ class CspComIF : public DeviceCommunicationIF, public SystemObject { ReturnValue_t cspTransfer(uint8_t cspAddress, uint8_t cspPort, const uint8_t *cmdBuffer, int cmdLen, 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; using vectorBuffer = std::vector; using VectorBufferMap = std::unordered_map; @@ -59,7 +57,6 @@ class CspComIF : public DeviceCommunicationIF, public SystemObject { /* Interface struct for csp protocol stack */ csp_iface_t csp_if; - char canInterface[5] = "can0"; int bitrate = 1000; diff --git a/linux/csp/CspCookie.cpp b/linux/csp/CspCookie.cpp index 39274908..75d5ba73 100644 --- a/linux/csp/CspCookie.cpp +++ b/linux/csp/CspCookie.cpp @@ -1,10 +1,38 @@ #include "CspCookie.h" -CspCookie::CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_) - : maxReplyLength(maxReplyLength_), cspAddress(cspAddress_) {} +CspCookie::CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_, uint32_t timeoutMs) + : maxReplyLength(maxReplyLength_), cspAddress(cspAddress_), timeoutMs(timeoutMs), + reqType(DEFAULT_COM_IF) {} CspCookie::~CspCookie() {} uint16_t CspCookie::getMaxReplyLength() { return maxReplyLength; } -uint8_t CspCookie::getCspAddress() { return cspAddress; } +uint8_t CspCookie::getCspAddress() { + return cspAddress; +} + +CspCookie::SpecialRequestTypes CspCookie::getRequest() const { + return reqType; +} + +void CspCookie::setRequest(SpecialRequestTypes request, size_t replyLen_) { + reqType = request; + replyLen = replyLen_; +} + +uint8_t CspCookie::getCspPort() const { + return cspPort; +} + +uint32_t CspCookie::getTimeout() const { + return timeoutMs; +} + +void CspCookie::setCspPort(uint8_t port) { + cspPort = port; +} + +size_t CspCookie::getReplyLen() const { + return replyLen; +} diff --git a/linux/csp/CspCookie.h b/linux/csp/CspCookie.h index e59f3d35..b0f71d2e 100644 --- a/linux/csp/CspCookie.h +++ b/linux/csp/CspCookie.h @@ -4,6 +4,7 @@ #include #include +#include /** * @brief This is the cookie for devices supporting the CSP (CubeSat Space @@ -12,15 +13,35 @@ */ class CspCookie : public CookieIF { public: - CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_); + enum SpecialRequestTypes { + DEFAULT_COM_IF, + GET_PDU_HK, + GET_PDU_CONFIG, + GET_ACU_HK, + GET_ACU_CONFIG, + GET_P60DOCK_HK, + GET_P60DOCK_CONFIG + }; + + CspCookie(uint16_t maxReplyLength_, uint8_t cspAddress_, uint32_t timeoutMs); virtual ~CspCookie(); + void setCspPort(uint8_t port); + uint8_t getCspPort() const; uint16_t getMaxReplyLength(); + SpecialRequestTypes getRequest() const; + void setRequest(SpecialRequestTypes request, size_t replyLen); + size_t getReplyLen() const; uint8_t getCspAddress(); + uint32_t getTimeout() const; private: + uint8_t cspPort; uint16_t maxReplyLength; uint8_t cspAddress; + size_t replyLen = 0; + uint32_t timeoutMs; + SpecialRequestTypes reqType; }; #endif /* LINUX_CSP_CSPCOOKIE_H_ */ diff --git a/mission/devices/GomspaceDeviceHandler.cpp b/mission/devices/GomspaceDeviceHandler.cpp index d4442df9..c8659f7a 100644 --- a/mission/devices/GomspaceDeviceHandler.cpp +++ b/mission/devices/GomspaceDeviceHandler.cpp @@ -2,9 +2,13 @@ #include #include +#include +#include +#include #include "devicedefinitions/GomSpacePackets.h" #include "devicedefinitions/powerDefinitions.h" +#include using namespace GOMSPACE; @@ -426,22 +430,29 @@ ReturnValue_t GomspaceDeviceHandler::generateResetWatchdogCmd() { } ReturnValue_t GomspaceDeviceHandler::generateRequestFullTableCmd(uint8_t tableId, - uint16_t hkTableReplySize) { - uint16_t querySize = hkTableReplySize; - RequestFullTableCommand requestFullTableCommand(querySize, tableId); + uint16_t tableReplySize) { + uint16_t querySize = tableReplySize; + if(getObjectId() == objects::PDU1_HANDLER or getObjectId() == objects::PDU2_HANDLER) { + auto* cspCookie = dynamic_cast(comCookie); + cspCookie->setRequest(CspCookie::SpecialRequestTypes::GET_PDU_HK, tableReplySize); + cspCookie->setCspPort(GOMSPACE::CspPorts::P60_PORT_RPARAM_ENUM); + } else { + RequestFullTableCommand requestFullTableCommand(querySize, tableId); - size_t cspPacketLen = 0; - uint8_t* buffer = cspPacket; - ReturnValue_t result = requestFullTableCommand.serialize( - &buffer, &cspPacketLen, sizeof(cspPacket), SerializeIF::Endianness::BIG); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::error << "GomspaceDeviceHandler::generateRequestFullTableCmd Failed to serialize " - "full table request command " - << std::endl; - return result; + size_t cspPacketLen = 0; + uint8_t* buffer = cspPacket; + ReturnValue_t result = requestFullTableCommand.serialize( + &buffer, &cspPacketLen, sizeof(cspPacket), SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "GomspaceDeviceHandler::generateRequestFullTableCmd Failed to serialize " + "full table request command " + << std::endl; + return result; + } + rawPacket = cspPacket; + rawPacketLen = cspPacketLen; } - rawPacket = cspPacket; - rawPacketLen = cspPacketLen; + rememberRequestedSize = querySize; rememberCommandId = GOMSPACE::REQUEST_HK_TABLE; return RETURN_OK; @@ -458,7 +469,6 @@ ReturnValue_t GomspaceDeviceHandler::printStatus(DeviceCommandId_t cmd) { ReturnValue_t GomspaceDeviceHandler::parsePduHkTable(PDU::PduCoreHk& coreHk, PDU::PduAuxHk& auxHk, const uint8_t* packet) { - uint16_t dataOffset = 0; PoolReadGuard pg0(&coreHk); PoolReadGuard pg1(&auxHk); if (pg0.getReadResult() != HasReturnvaluesIF::RETURN_OK or @@ -468,92 +478,51 @@ ReturnValue_t GomspaceDeviceHandler::parsePduHkTable(PDU::PduCoreHk& coreHk, PDU } /* Fist 10 bytes contain the gomspace header. Each variable is preceded by the 16-bit table * address. */ - dataOffset += 12; + //dataOffset += 12; for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) { - coreHk.currents[idx] = (packet[dataOffset] << 8) | packet[dataOffset + 1]; - dataOffset += 4; + coreHk.currents[idx] = as(packet + (idx * 2)); } for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) { - coreHk.voltages[idx] = (packet[dataOffset] << 8) | packet[dataOffset + 1]; - dataOffset += 4; + coreHk.voltages[idx] = as(packet + 0x12 + (idx*2)); } - - auxHk.vcc = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); - dataOffset += 4; - auxHk.vbat = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); - dataOffset += 4; - coreHk.temperature = - static_cast(*(packet + dataOffset) << 8 | *(packet + dataOffset + 1)) * 0.1; - dataOffset += 4; + auxHk.vcc.value = as(packet + 0x24); + auxHk.vbat.value = as(packet + 0x26); + coreHk.temperature = as(packet + 0x28) * 0.1; for (uint8_t idx = 0; idx < 3; idx++) { - auxHk.converterEnable[idx] = packet[dataOffset]; - dataOffset += 3; + auxHk.converterEnable[idx] = packet[0x2a + idx]; } for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) { - coreHk.outputEnables[idx] = packet[dataOffset]; - dataOffset += 3; + coreHk.outputEnables[idx] = packet[0x2e + idx]; } - - auxHk.bootcause = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - coreHk.bootcount = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.uptime = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.resetcause = *(packet + dataOffset + 1) << 8 | *(packet + dataOffset); - dataOffset += 4; - coreHk.battMode = *(packet + dataOffset); - /* +10 because here begins the second gomspace csp packet */ - dataOffset += 3 + 10; + auxHk.bootcause = as(packet + 0x38); + coreHk.bootcount = as(packet + 0x3c); + auxHk.uptime = as(packet + 0x40); + auxHk.resetcause = as(packet + 0x44); + coreHk.battMode = *(packet + 0x46); for (uint8_t idx = 0; idx < PDU::CHANNELS_LEN; idx++) { - auxHk.latchups[idx] = *(packet + dataOffset) << 8 | *(packet + dataOffset + 1); - dataOffset += 4; + auxHk.latchups[idx] = as(packet + 0x48 + (idx*2)); } for (uint8_t idx = 0; idx < PDU::DEVICES_NUM; idx++) { - auxHk.deviceTypes[idx] = *(packet + dataOffset); - dataOffset += 3; + auxHk.deviceTypes[idx] = *(packet + 0x5a + idx); } for (uint8_t idx = 0; idx < PDU::DEVICES_NUM; idx++) { - auxHk.devicesStatus[idx] = *(packet + dataOffset); - dataOffset += 3; + auxHk.devicesStatus[idx] = *(packet + 0x62 + idx); } - auxHk.gndWdtReboots = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.i2cWdtReboots = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.canWdtReboots = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.csp1WdtReboots = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.csp2WdtReboots = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.groundWatchdogSecondsLeft = *(packet + dataOffset) << 24 | - *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.i2cWatchdogSecondsLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.canWatchdogSecondsLeft = *(packet + dataOffset) << 24 | *(packet + dataOffset + 1) << 16 | - *(packet + dataOffset + 2) << 8 | *(packet + dataOffset + 3); - dataOffset += 6; - auxHk.csp1WatchdogPingsLeft = *(packet + dataOffset); - dataOffset += 3; - auxHk.csp2WatchdogPingsLeft = *(packet + dataOffset); - + auxHk.gndWdtReboots = as(packet + 0x6c); + auxHk.i2cWdtReboots = as(packet + 0x70); + auxHk.canWdtReboots = as(packet + 0x74); + auxHk.csp1WdtReboots = as(packet + 0x78); + auxHk.csp2WdtReboots = as(packet + 0x78 + 4); + auxHk.groundWatchdogSecondsLeft = as(packet + 0x80); + auxHk.i2cWatchdogSecondsLeft = as(packet + 0x84); + auxHk.canWatchdogSecondsLeft = as(packet + 0x88); + auxHk.csp1WatchdogPingsLeft = *(packet + 0x8c); + auxHk.csp2WatchdogPingsLeft = *(packet + 0x8c + 1); coreHk.setChanged(true); if (not coreHk.isValid()) { coreHk.setValidity(true, true); diff --git a/mission/devices/GomspaceDeviceHandler.h b/mission/devices/GomspaceDeviceHandler.h index 82487ba5..fbacaf07 100644 --- a/mission/devices/GomspaceDeviceHandler.h +++ b/mission/devices/GomspaceDeviceHandler.h @@ -82,7 +82,7 @@ class GomspaceDeviceHandler : public DeviceHandlerBase { * @brief The command to generate a request to receive the full housekeeping table is device * specific. Thus the child has to build this command. */ - virtual ReturnValue_t generateRequestFullTableCmd(uint8_t tableId, uint16_t hkTableSize); + virtual ReturnValue_t generateRequestFullTableCmd(uint8_t tableId, uint16_t tableSize); /** * This command handles printing the HK table to the console. This is useful for debugging @@ -115,6 +115,7 @@ class GomspaceDeviceHandler : public DeviceHandlerBase { LocalDataPoolManager &poolManager, std::array initOutEnb); + template T as(const uint8_t*); static bool validTableId(uint8_t id); private: @@ -160,4 +161,9 @@ class GomspaceDeviceHandler : public DeviceHandlerBase { ReturnValue_t generateResetWatchdogCmd(); }; +template +inline T GomspaceDeviceHandler::as(const uint8_t* ptr) { + return *(reinterpret_cast(ptr)); +} + #endif /* MISSION_DEVICES_GOMSPACEDEVICEHANDLER_H_ */ diff --git a/mission/devices/PDU1Handler.cpp b/mission/devices/PDU1Handler.cpp index 9c2f845c..e2466389 100644 --- a/mission/devices/PDU1Handler.cpp +++ b/mission/devices/PDU1Handler.cpp @@ -2,13 +2,14 @@ #include #include +#include #include "devices/powerSwitcherList.h" PDU1Handler::PDU1Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, FailureIsolationBase *customFdir) : GomspaceDeviceHandler(objectId, comIF, comCookie, customFdir, PDU::MAX_CONFIGTABLE_ADDRESS, - PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE), + PDU::MAX_HKTABLE_ADDRESS, P60PDU_HK_SIZE), coreHk(this), auxHk(this) {} diff --git a/mission/devices/PDU2Handler.cpp b/mission/devices/PDU2Handler.cpp index 073ccb23..2a1580f3 100644 --- a/mission/devices/PDU2Handler.cpp +++ b/mission/devices/PDU2Handler.cpp @@ -2,13 +2,14 @@ #include #include +#include #include "devices/powerSwitcherList.h" PDU2Handler::PDU2Handler(object_id_t objectId, object_id_t comIF, CookieIF *comCookie, FailureIsolationBase *customFdir) : GomspaceDeviceHandler(objectId, comIF, comCookie, customFdir, PDU::MAX_CONFIGTABLE_ADDRESS, - PDU::MAX_HKTABLE_ADDRESS, PDU::HK_TABLE_REPLY_SIZE), + PDU::MAX_HKTABLE_ADDRESS, P60PDU_HK_SIZE), coreHk(this), auxHk(this) {} diff --git a/mission/devices/devicedefinitions/GomspaceDefinitions.h b/mission/devices/devicedefinitions/GomspaceDefinitions.h index 2f171ce9..ae1a2e83 100644 --- a/mission/devices/devicedefinitions/GomspaceDefinitions.h +++ b/mission/devices/devicedefinitions/GomspaceDefinitions.h @@ -12,6 +12,13 @@ namespace GOMSPACE { +enum CspPorts: uint8_t { + CSP_PING = 1, + CSP_REBOOT = 4, + P60_PORT_RPARAM_ENUM = 7, + P60_PORT_GNDWDT_RESET_ENUM = 9 +}; + enum class Pdu { PDU1, PDU2 }; using ChannelSwitchHook = void (*)(Pdu pdu, uint8_t channel, bool on, void* args); @@ -466,6 +473,12 @@ class PduAuxHk : public StaticLocalDataSet<36> { lp_var_t(sid.objectId, P60System::pool::PDU_WDT_CSP_LEFT2, this); }; +//class HkWrapper { +//public: +// HkWrapper(PduCoreHk& coreHk, PduAuxHk& auxHk) { +// +// } +//}; } // namespace PDU namespace PDU1 { diff --git a/thirdparty/gomspace-sw b/thirdparty/gomspace-sw index 6b9db5e6..0b66e23a 160000 --- a/thirdparty/gomspace-sw +++ b/thirdparty/gomspace-sw @@ -1 +1 @@ -Subproject commit 6b9db5e60cadcb9bbe1712f0f1b50aede2cbf7be +Subproject commit 0b66e23a8900e315f01cfc52088adad10bdabf26