diff --git a/fsw/fprime/fss_src/Generic_fss.cpp b/fsw/fprime/fss_src/Generic_fss.cpp index 0912a1f..f5d0d7b 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) @@ -58,6 +52,8 @@ namespace Components { status = OS_ERROR; } + status = spi_close_device(&FssSpi); + } Generic_fss :: @@ -75,35 +71,190 @@ namespace Components { // Handler implementations for commands // ---------------------------------------------------------------------- - void Generic_fss :: REQUEST_DATA_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) - { + void Generic_fss :: NOOP_cmdHandler(FwOpcodeType opCode, U32 cmdSeq){ + HkTelemetryPkt.CommandCount++; + this->log_ACTIVITY_HI_TELEM("NOOP command success!"); + + this->tlmWrite_CommandCount(HkTelemetryPkt.CommandCount); + this->tlmWrite_DeviceEnabled(get_active_state(HkTelemetryPkt.DeviceEnabled)); + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } + + void Generic_fss :: ENABLE_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_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!"); + } + else + { + HkTelemetryPkt.DeviceErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Enable command failed to init SPI!"); + } + } + else + { + HkTelemetryPkt.CommandErrorCount++; + + this->log_ACTIVITY_HI_TELEM("Enable failed, already Enabled!"); + } + + 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!"); + } + else + { + HkTelemetryPkt.DeviceErrorCount++; + this->log_ACTIVITY_HI_TELEM("Disable command failed to close SPI!"); + } + } + else + { + HkTelemetryPkt.CommandErrorCount++; + this->log_ACTIVITY_HI_TELEM("Disable failed, already Disabled!"); + } + + 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){ + + if(HkTelemetryPkt.DeviceEnabled == GENERIC_FSS_DEVICE_ENABLED) { - this->log_ACTIVITY_HI_TELEM("RequestData command success\n"); - + HkTelemetryPkt.CommandCount++; + + 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!"); } else { + this->log_ACTIVITY_HI_TELEM("HK Failed, Device Disabled!"); + } + + + + 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!"); + 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; + + + 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"); + } + else + { + HkTelemetryPkt.DeviceErrorCount++; this->log_ACTIVITY_HI_TELEM("RequestData command failed\n"); + } } + else + { + HkTelemetryPkt.CommandErrorCount++; + this->log_ACTIVITY_HI_TELEM("RequestData command failed, Device Disabled\n"); - 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); + }; }