From 45804a86752f411ce196e1e01f191dbd42bfe26e Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" <–meierj@irs.uni-stuttgart.de> Date: Thu, 8 Jul 2021 11:20:19 +0200 Subject: [PATCH] star tracker read temperature and included arcsec lib --- .gitmodules | 6 +- CMakeLists.txt | 5 ++ arcsec-start-tracker | 1 - bsp_q7s/core/ObjectFactory.cpp | 2 +- mission/devices/CMakeLists.txt | 1 + mission/devices/StarTrackerHandler.cpp | 76 +++++++------------ mission/devices/StarTrackerHandler.h | 17 ++--- .../StarTrackerDefinitions.h | 2 +- thirdparty/arcsec_star_tracker | 1 + 9 files changed, 47 insertions(+), 64 deletions(-) delete mode 160000 arcsec-start-tracker create mode 160000 thirdparty/arcsec_star_tracker diff --git a/.gitmodules b/.gitmodules index 67e083f0..b555af94 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,6 +19,6 @@ [submodule "generators/fsfwgen"] path = generators/fsfwgen url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-generators.git -[submodule "arcsec-start-tracker"] - path = arcsec-start-tracker - url = https://egit.irs.uni-stuttgart.de/eive/arcsec-star-tracker.git +[submodule "thirdparty/arcsec_star_tracker"] + path = thirdparty/arcsec_star_tracker + url = https://egit.irs.uni-stuttgart.de/eive/arcsec_star_tracker.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 10c3a349..b5abe9ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(LIB_ETL_NAME etl) set(LIB_CSP_NAME libcsp) set(LIB_FSFW_HAL_NAME fsfw_hal) set(LIB_LWGPS_NAME lwgps) +set(LIB_ARCSEC wire) set(THIRD_PARTY_FOLDER thirdparty) # Set path names @@ -64,6 +65,7 @@ set(FSFW_HAL_LIB_PATH fsfw_hal) set(CSP_LIB_PATH ${THIRD_PARTY_FOLDER}/libcsp) set(ETL_LIB_PATH ${THIRD_PARTY_FOLDER}/etl) set(LWGPS_LIB_PATH ${THIRD_PARTY_FOLDER}/lwgps) +set(ARCSEC_LIB_PATH ${THIRD_PARTY_FOLDER}/arcsec_star_tracker) set(FSFW_WARNING_SHADOW_LOCAL_GCC OFF) set(ADD_LINUX_FILES False) @@ -148,6 +150,7 @@ if(NOT Q7S_SIMPLE_MODE) add_subdirectory(${MISSION_PATH}) add_subdirectory(${TEST_PATH}) add_subdirectory(${FSFW_HAL_LIB_PATH}) + add_subdirectory(${ARCSEC_LIB_PATH}) endif() @@ -164,6 +167,7 @@ if(NOT Q7S_SIMPLE_MODE) ${LIB_OS_NAME} ${LIB_LWGPS_NAME} ${LIB_FSFW_HAL_NAME} + ${LIB_ARCSEC} ) endif() @@ -184,6 +188,7 @@ target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${FSFW_CONFIG_PATH} ${CMAKE_CURRENT_BINARY_DIR} + ${ARCSEC_LIB_PATH} ) diff --git a/arcsec-start-tracker b/arcsec-start-tracker deleted file mode 160000 index 7103370d..00000000 --- a/arcsec-start-tracker +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7103370d15c19a843e40dc880a29ace51f348f92 diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index 0233672f..2aaf5264 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -622,7 +622,7 @@ void ObjectFactory::produce(void* args){ rw4SpiCookie->setCallbackArgs(rwHandler4); UartCookie* starTrackerCookie = new UartCookie(objects::START_TRACKER, std::string("/dev/ttyUL3"), - UartModes::NON_CANONICAL, 115200, StartTracker::MAX_FRAME_SIZE* 2 + 2); + UartModes::NON_CANONICAL, 115200, StarTracker::MAX_FRAME_SIZE* 2 + 2); starTrackerCookie->setNoFixedSizeReply(); new StarTrackerHandler(objects::START_TRACKER, objects::UART_COM_IF, starTrackerCookie); diff --git a/mission/devices/CMakeLists.txt b/mission/devices/CMakeLists.txt index 78d54185..c49a29db 100644 --- a/mission/devices/CMakeLists.txt +++ b/mission/devices/CMakeLists.txt @@ -16,6 +16,7 @@ target_sources(${TARGET_NAME} PUBLIC RadiationSensorHandler.cpp GyroADIS16507Handler.cpp RwHandler.cpp + StarTrackerHandler.cpp ) diff --git a/mission/devices/StarTrackerHandler.cpp b/mission/devices/StarTrackerHandler.cpp index c2fefc6a..59eab3de 100644 --- a/mission/devices/StarTrackerHandler.cpp +++ b/mission/devices/StarTrackerHandler.cpp @@ -4,10 +4,13 @@ #include #include -#include +extern "C" { + #include + #include "common/misc.h" +} StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, - CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t enableGpio) : + CookieIF * comCookie) : DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this) { if (comCookie == NULL) { sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl; @@ -34,7 +37,7 @@ void StarTrackerHandler::doShutDown() { ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) { switch (internalState) { case InternalState::TEMPERATURE_REQUEST: - *id = StartTracker::REQ_TEMPERATURE; + *id = StarTracker::REQ_TEMPERATURE; break; default: sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid internal step" @@ -52,7 +55,7 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi const uint8_t * commandData, size_t commandDataLen) { switch (deviceCommand) { - case (StartTracker::REQ_TEMPERATURE): { + case (StarTracker::REQ_TEMPERATURE): { prepareTemperatureRequest(); return RETURN_OK; } @@ -65,8 +68,8 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi void StarTrackerHandler::fillCommandAndReplyMap() { /** Reply lengths are unknown because of the slip encoding. Thus always maximum reply size * is specified */ - this->insertInCommandAndReplyMap(StartTracker::REQ_TEMPERATURE, 1, &temperatureSet, - sStartTracker::MAX_FRAME_SIZE * 2 + 2); + this->insertInCommandAndReplyMap(StarTracker::REQ_TEMPERATURE, 1, &temperatureSet, + StarTracker::MAX_FRAME_SIZE * 2 + 2); } ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t remainingSize, @@ -74,8 +77,8 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t rema uint32_t decodedLength = 0; - for (int i = 0; i < remainingSize; i++) { - enum arc_dec_result decResult = arc_transport_decode_body(*(start + i), &slipInfo, + for (size_t idx = 0; idx < remainingSize; idx++) { + enum arc_dec_result decResult = arc_transport_decode_body(*(start + idx), &slipInfo, decodedFrame, &decodedLength); switch (decResult) { @@ -102,10 +105,10 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t rema } } - switch (*(decodedFrame[1])) { - case (static_cast(StartTracker::REQ_TEMPERATURE)): { + switch (decodedFrame[1]) { + case (static_cast(StarTracker::REQ_TEMPERATURE)): { *foundLen = decodedLength; - *foundId = StartTracker::REQ_TEMPERATURE; + *foundId = StarTracker::REQ_TEMPERATURE; break; } default: { @@ -122,7 +125,7 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t rema ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) { switch (id) { - case (StartTracker::REQ_TEMPERATURE): { + case (StarTracker::REQ_TEMPERATURE): { handleTemperatureTm(); break; } @@ -146,38 +149,11 @@ uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { - localDataPoolMap.emplace(RwDefinitions::TEMPERATURE_C, new PoolEntry( { 0 })); - - localDataPoolMap.emplace(RwDefinitions::CURR_SPEED, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::REFERENCE_SPEED, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::STATE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::CLC_MODE, new PoolEntry( { 0 })); - - localDataPoolMap.emplace(RwDefinitions::LAST_RESET_STATUS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::CURRRENT_RESET_STATUS, new PoolEntry( { 0 })); - - localDataPoolMap.emplace(RwDefinitions::TM_LAST_RESET_STATUS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::TM_MCU_TEMPERATURE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::TM_RW_STATE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::TM_CLC_MODE, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::TM_RW_CURR_SPEED, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::TM_RW_REF_SPEED, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::INVALID_CRC_PACKETS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::INVALID_LEN_PACKETS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::INVALID_CMD_PACKETS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::EXECUTED_REPLIES, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::COMMAND_REPLIES, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_BYTES_WRITTEN, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_BYTES_READ, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_PARITY_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_NOISE_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_FRAME_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_REG_OVERRUN_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::UART_TOTAL_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_WRITTEN, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_READ, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::SPI_REG_OVERRUN_ERRORS, new PoolEntry( { 0 })); - localDataPoolMap.emplace(RwDefinitions::SPI_TOTAL_ERRORS, new PoolEntry( { 0 })); + localDataPoolMap.emplace(StarTracker::STATUS, new PoolEntry( { 0 })); + localDataPoolMap.emplace(StarTracker::TICKS, new PoolEntry( { 0 })); + localDataPoolMap.emplace(StarTracker::TIME, new PoolEntry( { 0 })); + localDataPoolMap.emplace(StarTracker::MCU_TEMPERATURE, new PoolEntry( { 0 })); + localDataPoolMap.emplace(StarTracker::CMOS_TEMPERATURE, new PoolEntry( { 0 })); return RETURN_OK; } @@ -188,7 +164,7 @@ size_t StarTrackerHandler::getNextReplyLength(DeviceCommandId_t commandId){ void StarTrackerHandler::slipInit() { slipInfo.buffer = rxBuffer; - slipInfo.maxlength = StartTracker::MAX_FRAME_SIZE; + slipInfo.maxlength = StarTracker::MAX_FRAME_SIZE; slipInfo.length = 0; slipInfo.unescape_next = 0; slipInfo.prev_state = SLIP_COMPLETE; @@ -196,7 +172,7 @@ void StarTrackerHandler::slipInit() { void StarTrackerHandler::prepareTemperatureRequest() { uint32_t length = 0; - arc_tm_pack_temperature_req(commandBuffer); + arc_tm_pack_temperature_req(commandBuffer, &length); uint32_t encLength = 0; arc_transport_encode_body(commandBuffer, length, encBuffer, &encLength); rawPacket = encBuffer; @@ -210,15 +186,17 @@ void StarTrackerHandler::handleTemperatureTm() { offset += 1; if(temperatureSet.status.value != 0) { sif::warning << "StarTrackerHandler::handleTemperatureTm: Reply error: " - << static_const(temperatureSet.status.value) << std::endl; + << static_cast(temperatureSet.status.value) << std::endl; triggerEvent(TM_REPLY_ERROR, temperatureSet.status.value); } temperatureSet.ticks = *(decodedFrame + offset) << 24 | *(decodedFrame + offset + 1) << 16 | *(decodedFrame + offset + 2) << 8 | *(decodedFrame + offset + 3); offset += 4; - temperatureSet.time = *(decodedFrame + offset) << 56 | *(decodedFrame + offset + 1) << 48 - | *(decodedFrame + offset + 2) << 40 | *(decodedFrame + offset + 3) << 32 + temperatureSet.time = static_cast(*(decodedFrame + offset)) << 56 + | static_cast(*(decodedFrame + offset + 1)) << 48 + | static_cast(*(decodedFrame + offset + 2)) << 40 + | static_cast(*(decodedFrame + offset + 3)) << 32 | *(decodedFrame + offset + 4) << 24 | *(decodedFrame + offset + 5) << 16 | *(decodedFrame + offset + 6) << 8 | *(decodedFrame + offset + 7); offset += 8; diff --git a/mission/devices/StarTrackerHandler.h b/mission/devices/StarTrackerHandler.h index 09478de9..ee96e544 100644 --- a/mission/devices/StarTrackerHandler.h +++ b/mission/devices/StarTrackerHandler.h @@ -3,6 +3,7 @@ #include #include +#include /** * @brief This is the device handler for the star tracker from arcsec. @@ -58,6 +59,7 @@ private: //! [EXPORT] : [COMMENT] Received reply is too short static const ReturnValue_t REPLY_TOO_SHORT = MAKE_RETURN_CODE(0xB0); //! [EXPORT] : [COMMENT] Received reply with invalid CRC + static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xB0); static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HANDLER; @@ -65,19 +67,16 @@ private: static const ReturnValue_t TM_REPLY_ERROR = MAKE_RETURN_CODE(0xA0); //! P1: TM id - LinuxLibgpioIF* gpioComIF = nullptr; - gpioId_t enableGpio = gpio::NO_GPIO; - StarTracker::TemperatureSet temperatureSet; - uint8_t commandBuffer[StartTracker::MAX_FRAME_SIZE]; - uint8_t rxBuffer[StartTracker::MAX_FRAME_SIZE]; - uint8_t decodedFrame[StartTracker::MAX_FRAME_SIZE]; + uint8_t commandBuffer[StarTracker::MAX_FRAME_SIZE]; + uint8_t rxBuffer[StarTracker::MAX_FRAME_SIZE]; + uint8_t decodedFrame[StarTracker::MAX_FRAME_SIZE]; /** Size of buffer derived from the egse source code */ - uint8_t encBuffer[StartTracker::MAX_FRAME_SIZE * 2 + 2]; + uint8_t encBuffer[StarTracker::MAX_FRAME_SIZE * 2 + 2]; - static slip_decode_state slipInfo = {0}; + slip_decode_state slipInfo; enum class InternalState { TEMPERATURE_REQUEST @@ -90,7 +89,7 @@ private: */ void slipInit(); - void prepareTemperatureRequest(DeviceCommandId_t id); + void prepareTemperatureRequest(); /** * @brief This function handles the telemetry reply of a temperature request. diff --git a/mission/devices/devicedefinitions/StarTrackerDefinitions.h b/mission/devices/devicedefinitions/StarTrackerDefinitions.h index 83392e58..cf4353dd 100644 --- a/mission/devices/devicedefinitions/StarTrackerDefinitions.h +++ b/mission/devices/devicedefinitions/StarTrackerDefinitions.h @@ -50,7 +50,7 @@ public: lp_var_t ticks = lp_var_t(sid.objectId, PoolIds::TICKS, this); /** Unix time in microseconds */ - lp_var_t ticks = lp_var_t(sid.objectId, + lp_var_t time = lp_var_t(sid.objectId, PoolIds::TIME, this); lp_var_t mcuTemperature = lp_var_t(sid.objectId, PoolIds::MCU_TEMPERATURE, this); diff --git a/thirdparty/arcsec_star_tracker b/thirdparty/arcsec_star_tracker new file mode 160000 index 00000000..65dfee81 --- /dev/null +++ b/thirdparty/arcsec_star_tracker @@ -0,0 +1 @@ +Subproject commit 65dfee8191cd0254d4988b08c9607024389e2b08