From b68a5cc0b373de4ccbe74ac8b8bdc61225a7bbe7 Mon Sep 17 00:00:00 2001 From: Kushal Parekh Date: Mon, 9 Jun 2025 17:57:12 +0000 Subject: [PATCH 1/4] [nasa/nos3#731] fprime css fidelity --- fsw/fprime/fss_src/Generic_fss.cpp | 209 +++++++++++++++++++++++++---- fsw/fprime/fss_src/Generic_fss.fpp | 37 ++++- fsw/fprime/fss_src/Generic_fss.hpp | 53 ++++++++ 3 files changed, 269 insertions(+), 30 deletions(-) diff --git a/fsw/fprime/fss_src/Generic_fss.cpp b/fsw/fprime/fss_src/Generic_fss.cpp index 0912a1f..5ae9453 100644 --- a/fsw/fprime/fss_src/Generic_fss.cpp +++ b/fsw/fprime/fss_src/Generic_fss.cpp @@ -7,18 +7,6 @@ #include "fss_src/Generic_fss.hpp" #include "FpConfig.hpp" -extern "C"{ - #include "generic_fss_device.h" - #include "generic_fss_platform_cfg.h" - #include "libuart.h" - } - - #include "nos_link.h" -/* -** Global Variables -*/ -spi_info_t FssSpi; -GENERIC_FSS_Device_Data_tlm_t FSSData; namespace Components { @@ -46,6 +34,12 @@ namespace Components { FssSpi.bus = GENERIC_FSS_CFG_BUS; FssSpi.cs = GENERIC_FSS_CFG_CS; + HkTelemetryPkt.CommandCount = 0; + HkTelemetryPkt.CommandErrorCount = 0; + HkTelemetryPkt.DeviceCount = 0; + HkTelemetryPkt.DeviceErrorCount = 0; + HkTelemetryPkt.DeviceEnabled = GENERIC_FSS_DEVICE_DISABLED; + /* Open device specific protocols */ status = spi_init_dev(&FssSpi); if (status == OS_SUCCESS) @@ -75,35 +69,192 @@ namespace Components { // Handler implementations for commands // ---------------------------------------------------------------------- + void Generic_fss :: NOOP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + HkTelemetryPkt.CommandCount++; + + this->log_ACTIVITY_HI_TELEM("NOOP command success!"); + OS_printf("NOOP command successful!\n"); + + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + + void Generic_fss :: ENABLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + int32_t status = OS_SUCCESS; + + if(HkTelemetryPkt.DeviceEnabled == GENERIC_FSS_DEVICE_DISABLED) + { + HkTelemetryPkt.CommandCount++; + + FssSpi.deviceString = GENERIC_FSS_CFG_STRING; + FssSpi.handle = GENERIC_FSS_CFG_HANDLE; + FssSpi.baudrate = GENERIC_FSS_CFG_BAUD; + FssSpi.spi_mode = GENERIC_FSS_CFG_SPI_MODE; + FssSpi.bits_per_word = GENERIC_FSS_CFG_BITS_PER_WORD; + FssSpi.bus = GENERIC_FSS_CFG_BUS; + FssSpi.cs = GENERIC_FSS_CFG_CS; + + status = spi_init_dev(&FssSpi); + if(status == OS_SUCCESS) + { + HkTelemetryPkt.DeviceEnabled = GENERIC_FSS_DEVICE_ENABLED; + HkTelemetryPkt.DeviceCount++; + + this->log_ACTIVITY_HI_TELEM("Enable command success!"); + OS_printf("Enable command successful!\n"); + } + else + { + HkTelemetryPkt.DeviceErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Enable command failed to init SPI!"); + OS_printf("Enable command failed to init SPI!\n"); + } + } + else + { + HkTelemetryPkt.CommandErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Enable failed, already Enabled!"); + OS_printf("Enable failed, already Enabled!\n"); + } + + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + + void Generic_fss :: DISABLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + int32_t status = OS_SUCCESS; + + if(HkTelemetryPkt.DeviceEnabled == GENERIC_FSS_DEVICE_ENABLED) + { + HkTelemetryPkt.CommandCount++; + + status = spi_close_device(&FssSpi); + if(status == OS_SUCCESS) + { + HkTelemetryPkt.DeviceEnabled = GENERIC_FSS_DEVICE_DISABLED; + HkTelemetryPkt.DeviceCount++; + + this->log_ACTIVITY_HI_TELEM("Disable command success!"); + OS_printf("Disable command successful!\n"); + } + else + { + HkTelemetryPkt.DeviceErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Disable command failed to close SPI!"); + OS_printf("Disable command failed to close SPI!\n"); + } + } + else + { + HkTelemetryPkt.CommandErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Disable failed, already Disabled!"); + OS_printf("Disable failed, already Disabled!\n"); + } + + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + + void Generic_fss :: REQUEST_HOUSEKEEPING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + + this->tlmWrite_ALPHA(FSSData.Alpha); + this->tlmWrite_BETA(FSSData.Beta); + this->tlmWrite_ERRORCODE(FSSData.ErrorCode); + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + + this->log_ACTIVITY_HI_TELEM("Requested Housekeeping!"); + OS_printf("Requested Housekeeping!\n"); + + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + + void Generic_fss :: RESET_COUNTERS_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + HkTelemetryPkt.CommandCount = 0; + HkTelemetryPkt.CommandErrorCount = 0; + HkTelemetryPkt.DeviceCount = 0; + HkTelemetryPkt.DeviceErrorCount = 0; + + this->log_ACTIVITY_HI_TELEM("Reset Counters command successful!"); + OS_printf("Reset Counters command successful!\n"); + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); + + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + void Generic_fss :: REQUEST_DATA_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { int32_t status = OS_SUCCESS; - float Alpha; - float Beta; - uint8_t ErrorCode; - uint8_t read_data[GENERIC_FSS_DEVICE_DATA_SIZE]; - uint8_t write_data[GENERIC_FSS_DEVICE_DATA_SIZE]; - - status = GENERIC_FSS_RequestData(&FssSpi, &FSSData); - if (status == OS_SUCCESS) + + + if(HkTelemetryPkt.DeviceEnabled == GENERIC_FSS_DEVICE_ENABLED) { + HkTelemetryPkt.CommandCount++; + status = GENERIC_FSS_RequestData(&FssSpi, &FSSData); + if (status == OS_SUCCESS) + { + HkTelemetryPkt.DeviceCount++; this->log_ACTIVITY_HI_TELEM("RequestData command success\n"); - + OS_printf("RequestData command successful!\n"); + + } + else + { + HkTelemetryPkt.DeviceErrorCount++; + this->log_ACTIVITY_HI_TELEM("RequestData command failed\n"); + OS_printf("RequestData command failed!\n"); + } } else { - this->log_ACTIVITY_HI_TELEM("RequestData command failed\n"); + HkTelemetryPkt.CommandErrorCount++; } - Alpha = FSSData.Alpha; - Beta = FSSData.Beta; - ErrorCode = FSSData.ErrorCode; - - this->tlmWrite_ALPHA(Alpha); - this->tlmWrite_BETA(Beta); - this->tlmWrite_ERRORCODE(ErrorCode); + this->tlmWrite_ALPHA(FSSData.Alpha); + this->tlmWrite_BETA(FSSData.Beta); + this->tlmWrite_ERRORCODE(FSSData.ErrorCode); + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } + inline Generic_fss_ActiveState Generic_fss :: get_active_state(uint8_t DeviceEnabled) + { + Generic_fss_ActiveState state; + + if(DeviceEnabled == GENERIC_FSS_DEVICE_ENABLED) + { + state.e = Generic_fss_ActiveState::ENABLED; + } + else + { + state.e = Generic_fss_ActiveState::DISABLED; + } + + return state; + } + } diff --git a/fsw/fprime/fss_src/Generic_fss.fpp b/fsw/fprime/fss_src/Generic_fss.fpp index ec72054..24682ac 100755 --- a/fsw/fprime/fss_src/Generic_fss.fpp +++ b/fsw/fprime/fss_src/Generic_fss.fpp @@ -6,15 +6,50 @@ module Components { #### Uncomment the following examples to start customizing your component #### ############################################################################## + @ Component Enable State + enum ActiveState { + DISABLED @< DISABLED + ENABLED @< ENABLED + } + + @ NOOP Cmd + async command NOOP() + + @ Reset Counters Cmd + async command RESET_COUNTERS() + + @ Enable Cmd + async command ENABLE() + + @ Disable Cmd + async command DISABLE() + + @ Request Housekeeping + async command REQUEST_HOUSEKEEPING() + @ Command to request data async command REQUEST_DATA( ) @ Telemetry event event TELEM( - log_info: string size 30 + log_info: string size 40 ) severity activity high format "Generic_fss: {}" + @ Command Count + telemetry CommandCount: U32 + + @ Command Error Count + telemetry CommandErrorCount: U32 + + @ Device Count + telemetry DeviceCount: U32 + + @ Device Error Count + telemetry DeviceErrorCount: U32 + + telemetry DeviceEnabled: ActiveState + @ Angle alpha telemetry ALPHA: U32 diff --git a/fsw/fprime/fss_src/Generic_fss.hpp b/fsw/fprime/fss_src/Generic_fss.hpp index 49e7833..7687f5c 100644 --- a/fsw/fprime/fss_src/Generic_fss.hpp +++ b/fsw/fprime/fss_src/Generic_fss.hpp @@ -8,6 +8,28 @@ #define Components_Generic_fss_HPP #include "fss_src/Generic_fssComponentAc.hpp" +#include "fss_src/Generic_fss_ActiveStateEnumAc.hpp" + +extern "C"{ + #include "generic_fss_device.h" + #include "generic_fss_platform_cfg.h" + #include "libuart.h" + } + +#include "nos_link.h" + +typedef struct +{ + uint8_t DeviceCount; + uint8_t DeviceErrorCount; + uint8_t CommandErrorCount; + uint8_t CommandCount; + uint8_t DeviceEnabled; +} FSS_Hk_tlm_t; +#define FSS_HK_TLM_LNGTH sizeof(FSS_Hk_tlm_t) + +#define GENERIC_FSS_DEVICE_DISABLED 0 +#define GENERIC_FSS_DEVICE_ENABLED 1 namespace Components { @@ -17,6 +39,10 @@ namespace Components { public: + spi_info_t FssSpi; + GENERIC_FSS_Device_Data_tlm_t FSSData; + FSS_Hk_tlm_t HkTelemetryPkt; + // ---------------------------------------------------------------------- // Component construction and destruction // ---------------------------------------------------------------------- @@ -35,11 +61,38 @@ namespace Components { // Handler implementations for commands // ---------------------------------------------------------------------- + void NOOP_cmdHandler( + FwOpcodeType opCode, + U32 cmdSeq + ) override; + + void RESET_COUNTERS_cmdHandler( + FwOpcodeType opCode, + U32 cmdSeq + ) override; + + void ENABLE_cmdHandler( + FwOpcodeType opCode, + U32 cmdSeq + ) override; + + void DISABLE_cmdHandler( + FwOpcodeType opCode, + U32 cmdSeq + ) override; + + void REQUEST_HOUSEKEEPING_cmdHandler( + FwOpcodeType opCode, + U32 cmdSeq + ) override; + void REQUEST_DATA_cmdHandler( FwOpcodeType opCode, //!< The opcode U32 cmdSeq //!< The command sequence number ) override; + inline Generic_fss_ActiveState get_active_state(uint8_t DeviceEnabled); + }; } From 2d020b2eca1282a79f2b6085807e7deb14e2c52e Mon Sep 17 00:00:00 2001 From: Kushal Parekh Date: Mon, 9 Jun 2025 20:01:02 +0000 Subject: [PATCH 2/4] [nasa/nos3#731] fix enable state fss --- fsw/fprime/fss_src/Generic_fss.cpp | 34 +++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/fsw/fprime/fss_src/Generic_fss.cpp b/fsw/fprime/fss_src/Generic_fss.cpp index 5ae9453..4e4aeda 100644 --- a/fsw/fprime/fss_src/Generic_fss.cpp +++ b/fsw/fprime/fss_src/Generic_fss.cpp @@ -52,6 +52,8 @@ namespace Components { status = OS_ERROR; } + status = spi_close_device(&FssSpi); + } Generic_fss :: @@ -171,17 +173,29 @@ namespace Components { void Generic_fss :: REQUEST_HOUSEKEEPING_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ - this->tlmWrite_ALPHA(FSSData.Alpha); - this->tlmWrite_BETA(FSSData.Beta); - this->tlmWrite_ERRORCODE(FSSData.ErrorCode); - this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); - this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); - this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); - this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); - this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + if(HkTelemetryPkt.DeviceEnabled == GENERIC_FSS_DEVICE_ENABLED) + { + HkTelemetryPkt.CommandCount++; - this->log_ACTIVITY_HI_TELEM("Requested Housekeeping!"); - OS_printf("Requested Housekeeping!\n"); + this->tlmWrite_ALPHA(FSSData.Alpha); + this->tlmWrite_BETA(FSSData.Beta); + this->tlmWrite_ERRORCODE(FSSData.ErrorCode); + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); + this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); + this->tlmWrite_DeviceErrorCount(HkTelemetryPkt.DeviceErrorCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + + this->log_ACTIVITY_HI_TELEM("Requested Housekeeping!"); + OS_printf("Requested Housekeeping!\n"); + } + else + { + this->log_ACTIVITY_HI_TELEM("Device Disabled!"); + OS_printf("Device Disabled!\n"); + } + + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } From 3fe65d8640f31d3a029e3d9c90bc9b0abc2c7d11 Mon Sep 17 00:00:00 2001 From: Kushal Parekh Date: Tue, 10 Jun 2025 14:35:07 +0000 Subject: [PATCH 3/4] [nasa/nos3#731] noop shows active state --- fsw/fprime/fss_src/Generic_fss.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/fsw/fprime/fss_src/Generic_fss.cpp b/fsw/fprime/fss_src/Generic_fss.cpp index 4e4aeda..a8e7be5 100644 --- a/fsw/fprime/fss_src/Generic_fss.cpp +++ b/fsw/fprime/fss_src/Generic_fss.cpp @@ -78,6 +78,7 @@ namespace Components { OS_printf("NOOP command successful!\n"); this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); } From fe54c06394eef9505f575952080da6bf789ec58c Mon Sep 17 00:00:00 2001 From: Kushal Parekh Date: Wed, 18 Jun 2025 16:06:01 +0000 Subject: [PATCH 4/4] [nasa/nos3#731] remove os_printfs --- fsw/fprime/fss_src/Generic_fss.cpp | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/fsw/fprime/fss_src/Generic_fss.cpp b/fsw/fprime/fss_src/Generic_fss.cpp index a8e7be5..f5d0d7b 100644 --- a/fsw/fprime/fss_src/Generic_fss.cpp +++ b/fsw/fprime/fss_src/Generic_fss.cpp @@ -73,9 +73,7 @@ namespace Components { void Generic_fss :: NOOP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ HkTelemetryPkt.CommandCount++; - this->log_ACTIVITY_HI_TELEM("NOOP command success!"); - OS_printf("NOOP command successful!\n"); this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); @@ -104,14 +102,12 @@ namespace Components { HkTelemetryPkt.DeviceCount++; this->log_ACTIVITY_HI_TELEM("Enable command success!"); - OS_printf("Enable command successful!\n"); } else { HkTelemetryPkt.DeviceErrorCount++; this->log_ACTIVITY_HI_TELEM("Enable command failed to init SPI!"); - OS_printf("Enable command failed to init SPI!\n"); } } else @@ -119,7 +115,6 @@ namespace Components { HkTelemetryPkt.CommandErrorCount++; this->log_ACTIVITY_HI_TELEM("Enable failed, already Enabled!"); - OS_printf("Enable failed, already Enabled!\n"); } this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); @@ -143,24 +138,18 @@ namespace Components { { HkTelemetryPkt.DeviceEnabled = GENERIC_FSS_DEVICE_DISABLED; HkTelemetryPkt.DeviceCount++; - this->log_ACTIVITY_HI_TELEM("Disable command success!"); - OS_printf("Disable command successful!\n"); } else { HkTelemetryPkt.DeviceErrorCount++; - this->log_ACTIVITY_HI_TELEM("Disable command failed to close SPI!"); - OS_printf("Disable command failed to close SPI!\n"); } } else { HkTelemetryPkt.CommandErrorCount++; - this->log_ACTIVITY_HI_TELEM("Disable failed, already Disabled!"); - OS_printf("Disable failed, already Disabled!\n"); } this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); @@ -188,12 +177,10 @@ namespace Components { this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); this->log_ACTIVITY_HI_TELEM("Requested Housekeeping!"); - OS_printf("Requested Housekeeping!\n"); } else { - this->log_ACTIVITY_HI_TELEM("Device Disabled!"); - OS_printf("Device Disabled!\n"); + this->log_ACTIVITY_HI_TELEM("HK Failed, Device Disabled!"); } @@ -208,7 +195,6 @@ namespace Components { HkTelemetryPkt.DeviceErrorCount = 0; this->log_ACTIVITY_HI_TELEM("Reset Counters command successful!"); - OS_printf("Reset Counters command successful!\n"); this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); this->tlmWrite_CommandErrorCount(HkTelemetryPkt.CommandErrorCount); this->tlmWrite_DeviceCount(HkTelemetryPkt.DeviceCount); @@ -229,20 +215,19 @@ namespace Components { if (status == OS_SUCCESS) { HkTelemetryPkt.DeviceCount++; - this->log_ACTIVITY_HI_TELEM("RequestData command success\n"); - OS_printf("RequestData command successful!\n"); - + this->log_ACTIVITY_HI_TELEM("RequestData command success\n"); } else { HkTelemetryPkt.DeviceErrorCount++; this->log_ACTIVITY_HI_TELEM("RequestData command failed\n"); - OS_printf("RequestData command failed!\n"); } } else { HkTelemetryPkt.CommandErrorCount++; + this->log_ACTIVITY_HI_TELEM("RequestData command failed, Device Disabled\n"); + } this->tlmWrite_ALPHA(FSSData.Alpha);