From 7f8720706e71e95c672c825795a515a2f28b8d24 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 4 Mar 2021 18:31:10 +0100 Subject: [PATCH 01/42] added etl --- etl | 1 + 1 file changed, 1 insertion(+) create mode 160000 etl diff --git a/etl b/etl new file mode 160000 index 00000000..ae06e641 --- /dev/null +++ b/etl @@ -0,0 +1 @@ +Subproject commit ae06e6417702b770c49289c9e7162cb3f4a5a217 From 699b4a0eb96db746871a5d161c418d7682ece64a Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 29 Mar 2021 14:37:52 +0200 Subject: [PATCH 02/42] ploc handler wip --- mission/devices/PlocHandler.cpp | 213 ++++++++++++++++++++++++++++++++ mission/devices/PlocHandler.h | 77 ++++++++++++ tmtc | 2 +- 3 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 mission/devices/PlocHandler.cpp create mode 100644 mission/devices/PlocHandler.h diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp new file mode 100644 index 00000000..7070b51e --- /dev/null +++ b/mission/devices/PlocHandler.cpp @@ -0,0 +1,213 @@ +#include "PlocHandler.h" + +#include +#include +#include +#include + +PlocHandler::PlocHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), engHkDataset(this) { + if (comCookie == NULL) { + sif::error << "PlocHandler: Invalid com cookie" << std::endl; + } +} + +PlocHandler::~PlocHandler() { +} + + +void PlocHandler::doStartUp(){ + if(mode == _MODE_START_UP){ + setMode(MODE_ON); + } +} + +void PlocHandler::doShutDown(){ + +} + +ReturnValue_t PlocHandler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + *id = IMTQ::GET_ENG_HK_DATA; + return buildCommandFromCommand(*id, NULL, 0); +} + +ReturnValue_t PlocHandler::buildTransitionDeviceCommand( + DeviceCommandId_t * id){ + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t PlocHandler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(IMTQ::GET_ENG_HK_DATA): { + commandBuffer[0] = IMTQ::CC::GET_ENG_HK_DATA; + rawPacket = commandBuffer; + return RETURN_OK; + } + case(IMTQ::START_ACTUATION_DIPOLE): { + /* IMTQ expects low byte first */ + commandBuffer[0] = IMTQ::CC::START_ACTUATION_DIPOLE; + commandBuffer[1] = *(commandData + 1); + commandBuffer[2] = *(commandData); + commandBuffer[3] = *(commandData + 3); + commandBuffer[4] = *(commandData + 2); + commandBuffer[5] = *(commandData + 5); + commandBuffer[6] = *(commandData + 4); + commandBuffer[7] = *(commandData + 7); + commandBuffer[8] = *(commandData + 6); + rawPacket = commandBuffer; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void PlocHandler::fillCommandAndReplyMap() { + this->insertInCommandAndReplyMap(IMTQ::GET_ENG_HK_DATA, 1, &engHkDataset, + IMTQ::SIZE_ENG_HK_DATA_REPLY, false, true, IMTQ::SIZE_ENG_HK_DATA_REPLY); +} + +ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + + ReturnValue_t result = RETURN_OK; + + switch(*start) { + case(IMTQ::CC::GET_ENG_HK_DATA): + *foundLen = IMTQ::SIZE_ENG_HK_DATA_REPLY; + *foundId = IMTQ::GET_ENG_HK_DATA; + break; + default: + sif::debug << "PlocHandler::scanForReply: Reply contains invalid command code" << std::endl; + result = IGNORE_REPLY_DATA; + break; + } + + return result; +} + +ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + + ReturnValue_t result = RETURN_OK; + + result = parseStatusByte(packet); + + if (result != RETURN_OK) { + return result; + } + + switch (id) { + case (IMTQ::GET_ENG_HK_DATA): + fillEngHkDataset(packet); + break; + default: { + sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + } + + return RETURN_OK; +} + +ReturnValue_t PlocHandler::parseStatusByte(const uint8_t* packet) { + uint8_t cmdErrorField = *(packet + 1) & 0xF; + switch (cmdErrorField) { + case 0: + return RETURN_OK; + case 1: + return REJECTED_WITHOUT_REASON; + case 2: + return INVALID_COMMAND_CODE; + case 3: + return PARAMETER_MISSING; + case 4: + return PARAMETER_INVALID; + case 5: + return CC_UNAVAILABLE; + case 7: + return INTERNAL_PROCESSING_ERROR; + default: + sif::error << "PlocHandler::parseStatusByte: CMD Error field contains unknown error code " + << cmdErrorField << std::endl; + return CMD_ERR_UNKNOWN; + } +} + +void PlocHandler::fillEngHkDataset(const uint8_t* packet) { + uint8_t offset = 2; + engHkDataset.digitalVoltageMv = *(packet + offset + 1) | *(packet + offset); + offset += 2; + engHkDataset.analogVoltageMv = *(packet + offset + 1) | *(packet + offset); + offset += 2; + engHkDataset.digitalCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + offset += 2; + engHkDataset.analogCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + offset += 2; + engHkDataset.coilXcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + offset += 2; + engHkDataset.coilYcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + offset += 2; + engHkDataset.coilZcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + offset += 2; + engHkDataset.coilXTemperature = (*(packet + offset + 1) | *(packet + offset)); + offset += 2; + engHkDataset.coilYTemperature = (*(packet + offset + 1) | *(packet + offset)); + offset += 2; + engHkDataset.coilZTemperature = (*(packet + offset + 1) | *(packet + offset)); + offset += 2; + engHkDataset.mcuTemperature = (*(packet + offset + 1) | *(packet + offset)); + +#if OBSW_VERBOSE_LEVEL >= 1 && IMTQ_DEBUG == 1 + sif::info << "IMTQ digital voltage: " << engHkDataset.digitalVoltageMv << " mV" << std::endl; + sif::info << "IMTQ analog voltage: " << engHkDataset.analogVoltageMv << " mV" << std::endl; + sif::info << "IMTQ digital current: " << engHkDataset.digitalCurrentA << " A" << std::endl; + sif::info << "IMTQ analog current: " << engHkDataset.analogCurrentA << " A" << std::endl; + sif::info << "IMTQ coil X current: " << engHkDataset.coilXcurrentA << " A" << std::endl; + sif::info << "IMTQ coil Y current: " << engHkDataset.coilYcurrentA << " A" << std::endl; + sif::info << "IMTQ coil Z current: " << engHkDataset.coilZcurrentA << " A" << std::endl; + sif::info << "IMTQ coil X temperature: " << engHkDataset.coilXTemperature << " °C" + << std::endl; + sif::info << "IMTQ coil Y temperature: " << engHkDataset.coilYTemperature << " °C" + << std::endl; + sif::info << "IMTQ coil Z temperature: " << engHkDataset.coilZTemperature << " °C" + << std::endl; + sif::info << "IMTQ coil MCU temperature: " << engHkDataset.mcuTemperature << " °C" + << std::endl; +#endif +} + +void PlocHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t PlocHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 500; +} + +ReturnValue_t PlocHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + + localDataPoolMap.emplace(IMTQ::DIGITAL_VOLTAGE_MV, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ANALOG_VOLTAGE_MV, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_X_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Y_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Z_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MCU_TEMPERATURE, new PoolEntry( { 0 })); + + return HasReturnvaluesIF::RETURN_OK; +} + +void PlocHandler::setModeNormal() { + mode = MODE_NORMAL; +} + diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h new file mode 100644 index 00000000..2505f224 --- /dev/null +++ b/mission/devices/PlocHandler.h @@ -0,0 +1,77 @@ +#ifndef MISSION_DEVICES_PLOCHANDLER_H_ +#define MISSION_DEVICES_PLOCHANDLER_H_ + +#include +#include +#include + +/** + * @brief This is the device handler for the ISIS Magnetorquer iMTQ. + * + * @author J. Meier + */ +class PlocHandler: public DeviceHandlerBase { +public: + + PlocHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie); + virtual ~PlocHandler(); + + /** + * @brief Sets mode to MODE_NORMAL. Can be used for debugging. + */ + void setModeNormal(); + +protected: + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override; + void fillCommandAndReplyMap() override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData,size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void setNormalDatapoolEntriesInvalid() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + +private: + + static const uint8_t INTERFACE_ID = CLASS_ID::IMTQ_HANDLER; + + static const ReturnValue_t INVALID_COMMAND_CODE = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t PARAMETER_MISSING = MAKE_RETURN_CODE(0xA1); + static const ReturnValue_t PARAMETER_INVALID = MAKE_RETURN_CODE(0xA2); + static const ReturnValue_t CC_UNAVAILABLE = MAKE_RETURN_CODE(0xA3); + static const ReturnValue_t INTERNAL_PROCESSING_ERROR = MAKE_RETURN_CODE(0xA4); + static const ReturnValue_t REJECTED_WITHOUT_REASON = MAKE_RETURN_CODE(0xA5); + static const ReturnValue_t CMD_ERR_UNKNOWN = MAKE_RETURN_CODE(0xA6); + + + IMTQ::EngHkDataset engHkDataset; + + uint8_t commandBuffer[IMTQ::MAX_COMMAND_SIZE]; + + /** + * @brief Each reply contains a status byte giving information about a request. This function + * parses this byte and returns the associated failure message. + * + * @param packet Pointer to the received message containing the status byte. + * + * @return The return code derived from the received status byte. + */ + ReturnValue_t parseStatusByte(const uint8_t* packet); + + /** + * @brief This function fills the engineering housekeeping dataset with the received data. + + * @param packet Pointer to the received data. + * + */ + void fillEngHkDataset(const uint8_t* packet); +}; + +#endif /* MISSION_DEVICES_PLOCHANDLER_H_ */ diff --git a/tmtc b/tmtc index 80ee4208..f40b70f6 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 80ee42089e5baadd60479178417299a8c660c80a +Subproject commit f40b70f66eba176d3c36533a779e4e0ed13ae701 From 400f60c7be3987a2369a79d412a2038e6691168f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 11 Apr 2021 12:04:13 +0200 Subject: [PATCH 03/42] plocHandler wip --- README.md | 2 +- bsp_q7s/ObjectFactory.cpp | 16 ++ fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/objects/systemObjectList.h | 1 + .../pollingSequenceFactory.cpp | 5 + fsfwconfig/returnvalues/classIds.h | 1 + mission/devices/CMakeLists.txt | 1 + mission/devices/PlocHandler.cpp | 262 +++++++++++------- mission/devices/PlocHandler.h | 71 +++-- .../devicedefinitions/PlocDefinitions.h | 131 +++++++++ tmtc | 2 +- 11 files changed, 365 insertions(+), 129 deletions(-) create mode 100644 mission/devices/devicedefinitions/PlocDefinitions.h diff --git a/README.md b/README.md index f0c749be..dafbfbba 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ Copying a file from Q7S to flatsat PC scp -P 22 root@192.168.133.10:/tmp/kernel-config /tmp ```` -From a windows machine files can be copied with putty tools +From a windows machine files can be copied with putty tools (note: use IPv4 address) ```` pscp -scp -P 22 eive@192.168.199.227:/example-file ```` diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6cd3ec64..85d82a48 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -21,10 +21,12 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -327,6 +329,13 @@ void ObjectFactory::produce(){ IMTQHandler* imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie); imtqHandler->setStartUpImmediately(); + UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, + PLOC::MAX_REPLY_SIZE); + /* Testing PlocHandler on TE0720-03-1CFA */ + PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, + plocUartCookie); + plocHandler->setStartUpImmediately(); + #endif new TmTcUnixUdpBridge(objects::UDP_BRIDGE, @@ -348,5 +357,12 @@ void ObjectFactory::produce(){ heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, objects::PCDU_HANDLER, pcduSwitches::TCS_BOARD_8V_HEATER_IN); + + UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, + PLOC::MAX_REPLY_SIZE); + /* Testing PlocHandler on TE0720-03-1CFA */ + PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, + plocUartCookie); + plocHandler->setStartUpImmediately(); #endif } diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 73c05edb..3f5ebfca 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -19,7 +19,7 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 0 +#define TE0720 1 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index c0c78a62..352c4ddc 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -52,6 +52,7 @@ namespace objects { GYRO_2_L3G_HANDLER = 0x44000013, IMTQ_HANDLER = 0x44000014, + PLOC_HANDLER = 0x44000015, /* Custom device handler */ PCDU_HANDLER = 0x44001000, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 43435cf3..86e3629e 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -36,6 +36,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC17, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::RTD_IC18, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0.2, DeviceHandlerIF::SEND_WRITE); @@ -56,6 +57,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC17, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::RTD_IC18, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0.4, DeviceHandlerIF::GET_WRITE); @@ -76,6 +78,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC17, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::RTD_IC18, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0.6, DeviceHandlerIF::SEND_READ); @@ -96,6 +99,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC17, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::RTD_IC18, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0.8, DeviceHandlerIF::GET_READ); @@ -116,6 +120,7 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC17, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::RTD_IC18, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; diff --git a/fsfwconfig/returnvalues/classIds.h b/fsfwconfig/returnvalues/classIds.h index 93349596..22bb0457 100644 --- a/fsfwconfig/returnvalues/classIds.h +++ b/fsfwconfig/returnvalues/classIds.h @@ -20,6 +20,7 @@ enum { SA_DEPL_HANDLER, SYRLINKS_HANDLER, IMTQ_HANDLER, + PLOC_HANDLER }; } diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 6e8518b0..7d34aac9 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources(${TARGET_NAME} PUBLIC SyrlinksHkHandler.cpp Max31865PT1000Handler.cpp IMTQHandler.cpp + PlocHandler.cpp ) diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index 7070b51e..b88dde90 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -6,7 +6,7 @@ #include PlocHandler::PlocHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), engHkDataset(this) { + DeviceHandlerBase(objectId, comIF, comCookie) { if (comCookie == NULL) { sif::error << "PlocHandler: Invalid com cookie" << std::endl; } @@ -28,8 +28,7 @@ void PlocHandler::doShutDown(){ ReturnValue_t PlocHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - *id = IMTQ::GET_ENG_HK_DATA; - return buildCommandFromCommand(*id, NULL, 0); + return RETURN_OK; } ReturnValue_t PlocHandler::buildTransitionDeviceCommand( @@ -41,34 +40,37 @@ ReturnValue_t PlocHandler::buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t * commandData, size_t commandDataLen) { switch(deviceCommand) { - case(IMTQ::GET_ENG_HK_DATA): { - commandBuffer[0] = IMTQ::CC::GET_ENG_HK_DATA; - rawPacket = commandBuffer; + case(PLOC::TC_MEM_WRITE): { + const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 + | *(commandData + 2) << 8 | *(commandData + 3); + const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 + | *(commandData + 6) << 8 | *(commandData + 7); + PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData); + rawPacket = tcMemWrite.getWholeData(); + rawPacketLen = tcMemWrite.getFullSize(); + rememberCommandId = PLOC::TC_MEM_WRITE; return RETURN_OK; } - case(IMTQ::START_ACTUATION_DIPOLE): { - /* IMTQ expects low byte first */ - commandBuffer[0] = IMTQ::CC::START_ACTUATION_DIPOLE; - commandBuffer[1] = *(commandData + 1); - commandBuffer[2] = *(commandData); - commandBuffer[3] = *(commandData + 3); - commandBuffer[4] = *(commandData + 2); - commandBuffer[5] = *(commandData + 5); - commandBuffer[6] = *(commandData + 4); - commandBuffer[7] = *(commandData + 7); - commandBuffer[8] = *(commandData + 6); - rawPacket = commandBuffer; + case(PLOC::TC_MEM_READ): { + const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 + | *(commandData + 2) << 8 | *(commandData + 3); + PLOC::TcMemRead tcMemRead(memoryAddress); + rawPacket = tcMemRead.getWholeData(); + rawPacketLen = tcMemRead.getFullSize(); + rememberCommandId = PLOC::TC_MEM_READ; return RETURN_OK; } default: + sif::debug << "PlocHandler::buildCommandFromCommand: Command not implemented" << std::endl; return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } return HasReturnvaluesIF::RETURN_FAILED; } void PlocHandler::fillCommandAndReplyMap() { - this->insertInCommandAndReplyMap(IMTQ::GET_ENG_HK_DATA, 1, &engHkDataset, - IMTQ::SIZE_ENG_HK_DATA_REPLY, false, true, IMTQ::SIZE_ENG_HK_DATA_REPLY); + this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_ACK_REPORT); + this->insertInReplyMap(PLOC::ACK_SUCCESS, 1); + this->insertInReplyMap(PLOC::ACK_FAILURE, 1); } ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, @@ -76,34 +78,51 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, ReturnValue_t result = RETURN_OK; - switch(*start) { - case(IMTQ::CC::GET_ENG_HK_DATA): - *foundLen = IMTQ::SIZE_ENG_HK_DATA_REPLY; - *foundId = IMTQ::GET_ENG_HK_DATA; + *foundId = *(start) << 8 | *(start + 1) & APID_MASK; + + switch(*foundId) { + case(PLOC::ACK_SUCCESS): + *foundLen = PLOC::SIZE_ACK_REPORT; + break; + case(PLOC::ACK_FAILURE): + *foundLen = PLOC::SIZE_ACK_REPORT; break; default: - sif::debug << "PlocHandler::scanForReply: Reply contains invalid command code" << std::endl; + sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl; result = IGNORE_REPLY_DATA; break; } + result = verifyPacket(start, foundLen); + return result; } +ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t* foundLen) { + + uint16_t receivedCrc = *(start + *foundLen - 2) << 8 | *(start + *foundlen - 1); + + if (receivedCrc != CRC::crc16ccitt(start, *foundLen, 0)) { + return CRC_FAILURE; + } + + return RETURN_OK; +} + ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { ReturnValue_t result = RETURN_OK; - result = parseStatusByte(packet); - - if (result != RETURN_OK) { - return result; - } - switch (id) { - case (IMTQ::GET_ENG_HK_DATA): - fillEngHkDataset(packet); + case (PLOC::ACK_SUCCESS): + receiveTm(); + receiveExecutionReport(); + break; + case (PLOC::ACK_FAILURE): + //TODO: Interpretation of status field in ack reply. + sif::error << "PlocHandler::interpretDeviceReply: Received ack failure reply" << std::endl; + triggerEvent(ACK_FAILURE, rememberCommandId); break; default: { sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; @@ -114,71 +133,116 @@ ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, return RETURN_OK; } -ReturnValue_t PlocHandler::parseStatusByte(const uint8_t* packet) { - uint8_t cmdErrorField = *(packet + 1) & 0xF; - switch (cmdErrorField) { - case 0: - return RETURN_OK; - case 1: - return REJECTED_WITHOUT_REASON; - case 2: - return INVALID_COMMAND_CODE; - case 3: - return PARAMETER_MISSING; - case 4: - return PARAMETER_INVALID; - case 5: - return CC_UNAVAILABLE; - case 7: - return INTERNAL_PROCESSING_ERROR; +ReturnValue_t PlocHandler::receiveTm() { + switch (rememberCommandId) { + case (PLOC::TC_MEM_WRITE): + break; + case (PLOC::TC_MEM_READ): + receiveTmMemoryReadReport(); + break; default: - sif::error << "PlocHandler::parseStatusByte: CMD Error field contains unknown error code " - << cmdErrorField << std::endl; - return CMD_ERR_UNKNOWN; + sif::debug << "PlocHandler::receiveTm: Rembered unknown command id" << std::endl; + break; } } -void PlocHandler::fillEngHkDataset(const uint8_t* packet) { - uint8_t offset = 2; - engHkDataset.digitalVoltageMv = *(packet + offset + 1) | *(packet + offset); - offset += 2; - engHkDataset.analogVoltageMv = *(packet + offset + 1) | *(packet + offset); - offset += 2; - engHkDataset.digitalCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; - offset += 2; - engHkDataset.analogCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; - offset += 2; - engHkDataset.coilXcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; - offset += 2; - engHkDataset.coilYcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; - offset += 2; - engHkDataset.coilZcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; - offset += 2; - engHkDataset.coilXTemperature = (*(packet + offset + 1) | *(packet + offset)); - offset += 2; - engHkDataset.coilYTemperature = (*(packet + offset + 1) | *(packet + offset)); - offset += 2; - engHkDataset.coilZTemperature = (*(packet + offset + 1) | *(packet + offset)); - offset += 2; - engHkDataset.mcuTemperature = (*(packet + offset + 1) | *(packet + offset)); +void PlocHandler::receiveExecutionReport() { -#if OBSW_VERBOSE_LEVEL >= 1 && IMTQ_DEBUG == 1 - sif::info << "IMTQ digital voltage: " << engHkDataset.digitalVoltageMv << " mV" << std::endl; - sif::info << "IMTQ analog voltage: " << engHkDataset.analogVoltageMv << " mV" << std::endl; - sif::info << "IMTQ digital current: " << engHkDataset.digitalCurrentA << " A" << std::endl; - sif::info << "IMTQ analog current: " << engHkDataset.analogCurrentA << " A" << std::endl; - sif::info << "IMTQ coil X current: " << engHkDataset.coilXcurrentA << " A" << std::endl; - sif::info << "IMTQ coil Y current: " << engHkDataset.coilYcurrentA << " A" << std::endl; - sif::info << "IMTQ coil Z current: " << engHkDataset.coilZcurrentA << " A" << std::endl; - sif::info << "IMTQ coil X temperature: " << engHkDataset.coilXTemperature << " °C" - << std::endl; - sif::info << "IMTQ coil Y temperature: " << engHkDataset.coilYTemperature << " °C" - << std::endl; - sif::info << "IMTQ coil Z temperature: " << engHkDataset.coilZTemperature << " °C" - << std::endl; - sif::info << "IMTQ coil MCU temperature: " << engHkDataset.mcuTemperature << " °C" - << std::endl; -#endif + size_t receivedDataLen = 0; + uint8_t *receivedData = nullptr; + + communicationInterface->requestReceiveMessage(comCookie, PLOC::SIZE_EXE_REPORT); + communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); + + if(!verifyPacket(receivedData, receivedDataLen)) { + replyRawData(data, len, defaultRawReceiver); + triggerEvent(EXE_RPT_INVALID_CRC); + sif::error << "PlocHandler::receiveExecutionReport: Execution report has invalid crc" + << std::endl; + return; + } + + handleExecutionReport(receivedData, receivedDataLen); +} + +void PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { + + uint16_t apid = *(start) << 8 | *(start + 1) & APID_MASK; + + switch (apid) { + case (PLOC::APID_EXE_SUCCESS): { + return; + } + case (PLOC::APID_EXE_FAILURE): { + //TODO: Interpretation of status field in execution report + sif::error << "PlocHandler::handleExecutionReport: Received execution failure report" + << std::endl; + triggerEvent(EXE_FAILURE, rememberCommandId); + return; + } + } + return; +} + +void PlocHandler::receiveTmMemoryReadReport() { + + size_t receivedDataLen = 0; + uint8_t *receivedData = nullptr; + + /* Receiving the telemetry packet */ + ReturnValue_t result = communicationInterface->requestReceiveMessage(comCookie, + PLOC::SIZE_TM_MEM_READ_REPORT); + if (result != RETURN_OK) { + sif::error << "PlocHandler::receiveExecutionReport: Failed to request memory read telemetry " + << std::endl; + triggerEvent(REQUESTING_TM_READ_REPORT_FAILED, result); + return; + } + result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); + if (result != RETURN_OK) { + sif::error << "PlocHandler::receiveExecutionReport: Failed to request memory read telemetry " + << std::endl; + return; + } + + uint16_t apid = *(start) << 8 | *(start + 1) & APID_MASK; + if (apid != PLOC::APID_TM_READ_REPORT) { + sif::error << "PlocHandler::receiveTmReadReport: Tm read report has invalid apid" + << std::endl; + return; + } + + if(!verifyPacket(receivedData, receivedDataLen)) { + replyRawData(data, len, defaultRawReceiver); + triggerEvent(TM_READ_RPT_INVALID_CRC); + sif::error << "PlocHandler::receiveTmReadReport: TM read report has invalid crc" + << std::endl; + return; + } + + handleDeviceTM(receivedData, receivedDataLen, PLOC::TC_MEM_READ); + +} + +void PlocHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId) { + + ReturnValue_t result = RETURN_OK; + + DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId); + if (iter == deviceReplyMap.end()) { + sif::debug << "PlocHandler::handleDeviceTM: Unknown reply id" << std::endl; + return; + } + MessageQueueId_t queueId = iter->second.command->second.sendReplyTo; + + if (queueId == NO_COMMANDER) { + return; + } + + result = actionHelper.reportData(queueId, replyId, dataSet); + if (result != RETURN_OK) { + sif::debug << "PlocHandler::handleDeviceTM: Failed to report data" << std::endl; + } } void PlocHandler::setNormalDatapoolEntriesInvalid(){ @@ -192,18 +256,6 @@ uint32_t PlocHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ ReturnValue_t PlocHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(IMTQ::DIGITAL_VOLTAGE_MV, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::ANALOG_VOLTAGE_MV, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_X_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Y_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Z_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::MCU_TEMPERATURE, new PoolEntry( { 0 })); - return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 2505f224..86e2e2dd 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -2,7 +2,7 @@ #define MISSION_DEVICES_PLOCHANDLER_H_ #include -#include +#include #include /** @@ -40,38 +40,67 @@ protected: private: - static const uint8_t INTERFACE_ID = CLASS_ID::IMTQ_HANDLER; + static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_HANDLER; - static const ReturnValue_t INVALID_COMMAND_CODE = MAKE_RETURN_CODE(0xA0); - static const ReturnValue_t PARAMETER_MISSING = MAKE_RETURN_CODE(0xA1); - static const ReturnValue_t PARAMETER_INVALID = MAKE_RETURN_CODE(0xA2); - static const ReturnValue_t CC_UNAVAILABLE = MAKE_RETURN_CODE(0xA3); - static const ReturnValue_t INTERNAL_PROCESSING_ERROR = MAKE_RETURN_CODE(0xA4); - static const ReturnValue_t REJECTED_WITHOUT_REASON = MAKE_RETURN_CODE(0xA5); - static const ReturnValue_t CMD_ERR_UNKNOWN = MAKE_RETURN_CODE(0xA6); + static const ReturnValue_t TC_ACK_FAILURE = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA1); + static const Event REQUESTING_TM_READ_REPORT_FAILED = MAKE_EVENT(0, severity::LOW); + static const Event TM_READ_RPT_INVALID_CRC = MAKE_EVENT(1, severity::LOW); + static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); + static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW); + static const Event EXE_RPT_INVALID_CRC = MAKE_EVENT(4, severity::LOW); - IMTQ::EngHkDataset engHkDataset; + static const uint16_t APID_MASK = 0x7FF; - uint8_t commandBuffer[IMTQ::MAX_COMMAND_SIZE]; + DeviceCommandId_t rememberCommandId = PLOC::NONE; + + /** + * @brief This function checks wheter a telemetry packet is expected or not. + */ + ReturnValue_t receiveTm(); /** - * @brief Each reply contains a status byte giving information about a request. This function - * parses this byte and returns the associated failure message. + * @brief This function checks the crc of the received PLOC reply. * - * @param packet Pointer to the received message containing the status byte. + * @param start Pointer to the first byte of the reply. + * @param foundLen Pointer to the length of the whole packet. * - * @return The return code derived from the received status byte. + * @return RETURN_OK if CRC is ok, otherwise CRC_FAILURE. */ - ReturnValue_t parseStatusByte(const uint8_t* packet); + ReturnValue_t verifyPacket(const uint8_t* start, size_t* foundLen); /** - * @brief This function fills the engineering housekeeping dataset with the received data. - - * @param packet Pointer to the received data. - * + * @brief This function reads and handles the execution reply. */ - void fillEngHkDataset(const uint8_t* packet); + void receiveExecutionReport(); + + /** + * @brief This function handles the data of a execution report. + * + * @param receivedData Pointer to the received data + * @param receivedDataLen Size in bytes of the received data + */ + void handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen); + + /** + * @brief This function reads and handles the memory read report telemetry packet received + * after requesting the packet with the TC_MEM_READ command. + * + * @details In case of a valid packet the received memory content will be forwarded to the + * commanding object via an action message. + */ + void receiveTmMemoryReadReport(); + + /** + * @brief This function handles action message replies in case the telemetry has been + * requested by another object. + * + * @param data Pointer to the telemtry data. + * @param dataSize Size of telemetry in bytes. + * @param replyId Id of the reply. This will be added to the ActionMessage. + */ + void handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId); }; #endif /* MISSION_DEVICES_PLOCHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h new file mode 100644 index 00000000..d468d0dd --- /dev/null +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -0,0 +1,131 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCDEFINITIONS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCDEFINITIONS_H_ + +#include +#include + +namespace PLOC { + + static const DeviceCommandId_t NONE = 0x0; + static const DeviceCommandId_t TC_MEM_WRITE = 0x714; + static const DeviceCommandId_t TC_MEM_READ = 0x715; + static const DeviceCommandId_t ACK_SUCCESS = 0x400; + static const DeviceCommandId_t ACK_FAILURE = 0x401; + static const DeviceCommandId_t TM_READ_REPORT = 0x404; + + static const uint16_t SIZE_ACK_REPORT = 14; + static const uint16_t SIZE_EXE_REPORT = 14; + static const uint16_t SIZE_TM_MEM_READ_REPORT = 18; + + /** + * SpacePacket apids of PLOC telecommands and telemetry. + */ + static const uint16_t APID_TC_MEM_WRITE = 0x714; + static const uint16_t APID_TM_READ_REPORT = 0x404; + static const uint16_t APID_EXE_SUCCESS = 0x402; + static const uint16_t APID_EXE_FAILURE = 0x403; + + /** + * PLOC space packet length for fixed size packets. This is the size of the whole packet data + * field. For the length field in the space packet this size will be substracted by one. + */ + static const uint16_t LENGTH_TC_MEM_WRITE = 12; + static const uint16_t LENGTH_TC_MEM_READ = 8; + + static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT; + + /** + * @brief This class helps to build the memory read command for the PLOC. + * + * @details The last two bytes of the packet data field contain a CRC calculated over the whole + * space packet. This is the CRC-16-CCITT as specified in + * ECSS-E-ST-70-41C – Telemetry and telecommand packet utilization. + */ + class TcMemRead : public SpacePacket { + public: + /** + * @brief Constructor + * + * @param memAddr The memory address to read from. + */ + TcMemRead(const uint32_t memAddr) : + SpacePacket(LENGTH_TC_MEM_READ - 1, true, APID_TC_MEM_READ) { + fillPacketDataField(&memAddr); + } + + private: + + /** + * @brief This function builds the packet data field for the mem read command. + * + * @param memAddrPtr Pointer to the memory address to read from. + */ + void fillPacketDataField(const uint32_t* memAddrPtr) { + /* Add memAddr to packet data field */ + memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(memAddrPtr)); + /* Add memLen to packet data field */ + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, + sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE, 0); + /* Add crc to packet data field of space packet */ + memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); + } + + static const uint8_t CRC_OFFSET = 12; + static const uint8_t OFFSET_MEM_LEN_FIELD = 10; + + }; + + /** + * @brief This class helps to generate the space packet to write to a memory address within + * the PLOC. + * @details The last two bytes of the packet data field contain a CRC calculated over the whole + * space packet. This is the CRC-16-CCITT as specified in + * ECSS-E-ST-70-41C – Telemetry and telecommand packet utilization. + */ + class TcMemWrite : public SpacePacket { + public: + /** + * @brief Constructor + * + * @param memAddr The PLOC memory address where to write to. + * @param memoryData The data to write to the specified memory address. + */ + TcMemWrite(const uint32_t memAddr, const uint32_t memoryData) : + SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, APID_TC_MEM_WRITE) { + fillPacketDataField(&memAddr, &memoryData); + } + + private: + + /** + * @brief This function builds the packet data field for the mem write command. + * + * @param memAddrPtr Pointer to the PLOC memory address where to write to. + * @param memoryDataPtr Pointer to the memoryData to write + */ + void fillPacketDataField(const uint32_t* memAddrPtr, const uint32_t* memoryDataPtr) { + /* Add memAddr to packet data field */ + memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(memAddrPtr)); + /* Add memLen to packet data field */ + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + /* Add memData to packet data field */ + memcpy(this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD, memAddrPtr, + sizeof(memAddrPtr)); + uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, + sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE, 0); + /* Add crc to packet data field of space packet */ + memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); + } + + static const uint8_t OFFSET_MEM_LEN_FIELD = 10; + static const uint8_t OFFSET_MEM_DATA_FIELD = 12; + static const uint8_t CRC_OFFSET = 16; + }; + +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCDEFINITIONS_H_ */ diff --git a/tmtc b/tmtc index f40b70f6..73105138 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit f40b70f66eba176d3c36533a779e4e0ed13ae701 +Subproject commit 73105138050b5661a6cff76e1d64af40981f9c7f From 5d4c2bd5213c5965f21dc3d12d0be3b1a6b14efb Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 12 Apr 2021 10:16:59 +0200 Subject: [PATCH 04/42] plocHandler wip --- README.md | 8 ++++++- bsp_q7s/ObjectFactory.cpp | 5 ++-- fsfw_hal | 1 + fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/events/subsystemIdRanges.h | 3 ++- mission/devices/PlocHandler.cpp | 23 +++++++++---------- mission/devices/PlocHandler.h | 4 +++- .../IMTQHandlerDefinitions.h | 2 +- .../devicedefinitions/PlocDefinitions.h | 7 +++--- 9 files changed, 32 insertions(+), 23 deletions(-) create mode 160000 fsfw_hal diff --git a/README.md b/README.md index dafbfbba..73845e41 100644 --- a/README.md +++ b/README.md @@ -573,4 +573,10 @@ to install the required GPIO libraries before cloning the system root folder. When using Eclipse, there are two special build variables in the project properties → C/C++ Build → Build Variables called `Q7S_SYSROOT` or `RPI_SYSROOT`. You can set the sysroot path in those variables to get any additional includes like `gpiod.h` in the -Eclipse indexer. \ No newline at end of file +Eclipse indexer. + +## Xilinx UARTLIE +Get info about ttyUL* devices +```` +cat /proc/tty/driver +```` \ No newline at end of file diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 85d82a48..fe852662 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -321,7 +321,7 @@ void ObjectFactory::produce(){ Max31865PT1000Handler* rtdIc16 = new Max31865PT1000Handler(objects::RTD_IC16, objects::SPI_COM_IF, spiRtdIc16, 0); Max31865PT1000Handler* rtdIc17 = new Max31865PT1000Handler(objects::RTD_IC17, objects::SPI_COM_IF, spiRtdIc17, 0); Max31865PT1000Handler* rtdIc18 = new Max31865PT1000Handler(objects::RTD_IC18, objects::SPI_COM_IF, spiRtdIc18, 0); - rtdIc10->setStartUpImmediately(); +// rtdIc10->setStartUpImmediately(); // rtdIc4->setStartUpImmediately(); I2cCookie* imtqI2cCookie = new I2cCookie(addresses::IMTQ, IMTQ::MAX_REPLY_SIZE, @@ -329,9 +329,8 @@ void ObjectFactory::produce(){ IMTQHandler* imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie); imtqHandler->setStartUpImmediately(); - UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, + UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyUL3"), 115200, PLOC::MAX_REPLY_SIZE); - /* Testing PlocHandler on TE0720-03-1CFA */ PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, plocUartCookie); plocHandler->setStartUpImmediately(); diff --git a/fsfw_hal b/fsfw_hal new file mode 160000 index 00000000..14fe3257 --- /dev/null +++ b/fsfw_hal @@ -0,0 +1 @@ +Subproject commit 14fe32572d62db9d19707dc1f9bb6fecb1993b73 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 3f5ebfca..73c05edb 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -19,7 +19,7 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 1 +#define TE0720 0 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/fsfwconfig/events/subsystemIdRanges.h b/fsfwconfig/events/subsystemIdRanges.h index b2e9aaac..b33ee807 100644 --- a/fsfwconfig/events/subsystemIdRanges.h +++ b/fsfwconfig/events/subsystemIdRanges.h @@ -21,7 +21,8 @@ enum: uint8_t { MGM_RM3100, PCDU_HANDLER, HEATER_HANDLER, - SA_DEPL_HANDLER + SA_DEPL_HANDLER, + PLOC_HANDLER }; } diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index b88dde90..fca51b71 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -68,6 +68,7 @@ ReturnValue_t PlocHandler::buildCommandFromCommand( } void PlocHandler::fillCommandAndReplyMap() { + this->insertInCommandAndReplyMap(PLOC::TC_MEM_WRITE, 1, nullptr, PLOC::SIZE_ACK_REPORT); this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_ACK_REPORT); this->insertInReplyMap(PLOC::ACK_SUCCESS, 1); this->insertInReplyMap(PLOC::ACK_FAILURE, 1); @@ -78,7 +79,7 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, ReturnValue_t result = RETURN_OK; - *foundId = *(start) << 8 | *(start + 1) & APID_MASK; + *foundId = (*(start) << 8 | *(start + 1)) & APID_MASK; switch(*foundId) { case(PLOC::ACK_SUCCESS): @@ -100,7 +101,7 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t* foundLen) { - uint16_t receivedCrc = *(start + *foundLen - 2) << 8 | *(start + *foundlen - 1); + uint16_t receivedCrc = *(start + *foundLen - 2) << 8 | *(start + *foundLen - 1); if (receivedCrc != CRC::crc16ccitt(start, *foundLen, 0)) { return CRC_FAILURE; @@ -112,8 +113,6 @@ ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t* foundLen) ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { - ReturnValue_t result = RETURN_OK; - switch (id) { case (PLOC::ACK_SUCCESS): receiveTm(); @@ -133,7 +132,7 @@ ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, return RETURN_OK; } -ReturnValue_t PlocHandler::receiveTm() { +void PlocHandler::receiveTm() { switch (rememberCommandId) { case (PLOC::TC_MEM_WRITE): break; @@ -154,8 +153,8 @@ void PlocHandler::receiveExecutionReport() { communicationInterface->requestReceiveMessage(comCookie, PLOC::SIZE_EXE_REPORT); communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); - if(!verifyPacket(receivedData, receivedDataLen)) { - replyRawData(data, len, defaultRawReceiver); + if(!verifyPacket(receivedData, &receivedDataLen)) { + replyRawData(receivedData, receivedDataLen, defaultRawReceiver); triggerEvent(EXE_RPT_INVALID_CRC); sif::error << "PlocHandler::receiveExecutionReport: Execution report has invalid crc" << std::endl; @@ -167,7 +166,7 @@ void PlocHandler::receiveExecutionReport() { void PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { - uint16_t apid = *(start) << 8 | *(start + 1) & APID_MASK; + uint16_t apid = (*(receivedData) << 8 | *(receivedData + 1)) & APID_MASK; switch (apid) { case (PLOC::APID_EXE_SUCCESS): { @@ -205,15 +204,15 @@ void PlocHandler::receiveTmMemoryReadReport() { return; } - uint16_t apid = *(start) << 8 | *(start + 1) & APID_MASK; + uint16_t apid = (*(receivedData) << 8 | *(receivedData + 1)) & APID_MASK; if (apid != PLOC::APID_TM_READ_REPORT) { sif::error << "PlocHandler::receiveTmReadReport: Tm read report has invalid apid" << std::endl; return; } - if(!verifyPacket(receivedData, receivedDataLen)) { - replyRawData(data, len, defaultRawReceiver); + if(!verifyPacket(receivedData, &receivedDataLen)) { + replyRawData(receivedData, receivedDataLen, defaultRawReceiver); triggerEvent(TM_READ_RPT_INVALID_CRC); sif::error << "PlocHandler::receiveTmReadReport: TM read report has invalid crc" << std::endl; @@ -239,7 +238,7 @@ void PlocHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCom return; } - result = actionHelper.reportData(queueId, replyId, dataSet); + result = actionHelper.reportData(queueId, replyId, data, dataSize); if (result != RETURN_OK) { sif::debug << "PlocHandler::handleDeviceTM: Failed to report data" << std::endl; } diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 86e2e2dd..8e3a6aa4 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -45,6 +45,8 @@ private: static const ReturnValue_t TC_ACK_FAILURE = MAKE_RETURN_CODE(0xA0); static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA1); + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER; + static const Event REQUESTING_TM_READ_REPORT_FAILED = MAKE_EVENT(0, severity::LOW); static const Event TM_READ_RPT_INVALID_CRC = MAKE_EVENT(1, severity::LOW); static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); @@ -58,7 +60,7 @@ private: /** * @brief This function checks wheter a telemetry packet is expected or not. */ - ReturnValue_t receiveTm(); + void receiveTm(); /** * @brief This function checks the crc of the received PLOC reply. diff --git a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h index 21ad7dec..23ff8b9a 100644 --- a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h +++ b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h @@ -18,7 +18,7 @@ namespace IMTQ { static const uint8_t MAX_REPLY_SIZE = SIZE_ENG_HK_DATA_REPLY; static const uint8_t MAX_COMMAND_SIZE = 9; - static const uint8_t POOL_ENTRIES = 8; + static const uint8_t POOL_ENTRIES = 11; /** * Command code definitions. Each command or reply of an IMTQ request will begin with one of diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index d468d0dd..dbd157e5 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -21,6 +21,7 @@ namespace PLOC { * SpacePacket apids of PLOC telecommands and telemetry. */ static const uint16_t APID_TC_MEM_WRITE = 0x714; + static const uint16_t APID_TC_MEM_READ = 0x715; static const uint16_t APID_TM_READ_REPORT = 0x404; static const uint16_t APID_EXE_SUCCESS = 0x402; static const uint16_t APID_EXE_FAILURE = 0x403; @@ -62,7 +63,7 @@ namespace PLOC { */ void fillPacketDataField(const uint32_t* memAddrPtr) { /* Add memAddr to packet data field */ - memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(memAddrPtr)); + memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(*memAddrPtr)); /* Add memLen to packet data field */ this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; @@ -107,13 +108,13 @@ namespace PLOC { */ void fillPacketDataField(const uint32_t* memAddrPtr, const uint32_t* memoryDataPtr) { /* Add memAddr to packet data field */ - memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(memAddrPtr)); + memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(*memAddrPtr)); /* Add memLen to packet data field */ this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; /* Add memData to packet data field */ memcpy(this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD, memAddrPtr, - sizeof(memAddrPtr)); + sizeof(*memAddrPtr)); uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE, 0); /* Add crc to packet data field of space packet */ From 0916ca87d970964f0de85f669978a8aed7b3cabe Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 15 Apr 2021 13:17:15 +0200 Subject: [PATCH 05/42] plocHandler wip --- bsp_q7s/InitMission.cpp | 16 +- bsp_q7s/ObjectFactory.cpp | 10 +- bsp_q7s/devices/HeaterHandler.cpp | 5 +- fsfwconfig/OBSWConfig.h | 2 +- .../pollingSequenceFactory.cpp | 24 ++- .../pollingsequence/pollingSequenceFactory.h | 5 + mission/devices/PlocHandler.cpp | 156 +++++++++++------- mission/devices/PlocHandler.h | 32 +++- .../devicedefinitions/PlocDefinitions.h | 53 ++++-- 9 files changed, 214 insertions(+), 89 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index c776ead0..8c512c83 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -135,6 +135,8 @@ void initmission::initTasks() { initmission::printAddObjectError("PUS_17", objects::PUS_SERVICE_17_TEST); } +#if TE0720 == 0 + //TODO: Add handling of missed deadlines /* Polling Sequence Table Default */ FixedTimeslotTaskIF * pollingSequenceTableTaskDefault = factory->createFixedTimeslotTask( @@ -145,7 +147,6 @@ void initmission::initTasks() { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; } -#if TE0720 == 0 FixedTimeslotTaskIF* gomSpacePstTask = factory-> createFixedTimeslotTask("GS_PST_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE*8, 3.0, missedDeadlineFunc); @@ -153,6 +154,15 @@ void initmission::initTasks() { if(result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: GomSpace PST initialization failed!" << std::endl; } + +#else + FixedTimeslotTaskIF * pollingSequenceTableTE0720 = factory->createFixedTimeslotTask( + "PST_TASK_TE0720", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, + missedDeadlineFunc); + result = pst::pollingSequenceTE0720(pollingSequenceTableTE0720); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "InitMission::initTasks: Creating TE0720 PST failed!" << std::endl; + } #endif PeriodicTaskIF* testTask = factory->createPeriodicTask( @@ -177,8 +187,10 @@ void initmission::initTasks() { #if TE0720 == 0 gomSpacePstTask->startTask(); -#endif pollingSequenceTableTaskDefault->startTask(); +#else + pollingSequenceTableTE0720->startTask(); +#endif pusVerification->startTask(); pusEvents->startTask(); diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index fe852662..55373525 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -351,11 +351,11 @@ void ObjectFactory::produce(){ new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); #elif TE0720 == 1 /* Configuration for MIO0 on TE0720-03-1CFA */ - GpiodRegular gpioConfigForDummyHeater(std::string("gpiochip0"), 0, - std::string("Heater0"), gpio::OUT, 0); - heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpioConfigForDummyHeater); - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, - objects::PCDU_HANDLER, pcduSwitches::TCS_BOARD_8V_HEATER_IN); +// GpiodRegular* gpio = new GpiodRegular(std::string("gpiochip0"), 0, std::string("Heater0"), +// gpio::OUT, 0); +// heaterGpiosCookie->addGpio(gpioIds::HEATER_0, gpio); +// new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, heaterGpiosCookie, +// objects::PCDU_HANDLER, pcduSwitches::TCS_BOARD_8V_HEATER_IN); UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, PLOC::MAX_REPLY_SIZE); diff --git a/bsp_q7s/devices/HeaterHandler.cpp b/bsp_q7s/devices/HeaterHandler.cpp index 9a44c57b..3f53af2f 100644 --- a/bsp_q7s/devices/HeaterHandler.cpp +++ b/bsp_q7s/devices/HeaterHandler.cpp @@ -58,8 +58,9 @@ ReturnValue_t HeaterHandler::initialize() { if(mainLineSwitcherObjectId != objects::NO_OBJECT) { mainLineSwitcher = objectManager->get(mainLineSwitcherObjectId); if (mainLineSwitcher == nullptr) { - sif::error << "HeaterHandler::initialize: Main line switcher failed to fetch object" - << "from object ID." << std::endl; + sif::error + << "HeaterHandler::initialize: Failed to get main line switcher. Make sure " + << "main line switcher object is initialized." << std::endl; return ObjectManagerIF::CHILD_INIT_FAILED; } } diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 73c05edb..3f5ebfca 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -19,7 +19,7 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 0 +#define TE0720 1 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 86e3629e..51427e90 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -5,13 +5,13 @@ #include #include #include +#include ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) { /* Length of a communication cycle */ uint32_t length = thisSequence->getPeriodMs(); - thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0, @@ -229,3 +229,25 @@ ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { } return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { + uint32_t length = thisSequence->getPeriodMs(); + + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); + + if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { + sif::error << "Initialization of TE0720 PST failed" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.h b/fsfwconfig/pollingsequence/pollingSequenceFactory.h index 09dd7242..73cdc0bb 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.h +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.h @@ -35,6 +35,11 @@ ReturnValue_t pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence); ReturnValue_t gomspacePstInit(FixedTimeslotTaskIF *thisSequence); ReturnValue_t pollingSequenceAcsTest(FixedTimeslotTaskIF* thisSequence); + +/** + * @brief This polling sequence will be created when the software is compiled for the TE0720. + */ +ReturnValue_t pollingSequenceTE0720(FixedTimeslotTaskIF* thisSequence); } diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index fca51b71..7300a610 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -41,24 +41,10 @@ ReturnValue_t PlocHandler::buildCommandFromCommand( size_t commandDataLen) { switch(deviceCommand) { case(PLOC::TC_MEM_WRITE): { - const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 - | *(commandData + 2) << 8 | *(commandData + 3); - const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 - | *(commandData + 6) << 8 | *(commandData + 7); - PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData); - rawPacket = tcMemWrite.getWholeData(); - rawPacketLen = tcMemWrite.getFullSize(); - rememberCommandId = PLOC::TC_MEM_WRITE; - return RETURN_OK; + return prepareTcMemWriteCommand(commandData, commandDataLen); } case(PLOC::TC_MEM_READ): { - const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 - | *(commandData + 2) << 8 | *(commandData + 3); - PLOC::TcMemRead tcMemRead(memoryAddress); - rawPacket = tcMemRead.getWholeData(); - rawPacketLen = tcMemRead.getFullSize(); - rememberCommandId = PLOC::TC_MEM_READ; - return RETURN_OK; + return prepareTcMemReadCommand(commandData, commandDataLen); } default: sif::debug << "PlocHandler::buildCommandFromCommand: Command not implemented" << std::endl; @@ -67,11 +53,43 @@ ReturnValue_t PlocHandler::buildCommandFromCommand( return HasReturnvaluesIF::RETURN_FAILED; } +ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, + size_t commandDataLen) { + const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 + | *(commandData + 2) << 8 | *(commandData + 3); + const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 + | *(commandData + 6) << 8 | *(commandData + 7); + PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData); + if (tcMemWrite.getFullSize() > PLOC::MAX_COMMAND_SIZE) { + sif::debug << "PlocHandler::prepareTcMemWriteCommand: Command too big" << std::endl; + return RETURN_FAILED; + } + memcpy(commandBuffer, tcMemWrite.getWholeData(), tcMemWrite.getFullSize()); + rawPacket = commandBuffer; + rawPacketLen = tcMemWrite.getFullSize(); + rememberCommandId = PLOC::TC_MEM_WRITE; + return RETURN_OK; +} + +ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, + size_t commandDataLen) { + const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 + | *(commandData + 2) << 8 | *(commandData + 3); + PLOC::TcMemRead tcMemRead(memoryAddress); + if (tcMemRead.getFullSize() > PLOC::MAX_COMMAND_SIZE) { + sif::debug << "PlocHandler::prepareTcMemReadCommand: Command too big" << std::endl; + return RETURN_FAILED; + } + memcpy(commandBuffer, tcMemRead.getWholeData(), tcMemRead.getFullSize()); + rawPacket = commandBuffer; + rawPacketLen = tcMemRead.getFullSize(); + rememberCommandId = PLOC::TC_MEM_READ; + return RETURN_OK; +} + void PlocHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(PLOC::TC_MEM_WRITE, 1, nullptr, PLOC::SIZE_ACK_REPORT); this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_ACK_REPORT); - this->insertInReplyMap(PLOC::ACK_SUCCESS, 1); - this->insertInReplyMap(PLOC::ACK_FAILURE, 1); } ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, @@ -79,31 +97,34 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, ReturnValue_t result = RETURN_OK; - *foundId = (*(start) << 8 | *(start + 1)) & APID_MASK; + uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK; - switch(*foundId) { - case(PLOC::ACK_SUCCESS): + switch(apid) { + case(PLOC::APID_ACK_SUCCESS): *foundLen = PLOC::SIZE_ACK_REPORT; + *foundId = rememberCommandId; break; - case(PLOC::ACK_FAILURE): + case(PLOC::APID_ACK_FAILURE): *foundLen = PLOC::SIZE_ACK_REPORT; - break; + *foundId = rememberCommandId; + break; default: sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl; - result = IGNORE_REPLY_DATA; + return IGNORE_REPLY_DATA; break; } - result = verifyPacket(start, foundLen); - return result; } -ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t* foundLen) { +ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t foundLen) { - uint16_t receivedCrc = *(start + *foundLen - 2) << 8 | *(start + *foundLen - 1); + uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1); - if (receivedCrc != CRC::crc16ccitt(start, *foundLen, 0)) { + uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2, 0); + + if (receivedCrc != recalculatedCrc) { + sif::debug << "PlocHandler::verifyPacket: CRC failure of ACK reply" << std::endl; return CRC_FAILURE; } @@ -113,55 +134,68 @@ ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t* foundLen) ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { + uint16_t apid = (*(packet) << 8 | *(packet + 1)) & APID_MASK; + + if (apid == PLOC::APID_ACK_FAILURE) { + sif::error << "PlocHandler::interpretDeviceReply: Received ACK failure reply" << std::endl; + triggerEvent(ACK_FAILURE, id); + replyRawData(packet, PLOC::SIZE_ACK_REPORT, defaultRawReceiver); + return RETURN_OK; + } + + if (verifyPacket(packet, PLOC::SIZE_ACK_REPORT) == CRC_FAILURE) { + sif::error << "PlocHandler::interpretDeviceReply: CRC failure in Ack reply" << std::endl; + replyRawData(packet, PLOC::SIZE_ACK_REPORT, defaultRawReceiver); + triggerEvent(CRC_FAILURE_IN_ACK_REPLY, id); + return RETURN_OK; + } + switch (id) { - case (PLOC::ACK_SUCCESS): - receiveTm(); - receiveExecutionReport(); - break; - case (PLOC::ACK_FAILURE): - //TODO: Interpretation of status field in ack reply. - sif::error << "PlocHandler::interpretDeviceReply: Received ack failure reply" << std::endl; - triggerEvent(ACK_FAILURE, rememberCommandId); - break; - default: { - sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } - } - - return RETURN_OK; -} - -void PlocHandler::receiveTm() { - switch (rememberCommandId) { case (PLOC::TC_MEM_WRITE): + receiveExecutionReport(); break; case (PLOC::TC_MEM_READ): receiveTmMemoryReadReport(); + receiveExecutionReport(); break; default: - sif::debug << "PlocHandler::receiveTm: Rembered unknown command id" << std::endl; - break; - } + sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + rememberCommandId = PLOC::NONE; + return RETURN_OK; } -void PlocHandler::receiveExecutionReport() { +ReturnValue_t PlocHandler::receiveExecutionReport() { size_t receivedDataLen = 0; uint8_t *receivedData = nullptr; - communicationInterface->requestReceiveMessage(comCookie, PLOC::SIZE_EXE_REPORT); - communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); + ReturnValue_t result = RETURN_OK; - if(!verifyPacket(receivedData, &receivedDataLen)) { + result = communicationInterface->requestReceiveMessage(comCookie, PLOC::SIZE_EXE_REPORT); + if (result != RETURN_OK) { + sif::error << "PlocHandler::receiveExecutionReport: Failed to request execution report" + << std::endl; + return result; + } + result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); + if (result != RETURN_OK) { + sif::error << "PlocHandler::receiveExecutionReport: Failed to read execution report" + << std::endl; + return result; + } + + if(verifyPacket(receivedData, receivedDataLen) == CRC_FAILURE) { replyRawData(receivedData, receivedDataLen, defaultRawReceiver); triggerEvent(EXE_RPT_INVALID_CRC); sif::error << "PlocHandler::receiveExecutionReport: Execution report has invalid crc" << std::endl; - return; + return result; } - handleExecutionReport(receivedData, receivedDataLen); + result = handleExecutionReport(receivedData, receivedDataLen); } void PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { @@ -177,10 +211,10 @@ void PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t rece sif::error << "PlocHandler::handleExecutionReport: Received execution failure report" << std::endl; triggerEvent(EXE_FAILURE, rememberCommandId); - return; + return EXE_REPLY_CRC_FAILURE; } } - return; + return RETURN_OK; } void PlocHandler::receiveTmMemoryReadReport() { @@ -211,7 +245,7 @@ void PlocHandler::receiveTmMemoryReadReport() { return; } - if(!verifyPacket(receivedData, &receivedDataLen)) { + if(verifyPacket(receivedData, receivedDataLen) == CRC_FAILURE) { replyRawData(receivedData, receivedDataLen, defaultRawReceiver); triggerEvent(TM_READ_RPT_INVALID_CRC); sif::error << "PlocHandler::receiveTmReadReport: TM read report has invalid crc" diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 8e3a6aa4..0c0bf7d8 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -44,12 +44,14 @@ private: static const ReturnValue_t TC_ACK_FAILURE = MAKE_RETURN_CODE(0xA0); static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA1); + static const ReturnValue_t EXE_REPLY_CRC_FAILURE = MAKE_RETURN_CODE(0xA1); static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER; static const Event REQUESTING_TM_READ_REPORT_FAILED = MAKE_EVENT(0, severity::LOW); static const Event TM_READ_RPT_INVALID_CRC = MAKE_EVENT(1, severity::LOW); static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); + static const Event CRC_FAILURE_IN_ACK_REPLY = MAKE_EVENT(2, severity::LOW); static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW); static const Event EXE_RPT_INVALID_CRC = MAKE_EVENT(4, severity::LOW); @@ -57,10 +59,27 @@ private: DeviceCommandId_t rememberCommandId = PLOC::NONE; + uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; + /** - * @brief This function checks wheter a telemetry packet is expected or not. + * @brief This function fills the commandBuffer to initiate the write memory command. + * + * @param commandData Pointer to action command data. + * @param commanDataLen Size of command data in bytes. + * + * @return RETURN_OK if successful, else RETURN_FAILURE. */ - void receiveTm(); + ReturnValue_t prepareTcMemWriteCommand(const uint8_t * commandData, size_t commandDataLen); + + /** + * @brief This function fills the commandBuffer to initiate the write reads command. + * + * @param commandData Pointer to action command data. + * @param commanDataLen Size of command data in bytes. + * + * @return RETURN_OK if successful, else RETURN_FAILURE. + */ + ReturnValue_t prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen); /** * @brief This function checks the crc of the received PLOC reply. @@ -70,18 +89,21 @@ private: * * @return RETURN_OK if CRC is ok, otherwise CRC_FAILURE. */ - ReturnValue_t verifyPacket(const uint8_t* start, size_t* foundLen); + ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen); /** * @brief This function reads and handles the execution reply. + * @param RETURN_OK if reading and handling of reply successful, otherwise failure value. */ - void receiveExecutionReport(); + ReturnValue_t receiveExecutionReport(); /** * @brief This function handles the data of a execution report. * * @param receivedData Pointer to the received data * @param receivedDataLen Size in bytes of the received data + * + * @return RETURN_OK if successful, otherwise an error code. */ void handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen); @@ -92,7 +114,7 @@ private: * @details In case of a valid packet the received memory content will be forwarded to the * commanding object via an action message. */ - void receiveTmMemoryReadReport(); + ReturnValue_t receiveTmMemoryReadReport(); /** * @brief This function handles action message replies in case the telemetry has been diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index dbd157e5..74dd3c09 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -3,15 +3,13 @@ #include #include +#include namespace PLOC { static const DeviceCommandId_t NONE = 0x0; static const DeviceCommandId_t TC_MEM_WRITE = 0x714; static const DeviceCommandId_t TC_MEM_READ = 0x715; - static const DeviceCommandId_t ACK_SUCCESS = 0x400; - static const DeviceCommandId_t ACK_FAILURE = 0x401; - static const DeviceCommandId_t TM_READ_REPORT = 0x404; static const uint16_t SIZE_ACK_REPORT = 14; static const uint16_t SIZE_EXE_REPORT = 14; @@ -23,6 +21,8 @@ namespace PLOC { static const uint16_t APID_TC_MEM_WRITE = 0x714; static const uint16_t APID_TC_MEM_READ = 0x715; static const uint16_t APID_TM_READ_REPORT = 0x404; + static const uint16_t APID_ACK_SUCCESS = 0x400; + static const uint16_t APID_ACK_FAILURE = 0x401; static const uint16_t APID_EXE_SUCCESS = 0x402; static const uint16_t APID_EXE_FAILURE = 0x403; @@ -34,6 +34,7 @@ namespace PLOC { static const uint16_t LENGTH_TC_MEM_READ = 8; static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT; + static const size_t MAX_COMMAND_SIZE = 18; /** * @brief This class helps to build the memory read command for the PLOC. @@ -44,6 +45,7 @@ namespace PLOC { */ class TcMemRead : public SpacePacket { public: + /** * @brief Constructor * @@ -63,18 +65,29 @@ namespace PLOC { */ void fillPacketDataField(const uint32_t* memAddrPtr) { /* Add memAddr to packet data field */ - memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(*memAddrPtr)); + size_t serializedSize = 0; + uint8_t* memoryAddressPos = this->localData.fields.buffer; + SerializeAdapter::serialize(memAddrPtr, &memoryAddressPos, &serializedSize, + sizeof(*memAddrPtr), SerializeIF::Endianness::BIG); + /* Add memLen to packet data field */ this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + + /* Calculate crc */ uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE, 0); + /* Add crc to packet data field of space packet */ + serializedSize = 0; + uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; + SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, + sizeof(crc), SerializeIF::Endianness::BIG); memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); } - static const uint8_t CRC_OFFSET = 12; - static const uint8_t OFFSET_MEM_LEN_FIELD = 10; + static const uint8_t OFFSET_MEM_LEN_FIELD = 4; + static const uint8_t CRC_OFFSET = 6; }; @@ -107,23 +120,39 @@ namespace PLOC { * @param memoryDataPtr Pointer to the memoryData to write */ void fillPacketDataField(const uint32_t* memAddrPtr, const uint32_t* memoryDataPtr) { + /* Add memAddr to packet data field */ - memcpy(this->localData.fields.buffer, memAddrPtr, sizeof(*memAddrPtr)); + size_t serializedSize = 0; + uint8_t* memoryAddressPos = this->localData.fields.buffer; + SerializeAdapter::serialize(memAddrPtr, &memoryAddressPos, &serializedSize, + sizeof(*memAddrPtr), SerializeIF::Endianness::BIG); + /* Add memLen to packet data field */ this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + /* Add memData to packet data field */ - memcpy(this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD, memAddrPtr, - sizeof(*memAddrPtr)); + serializedSize = 0; + uint8_t* memoryDataPos = this->localData.fields.buffer + OFFSET_MEM_DATA_FIELD; + SerializeAdapter::serialize(memoryDataPtr, &memoryDataPos, &serializedSize, + sizeof(*memoryDataPtr), SerializeIF::Endianness::BIG); + + /* Calculate crc */ uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE, 0); + + serializedSize = 0; + uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; /* Add crc to packet data field of space packet */ + SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, + sizeof(crc), SerializeIF::Endianness::BIG); memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); } - static const uint8_t OFFSET_MEM_LEN_FIELD = 10; - static const uint8_t OFFSET_MEM_DATA_FIELD = 12; - static const uint8_t CRC_OFFSET = 16; + /** Offsets from base address of packet data field */ + static const uint8_t OFFSET_MEM_LEN_FIELD = 4; + static const uint8_t OFFSET_MEM_DATA_FIELD = 6; + static const uint8_t CRC_OFFSET = 10; }; } From b0e8a8624a5623e5bdca97304dc2f01d9fed1d26 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Fri, 16 Apr 2021 18:59:48 +0200 Subject: [PATCH 06/42] wip --- mission/devices/PlocHandler.cpp | 4 ++-- mission/devices/devicedefinitions/PlocDefinitions.h | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index 7300a610..802c26e5 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -89,7 +89,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, void PlocHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(PLOC::TC_MEM_WRITE, 1, nullptr, PLOC::SIZE_ACK_REPORT); - this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_ACK_REPORT); + this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_TC_MEM_READ_REPLY); } ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, @@ -198,7 +198,7 @@ ReturnValue_t PlocHandler::receiveExecutionReport() { result = handleExecutionReport(receivedData, receivedDataLen); } -void PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { +ReturnValue_t PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { uint16_t apid = (*(receivedData) << 8 | *(receivedData + 1)) & APID_MASK; diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index 74dd3c09..89cef3da 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -15,6 +15,9 @@ namespace PLOC { static const uint16_t SIZE_EXE_REPORT = 14; static const uint16_t SIZE_TM_MEM_READ_REPORT = 18; + /** Reply comprises one ack report, the telemetry packet and the execution report */ + static const uint16_t SIZE_TC_MEM_READ_REPLY = 49; + /** * SpacePacket apids of PLOC telecommands and telemetry. */ @@ -33,7 +36,7 @@ namespace PLOC { static const uint16_t LENGTH_TC_MEM_WRITE = 12; static const uint16_t LENGTH_TC_MEM_READ = 8; - static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT; + static const size_t MAX_REPLY_SIZE = SIZE_TC_MEM_READ_REPLY; static const size_t MAX_COMMAND_SIZE = 18; /** From 7c28b2a0bc5116b962ad8e1d0482f066b3816619 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 19 Apr 2021 17:17:22 +0200 Subject: [PATCH 07/42] changes in plocDefinitions and plocHandler --- README.md | 6 ++++++ mission/devices/PlocHandler.cpp | 13 +++++++++++++ mission/devices/devicedefinitions/PlocDefinitions.h | 8 ++++++++ 3 files changed, 27 insertions(+) diff --git a/README.md b/README.md index 73845e41..b4e5acab 100644 --- a/README.md +++ b/README.md @@ -579,4 +579,10 @@ Eclipse indexer. Get info about ttyUL* devices ```` cat /proc/tty/driver +```` + +## Useful Q7S Linux Commands +Rebooting currently running image: +```` +xsc_boot_copy -r ```` \ No newline at end of file diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index 802c26e5..38c835dc 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -106,8 +106,21 @@ ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, break; case(PLOC::APID_ACK_FAILURE): *foundLen = PLOC::SIZE_ACK_REPORT; +<<<<<<< Updated upstream *foundId = rememberCommandId; break; +======= + break; + case(PLOC::TM_READ_REPORT): + *foundLen = PLOC::SIZE_ACK_REPORT; + break; + case(PLOC::EXE_SUCCESS): + *foundLen = PLOC::SIZE_EXE_REPORT; + break; + case(PLOC::EXE_FAILURE): + *foundLen = PLOC::SIZE_EXE_REPORT; + break; +>>>>>>> Stashed changes default: sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl; return IGNORE_REPLY_DATA; diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index 89cef3da..fdcae741 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -10,6 +10,14 @@ namespace PLOC { static const DeviceCommandId_t NONE = 0x0; static const DeviceCommandId_t TC_MEM_WRITE = 0x714; static const DeviceCommandId_t TC_MEM_READ = 0x715; +<<<<<<< Updated upstream +======= + static const DeviceCommandId_t ACK_SUCCESS = 0x400; + static const DeviceCommandId_t ACK_FAILURE = 0x401; + static const DeviceCommandId_t EXE_SUCCESS = 0x402; + static const DeviceCommandId_t EXE_FAILURE = 0x403; + static const DeviceCommandId_t TM_READ_REPORT = 0x404; +>>>>>>> Stashed changes static const uint16_t SIZE_ACK_REPORT = 14; static const uint16_t SIZE_EXE_REPORT = 14; From a0a5c4c8aa2ab72f6365d357082cd7fe91aa04cc Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 22 Apr 2021 17:32:39 +0200 Subject: [PATCH 08/42] tc mem write and tc mem read implemented --- linux/uart/UartComIF.cpp | 3 + mission/devices/PlocHandler.cpp | 470 ++++++++++++------ mission/devices/PlocHandler.h | 91 +++- .../devicedefinitions/PlocDefinitions.h | 31 +- 4 files changed, 401 insertions(+), 194 deletions(-) diff --git a/linux/uart/UartComIF.cpp b/linux/uart/UartComIF.cpp index 79470a45..8d9a15c3 100644 --- a/linux/uart/UartComIF.cpp +++ b/linux/uart/UartComIF.cpp @@ -363,6 +363,9 @@ ReturnValue_t UartComIF::readReceivedMessage(CookieIF *cookie, *buffer = uartDeviceMapIter->second.replyBuffer.data(); *size = uartDeviceMapIter->second.replyLen; + /* Length is reset to 0 to prevent reading the same data twice */ + uartDeviceMapIter->second.replyLen = 0; + return RETURN_OK; } diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index 38c835dc..f1444488 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -53,6 +53,98 @@ ReturnValue_t PlocHandler::buildCommandFromCommand( return HasReturnvaluesIF::RETURN_FAILED; } +void PlocHandler::fillCommandAndReplyMap() { + this->insertInCommandMap(PLOC::TC_MEM_WRITE); + this->insertInCommandMap(PLOC::TC_MEM_READ); + this->insertInReplyMap(PLOC::ACK_REPORT, 1, nullptr, PLOC::SIZE_ACK_REPORT); + this->insertInReplyMap(PLOC::EXE_REPORT, 3, nullptr, PLOC::SIZE_EXE_REPORT); + this->insertInReplyMap(PLOC::TM_MEMORY_READ_REPORT, 2, nullptr, PLOC::SIZE_TM_MEM_READ_REPORT); +} + +ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + + ReturnValue_t result = RETURN_OK; + + uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK; + + switch(apid) { + case(PLOC::APID_ACK_SUCCESS): + *foundLen = PLOC::SIZE_ACK_REPORT; + *foundId = PLOC::ACK_REPORT; + break; + case(PLOC::APID_ACK_FAILURE): + *foundLen = PLOC::SIZE_ACK_REPORT; + *foundId = PLOC::ACK_REPORT; + break; + case(PLOC::APID_TM_MEMORY_READ_REPORT): + *foundLen = PLOC::SIZE_TM_MEM_READ_REPORT; + *foundId = PLOC::TM_MEMORY_READ_REPORT; + break; + case(PLOC::APID_EXE_SUCCESS): + *foundLen = PLOC::SIZE_EXE_REPORT; + *foundId = PLOC::EXE_REPORT; + break; + case(PLOC::APID_EXE_FAILURE): + *foundLen = PLOC::SIZE_EXE_REPORT; + *foundId = PLOC::EXE_REPORT; + break; + default: { + sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl; + *foundLen = remainingSize; + result = INVALID_APID; + break; + } + } + + return result; +} + +ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + + ReturnValue_t result = RETURN_OK; + + switch (id) { + case PLOC::ACK_REPORT: { + result = handleAckReport(packet); + break; + } + case (PLOC::TM_MEMORY_READ_REPORT): { + result = handleMemoryReadReport(packet); + break; + } + case (PLOC::EXE_REPORT): { + result = handleExecutionReport(packet); + break; + } + default: { + sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + } + + return result; +} + +void PlocHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t PlocHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 500; +} + +ReturnValue_t PlocHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + + return HasReturnvaluesIF::RETURN_OK; +} + +void PlocHandler::setModeNormal() { + mode = MODE_NORMAL; +} + ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, size_t commandDataLen) { const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 @@ -67,7 +159,7 @@ ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, memcpy(commandBuffer, tcMemWrite.getWholeData(), tcMemWrite.getFullSize()); rawPacket = commandBuffer; rawPacketLen = tcMemWrite.getFullSize(); - rememberCommandId = PLOC::TC_MEM_WRITE; + nextReplyId = PLOC::ACK_REPORT; return RETURN_OK; } @@ -83,53 +175,10 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, memcpy(commandBuffer, tcMemRead.getWholeData(), tcMemRead.getFullSize()); rawPacket = commandBuffer; rawPacketLen = tcMemRead.getFullSize(); - rememberCommandId = PLOC::TC_MEM_READ; + nextReplyId = PLOC::ACK_REPORT; return RETURN_OK; } -void PlocHandler::fillCommandAndReplyMap() { - this->insertInCommandAndReplyMap(PLOC::TC_MEM_WRITE, 1, nullptr, PLOC::SIZE_ACK_REPORT); - this->insertInCommandAndReplyMap(PLOC::TC_MEM_READ, 1, nullptr, PLOC::SIZE_TC_MEM_READ_REPLY); -} - -ReturnValue_t PlocHandler::scanForReply(const uint8_t *start, - size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { - - ReturnValue_t result = RETURN_OK; - - uint16_t apid = (*(start) << 8 | *(start + 1)) & APID_MASK; - - switch(apid) { - case(PLOC::APID_ACK_SUCCESS): - *foundLen = PLOC::SIZE_ACK_REPORT; - *foundId = rememberCommandId; - break; - case(PLOC::APID_ACK_FAILURE): - *foundLen = PLOC::SIZE_ACK_REPORT; -<<<<<<< Updated upstream - *foundId = rememberCommandId; - break; -======= - break; - case(PLOC::TM_READ_REPORT): - *foundLen = PLOC::SIZE_ACK_REPORT; - break; - case(PLOC::EXE_SUCCESS): - *foundLen = PLOC::SIZE_EXE_REPORT; - break; - case(PLOC::EXE_FAILURE): - *foundLen = PLOC::SIZE_EXE_REPORT; - break; ->>>>>>> Stashed changes - default: - sif::debug << "PlocHandler::scanForReply: Reply has invalid apid" << std::endl; - return IGNORE_REPLY_DATA; - break; - } - - return result; -} - ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t foundLen) { uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1); @@ -137,137 +186,202 @@ ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t foundLen) { uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2, 0); if (receivedCrc != recalculatedCrc) { - sif::debug << "PlocHandler::verifyPacket: CRC failure of ACK reply" << std::endl; return CRC_FAILURE; } return RETURN_OK; } -ReturnValue_t PlocHandler::interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) { - - uint16_t apid = (*(packet) << 8 | *(packet + 1)) & APID_MASK; - - if (apid == PLOC::APID_ACK_FAILURE) { - sif::error << "PlocHandler::interpretDeviceReply: Received ACK failure reply" << std::endl; - triggerEvent(ACK_FAILURE, id); - replyRawData(packet, PLOC::SIZE_ACK_REPORT, defaultRawReceiver); - return RETURN_OK; - } - - if (verifyPacket(packet, PLOC::SIZE_ACK_REPORT) == CRC_FAILURE) { - sif::error << "PlocHandler::interpretDeviceReply: CRC failure in Ack reply" << std::endl; - replyRawData(packet, PLOC::SIZE_ACK_REPORT, defaultRawReceiver); - triggerEvent(CRC_FAILURE_IN_ACK_REPLY, id); - return RETURN_OK; - } - - switch (id) { - case (PLOC::TC_MEM_WRITE): - receiveExecutionReport(); - break; - case (PLOC::TC_MEM_READ): - receiveTmMemoryReadReport(); - receiveExecutionReport(); - break; - default: - sif::debug << "PlocHandler::interpretDeviceReply: Unknown device reply id" << std::endl; - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } - - rememberCommandId = PLOC::NONE; - return RETURN_OK; -} - -ReturnValue_t PlocHandler::receiveExecutionReport() { - - size_t receivedDataLen = 0; - uint8_t *receivedData = nullptr; +ReturnValue_t PlocHandler::handleAckReport(const uint8_t* data) { ReturnValue_t result = RETURN_OK; - result = communicationInterface->requestReceiveMessage(comCookie, PLOC::SIZE_EXE_REPORT); - if (result != RETURN_OK) { - sif::error << "PlocHandler::receiveExecutionReport: Failed to request execution report" - << std::endl; - return result; - } - result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); - if (result != RETURN_OK) { - sif::error << "PlocHandler::receiveExecutionReport: Failed to read execution report" - << std::endl; - return result; + result = verifyPacket(data, PLOC::SIZE_ACK_REPORT); + if(result == CRC_FAILURE) { + sif::error << "PlocHandler::handleAckReport: CRC failure" << std::endl; + nextReplyId = PLOC::NONE; + replyRawReplyIfnotWiretapped(data, PLOC::SIZE_ACK_REPORT); + triggerEvent(CRC_FAILURE_EVENT); + sendFailureReport(PLOC::ACK_REPORT, CRC_FAILURE); + disableAllReplies(); + return IGNORE_REPLY_DATA; } - if(verifyPacket(receivedData, receivedDataLen) == CRC_FAILURE) { - replyRawData(receivedData, receivedDataLen, defaultRawReceiver); - triggerEvent(EXE_RPT_INVALID_CRC); - sif::error << "PlocHandler::receiveExecutionReport: Execution report has invalid crc" - << std::endl; - return result; - } + uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK; - result = handleExecutionReport(receivedData, receivedDataLen); + switch(apid) { + case PLOC::APID_ACK_FAILURE: { + //TODO: Interpretation of status field in acknowledgment report + sif::debug << "PlocHandler::handleAckReport: Received Ack failure report" << std::endl; + DeviceCommandId_t commandId = getPendingCommand(); + if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { + triggerEvent(ACK_FAILURE, commandId); + } + sendFailureReport(PLOC::ACK_REPORT, RECEIVED_ACK_FAILURE); + disableAllReplies(); + nextReplyId = PLOC::NONE; + result = IGNORE_REPLY_DATA; + break; + } + case PLOC::APID_ACK_SUCCESS: { + setNextReplyId(); + break; + } + default: { + sif::debug << "PlocHandler::handleAckReport: Invalid APID in Ack report" << std::endl; + result = RETURN_FAILED; + break; + } + } + + return result; } -ReturnValue_t PlocHandler::handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen) { +ReturnValue_t PlocHandler::handleExecutionReport(const uint8_t* data) { - uint16_t apid = (*(receivedData) << 8 | *(receivedData + 1)) & APID_MASK; + ReturnValue_t result = RETURN_OK; + + result = verifyPacket(data, PLOC::SIZE_EXE_REPORT); + if(result == CRC_FAILURE) { + sif::error << "PlocHandler::handleExecutionReport: CRC failure" << std::endl; + nextReplyId = PLOC::NONE; + return result; + } + + uint16_t apid = (*(data) << 8 | *(data + 1)) & APID_MASK; switch (apid) { case (PLOC::APID_EXE_SUCCESS): { - return; + break; } case (PLOC::APID_EXE_FAILURE): { //TODO: Interpretation of status field in execution report sif::error << "PlocHandler::handleExecutionReport: Received execution failure report" << std::endl; - triggerEvent(EXE_FAILURE, rememberCommandId); - return EXE_REPLY_CRC_FAILURE; + DeviceCommandId_t commandId = getPendingCommand(); + if (commandId != DeviceHandlerIF::NO_COMMAND_ID) { + triggerEvent(EXE_FAILURE, commandId); + } + else { + sif::debug << "PlocHandler::handleExecutionReport: Unknown command id" << std::endl; + } + sendFailureReport(PLOC::EXE_REPORT, RECEIVED_EXE_FAILURE); + disableExeReportReply(); + result = IGNORE_REPLY_DATA; + break; + } + default: { + sif::error << "PlocHandler::handleExecutionReport: Unknown APID" << std::endl; + result = RETURN_FAILED; + break; } } + + nextReplyId = PLOC::NONE; + + return result; +} + +ReturnValue_t PlocHandler::handleMemoryReadReport(const uint8_t* data) { + + ReturnValue_t result = RETURN_OK; + + result = verifyPacket(data, PLOC::SIZE_TM_MEM_READ_REPORT); + + if(result == CRC_FAILURE) { + sif::error << "PlocHandler::handleMemoryReadReport: Memory read report has invalid crc" + << std::endl; + } + /** Send data to commanding queue */ + handleDeviceTM(data + PLOC::DATA_FIELD_OFFSET, PLOC::SIZE_MEM_READ_REPORT_DATA, + PLOC::TM_MEMORY_READ_REPORT); + + nextReplyId = PLOC::EXE_REPORT; + + return result; +} + +ReturnValue_t PlocHandler::enableReplyInReplyMap(DeviceCommandMap::iterator command, + uint8_t expectedReplies, bool useAlternateId, + DeviceCommandId_t alternateReplyID) { + + ReturnValue_t result = RETURN_OK; + + uint8_t enabledReplies = 0; + + switch (command->first) { + case PLOC::TC_MEM_WRITE: + enabledReplies = 2; + break; + case PLOC::TC_MEM_READ: { + enabledReplies = 3; + result = DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, + PLOC::TM_MEMORY_READ_REPORT); + if (result != RETURN_OK) { + sif::debug << "PlocHandler::enableReplyInReplyMap: Reply with id " + << PLOC::TM_MEMORY_READ_REPORT << " not in replyMap" << std::endl; + } + break; + } + default: + sif::debug << "PlocHandler::enableReplyInReplyMap: Unknown command id" << std::endl; + break; + } + + /** + * Every command causes at least one acknowledgment and one execution report. Therefore both + * replies will be enabled here. + */ + result = DeviceHandlerBase::enableReplyInReplyMap(command, + enabledReplies, true, PLOC::ACK_REPORT); + if (result != RETURN_OK) { + sif::debug << "PlocHandler::enableReplyInReplyMap: Reply with id " << PLOC::ACK_REPORT + << " not in replyMap" << std::endl; + } + + result = DeviceHandlerBase::enableReplyInReplyMap(command, + enabledReplies, true, PLOC::EXE_REPORT); + if (result != RETURN_OK) { + sif::debug << "PlocHandler::enableReplyInReplyMap: Reply with id " << PLOC::EXE_REPORT + << " not in replyMap" << std::endl; + } + return RETURN_OK; } -void PlocHandler::receiveTmMemoryReadReport() { - - size_t receivedDataLen = 0; - uint8_t *receivedData = nullptr; - - /* Receiving the telemetry packet */ - ReturnValue_t result = communicationInterface->requestReceiveMessage(comCookie, - PLOC::SIZE_TM_MEM_READ_REPORT); - if (result != RETURN_OK) { - sif::error << "PlocHandler::receiveExecutionReport: Failed to request memory read telemetry " - << std::endl; - triggerEvent(REQUESTING_TM_READ_REPORT_FAILED, result); - return; +void PlocHandler::setNextReplyId() { + switch(getPendingCommand()) { + case PLOC::TC_MEM_READ: + nextReplyId = PLOC::TM_MEMORY_READ_REPORT; + break; + default: + /* If no telemetry is expected the next reply is always the execution report */ + nextReplyId = PLOC::EXE_REPORT; + break; } - result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); - if (result != RETURN_OK) { - sif::error << "PlocHandler::receiveExecutionReport: Failed to request memory read telemetry " - << std::endl; - return; +} +size_t PlocHandler::getNextReplyLength(DeviceCommandId_t commandId){ + + size_t replyLen = 0; + + if (nextReplyId == PLOC::NONE) { + return replyLen; } - uint16_t apid = (*(receivedData) << 8 | *(receivedData + 1)) & APID_MASK; - if (apid != PLOC::APID_TM_READ_REPORT) { - sif::error << "PlocHandler::receiveTmReadReport: Tm read report has invalid apid" - << std::endl; - return; + DeviceReplyIter iter = deviceReplyMap.find(nextReplyId); + if (iter != deviceReplyMap.end()) { + if (iter->second.delayCycles == 0) { + /* Reply inactive */ + return replyLen; + } + replyLen = iter->second.replyLen; + } + else { + sif::debug << "PlocHandler::getNextReplyLength: No entry for reply with reply id " + << std::hex << nextReplyId << " in deviceReplyMap" << std::endl; } - if(verifyPacket(receivedData, receivedDataLen) == CRC_FAILURE) { - replyRawData(receivedData, receivedDataLen, defaultRawReceiver); - triggerEvent(TM_READ_RPT_INVALID_CRC); - sif::error << "PlocHandler::receiveTmReadReport: TM read report has invalid crc" - << std::endl; - return; - } - - handleDeviceTM(receivedData, receivedDataLen, PLOC::TC_MEM_READ); - + return replyLen; } void PlocHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId) { @@ -291,21 +405,67 @@ void PlocHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCom } } -void PlocHandler::setNormalDatapoolEntriesInvalid(){ +void PlocHandler::disableAllReplies() { + DeviceReplyMap::iterator iter; + + /* Disable ack reply */ + iter = deviceReplyMap.find(PLOC::ACK_REPORT); + DeviceReplyInfo *info = &(iter->second); + info->delayCycles = 0; + info->command = deviceCommandMap.end(); + + DeviceCommandId_t commandId = getPendingCommand(); + + /* If the command expects a telemetry packet the appropriate tm reply will be disabled here */ + switch (commandId) { + case PLOC::TC_MEM_WRITE: + break; + case PLOC::TC_MEM_READ: { + iter = deviceReplyMap.find(PLOC::TM_MEMORY_READ_REPORT); + info = &(iter->second); + info->delayCycles = 0; + info->command = deviceCommandMap.end(); + break; + } + default: { + sif::debug << "PlocHandler::disableAllReplies: Unknown command id" << commandId + << std::endl; + break; + } + } + + /* We must always disable the execution report reply here */ + disableExeReportReply(); } -uint32_t PlocHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 500; +void PlocHandler::sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status) { + + DeviceReplyIter iter = deviceReplyMap.find(replyId); + + if (iter == deviceReplyMap.end()) { + sif::debug << "PlocHandler::sendFailureReport: Reply not in reply map" << std::endl; + return; + } + + DeviceCommandInfo* info = &(iter->second.command->second); + + if (info == nullptr) { + sif::debug << "PlocHandler::sendFailureReport: Reply has no active command" << std::endl; + return; + } + + if (info->sendReplyTo != NO_COMMANDER) { + actionHelper.finish(false, info->sendReplyTo, iter->first, status); + } + info->isExecuting = false; } -ReturnValue_t PlocHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) { - - return HasReturnvaluesIF::RETURN_OK; +void PlocHandler::disableExeReportReply() { + DeviceReplyIter iter = deviceReplyMap.find(PLOC::EXE_REPORT); + DeviceReplyInfo *info = &(iter->second); + info->delayCycles = 0; + info->command = deviceCommandMap.end(); + /* Expected replies is set to one here. The value will set to 0 in replyToReply() */ + info->command->second.expectedReplies = 0; } - -void PlocHandler::setModeNormal() { - mode = MODE_NORMAL; -} - diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 0c0bf7d8..b241c838 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -6,7 +6,10 @@ #include /** - * @brief This is the device handler for the ISIS Magnetorquer iMTQ. + * @brief This is the device handler for the PLOC. + * + * @details The PLOC uses the space packet protocol for communication. On each command the PLOC + * answers at least with one acknowledgment and one execution report. * * @author J. Meier */ @@ -37,30 +40,38 @@ protected: uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; + ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator command, + uint8_t expectedReplies = 1, bool useAlternateId = false, + DeviceCommandId_t alternateReplyID = 0) override; + size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override; private: static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_HANDLER; - static const ReturnValue_t TC_ACK_FAILURE = MAKE_RETURN_CODE(0xA0); - static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA1); - static const ReturnValue_t EXE_REPLY_CRC_FAILURE = MAKE_RETURN_CODE(0xA1); + static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0); //!> Space Packet received from PLOC has invalid CRC + static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1); //!> Received ACK failure reply from PLOC + static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2); //!> Received execution failure reply from PLOC + static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3); //!> Received space packet with invalid APID from PLOC static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER; - static const Event REQUESTING_TM_READ_REPORT_FAILED = MAKE_EVENT(0, severity::LOW); - static const Event TM_READ_RPT_INVALID_CRC = MAKE_EVENT(1, severity::LOW); - static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); - static const Event CRC_FAILURE_IN_ACK_REPLY = MAKE_EVENT(2, severity::LOW); - static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW); - static const Event EXE_RPT_INVALID_CRC = MAKE_EVENT(4, severity::LOW); + static const Event MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW); //!> PLOC crc failure in telemetry packet + static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW); //!> PLOC receive acknowledgment failure report + static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW); //!> PLOC receive execution failure report + static const Event CRC_FAILURE_EVENT = MAKE_EVENT(4, severity::LOW); //!> PLOC reply has invalid crc static const uint16_t APID_MASK = 0x7FF; - DeviceCommandId_t rememberCommandId = PLOC::NONE; - uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; + /** + * This variable is used to store the id of the next reply to receive. This is necessary + * because the PLOC sends as reply to each command at least one acknowledgment and execution + * report. + */ + DeviceCommandId_t nextReplyId = PLOC::NONE; + /** * @brief This function fills the commandBuffer to initiate the write memory command. * @@ -92,39 +103,71 @@ private: ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen); /** - * @brief This function reads and handles the execution reply. - * @param RETURN_OK if reading and handling of reply successful, otherwise failure value. + * @brief This function handles the acknowledgment report. + * + * @param data Pointer to the data holding the acknowledgment report. + * + * @return RETURN_OK if successful, otherwise an error code. */ - ReturnValue_t receiveExecutionReport(); + ReturnValue_t handleAckReport(const uint8_t* data); /** * @brief This function handles the data of a execution report. * - * @param receivedData Pointer to the received data - * @param receivedDataLen Size in bytes of the received data + * @param data Pointer to the received data packet. * * @return RETURN_OK if successful, otherwise an error code. */ - void handleExecutionReport(const uint8_t* receivedData, size_t receivedDataLen); + ReturnValue_t handleExecutionReport(const uint8_t* data); /** - * @brief This function reads and handles the memory read report telemetry packet received - * after requesting the packet with the TC_MEM_READ command. + * @brief This function handles the memory read report. * - * @details In case of a valid packet the received memory content will be forwarded to the - * commanding object via an action message. + * @param data Pointer to the data buffer holding the memory read report. + * + * @return RETURN_OK if successful, otherwise an error code. */ - ReturnValue_t receiveTmMemoryReadReport(); + ReturnValue_t handleMemoryReadReport(const uint8_t* data); + + /** + * @brief Depending on the current active command, this function sets the reply id of the + * next reply after a successful acknowledgment report has been received. This is + * required by the function getNextReplyLength() to identify the length of the next + * reply to read. + */ + void setNextReplyId(); /** * @brief This function handles action message replies in case the telemetry has been * requested by another object. * - * @param data Pointer to the telemtry data. + * @param data Pointer to the telemetry data. * @param dataSize Size of telemetry in bytes. * @param replyId Id of the reply. This will be added to the ActionMessage. */ void handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId); + + /** + * @brief In case an acknowledgment failure reply has been received this function disables + * all previously enabled commands and resets the exepected replies variable of an + * active command. + */ + void disableAllReplies(); + + /** + * @brief This function sends a failure report if the active action was commanded by an other + * object. + * + * @param replyId The id of the reply which signals a failure. + * @param status A status byte which gives information about the failure type. + */ + void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status); + + /** + * @brief This function disables the execution report reply. Within this function also the + * the variable expectedReplies of an active command will be set to 0. + */ + void disableExeReportReply(); }; #endif /* MISSION_DEVICES_PLOCHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index fdcae741..b7378a8a 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -8,35 +8,36 @@ namespace PLOC { static const DeviceCommandId_t NONE = 0x0; - static const DeviceCommandId_t TC_MEM_WRITE = 0x714; - static const DeviceCommandId_t TC_MEM_READ = 0x715; -<<<<<<< Updated upstream -======= - static const DeviceCommandId_t ACK_SUCCESS = 0x400; - static const DeviceCommandId_t ACK_FAILURE = 0x401; - static const DeviceCommandId_t EXE_SUCCESS = 0x402; - static const DeviceCommandId_t EXE_FAILURE = 0x403; - static const DeviceCommandId_t TM_READ_REPORT = 0x404; ->>>>>>> Stashed changes + static const DeviceCommandId_t TC_MEM_WRITE = 0x1; + static const DeviceCommandId_t TC_MEM_READ = 0x2; + static const DeviceCommandId_t ACK_REPORT = 0x3; + static const DeviceCommandId_t EXE_REPORT = 0x5; + static const DeviceCommandId_t TM_MEMORY_READ_REPORT = 0x6; static const uint16_t SIZE_ACK_REPORT = 14; static const uint16_t SIZE_EXE_REPORT = 14; static const uint16_t SIZE_TM_MEM_READ_REPORT = 18; - /** Reply comprises one ack report, the telemetry packet and the execution report */ - static const uint16_t SIZE_TC_MEM_READ_REPLY = 49; - /** * SpacePacket apids of PLOC telecommands and telemetry. */ static const uint16_t APID_TC_MEM_WRITE = 0x714; static const uint16_t APID_TC_MEM_READ = 0x715; - static const uint16_t APID_TM_READ_REPORT = 0x404; + static const uint16_t APID_TM_MEMORY_READ_REPORT = 0x404; static const uint16_t APID_ACK_SUCCESS = 0x400; static const uint16_t APID_ACK_FAILURE = 0x401; static const uint16_t APID_EXE_SUCCESS = 0x402; static const uint16_t APID_EXE_FAILURE = 0x403; + /** Offset from first byte in Space packet to first byte of data field */ + static const uint8_t DATA_FIELD_OFFSET = 6; + + /** + * The size of payload data which will be forwarded to the requesting object. e.g. PUS Service + * 8. + */ + static const uint8_t SIZE_MEM_READ_REPORT_DATA = 10; + /** * PLOC space packet length for fixed size packets. This is the size of the whole packet data * field. For the length field in the space packet this size will be substracted by one. @@ -44,7 +45,7 @@ namespace PLOC { static const uint16_t LENGTH_TC_MEM_WRITE = 12; static const uint16_t LENGTH_TC_MEM_READ = 8; - static const size_t MAX_REPLY_SIZE = SIZE_TC_MEM_READ_REPLY; + static const size_t MAX_REPLY_SIZE = SIZE_TM_MEM_READ_REPORT; static const size_t MAX_COMMAND_SIZE = 18; /** From 2e28016281996fa4923085b063815f6e0f0f4883 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sat, 24 Apr 2021 12:46:08 +0200 Subject: [PATCH 09/42] readme update --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index b4e5acab..12239b49 100644 --- a/README.md +++ b/README.md @@ -581,6 +581,13 @@ Get info about ttyUL* devices cat /proc/tty/driver ```` +## I2C +Getting information about I2C device +```` +ls /sys/class/i2c-dev/i2c-0/device/device/driver +```` +This shows the memory mapping of /dev/i2c-0 + ## Useful Q7S Linux Commands Rebooting currently running image: ```` From e4a715e24c0543a7d953a0169e931b72c3f545d9 Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Sat, 24 Apr 2021 14:22:22 +0200 Subject: [PATCH 10/42] ploc build for q7s --- bsp_q7s/ObjectFactory.cpp | 1 - fsfw | 2 +- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 2 +- tmtc | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 55373525..ca61442f 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include diff --git a/fsfw b/fsfw index 42720e6f..18a9729c 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 42720e6f7d64bdd9a1ac0cea5846c9a8cedea0ff +Subproject commit 18a9729c75875f8bee674f03dd93a5eeeb657a66 diff --git a/fsfw_hal b/fsfw_hal index 14fe3257..7a3190e5 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 14fe32572d62db9d19707dc1f9bb6fecb1993b73 +Subproject commit 7a3190e5b6980ad2addc5e8a76d21994b542f0e0 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 3f5ebfca..73c05edb 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -19,7 +19,7 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 1 +#define TE0720 0 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/tmtc b/tmtc index 73105138..79e897b0 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 73105138050b5661a6cff76e1d64af40981f9c7f +Subproject commit 79e897b0353acacf0f986f22f57e9cd8cf30a0da From e1c7ed419f3fab042ff64419dba28ddda86f5089 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 25 Apr 2021 12:35:24 +0200 Subject: [PATCH 11/42] OBSW VERsion --- common/config/OBSWVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/OBSWVersion.h b/common/config/OBSWVersion.h index 548363f2..7ac812e6 100644 --- a/common/config/OBSWVersion.h +++ b/common/config/OBSWVersion.h @@ -4,7 +4,7 @@ const char* const SW_NAME = "eive"; #define SW_VERSION 1 -#define SW_SUBVERSION 1 +#define SW_SUBVERSION 2 #define SW_SUBSUBVERSION 0 #endif /* COMMON_CONFIG_OBSWVERSION_H_ */ From 38ea091a7faa64c81d59a1f45482b9ffc311b12a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 25 Apr 2021 12:37:59 +0200 Subject: [PATCH 12/42] obsw version update --- common/config/OBSWVersion.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/OBSWVersion.h b/common/config/OBSWVersion.h index 7ac812e6..548363f2 100644 --- a/common/config/OBSWVersion.h +++ b/common/config/OBSWVersion.h @@ -4,7 +4,7 @@ const char* const SW_NAME = "eive"; #define SW_VERSION 1 -#define SW_SUBVERSION 2 +#define SW_SUBVERSION 1 #define SW_SUBSUBVERSION 0 #endif /* COMMON_CONFIG_OBSWVERSION_H_ */ From d877887826032187d606dfbc8827d07c0a018a3f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 25 Apr 2021 12:47:41 +0200 Subject: [PATCH 13/42] imqt wip --- mission/devices/IMTQHandler.cpp | 61 +++++++++++++++++++-------------- mission/devices/IMTQHandler.h | 1 + 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index 0c1b1d1e..59f6dd46 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -117,6 +117,41 @@ ReturnValue_t IMTQHandler::interpretDeviceReply(DeviceCommandId_t id, return RETURN_OK; } +void IMTQHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t IMTQHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 500; +} + +ReturnValue_t IMTQHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + + localDataPoolMap.emplace(IMTQ::DIGITAL_VOLTAGE_MV, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ANALOG_VOLTAGE_MV, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_X_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Y_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Z_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MCU_TEMPERATURE, new PoolEntry( { 0 })); + + return HasReturnvaluesIF::RETURN_OK; +} + +size_t DeviceHandlerBase::getNextReplyLength(DeviceCommandId_t commandId){ + DeviceReplyIter iter = deviceReplyMap.find(commandId); + if(iter != deviceReplyMap.end()) { + return iter->second.replyLen; + }else{ + return 0; + } +} + ReturnValue_t IMTQHandler::parseStatusByte(const uint8_t* packet) { uint8_t cmdErrorField = *(packet + 1) & 0xF; switch (cmdErrorField) { @@ -184,32 +219,6 @@ void IMTQHandler::fillEngHkDataset(const uint8_t* packet) { #endif } -void IMTQHandler::setNormalDatapoolEntriesInvalid(){ - -} - -uint32_t IMTQHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 500; -} - -ReturnValue_t IMTQHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) { - - localDataPoolMap.emplace(IMTQ::DIGITAL_VOLTAGE_MV, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::ANALOG_VOLTAGE_MV, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_X_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Y_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Z_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::MCU_TEMPERATURE, new PoolEntry( { 0 })); - - return HasReturnvaluesIF::RETURN_OK; -} - void IMTQHandler::setModeNormal() { mode = MODE_NORMAL; } diff --git a/mission/devices/IMTQHandler.h b/mission/devices/IMTQHandler.h index 2e2a7612..21ba770f 100644 --- a/mission/devices/IMTQHandler.h +++ b/mission/devices/IMTQHandler.h @@ -37,6 +37,7 @@ protected: uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; + virtual size_t getNextReplyLength(DeviceCommandId_t commandId) override; private: From 191f4b6d0c296980dac641693bd8e1812172c904 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 25 Apr 2021 15:53:44 +0200 Subject: [PATCH 14/42] get commanded dipole wip --- .../pollingSequenceFactory.cpp | 3 +- mission/devices/IMTQHandler.cpp | 93 ++++++++++++++----- mission/devices/IMTQHandler.h | 1 - .../IMTQHandlerDefinitions.h | 4 + tmtc | 2 +- 5 files changed, 78 insertions(+), 25 deletions(-) diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 02e6b625..f7422786 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -85,9 +85,10 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RTD_IC16, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::RTD_IC17, length * 0.4, DeviceHandlerIF::GET_WRITE); thisSequence->addSlot(objects::RTD_IC18, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); #endif /* Q7S_ADD_RTD_DEVICES */ + thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TMP1075_HANDLER_1, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::TMP1075_HANDLER_2, length * 0.6, DeviceHandlerIF::SEND_READ); diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index 59f6dd46..80cc1550 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -42,25 +42,31 @@ ReturnValue_t IMTQHandler::buildCommandFromCommand( DeviceCommandId_t deviceCommand, const uint8_t * commandData, size_t commandDataLen) { switch(deviceCommand) { + case(IMTQ::START_ACTUATION_DIPOLE): { + /* IMTQ expects low byte first */ + commandBuffer[0] = IMTQ::CC::START_ACTUATION_DIPOLE; + commandBuffer[1] = *(commandData + 1); + commandBuffer[2] = *(commandData); + commandBuffer[3] = *(commandData + 3); + commandBuffer[4] = *(commandData + 2); + commandBuffer[5] = *(commandData + 5); + commandBuffer[6] = *(commandData + 4); + commandBuffer[7] = *(commandData + 7); + commandBuffer[8] = *(commandData + 6); + rawPacket = commandBuffer; + rawPacketLen = 9; + return RETURN_OK; + } case(IMTQ::GET_ENG_HK_DATA): { commandBuffer[0] = IMTQ::CC::GET_ENG_HK_DATA; rawPacket = commandBuffer; rawPacketLen = 1; return RETURN_OK; } - case(IMTQ::START_ACTUATION_DIPOLE): { - /* IMTQ expects low byte first */ - commandBuffer[0] = IMTQ::CC::START_ACTUATION_DIPOLE; - commandBuffer[1] = *(commandData + 1); - commandBuffer[2] = *(commandData); - commandBuffer[3] = *(commandData + 3); - commandBuffer[4] = *(commandData + 2); - commandBuffer[5] = *(commandData + 5); - commandBuffer[6] = *(commandData + 4); - commandBuffer[7] = *(commandData + 7); - commandBuffer[8] = *(commandData + 6); + case(IMTQ::GET_COMMANDED_DIPOLE): { + commandBuffer[0] = IMTQ::CC::GET_COMMANDED_DIPOLE; rawPacket = commandBuffer; - rawPacketLen = 9; + rawPacketLen = 1; return RETURN_OK; } default: @@ -70,8 +76,12 @@ ReturnValue_t IMTQHandler::buildCommandFromCommand( } void IMTQHandler::fillCommandAndReplyMap() { + this->insertInCommandAndReplyMap(IMTQ::START_ACTUATION_DIPOLE, 1, nullptr, + IMTQ::SIZE_STATUS_REPLY); this->insertInCommandAndReplyMap(IMTQ::GET_ENG_HK_DATA, 1, &engHkDataset, - IMTQ::SIZE_ENG_HK_DATA_REPLY, false, true, IMTQ::SIZE_ENG_HK_DATA_REPLY); + IMTQ::SIZE_ENG_HK_DATA_REPLY); + this->insertInCommandAndReplyMap(IMTQ::GET_COMMANDED_DIPOLE, 1, nullptr, + IMTQ::SIZE_ENG_HK_DATA_REPLY); } ReturnValue_t IMTQHandler::scanForReply(const uint8_t *start, @@ -80,10 +90,18 @@ ReturnValue_t IMTQHandler::scanForReply(const uint8_t *start, ReturnValue_t result = RETURN_OK; switch(*start) { + case(IMTQ::CC::START_ACTUATION_DIPOLE): + *foundLen = IMTQ::SIZE_STATUS_REPLY; + *foundId = IMTQ::START_ACTUATION_DIPOLE; + break; case(IMTQ::CC::GET_ENG_HK_DATA): *foundLen = IMTQ::SIZE_ENG_HK_DATA_REPLY; *foundId = IMTQ::GET_ENG_HK_DATA; break; + case(IMTQ::CC::GET_COMMANDED_DIPOLE): + *foundLen = IMTQ::SIZE_GET_COMMANDED_DIPOLE_REPLY; + *foundId = IMTQ::GET_COMMANDED_DIPOLE; + break; default: sif::debug << "IMTQHandler::scanForReply: Reply contains invalid command code" << std::endl; result = IGNORE_REPLY_DATA; @@ -105,9 +123,15 @@ ReturnValue_t IMTQHandler::interpretDeviceReply(DeviceCommandId_t id, } switch (id) { + case (IMTQ::START_ACTUATION_DIPOLE): + // Replies only the status byte which is already handled with parseStatusByte + break; case (IMTQ::GET_ENG_HK_DATA): fillEngHkDataset(packet); break; + case (IMTQ::GET_COMMANDED_DIPOLE): + handleGetCommandedDipoleReply(packet); + break; default: { sif::debug << "IMTQHandler::interpretDeviceReply: Unknown device reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; @@ -143,31 +167,29 @@ ReturnValue_t IMTQHandler::initializeLocalDataPool(localpool::DataPool& localDat return HasReturnvaluesIF::RETURN_OK; } -size_t DeviceHandlerBase::getNextReplyLength(DeviceCommandId_t commandId){ - DeviceReplyIter iter = deviceReplyMap.find(commandId); - if(iter != deviceReplyMap.end()) { - return iter->second.replyLen; - }else{ - return 0; - } -} - ReturnValue_t IMTQHandler::parseStatusByte(const uint8_t* packet) { uint8_t cmdErrorField = *(packet + 1) & 0xF; switch (cmdErrorField) { case 0: return RETURN_OK; case 1: + sif::error << "IMTQHandler::parseStatusByte: Command rejected without reason" << std::endl; return REJECTED_WITHOUT_REASON; case 2: + sif::error << "IMTQHandler::parseStatusByte: Command has invalid command code" << std::endl; return INVALID_COMMAND_CODE; case 3: + sif::error << "IMTQHandler::parseStatusByte: Command has missing parameter" << std::endl; return PARAMETER_MISSING; case 4: + sif::error << "IMTQHandler::parseStatusByte: Command has invalid parameter" << std::endl; return PARAMETER_INVALID; case 5: + sif::error << "IMTQHandler::parseStatusByte: CC unavailable" << std::endl; return CC_UNAVAILABLE; case 7: + sif::error << "IMTQHandler::parseStatusByte: IMQT replied internal processing error" + << std::endl; return INTERNAL_PROCESSING_ERROR; default: sif::error << "IMTQHandler::parseStatusByte: CMD Error field contains unknown error code " @@ -223,3 +245,30 @@ void IMTQHandler::setModeNormal() { mode = MODE_NORMAL; } + + +void IMTQHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId) { + + ReturnValue_t result = RETURN_OK; + + if (wiretappingMode == RAW) { + /* Data already sent in doGetRead() */ + return result; + } + + DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId); + if (iter == deviceReplyMap.end()) { + sif::debug << "IMTQHandler::handleDeviceTM: Unknown reply id" << std::endl; + return; + } + MessageQueueId_t queueId = iter->second.command->second.sendReplyTo; + + if (queueId == NO_COMMANDER) { + return; + } + + result = actionHelper.reportData(queueId, replyId, data, dataSize); + if (result != RETURN_OK) { + sif::debug << "IMTQHandler::handleDeviceTM: Failed to report data" << std::endl; + } +} diff --git a/mission/devices/IMTQHandler.h b/mission/devices/IMTQHandler.h index 21ba770f..2e2a7612 100644 --- a/mission/devices/IMTQHandler.h +++ b/mission/devices/IMTQHandler.h @@ -37,7 +37,6 @@ protected: uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - virtual size_t getNextReplyLength(DeviceCommandId_t commandId) override; private: diff --git a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h index 23ff8b9a..60bd511e 100644 --- a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h +++ b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h @@ -6,6 +6,7 @@ namespace IMTQ { static const DeviceCommandId_t NONE = 0x0; static const DeviceCommandId_t GET_ENG_HK_DATA = 0x1; static const DeviceCommandId_t START_ACTUATION_DIPOLE = 0x2; + static const DeviceCommandId_t GET_COMMANDED_DIPOLE = 0x3; static const uint8_t GET_TEMP_REPLY_SIZE = 2; static const uint8_t CFGR_CMD_SIZE = 3; @@ -13,7 +14,9 @@ namespace IMTQ { static const uint32_t ENG_HK_DATA_SET_ID = GET_ENG_HK_DATA; static const uint8_t SIZE_ENG_HK_COMMAND = 1; + static const uint8_t SIZE_STATUS_REPLY = 2; static const uint8_t SIZE_ENG_HK_DATA_REPLY = 24; + static const uint8_t SIZE_GET_COMMANDED_DIPOLE_REPLY = 8; static const uint8_t MAX_REPLY_SIZE = SIZE_ENG_HK_DATA_REPLY; static const uint8_t MAX_COMMAND_SIZE = 9; @@ -28,6 +31,7 @@ namespace IMTQ { static const uint8_t START_ACTUATION_DIPOLE = 0x6; static const uint8_t SOFTWARE_RESET = 0xAA; static const uint8_t GET_ENG_HK_DATA = 0x4A; + static const uint8_t GET_COMMANDED_DIPOLE = 0x46; }; enum IMTQPoolIds: lp_id_t { diff --git a/tmtc b/tmtc index 986f88e2..3e466f06 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 986f88e2908c6bc555a279b53f11e82d9a8a851c +Subproject commit 3e466f06ef7737f2f1bab8c3d68feb633da76dbc From 986ee977216d4f015ea572b1b61bc994777b5223 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 25 Apr 2021 15:54:48 +0200 Subject: [PATCH 15/42] added wiretapping mode check in handleDeviceTm of PlocHandler --- fsfw | 2 +- fsfw_hal | 2 +- mission/devices/PlocHandler.cpp | 5 +++++ thirdparty/etl | 2 +- tmtc | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fsfw b/fsfw index 42720e6f..e7d24563 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 42720e6f7d64bdd9a1ac0cea5846c9a8cedea0ff +Subproject commit e7d245635047439ca4b5a46d05bf58437a5aa33a diff --git a/fsfw_hal b/fsfw_hal index 14fe3257..a85c0146 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 14fe32572d62db9d19707dc1f9bb6fecb1993b73 +Subproject commit a85c01465bc8687773676f05c5e7eb8af54b25ff diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index f1444488..5b106477 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -388,6 +388,11 @@ void PlocHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCom ReturnValue_t result = RETURN_OK; + if (wiretappingMode == RAW) { + /* Data already sent in doGetRead() */ + return result; + } + DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId); if (iter == deviceReplyMap.end()) { sif::debug << "PlocHandler::handleDeviceTM: Unknown reply id" << std::endl; diff --git a/thirdparty/etl b/thirdparty/etl index ae06e641..c308dc42 160000 --- a/thirdparty/etl +++ b/thirdparty/etl @@ -1 +1 @@ -Subproject commit ae06e6417702b770c49289c9e7162cb3f4a5a217 +Subproject commit c308dc427b7a34e54f33860fb2e244564b2740b4 diff --git a/tmtc b/tmtc index 73105138..3e466f06 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 73105138050b5661a6cff76e1d64af40981f9c7f +Subproject commit 3e466f06ef7737f2f1bab8c3d68feb633da76dbc From ad48d5888dc5d41d7ab08160dc42feae2381ba57 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 26 Apr 2021 07:56:02 +0200 Subject: [PATCH 16/42] imqt base functions --- mission/devices/IMTQHandler.cpp | 199 +++++++++++++++--- mission/devices/IMTQHandler.h | 41 ++++ .../IMTQHandlerDefinitions.h | 112 ++++++++-- tmtc | 2 +- 4 files changed, 304 insertions(+), 50 deletions(-) diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index 80cc1550..f3d1880a 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -6,7 +6,8 @@ #include IMTQHandler::IMTQHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), engHkDataset(this) { + DeviceHandlerBase(objectId, comIF, comCookie), engHkDataset(this), calMtmMeasurementSet( + this), rawMtmMeasurementSet(this) { if (comCookie == NULL) { sif::error << "IMTQHandler: Invalid com cookie" << std::endl; } @@ -29,7 +30,28 @@ void IMTQHandler::doShutDown(){ ReturnValue_t IMTQHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - *id = IMTQ::GET_ENG_HK_DATA; + switch (communicationStep) { + case CommunicationStep::GET_ENG_HK_DATA: + *id = IMTQ::GET_ENG_HK_DATA; + communicationStep = CommunicationStep::START_MTM_MEASUREMENT; + break; + case CommunicationStep::START_MTM_MEASUREMENT: + *id = IMTQ::START_MTM_MEASUREMENT; + communicationStep = CommunicationStep::GET_CAL_MTM_MEASUREMENT; + break; + case CommunicationStep::GET_CAL_MTM_MEASUREMENT: + *id = IMTQ::GET_CAL_MTM_MEASUREMENT; + communicationStep = CommunicationStep::GET_RAW_MTM_MEASUREMENT; + break; + case CommunicationStep::GET_RAW_MTM_MEASUREMENT: + *id = IMTQ::GET_RAW_MTM_MEASUREMENT; + communicationStep = CommunicationStep::GET_ENG_HK_DATA; + break; + default: + sif::debug << "IMTQHandler::buildNormalDeviceCommand: Invalid communication step" + << std::endl; + break; + } return buildCommandFromCommand(*id, NULL, 0); } @@ -69,6 +91,24 @@ ReturnValue_t IMTQHandler::buildCommandFromCommand( rawPacketLen = 1; return RETURN_OK; } + case(IMTQ::START_MTM_MEASUREMENT): { + commandBuffer[0] = IMTQ::CC::START_MTM_MEASUREMENT; + rawPacket = commandBuffer; + rawPacketLen = 1; + return RETURN_OK; + } + case(IMTQ::GET_CAL_MTM_MEASUREMENT): { + commandBuffer[0] = IMTQ::CC::GET_CAL_MTM_MEASUREMENT; + rawPacket = commandBuffer; + rawPacketLen = 1; + return RETURN_OK; + } + case(IMTQ::GET_RAW_MTM_MEASUREMENT): { + commandBuffer[0] = IMTQ::CC::GET_RAW_MTM_MEASUREMENT; + rawPacket = commandBuffer; + rawPacketLen = 1; + return RETURN_OK; + } default: return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; } @@ -81,7 +121,13 @@ void IMTQHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(IMTQ::GET_ENG_HK_DATA, 1, &engHkDataset, IMTQ::SIZE_ENG_HK_DATA_REPLY); this->insertInCommandAndReplyMap(IMTQ::GET_COMMANDED_DIPOLE, 1, nullptr, - IMTQ::SIZE_ENG_HK_DATA_REPLY); + IMTQ::SIZE_GET_COMMANDED_DIPOLE_REPLY); + this->insertInCommandAndReplyMap(IMTQ::START_MTM_MEASUREMENT, 1, nullptr, + IMTQ::SIZE_STATUS_REPLY); + this->insertInCommandAndReplyMap(IMTQ::GET_CAL_MTM_MEASUREMENT, 1, &calMtmMeasurementSet, + IMTQ::SIZE_GET_CAL_MTM_MEASUREMENT); + this->insertInCommandAndReplyMap(IMTQ::GET_RAW_MTM_MEASUREMENT, 1, &rawMtmMeasurementSet, + IMTQ::SIZE_GET_RAW_MTM_MEASUREMENT); } ReturnValue_t IMTQHandler::scanForReply(const uint8_t *start, @@ -94,6 +140,10 @@ ReturnValue_t IMTQHandler::scanForReply(const uint8_t *start, *foundLen = IMTQ::SIZE_STATUS_REPLY; *foundId = IMTQ::START_ACTUATION_DIPOLE; break; + case(IMTQ::CC::START_MTM_MEASUREMENT): + *foundLen = IMTQ::SIZE_STATUS_REPLY; + *foundId = IMTQ::START_MTM_MEASUREMENT; + break; case(IMTQ::CC::GET_ENG_HK_DATA): *foundLen = IMTQ::SIZE_ENG_HK_DATA_REPLY; *foundId = IMTQ::GET_ENG_HK_DATA; @@ -102,6 +152,14 @@ ReturnValue_t IMTQHandler::scanForReply(const uint8_t *start, *foundLen = IMTQ::SIZE_GET_COMMANDED_DIPOLE_REPLY; *foundId = IMTQ::GET_COMMANDED_DIPOLE; break; + case(IMTQ::CC::GET_CAL_MTM_MEASUREMENT): + *foundLen = IMTQ::SIZE_GET_CAL_MTM_MEASUREMENT; + *foundId = IMTQ::GET_CAL_MTM_MEASUREMENT; + break; + case(IMTQ::CC::GET_RAW_MTM_MEASUREMENT): + *foundLen = IMTQ::SIZE_GET_RAW_MTM_MEASUREMENT; + *foundId = IMTQ::GET_RAW_MTM_MEASUREMENT; + break; default: sif::debug << "IMTQHandler::scanForReply: Reply contains invalid command code" << std::endl; result = IGNORE_REPLY_DATA; @@ -124,7 +182,8 @@ ReturnValue_t IMTQHandler::interpretDeviceReply(DeviceCommandId_t id, switch (id) { case (IMTQ::START_ACTUATION_DIPOLE): - // Replies only the status byte which is already handled with parseStatusByte + case (IMTQ::START_MTM_MEASUREMENT): + /* Replies only the status byte which is already handled with parseStatusByte */ break; case (IMTQ::GET_ENG_HK_DATA): fillEngHkDataset(packet); @@ -132,6 +191,12 @@ ReturnValue_t IMTQHandler::interpretDeviceReply(DeviceCommandId_t id, case (IMTQ::GET_COMMANDED_DIPOLE): handleGetCommandedDipoleReply(packet); break; + case (IMTQ::GET_CAL_MTM_MEASUREMENT): + fillCalibratedMtmDataset(packet); + break; + case (IMTQ::GET_RAW_MTM_MEASUREMENT): + fillRawMtmDataset(packet); + break; default: { sif::debug << "IMTQHandler::interpretDeviceReply: Unknown device reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; @@ -152,18 +217,31 @@ uint32_t IMTQHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ ReturnValue_t IMTQHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { + /** Entries of engineering housekeeping dataset */ localDataPoolMap.emplace(IMTQ::DIGITAL_VOLTAGE_MV, new PoolEntry( { 0 })); localDataPoolMap.emplace(IMTQ::ANALOG_VOLTAGE_MV, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT_A, new PoolEntry( { 0 })); - localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT_A, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::DIGITAL_CURRENT, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ANALOG_CURRENT, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_X_CURRENT, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Y_CURRENT, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::COIL_Z_CURRENT, new PoolEntry( { 0 })); localDataPoolMap.emplace(IMTQ::COIL_X_TEMPERATURE, new PoolEntry( { 0 })); localDataPoolMap.emplace(IMTQ::COIL_Y_TEMPERATURE, new PoolEntry( { 0 })); localDataPoolMap.emplace(IMTQ::COIL_Z_TEMPERATURE, new PoolEntry( { 0 })); localDataPoolMap.emplace(IMTQ::MCU_TEMPERATURE, new PoolEntry( { 0 })); + /** Entries of calibrated MTM measurement dataset */ + localDataPoolMap.emplace(IMTQ::MTM_CAL_X, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MTM_CAL_Y, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MTM_CAL_Z, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ACTUATION_CAL_STATUS, new PoolEntry( { 0 })); + + /** Entries of raw MTM measurement dataset */ + localDataPoolMap.emplace(IMTQ::MTM_RAW_X, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MTM_RAW_Y, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::MTM_RAW_Z, new PoolEntry( { 0 })); + localDataPoolMap.emplace(IMTQ::ACTUATION_RAW_STATUS, new PoolEntry( { 0 })); + return HasReturnvaluesIF::RETURN_OK; } @@ -200,36 +278,36 @@ ReturnValue_t IMTQHandler::parseStatusByte(const uint8_t* packet) { void IMTQHandler::fillEngHkDataset(const uint8_t* packet) { uint8_t offset = 2; - engHkDataset.digitalVoltageMv = *(packet + offset + 1) | *(packet + offset); + engHkDataset.digitalVoltageMv = *(packet + offset + 1) << 8 | *(packet + offset); offset += 2; - engHkDataset.analogVoltageMv = *(packet + offset + 1) | *(packet + offset); + engHkDataset.analogVoltageMv = *(packet + offset + 1) << 8 | *(packet + offset); offset += 2; - engHkDataset.digitalCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + engHkDataset.digitalCurrentmA = (*(packet + offset + 1) << 8 | *(packet + offset)) * 0.1; offset += 2; - engHkDataset.analogCurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + engHkDataset.analogCurrentmA = (*(packet + offset + 1) << 8 | *(packet + offset)) * 0.1; offset += 2; - engHkDataset.coilXcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + engHkDataset.coilXCurrentmA = (*(packet + offset + 1) << 8 | *(packet + offset)) * 0.1; offset += 2; - engHkDataset.coilYcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + engHkDataset.coilYCurrentmA = (*(packet + offset + 1) << 8 | *(packet + offset)) * 0.1; offset += 2; - engHkDataset.coilZcurrentA = (*(packet + offset + 1) | *(packet + offset)) * 0.0001; + engHkDataset.coilZCurrentmA = (*(packet + offset + 1) << 8 | *(packet + offset)) * 0.1; offset += 2; - engHkDataset.coilXTemperature = (*(packet + offset + 1) | *(packet + offset)); + engHkDataset.coilXTemperature = (*(packet + offset + 1) << 8 | *(packet + offset)); offset += 2; - engHkDataset.coilYTemperature = (*(packet + offset + 1) | *(packet + offset)); + engHkDataset.coilYTemperature = (*(packet + offset + 1) << 8 | *(packet + offset)); offset += 2; - engHkDataset.coilZTemperature = (*(packet + offset + 1) | *(packet + offset)); + engHkDataset.coilZTemperature = (*(packet + offset + 1) << 8 | *(packet + offset)); offset += 2; - engHkDataset.mcuTemperature = (*(packet + offset + 1) | *(packet + offset)); + engHkDataset.mcuTemperature = (*(packet + offset + 1) << 8 | *(packet + offset)); #if OBSW_VERBOSE_LEVEL >= 1 && IMQT_DEBUG == 1 sif::info << "IMTQ digital voltage: " << engHkDataset.digitalVoltageMv << " mV" << std::endl; sif::info << "IMTQ analog voltage: " << engHkDataset.analogVoltageMv << " mV" << std::endl; - sif::info << "IMTQ digital current: " << engHkDataset.digitalCurrentA << " A" << std::endl; - sif::info << "IMTQ analog current: " << engHkDataset.analogCurrentA << " A" << std::endl; - sif::info << "IMTQ coil X current: " << engHkDataset.coilXcurrentA << " A" << std::endl; - sif::info << "IMTQ coil Y current: " << engHkDataset.coilYcurrentA << " A" << std::endl; - sif::info << "IMTQ coil Z current: " << engHkDataset.coilZcurrentA << " A" << std::endl; + sif::info << "IMTQ digital current: " << engHkDataset.digitalCurrentmA << " mA" << std::endl; + sif::info << "IMTQ analog current: " << engHkDataset.analogCurrentmA << " mA" << std::endl; + sif::info << "IMTQ coil X current: " << engHkDataset.coilXCurrentmA << " mA" << std::endl; + sif::info << "IMTQ coil Y current: " << engHkDataset.coilYCurrentmA << " mA" << std::endl; + sif::info << "IMTQ coil Z current: " << engHkDataset.coilZCurrentmA << " mA" << std::endl; sif::info << "IMTQ coil X temperature: " << engHkDataset.coilXTemperature << " °C" << std::endl; sif::info << "IMTQ coil Y temperature: " << engHkDataset.coilYTemperature << " °C" @@ -245,15 +323,11 @@ void IMTQHandler::setModeNormal() { mode = MODE_NORMAL; } - - void IMTQHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId) { - ReturnValue_t result = RETURN_OK; - if (wiretappingMode == RAW) { /* Data already sent in doGetRead() */ - return result; + return; } DeviceReplyMap::iterator iter = deviceReplyMap.find(replyId); @@ -267,8 +341,71 @@ void IMTQHandler::handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCom return; } - result = actionHelper.reportData(queueId, replyId, data, dataSize); + ReturnValue_t result = actionHelper.reportData(queueId, replyId, data, dataSize); if (result != RETURN_OK) { sif::debug << "IMTQHandler::handleDeviceTM: Failed to report data" << std::endl; + return; } } + +void IMTQHandler::handleGetCommandedDipoleReply(const uint8_t* packet) { + uint8_t tmData[6]; + /* Switching endianess of received dipole values */ + tmData[0] = *(packet + 3); + tmData[1] = *(packet + 2); + tmData[2] = *(packet + 5); + tmData[3] = *(packet + 4); + tmData[4] = *(packet + 7); + tmData[5] = *(packet + 6); + handleDeviceTM(tmData, sizeof(tmData), IMTQ::GET_COMMANDED_DIPOLE); +} + +void IMTQHandler::fillCalibratedMtmDataset(const uint8_t* packet) { + int8_t offset = 2; + calMtmMeasurementSet.mtmXnT = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset); + offset += 4; + calMtmMeasurementSet.mtmYnT = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset); + offset += 4; + calMtmMeasurementSet.mtmZnT = *(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset); + offset += 4; + calMtmMeasurementSet.coilActuationStatus = (*(packet + offset + 3) << 24) + | (*(packet + offset + 2) << 16) | (*(packet + offset + 1) << 8) | (*(packet + offset)); +#if OBSW_VERBOSE_LEVEL >= 1 && IMQT_DEBUG == 1 + sif::info << "IMTQ calibrated MTM measurement X: " << calMtmMeasurementSet.mtmXnT << " nT" + << std::endl; + sif::info << "IMTQ calibrated MTM measurement Y: " << calMtmMeasurementSet.mtmYnT << " nT" + << std::endl; + sif::info << "IMTQ calibrated MTM measurement Z: " << calMtmMeasurementSet.mtmZnT << " nT" + << std::endl; + sif::info << "IMTQ coil actuation status during MTM measurement: " + << (unsigned int) calMtmMeasurementSet.coilActuationStatus.value << std::endl; +#endif +} + +void IMTQHandler::fillRawMtmDataset(const uint8_t* packet) { + int8_t offset = 2; + rawMtmMeasurementSet.mtmXnT = (*(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset)) * 7.5; + offset += 4; + rawMtmMeasurementSet.mtmYnT = (*(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset)) * 7.5; + offset += 4; + rawMtmMeasurementSet.mtmZnT = (*(packet + offset + 3) << 24 | *(packet + offset + 2) << 16 + | *(packet + offset + 1) << 8 | *(packet + offset)) * 7.5; + offset += 4; + rawMtmMeasurementSet.coilActuationStatus = (*(packet + offset + 3) << 24) + | (*(packet + offset + 2) << 16) | (*(packet + offset + 1) << 8) | (*(packet + offset)); +#if OBSW_VERBOSE_LEVEL >= 1 && IMQT_DEBUG == 1 + sif::info << "IMTQ raw MTM measurement X: " << rawMtmMeasurementSet.mtmXnT << " nT" + << std::endl; + sif::info << "IMTQ raw MTM measurement Y: " << rawMtmMeasurementSet.mtmYnT << " nT" + << std::endl; + sif::info << "IMTQ raw MTM measurement Z: " << rawMtmMeasurementSet.mtmZnT << " nT" + << std::endl; + sif::info << "IMTQ coil actuation status during MTM measurement: " + << (unsigned int) rawMtmMeasurementSet.coilActuationStatus.value << std::endl; +#endif +} diff --git a/mission/devices/IMTQHandler.h b/mission/devices/IMTQHandler.h index 2e2a7612..be680560 100644 --- a/mission/devices/IMTQHandler.h +++ b/mission/devices/IMTQHandler.h @@ -52,9 +52,20 @@ private: IMTQ::EngHkDataset engHkDataset; + IMTQ::CalibratedMtmMeasurementSet calMtmMeasurementSet; + IMTQ::RawMtmMeasurementSet rawMtmMeasurementSet; uint8_t commandBuffer[IMTQ::MAX_COMMAND_SIZE]; + enum class CommunicationStep { + GET_ENG_HK_DATA, + START_MTM_MEASUREMENT, + GET_CAL_MTM_MEASUREMENT, + GET_RAW_MTM_MEASUREMENT + }; + + CommunicationStep communicationStep = CommunicationStep::GET_ENG_HK_DATA; + /** * @brief Each reply contains a status byte giving information about a request. This function * parses this byte and returns the associated failure message. @@ -72,6 +83,36 @@ private: * */ void fillEngHkDataset(const uint8_t* packet); + + /** + * @brief This function sends a command reply to the requesting queue. + * + * @param data Pointer to the data to send. + * @param dataSize Size of the data to send. + * @param relplyId Reply id which will be inserted at the beginning of the action message. + */ + void handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId); + + /** + * @brief This function handles the reply containing the commanded dipole. + * + * @param packet Pointer to the reply data. + */ + void handleGetCommandedDipoleReply(const uint8_t* packet); + + /** + * @brief This function parses the reply containing the calibrated MTM measurement and writes + * the values to the appropriate dataset. + * @param packet Pointer to the reply data. + */ + void fillCalibratedMtmDataset(const uint8_t* packet); + + /** + * @brief This function copies the raw MTM measurements to the MTM raw dataset. + * @param packet Pointer to the reply data requested with the GET_RAW_MTM_MEASUREMENTS + * command. + */ + void fillRawMtmDataset(const uint8_t* packet); }; #endif /* MISSION_DEVICES_IMTQHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h index 60bd511e..23b5982a 100644 --- a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h +++ b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h @@ -7,49 +7,71 @@ namespace IMTQ { static const DeviceCommandId_t GET_ENG_HK_DATA = 0x1; static const DeviceCommandId_t START_ACTUATION_DIPOLE = 0x2; static const DeviceCommandId_t GET_COMMANDED_DIPOLE = 0x3; + /** Generates new measurement of the magnetic field */ + static const DeviceCommandId_t START_MTM_MEASUREMENT = 0x4; + /** Requests the calibrated magnetometer measurement */ + static const DeviceCommandId_t GET_CAL_MTM_MEASUREMENT = 0x5; + /** Requests the raw values measured by the built-in MTM XEN1210 */ + static const DeviceCommandId_t GET_RAW_MTM_MEASUREMENT = 0x6; static const uint8_t GET_TEMP_REPLY_SIZE = 2; static const uint8_t CFGR_CMD_SIZE = 3; static const uint8_t POINTER_REG_SIZE = 1; static const uint32_t ENG_HK_DATA_SET_ID = GET_ENG_HK_DATA; + static const uint32_t CAL_MTM_SET = GET_CAL_MTM_MEASUREMENT; + static const uint8_t SIZE_ENG_HK_COMMAND = 1; static const uint8_t SIZE_STATUS_REPLY = 2; static const uint8_t SIZE_ENG_HK_DATA_REPLY = 24; static const uint8_t SIZE_GET_COMMANDED_DIPOLE_REPLY = 8; + static const uint8_t SIZE_GET_CAL_MTM_MEASUREMENT = 15; + static const uint8_t SIZE_GET_RAW_MTM_MEASUREMENT = 15; static const uint8_t MAX_REPLY_SIZE = SIZE_ENG_HK_DATA_REPLY; static const uint8_t MAX_COMMAND_SIZE = 9; - static const uint8_t POOL_ENTRIES = 11; + static const uint8_t ENG_HK_SET_POOL_ENTRIES = 11; + static const uint8_t CAL_MTM_POOL_ENTRIES = 4; /** * Command code definitions. Each command or reply of an IMTQ request will begin with one of * the following command codes. */ namespace CC { + static const uint8_t START_MTM_MEASUREMENT = 0x4; static const uint8_t START_ACTUATION_DIPOLE = 0x6; static const uint8_t SOFTWARE_RESET = 0xAA; static const uint8_t GET_ENG_HK_DATA = 0x4A; static const uint8_t GET_COMMANDED_DIPOLE = 0x46; + static const uint8_t GET_RAW_MTM_MEASUREMENT = 0x42; + static const uint8_t GET_CAL_MTM_MEASUREMENT = 0x43; }; enum IMTQPoolIds: lp_id_t { DIGITAL_VOLTAGE_MV, ANALOG_VOLTAGE_MV, - DIGITAL_CURRENT_A, - ANALOG_CURRENT_A, - COIL_X_CURRENT_A, - COIL_Y_CURRENT_A, - COIL_Z_CURRENT_A, + DIGITAL_CURRENT, + ANALOG_CURRENT, + COIL_X_CURRENT, + COIL_Y_CURRENT, + COIL_Z_CURRENT, COIL_X_TEMPERATURE, COIL_Y_TEMPERATURE, COIL_Z_TEMPERATURE, - MCU_TEMPERATURE + MCU_TEMPERATURE, + MTM_CAL_X, + MTM_CAL_Y, + MTM_CAL_Z, + ACTUATION_CAL_STATUS, + MTM_RAW_X, + MTM_RAW_Y, + MTM_RAW_Z, + ACTUATION_RAW_STATUS }; class EngHkDataset: - public StaticLocalDataSet { + public StaticLocalDataSet { public: EngHkDataset(HasLocalDataPoolIF* owner): @@ -64,16 +86,16 @@ public: DIGITAL_VOLTAGE_MV, this); lp_var_t analogVoltageMv = lp_var_t(sid.objectId, ANALOG_VOLTAGE_MV, this); - lp_var_t digitalCurrentA = lp_var_t(sid.objectId, - DIGITAL_CURRENT_A, this); - lp_var_t analogCurrentA = lp_var_t(sid.objectId, - ANALOG_CURRENT_A, this); - lp_var_t coilXcurrentA = lp_var_t(sid.objectId, - COIL_X_CURRENT_A, this); - lp_var_t coilYcurrentA = lp_var_t(sid.objectId, - COIL_Y_CURRENT_A, this); - lp_var_t coilZcurrentA = lp_var_t(sid.objectId, - COIL_Z_CURRENT_A, this); + lp_var_t digitalCurrentmA = lp_var_t(sid.objectId, + DIGITAL_CURRENT, this); + lp_var_t analogCurrentmA = lp_var_t(sid.objectId, + ANALOG_CURRENT, this); + lp_var_t coilXCurrentmA = lp_var_t(sid.objectId, + COIL_X_CURRENT, this); + lp_var_t coilYCurrentmA = lp_var_t(sid.objectId, + COIL_Y_CURRENT, this); + lp_var_t coilZCurrentmA = lp_var_t(sid.objectId, + COIL_Z_CURRENT, this); /** All temperatures in [°C] */ lp_var_t coilXTemperature = lp_var_t(sid.objectId, COIL_X_TEMPERATURE, this); @@ -85,6 +107,60 @@ public: MCU_TEMPERATURE, this); }; +/** + * @brief This dataset holds the raw MTM measurements. + */ +class CalibratedMtmMeasurementSet: + public StaticLocalDataSet { +public: + + CalibratedMtmMeasurementSet(HasLocalDataPoolIF* owner): + StaticLocalDataSet(owner, CAL_MTM_SET) { + } + + CalibratedMtmMeasurementSet(object_id_t objectId): + StaticLocalDataSet(sid_t(objectId, CAL_MTM_SET)) { + } + + /** The unit of all measurements is nT */ + lp_var_t mtmXnT = lp_var_t(sid.objectId, + MTM_CAL_X, this); + lp_var_t mtmYnT = lp_var_t(sid.objectId, + MTM_CAL_Y, this); + lp_var_t mtmZnT = lp_var_t(sid.objectId, + MTM_CAL_Z, this); + /** 1 if coils were actuating during measurement otherwise 0 */ + lp_var_t coilActuationStatus = lp_var_t(sid.objectId, + ACTUATION_CAL_STATUS, this); +}; + +/** + * @brief This dataset holds the last calibrated MTM measurement. + */ +class RawMtmMeasurementSet: + public StaticLocalDataSet { +public: + + RawMtmMeasurementSet(HasLocalDataPoolIF* owner): + StaticLocalDataSet(owner, CAL_MTM_SET) { + } + + RawMtmMeasurementSet(object_id_t objectId): + StaticLocalDataSet(sid_t(objectId, CAL_MTM_SET)) { + } + + /** The unit of all measurements is nT */ + lp_var_t mtmXnT = lp_var_t(sid.objectId, + MTM_RAW_X, this); + lp_var_t mtmYnT = lp_var_t(sid.objectId, + MTM_RAW_Y, this); + lp_var_t mtmZnT = lp_var_t(sid.objectId, + MTM_RAW_Z, this); + /** 1 if coils were actuating during measurement otherwise 0 */ + lp_var_t coilActuationStatus = lp_var_t(sid.objectId, + ACTUATION_RAW_STATUS, this); +}; + /** * @brief This class can be used to ease the generation of an action message commanding the * IMTQHandler to configure the magnettorquer with the desired dipoles. diff --git a/tmtc b/tmtc index 3e466f06..4d2b7a61 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 3e466f06ef7737f2f1bab8c3d68feb633da76dbc +Subproject commit 4d2b7a61509a41e67cf62ecaa2864bba3acd9ef4 From cdde3e29a8a807dae6cedc62324f6f94cbe444b8 Mon Sep 17 00:00:00 2001 From: IRS Cleanroom Laptop Date: Mon, 26 Apr 2021 11:28:19 +0200 Subject: [PATCH 17/42] corrections in plocHandler, endianness --- .../Q7S/win_path_helper_xilinx_tools.sh | 10 +++++-- fsfw_hal | 2 +- mission/devices/PlocHandler.cpp | 19 ++++++++++-- mission/devices/PlocHandler.h | 5 ++++ .../devicedefinitions/PlocDefinitions.h | 29 +++++++++---------- tmtc | 2 +- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh b/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh index c9bcc54a..d0a24dba 100644 --- a/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh +++ b/cmake/scripts/Q7S/win_path_helper_xilinx_tools.sh @@ -1,5 +1,9 @@ #!/bin/sh -export PATH=$PATH:"/c/Xilinx/SDK/2018.2/gnu/aarch32/nt/gcc-arm-linux-gnueabi/bin" -export CROSS_COMPILE="arm-linux-gnueabihf" +export PATH=/c/Users/integration/Documents/EIVE/gcc-arm-linux-gnueabi/bin:${PATH} +export CROSS_COMPILE=arm-linux-gnueabihf -export Q7S_SYSROOT="/c/Xilinx/SDK/2018.2/gnu/aarch32/nt/gcc-arm-linux-gnueabi/arm-linux-gnueabihf/libc" +export CMAKE_ASM_COMPILER=arm-linux-gnueabihf-as +export CMAKE_C_COMPILER=arm-linux-gnueabihf-gcc +export CMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++ + +export Q7S_SYSROOT=/c/Users/integration/Documents/EIVE/cortexa9hf-neon-xiphos-linux-gnueabi diff --git a/fsfw_hal b/fsfw_hal index 7a3190e5..c47d3996 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 7a3190e5b6980ad2addc5e8a76d21994b542f0e0 +Subproject commit c47d39964fcdc08f6ab93a5e6b6e3b63d4a21abb diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index f1444488..427eac4c 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -151,7 +151,10 @@ ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, | *(commandData + 2) << 8 | *(commandData + 3); const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 | *(commandData + 6) << 8 | *(commandData + 7); - PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData); + if (subsequenceCount != 0) { + subsequenceCount++; + } + PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, subsequenceCount); if (tcMemWrite.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemWriteCommand: Command too big" << std::endl; return RETURN_FAILED; @@ -167,7 +170,10 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen) { const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 | *(commandData + 3); - PLOC::TcMemRead tcMemRead(memoryAddress); + if (subsequenceCount != 0) { + subsequenceCount++; + } + PLOC::TcMemRead tcMemRead(memoryAddress, subsequenceCount); if (tcMemRead.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemReadCommand: Command too big" << std::endl; return RETURN_FAILED; @@ -176,6 +182,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, rawPacket = commandBuffer; rawPacketLen = tcMemRead.getFullSize(); nextReplyId = PLOC::ACK_REPORT; + return RETURN_OK; } @@ -183,7 +190,7 @@ ReturnValue_t PlocHandler::verifyPacket(const uint8_t* start, size_t foundLen) { uint16_t receivedCrc = *(start + foundLen - 2) << 8 | *(start + foundLen - 1); - uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2, 0); + uint16_t recalculatedCrc = CRC::crc16ccitt(start, foundLen - 2); if (receivedCrc != recalculatedCrc) { return CRC_FAILURE; @@ -221,10 +228,12 @@ ReturnValue_t PlocHandler::handleAckReport(const uint8_t* data) { disableAllReplies(); nextReplyId = PLOC::NONE; result = IGNORE_REPLY_DATA; + subsequenceCount = ((*(data + 2) & 0x3F) << 8) | *(data + 3); break; } case PLOC::APID_ACK_SUCCESS: { setNextReplyId(); + subsequenceCount = ((*(data + 2) & 0x3F) << 8) | *(data + 3); break; } default: { @@ -252,6 +261,7 @@ ReturnValue_t PlocHandler::handleExecutionReport(const uint8_t* data) { switch (apid) { case (PLOC::APID_EXE_SUCCESS): { + subsequenceCount = ((*(data + 2) & 0x3F) << 8) | *(data + 3); break; } case (PLOC::APID_EXE_FAILURE): { @@ -268,6 +278,7 @@ ReturnValue_t PlocHandler::handleExecutionReport(const uint8_t* data) { sendFailureReport(PLOC::EXE_REPORT, RECEIVED_EXE_FAILURE); disableExeReportReply(); result = IGNORE_REPLY_DATA; + subsequenceCount = ((*(data + 2) & 0x3F) << 8) | *(data + 3); break; } default: { @@ -298,6 +309,8 @@ ReturnValue_t PlocHandler::handleMemoryReadReport(const uint8_t* data) { nextReplyId = PLOC::EXE_REPORT; + subsequenceCount = ((*(data + 2) & 0x3F) << 8) | *(data + 3); + return result; } diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index b241c838..fcb423d3 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -65,6 +65,11 @@ private: uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; + /** + * This object counts takes the subsequence count of the PLOC space packets. + */ + uint16_t subsequenceCount = 0; + /** * This variable is used to store the id of the next reply to receive. This is necessary * because the PLOC sends as reply to each command at least one acknowledgment and execution diff --git a/mission/devices/devicedefinitions/PlocDefinitions.h b/mission/devices/devicedefinitions/PlocDefinitions.h index b7378a8a..f5add451 100644 --- a/mission/devices/devicedefinitions/PlocDefinitions.h +++ b/mission/devices/devicedefinitions/PlocDefinitions.h @@ -63,10 +63,10 @@ namespace PLOC { * * @param memAddr The memory address to read from. */ - TcMemRead(const uint32_t memAddr) : - SpacePacket(LENGTH_TC_MEM_READ - 1, true, APID_TC_MEM_READ) { - fillPacketDataField(&memAddr); - } + TcMemRead(const uint32_t memAddr, uint16_t sequenceCount) : + SpacePacket(LENGTH_TC_MEM_READ - 1, true, APID_TC_MEM_READ, sequenceCount) { + fillPacketDataField(&memAddr); + } private: @@ -80,22 +80,21 @@ namespace PLOC { size_t serializedSize = 0; uint8_t* memoryAddressPos = this->localData.fields.buffer; SerializeAdapter::serialize(memAddrPtr, &memoryAddressPos, &serializedSize, - sizeof(*memAddrPtr), SerializeIF::Endianness::BIG); + sizeof(*memAddrPtr), SerializeIF::Endianness::LITTLE); /* Add memLen to packet data field */ - this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; - this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 1; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 0; /* Calculate crc */ uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, - sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE, 0); + sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_READ - CRC_SIZE); /* Add crc to packet data field of space packet */ serializedSize = 0; uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, sizeof(crc), SerializeIF::Endianness::BIG); - memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); } static const uint8_t OFFSET_MEM_LEN_FIELD = 4; @@ -117,9 +116,10 @@ namespace PLOC { * * @param memAddr The PLOC memory address where to write to. * @param memoryData The data to write to the specified memory address. + * @param sequenceCount The subsequence count. Must be incremented with each new packet. */ - TcMemWrite(const uint32_t memAddr, const uint32_t memoryData) : - SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, APID_TC_MEM_WRITE) { + TcMemWrite(const uint32_t memAddr, const uint32_t memoryData, uint16_t sequenceCount) : + SpacePacket(LENGTH_TC_MEM_WRITE - 1, true, APID_TC_MEM_WRITE, sequenceCount) { fillPacketDataField(&memAddr, &memoryData); } @@ -140,8 +140,8 @@ namespace PLOC { sizeof(*memAddrPtr), SerializeIF::Endianness::BIG); /* Add memLen to packet data field */ - this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 0; - this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 1; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD] = 1; + this->localData.fields.buffer[OFFSET_MEM_LEN_FIELD + 1] = 0; /* Add memData to packet data field */ serializedSize = 0; @@ -151,14 +151,13 @@ namespace PLOC { /* Calculate crc */ uint16_t crc = CRC::crc16ccitt(this->localData.byteStream, - sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE, 0); + sizeof(CCSDSPrimaryHeader) + LENGTH_TC_MEM_WRITE - CRC_SIZE); serializedSize = 0; uint8_t* crcPos = this->localData.fields.buffer + CRC_OFFSET; /* Add crc to packet data field of space packet */ SerializeAdapter::serialize(&crc, &crcPos, &serializedSize, sizeof(crc), SerializeIF::Endianness::BIG); - memcpy(this->localData.fields.buffer + CRC_OFFSET, &crc, sizeof(crc)); } /** Offsets from base address of packet data field */ diff --git a/tmtc b/tmtc index 79e897b0..b464648f 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 79e897b0353acacf0f986f22f57e9cd8cf30a0da +Subproject commit b464648f53b8b9b41f1ee00c94c095c55ee673e1 From 4e8a6b65ec7cf1e199fbf3b16f03dff4cebd6f8e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 26 Apr 2021 14:25:23 +0200 Subject: [PATCH 18/42] self test wip --- mission/devices/IMTQHandler.cpp | 5 +++++ mission/devices/IMTQHandler.h | 1 + mission/devices/devicedefinitions/IMTQHandlerDefinitions.h | 1 + 3 files changed, 7 insertions(+) diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index f3d1880a..0e92a6c1 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -21,6 +21,7 @@ void IMTQHandler::doStartUp(){ if(mode == _MODE_START_UP){ //TODO: Set to MODE_ON again setMode(MODE_NORMAL); + communicationStep = CommunicationStep::SELT_TEST; } } @@ -31,6 +32,10 @@ void IMTQHandler::doShutDown(){ ReturnValue_t IMTQHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { switch (communicationStep) { + case CommunicationStep::SELF_TEST: + *id = IMTQ::SELF_TEST; + communicationStep = CommunicationStep::GET_ENG_HK_DATA; + break; case CommunicationStep::GET_ENG_HK_DATA: *id = IMTQ::GET_ENG_HK_DATA; communicationStep = CommunicationStep::START_MTM_MEASUREMENT; diff --git a/mission/devices/IMTQHandler.h b/mission/devices/IMTQHandler.h index be680560..e162c1c6 100644 --- a/mission/devices/IMTQHandler.h +++ b/mission/devices/IMTQHandler.h @@ -58,6 +58,7 @@ private: uint8_t commandBuffer[IMTQ::MAX_COMMAND_SIZE]; enum class CommunicationStep { + SELF_TEST, GET_ENG_HK_DATA, START_MTM_MEASUREMENT, GET_CAL_MTM_MEASUREMENT, diff --git a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h index 23b5982a..0cbbb04e 100644 --- a/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h +++ b/mission/devices/devicedefinitions/IMTQHandlerDefinitions.h @@ -13,6 +13,7 @@ namespace IMTQ { static const DeviceCommandId_t GET_CAL_MTM_MEASUREMENT = 0x5; /** Requests the raw values measured by the built-in MTM XEN1210 */ static const DeviceCommandId_t GET_RAW_MTM_MEASUREMENT = 0x6; + static const DeviceCommandId_t SELF_TEST = 0x7; static const uint8_t GET_TEMP_REPLY_SIZE = 2; static const uint8_t CFGR_CMD_SIZE = 3; From ea2b1fbda487e5ca6f5d32660475ea59f73b0e02 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Tue, 27 Apr 2021 17:34:50 +0200 Subject: [PATCH 19/42] basic structure for ILH PLOC control --- bsp_q7s/ObjectFactory.cpp | 15 +++++++++------ fsfwconfig/OBSWConfig.h | 3 ++- mission/devices/PlocHandler.cpp | 17 ++++++++++------- mission/devices/PlocHandler.h | 20 ++++++++++++-------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 9102f79e..0815b81d 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -433,12 +433,6 @@ void ObjectFactory::produce(){ gpioCookie->addGpio(gpioIds::TEST_ID_0, gpioConfigMio0); new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); #elif TE0720 == 1 - /* Configuration for MIO0 on TE0720-03-1CFA */ - GpiodRegular* heaterGpio = new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); - GpioCookie* gpioCookie = new GpioCookie; - gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); - new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, - pcduSwitches::TCS_BOARD_8V_HEATER_IN); UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, PLOC::MAX_REPLY_SIZE); @@ -448,6 +442,15 @@ void ObjectFactory::produce(){ plocHandler->setStartUpImmediately(); #endif +#if TE0720 == 1 && TE0720_HEATER_TEST == 1 + /* Configuration for MIO0 on TE0720-03-1CFA */ + GpiodRegular* heaterGpio = new GpiodRegular(std::string("gpiochip0"), 0, std::string("MIO0"), gpio::IN, 0); + GpioCookie* gpioCookie = new GpioCookie; + gpioCookie->addGpio(gpioIds::HEATER_0, heaterGpio); + new HeaterHandler(objects::HEATER_HANDLER, objects::GPIO_IF, gpioCookie, objects::PCDU_HANDLER, + pcduSwitches::TCS_BOARD_8V_HEATER_IN); +#endif + #if Q7S_ADD_SPI_TEST == 1 new SpiTestClass(objects::SPI_TEST, gpioComIF); #endif diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index f3f7cda3..c1a6c313 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -21,7 +21,8 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 0 +#define TE0720 1 +#define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 #define PDU1_DEBUG 0 diff --git a/mission/devices/PlocHandler.cpp b/mission/devices/PlocHandler.cpp index d8ed395e..b0660ba0 100644 --- a/mission/devices/PlocHandler.cpp +++ b/mission/devices/PlocHandler.cpp @@ -156,6 +156,7 @@ ReturnValue_t PlocHandler::prepareTcMemWriteCommand(const uint8_t * commandData, | *(commandData + 2) << 8 | *(commandData + 3); const uint32_t memoryData = *(commandData + 4) << 24 | *(commandData + 5) << 16 | *(commandData + 6) << 8 | *(commandData + 7); + packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; PLOC::TcMemWrite tcMemWrite(memoryAddress, memoryData, packetSequenceCount); if (tcMemWrite.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemWriteCommand: Command too big" << std::endl; @@ -172,6 +173,7 @@ ReturnValue_t PlocHandler::prepareTcMemReadCommand(const uint8_t * commandData, size_t commandDataLen) { const uint32_t memoryAddress = *(commandData) << 24 | *(commandData + 1) << 16 | *(commandData + 2) << 8 | *(commandData + 3); + packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; PLOC::TcMemRead tcMemRead(memoryAddress, packetSequenceCount); if (tcMemRead.getFullSize() > PLOC::MAX_COMMAND_SIZE) { sif::debug << "PlocHandler::prepareTcMemReadCommand: Command too big" << std::endl; @@ -482,14 +484,15 @@ void PlocHandler::disableExeReportReply() { } ReturnValue_t PlocHandler::checkPacketSequenceCount(const uint8_t* data) { - uint16_t receivedSequenceCount = *(data + 2) << 8 | *(data + 3) & PACKET_SEQUENCE_COUNT_MASK; - if (receivedSequenceCount != ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK)) { - sif::debug << "PlocHandler::checkPacketSequenceCount: Packet sequence count mismatch" + uint16_t receivedSequenceCount = (*(data + 2) << 8 | *(data + 3)) & PACKET_SEQUENCE_COUNT_MASK; + uint16_t expectedPacketSequenceCount = ((packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK); + if (receivedSequenceCount != expectedPacketSequenceCount) { + sif::debug + << "PlocHandler::checkPacketSequenceCount: Packet sequence count mismatch. " << std::endl; - /** The packet sequence count is corrected here to match the sequence count of the PLOC */ - packetSequenceCount = (receivedSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; - return SUBSEQUENCE_COUNT_FAILURE; + sif::debug << "Received sequence count: " << receivedSequenceCount << ". OBSW sequence " + << "count: " << expectedPacketSequenceCount << std::endl; } - packetSequenceCount = (packetSequenceCount + 1) & PACKET_SEQUENCE_COUNT_MASK; + packetSequenceCount = receivedSequenceCount; return RETURN_OK; } diff --git a/mission/devices/PlocHandler.h b/mission/devices/PlocHandler.h index 1b529484..06965d0f 100644 --- a/mission/devices/PlocHandler.h +++ b/mission/devices/PlocHandler.h @@ -8,8 +8,8 @@ /** * @brief This is the device handler for the PLOC. * - * @details The PLOC uses the space packet protocol for communication. On each command the PLOC - * answers at least with one acknowledgment and one execution report. + * @details The PLOC uses the space packet protocol for communication. To each command the PLOC + * answers with at least one acknowledgment and one execution report. * * @author J. Meier */ @@ -53,7 +53,6 @@ private: static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1); //!> Received ACK failure reply from PLOC static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2); //!> Received execution failure reply from PLOC static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3); //!> Received space packet with invalid APID from PLOC - static const ReturnValue_t SUBSEQUENCE_COUNT_FAILURE = MAKE_RETURN_CODE(0xA4); //!> The packet sequence count does not match the expected packet sequence count. There may be one packet lost. static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_HANDLER; @@ -63,7 +62,7 @@ private: static const Event CRC_FAILURE_EVENT = MAKE_EVENT(4, severity::LOW); //!> PLOC reply has invalid crc static const uint16_t APID_MASK = 0x7FF; - static const unit16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; + static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF; uint8_t commandBuffer[PLOC::MAX_COMMAND_SIZE]; @@ -184,14 +183,19 @@ private: void disableExeReportReply(); /** - * @brief This function checks the subsequence count of a received space packet to detect - * lost packets. + * @brief This function checks and increments the packet sequence count of a received space + * packet. * * @param data Pointer to a space packet. * - * @return RETURN_OK if successful, else SUBSEQUENCE_COUNT_FAILURE + * @return RETURN_OK if successful + * + * @details There should be never a case in which a wrong packet sequence count is received + * because the communication scheme between PLOC and OBC always follows a strict + * procedure. Thus this function mainly serves for debugging purposes to detected an + * invalid handling of the packet sequence count. */ - ReturnValue_t checkSubsequenceCount(const uint8_t* data); + ReturnValue_t checkPacketSequenceCount(const uint8_t* data); }; #endif /* MISSION_DEVICES_PLOCHANDLER_H_ */ From ed6eea82c5e5929aff615ec2e3efd8d26f3e6891 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 29 Apr 2021 10:40:11 +0200 Subject: [PATCH 20/42] max1227 wip --- mission/devices/IMTQHandler.cpp | 4 +- mission/devices/Max1227Handler.cpp | 145 ++++++++++++++++++ mission/devices/Max1227Handler.h | 64 ++++++++ .../devicedefinitions/Max1227Definitions.h | 47 ++++++ tmtc | 2 +- 5 files changed, 260 insertions(+), 2 deletions(-) create mode 100644 mission/devices/Max1227Handler.cpp create mode 100644 mission/devices/Max1227Handler.h create mode 100644 mission/devices/devicedefinitions/Max1227Definitions.h diff --git a/mission/devices/IMTQHandler.cpp b/mission/devices/IMTQHandler.cpp index 2051849f..3111c39d 100644 --- a/mission/devices/IMTQHandler.cpp +++ b/mission/devices/IMTQHandler.cpp @@ -33,7 +33,9 @@ ReturnValue_t IMTQHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { switch (communicationStep) { case CommunicationStep::SELF_TEST: - *id = IMTQ::SELF_TEST; +// *id = IMTQ::SELF_TEST; +//TODO: Implementing self test command. On-hold because of issue with humidity in clean +// room communicationStep = CommunicationStep::GET_ENG_HK_DATA; break; case CommunicationStep::GET_ENG_HK_DATA: diff --git a/mission/devices/Max1227Handler.cpp b/mission/devices/Max1227Handler.cpp new file mode 100644 index 00000000..2ecfce9c --- /dev/null +++ b/mission/devices/Max1227Handler.cpp @@ -0,0 +1,145 @@ +#include +#include +#include + +Max1227Handler::Max1227Handler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "Max1227Handler: Invalid com cookie" << std::endl; + } +} + +Max1227Handler::~Max1227Handler() { +} + + +void Max1227Handler::doStartUp(){ + if(mode == _MODE_START_UP){ + setMode(MODE_ON); + } +} + +void Max1227Handler::doShutDown(){ + +} + +ReturnValue_t Max1227Handler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + + if(communicationStep == CommunicationStep::START_ADC_CONVERSION) { + *id = TMP1075::START_ADC_CONVERSION; + communicationStep = CommunicationStep::GET_TEMPERATURE; + return buildCommandFromCommand(*id, NULL, 0); + } + else { + *id = TMP1075::GET_TEMP; + communicationStep = CommunicationStep::START_ADC_CONVERSION; + return buildCommandFromCommand(*id, NULL, 0); + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::buildTransitionDeviceCommand( + DeviceCommandId_t * id){ + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(TMP1075::START_ADC_CONVERSION): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + prepareAdcConversionCommand(); + rawPacket = cmdBuffer; + rawPacketLen = TMP1075::CFGR_CMD_SIZE; + return RETURN_OK; + } + case(TMP1075::GET_TEMP): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + prepareGetTempCommand(); + rawPacket = cmdBuffer; + rawPacketLen = TMP1075::POINTER_REG_SIZE; + rememberCommandId = TMP1075::GET_TEMP; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void Max1227Handler::fillCommandAndReplyMap(){ + this->insertInCommandMap(TMP1075::START_ADC_CONVERSION); + this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset, + TMP1075::GET_TEMP_REPLY_SIZE); +} + +ReturnValue_t Max1227Handler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + switch(rememberCommandId) { + case(TMP1075::GET_TEMP): + *foundId = TMP1075::GET_TEMP; + *foundLen = TMP1075::GET_TEMP_REPLY_SIZE; + rememberCommandId = TMP1075::NONE; + break; + default: + return IGNORE_REPLY_DATA; + } + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Max1227Handler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + switch (id) { + case TMP1075::GET_TEMP: { + int16_t tempValueRaw = 0; + tempValueRaw = packet[0] << 4 | packet[1] >> 4; + float tempValue = ((static_cast(tempValueRaw)) * 0.0625); +#if OBSW_VERBOSE_LEVEL >= 1 + sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId() + << ": Temperature: " << tempValue<< " °C" + << std::endl; +#endif + ReturnValue_t result = dataset.read(); + if(result == HasReturnvaluesIF::RETURN_OK) { + dataset.temperatureCelcius = tempValue; + dataset.commit(); + } + break; + } + + default: { + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void Max1227Handler::setNormalDatapoolEntriesInvalid(){ + +} + +void Max1227Handler::prepareAdcConversionCommand(){ + cmdBuffer[0] = TMP1075::CFGR_ADDR; + cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8; + cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF; +} + +void Max1227Handler::prepareGetTempCommand(){ + cmdBuffer[0] = TMP1075::TEMP_REG_ADDR; +} + +uint32_t Max1227Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 500; +} + +ReturnValue_t Max1227Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry( { 0.0 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/Max1227Handler.h b/mission/devices/Max1227Handler.h new file mode 100644 index 00000000..76584559 --- /dev/null +++ b/mission/devices/Max1227Handler.h @@ -0,0 +1,64 @@ +#ifndef MISSION_DEVICES_MAX1227HANDLER_H_ +#define MISSION_DEVICES_MAX1227HANDLER_H_ + +#include +#include + +/** + * @brief This is the device handler class for the MAX1227 ADC converter. + * + * @details Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * + * @author J. Meier + */ +class Max1227Handler: public DeviceHandlerBase { +public: + + Max1227Handler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie); + virtual ~Max1227Handler(); + +protected: + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override; + void fillCommandAndReplyMap() override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData,size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void setNormalDatapoolEntriesInvalid() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + +private: + + /** + * @brief Function fills cmdBuffer with command to start the adc + * conversion for a new temperature value. + */ + void prepareAdcConversionCommand(); + + void prepareGetTempCommand(); + + enum class CommunicationStep { + START_ADC_CONVERSION, + GET_TEMPERATURE + }; + + TMP1075::Tmp1075Dataset dataset; + + static const uint8_t MAX_CMD_LEN = 3; + + uint8_t rememberRequestedSize = 0; + uint8_t rememberCommandId = TMP1075::NONE; + uint8_t cmdBuffer[MAX_CMD_LEN]; + CommunicationStep communicationStep = + CommunicationStep::START_ADC_CONVERSION; +}; + +#endif /* MISSION_DEVICES_MAX1227HANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/Max1227Definitions.h b/mission/devices/devicedefinitions/Max1227Definitions.h new file mode 100644 index 00000000..49d83cf3 --- /dev/null +++ b/mission/devices/devicedefinitions/Max1227Definitions.h @@ -0,0 +1,47 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ + +namespace MAX1227 { + static const uint8_t TEMP_REG_ADDR = 0x0; + static const uint8_t CFGR_ADDR = 0x1; + + /* Writing this information to the configuration register sets the tmp1075 + * to shutdown mode and starts a single temperature conversion */ + static const uint16_t ONE_SHOT_MODE = 0x8100; + + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending + static const DeviceCommandId_t GET_TEMP = 0x1; + static const DeviceCommandId_t START_ADC_CONVERSION = 0x2; + + static const uint8_t GET_TEMP_REPLY_SIZE = 2; + static const uint8_t CFGR_CMD_SIZE = 3; + static const uint8_t POINTER_REG_SIZE = 1; + + static const uint32_t TMP1075_DATA_SET_ID = GET_TEMP; + + static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE; + + enum Tmp1075PoolIds: lp_id_t { + TEMPERATURE_C_TMP1075_1, + TEMPERATURE_C_TMP1075_2 + }; + +class Tmp1075Dataset: + public StaticLocalDataSet { +public: + + Tmp1075Dataset(HasLocalDataPoolIF* owner): + StaticLocalDataSet(owner, TMP1075_DATA_SET_ID) { + } + + Tmp1075Dataset(object_id_t objectId): + StaticLocalDataSet(sid_t(objectId, TMP1075_DATA_SET_ID)) { + } + + lp_var_t temperatureCelcius = lp_var_t(sid.objectId, + TEMPERATURE_C_TMP1075_1, this); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ */ diff --git a/tmtc b/tmtc index e23bc116..06750809 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit e23bc116088fc673aaec45768c7a07c20d75a2f6 +Subproject commit 06750809cb52044392e0683896538a652f11a512 From 8509e15736096e3c58faaeb8a17f331f9b32a20c Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 29 Apr 2021 17:45:19 +0200 Subject: [PATCH 21/42] integrated gyro and mgm handler --- bsp_q7s/InitMission.cpp | 2 +- bsp_q7s/ObjectFactory.cpp | 32 ++++++-- bsp_q7s/boardconfig/q7s_config.h | 2 +- fsfwconfig/OBSWConfig.h | 2 +- .../pollingSequenceFactory.cpp | 78 ++++++++++++------- .../MGMHandlerRM3100Definitions.h | 4 +- tmtc | 2 +- 7 files changed, 82 insertions(+), 40 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index e5d33fdc..a8ba7d1d 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -151,7 +151,7 @@ void initmission::initTasks() { FixedTimeslotTaskIF* gomSpacePstTask = factory-> createFixedTimeslotTask("GS_PST_TASK", 50, - PeriodicTaskIF::MINIMUM_STACK_SIZE*8, 3.0, missedDeadlineFunc); + PeriodicTaskIF::MINIMUM_STACK_SIZE*8, 1.0, missedDeadlineFunc); result = pst::gomspacePstInit(gomSpacePstTask); if(result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: GomSpace PST initialization failed!" << std::endl; diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 0815b81d..77148be8 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -107,11 +107,11 @@ void ObjectFactory::produce(){ Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); - tmp1075Handler_1->setStartUpImmediately(); +// tmp1075Handler_1->setStartUpImmediately(); Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler( objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); - tmp1075Handler_2->setStartUpImmediately(); +// tmp1075Handler_2->setStartUpImmediately(); GpioCookie* heaterGpiosCookie = new GpioCookie; @@ -152,13 +152,13 @@ void ObjectFactory::produce(){ #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); GpiodRegular* gpio = nullptr; - gpio = new GpiodRegular(std::string("gpiochip5"), 1, std::string("CS_GYRO_1_ADIS"), + gpio = new GpiodRegular(std::string("gpiochip5"), 1, std::string("CS_GYRO_0_ADIS"), gpio::OUT, gpio::HIGH); gpioCookieAcsBoard->addGpio(gpioIds::GYRO_0_ADIS_CS, gpio); - gpio = new GpiodRegular(std::string("gpiochip5"), 7, std::string("CS_GYRO_2_L3G"), + gpio = new GpiodRegular(std::string("gpiochip5"), 7, std::string("CS_GYRO_1_L3G"), gpio::OUT, gpio::HIGH); gpioCookieAcsBoard->addGpio(gpioIds::GYRO_1_L3G_CS, gpio); - gpio = new GpiodRegular(std::string("gpiochip5"), 3, std::string("CS_GYRO_3_L3G"), + gpio = new GpiodRegular(std::string("gpiochip5"), 3, std::string("CS_GYRO_2_L3G"), gpio::OUT, gpio::HIGH); gpioCookieAcsBoard->addGpio(gpioIds::GYRO_2_L3G_CS, gpio); @@ -166,7 +166,7 @@ void ObjectFactory::produce(){ gpio::OUT, gpio::HIGH); gpioCookieAcsBoard->addGpio(gpioIds::MGM_0_LIS3_CS, gpio); - gpio = new GpiodRegular(std::string("gpiochip5"), 17, std::string("CS_MGM_1_RM3100_A"), + gpio = new GpiodRegular(std::string("gpiochip5"), 16, std::string("CS_MGM_1_RM3100_A"), gpio::OUT, gpio::HIGH); gpioCookieAcsBoard->addGpio(gpioIds::MGM_1_RM3100_CS, gpio); @@ -199,11 +199,27 @@ void ObjectFactory::produce(){ objects::SPI_COM_IF, spiCookie); mgmRm3100Handler->setStartUpImmediately(); + spiCookie = new SpiCookie(addresses::MGM_3_RM3100, gpioIds::MGM_3_RM3100_CS, spiDev, + RM3100::MAX_BUFFER_SIZE, spi::DEFAULT_RM3100_MODE, spi::DEFAULT_RM3100_SPEED); + mgmRm3100Handler = new MGMHandlerRM3100(objects::MGM_3_RM3100_HANDLER, + objects::SPI_COM_IF, spiCookie); + mgmRm3100Handler->setStartUpImmediately(); + + //TODO: Adis Gyro (Gyro 0 Side A) + + /* Gyro 1 Side A */ spiCookie = new SpiCookie(addresses::GYRO_1_L3G, gpioIds::GYRO_1_L3G_CS, spiDev, L3GD20H::MAX_BUFFER_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); auto gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_1_L3G_HANDLER, objects::SPI_COM_IF, spiCookie); gyroL3gHandler->setStartUpImmediately(); + + /* Gyro 2 Side B */ + spiCookie = new SpiCookie(addresses::GYRO_2_L3G, gpioIds::GYRO_2_L3G_CS, spiDev, + L3GD20H::MAX_BUFFER_SIZE, spi::DEFAULT_L3G_MODE, spi::DEFAULT_L3G_SPEED); + gyroL3gHandler = new GyroHandlerL3GD20H(objects::GYRO_2_L3G_HANDLER, objects::SPI_COM_IF, + spiCookie); + gyroL3gHandler->setStartUpImmediately(); #endif /* Pin H2-11 on stack connector */ @@ -411,13 +427,13 @@ void ObjectFactory::produce(){ I2cCookie* imtqI2cCookie = new I2cCookie(addresses::IMTQ, IMTQ::MAX_REPLY_SIZE, std::string("/dev/i2c-0")); IMTQHandler* imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie); - imtqHandler->setStartUpImmediately(); +// imtqHandler->setStartUpImmediately(); UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyUL3"), 115200, PLOC::MAX_REPLY_SIZE); PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, plocUartCookie); - plocHandler->setStartUpImmediately(); +// plocHandler->setStartUpImmediately(); #endif /* TE0720 == 0 */ diff --git a/bsp_q7s/boardconfig/q7s_config.h b/bsp_q7s/boardconfig/q7s_config.h index 782ecf4f..3d1bc8ad 100644 --- a/bsp_q7s/boardconfig/q7s_config.h +++ b/bsp_q7s/boardconfig/q7s_config.h @@ -5,7 +5,7 @@ /* Only one of those 2 should be enabled! */ /* Add code for ACS board */ -#define OBSW_ADD_ACS_BOARD 0 +#define OBSW_ADD_ACS_BOARD 1 #define Q7S_ADD_SPI_TEST 0 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index c1a6c313..0b9320e1 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -21,7 +21,7 @@ debugging. */ #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index fe728b12..01f47b39 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -212,7 +212,7 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ // DeviceHandlerIF::SEND_READ); // thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, // DeviceHandlerIF::GET_READ); -// + // thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, // DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, @@ -224,27 +224,53 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ // thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, // DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, +// DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, +// DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, +// DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, +// DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, +// DeviceHandlerIF::GET_READ); +// +// +// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, +// DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, +// DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, +// DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, +// DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, +// DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, + +// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0, // DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, +// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.2, // DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, +// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.4, // DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, +// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.6, // DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, +// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.8, // DeviceHandlerIF::GET_READ); + + + thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); + #endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { @@ -268,16 +294,16 @@ ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, +// DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, +// DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, +// DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, +// DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, +// DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); diff --git a/mission/devices/devicedefinitions/MGMHandlerRM3100Definitions.h b/mission/devices/devicedefinitions/MGMHandlerRM3100Definitions.h index 2856c170..08f80dd9 100644 --- a/mission/devices/devicedefinitions/MGMHandlerRM3100Definitions.h +++ b/mission/devices/devicedefinitions/MGMHandlerRM3100Definitions.h @@ -12,7 +12,7 @@ namespace RM3100 { /* Actually 10, we round up a little bit */ static constexpr size_t MAX_BUFFER_SIZE = 12; -static constexpr uint8_t READ_MASK = 0b1000'0000; +static constexpr uint8_t READ_MASK = 0x80; /*----------------------------------------------------------------------------*/ /* CMM Register */ @@ -45,7 +45,7 @@ static constexpr uint8_t TMRC_75HZ_VALUE = 0x95; static constexpr uint8_t TMRC_DEFAULT_37HZ_VALUE = 0x96; static constexpr uint8_t TMRC_REGISTER = 0x0B; -static constexpr uint8_t TMRC_DEFAULT_VALUE = TMRC_75HZ_VALUE; +static constexpr uint8_t TMRC_DEFAULT_VALUE = TMRC_DEFAULT_37HZ_VALUE; static constexpr uint8_t MEASUREMENT_REG_START = 0x24; static constexpr uint8_t BIST_REGISTER = 0x33; diff --git a/tmtc b/tmtc index e23bc116..06750809 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit e23bc116088fc673aaec45768c7a07c20d75a2f6 +Subproject commit 06750809cb52044392e0683896538a652f11a512 From b87383164509a51a7f2654b0b5e477f65a85b6fa Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 2 May 2021 13:48:39 +0200 Subject: [PATCH 22/42] spi decoder callbacks wip --- README.md | 2 +- bsp_q7s/ObjectFactory.cpp | 19 +- bsp_q7s/boardconfig/q7s_config.h | 2 +- bsp_q7s/gpio/gpioCallbacks.cpp | 204 ++++++++++-------- bsp_q7s/gpio/gpioCallbacks.h | 34 +++ fsfwconfig/OBSWConfig.h | 3 +- fsfwconfig/devices/addresses.h | 2 + fsfwconfig/devices/gpioIds.h | 4 +- fsfwconfig/devices/spi.h | 3 + fsfwconfig/objects/systemObjectList.h | 2 + .../pollingSequenceFactory.cpp | 8 + mission/devices/CMakeLists.txt | 1 + mission/devices/Max1227Handler.cpp | 145 ------------- mission/devices/RadiationSensorHandler.cpp | 158 ++++++++++++++ ...1227Handler.h => RadiationSensorHandler.h} | 46 ++-- .../devicedefinitions/Max1227Definitions.h | 47 ---- .../devicedefinitions/RadSensorDefinitions.h | 79 +++++++ 17 files changed, 447 insertions(+), 312 deletions(-) delete mode 100644 mission/devices/Max1227Handler.cpp create mode 100644 mission/devices/RadiationSensorHandler.cpp rename mission/devices/{Max1227Handler.h => RadiationSensorHandler.h} (53%) delete mode 100644 mission/devices/devicedefinitions/Max1227Definitions.h create mode 100644 mission/devices/devicedefinitions/RadSensorDefinitions.h diff --git a/README.md b/README.md index 44d699d1..ec32a2bb 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ To transfer files from the local machine to the Q7S, use port forwarding ssh -L 1535:192.168.133.10:22 eive@2001:7c0:2018:1099:babe:0:e1fe:f1a5 ``` -Then you can copy an `example` file like this +An `example` file can be copied like this ```sh scp -P 1535 example root@localhost:/tmp diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 77148be8..9d0b9ecb 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -20,16 +20,18 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include #include +#include +#include #include #include @@ -428,12 +430,27 @@ void ObjectFactory::produce(){ std::string("/dev/i2c-0")); IMTQHandler* imtqHandler = new IMTQHandler(objects::IMTQ_HANDLER, objects::I2C_COM_IF, imtqI2cCookie); // imtqHandler->setStartUpImmediately(); + (void) imtqHandler; UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyUL3"), 115200, PLOC::MAX_REPLY_SIZE); PlocHandler* plocHandler = new PlocHandler(objects::PLOC_HANDLER, objects::UART_COM_IF, plocUartCookie); // plocHandler->setStartUpImmediately(); + (void) plocHandler; + + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip5"), 19, + std::string("Chip Select Radiation Sensor"), gpio::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + + SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, + std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, + objects::SPI_COM_IF, spiCookieRadSensor); + radSensor->setStartUpImmediately(); #endif /* TE0720 == 0 */ diff --git a/bsp_q7s/boardconfig/q7s_config.h b/bsp_q7s/boardconfig/q7s_config.h index 3d1bc8ad..782ecf4f 100644 --- a/bsp_q7s/boardconfig/q7s_config.h +++ b/bsp_q7s/boardconfig/q7s_config.h @@ -5,7 +5,7 @@ /* Only one of those 2 should be enabled! */ /* Add code for ACS board */ -#define OBSW_ADD_ACS_BOARD 1 +#define OBSW_ADD_ACS_BOARD 0 #define Q7S_ADD_SPI_TEST 0 diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index 086e6469..afdc90b6 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -22,19 +22,20 @@ void initTcsBoardDecoder(GpioIF* gpioComIF) { gpioComInterface = gpioComIF; GpioCookie* spiMuxGpios = new GpioCookie; - /** - * Initial values of the spi mux gpios can all be set to an arbitrary value expect for spi mux - * bit 1. Setting spi mux bit 1 to high will pull all decoder outputs to high voltage level. - */ + + /** Setting mux bit 1 to low will disable IC21 on the interface board */ GpiodRegular* spiMuxBit1 = new GpiodRegular(std::string("gpiochip7"), 13, - std::string("SPI Mux Bit 1"), gpio::OUT, 1); + std::string("SPI Mux Bit 1"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_1, spiMuxBit1); + /** Setting mux bit 2 to low disables IC1 on the TCS board */ GpiodRegular* spiMuxBit2 = new GpiodRegular(std::string("gpiochip7"), 14, std::string("SPI Mux Bit 2"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_2, spiMuxBit2); + /** Setting mux bit 3 to low disables IC2 on the TCS board and IC22 on the interface board */ GpiodRegular* spiMuxBit3 = new GpiodRegular(std::string("gpiochip7"), 15, std::string("SPI Mux Bit 3"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_3, spiMuxBit3); + /** The following gpios can take arbitrary initial values */ GpiodRegular* spiMuxBit4 = new GpiodRegular(std::string("gpiochip7"), 16, std::string("SPI Mux Bit 4"), gpio::OUT, 0); spiMuxGpios->addGpio(gpioIds::SPI_MUX_BIT_4, spiMuxBit4); @@ -74,136 +75,93 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va else if (value == 0) { switch (gpioId) { case(gpioIds::RTD_IC3): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY7(); break; } case(gpioIds::RTD_IC4): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY6(); break; } case(gpioIds::RTD_IC5): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY5(); break; } case(gpioIds::RTD_IC6): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY4(); break; } case(gpioIds::RTD_IC7): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY3(); break; } case(gpioIds::RTD_IC8): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY2(); break; } case(gpioIds::RTD_IC9): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY1(); break; } case(gpioIds::RTD_IC10): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc1(); + selectY0(); break; } case(gpioIds::RTD_IC11): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY7(); break; } case(gpioIds::RTD_IC12): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY6(); break; } case(gpioIds::RTD_IC13): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY5(); break; } case(gpioIds::RTD_IC14): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY4(); break; } case(gpioIds::RTD_IC15): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY3(); break; } case(gpioIds::RTD_IC16): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY2(); break; } case(gpioIds::RTD_IC17): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + enableDecoderTcsIc2(); + selectY1(); break; } case(gpioIds::RTD_IC18): { - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); + enableDecoderTcsIc2(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_1): { + enableDecoderInterfaceBoardIc21(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_2): { + enableDecoderInterfaceBoardIc21(); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); @@ -218,4 +176,70 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va } } +void enableDecoderTcsIc1() { + +} + +void enableDecoderTcsIc2() { + +} + +void enableDecoderInterfaceBoardIc21() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); +} + +void enableDecoderInterfaceBoardIc22() { + +} + +void selectY0() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY1() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY2() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY3() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); +} + +void selectY4() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY5() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY6() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + +void selectY7() { + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_4); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_5); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); +} + } diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 845127fb..3cfd4884 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -18,6 +18,40 @@ namespace gpioCallbacks { * chips SN74LVC138APWR on the TCS board. */ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the TCS board which is named to IC1 in the schematic. + */ + void enableDecoderTcsIc1(); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the TCS board which is named to IC2 in the schematic. + */ + void enableDecoderTcsIc2(); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the inteface board board which is named to IC21 in the schematic. + */ + void enableDecoderInterfaceBoardIc21(); + + /** + * @brief This function sets mux bits 1-3 to a state which will only enable the decoder + * on the inteface board board which is named to IC22 in the schematic. + */ + void enableDecoderInterfaceBoardIc22(); + + /** The following functions enable the appropriate channel of the currently enabled decoder */ + void selectY0(); + void selectY1(); + void selectY2(); + void selectY3(); + void selectY4(); + void selectY5(); + void selectY6(); + void selectY7(); } #endif /* LINUX_GPIO_GPIOCALLBACKS_H_ */ diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 0b9320e1..be770ad1 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -29,7 +29,8 @@ debugging. */ #define PDU2_DEBUG 0 #define ACU_DEBUG 0 #define SYRLINKS_DEBUG 0 -#define IMQT_DEBUG 1 +#define IMQT_DEBUG 0 +#define DEBUG_RAD_SENSOR 1 #include "OBSWVersion.h" diff --git a/fsfwconfig/devices/addresses.h b/fsfwconfig/devices/addresses.h index 4974834d..26a86b2a 100644 --- a/fsfwconfig/devices/addresses.h +++ b/fsfwconfig/devices/addresses.h @@ -19,6 +19,8 @@ namespace addresses { GYRO_1_L3G = objects::GYRO_1_L3G_HANDLER, GYRO_2_L3G = objects::GYRO_2_L3G_HANDLER, + RAD_SENSOR = objects::RAD_SENSOR, + /* Dummy and Test Addresses */ DUMMY_ECHO = 129, DUMMY_GPS0 = 130, diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index ac999152..8b9edffc 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -49,7 +49,9 @@ namespace gpioIds { SPI_MUX_BIT_3, SPI_MUX_BIT_4, SPI_MUX_BIT_5, - SPI_MUX_BIT_6 + SPI_MUX_BIT_6, + + CS_RAD_SENSOR }; } diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 55271a40..eb17786b 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,6 +20,9 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; + } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index 72dcfc21..1249b862 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -82,6 +82,8 @@ namespace objects { RTD_IC17 = 0x5400003F, RTD_IC18 = 0x5400004F, + RAD_SENSOR = 0x54000050, + /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, LIBGPIOD_TEST = 0x54123456, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 01f47b39..a54d70ba 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -142,6 +142,14 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::IMTQ_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); + + /* Radiation sensor */ + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 7d34aac9..4088d98b 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources(${TARGET_NAME} PUBLIC Max31865PT1000Handler.cpp IMTQHandler.cpp PlocHandler.cpp + RadiationSensorHandler.cpp ) diff --git a/mission/devices/Max1227Handler.cpp b/mission/devices/Max1227Handler.cpp deleted file mode 100644 index 2ecfce9c..00000000 --- a/mission/devices/Max1227Handler.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include -#include - -Max1227Handler::Max1227Handler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "Max1227Handler: Invalid com cookie" << std::endl; - } -} - -Max1227Handler::~Max1227Handler() { -} - - -void Max1227Handler::doStartUp(){ - if(mode == _MODE_START_UP){ - setMode(MODE_ON); - } -} - -void Max1227Handler::doShutDown(){ - -} - -ReturnValue_t Max1227Handler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { - - if(communicationStep == CommunicationStep::START_ADC_CONVERSION) { - *id = TMP1075::START_ADC_CONVERSION; - communicationStep = CommunicationStep::GET_TEMPERATURE; - return buildCommandFromCommand(*id, NULL, 0); - } - else { - *id = TMP1075::GET_TEMP; - communicationStep = CommunicationStep::START_ADC_CONVERSION; - return buildCommandFromCommand(*id, NULL, 0); - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::buildTransitionDeviceCommand( - DeviceCommandId_t * id){ - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) { - switch(deviceCommand) { - case(TMP1075::START_ADC_CONVERSION): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - prepareAdcConversionCommand(); - rawPacket = cmdBuffer; - rawPacketLen = TMP1075::CFGR_CMD_SIZE; - return RETURN_OK; - } - case(TMP1075::GET_TEMP): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - prepareGetTempCommand(); - rawPacket = cmdBuffer; - rawPacketLen = TMP1075::POINTER_REG_SIZE; - rememberCommandId = TMP1075::GET_TEMP; - return RETURN_OK; - } - default: - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; -} - -void Max1227Handler::fillCommandAndReplyMap(){ - this->insertInCommandMap(TMP1075::START_ADC_CONVERSION); - this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset, - TMP1075::GET_TEMP_REPLY_SIZE); -} - -ReturnValue_t Max1227Handler::scanForReply(const uint8_t *start, - size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { - switch(rememberCommandId) { - case(TMP1075::GET_TEMP): - *foundId = TMP1075::GET_TEMP; - *foundLen = TMP1075::GET_TEMP_REPLY_SIZE; - rememberCommandId = TMP1075::NONE; - break; - default: - return IGNORE_REPLY_DATA; - } - return HasReturnvaluesIF::RETURN_OK; -} - -ReturnValue_t Max1227Handler::interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) { - switch (id) { - case TMP1075::GET_TEMP: { - int16_t tempValueRaw = 0; - tempValueRaw = packet[0] << 4 | packet[1] >> 4; - float tempValue = ((static_cast(tempValueRaw)) * 0.0625); -#if OBSW_VERBOSE_LEVEL >= 1 - sif::info << "Tmp1075 with object id: 0x" << std::hex << getObjectId() - << ": Temperature: " << tempValue<< " °C" - << std::endl; -#endif - ReturnValue_t result = dataset.read(); - if(result == HasReturnvaluesIF::RETURN_OK) { - dataset.temperatureCelcius = tempValue; - dataset.commit(); - } - break; - } - - default: { - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } - - } - return HasReturnvaluesIF::RETURN_OK; -} - -void Max1227Handler::setNormalDatapoolEntriesInvalid(){ - -} - -void Max1227Handler::prepareAdcConversionCommand(){ - cmdBuffer[0] = TMP1075::CFGR_ADDR; - cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8; - cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF; -} - -void Max1227Handler::prepareGetTempCommand(){ - cmdBuffer[0] = TMP1075::TEMP_REG_ADDR; -} - -uint32_t Max1227Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 500; -} - -ReturnValue_t Max1227Handler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, - LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(TMP1075::TEMPERATURE_C_TMP1075_1, new PoolEntry( { 0.0 })); - return HasReturnvaluesIF::RETURN_OK; -} - diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp new file mode 100644 index 00000000..64391c79 --- /dev/null +++ b/mission/devices/RadiationSensorHandler.cpp @@ -0,0 +1,158 @@ +#include +#include +#include + +RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; + } +} + +RadiationSensorHandler::~RadiationSensorHandler() { +} + + +void RadiationSensorHandler::doStartUp(){ + if (internalState == InternalState::CONFIGURED) { +#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 + setMode(MODE_NORMAL); +#else + setMode(_MODE_TO_ON); +#endif + } +} + +void RadiationSensorHandler::doShutDown(){ + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + + switch (communicationStep) { + case CommunicationStep::START_CONVERSION: { + *id = RAD_SENSOR::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = RAD_SENSOR::READ_CONVERSIONS; +// communicationStep = CommunicationStep::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + default: { + sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( + DeviceCommandId_t * id){ + if (internalState == InternalState::SETUP) { + *id = RAD_SENSOR::WRITE_SETUP; + } + else { + return HasReturnvaluesIF::RETURN_OK; + } + buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(RAD_SENSOR::WRITE_SETUP): { + cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(RAD_SENSOR::START_CONVERSION): { + cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + return RETURN_OK; + } + case(RAD_SENSOR::READ_CONVERSIONS): { + cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[6] = RAD_SENSOR::DUMMY_BYTE; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void RadiationSensorHandler::fillCommandAndReplyMap() { + this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); + this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); + this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, + RAD_SENSOR::READ_SIZE); +} + +ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundId = this->getPendingCommand(); + *foundLen = remainingSize; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + switch (id) { + case RAD_SENSOR::READ_CONVERSIONS: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); +#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_RAD_SENSOR + sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" + << std::endl; + sif::info << "Radiation sensor temperature ADC value channel 0: " << dataset.channel0 + << std::endl; + sif::info << "Radiation sensor temperature ADC value channel 1: " << dataset.channel1 + << std::endl; +#endif + break; + } + default: { + sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 5000; +} + +ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(RAD_SENSOR::TEMPERATURE_C, new PoolEntry( { 0.0 })); + localDataPoolMap.emplace(RAD_SENSOR::CHANNEL_0, new PoolEntry( { 0 })); + localDataPoolMap.emplace(RAD_SENSOR::CHANNEL_1, new PoolEntry( { 0 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/Max1227Handler.h b/mission/devices/RadiationSensorHandler.h similarity index 53% rename from mission/devices/Max1227Handler.h rename to mission/devices/RadiationSensorHandler.h index 76584559..5612a1e0 100644 --- a/mission/devices/Max1227Handler.h +++ b/mission/devices/RadiationSensorHandler.h @@ -1,22 +1,23 @@ -#ifndef MISSION_DEVICES_MAX1227HANDLER_H_ -#define MISSION_DEVICES_MAX1227HANDLER_H_ +#ifndef MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ +#define MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ #include -#include +#include /** - * @brief This is the device handler class for the MAX1227 ADC converter. + * @brief This is the device handler class for radiation sensor on the OBC IF Board. The sensor + * is based on the MAX1227 ADC converter. * - * @details Datasheet: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf * * @author J. Meier */ -class Max1227Handler: public DeviceHandlerBase { +class RadiationSensorHandler: public DeviceHandlerBase { public: - Max1227Handler(object_id_t objectId, object_id_t comIF, + RadiationSensorHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie); - virtual ~Max1227Handler(); + virtual ~RadiationSensorHandler(); protected: void doStartUp() override; @@ -37,28 +38,23 @@ protected: private: - /** - * @brief Function fills cmdBuffer with command to start the adc - * conversion for a new temperature value. - */ - void prepareAdcConversionCommand(); - - void prepareGetTempCommand(); - enum class CommunicationStep { - START_ADC_CONVERSION, - GET_TEMPERATURE + START_CONVERSION, + READ_CONVERSIONS }; - TMP1075::Tmp1075Dataset dataset; + enum class InternalState { + SETUP, + CONFIGURED + }; - static const uint8_t MAX_CMD_LEN = 3; + RAD_SENSOR::RadSensorDataset dataset; + + static const uint8_t MAX_CMD_LEN = RAD_SENSOR::READ_SIZE; - uint8_t rememberRequestedSize = 0; - uint8_t rememberCommandId = TMP1075::NONE; uint8_t cmdBuffer[MAX_CMD_LEN]; - CommunicationStep communicationStep = - CommunicationStep::START_ADC_CONVERSION; + InternalState internalState = InternalState::SETUP; + CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; }; -#endif /* MISSION_DEVICES_MAX1227HANDLER_H_ */ +#endif /* MISSION_DEVICES_RADIATIONSENSORHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/Max1227Definitions.h b/mission/devices/devicedefinitions/Max1227Definitions.h deleted file mode 100644 index 49d83cf3..00000000 --- a/mission/devices/devicedefinitions/Max1227Definitions.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ -#define MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ - -namespace MAX1227 { - static const uint8_t TEMP_REG_ADDR = 0x0; - static const uint8_t CFGR_ADDR = 0x1; - - /* Writing this information to the configuration register sets the tmp1075 - * to shutdown mode and starts a single temperature conversion */ - static const uint16_t ONE_SHOT_MODE = 0x8100; - - static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending - static const DeviceCommandId_t GET_TEMP = 0x1; - static const DeviceCommandId_t START_ADC_CONVERSION = 0x2; - - static const uint8_t GET_TEMP_REPLY_SIZE = 2; - static const uint8_t CFGR_CMD_SIZE = 3; - static const uint8_t POINTER_REG_SIZE = 1; - - static const uint32_t TMP1075_DATA_SET_ID = GET_TEMP; - - static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE; - - enum Tmp1075PoolIds: lp_id_t { - TEMPERATURE_C_TMP1075_1, - TEMPERATURE_C_TMP1075_2 - }; - -class Tmp1075Dataset: - public StaticLocalDataSet { -public: - - Tmp1075Dataset(HasLocalDataPoolIF* owner): - StaticLocalDataSet(owner, TMP1075_DATA_SET_ID) { - } - - Tmp1075Dataset(object_id_t objectId): - StaticLocalDataSet(sid_t(objectId, TMP1075_DATA_SET_ID)) { - } - - lp_var_t temperatureCelcius = lp_var_t(sid.objectId, - TEMPERATURE_C_TMP1075_1, this); -}; -} - - -#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_MAX1227_H_ */ diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h new file mode 100644 index 00000000..46e5be40 --- /dev/null +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -0,0 +1,79 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ + +namespace RAD_SENSOR { + + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending + + /** + * This command initiates the ADC conversion for all channels including the internal + * temperature sensor. + */ + static const DeviceCommandId_t WRITE_SETUP = 0x1; + static const DeviceCommandId_t START_CONVERSION = 0x2; + static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + + static const uint32_t MAX1227_DATA_SET_ID = READ_CONVERSIONS; + + /** + * @brief This is the configuration byte which will be written to the setup register after + * power on. + * + * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b01, external reference single ended + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing + * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * + */ + static const uint8_t SETUP_DEFINITION = 0b01101000; + + /** + * @brief This value will always be written to the ADC conversion register to specify the + * conversions to perform. + * @details Bit0: 1 - Enables temperature conversion + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00 (channel conversion from 0 to N) + * Bit6 - Bit3 defines N: 0b0001 (N = 1) + * Bit7: Always 1. Tells the ADC that this is the conversion register. + */ + static const uint8_t CONVERSION_DEFINITION = 0b10001001; + + /** + * Unipolar only required for differential measurement. Unipolar or dipolar determines the + * voltage range. + */ + static const uint8_t UNIPOLAR_SETUP = 0b10000000; + + static const uint8_t DUMMY_BYTE = 0xFF; + + static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; + + /** + * One temperature value, conversion of channel 0 and conversion of channel 1 + */ + static const uint8_t READ_SIZE = 6; + + enum Max1227PoolIds: lp_id_t { + TEMPERATURE_C, + CHANNEL_0, + CHANNEL_1, + }; + +class RadSensorDataset: public StaticLocalDataSet { +public: + + RadSensorDataset(HasLocalDataPoolIF* owner) : + StaticLocalDataSet(owner, RAD_SENSOR_DATA_SET_ID) { + } + + RadSensorDataset(object_id_t objectId) : + StaticLocalDataSet(sid_t(objectId, RAD_SENSOR_DATA_SET_ID)) { + } + + lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); + lp_var_t channel0 = lp_var_t(sid.objectId, CHANNEL_0, this); + lp_var_t channel1 = lp_var_t(sid.objectId, CHANNEL_1, this); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_RADSENSOR_H_ */ From f708a67fa8b305c0b2d97d1d65b84dd6ef15e6fd Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 11:59:33 +0200 Subject: [PATCH 23/42] rad sensor change wip --- bsp_q7s/ObjectFactory.cpp | 137 ++++++++++++--- bsp_q7s/gpio/gpioCallbacks.cpp | 84 +++++++-- bsp_q7s/gpio/gpioCallbacks.h | 10 +- fsfwconfig/OBSWConfig.h | 3 +- fsfwconfig/devices/addresses.h | 14 ++ fsfwconfig/devices/gpioIds.h | 14 ++ fsfwconfig/objects/systemObjectList.h | 14 ++ .../pollingSequenceFactory.cpp | 7 + mission/devices/CMakeLists.txt | 1 + mission/devices/RadiationSensorHandler.cpp | 51 ++---- mission/devices/SusHandler.cpp | 165 ++++++++++++++++++ mission/devices/SusHandler.h | 61 +++++++ .../devicedefinitions/RadSensorDefinitions.h | 11 +- .../devicedefinitions/SusDefinitions.h | 83 +++++++++ 14 files changed, 563 insertions(+), 92 deletions(-) create mode 100644 mission/devices/SusHandler.cpp create mode 100644 mission/devices/SusHandler.h create mode 100644 mission/devices/devicedefinitions/SusDefinitions.h diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 9d0b9ecb..776a3e4b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -26,11 +26,13 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -106,14 +108,8 @@ void ObjectFactory::produce(){ #endif /* Temperature sensors */ - Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( - objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, - i2cCookieTmp1075tcs1); -// tmp1075Handler_1->setStartUpImmediately(); - Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler( - objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, - i2cCookieTmp1075tcs2); -// tmp1075Handler_2->setStartUpImmediately(); + new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); + new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); GpioCookie* heaterGpiosCookie = new GpioCookie; @@ -151,6 +147,98 @@ void ObjectFactory::produce(){ (void) pdu2handler; (void) acuhandler; + /* Adding gpios for chip select decoding to the gpioComIf */ + gpioCallbacks::initSpiCsDecoder(gpioComIF); + + GpioCookie* gpioCookieSus = new GpioCookie(); + + GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 2"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 3"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 4"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 5"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 6"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 7"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 8"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 9"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 10"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 11"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 12"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_12, susgpio); + susgpio = new GpioCallback(std::string("Chip select SUS 13"), gpio::OUT, 1, + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + gpioCookieSus->addGpio(gpioIds::CS_SUS_13, susgpio); + + gpioComIF->addGpios(gpioCookieSus); + + SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, + std::string("/dev/spidev2.0"), SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), + SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); + + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); + (void) sus1; +// sus1->setStartUpImmediately(); + + new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); + new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); + new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); + new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); + new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); + new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); + new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); + new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); + new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); + new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); + #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); GpiodRegular* gpio = nullptr; @@ -287,54 +375,53 @@ void ObjectFactory::produce(){ #if Q7S_ADD_RTD_DEVICES == 1 GpioCookie* rtdGpioCookie = new GpioCookie; - gpioCallbacks::initTcsBoardDecoder(gpioComIF); GpioCallback* gpioRtdIc3 = new GpioCallback(std::string("Chip select RTD IC3"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC3, gpioRtdIc3); GpioCallback* gpioRtdIc4 = new GpioCallback(std::string("Chip select RTD IC4"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC4, gpioRtdIc4); GpioCallback* gpioRtdIc5 = new GpioCallback(std::string("Chip select RTD IC5"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC5, gpioRtdIc5); GpioCallback* gpioRtdIc6 = new GpioCallback(std::string("Chip select RTD IC6"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC6, gpioRtdIc6); GpioCallback* gpioRtdIc7 = new GpioCallback(std::string("Chip select RTD IC7"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC7, gpioRtdIc7); GpioCallback* gpioRtdIc8 = new GpioCallback(std::string("Chip select RTD IC8"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC8, gpioRtdIc8); GpioCallback* gpioRtdIc9 = new GpioCallback(std::string("Chip select RTD IC9"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC9, gpioRtdIc9); GpioCallback* gpioRtdIc10 = new GpioCallback(std::string("Chip select RTD IC10"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC10, gpioRtdIc10); GpioCallback* gpioRtdIc11 = new GpioCallback(std::string("Chip select RTD IC11"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC11, gpioRtdIc11); GpioCallback* gpioRtdIc12 = new GpioCallback(std::string("Chip select RTD IC12"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC12, gpioRtdIc12); GpioCallback* gpioRtdIc13 = new GpioCallback(std::string("Chip select RTD IC13"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC13, gpioRtdIc13); GpioCallback* gpioRtdIc14 = new GpioCallback(std::string("Chip select RTD IC14"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC14, gpioRtdIc14); GpioCallback* gpioRtdIc15 = new GpioCallback(std::string("Chip select RTD IC15"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC15, gpioRtdIc15); GpioCallback* gpioRtdIc16 = new GpioCallback(std::string("Chip select RTD IC16"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC16, gpioRtdIc16); GpioCallback* gpioRtdIc17 = new GpioCallback(std::string("Chip select RTD IC17"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC17, gpioRtdIc17); GpioCallback* gpioRtdIc18 = new GpioCallback(std::string("Chip select RTD IC18"), gpio::OUT, 1, - &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); + &gpioCallbacks::spiCsDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC18, gpioRtdIc18); gpioComIF->addGpios(rtdGpioCookie); diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index afdc90b6..a40f6ba4 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -10,12 +10,12 @@ namespace gpioCallbacks { GpioIF* gpioComInterface; -void initTcsBoardDecoder(GpioIF* gpioComIF) { +void initSpiCsDecoder(GpioIF* gpioComIF) { ReturnValue_t result; if (gpioComIF == nullptr) { - sif::debug << "initTcsBoardDecoder: Invalid gpioComIF" << std::endl; + sif::debug << "initSpiCsDecoder: Invalid gpioComIF" << std::endl; return; } @@ -48,13 +48,13 @@ void initTcsBoardDecoder(GpioIF* gpioComIF) { result = gpioComInterface->addGpios(spiMuxGpios); if (result != HasReturnvaluesIF::RETURN_OK) { - sif::error << "initTcsBoardDecoder: Failed to add mux bit gpios to gpioComIF" + sif::error << "initSpiCsDecoder: Failed to add mux bit gpios to gpioComIF" << std::endl; return; } } -void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, +void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args) { if (gpioComInterface == nullptr) { @@ -161,27 +161,83 @@ void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int va } case(gpioIds::CS_SUS_2): { enableDecoderInterfaceBoardIc21(); - - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_4); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_5); - gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_6); + selectY1(); + break; + } + case(gpioIds::CS_SUS_3): { + enableDecoderInterfaceBoardIc21(); + selectY2(); + break; + } + case(gpioIds::CS_SUS_4): { + enableDecoderInterfaceBoardIc21(); + selectY3(); + break; + } + case(gpioIds::CS_SUS_5): { + enableDecoderInterfaceBoardIc21(); + selectY4(); + break; + } + case(gpioIds::CS_SUS_6): { + enableDecoderInterfaceBoardIc21(); + selectY5(); + break; + } + case(gpioIds::CS_SUS_7): { + enableDecoderInterfaceBoardIc21(); + selectY6(); + break; + } + case(gpioIds::CS_SUS_8): { + enableDecoderInterfaceBoardIc22(); + selectY0(); + break; + } + case(gpioIds::CS_SUS_9): { + enableDecoderInterfaceBoardIc22(); + selectY1(); + break; + } + case(gpioIds::CS_SUS_10): { + enableDecoderInterfaceBoardIc22(); + selectY2(); + break; + } + case(gpioIds::CS_SUS_11): { + enableDecoderInterfaceBoardIc22(); + selectY3(); + break; + } + case(gpioIds::CS_SUS_12): { + enableDecoderInterfaceBoardIc22(); + selectY4(); + break; + } + case(gpioIds::CS_SUS_13): { + enableDecoderInterfaceBoardIc22(); + selectY5(); break; } default: - sif::debug << "tcsBoardDecoderCallback: Invalid gpioid " << gpioId << std::endl; + sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; } } else { - sif::debug << "tcsBoardDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; + sif::debug << "spiCsDecoderCallback: Invalid value. Must be 0 or 1" << std::endl; } } void enableDecoderTcsIc1() { - + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); } void enableDecoderTcsIc2() { - + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } void enableDecoderInterfaceBoardIc21() { @@ -191,7 +247,9 @@ void enableDecoderInterfaceBoardIc21() { } void enableDecoderInterfaceBoardIc22() { - + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } void selectY0() { diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 3cfd4884..67ae4dc2 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -9,15 +9,15 @@ namespace gpioCallbacks { /** * @brief This function initializes the GPIOs used to control the SN74LVC138APWR decoders on - * the TCS Board. + * the TCS Board and the interface board. */ - void initTcsBoardDecoder(GpioIF* gpioComIF); + void initSpiCsDecoder(GpioIF* gpioComIF); /** - * @brief This function implements the decoding to multiply gpios by using the two decoder - * chips SN74LVC138APWR on the TCS board. + * @brief This function implements the decoding to multiply gpios by using the decoder + * chips SN74LVC138APWR on the TCS board and the interface board. */ - void tcsBoardDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); + void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value, void* args); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index be770ad1..d6a059e6 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -30,7 +30,8 @@ debugging. */ #define ACU_DEBUG 0 #define SYRLINKS_DEBUG 0 #define IMQT_DEBUG 0 -#define DEBUG_RAD_SENSOR 1 +#define DEBUG_RAD_SENSOR 1 +#define DEBUG_SUS 1 #include "OBSWVersion.h" diff --git a/fsfwconfig/devices/addresses.h b/fsfwconfig/devices/addresses.h index 26a86b2a..3de3a105 100644 --- a/fsfwconfig/devices/addresses.h +++ b/fsfwconfig/devices/addresses.h @@ -21,6 +21,20 @@ namespace addresses { RAD_SENSOR = objects::RAD_SENSOR, + SUS_1 = objects::SUS_1, + SUS_2 = objects::SUS_2, + SUS_3 = objects::SUS_3, + SUS_4 = objects::SUS_4, + SUS_5 = objects::SUS_5, + SUS_6 = objects::SUS_6, + SUS_7 = objects::SUS_7, + SUS_8 = objects::SUS_8, + SUS_9 = objects::SUS_9, + SUS_10 = objects::SUS_10, + SUS_11 = objects::SUS_11, + SUS_12 = objects::SUS_12, + SUS_13 = objects::SUS_13, + /* Dummy and Test Addresses */ DUMMY_ECHO = 129, DUMMY_GPS0 = 130, diff --git a/fsfwconfig/devices/gpioIds.h b/fsfwconfig/devices/gpioIds.h index 8b9edffc..3221c613 100644 --- a/fsfwconfig/devices/gpioIds.h +++ b/fsfwconfig/devices/gpioIds.h @@ -44,6 +44,20 @@ namespace gpioIds { RTD_IC17, RTD_IC18, + CS_SUS_1, + CS_SUS_2, + CS_SUS_3, + CS_SUS_4, + CS_SUS_5, + CS_SUS_6, + CS_SUS_7, + CS_SUS_8, + CS_SUS_9, + CS_SUS_10, + CS_SUS_11, + CS_SUS_12, + CS_SUS_13, + SPI_MUX_BIT_1, SPI_MUX_BIT_2, SPI_MUX_BIT_3, diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index 1249b862..c1f792eb 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -84,6 +84,20 @@ namespace objects { RAD_SENSOR = 0x54000050, + SUS_1 = 0x54000051, + SUS_2 = 0x54000052, + SUS_3 = 0x54000053, + SUS_4 = 0x54000054, + SUS_5 = 0x54000055, + SUS_6 = 0x54000056, + SUS_7 = 0x54000057, + SUS_8 = 0x54000058, + SUS_9 = 0x54000059, + SUS_10 = 0x5400005A, + SUS_11 = 0x5400005B, + SUS_12 = 0x5400005C, + SUS_13 = 0x5400005D, + /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, LIBGPIOD_TEST = 0x54123456, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index a54d70ba..31b56865 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -150,6 +150,13 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); + /* Sun sensor 1 */ + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 4088d98b..9965fedc 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -15,6 +15,7 @@ target_sources(${TARGET_NAME} PUBLIC IMTQHandler.cpp PlocHandler.cpp RadiationSensorHandler.cpp + SusHandler.cpp ) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 64391c79..8d44ea9a 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -31,25 +31,7 @@ void RadiationSensorHandler::doShutDown(){ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - - switch (communicationStep) { - case CommunicationStep::START_CONVERSION: { - *id = RAD_SENSOR::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; - } - case CommunicationStep::READ_CONVERSIONS: { - *id = RAD_SENSOR::READ_CONVERSIONS; -// communicationStep = CommunicationStep::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; - } - default: { - sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " - << "step" << std::endl; - return HasReturnvaluesIF::RETURN_OK; - } - } + *id = RAD_SENSOR::PERFORM_CONVERSION; return buildCommandFromCommand(*id, nullptr, 0); } @@ -61,7 +43,7 @@ ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( else { return HasReturnvaluesIF::RETURN_OK; } - buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( @@ -75,23 +57,17 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(RAD_SENSOR::START_CONVERSION): { + case(RAD_SENSOR::PERFORM_CONVERSION): { + /* Dummy bytes are written to remove old values from fifo */ cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = 1; - return RETURN_OK; - } - case(RAD_SENSOR::READ_CONVERSIONS): { - cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; - cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; - cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; - cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; - cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; - cmdBuffer[6] = RAD_SENSOR::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; + cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; } default: return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; @@ -101,8 +77,7 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( void RadiationSensorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); - this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, + this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset, RAD_SENSOR::READ_SIZE); } @@ -116,7 +91,7 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case RAD_SENSOR::READ_CONVERSIONS: { + case RAD_SENSOR::PERFORM_CONVERSION: { PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp new file mode 100644 index 00000000..3339ff26 --- /dev/null +++ b/mission/devices/SusHandler.cpp @@ -0,0 +1,165 @@ +#include +#include +#include + +SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "SusHandler: Invalid com cookie" << std::endl; + } +} + +SusHandler::~SusHandler() { +} + + +void SusHandler::doStartUp(){ + if (internalState == InternalState::CONFIGURED) { +#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 + setMode(MODE_NORMAL); +#else + setMode(_MODE_TO_ON); +#endif + } +} + +void SusHandler::doShutDown(){ + setMode(_MODE_POWER_DOWN); +} + +ReturnValue_t SusHandler::buildNormalDeviceCommand( + DeviceCommandId_t * id) { + + switch (communicationStep) { + case CommunicationStep::START_CONVERSION: { + *id = SUS::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = SUS::READ_CONVERSIONS; +// communicationStep = CommunicationStep::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + default: { + sif::debug << "SusHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t SusHandler::buildTransitionDeviceCommand( + DeviceCommandId_t * id){ + if (internalState == InternalState::SETUP) { + *id = SUS::WRITE_SETUP; + } + else { + return HasReturnvaluesIF::RETURN_OK; + } + return buildCommandFromCommand(*id, nullptr, 0); +} + +ReturnValue_t SusHandler::buildCommandFromCommand( + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(SUS::WRITE_SETUP): { + cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + rawPacket = cmdBuffer; + rawPacketLen = 2; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(SUS::START_CONVERSION): { + cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + return RETURN_OK; + } + case(SUS::READ_CONVERSIONS): { + cmdBuffer[0] = SUS::DUMMY_BYTE; + cmdBuffer[1] = SUS::DUMMY_BYTE; + cmdBuffer[2] = SUS::DUMMY_BYTE; + cmdBuffer[3] = SUS::DUMMY_BYTE; + cmdBuffer[4] = SUS::DUMMY_BYTE; + cmdBuffer[5] = SUS::DUMMY_BYTE; + cmdBuffer[6] = SUS::DUMMY_BYTE; + cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[8] = SUS::DUMMY_BYTE; + rawPacket = cmdBuffer; + rawPacketLen = SUS::READ_SIZE; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; +} + +void SusHandler::fillCommandAndReplyMap() { + this->insertInCommandMap(SUS::WRITE_SETUP); + this->insertInCommandMap(SUS::START_CONVERSION); + this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, + SUS::READ_SIZE); +} + +ReturnValue_t SusHandler::scanForReply(const uint8_t *start, + size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) { + *foundId = this->getPendingCommand(); + *foundLen = remainingSize; + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) { + switch (id) { + case SUS::READ_CONVERSIONS: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.diffScanChannel0_1 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.diffScanChannel2_3 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.diffScanChannel4_5 = (*(packet + 2) << 8 | *(packet + 3)); +#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS + sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: " + << dataset.temperatureCelcius << " °C" << std::endl; + sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 0/1: " + << dataset.diffScanChannel0_1 << std::endl; + sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 2/3: " + << dataset.diffScanChannel2_3 << std::endl; + sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 4/5: " + << dataset.diffScanChannel4_5 << std::endl; +#endif + break; + } + default: { + sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } + + } + return HasReturnvaluesIF::RETURN_OK; +} + +void SusHandler::setNormalDatapoolEntriesInvalid(){ + +} + +uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ + return 5000; +} + +ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry( { 0.0 })); + localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_0_1, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_2_3, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_4_5, new PoolEntry( { 0 })); + return HasReturnvaluesIF::RETURN_OK; +} + diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h new file mode 100644 index 00000000..445722a8 --- /dev/null +++ b/mission/devices/SusHandler.h @@ -0,0 +1,61 @@ +#ifndef MISSION_DEVICES_SUSHANDLER_H_ +#define MISSION_DEVICES_SUSHANDLER_H_ + +#include +#include + +/** + * @brief This is the device handler class for the SUS sensor. The sensor is + * based on the MAX1227 ADC. Details about the SUS electronic can be found at + * https://egit.irs.uni-stuttgart.de/eive/eive_dokumente/src/branch/master/400_Raumsegment/443_SunSensorDocumentation/release + * + * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf + * + * @author J. Meier + */ +class SusHandler: public DeviceHandlerBase { +public: + + SusHandler(object_id_t objectId, object_id_t comIF, + CookieIF * comCookie); + virtual ~SusHandler(); + +protected: + void doStartUp() override; + void doShutDown() override; + ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override; + ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override; + void fillCommandAndReplyMap() override; + ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData,size_t commandDataLen) override; + ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, + DeviceCommandId_t *foundId, size_t *foundLen) override; + ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) override; + void setNormalDatapoolEntriesInvalid() override; + uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + +private: + + enum class CommunicationStep { + START_CONVERSION, + READ_CONVERSIONS + }; + + enum class InternalState { + SETUP, + CONFIGURED + }; + + SUS::SusDataset dataset; + + static const uint8_t MAX_CMD_LEN = SUS::READ_SIZE; + + uint8_t cmdBuffer[MAX_CMD_LEN]; + InternalState internalState = InternalState::SETUP; + CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; +}; + +#endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index 46e5be40..c962b2e2 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -10,11 +10,8 @@ namespace RAD_SENSOR { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t START_CONVERSION = 0x2; + static const DeviceCommandId_t PERFORM_CONVERSION = 0x2; static const DeviceCommandId_t READ_CONVERSIONS = 0x3; - - static const uint32_t MAX1227_DATA_SET_ID = READ_CONVERSIONS; - /** * @brief This is the configuration byte which will be written to the setup register after * power on. @@ -37,12 +34,6 @@ namespace RAD_SENSOR { */ static const uint8_t CONVERSION_DEFINITION = 0b10001001; - /** - * Unipolar only required for differential measurement. Unipolar or dipolar determines the - * voltage range. - */ - static const uint8_t UNIPOLAR_SETUP = 0b10000000; - static const uint8_t DUMMY_BYTE = 0xFF; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h new file mode 100644 index 00000000..efc56959 --- /dev/null +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -0,0 +1,83 @@ +#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ +#define MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ + +namespace SUS { + + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending + + /** + * This command initiates the ADC conversion for all channels including the internal + * temperature sensor. + */ + static const DeviceCommandId_t WRITE_SETUP = 0x1; + static const DeviceCommandId_t START_CONVERSION = 0x2; + static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + + /** + * @brief This is the configuration byte which will be written to the setup register after + * power on. + * + * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the + * unipolar register to perform differential conversion + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b11, external reference differential (AIN6 is REF-) + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing + * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * + */ + static const uint8_t SETUP_DEFINITION = 0b01101110; + + /** + * @brief This byte will be written to the unipolar register + * + * @details Setting bits 7 - 5 to will configure channels 0/1, 2/3 and 4/5 as differential + * pairs. + */ + static const uint8_t UNIPOLAR_CONFIG = 0b11100000; + + /** + * @brief This value will always be written to the ADC conversion register to specify the + * conversions to perform. + * @details Bit0: 1 - Enables temperature conversion + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00 (channel conversion from 0 to N) + * Bit6 - Bit3 defines N: 0b0001 (N = 4) + * Bit7: Always 1. Tells the ADC that this is the conversion register. + */ + static const uint8_t CONVERSION_DEFINITION = 0b10100001; + + static const uint8_t DUMMY_BYTE = 0xFF; + + static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; + + /** + * One temperature value, one differential conversion for channels 0/1, one for channels 2/3 and + * one for channels 3/4 + */ + static const uint8_t READ_SIZE = 8; + + enum Max1227PoolIds: lp_id_t { + TEMPERATURE_C, + DIFF_SCAN_CHANNEL_0_1, + DIFF_SCAN_CHANNEL_2_3, + DIFF_SCAN_CHANNEL_4_5, + }; + +class SusDataset: public StaticLocalDataSet { +public: + + SusDataset(HasLocalDataPoolIF* owner) : + StaticLocalDataSet(owner, SUS_DATA_SET_ID) { + } + + SusDataset(object_id_t objectId) : + StaticLocalDataSet(sid_t(objectId, SUS_DATA_SET_ID)) { + } + + lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); + lp_var_t diffScanChannel0_1 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_0_1, this); + lp_var_t diffScanChannel2_3 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_2_3, this); + lp_var_t diffScanChannel4_5 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_4_5, this); +}; +} + + +#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_SUS_H_ */ From 31b4246bca2426e3958e480ac1e33db32b22372b Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 12:05:19 +0200 Subject: [PATCH 24/42] another try to read out the adc --- mission/devices/RadiationSensorHandler.cpp | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 8d44ea9a..38a1f148 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -31,8 +31,29 @@ void RadiationSensorHandler::doShutDown(){ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - *id = RAD_SENSOR::PERFORM_CONVERSION; - return buildCommandFromCommand(*id, nullptr, 0); + switch (communicationStep) { + case CommunicationStep::FIRST_CONVERSION: { + *id = RAD_SENSOR::FIRST_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::PERFORM_CONVERSION: { + *id = RAD_SENSOR::PERFORM_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = RAD_SENSOR::READ_CONVERSIONS; + communicationStep = CommunicationStep::PERFRORM_CONVERSION; + break; + } + default: { + sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( @@ -57,6 +78,13 @@ ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } + case(RAD_SENSOR::FIRST_CONVERSION): { + /* Dummy bytes are written to remove old values from fifo */ + cmdBuffer[0] = RAD_SENSOR::FIRST_CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } case(RAD_SENSOR::PERFORM_CONVERSION): { /* Dummy bytes are written to remove old values from fifo */ cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; From fd9adee1aee97616822aa88f2bc3a87e1dec875a Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 12:49:14 +0200 Subject: [PATCH 25/42] rad sensor working --- bsp_q7s/ObjectFactory.cpp | 137 ++++-------------- mission/devices/RadiationSensorHandler.cpp | 121 ++++++++-------- mission/devices/SusHandler.cpp | 6 +- .../devicedefinitions/RadSensorDefinitions.h | 8 +- .../devicedefinitions/SusDefinitions.h | 5 + 5 files changed, 100 insertions(+), 177 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 776a3e4b..9d0b9ecb 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -26,13 +26,11 @@ #include #include #include -#include #include #include #include #include -#include #include #include @@ -108,8 +106,14 @@ void ObjectFactory::produce(){ #endif /* Temperature sensors */ - new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); - new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); + Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler( + objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, + i2cCookieTmp1075tcs1); +// tmp1075Handler_1->setStartUpImmediately(); + Tmp1075Handler* tmp1075Handler_2 = new Tmp1075Handler( + objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, + i2cCookieTmp1075tcs2); +// tmp1075Handler_2->setStartUpImmediately(); GpioCookie* heaterGpiosCookie = new GpioCookie; @@ -147,98 +151,6 @@ void ObjectFactory::produce(){ (void) pdu2handler; (void) acuhandler; - /* Adding gpios for chip select decoding to the gpioComIf */ - gpioCallbacks::initSpiCsDecoder(gpioComIF); - - GpioCookie* gpioCookieSus = new GpioCookie(); - - GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_1, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 2"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_2, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 3"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_3, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 4"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_4, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 5"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_5, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 6"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_6, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 7"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_7, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 8"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_8, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 9"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_9, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 10"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_10, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 11"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_11, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 12"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_12, susgpio); - susgpio = new GpioCallback(std::string("Chip select SUS 13"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); - gpioCookieSus->addGpio(gpioIds::CS_SUS_13, susgpio); - - gpioComIF->addGpios(gpioCookieSus); - - SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, - std::string("/dev/spidev2.0"), SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); - (void) sus1; -// sus1->setStartUpImmediately(); - - new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); - new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); - new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); - new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); - new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); - new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); - new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); - new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); - new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11); - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); - #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); GpiodRegular* gpio = nullptr; @@ -375,53 +287,54 @@ void ObjectFactory::produce(){ #if Q7S_ADD_RTD_DEVICES == 1 GpioCookie* rtdGpioCookie = new GpioCookie; + gpioCallbacks::initTcsBoardDecoder(gpioComIF); GpioCallback* gpioRtdIc3 = new GpioCallback(std::string("Chip select RTD IC3"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC3, gpioRtdIc3); GpioCallback* gpioRtdIc4 = new GpioCallback(std::string("Chip select RTD IC4"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC4, gpioRtdIc4); GpioCallback* gpioRtdIc5 = new GpioCallback(std::string("Chip select RTD IC5"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC5, gpioRtdIc5); GpioCallback* gpioRtdIc6 = new GpioCallback(std::string("Chip select RTD IC6"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC6, gpioRtdIc6); GpioCallback* gpioRtdIc7 = new GpioCallback(std::string("Chip select RTD IC7"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC7, gpioRtdIc7); GpioCallback* gpioRtdIc8 = new GpioCallback(std::string("Chip select RTD IC8"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC8, gpioRtdIc8); GpioCallback* gpioRtdIc9 = new GpioCallback(std::string("Chip select RTD IC9"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC9, gpioRtdIc9); GpioCallback* gpioRtdIc10 = new GpioCallback(std::string("Chip select RTD IC10"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC10, gpioRtdIc10); GpioCallback* gpioRtdIc11 = new GpioCallback(std::string("Chip select RTD IC11"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC11, gpioRtdIc11); GpioCallback* gpioRtdIc12 = new GpioCallback(std::string("Chip select RTD IC12"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC12, gpioRtdIc12); GpioCallback* gpioRtdIc13 = new GpioCallback(std::string("Chip select RTD IC13"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC13, gpioRtdIc13); GpioCallback* gpioRtdIc14 = new GpioCallback(std::string("Chip select RTD IC14"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC14, gpioRtdIc14); GpioCallback* gpioRtdIc15 = new GpioCallback(std::string("Chip select RTD IC15"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC15, gpioRtdIc15); GpioCallback* gpioRtdIc16 = new GpioCallback(std::string("Chip select RTD IC16"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC16, gpioRtdIc16); GpioCallback* gpioRtdIc17 = new GpioCallback(std::string("Chip select RTD IC17"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC17, gpioRtdIc17); GpioCallback* gpioRtdIc18 = new GpioCallback(std::string("Chip select RTD IC18"), gpio::OUT, 1, - &gpioCallbacks::spiCsDecoderCallback, gpioComIF); + &gpioCallbacks::tcsBoardDecoderCallback, gpioComIF); rtdGpioCookie->addGpio(gpioIds::RTD_IC18, gpioRtdIc18); gpioComIF->addGpios(rtdGpioCookie); diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 38a1f148..bd16ddaf 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -3,12 +3,12 @@ #include RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; - } + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; + } } RadiationSensorHandler::~RadiationSensorHandler() { @@ -30,21 +30,17 @@ void RadiationSensorHandler::doShutDown(){ } ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { + DeviceCommandId_t * id) { + switch (communicationStep) { - case CommunicationStep::FIRST_CONVERSION: { - *id = RAD_SENSOR::FIRST_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; - } - case CommunicationStep::PERFORM_CONVERSION: { - *id = RAD_SENSOR::PERFORM_CONVERSION; + case CommunicationStep::START_CONVERSION: { + *id = RAD_SENSOR::START_CONVERSION; communicationStep = CommunicationStep::READ_CONVERSIONS; break; } case CommunicationStep::READ_CONVERSIONS: { *id = RAD_SENSOR::READ_CONVERSIONS; - communicationStep = CommunicationStep::PERFRORM_CONVERSION; + communicationStep = CommunicationStep::START_CONVERSION; break; } default: { @@ -57,55 +53,56 @@ ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( } ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( - DeviceCommandId_t * id){ + DeviceCommandId_t * id){ if (internalState == InternalState::SETUP) { *id = RAD_SENSOR::WRITE_SETUP; } else { return HasReturnvaluesIF::RETURN_OK; } - return buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) { - switch(deviceCommand) { - case(RAD_SENSOR::WRITE_SETUP): { - cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = 1; - internalState = InternalState::CONFIGURED; - return RETURN_OK; - } - case(RAD_SENSOR::FIRST_CONVERSION): { - /* Dummy bytes are written to remove old values from fifo */ - cmdBuffer[0] = RAD_SENSOR::FIRST_CONVERSION_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; - } - case(RAD_SENSOR::PERFORM_CONVERSION): { - /* Dummy bytes are written to remove old values from fifo */ - cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; - cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(RAD_SENSOR::WRITE_SETUP): { + cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(RAD_SENSOR::START_CONVERSION): { + /* First the fifo will be reset here */ + cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; + cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 2; + return RETURN_OK; + } + case(RAD_SENSOR::READ_CONVERSIONS): { + cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; - } - default: - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; } void RadiationSensorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset, + this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); + this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, RAD_SENSOR::READ_SIZE); } @@ -118,12 +115,12 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { - switch (id) { - case RAD_SENSOR::PERFORM_CONVERSION: { - PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; - dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); + switch (id) { + case RAD_SENSOR::READ_CONVERSIONS: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_RAD_SENSOR sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" << std::endl; @@ -132,15 +129,15 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "Radiation sensor temperature ADC value channel 1: " << dataset.channel1 << std::endl; #endif - break; - } - default: { - sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } + break; + } + default: { + sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } - } - return HasReturnvaluesIF::RETURN_OK; + } + return HasReturnvaluesIF::RETURN_OK; } void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ @@ -148,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 5000; } ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3339ff26..69aee06d 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -77,9 +77,11 @@ ReturnValue_t SusHandler::buildCommandFromCommand( return RETURN_OK; } case(SUS::START_CONVERSION): { - cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + /* First the fifo will be reset before a new conversion is initiated */ + cmdBuffer[0] = SUS::RESET_DEFINITION; + cmdBuffer[1] = SUS::CONVERSION_DEFINITION; rawPacket = cmdBuffer; - rawPacketLen = 1; + rawPacketLen = 2; return RETURN_OK; } case(SUS::READ_CONVERSIONS): { diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index c962b2e2..db105495 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -10,8 +10,9 @@ namespace RAD_SENSOR { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t PERFORM_CONVERSION = 0x2; + static const DeviceCommandId_t START_CONVERSION = 0x2; static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + /** * @brief This is the configuration byte which will be written to the setup register after * power on. @@ -34,6 +35,11 @@ namespace RAD_SENSOR { */ static const uint8_t CONVERSION_DEFINITION = 0b10001001; + /** + * @brief Writing this value resets the fifo of the MAX1227. + */ + static const uint8_t RESET_DEFINITION = 0b00011000; + static const uint8_t DUMMY_BYTE = 0xFF; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index efc56959..7d48259b 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -34,6 +34,11 @@ namespace SUS { */ static const uint8_t UNIPOLAR_CONFIG = 0b11100000; + /** + * @brief Writing this value resets the fifo of the MAX1227. + */ + static const uint8_t RESET_DEFINITION = 0b00011000; + /** * @brief This value will always be written to the ADC conversion register to specify the * conversions to perform. From 3c6ec68faa48f05304b24a3113c06fc8c10555d1 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 3 May 2021 13:35:16 +0200 Subject: [PATCH 26/42] rad sensor working --- mission/devices/RadiationSensorHandler.cpp | 123 +++++++++++------- .../devicedefinitions/RadSensorDefinitions.h | 8 +- 2 files changed, 81 insertions(+), 50 deletions(-) diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index 8d44ea9a..bd16ddaf 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -3,12 +3,12 @@ #include RadiationSensorHandler::RadiationSensorHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; - } + CookieIF * comCookie) : + DeviceHandlerBase(objectId, comIF, comCookie), dataset( + this) { + if (comCookie == NULL) { + sif::error << "RadiationSensorHandler: Invalid com cookie" << std::endl; + } } RadiationSensorHandler::~RadiationSensorHandler() { @@ -30,54 +30,79 @@ void RadiationSensorHandler::doShutDown(){ } ReturnValue_t RadiationSensorHandler::buildNormalDeviceCommand( - DeviceCommandId_t * id) { - *id = RAD_SENSOR::PERFORM_CONVERSION; - return buildCommandFromCommand(*id, nullptr, 0); + DeviceCommandId_t * id) { + + switch (communicationStep) { + case CommunicationStep::START_CONVERSION: { + *id = RAD_SENSOR::START_CONVERSION; + communicationStep = CommunicationStep::READ_CONVERSIONS; + break; + } + case CommunicationStep::READ_CONVERSIONS: { + *id = RAD_SENSOR::READ_CONVERSIONS; + communicationStep = CommunicationStep::START_CONVERSION; + break; + } + default: { + sif::debug << "RadiationSensorHandler::buildNormalDeviceCommand: Unknwon communication " + << "step" << std::endl; + return HasReturnvaluesIF::RETURN_OK; + } + } + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildTransitionDeviceCommand( - DeviceCommandId_t * id){ + DeviceCommandId_t * id){ if (internalState == InternalState::SETUP) { *id = RAD_SENSOR::WRITE_SETUP; } else { return HasReturnvaluesIF::RETURN_OK; } - return buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t RadiationSensorHandler::buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) { - switch(deviceCommand) { - case(RAD_SENSOR::WRITE_SETUP): { - cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; - rawPacket = cmdBuffer; - rawPacketLen = 1; - internalState = InternalState::CONFIGURED; - return RETURN_OK; - } - case(RAD_SENSOR::PERFORM_CONVERSION): { - /* Dummy bytes are written to remove old values from fifo */ - cmdBuffer[0] = RAD_SENSOR::CONVERSION_DEFINITION; - cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; + DeviceCommandId_t deviceCommand, const uint8_t * commandData, + size_t commandDataLen) { + switch(deviceCommand) { + case(RAD_SENSOR::WRITE_SETUP): { + cmdBuffer[0] = RAD_SENSOR::SETUP_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 1; + internalState = InternalState::CONFIGURED; + return RETURN_OK; + } + case(RAD_SENSOR::START_CONVERSION): { + /* First the fifo will be reset here */ + cmdBuffer[0] = RAD_SENSOR::RESET_DEFINITION; + cmdBuffer[1] = RAD_SENSOR::CONVERSION_DEFINITION; + rawPacket = cmdBuffer; + rawPacketLen = 2; + return RETURN_OK; + } + case(RAD_SENSOR::READ_CONVERSIONS): { + cmdBuffer[0] = RAD_SENSOR::DUMMY_BYTE; + cmdBuffer[1] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[2] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[3] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[4] = RAD_SENSOR::DUMMY_BYTE; cmdBuffer[5] = RAD_SENSOR::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = RAD_SENSOR::READ_SIZE; - return RETURN_OK; - } - default: - return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; - } - return HasReturnvaluesIF::RETURN_FAILED; + rawPacket = cmdBuffer; + rawPacketLen = RAD_SENSOR::READ_SIZE; + return RETURN_OK; + } + default: + return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; + } + return HasReturnvaluesIF::RETURN_FAILED; } void RadiationSensorHandler::fillCommandAndReplyMap() { this->insertInCommandMap(RAD_SENSOR::WRITE_SETUP); - this->insertInCommandAndReplyMap(RAD_SENSOR::PERFORM_CONVERSION, 1, &dataset, + this->insertInCommandMap(RAD_SENSOR::START_CONVERSION); + this->insertInCommandAndReplyMap(RAD_SENSOR::READ_CONVERSIONS, 1, &dataset, RAD_SENSOR::READ_SIZE); } @@ -90,12 +115,12 @@ ReturnValue_t RadiationSensorHandler::scanForReply(const uint8_t *start, ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { - switch (id) { - case RAD_SENSOR::PERFORM_CONVERSION: { - PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; - dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); + switch (id) { + case RAD_SENSOR::READ_CONVERSIONS: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.channel0 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.channel1 = (*(packet + 4) << 8 | *(packet + 5)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_RAD_SENSOR sif::info << "Radiation sensor temperature: " << dataset.temperatureCelcius << " °C" << std::endl; @@ -104,15 +129,15 @@ ReturnValue_t RadiationSensorHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "Radiation sensor temperature ADC value channel 1: " << dataset.channel1 << std::endl; #endif - break; - } - default: { - sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; - return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; - } + break; + } + default: { + sif::debug << "RadiationSensorHandler::interpretDeviceReply: Unknown reply id" << std::endl; + return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; + } - } - return HasReturnvaluesIF::RETURN_OK; + } + return HasReturnvaluesIF::RETURN_OK; } void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ @@ -120,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 5000; } ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index c962b2e2..db105495 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -10,8 +10,9 @@ namespace RAD_SENSOR { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t PERFORM_CONVERSION = 0x2; + static const DeviceCommandId_t START_CONVERSION = 0x2; static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + /** * @brief This is the configuration byte which will be written to the setup register after * power on. @@ -34,6 +35,11 @@ namespace RAD_SENSOR { */ static const uint8_t CONVERSION_DEFINITION = 0b10001001; + /** + * @brief Writing this value resets the fifo of the MAX1227. + */ + static const uint8_t RESET_DEFINITION = 0b00011000; + static const uint8_t DUMMY_BYTE = 0xFF; static const uint8_t RAD_SENSOR_DATA_SET_ID = READ_CONVERSIONS; From 5ce0a63ad6bd8f3c0848ed0538ce77e113556f2c Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 6 May 2021 18:00:58 +0200 Subject: [PATCH 27/42] save before implementing SusHandler with chip select --- bsp_q7s/ObjectFactory.cpp | 147 ++++++++++++------ fsfwconfig/OBSWConfig.h | 13 +- fsfwconfig/devices/spi.h | 3 +- fsfwconfig/objects/systemObjectList.h | 29 ++-- .../pollingSequenceFactory.cpp | 56 +++++-- mission/devices/SusHandler.cpp | 94 ++++++----- mission/devices/SusHandler.h | 10 +- .../devicedefinitions/SusDefinitions.h | 34 ++-- 8 files changed, 246 insertions(+), 140 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 776a3e4b..a0c6e964 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -150,6 +150,23 @@ void ObjectFactory::produce(){ /* Adding gpios for chip select decoding to the gpioComIf */ gpioCallbacks::initSpiCsDecoder(gpioComIF); + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip5"), 19, + std::string("Chip Select Radiation Sensor"), gpio::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + +// SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, +// std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, +// spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); +// RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, +// objects::SPI_COM_IF, spiCookieRadSensor); +// (void) radSensor; +// radSensor->setStartUpImmediately(); + GpioCookie* gpioCookieSus = new GpioCookie(); GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, @@ -195,47 +212,70 @@ void ObjectFactory::produce(){ gpioComIF->addGpios(gpioCookieSus); SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, - std::string("/dev/spidev2.0"), SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, + std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), - SUS::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); - (void) sus1; // sus1->setStartUpImmediately(); + (void) sus1; + + SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); +// sus2->setStartUpImmediately(); + (void) sus2; + + SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); + sus3->setStartUpImmediately(); + (void) sus3; - new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); - new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); - new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); + SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); +// sus8->setStartUpImmediately(); + (void) sus8; + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); - new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11); + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieRadSensor); + sus11->setStartUpImmediately(); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); @@ -526,19 +566,6 @@ void ObjectFactory::produce(){ // plocHandler->setStartUpImmediately(); (void) plocHandler; - GpioCookie* gpioCookieRadSensor = new GpioCookie; - GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip5"), 19, - std::string("Chip Select Radiation Sensor"), gpio::OUT, 1); - gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); - gpioComIF->addGpios(gpioCookieRadSensor); - - SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, - std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); - RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, - objects::SPI_COM_IF, spiCookieRadSensor); - radSensor->setStartUpImmediately(); - #endif /* TE0720 == 0 */ new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR, objects::TM_STORE, @@ -552,8 +579,40 @@ void ObjectFactory::produce(){ GpioCookie* gpioCookie = new GpioCookie; gpioCookie->addGpio(gpioIds::TEST_ID_0, gpioConfigMio0); new LibgpiodTest(objects::LIBGPIOD_TEST, objects::GPIO_IF, gpioCookie); -#elif TE0720 == 1 +#endif +#if TE0720 == 1 && TEST_SUS_HANDLER == 1 + GpioCookie* gpioCookieSus = new GpioCookie; + GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip0"), 9, + std::string("Chip Select Sus Sensor"), gpio::OUT, 1); + gpioCookieSus->addGpio(gpioIds::CS_SUS_1, chipSelectSus); + gpioComIF->addGpios(gpioCookieSus); + + SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, + std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus); + sus1->setStartUpImmediately(); +#endif + +#if TE0720 == 1 && TEST_RADIATION_SENSOR_HANDLER == 1 + GpioCookie* gpioCookieRadSensor = new GpioCookie; + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip0"), 9, + std::string("Chip select radiation sensor"), gpio::OUT, 1); + gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); + gpioComIF->addGpios(gpioCookieRadSensor); + + SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, + std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + spi::DEFAULT_MAX_1227_SPEED); + + RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, + objects::SPI_COM_IF, spiCookieRadSensor); + radSensor->setStartUpImmediately(); +#endif + +#if TE0720 == 1 && TEST_PLOC_HANDLER == 1 UartCookie* plocUartCookie = new UartCookie(std::string("/dev/ttyPS1"), 115200, PLOC::MAX_REPLY_SIZE); /* Testing PlocHandler on TE0720-03-1CFA */ diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index d6a059e6..ea73eb1c 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -16,12 +16,15 @@ /* These defines should be disabled for mission code but are useful for debugging. */ -#define OBSW_VERBOSE_LEVEL 1 -#define OBSW_PRINT_MISSED_DEADLINES 1 -#define OBSW_ADD_TEST_CODE 1 -#define TEST_LIBGPIOD 0 +#define OBSW_VERBOSE_LEVEL 1 +#define OBSW_PRINT_MISSED_DEADLINES 1 +#define OBSW_ADD_TEST_CODE 1 +#define TEST_LIBGPIOD 0 +#define TEST_RADIATION_SENSOR_HANDLER 0 +#define TEST_SUS_HANDLER 1 +#define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index eb17786b..29a345d4 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,7 +20,8 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; +//static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 2'900'000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; } diff --git a/fsfwconfig/objects/systemObjectList.h b/fsfwconfig/objects/systemObjectList.h index c1f792eb..746e83cf 100644 --- a/fsfwconfig/objects/systemObjectList.h +++ b/fsfwconfig/objects/systemObjectList.h @@ -54,6 +54,21 @@ namespace objects { IMTQ_HANDLER = 0x44000014, PLOC_HANDLER = 0x44000015, + + SUS_1 = 0x44000016, + SUS_2 = 0x44000017, + SUS_3 = 0x44000018, + SUS_4 = 0x44000019, + SUS_5 = 0x4400001A, + SUS_6 = 0x4400001B, + SUS_7 = 0x4400001C, + SUS_8 = 0x4400001D, + SUS_9 = 0x4400001E, + SUS_10 = 0x4400001F, + SUS_11 = 0x44000021, + SUS_12 = 0x44000022, + SUS_13 = 0x44000023, + /* Custom device handler */ PCDU_HANDLER = 0x44001000, SOLAR_ARRAY_DEPL_HANDLER = 0x44001001, @@ -84,20 +99,6 @@ namespace objects { RAD_SENSOR = 0x54000050, - SUS_1 = 0x54000051, - SUS_2 = 0x54000052, - SUS_3 = 0x54000053, - SUS_4 = 0x54000054, - SUS_5 = 0x54000055, - SUS_6 = 0x54000056, - SUS_7 = 0x54000057, - SUS_8 = 0x54000058, - SUS_9 = 0x54000059, - SUS_10 = 0x5400005A, - SUS_11 = 0x5400005B, - SUS_12 = 0x5400005C, - SUS_13 = 0x5400005D, - /* 0x54 ('T') for test handlers */ TEST_TASK = 0x54694269, LIBGPIOD_TEST = 0x54123456, diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 31b56865..5667ef12 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -144,11 +144,11 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /* Radiation sensor */ - thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); /* Sun sensor 1 */ thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); @@ -157,6 +157,18 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_2, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_2, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_2, length * 0.8, DeviceHandlerIF::GET_READ); + +// thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_11, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_11, length * 0.8, DeviceHandlerIF::GET_READ); + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; } @@ -340,16 +352,30 @@ ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { uint32_t length = thisSequence->getPeriodMs(); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); +#if TEST_PLOC_HANDLER == 1 + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + +#if TEST_SUS_HANDLER == 1 + thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + +#if TEST_RADIATION_SENSOR_HANDLER == 1 + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +#endif + if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "Initialization of TE0720 PST failed" << std::endl; diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3339ff26..d4b91650 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie) : @@ -31,26 +32,16 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - - switch (communicationStep) { - case CommunicationStep::START_CONVERSION: { - *id = SUS::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; + if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { + *id = SUS::PERFORM_CONVERSIONS; +// communicationStep = CommunicationStep::READ_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } - case CommunicationStep::READ_CONVERSIONS: { - *id = SUS::READ_CONVERSIONS; -// communicationStep = CommunicationStep::START_CONVERSION; - communicationStep = CommunicationStep::READ_CONVERSIONS; - break; + else if (communicationStep == CommunicationStep::READ_TEMP) { + *id = SUS::READ_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } - default: { - sif::debug << "SusHandler::buildNormalDeviceCommand: Unknwon communication " - << "step" << std::endl; - return HasReturnvaluesIF::RETURN_OK; - } - } - return buildCommandFromCommand(*id, nullptr, 0); + return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t SusHandler::buildTransitionDeviceCommand( @@ -76,24 +67,44 @@ ReturnValue_t SusHandler::buildCommandFromCommand( internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(SUS::START_CONVERSION): { - cmdBuffer[0] = SUS::CONVERSION_DEFINITION; + case(SUS::PERFORM_CONVERSIONS): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + /** + * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a + * measurement the setup has to be rewritten + */ + cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + // wirte one dummy byte here +// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; + cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; +// struct timeval startOfDelay; +// gettimeofday(&startOfDelay, NULL); +// struct timeval currentTime; +// gettimeofday(¤tTime, NULL); +// while (currentTime.tv_usec - startOfDelay.tv_usec < 1000) { +// gettimeofday(¤tTime, NULL); +// } + +// cmdBuffer[27] = SUS::CONVERT_DIFF_CHANNEL_0_1; +// cmdBuffer[29] = SUS::CONVERT_DIFF_CHANNEL_2_3; +// cmdBuffer[31] = SUS::CONVERT_DIFF_CHANNEL_4_5; + +// cmdBuffer[0] = SUS::SETUP_DEFINITION; +// cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; +// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; +// cmdBuffer[26] = SUS::CONVERT_DIFF_CHANNEL_0_1; +// cmdBuffer[28] = SUS::CONVERT_DIFF_CHANNEL_2_3; +// cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; - rawPacketLen = 1; +// rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; + rawPacketLen = 7; return RETURN_OK; } - case(SUS::READ_CONVERSIONS): { - cmdBuffer[0] = SUS::DUMMY_BYTE; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::DUMMY_BYTE; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::DUMMY_BYTE; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::DUMMY_BYTE; - cmdBuffer[7] = SUS::DUMMY_BYTE; - cmdBuffer[8] = SUS::DUMMY_BYTE; - rawPacket = cmdBuffer; - rawPacketLen = SUS::READ_SIZE; + case(SUS::READ_TEMP): { + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + rawPacket = cmdBuffer; + rawPacketLen = 26; return RETURN_OK; } default: @@ -104,9 +115,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandMap(SUS::START_CONVERSION); - this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, - SUS::READ_SIZE); + this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); +// this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, +// SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -119,12 +131,12 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::READ_CONVERSIONS: { + case SUS::PERFORM_CONVERSIONS: { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; - dataset.diffScanChannel0_1 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.diffScanChannel2_3 = (*(packet + 2) << 8 | *(packet + 3)); - dataset.diffScanChannel4_5 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; + dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); + dataset.diffScanChannel2_3 = (*(packet + 31) << 8 | *(packet + 32)); + dataset.diffScanChannel4_5 = (*(packet + 33) << 8 | *(packet + 34)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: " << dataset.temperatureCelcius << " °C" << std::endl; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 445722a8..2780556f 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -40,8 +40,8 @@ protected: private: enum class CommunicationStep { - START_CONVERSION, - READ_CONVERSIONS + PERFORM_CONVERSIONS, + READ_TEMP }; enum class InternalState { @@ -51,11 +51,9 @@ private: SUS::SusDataset dataset; - static const uint8_t MAX_CMD_LEN = SUS::READ_SIZE; - - uint8_t cmdBuffer[MAX_CMD_LEN]; + uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; InternalState internalState = InternalState::SETUP; - CommunicationStep communicationStep = CommunicationStep::START_CONVERSION; + CommunicationStep communicationStep = CommunicationStep::PERFORM_CONVERSIONS; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index efc56959..98ea7589 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -10,8 +10,8 @@ namespace SUS { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t START_CONVERSION = 0x2; - static const DeviceCommandId_t READ_CONVERSIONS = 0x3; + static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; + static const DeviceCommandId_t READ_TEMP = 0x3; /** * @brief This is the configuration byte which will be written to the setup register after @@ -19,12 +19,15 @@ namespace SUS { * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the * unipolar register to perform differential conversion - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b11, external reference differential (AIN6 is REF-) - * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference differential (AIN6 is REF-) + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01101110; +// static const uint8_t SETUP_DEFINITION = 0b0111110; + + // Internal reference 0b10 + static const uint8_t SETUP_DEFINITION = 0b0111010; /** * @brief This byte will be written to the unipolar register @@ -38,21 +41,24 @@ namespace SUS { * @brief This value will always be written to the ADC conversion register to specify the * conversions to perform. * @details Bit0: 1 - Enables temperature conversion - * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00 (channel conversion from 0 to N) + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b11, No scan, converts channel N once only. + * Scanning is not supported in spi clock mode. * Bit6 - Bit3 defines N: 0b0001 (N = 4) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ - static const uint8_t CONVERSION_DEFINITION = 0b10100001; +// static const uint8_t CONVERT_TEMPERATURE = 0b10000111; + static const uint8_t CONVERT_TEMPERATURE = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; + static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; - static const uint8_t DUMMY_BYTE = 0xFF; + static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; + static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; - /** - * One temperature value, one differential conversion for channels 0/1, one for channels 2/3 and - * one for channels 3/4 - */ - static const uint8_t READ_SIZE = 8; + static const uint8_t SIZE_PERFORM_CONVERSIONS = 34; + + static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, From 1eb99093774b9dfbb156f441a0af71a88ad57575 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Fri, 7 May 2021 18:48:42 +0200 Subject: [PATCH 28/42] save before making change in spicomif --- bsp_q7s/ObjectFactory.cpp | 59 +++++++----- bsp_q7s/gpio/gpioCallbacks.cpp | 93 ++++++++++--------- bsp_q7s/gpio/gpioCallbacks.h | 9 +- fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/devices/spi.h | 4 +- .../pollingSequenceFactory.cpp | 20 ++-- mission/devices/SusHandler.cpp | 44 +++++---- mission/devices/SusHandler.h | 7 +- .../devicedefinitions/SusDefinitions.h | 24 ++--- 9 files changed, 142 insertions(+), 120 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index a0c6e964..6af5921b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -156,16 +156,12 @@ void ObjectFactory::produce(){ gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); gpioComIF->addGpios(gpioCookieRadSensor); -// SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, -// std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, -// spi::DEFAULT_MAX_1227_SPEED); SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, - std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, + std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); -// RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, -// objects::SPI_COM_IF, spiCookieRadSensor); -// (void) radSensor; -// radSensor->setStartUpImmediately(); + RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, + objects::SPI_COM_IF, spiCookieRadSensor); + (void) radSensor; GpioCookie* gpioCookieSus = new GpioCookie(); @@ -251,33 +247,45 @@ void ObjectFactory::produce(){ std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1); + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, + gpioIds::CS_SUS_1); // sus1->setStartUpImmediately(); (void) sus1; - SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2); -// sus2->setStartUpImmediately(); + SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, + gpioIds::CS_SUS_2); + sus2->setStartUpImmediately(); (void) sus2; - SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3); + SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, + gpioIds::CS_SUS_3); sus3->setStartUpImmediately(); (void) sus3; - new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4); - new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5); - new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6); - new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7); - SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8); -// sus8->setStartUpImmediately(); - (void) sus8; + new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, + gpioIds::CS_SUS_4); + new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5, gpioComIF, + gpioIds::CS_SUS_5); + new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6, gpioComIF, + gpioIds::CS_SUS_6); + new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7, gpioComIF, + gpioIds::CS_SUS_7); + SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, + gpioIds::CS_SUS_8); + sus8->setStartUpImmediately(); - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9); - new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10); - SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieRadSensor); + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, + gpioIds::CS_SUS_9); + new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, + gpioIds::CS_SUS_10); + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, + gpioComIF, gpioIds::CS_SUS_11); sus11->setStartUpImmediately(); - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, + gpioIds::CS_SUS_12); + new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, + gpioIds::CS_SUS_13); #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); @@ -592,7 +600,8 @@ void ObjectFactory::produce(){ std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus); + SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus, gpioComIF, + gpioIds::CS_SUS_1); sus1->setStartUpImmediately(); #endif diff --git a/bsp_q7s/gpio/gpioCallbacks.cpp b/bsp_q7s/gpio/gpioCallbacks.cpp index a40f6ba4..2f59cb0e 100644 --- a/bsp_q7s/gpio/gpioCallbacks.cpp +++ b/bsp_q7s/gpio/gpioCallbacks.cpp @@ -58,19 +58,18 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value void* args) { if (gpioComInterface == nullptr) { - sif::debug << "tcsBoardDecoderCallback: No gpioComIF specified. Call initTcsBoardDecoder " + sif::debug << "spiCsDecoderCallback: No gpioComIF specified. Call initSpiCsDecoder " << "to specify gpioComIF" << std::endl; return; } - /* Read is not supported by the callback function */ + /* Reading is not supported by the callback function */ if (gpioOp == gpio::GpioOperation::READ) { return; } if (value == 1) { - /* This will pull all 16 decoder outputs to high */ - gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); + disableAllDecoder(); } else if (value == 0) { switch (gpioId) { @@ -155,70 +154,70 @@ void spiCsDecoderCallback(gpioId_t gpioId, gpio::GpioOperation gpioOp, int value break; } case(gpioIds::CS_SUS_1): { - enableDecoderInterfaceBoardIc21(); + enableDecoderInterfaceBoardIc1(); selectY0(); break; } case(gpioIds::CS_SUS_2): { - enableDecoderInterfaceBoardIc21(); + enableDecoderInterfaceBoardIc1(); selectY1(); break; } case(gpioIds::CS_SUS_3): { - enableDecoderInterfaceBoardIc21(); - selectY2(); - break; - } - case(gpioIds::CS_SUS_4): { - enableDecoderInterfaceBoardIc21(); - selectY3(); - break; - } - case(gpioIds::CS_SUS_5): { - enableDecoderInterfaceBoardIc21(); - selectY4(); - break; - } - case(gpioIds::CS_SUS_6): { - enableDecoderInterfaceBoardIc21(); - selectY5(); - break; - } - case(gpioIds::CS_SUS_7): { - enableDecoderInterfaceBoardIc21(); - selectY6(); - break; - } - case(gpioIds::CS_SUS_8): { - enableDecoderInterfaceBoardIc22(); + enableDecoderInterfaceBoardIc2(); selectY0(); break; } - case(gpioIds::CS_SUS_9): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_4): { + enableDecoderInterfaceBoardIc2(); selectY1(); break; } - case(gpioIds::CS_SUS_10): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_5): { + enableDecoderInterfaceBoardIc2(); selectY2(); break; } - case(gpioIds::CS_SUS_11): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_6): { + enableDecoderInterfaceBoardIc1(); + selectY2(); + break; + } + case(gpioIds::CS_SUS_7): { + enableDecoderInterfaceBoardIc1(); selectY3(); break; } - case(gpioIds::CS_SUS_12): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_8): { + enableDecoderInterfaceBoardIc2(); + selectY3(); + break; + } + case(gpioIds::CS_SUS_9): { + enableDecoderInterfaceBoardIc1(); selectY4(); break; } - case(gpioIds::CS_SUS_13): { - enableDecoderInterfaceBoardIc22(); + case(gpioIds::CS_SUS_10): { + enableDecoderInterfaceBoardIc1(); selectY5(); break; } + case(gpioIds::CS_SUS_11): { + enableDecoderInterfaceBoardIc2(); + selectY4(); + break; + } + case(gpioIds::CS_SUS_12): { + enableDecoderInterfaceBoardIc2(); + selectY5(); + break; + } + case(gpioIds::CS_SUS_13): { + enableDecoderInterfaceBoardIc1(); + selectY6(); + break; + } default: sif::debug << "spiCsDecoderCallback: Invalid gpio id " << gpioId << std::endl; } @@ -240,13 +239,13 @@ void enableDecoderTcsIc2() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); } -void enableDecoderInterfaceBoardIc21() { +void enableDecoderInterfaceBoardIc1() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); } -void enableDecoderInterfaceBoardIc22() { +void enableDecoderInterfaceBoardIc2() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_1); gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_3); @@ -300,4 +299,10 @@ void selectY7() { gpioComInterface->pullHigh(gpioIds::SPI_MUX_BIT_6); } +void disableAllDecoder() { + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_1); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_2); + gpioComInterface->pullLow(gpioIds::SPI_MUX_BIT_3); +} + } diff --git a/bsp_q7s/gpio/gpioCallbacks.h b/bsp_q7s/gpio/gpioCallbacks.h index 67ae4dc2..4a0c73cb 100644 --- a/bsp_q7s/gpio/gpioCallbacks.h +++ b/bsp_q7s/gpio/gpioCallbacks.h @@ -35,13 +35,18 @@ namespace gpioCallbacks { * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC21 in the schematic. */ - void enableDecoderInterfaceBoardIc21(); + void enableDecoderInterfaceBoardIc1(); /** * @brief This function sets mux bits 1-3 to a state which will only enable the decoder * on the inteface board board which is named to IC22 in the schematic. */ - void enableDecoderInterfaceBoardIc22(); + void enableDecoderInterfaceBoardIc2(); + + /** + * @brief This function disables all decoder. + */ + void disableAllDecoder(); /** The following functions enable the appropriate channel of the currently enabled decoder */ void selectY0(); diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index ea73eb1c..5db2e7d0 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 29a345d4..9558fb89 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,8 +21,8 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; //static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 2'900'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1'000'000; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 5667ef12..76571fc9 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -151,17 +151,17 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); /* Sun sensor 1 */ - thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::SUS_2, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_2, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_2, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_2, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_2, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); // thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index d4b91650..2ebe1858 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,15 +1,14 @@ #include #include #include -#include -SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie) : - DeviceHandlerBase(objectId, comIF, comCookie), dataset( - this) { - if (comCookie == NULL) { - sif::error << "SusHandler: Invalid com cookie" << std::endl; - } +SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, + LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId) : + DeviceHandlerBase(objectId, comIF, comCookie), gpioComIF(gpioComIF), chipSelectId( + chipSelectId), dataset(this) { + if (comCookie == NULL) { + sif::error << "SusHandler: Invalid com cookie" << std::endl; + } } SusHandler::~SusHandler() { @@ -34,8 +33,8 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { *id = SUS::PERFORM_CONVERSIONS; -// communicationStep = CommunicationStep::READ_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::READ_TEMP; +// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; @@ -61,23 +60,23 @@ ReturnValue_t SusHandler::buildCommandFromCommand( switch(deviceCommand) { case(SUS::WRITE_SETUP): { cmdBuffer[0] = SUS::SETUP_DEFINITION; - cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; rawPacket = cmdBuffer; - rawPacketLen = 2; + rawPacketLen = 0; internalState = InternalState::CONFIGURED; return RETURN_OK; } case(SUS::PERFORM_CONVERSIONS): { + gpioComIF->pullLow(chipSelectId); std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); /** * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a * measurement the setup has to be rewritten */ - cmdBuffer[0] = SUS::SETUP_DEFINITION; - cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; + cmdBuffer[0] = SUS::RESET_FIFO; + cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_0_1; // struct timeval startOfDelay; // gettimeofday(&startOfDelay, NULL); // struct timeval currentTime; @@ -98,13 +97,16 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 7; + rawPacketLen = 5; return RETURN_OK; } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); + cmdBuffer[0] = SUS::RESET_FIFO; + cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 26; + rawPacketLen = 27; return RETURN_OK; } default: @@ -115,7 +117,9 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); +// this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); // this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, // SUS::SIZE_PERFORM_CONVERSIONS); this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); @@ -149,6 +153,10 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, #endif break; } + case SUS::READ_TEMP: { + gpioComIF->pullHigh(chipSelectId); + break; + } default: { sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 2780556f..e5cc68ae 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -3,6 +3,7 @@ #include #include +#include /** * @brief This is the device handler class for the SUS sensor. The sensor is @@ -17,7 +18,7 @@ class SusHandler: public DeviceHandlerBase { public: SusHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie); + CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); protected: @@ -49,6 +50,10 @@ private: CONFIGURED }; + LinuxLibgpioIF* gpioComIF = nullptr; + + gpioId_t chipSelectId = gpio::NO_GPIO; + SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 98ea7589..1b3cbe70 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -17,25 +17,13 @@ namespace SUS { * @brief This is the configuration byte which will be written to the setup register after * power on. * - * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b10, following byte will be written to the - * unipolar register to perform differential conversion - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference differential (AIN6 is REF-) + * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b00, internal reference, needs wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ -// static const uint8_t SETUP_DEFINITION = 0b0111110; - - // Internal reference 0b10 - static const uint8_t SETUP_DEFINITION = 0b0111010; - - /** - * @brief This byte will be written to the unipolar register - * - * @details Setting bits 7 - 5 to will configure channels 0/1, 2/3 and 4/5 as differential - * pairs. - */ - static const uint8_t UNIPOLAR_CONFIG = 0b11100000; + static const uint8_t SETUP_DEFINITION = 0b01110000; /** * @brief This value will always be written to the ADC conversion register to specify the @@ -46,12 +34,13 @@ namespace SUS { * Bit6 - Bit3 defines N: 0b0001 (N = 4) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ -// static const uint8_t CONVERT_TEMPERATURE = 0b10000111; - static const uint8_t CONVERT_TEMPERATURE = 0b10000110; + static const uint8_t CONVERT_TEMPERATURE = 0b10000001; static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; + static const uint8_t RESET_FIFO = 0b00011000; + static const uint8_t DUMMY_BYTE = 0x0; static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; @@ -60,6 +49,7 @@ namespace SUS { static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; + enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, DIFF_SCAN_CHANNEL_0_1, From be29d0e71fdacb673ffbd56529f9dc62ffd7c44f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sat, 8 May 2021 22:49:21 +0200 Subject: [PATCH 29/42] some tries to get data from max1227 in externally clocked mode --- bsp_q7s/ObjectFactory.cpp | 2 +- fsfwconfig/OBSWConfig.h | 2 +- fsfwconfig/devices/spi.h | 2 +- mission/devices/SusHandler.cpp | 41 ++++++++++--------- mission/devices/SusHandler.h | 1 + .../devicedefinitions/SusDefinitions.h | 9 ++-- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6af5921b..5dae58db 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -228,7 +228,7 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpioIds::CS_SUS_8, + SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 5db2e7d0..ea73eb1c 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 9558fb89..18b91c6f 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,7 +21,7 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; //static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1'000'000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 2ebe1858..0469f60c 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -33,9 +33,13 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { *id = SUS::PERFORM_CONVERSIONS; - communicationStep = CommunicationStep::READ_TEMP; + communicationStep = CommunicationStep::REQUEST_TEMP; // communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } + else if (communicationStep == CommunicationStep::REQUEST_TEMP) { + *id = SUS::RQUEST_TEMP; + communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; communicationStep = CommunicationStep::PERFORM_CONVERSIONS; @@ -66,7 +70,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( return RETURN_OK; } case(SUS::PERFORM_CONVERSIONS): { - gpioComIF->pullLow(chipSelectId); +// gpioComIF->pullLow(chipSelectId); std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); /** * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a @@ -76,18 +80,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// struct timeval startOfDelay; -// gettimeofday(&startOfDelay, NULL); -// struct timeval currentTime; -// gettimeofday(¤tTime, NULL); -// while (currentTime.tv_usec - startOfDelay.tv_usec < 1000) { -// gettimeofday(¤tTime, NULL); -// } - -// cmdBuffer[27] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// cmdBuffer[29] = SUS::CONVERT_DIFF_CHANNEL_2_3; -// cmdBuffer[31] = SUS::CONVERT_DIFF_CHANNEL_4_5; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_2; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -100,13 +93,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand( rawPacketLen = 5; return RETURN_OK; } + case(SUS::RQUEST_TEMP): { +// gpioComIF->pullLow(chipSelectId); + std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); +// cmdBuffer[0] = SUS::RESET_FIFO; +// cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; + rawPacket = cmdBuffer; + rawPacketLen = 25; + return RETURN_OK; + } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[1] = SUS::SETUP_DEFINITION; - cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 27; + rawPacketLen = 0; return RETURN_OK; } default: @@ -122,7 +122,7 @@ void SusHandler::fillCommandAndReplyMap() { this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); // this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, // SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandMap(SUS::PERFORM_CONVERSIONS); + this->insertInCommandMap(SUS::RQUEST_TEMP); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -136,6 +136,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { case SUS::PERFORM_CONVERSIONS: { +// gpioComIF->pullHigh(chipSelectId); PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); @@ -154,7 +155,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, break; } case SUS::READ_TEMP: { - gpioComIF->pullHigh(chipSelectId); +// gpioComIF->pullHigh(chipSelectId); break; } default: { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index e5cc68ae..2fb2a6a8 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -42,6 +42,7 @@ private: enum class CommunicationStep { PERFORM_CONVERSIONS, + REQUEST_TEMP, READ_TEMP }; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 1b3cbe70..6e795775 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -12,6 +12,7 @@ namespace SUS { static const DeviceCommandId_t WRITE_SETUP = 0x1; static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; static const DeviceCommandId_t READ_TEMP = 0x3; + static const DeviceCommandId_t RQUEST_TEMP = 0x4; /** * @brief This is the configuration byte which will be written to the setup register after @@ -35,9 +36,11 @@ namespace SUS { * Bit7: Always 1. Tells the ADC that this is the conversion register. */ static const uint8_t CONVERT_TEMPERATURE = 0b10000001; - static const uint8_t CONVERT_DIFF_CHANNEL_0_1 = 0b10000110; - static const uint8_t CONVERT_DIFF_CHANNEL_2_3 = 0b10010110; - static const uint8_t CONVERT_DIFF_CHANNEL_4_5 = 0b10100110; + static const uint8_t CONVERT_DIFF_CHANNEL_0 = 0b10000110; + static const uint8_t CONVERT_DIFF_CHANNEL_1 = 0b10001110; + static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; + static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; + static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; static const uint8_t RESET_FIFO = 0b00011000; From eeb8167cdc937749b769132727828d189680fb9f Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 10:06:36 +0200 Subject: [PATCH 30/42] this worked with the prototype SUS --- mission/devices/SusHandler.cpp | 10 +++++----- mission/devices/devicedefinitions/SusDefinitions.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 0469f60c..15062148 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -38,7 +38,7 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( } else if (communicationStep == CommunicationStep::REQUEST_TEMP) { *id = SUS::RQUEST_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::READ_TEMP; } else if (communicationStep == CommunicationStep::READ_TEMP) { *id = SUS::READ_TEMP; @@ -65,7 +65,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( case(SUS::WRITE_SETUP): { cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; - rawPacketLen = 0; + rawPacketLen = 1; internalState = InternalState::CONFIGURED; return RETURN_OK; } @@ -80,7 +80,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -100,13 +100,13 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[1] = SUS::SETUP_DEFINITION; cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; - rawPacketLen = 25; + rawPacketLen = 1; return RETURN_OK; } case(SUS::READ_TEMP): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - rawPacketLen = 0; + rawPacketLen = 24; return RETURN_OK; } default: diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 6e795775..438d761d 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -24,7 +24,7 @@ namespace SUS { * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01110000; + static const uint8_t SETUP_DEFINITION = 0b01111000; /** * @brief This value will always be written to the ADC conversion register to specify the From 950eab2373e83689fa22caa139b6594e9d60f1b7 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 12:09:39 +0200 Subject: [PATCH 31/42] this works with the old SUS --- fsfwconfig/OBSWConfig.h | 2 +- mission/devices/SusHandler.cpp | 18 ++++++++++++------ mission/devices/SusHandler.h | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index ea73eb1c..5db2e7d0 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 15062148..b351ff43 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -31,9 +31,14 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { - if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { - *id = SUS::PERFORM_CONVERSIONS; + if (communicationStep == CommunicationStep::WRITE_SETUP) { + *id = SUS::WRITE_SETUP; communicationStep = CommunicationStep::REQUEST_TEMP; +// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + } + else if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { + *id = SUS::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::WRITE_SETUP; // communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } else if (communicationStep == CommunicationStep::REQUEST_TEMP) { @@ -63,6 +68,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( size_t commandDataLen) { switch(deviceCommand) { case(SUS::WRITE_SETUP): { + gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 1; @@ -76,11 +82,11 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a * measurement the setup has to be rewritten */ - cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[1] = SUS::SETUP_DEFINITION; +// cmdBuffer[0] = SUS::RESET_FIFO; +// cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_1; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; @@ -90,7 +96,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 5; + rawPacketLen = 3; return RETURN_OK; } case(SUS::RQUEST_TEMP): { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 2fb2a6a8..aabecac1 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -43,7 +43,8 @@ private: enum class CommunicationStep { PERFORM_CONVERSIONS, REQUEST_TEMP, - READ_TEMP + READ_TEMP, + WRITE_SETUP }; enum class InternalState { From 98387a6d24eb4684290d2781c6fc4cddd952b8fd Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 14:39:56 +0200 Subject: [PATCH 32/42] this works with q7s and new sus --- mission/devices/SusHandler.cpp | 19 +++++++++++++++---- mission/devices/SusHandler.h | 2 +- .../devicedefinitions/SusDefinitions.h | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index b351ff43..25c01c87 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -86,8 +86,19 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[1] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_1; - + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[1] = SUS::DUMMY_BYTE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[3] = SUS::DUMMY_BYTE; + cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[5] = SUS::DUMMY_BYTE; + cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; + cmdBuffer[10] = SUS::DUMMY_BYTE; + cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[12] = SUS::DUMMY_BYTE; + cmdBuffer[13] = SUS::DUMMY_BYTE; // cmdBuffer[0] = SUS::SETUP_DEFINITION; // cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; @@ -96,7 +107,7 @@ ReturnValue_t SusHandler::buildCommandFromCommand( // cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; // rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 3; + rawPacketLen = 14; return RETURN_OK; } case(SUS::RQUEST_TEMP): { @@ -142,7 +153,7 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { case SUS::PERFORM_CONVERSIONS: { -// gpioComIF->pullHigh(chipSelectId); + gpioComIF->pullHigh(chipSelectId); PoolReadGuard readSet(&dataset); dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index aabecac1..fdc4b28a 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -60,7 +60,7 @@ private: uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; InternalState internalState = InternalState::SETUP; - CommunicationStep communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 438d761d..0985ce99 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -19,7 +19,7 @@ namespace SUS { * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b00, internal reference, needs wake-up delay + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * @@ -41,6 +41,7 @@ namespace SUS { static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; + static const uint8_t CONVERT_DIFF_CHANNEL_5 = 0b10101110; static const uint8_t RESET_FIFO = 0b00011000; From 261f16f15b10b90d1b972833cee0be8779d2ed24 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 14:46:42 +0200 Subject: [PATCH 33/42] write setup byte and conversions --- mission/devices/SusHandler.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 25c01c87..3468d113 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -83,17 +83,17 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * measurement the setup has to be rewritten */ // cmdBuffer[0] = SUS::RESET_FIFO; -// cmdBuffer[1] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::SETUP_DEFINITION; // wirte one dummy byte here // cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[1] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[2] = SUS::DUMMY_BYTE; + cmdBuffer[3] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[4] = SUS::DUMMY_BYTE; + cmdBuffer[5] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[6] = SUS::DUMMY_BYTE; + cmdBuffer[7] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[8] = SUS::DUMMY_BYTE; cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; cmdBuffer[10] = SUS::DUMMY_BYTE; cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; From fab28904de17c21ad941a3a1ee9c7a683d678ef5 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 16:48:55 +0200 Subject: [PATCH 34/42] working SUS in externally clocked mode --- bsp_q7s/ObjectFactory.cpp | 26 +-- fsfwconfig/devices/spi.h | 3 +- .../pollingSequenceFactory.cpp | 46 ++++- mission/devices/SusHandler.cpp | 168 +++++++++--------- mission/devices/SusHandler.h | 14 +- .../devicedefinitions/SusDefinitions.h | 42 +++-- 6 files changed, 170 insertions(+), 129 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 5dae58db..af880406 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -209,43 +209,43 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SUS::SUS_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 18b91c6f..2d6a01ba 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -20,8 +20,7 @@ static constexpr spi::SpiModes DEFAULT_RM3100_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; -//static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 1000000; +static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 76571fc9..fe2eaf65 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -157,11 +157,47 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); // thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); + if (length != 3) { + sif::waring << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " + << "SUS sensors still produce correct values" << std::endl; + } + + /** + * The sun sensor will be shutdown as soon as the chip select is pulled high. Thus all + * requests to a sun sensor must be performed consecutively. Another reason for calling multiple + * device handler cycles is that some ADC conversions need a small delay before the results can + * be read. + * One sun sensor communication sequence also blocks the SPI bus. So other devices can not be + * inserted between the device handler cycles of one SUS. + */ + + /* Write setup */ + thisSequence->addSlot(objects::SUS_8, length * 0.991, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.992, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.993, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.994, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.995, DeviceHandlerIF::GET_READ); + + /* Request temperature */ + thisSequence->addSlot(objects::SUS_8, length * 0.996, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.997, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.998, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.999, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::GET_READ); + + /* Read temperature */ + thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); + + /* Request and read ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); // thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); // thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 3468d113..4f3dc834 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -9,6 +9,9 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo if (comCookie == NULL) { sif::error << "SusHandler: Invalid com cookie" << std::endl; } + if (gpioComIF == NULL) { + sif::error << "SusHandler: Invalid GpioComIF" << std::endl; + } } SusHandler::~SusHandler() { @@ -16,13 +19,11 @@ SusHandler::~SusHandler() { void SusHandler::doStartUp(){ - if (internalState == InternalState::CONFIGURED) { #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 - setMode(MODE_NORMAL); + setMode(MODE_NORMAL); #else - setMode(_MODE_TO_ON); + setMode(_MODE_TO_ON); #endif - } } void SusHandler::doShutDown(){ @@ -33,34 +34,26 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; - communicationStep = CommunicationStep::REQUEST_TEMP; -// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; + communicationStep = CommunicationStep::REQUEST_TEMPERATURE; } - else if (communicationStep == CommunicationStep::PERFORM_CONVERSIONS) { - *id = SUS::PERFORM_CONVERSIONS; + else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) { + *id = SUS::REQUEST_TEMPERATURE; + communicationStep = CommunicationStep::READ_TEMPERATURE; + } + else if (communicationStep == CommunicationStep::READ_TEMPERATURE) { + *id = SUS::READ_TEMPERATURE; + communicationStep = CommunicationStep::READ_CHANNELS; + } + else if (communicationStep == CommunicationStep::READ_CHANNELS) { + *id = SUS::READ_CHANNELS; communicationStep = CommunicationStep::WRITE_SETUP; -// communicationStep = CommunicationStep::PERFORM_CONVERSIONS; - } - else if (communicationStep == CommunicationStep::REQUEST_TEMP) { - *id = SUS::RQUEST_TEMP; - communicationStep = CommunicationStep::READ_TEMP; - } - else if (communicationStep == CommunicationStep::READ_TEMP) { - *id = SUS::READ_TEMP; - communicationStep = CommunicationStep::PERFORM_CONVERSIONS; } return buildCommandFromCommand(*id, nullptr, 0); } ReturnValue_t SusHandler::buildTransitionDeviceCommand( DeviceCommandId_t * id){ - if (internalState == InternalState::SETUP) { - *id = SUS::WRITE_SETUP; - } - else { - return HasReturnvaluesIF::RETURN_OK; - } - return buildCommandFromCommand(*id, nullptr, 0); + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t SusHandler::buildCommandFromCommand( @@ -68,59 +61,46 @@ ReturnValue_t SusHandler::buildCommandFromCommand( size_t commandDataLen) { switch(deviceCommand) { case(SUS::WRITE_SETUP): { + /** + * The sun sensor ADC is shutdown when CS is pulled high, so each time requesting a + * measurement the setup has to be rewritten. There must also be a little delay between + * the transmission of the setup byte and the first conversion. Thus the conversion + * will be performed in an extra step. + */ + //TODO: Protect spi bus with mutex gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP_DEFINITION; rawPacket = cmdBuffer; rawPacketLen = 1; - internalState = InternalState::CONFIGURED; return RETURN_OK; } - case(SUS::PERFORM_CONVERSIONS): { -// gpioComIF->pullLow(chipSelectId); + case(SUS::READ_CHANNELS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - /** - * The sun sensor ADC is shutdown when CS is pulled high so each time requesting a - * measurement the setup has to be rewritten - */ -// cmdBuffer[0] = SUS::RESET_FIFO; - cmdBuffer[0] = SUS::SETUP_DEFINITION; - // wirte one dummy byte here -// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; - cmdBuffer[1] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[2] = SUS::DUMMY_BYTE; - cmdBuffer[3] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[4] = SUS::DUMMY_BYTE; - cmdBuffer[5] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[6] = SUS::DUMMY_BYTE; - cmdBuffer[7] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[8] = SUS::DUMMY_BYTE; - cmdBuffer[9] = SUS::CONVERT_DIFF_CHANNEL_4; - cmdBuffer[10] = SUS::DUMMY_BYTE; - cmdBuffer[11] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; + cmdBuffer[1] = SUS::DUMMY_BYTE; + cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; + cmdBuffer[3] = SUS::DUMMY_BYTE; + cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; + cmdBuffer[5] = SUS::DUMMY_BYTE; + cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; + cmdBuffer[7] = SUS::DUMMY_BYTE; + cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4; + cmdBuffer[9] = SUS::DUMMY_BYTE; + cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5; + cmdBuffer[11] = SUS::DUMMY_BYTE; cmdBuffer[12] = SUS::DUMMY_BYTE; - cmdBuffer[13] = SUS::DUMMY_BYTE; -// cmdBuffer[0] = SUS::SETUP_DEFINITION; -// cmdBuffer[1] = SUS::UNIPOLAR_CONFIG; -// cmdBuffer[2] = SUS::CONVERT_TEMPERATURE; -// cmdBuffer[26] = SUS::CONVERT_DIFF_CHANNEL_0_1; -// cmdBuffer[28] = SUS::CONVERT_DIFF_CHANNEL_2_3; -// cmdBuffer[30] = SUS::CONVERT_DIFF_CHANNEL_4_5; rawPacket = cmdBuffer; -// rawPacketLen = SUS::SIZE_PERFORM_CONVERSIONS; - rawPacketLen = 14; + rawPacketLen = SUS::SIZE_READ_CHANNELS; return RETURN_OK; } - case(SUS::RQUEST_TEMP): { -// gpioComIF->pullLow(chipSelectId); + case(SUS::REQUEST_TEMPERATURE): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); -// cmdBuffer[0] = SUS::RESET_FIFO; -// cmdBuffer[1] = SUS::SETUP_DEFINITION; cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; rawPacket = cmdBuffer; rawPacketLen = 1; return RETURN_OK; } - case(SUS::READ_TEMP): { + case(SUS::READ_TEMPERATURE): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; rawPacketLen = 24; @@ -134,12 +114,10 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); -// this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandAndReplyMap(SUS::READ_TEMP, 1, nullptr, SUS::SIZE_PERFORM_CONVERSIONS); -// this->insertInCommandAndReplyMap(SUS::PERFORM_CONVERSIONS, 1, &dataset, -// SUS::SIZE_PERFORM_CONVERSIONS); - this->insertInCommandMap(SUS::RQUEST_TEMP); + this->insertInCommandMap(SUS::REQUEST_TEMPERATURE); + this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS); + this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr, + SUS::SIZE_READ_TEMPERATURE); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -152,27 +130,42 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::PERFORM_CONVERSIONS: { - gpioComIF->pullHigh(chipSelectId); + case SUS::READ_CHANNELS: { PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + 25) << 8 | *(packet + 26)) * 0.125; - dataset.diffScanChannel0_1 = (*(packet + 29) << 8 | *(packet + 30)); - dataset.diffScanChannel2_3 = (*(packet + 31) << 8 | *(packet + 32)); - dataset.diffScanChannel4_5 = (*(packet + 33) << 8 | *(packet + 34)); + dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2)); + dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4)); + dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6)); + dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8)); + dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10)); + dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", temperature: " - << dataset.temperatureCelcius << " °C" << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 0/1: " - << dataset.diffScanChannel0_1 << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 2/3: " - << dataset.diffScanChannel2_3 << std::endl; - sif::info << "SUS with object id " << std::hex << this->getObjectId() << ", channel 4/5: " - << dataset.diffScanChannel4_5 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: " + << std::dec << dataset.ain0 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: " + << std::dec << dataset.ain1 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN2: " + << std::dec << dataset.ain2 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN3: " + << std::dec << dataset.ain3 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN4: " + << std::dec << dataset.ain4 << std::endl; + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: " + << std::dec << dataset.ain5 << std::endl; #endif + /** + * Reading the channel conversion results is the last communication step in one SUS + * sequence. SPI bus can now be released again. + */ + gpioComIF->pullHigh(chipSelectId); break; } - case SUS::READ_TEMP: { -// gpioComIF->pullHigh(chipSelectId); + case SUS::READ_TEMPERATURE: { + PoolReadGuard readSet(&dataset); + dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125; +#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: " + << dataset.temperatureCelcius << " °C" << std::endl; +#endif break; } default: { @@ -189,15 +182,18 @@ void SusHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t SusHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 1000; } ReturnValue_t SusHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { localDataPoolMap.emplace(SUS::TEMPERATURE_C, new PoolEntry( { 0.0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_0_1, new PoolEntry( { 0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_2_3, new PoolEntry( { 0 })); - localDataPoolMap.emplace(SUS::DIFF_SCAN_CHANNEL_4_5, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN0, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN1, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN2, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN3, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN4, new PoolEntry( { 0 })); + localDataPoolMap.emplace(SUS::AIN5, new PoolEntry( { 0 })); return HasReturnvaluesIF::RETURN_OK; } diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index fdc4b28a..5ef7ec32 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -41,15 +41,10 @@ protected: private: enum class CommunicationStep { - PERFORM_CONVERSIONS, - REQUEST_TEMP, - READ_TEMP, - WRITE_SETUP - }; - - enum class InternalState { - SETUP, - CONFIGURED + WRITE_SETUP, + REQUEST_TEMPERATURE, + READ_TEMPERATURE, + READ_CHANNELS }; LinuxLibgpioIF* gpioComIF = nullptr; @@ -59,7 +54,6 @@ private: SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; - InternalState internalState = InternalState::SETUP; CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; }; diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 0985ce99..fc46f75f 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -3,6 +3,12 @@ namespace SUS { + /** + * The MAX1227 in externally clocked mode did not properly work with frequencies higher than + * 1 MHz. + */ + static const uint32_t SUS_MAX_1227_SPEED = 1000000; + static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending /** @@ -10,9 +16,9 @@ namespace SUS { * temperature sensor. */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t PERFORM_CONVERSIONS = 0x2; - static const DeviceCommandId_t READ_TEMP = 0x3; - static const DeviceCommandId_t RQUEST_TEMP = 0x4; + static const DeviceCommandId_t READ_CHANNELS = 0x2; + static const DeviceCommandId_t READ_TEMPERATURE = 0x3; + static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4; /** * @brief This is the configuration byte which will be written to the setup register after @@ -47,21 +53,28 @@ namespace SUS { static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = PERFORM_CONVERSIONS; + static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS; - static const uint8_t SIZE_PERFORM_CONVERSIONS = 34; + /** Size of data replies */ + static const uint8_t SIZE_READ_CHANNELS = 13; + static const uint8_t SIZE_READ_TEMPERATURE = 25; - static const uint8_t MAX_CMD_SIZE = SIZE_PERFORM_CONVERSIONS; + static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE; + + static const uint8_t POOL_ENTRIES = 7; enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, - DIFF_SCAN_CHANNEL_0_1, - DIFF_SCAN_CHANNEL_2_3, - DIFF_SCAN_CHANNEL_4_5, + AIN0, + AIN1, + AIN2, + AIN3, + AIN4, + AIN5, }; -class SusDataset: public StaticLocalDataSet { +class SusDataset: public StaticLocalDataSet { public: SusDataset(HasLocalDataPoolIF* owner) : @@ -73,9 +86,12 @@ public: } lp_var_t temperatureCelcius = lp_var_t(sid.objectId, TEMPERATURE_C, this); - lp_var_t diffScanChannel0_1 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_0_1, this); - lp_var_t diffScanChannel2_3 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_2_3, this); - lp_var_t diffScanChannel4_5 = lp_var_t(sid.objectId, DIFF_SCAN_CHANNEL_4_5, this); + lp_var_t ain0 = lp_var_t(sid.objectId, AIN0, this); + lp_var_t ain1 = lp_var_t(sid.objectId, AIN1, this); + lp_var_t ain2 = lp_var_t(sid.objectId, AIN2, this); + lp_var_t ain3 = lp_var_t(sid.objectId, AIN3, this); + lp_var_t ain4 = lp_var_t(sid.objectId, AIN4, this); + lp_var_t ain5 = lp_var_t(sid.objectId, AIN5, this); }; } From a6465c42ba116cb50529f8ef61a7dc48d48a80a2 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 9 May 2021 18:18:27 +0200 Subject: [PATCH 35/42] save before changing to internally clocked mode --- bsp_q7s/ObjectFactory.cpp | 42 ++++--- fsfwconfig/devices/spi.h | 2 +- .../pollingSequenceFactory.cpp | 112 +++++++++++++----- 3 files changed, 105 insertions(+), 51 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index af880406..6524c64b 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -161,7 +161,8 @@ void ObjectFactory::produce(){ spi::DEFAULT_MAX_1227_SPEED); RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); - (void) radSensor; +// (void) radSensor; + radSensor->setStartUpImmediately(); GpioCookie* gpioCookieSus = new GpioCookie(); @@ -207,59 +208,56 @@ void ObjectFactory::produce(){ gpioComIF->addGpios(gpioCookieSus); - SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, + SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpioIds::CS_SUS_2, + SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpioIds::CS_SUS_3, + SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpioIds::CS_SUS_4, + SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpioIds::CS_SUS_5, + SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpioIds::CS_SUS_6, + SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpioIds::CS_SUS_7, + SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpioIds::CS_SUS_9, + SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpioIds::CS_SUS_10, + SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpioIds::CS_SUS_11, + SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpioIds::CS_SUS_12, + SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); - SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpioIds::CS_SUS_13, + SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::SUS_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); -// sus1->setStartUpImmediately(); (void) sus1; SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); - sus2->setStartUpImmediately(); (void) sus2; SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); - sus3->setStartUpImmediately(); (void) sus3; new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, @@ -272,6 +270,7 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_7); SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); +// (void) sus8; sus8->setStartUpImmediately(); new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, @@ -280,12 +279,17 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_10); SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); - sus11->setStartUpImmediately(); + (void) sus11; - new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, + SusHandler* sus12 = new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, gpioIds::CS_SUS_12); - new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, +// sus12->setStartUpImmediately(); + (void) sus12; + + SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, gpioIds::CS_SUS_13); +// sus13->setStartUpImmediately(); + (void) sus13; #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); diff --git a/fsfwconfig/devices/spi.h b/fsfwconfig/devices/spi.h index 2d6a01ba..eb17786b 100644 --- a/fsfwconfig/devices/spi.h +++ b/fsfwconfig/devices/spi.h @@ -21,7 +21,7 @@ static constexpr uint32_t DEFAULT_L3G_SPEED = 3'900'000; static constexpr spi::SpiModes DEFAULT_L3G_MODE = spi::SpiModes::MODE_3; static constexpr uint32_t DEFAULT_MAX_1227_SPEED = 3'900'000; -static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_0; +static constexpr spi::SpiModes DEFAULT_MAX_1227_MODE = spi::SpiModes::MODE_3; } diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index fe2eaf65..2412921f 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -157,8 +157,8 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) // thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); // thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); - if (length != 3) { - sif::waring << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " + if (length != 3000) { + sif::warning << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " << "SUS sensors still produce correct values" << std::endl; } @@ -172,38 +172,88 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0.991, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.992, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.993, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.994, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.995, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); /* Request temperature */ - thisSequence->addSlot(objects::SUS_8, length * 0.996, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.997, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.998, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.999, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.9, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::SUS_8, 2905, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2906, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2907, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2908, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2909, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_8, 2910, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2911, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2912, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2913, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2914, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_8, 2915, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_8, 2916, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2917, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_8, 2918, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_8, 2919, DeviceHandlerIF::GET_READ); - /* Read temperature */ - thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); - - /* Request and read ADC conversions */ - thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); - -// thisSequence->addSlot(objects::SUS_11, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_11, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_11, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_11, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_11, length * 0.8, DeviceHandlerIF::GET_READ); + /* Write setup */ +// thisSequence->addSlot(objects::SUS_12, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::GET_READ); +// +// /* Request temperature */ +// thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_12, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.931, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.932, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_12, length * 0.936, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.937, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_12, length * 0.938, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_12, length * 0.939, DeviceHandlerIF::GET_READ); +// +// /* Write setup */ +// thisSequence->addSlot(objects::SUS_13, length * 0.94, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.941, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.942, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.943, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.945, DeviceHandlerIF::GET_READ); +// +// /* Request temperature */ +// thisSequence->addSlot(objects::SUS_13, length * 0.946, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.947, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.948, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.949, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::GET_READ); +// +// /* Read temperature */ +// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.951, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.952, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.953, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.954, DeviceHandlerIF::GET_READ); +// +// /* Request and read ADC conversions */ +// thisSequence->addSlot(objects::SUS_13, length * 0.955, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_13, length * 0.956, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.957, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_13, length * 0.958, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_13, length * 0.959, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; From e1e69539cacb523e76d5987f89c017956227cc0e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 10 May 2021 11:13:39 +0200 Subject: [PATCH 36/42] changed SusHandler MAX1227 to internal clock mode --- mission/devices/SusHandler.cpp | 84 ++++++------------- mission/devices/SusHandler.h | 5 +- .../devicedefinitions/RadSensorDefinitions.h | 2 +- .../devicedefinitions/SusDefinitions.h | 51 ++++++----- 4 files changed, 52 insertions(+), 90 deletions(-) diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 4f3dc834..8d80322c 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -34,18 +34,14 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; - communicationStep = CommunicationStep::REQUEST_TEMPERATURE; + communicationStep = CommunicationStep::START_CONVERSIONS; } - else if (communicationStep == CommunicationStep::REQUEST_TEMPERATURE) { - *id = SUS::REQUEST_TEMPERATURE; - communicationStep = CommunicationStep::READ_TEMPERATURE; + else if (communicationStep == CommunicationStep::START_CONVERSIONS) { + *id = SUS::START_CONVERSIONS; + communicationStep = CommunicationStep::READ_CONVERSIONS; } - else if (communicationStep == CommunicationStep::READ_TEMPERATURE) { - *id = SUS::READ_TEMPERATURE; - communicationStep = CommunicationStep::READ_CHANNELS; - } - else if (communicationStep == CommunicationStep::READ_CHANNELS) { - *id = SUS::READ_CHANNELS; + else if (communicationStep == CommunicationStep::READ_CONVERSIONS) { + *id = SUS::READ_CONVERSIONS; communicationStep = CommunicationStep::WRITE_SETUP; } return buildCommandFromCommand(*id, nullptr, 0); @@ -69,41 +65,22 @@ ReturnValue_t SusHandler::buildCommandFromCommand( */ //TODO: Protect spi bus with mutex gpioComIF->pullLow(chipSelectId); - cmdBuffer[0] = SUS::SETUP_DEFINITION; + cmdBuffer[0] = SUS::SETUP; rawPacket = cmdBuffer; rawPacketLen = 1; return RETURN_OK; } - case(SUS::READ_CHANNELS): { + case(SUS::START_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::CONVERT_DIFF_CHANNEL_0; - cmdBuffer[1] = SUS::DUMMY_BYTE; - cmdBuffer[2] = SUS::CONVERT_DIFF_CHANNEL_1; - cmdBuffer[3] = SUS::DUMMY_BYTE; - cmdBuffer[4] = SUS::CONVERT_DIFF_CHANNEL_2; - cmdBuffer[5] = SUS::DUMMY_BYTE; - cmdBuffer[6] = SUS::CONVERT_DIFF_CHANNEL_3; - cmdBuffer[7] = SUS::DUMMY_BYTE; - cmdBuffer[8] = SUS::CONVERT_DIFF_CHANNEL_4; - cmdBuffer[9] = SUS::DUMMY_BYTE; - cmdBuffer[10] = SUS::CONVERT_DIFF_CHANNEL_5; - cmdBuffer[11] = SUS::DUMMY_BYTE; - cmdBuffer[12] = SUS::DUMMY_BYTE; + cmdBuffer[0] = SUS::CONVERSION; rawPacket = cmdBuffer; - rawPacketLen = SUS::SIZE_READ_CHANNELS; + rawPacketLen = 1; return RETURN_OK; } - case(SUS::REQUEST_TEMPERATURE): { - std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); - cmdBuffer[0] = SUS::CONVERT_TEMPERATURE; - rawPacket = cmdBuffer; - rawPacketLen = 1; - return RETURN_OK; - } - case(SUS::READ_TEMPERATURE): { + case(SUS::READ_CONVERSIONS): { std::memset(cmdBuffer, 0, sizeof(cmdBuffer)); rawPacket = cmdBuffer; - rawPacketLen = 24; + rawPacketLen = SUS::SIZE_READ_CONVERSIONS; return RETURN_OK; } default: @@ -114,10 +91,8 @@ ReturnValue_t SusHandler::buildCommandFromCommand( void SusHandler::fillCommandAndReplyMap() { this->insertInCommandMap(SUS::WRITE_SETUP); - this->insertInCommandMap(SUS::REQUEST_TEMPERATURE); - this->insertInCommandAndReplyMap(SUS::READ_CHANNELS, 1, &dataset, SUS::SIZE_READ_CHANNELS); - this->insertInCommandAndReplyMap(SUS::READ_TEMPERATURE, 1, nullptr, - SUS::SIZE_READ_TEMPERATURE); + this->insertInCommandMap(SUS::START_CONVERSIONS); + this->insertInCommandAndReplyMap(SUS::READ_CONVERSIONS, 1, &dataset, SUS::SIZE_READ_CONVERSIONS); } ReturnValue_t SusHandler::scanForReply(const uint8_t *start, @@ -130,15 +105,18 @@ ReturnValue_t SusHandler::scanForReply(const uint8_t *start, ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case SUS::READ_CHANNELS: { + case SUS::READ_CONVERSIONS: { PoolReadGuard readSet(&dataset); - dataset.ain0 = (*(packet + 1) << 8 | *(packet + 2)); - dataset.ain1 = (*(packet + 3) << 8 | *(packet + 4)); - dataset.ain2 = (*(packet + 5) << 8 | *(packet + 6)); - dataset.ain3 = (*(packet + 7) << 8 | *(packet + 8)); - dataset.ain4 = (*(packet + 9) << 8 | *(packet + 10)); - dataset.ain5 = (*(packet + 11) << 8 | *(packet + 12)); + dataset.temperatureCelcius = (*(packet) << 8 | *(packet + 1)) * 0.125; + dataset.ain0 = (*(packet + 2) << 8 | *(packet + 3)); + dataset.ain1 = (*(packet + 4) << 8 | *(packet + 5)); + dataset.ain2 = (*(packet + 6) << 8 | *(packet + 7)); + dataset.ain3 = (*(packet + 8) << 8 | *(packet + 9)); + dataset.ain4 = (*(packet + 10) << 8 | *(packet + 11)); + dataset.ain5 = (*(packet + 12) << 8 | *(packet + 13)); #if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS + sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", Temperature: " + << dataset.temperatureCelcius << " °C" << std::endl; sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN0: " << std::dec << dataset.ain0 << std::endl; sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN1: " @@ -152,22 +130,10 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", AIN5: " << std::dec << dataset.ain5 << std::endl; #endif - /** - * Reading the channel conversion results is the last communication step in one SUS - * sequence. SPI bus can now be released again. - */ + /** SUS can now be shutdown and thus the SPI bus released again */ gpioComIF->pullHigh(chipSelectId); break; } - case SUS::READ_TEMPERATURE: { - PoolReadGuard readSet(&dataset); - dataset.temperatureCelcius = (*(packet + 22) << 8 | *(packet + 23)) * 0.125; -#if OBSW_VERBOSE_LEVEL >= 1 && DEBUG_SUS - sif::info << "SUS object id 0x" << std::hex << this->getObjectId() << ", temperature: " - << dataset.temperatureCelcius << " °C" << std::endl; -#endif - break; - } default: { sif::debug << "SusHandler::interpretDeviceReply: Unknown reply id" << std::endl; return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY; diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 5ef7ec32..14685dd9 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -42,9 +42,8 @@ private: enum class CommunicationStep { WRITE_SETUP, - REQUEST_TEMPERATURE, - READ_TEMPERATURE, - READ_CHANNELS + START_CONVERSIONS, + READ_CONVERSIONS }; LinuxLibgpioIF* gpioComIF = nullptr; diff --git a/mission/devices/devicedefinitions/RadSensorDefinitions.h b/mission/devices/devicedefinitions/RadSensorDefinitions.h index db105495..7d434d04 100644 --- a/mission/devices/devicedefinitions/RadSensorDefinitions.h +++ b/mission/devices/devicedefinitions/RadSensorDefinitions.h @@ -18,7 +18,7 @@ namespace RAD_SENSOR { * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, no data follows the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b01, external reference single ended + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, MAX1227 uses internal oscillator for timing * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register * diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index fc46f75f..6cc8aa65 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -11,55 +11,52 @@ namespace SUS { static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending - /** - * This command initiates the ADC conversion for all channels including the internal - * temperature sensor. - */ static const DeviceCommandId_t WRITE_SETUP = 0x1; - static const DeviceCommandId_t READ_CHANNELS = 0x2; - static const DeviceCommandId_t READ_TEMPERATURE = 0x3; - static const DeviceCommandId_t REQUEST_TEMPERATURE = 0x4; + /** + * This command initiates the ADC conversion for all channels including the internal + * temperature sensor. + */ + static const DeviceCommandId_t START_CONVERSIONS = 0x2; + /** + * This command reads the internal fifo which holds the temperature and the channel + * conversions. + */ + static const DeviceCommandId_t READ_CONVERSIONS = 0x3; /** * @brief This is the configuration byte which will be written to the setup register after * power on. * * @note Bit1 (DIFFSEL1) - Bit0 (DIFFSEL0): 0b00, No byte is following the setup byte - * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, internal reference, no wake-up delay - * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b11, MAX1227 clocked through SPI SCLK - * Bit7 - Bit6: 0b01, tells MAX1227 that this is the setup register + * Bit3 (REFSEL1) - Bit2 (REFSEL0): 0b10, Internal reference, no wake-up delay + * Bit5 (CLKSEL1) - Bit4 (CLKSEL0): 0b10, Internally clocked + * Bit7 - Bit6: 0b01, Tells MAX1227 that this byte should be + * written to the setup register * */ - static const uint8_t SETUP_DEFINITION = 0b01111000; + static const uint8_t SETUP = 0b01101000; /** - * @brief This value will always be written to the ADC conversion register to specify the + * @brief This values will always be written to the ADC conversion register to specify the * conversions to perform. * @details Bit0: 1 - Enables temperature conversion - * Bit2 (SCAN1) and Bit1 (SCAN0): 0b11, No scan, converts channel N once only. - * Scanning is not supported in spi clock mode. - * Bit6 - Bit3 defines N: 0b0001 (N = 4) + * Bit2 (SCAN1) and Bit1 (SCAN0): 0b00, Scans channels 0 through N + * Bit6 - Bit3 defines N: 0b0101 (N = 5) * Bit7: Always 1. Tells the ADC that this is the conversion register. */ - static const uint8_t CONVERT_TEMPERATURE = 0b10000001; - static const uint8_t CONVERT_DIFF_CHANNEL_0 = 0b10000110; - static const uint8_t CONVERT_DIFF_CHANNEL_1 = 0b10001110; - static const uint8_t CONVERT_DIFF_CHANNEL_2 = 0b10010110; - static const uint8_t CONVERT_DIFF_CHANNEL_3 = 0b10011110; - static const uint8_t CONVERT_DIFF_CHANNEL_4 = 0b10100110; - static const uint8_t CONVERT_DIFF_CHANNEL_5 = 0b10101110; + static const uint8_t CONVERSION = 0b10101001; + /** Writing this value resets the fifo */ static const uint8_t RESET_FIFO = 0b00011000; static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CHANNELS; + static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; - /** Size of data replies */ - static const uint8_t SIZE_READ_CHANNELS = 13; - static const uint8_t SIZE_READ_TEMPERATURE = 25; + /** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */ + static const uint8_t SIZE_READ_CONVERSIONS = 14; - static const uint8_t MAX_CMD_SIZE = SIZE_READ_TEMPERATURE; + static const uint8_t MAX_CMD_SIZE = SIZE_READ_CONVERSIONS; static const uint8_t POOL_ENTRIES = 7; From 2d170a1f6199620c19ef73e310dadbd5165501eb Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 12 May 2021 13:06:56 +0200 Subject: [PATCH 37/42] sus delay implementation --- bsp_q7s/InitMission.cpp | 8 +- bsp_q7s/ObjectFactory.cpp | 59 ++-- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 4 +- .../pollingSequenceFactory.cpp | 334 +++++++++--------- fsfwconfig/returnvalues/classIds.h | 3 +- mission/devices/RadiationSensorHandler.cpp | 2 +- mission/devices/SusHandler.cpp | 39 +- mission/devices/SusHandler.h | 13 + .../devicedefinitions/SusDefinitions.h | 12 +- 10 files changed, 269 insertions(+), 207 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index a8ba7d1d..534cb2ee 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -158,10 +158,10 @@ void initmission::initTasks() { } #else - FixedTimeslotTaskIF * pollingSequenceTableTE0720 = factory->createFixedTimeslotTask( - "PST_TASK_TE0720", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, + FixedTimeslotTaskIF * pollingSequenceTaskTE0720 = factory->createFixedTimeslotTask( + "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 5.0, missedDeadlineFunc); - result = pst::pollingSequenceTE0720(pollingSequenceTableTE0720); + result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating TE0720 PST failed!" << std::endl; } @@ -198,7 +198,7 @@ void initmission::initTasks() { gomSpacePstTask->startTask(); pollingSequenceTableTaskDefault->startTask(); #elif TE0720 == 1 && Q7S_ADD_SPI_TEST == 0 - pollingSequenceTableTE0720->startTask(); + pollingSequenceTaskTE0720->startTask(); #endif pusVerification->startTask(); diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index 6524c64b..62cf46d2 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -105,14 +105,12 @@ void ObjectFactory::produce(){ new UartComIF(objects::UART_COM_IF); #if Q7S_ADD_SPI_TEST == 0 new SpiComIF(objects::SPI_COM_IF, gpioComIF); -#endif +#endif /* Q7S_ADD_SPI_TEST == 0 */ /* Temperature sensors */ new Tmp1075Handler(objects::TMP1075_HANDLER_1, objects::I2C_COM_IF, i2cCookieTmp1075tcs1); new Tmp1075Handler(objects::TMP1075_HANDLER_2, objects::I2C_COM_IF, i2cCookieTmp1075tcs2); - GpioCookie* heaterGpiosCookie = new GpioCookie; - #if TE0720 == 0 CspCookie* p60DockCspCookie = new CspCookie(P60Dock::MAX_REPLY_LENGTH, addresses::P60DOCK); @@ -161,8 +159,7 @@ void ObjectFactory::produce(){ spi::DEFAULT_MAX_1227_SPEED); RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); -// (void) radSensor; - radSensor->setStartUpImmediately(); + (void) radSensor; GpioCookie* gpioCookieSus = new GpioCookie(); @@ -210,43 +207,43 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieSus1 = new SpiCookie(addresses::SUS_1, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus2 = new SpiCookie(addresses::SUS_2, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus3 = new SpiCookie(addresses::SUS_3, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus4 = new SpiCookie(addresses::SUS_4, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus5 = new SpiCookie(addresses::SUS_5, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus6 = new SpiCookie(addresses::SUS_6, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus7 = new SpiCookie(addresses::SUS_7, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus8 = new SpiCookie(addresses::SUS_8, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus9 = new SpiCookie(addresses::SUS_9, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus10 = new SpiCookie(addresses::SUS_10, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus11 = new SpiCookie(addresses::SUS_11, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus12 = new SpiCookie(addresses::SUS_12, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SpiCookie* spiCookieSus13 = new SpiCookie(addresses::SUS_13, gpio::NO_GPIO, std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - SUS::SUS_MAX_1227_SPEED); + SUS::MAX1227_SPI_FREQ); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); @@ -254,7 +251,7 @@ void ObjectFactory::produce(){ SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); - (void) sus2; + sus2->setStartUpImmediately(); SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); @@ -270,25 +267,26 @@ void ObjectFactory::produce(){ gpioIds::CS_SUS_7); SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); -// (void) sus8; - sus8->setStartUpImmediately(); + (void) sus8; - new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, + SusHandler* sus9 = new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, gpioIds::CS_SUS_9); - new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, + (void) sus9; + + SusHandler* sus10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, gpioIds::CS_SUS_10); + (void) sus10; + SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); (void) sus11; SusHandler* sus12 = new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, gpioIds::CS_SUS_12); -// sus12->setStartUpImmediately(); (void) sus12; SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, gpioIds::CS_SUS_13); -// sus13->setStartUpImmediately(); (void) sus13; #if OBSW_ADD_ACS_BOARD == 1 @@ -364,6 +362,8 @@ void ObjectFactory::produce(){ gyroL3gHandler->setStartUpImmediately(); #endif + GpioCookie* heaterGpiosCookie = new GpioCookie; + /* Pin H2-11 on stack connector */ GpiodRegular* gpioConfigHeater0 = new GpiodRegular(std::string("gpiochip7"), 6, std::string("Heater0"), gpio::OUT, 0); @@ -595,14 +595,13 @@ void ObjectFactory::produce(){ #if TE0720 == 1 && TEST_SUS_HANDLER == 1 GpioCookie* gpioCookieSus = new GpioCookie; - GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip0"), 9, + GpiodRegular* chipSelectSus = new GpiodRegular(std::string("gpiochip1"), 9, std::string("Chip Select Sus Sensor"), gpio::OUT, 1); gpioCookieSus->addGpio(gpioIds::CS_SUS_1, chipSelectSus); gpioComIF->addGpios(gpioCookieSus); - SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, gpioIds::CS_SUS_1, - std::string("/dev/spidev1.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, - spi::DEFAULT_MAX_1227_SPEED); + SpiCookie* spiCookieSus = new SpiCookie(addresses::SUS_1, std::string("/dev/spidev1.0"), + SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus, gpioComIF, gpioIds::CS_SUS_1); @@ -611,7 +610,7 @@ void ObjectFactory::produce(){ #if TE0720 == 1 && TEST_RADIATION_SENSOR_HANDLER == 1 GpioCookie* gpioCookieRadSensor = new GpioCookie; - GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip0"), 9, + GpiodRegular* chipSelectRadSensor = new GpiodRegular(std::string("gpiochip1"), 0, std::string("Chip select radiation sensor"), gpio::OUT, 1); gpioCookieRadSensor->addGpio(gpioIds::CS_RAD_SENSOR, chipSelectRadSensor); gpioComIF->addGpios(gpioCookieRadSensor); diff --git a/fsfw_hal b/fsfw_hal index a85c0146..425cfd2a 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit a85c01465bc8687773676f05c5e7eb8af54b25ff +Subproject commit 425cfd2ababe3639355c6681ce3f9b606b893430 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index 5db2e7d0..bfe528c6 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -20,11 +20,11 @@ debugging. */ #define OBSW_PRINT_MISSED_DEADLINES 1 #define OBSW_ADD_TEST_CODE 1 #define TEST_LIBGPIOD 0 -#define TEST_RADIATION_SENSOR_HANDLER 0 +#define TEST_RADIATION_SENSOR_HANDLER 1 #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 0 +#define TE0720 1 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 2412921f..ffa22fdc 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -144,18 +144,11 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /* Radiation sensor */ -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); - - /* Sun sensor 1 */ -// thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); if (length != 3000) { sif::warning << "pollingSequenceInitDefault: Frequency changed. Make sure timing critical " @@ -165,95 +158,74 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) /** * The sun sensor will be shutdown as soon as the chip select is pulled high. Thus all * requests to a sun sensor must be performed consecutively. Another reason for calling multiple - * device handler cycles is that some ADC conversions need a small delay before the results can - * be read. + * device handler cycles is that the ADC conversions take some time. Thus first the ADC + * conversions are initiated and in a next step the results can be read from the internal FIFO. * One sun sensor communication sequence also blocks the SPI bus. So other devices can not be * inserted between the device handler cycles of one SUS. */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.8, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.902, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); - /* Request temperature */ -// thisSequence->addSlot(objects::SUS_8, 2905, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2906, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2907, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2908, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2909, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_8, 2910, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2911, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2912, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2913, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2914, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_8, 2915, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_8, 2916, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2917, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_8, 2918, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_8, 2919, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_8, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.912, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.915, DeviceHandlerIF::GET_READ); /* Write setup */ -// thisSequence->addSlot(objects::SUS_12, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::GET_READ); -// -// /* Request temperature */ -// thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_12, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.931, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.932, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_12, length * 0.936, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.937, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_12, length * 0.938, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_12, length * 0.939, DeviceHandlerIF::GET_READ); -// -// /* Write setup */ -// thisSequence->addSlot(objects::SUS_13, length * 0.94, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.941, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.942, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.943, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.945, DeviceHandlerIF::GET_READ); -// -// /* Request temperature */ -// thisSequence->addSlot(objects::SUS_13, length * 0.946, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.947, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.948, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.949, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::GET_READ); -// -// /* Read temperature */ -// thisSequence->addSlot(objects::SUS_13, length * 0.95, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.951, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.952, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.953, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.954, DeviceHandlerIF::GET_READ); -// -// /* Request and read ADC conversions */ -// thisSequence->addSlot(objects::SUS_13, length * 0.955, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_13, length * 0.956, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.957, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_13, length * 0.958, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_13, length * 0.959, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.917, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.918, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.919, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.920, DeviceHandlerIF::GET_READ); + + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.930, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.931, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.932, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.933, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.934, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.935, DeviceHandlerIF::GET_READ); + + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_2, length * 0.936, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.937, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.938, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.939, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.94, DeviceHandlerIF::GET_READ); + + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_2, length * 0.941, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.942, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.943, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.944, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.945, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; @@ -315,62 +287,62 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ length * 0.8, DeviceHandlerIF::GET_READ); #if OBSW_ADD_ACS_BOARD == 1 -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); -// -// -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::MGM_2_LIS3_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); + + + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0, + DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.2, + DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.4, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.6, + DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::GYRO_2_L3G_HANDLER, length * 0.8, + DeviceHandlerIF::GET_READ); thisSequence->addSlot(objects::MGM_3_RM3100_HANDLER, length * 0, @@ -446,22 +418,68 @@ ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { thisSequence->addSlot(objects::PLOC_HANDLER, length * 0.8, DeviceHandlerIF::GET_READ); #endif -#if TEST_SUS_HANDLER == 1 - thisSequence->addSlot(objects::SUS_1, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.8, DeviceHandlerIF::GET_READ); -#endif - #if TEST_RADIATION_SENSOR_HANDLER == 1 - thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_READ); #endif +#if TEST_SUS_HANDLER == 1 + /* Write setup */ +// thisSequence->addSlot(objects::SUS_1, 1000, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 1010, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1020, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1030, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 1040, DeviceHandlerIF::GET_READ); +// +// /* Start ADC conversions */ +// thisSequence->addSlot(objects::SUS_1, 1050, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 1060, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1070, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 1080, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 1090, DeviceHandlerIF::GET_READ); +// +// /* Read ADC conversions from inernal FIFO */ +// thisSequence->addSlot(objects::SUS_1, 2000, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, 2010, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, 2020, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, 2030, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, 2040, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_READ); + + /* Cycle 1 */ + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_READ); + + /* Cycl2 */ + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_READ); + + /* Cycle 3 */ + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_READ); + +// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); +// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_WRITE); +// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_READ); +// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_READ); +#endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { sif::error << "Initialization of TE0720 PST failed" << std::endl; diff --git a/fsfwconfig/returnvalues/classIds.h b/fsfwconfig/returnvalues/classIds.h index 22bb0457..50bb3cea 100644 --- a/fsfwconfig/returnvalues/classIds.h +++ b/fsfwconfig/returnvalues/classIds.h @@ -20,7 +20,8 @@ enum { SA_DEPL_HANDLER, SYRLINKS_HANDLER, IMTQ_HANDLER, - PLOC_HANDLER + PLOC_HANDLER, + SUS_HANDLER }; } diff --git a/mission/devices/RadiationSensorHandler.cpp b/mission/devices/RadiationSensorHandler.cpp index bd16ddaf..c8e7b6b4 100644 --- a/mission/devices/RadiationSensorHandler.cpp +++ b/mission/devices/RadiationSensorHandler.cpp @@ -145,7 +145,7 @@ void RadiationSensorHandler::setNormalDatapoolEntriesInvalid(){ } uint32_t RadiationSensorHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){ - return 5000; + return 500; } ReturnValue_t RadiationSensorHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index 8d80322c..f8886d8f 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId) : @@ -17,6 +18,24 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo SusHandler::~SusHandler() { } +ReturnValue_t SusHandler::initialize() { + ReturnValue_t result = RETURN_OK; + result = DeviceHandlerBase::initialize(); + if (result != RETURN_OK) { + return result; + } + auto spiComIF = dynamic_cast(communicationInterface); + if (spiComIF == nullptr) { + sif::debug << "SusHandler::initialize: Invalid communication interface" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } + spiMutex = spiComIF->getMutex(); + if (spiMutex == nullptr) { + sif::debug << "SusHandler::initialize: Failed to get spi mutex" << std::endl; + return ObjectManagerIF::CHILD_INIT_FAILED; + } + return RETURN_OK; +} void SusHandler::doStartUp(){ #if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1 @@ -62,8 +81,20 @@ ReturnValue_t SusHandler::buildCommandFromCommand( * measurement the setup has to be rewritten. There must also be a little delay between * the transmission of the setup byte and the first conversion. Thus the conversion * will be performed in an extra step. + * Because the chip select is driven manually by the SusHandler the SPI bus must be + * protected with a mutex here. */ - //TODO: Protect spi bus with mutex + ReturnValue_t result = spiMutex->lockMutex(timeoutType, timeoutMs); + if(result == MutexIF::MUTEX_TIMEOUT) { + sif::error << "SusHandler::buildCommandFromCommand: Mutex timeout" << std::endl; + return ERROR_LOCK_MUTEX; + } + else if(result != HasReturnvaluesIF::RETURN_OK) { + sif::error << "SusHandler::buildCommandFromCommand: Failed to lock spi mutex" + << std::endl; + return ERROR_LOCK_MUTEX; + } + gpioComIF->pullLow(chipSelectId); cmdBuffer[0] = SUS::SETUP; rawPacket = cmdBuffer; @@ -132,6 +163,12 @@ ReturnValue_t SusHandler::interpretDeviceReply(DeviceCommandId_t id, #endif /** SUS can now be shutdown and thus the SPI bus released again */ gpioComIF->pullHigh(chipSelectId); + ReturnValue_t result = spiMutex->unlockMutex(); + if (result != RETURN_OK) { + sif::error << "SusHandler::interpretDeviceReply: Failed to unlock spi mutex" + << std::endl; + return ERROR_UNLOCK_MUTEX; + } break; } default: { diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 14685dd9..4adb15fa 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -4,6 +4,7 @@ #include #include #include +#include /** * @brief This is the device handler class for the SUS sensor. The sensor is @@ -21,6 +22,8 @@ public: CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); + virtual ReturnValue_t initialize(); + protected: void doStartUp() override; void doShutDown() override; @@ -40,6 +43,11 @@ protected: private: + static const uint8_t INTERFACE_ID = CLASS_ID::SUS_HANDLER; + + static const ReturnValue_t ERROR_UNLOCK_MUTEX = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1); + enum class CommunicationStep { WRITE_SETUP, START_CONVERSIONS, @@ -54,6 +62,11 @@ private: uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; + + MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; + uint32_t timeoutMs = 20; + + MutexIF* spiMutex = nullptr; }; #endif /* MISSION_DEVICES_SUSHANDLER_H_ */ diff --git a/mission/devices/devicedefinitions/SusDefinitions.h b/mission/devices/devicedefinitions/SusDefinitions.h index 6cc8aa65..18f33e0d 100644 --- a/mission/devices/devicedefinitions/SusDefinitions.h +++ b/mission/devices/devicedefinitions/SusDefinitions.h @@ -4,10 +4,10 @@ namespace SUS { /** - * The MAX1227 in externally clocked mode did not properly work with frequencies higher than - * 1 MHz. + * Some MAX1227 could not be reached with frequencies around 4 MHz. Maybe this is caused by + * the decoder and buffer circuits. Thus frequency is here defined to 1 MHz. */ - static const uint32_t SUS_MAX_1227_SPEED = 1000000; + static const uint32_t MAX1227_SPI_FREQ = 1000000; static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending @@ -46,11 +46,6 @@ namespace SUS { */ static const uint8_t CONVERSION = 0b10101001; - /** Writing this value resets the fifo */ - static const uint8_t RESET_FIFO = 0b00011000; - - static const uint8_t DUMMY_BYTE = 0x0; - static const uint8_t SUS_DATA_SET_ID = READ_CONVERSIONS; /** Size of data replies. Temperature and 6 channel convesions (AIN0 - AIN5) */ @@ -60,7 +55,6 @@ namespace SUS { static const uint8_t POOL_ENTRIES = 7; - enum Max1227PoolIds: lp_id_t { TEMPERATURE_C, AIN0, From 65d0c1fabf2e58a4600e8e691722a3720c50c873 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Wed, 12 May 2021 16:38:20 +0200 Subject: [PATCH 38/42] Sus handler complete --- bsp_q7s/InitMission.cpp | 2 +- .../pollingSequenceFactory.cpp | 77 ++++++------------- mission/devices/SusHandler.cpp | 29 ++++++- mission/devices/SusHandler.h | 13 +++- 4 files changed, 63 insertions(+), 58 deletions(-) diff --git a/bsp_q7s/InitMission.cpp b/bsp_q7s/InitMission.cpp index 534cb2ee..797c5e71 100644 --- a/bsp_q7s/InitMission.cpp +++ b/bsp_q7s/InitMission.cpp @@ -159,7 +159,7 @@ void initmission::initTasks() { #else FixedTimeslotTaskIF * pollingSequenceTaskTE0720 = factory->createFixedTimeslotTask( - "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 5.0, + "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 3.0, missedDeadlineFunc); result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index ffa22fdc..957f22a4 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -6,6 +6,7 @@ #include #include #include +#include ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) @@ -419,66 +420,34 @@ ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { #endif #if TEST_RADIATION_SENSOR_HANDLER == 1 -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::RAD_SENSOR, 800, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.2, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.4, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.6, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::RAD_SENSOR, length * 0.8, DeviceHandlerIF::GET_READ); #endif #if TEST_SUS_HANDLER == 1 /* Write setup */ -// thisSequence->addSlot(objects::SUS_1, 1000, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 1010, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1020, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1030, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 1040, DeviceHandlerIF::GET_READ); -// -// /* Start ADC conversions */ -// thisSequence->addSlot(objects::SUS_1, 1050, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 1060, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1070, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 1080, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 1090, DeviceHandlerIF::GET_READ); -// -// /* Read ADC conversions from inernal FIFO */ -// thisSequence->addSlot(objects::SUS_1, 2000, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, 2010, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, 2020, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, 2030, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, 2040, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::RAD_SENSOR, length * 0.1, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.902, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.905, DeviceHandlerIF::GET_READ); - /* Cycle 1 */ - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.2, DeviceHandlerIF::GET_READ); + /* Start conversion*/ + thisSequence->addSlot(objects::SUS_1, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.907, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.91, DeviceHandlerIF::GET_READ); - /* Cycl2 */ - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.3, DeviceHandlerIF::GET_READ); - - /* Cycle 3 */ - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_1, length * 0.4, DeviceHandlerIF::GET_READ); - -// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_READ); + /* Read conversions */ + thisSequence->addSlot(objects::SUS_1, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.912, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.915, DeviceHandlerIF::GET_READ); #endif if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { diff --git a/mission/devices/SusHandler.cpp b/mission/devices/SusHandler.cpp index f8886d8f..662323cf 100644 --- a/mission/devices/SusHandler.cpp +++ b/mission/devices/SusHandler.cpp @@ -18,6 +18,28 @@ SusHandler::SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCo SusHandler::~SusHandler() { } +ReturnValue_t SusHandler::performOperation(uint8_t counter) { + + if (counter != FIRST_WRITE) { + DeviceHandlerBase::performOperation(counter); + return RETURN_OK; + } + + if (mode != MODE_NORMAL) { + DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE); + return RETURN_OK; + } + + /* If device is in normale mode the communication sequence is initiated here */ + if (communicationStep == CommunicationStep::IDLE) { + communicationStep = CommunicationStep::WRITE_SETUP; + } + + DeviceHandlerBase::performOperation(DeviceHandlerIF::SEND_WRITE); + + return RETURN_OK; +} + ReturnValue_t SusHandler::initialize() { ReturnValue_t result = RETURN_OK; result = DeviceHandlerBase::initialize(); @@ -51,6 +73,11 @@ void SusHandler::doShutDown(){ ReturnValue_t SusHandler::buildNormalDeviceCommand( DeviceCommandId_t * id) { + + if (communicationStep == CommunicationStep::IDLE) { + return NOTHING_TO_SEND; + } + if (communicationStep == CommunicationStep::WRITE_SETUP) { *id = SUS::WRITE_SETUP; communicationStep = CommunicationStep::START_CONVERSIONS; @@ -61,7 +88,7 @@ ReturnValue_t SusHandler::buildNormalDeviceCommand( } else if (communicationStep == CommunicationStep::READ_CONVERSIONS) { *id = SUS::READ_CONVERSIONS; - communicationStep = CommunicationStep::WRITE_SETUP; + communicationStep = CommunicationStep::IDLE; } return buildCommandFromCommand(*id, nullptr, 0); } diff --git a/mission/devices/SusHandler.h b/mission/devices/SusHandler.h index 4adb15fa..c73cee97 100644 --- a/mission/devices/SusHandler.h +++ b/mission/devices/SusHandler.h @@ -13,16 +13,24 @@ * * @details Datasheet of MAX1227: https://datasheets.maximintegrated.com/en/ds/MAX1227-MAX1231.pdf * + * @note When adding a SusHandler to the polling sequence table make sure to add a slot with + * the executionStep FIRST_WRITE. Otherwise the communication sequence will never be + * started. + * * @author J. Meier */ class SusHandler: public DeviceHandlerBase { public: + static const uint8_t FIRST_WRITE = 7; + SusHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t chipSelectId); virtual ~SusHandler(); - virtual ReturnValue_t initialize(); + virtual ReturnValue_t performOperation(uint8_t counter) override; + + virtual ReturnValue_t initialize() override; protected: void doStartUp() override; @@ -49,6 +57,7 @@ private: static const ReturnValue_t ERROR_LOCK_MUTEX = MAKE_RETURN_CODE(0xA1); enum class CommunicationStep { + IDLE, WRITE_SETUP, START_CONVERSIONS, READ_CONVERSIONS @@ -61,7 +70,7 @@ private: SUS::SusDataset dataset; uint8_t cmdBuffer[SUS::MAX_CMD_SIZE]; - CommunicationStep communicationStep = CommunicationStep::WRITE_SETUP; + CommunicationStep communicationStep = CommunicationStep::IDLE; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; uint32_t timeoutMs = 20; From 33c229d08a11e3e985d4b921a51ff0e6a32893d1 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 13 May 2021 13:17:12 +0200 Subject: [PATCH 39/42] all sus initialized --- bsp_q7s/ObjectFactory.cpp | 61 +--- fsfw_hal | 2 +- fsfwconfig/OBSWConfig.h | 2 +- .../pollingSequenceFactory.cpp | 316 +++++++++++++----- 4 files changed, 256 insertions(+), 125 deletions(-) diff --git a/bsp_q7s/ObjectFactory.cpp b/bsp_q7s/ObjectFactory.cpp index c34f847a..4d1a413e 100644 --- a/bsp_q7s/ObjectFactory.cpp +++ b/bsp_q7s/ObjectFactory.cpp @@ -163,10 +163,7 @@ void ObjectFactory::produce(){ SpiCookie* spiCookieRadSensor = new SpiCookie(addresses::RAD_SENSOR, gpioIds::CS_RAD_SENSOR, std::string("/dev/spidev2.0"), RAD_SENSOR::READ_SIZE, spi::DEFAULT_MAX_1227_MODE, spi::DEFAULT_MAX_1227_SPEED); - RadiationSensorHandler* radSensor = new RadiationSensorHandler(objects::RAD_SENSOR, - objects::SPI_COM_IF, spiCookieRadSensor); - (void) radSensor; - + new RadiationSensorHandler(objects::RAD_SENSOR, objects::SPI_COM_IF, spiCookieRadSensor); GpioCookie* gpioCookieSus = new GpioCookie(); GpioCallback* susgpio = new GpioCallback(std::string("Chip select SUS 1"), gpio::OUT, 1, @@ -251,49 +248,19 @@ void ObjectFactory::produce(){ std::string("/dev/spidev2.0"), SUS::MAX_CMD_SIZE, spi::DEFAULT_MAX_1227_MODE, SUS::MAX1227_SPI_FREQ); - SusHandler* sus1 = new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, - gpioIds::CS_SUS_1); - (void) sus1; - - SusHandler* sus2 = new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, - gpioIds::CS_SUS_2); - sus2->setStartUpImmediately(); - - SusHandler* sus3 = new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, - gpioIds::CS_SUS_3); - (void) sus3; - - new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, - gpioIds::CS_SUS_4); - new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5, gpioComIF, - gpioIds::CS_SUS_5); - new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6, gpioComIF, - gpioIds::CS_SUS_6); - new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7, gpioComIF, - gpioIds::CS_SUS_7); - SusHandler* sus8 = new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, - gpioIds::CS_SUS_8); - (void) sus8; - - SusHandler* sus9 = new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, - gpioIds::CS_SUS_9); - (void) sus9; - - SusHandler* sus10 = new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, - gpioIds::CS_SUS_10); - (void) sus10; - - SusHandler* sus11 = new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, - gpioComIF, gpioIds::CS_SUS_11); - (void) sus11; - - SusHandler* sus12 = new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, - gpioIds::CS_SUS_12); - (void) sus12; - - SusHandler* sus13 = new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, - gpioIds::CS_SUS_13); - (void) sus13; + new SusHandler(objects::SUS_1, objects::SPI_COM_IF, spiCookieSus1, gpioComIF, gpioIds::CS_SUS_1); + new SusHandler(objects::SUS_2, objects::SPI_COM_IF, spiCookieSus2, gpioComIF, gpioIds::CS_SUS_2); + new SusHandler(objects::SUS_3, objects::SPI_COM_IF, spiCookieSus3, gpioComIF, gpioIds::CS_SUS_3); + new SusHandler(objects::SUS_4, objects::SPI_COM_IF, spiCookieSus4, gpioComIF, gpioIds::CS_SUS_4); + new SusHandler(objects::SUS_5, objects::SPI_COM_IF, spiCookieSus5, gpioComIF, gpioIds::CS_SUS_5); + new SusHandler(objects::SUS_6, objects::SPI_COM_IF, spiCookieSus6, gpioComIF, gpioIds::CS_SUS_6); + new SusHandler(objects::SUS_7, objects::SPI_COM_IF, spiCookieSus7, gpioComIF, gpioIds::CS_SUS_7); + new SusHandler(objects::SUS_8, objects::SPI_COM_IF, spiCookieSus8, gpioComIF, gpioIds::CS_SUS_8); + new SusHandler(objects::SUS_9, objects::SPI_COM_IF, spiCookieSus9, gpioComIF, gpioIds::CS_SUS_9); + new SusHandler(objects::SUS_10, objects::SPI_COM_IF, spiCookieSus10, gpioComIF, gpioIds::CS_SUS_10); + new SusHandler(objects::SUS_11, objects::SPI_COM_IF, spiCookieSus11, gpioComIF, gpioIds::CS_SUS_11); + new SusHandler(objects::SUS_12, objects::SPI_COM_IF, spiCookieSus12, gpioComIF, gpioIds::CS_SUS_12); + new SusHandler(objects::SUS_13, objects::SPI_COM_IF, spiCookieSus13, gpioComIF, gpioIds::CS_SUS_13); #if OBSW_ADD_ACS_BOARD == 1 GpioCookie* gpioCookieAcsBoard = new GpioCookie(); diff --git a/fsfw_hal b/fsfw_hal index 425cfd2a..e5da8b19 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 425cfd2ababe3639355c6681ce3f9b606b893430 +Subproject commit e5da8b194d61aed01fee7b8d6f6b7fe8b01dc547 diff --git a/fsfwconfig/OBSWConfig.h b/fsfwconfig/OBSWConfig.h index bfe528c6..9426d01b 100644 --- a/fsfwconfig/OBSWConfig.h +++ b/fsfwconfig/OBSWConfig.h @@ -24,7 +24,7 @@ debugging. */ #define TEST_SUS_HANDLER 1 #define TEST_PLOC_HANDLER 0 -#define TE0720 1 +#define TE0720 0 #define TE0720_HEATER_TEST 0 #define P60DOCK_DEBUG 0 diff --git a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp index 77c5e8ff..1199ae2c 100644 --- a/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp +++ b/fsfwconfig/pollingsequence/pollingSequenceFactory.cpp @@ -166,45 +166,251 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence) */ /* Write setup */ - thisSequence->addSlot(objects::SUS_8, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.902, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.903, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.904, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.905, DeviceHandlerIF::GET_READ); - - /* Start ADC conversions */ - thisSequence->addSlot(objects::SUS_8, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.907, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.908, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.909, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.91, DeviceHandlerIF::GET_READ); - - /* Read ADC conversions from inernal FIFO */ - thisSequence->addSlot(objects::SUS_8, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_8, length * 0.912, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.913, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_8, length * 0.914, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_8, length * 0.915, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.9, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.9, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.901, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.901, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_1, length * 0.902, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_1, length * 0.902, DeviceHandlerIF::GET_READ); /* Write setup */ - thisSequence->addSlot(objects::SUS_12, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_12, length * 0.917, SusHandler::FIRST_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.918, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.919, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_12, length * 0.920, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.903, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.903, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.904, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.904, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_2, length * 0.905, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_2, length * 0.905, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.906, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.906, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.907, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.907, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_3, length * 0.908, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_3, length * 0.908, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.909, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.909, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.91, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.91, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_4, length * 0.911, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_4, length * 0.911, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.912, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.912, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.913, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.913, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_5, length * 0.914, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_5, length * 0.914, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.915, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.915, DeviceHandlerIF::GET_READ); /* Start ADC conversions */ - thisSequence->addSlot(objects::SUS_12, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_12, length * 0.922, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.923, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.924, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_12, length * 0.925, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.916, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_6, length * 0.917, DeviceHandlerIF::GET_READ); - thisSequence->addSlot(objects::SUS_12, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::SUS_12, length * 0.927, DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.928, DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::SUS_12, length * 0.929, DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::SUS_12, length * 0.93, DeviceHandlerIF::GET_READ); + /* Write setup */ + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.918, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.918, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.919, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_7, length * 0.92, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.921, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.921, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.922, DeviceHandlerIF::GET_READ); + /* Read ADC conversions from inernal FIFO */ + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_8, length * 0.923, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.924, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.924, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.925, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_9, length * 0.926, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.927, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.927, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.928, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_10, length * 0.929, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.93, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.93, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.931, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_11, length * 0.932, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.933, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.933, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.934, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_12, length * 0.935, DeviceHandlerIF::GET_READ); + + /* Write setup */ + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.936, SusHandler::FIRST_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.936, DeviceHandlerIF::GET_READ); + /* Start ADC conversions */ + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.937, DeviceHandlerIF::GET_READ); + /* Read ADC conversions */ + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::SUS_13, length * 0.938, DeviceHandlerIF::GET_READ); if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_OK; @@ -344,48 +550,6 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){ return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t pst::pollingSequenceAcsTest(FixedTimeslotTaskIF *thisSequence) { - uint32_t length = thisSequence->getPeriodMs(); - - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::MGM_0_LIS3_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); - -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0, -// DeviceHandlerIF::PERFORM_OPERATION); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.2, -// DeviceHandlerIF::SEND_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.4, -// DeviceHandlerIF::GET_WRITE); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.6, -// DeviceHandlerIF::SEND_READ); -// thisSequence->addSlot(objects::MGM_1_RM3100_HANDLER, length * 0.8, -// DeviceHandlerIF::GET_READ); - - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0, - DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.2, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.4, - DeviceHandlerIF::GET_WRITE); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.6, - DeviceHandlerIF::SEND_READ); - thisSequence->addSlot(objects::GYRO_1_L3G_HANDLER, length * 0.8, - DeviceHandlerIF::GET_READ); - if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) { - sif::error << "Initialization of ACS Board PST failed" << std::endl; - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; -} - ReturnValue_t pst::pollingSequenceTE0720(FixedTimeslotTaskIF *thisSequence) { uint32_t length = thisSequence->getPeriodMs(); From 5b2e226bdcd3533ab8f5fc3c2cf3e2b9639f2bdb Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 13 May 2021 13:35:24 +0200 Subject: [PATCH 40/42] updated submodules --- fsfw | 2 +- fsfw_hal | 2 +- thirdparty/etl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fsfw b/fsfw index 5273ffa7..e7d24563 160000 --- a/fsfw +++ b/fsfw @@ -1 +1 @@ -Subproject commit 5273ffa721dd83634ebbcc37c4646752f0bea20f +Subproject commit e7d245635047439ca4b5a46d05bf58437a5aa33a diff --git a/fsfw_hal b/fsfw_hal index 14fe3257..a0f698ff 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit 14fe32572d62db9d19707dc1f9bb6fecb1993b73 +Subproject commit a0f698fffa4dd5c9f86337c5d6170f9321cb8de7 diff --git a/thirdparty/etl b/thirdparty/etl index ae06e641..c308dc42 160000 --- a/thirdparty/etl +++ b/thirdparty/etl @@ -1 +1 @@ -Subproject commit ae06e6417702b770c49289c9e7162cb3f4a5a217 +Subproject commit c308dc427b7a34e54f33860fb2e244564b2740b4 From b0c2606e6a2b5e1b63f92cd06318bf7879b3f9f7 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Thu, 13 May 2021 13:42:47 +0200 Subject: [PATCH 41/42] updated fsfw_hal --- fsfw_hal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fsfw_hal b/fsfw_hal index e5da8b19..a0f698ff 160000 --- a/fsfw_hal +++ b/fsfw_hal @@ -1 +1 @@ -Subproject commit e5da8b194d61aed01fee7b8d6f6b7fe8b01dc547 +Subproject commit a0f698fffa4dd5c9f86337c5d6170f9321cb8de7 From 8508957f5bf6560ae2965085f02db620d0b7ab5e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Mon, 17 May 2021 13:54:12 +0200 Subject: [PATCH 42/42] added etl and tmtc --- thirdparty/etl | 2 +- tmtc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/thirdparty/etl b/thirdparty/etl index c308dc42..0efecca7 160000 --- a/thirdparty/etl +++ b/thirdparty/etl @@ -1 +1 @@ -Subproject commit c308dc427b7a34e54f33860fb2e244564b2740b4 +Subproject commit 0efecca700c6d0847f91b5540638571ba298c793 diff --git a/tmtc b/tmtc index 06750809..574a3e92 160000 --- a/tmtc +++ b/tmtc @@ -1 +1 @@ -Subproject commit 06750809cb52044392e0683896538a652f11a512 +Subproject commit 574a3e92074d9d4d0335dad3ddc5962e1369f5d5