diff --git a/.travis.yml b/.travis.yml index 04a2ffb..b9516a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ +os: linux dist: bionic -sudo: required -language: - - c +language: c compiler: - gcc addons: @@ -16,7 +15,7 @@ before_install: - cppcheck --version # for clang-format 10 - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - - - sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main' + - sudo add-apt-repository 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main' - sudo apt-get update - sudo apt-get install clang-format-10 - clang-format-10 --version diff --git a/fsw/mission_inc/ci_lab_perfids.h b/fsw/mission_inc/ci_lab_perfids.h index a9552cd..a9bdeae 100644 --- a/fsw/mission_inc/ci_lab_perfids.h +++ b/fsw/mission_inc/ci_lab_perfids.h @@ -29,8 +29,8 @@ #ifndef _ci_lab_perfids_h_ #define _ci_lab_perfids_h_ -#define CI_MAIN_TASK_PERF_ID 32 -#define CI_SOCKET_RCV_PERF_ID 33 +#define CI_LAB_MAIN_TASK_PERF_ID 32 +#define CI_LAB_SOCKET_RCV_PERF_ID 33 #endif /* _ci_lab_perfids_h_ */ diff --git a/fsw/src/ci_lab_app.c b/fsw/src/ci_lab_app.c index 88446a3..ca8f53b 100644 --- a/fsw/src/ci_lab_app.c +++ b/fsw/src/ci_lab_app.c @@ -33,46 +33,61 @@ #include "ci_lab_perfids.h" #include "ci_lab_msgids.h" #include "ci_lab_msg.h" -#include "ci_lab_defs.h" #include "ci_lab_events.h" #include "ci_lab_version.h" -#include "cfe_platform_cfg.h" - /* ** CI global data... */ -bool CI_SocketConnected = false; -ci_hk_tlm_t CI_HkTelemetryPkt; -CFE_SB_PipeId_t CI_CommandPipe; -CFE_SB_MsgPtr_t CIMsgPtr; -int CI_SocketID; -struct sockaddr_in CI_SocketAddress; -uint8 CI_IngestBuffer[CI_MAX_INGEST]; -CFE_SB_Msg_t * CI_IngestPointer = (CFE_SB_Msg_t *)&CI_IngestBuffer[0]; -CFE_SB_MsgId_t PDUMessageID = 0; -bool adjustFileSize = false; -int PDUFileSizeAdjustment; -bool dropFileData = false; -int dropFileDataCnt; -bool dropEOF = false; -int dropEOFCnt; -bool dropFIN = false; -int dropFINCnt; -bool dropACK = false; -int dropACKCnt; -bool dropMetaData = false; -int dropMetaDataCnt; -bool dropNAK = false; -int dropNAKCnt; -bool corruptChecksum = false; - -static CFE_EVS_BinFilter_t CI_EventFilters[] = {/* Event ID mask */ - {CI_SOCKETCREATE_ERR_EID, 0x0000}, {CI_SOCKETBIND_ERR_EID, 0x0000}, - {CI_STARTUP_INF_EID, 0x0000}, {CI_COMMAND_ERR_EID, 0x0000}, - {CI_COMMANDNOP_INF_EID, 0x0000}, {CI_COMMANDRST_INF_EID, 0x0000}, - {CI_INGEST_INF_EID, 0x0000}, {CI_INGEST_ERR_EID, 0x0000}}; +/* + * Declaring the CI_LAB_IngestBuffer as a union + * ensures it is aligned appropriately to + * store a CFE_SB_Msg_t type. + */ +typedef union +{ + CFE_SB_Msg_t MsgHdr; + uint8 bytes[CI_LAB_MAX_INGEST]; + uint16 hwords[2]; +} CI_LAB_IngestBuffer_t; + +typedef union +{ + CFE_SB_Msg_t MsgHdr; + CI_LAB_HkTlm_t HkTlm; +} CI_LAB_HkTlm_Buffer_t; + +typedef struct +{ + bool SocketConnected; + CFE_SB_PipeId_t CommandPipe; + CFE_SB_MsgPtr_t MsgPtr; + uint32 SocketID; + OS_SockAddr_t SocketAddress; + + CI_LAB_HkTlm_Buffer_t HkBuffer; + CI_LAB_IngestBuffer_t IngestBuffer; +} CI_LAB_GlobalData_t; + +CI_LAB_GlobalData_t CI_LAB_Global; + +static CFE_EVS_BinFilter_t CI_LAB_EventFilters[] = + {/* Event ID mask */ + {CI_LAB_SOCKETCREATE_ERR_EID, 0x0000}, {CI_LAB_SOCKETBIND_ERR_EID, 0x0000}, {CI_LAB_STARTUP_INF_EID, 0x0000}, + {CI_LAB_COMMAND_ERR_EID, 0x0000}, {CI_LAB_COMMANDNOP_INF_EID, 0x0000}, {CI_LAB_COMMANDRST_INF_EID, 0x0000}, + {CI_LAB_INGEST_INF_EID, 0x0000}, {CI_LAB_INGEST_ERR_EID, 0x0000}}; + +/* + * Individual message handler function prototypes + * + * Per the recommended code pattern, these should accept a const pointer + * to a structure type which matches the message, and return an int32 + * where CFE_SUCCESS (0) indicates successful handling of the message. + */ +int32 CI_LAB_Noop(const CI_LAB_Noop_t *data); +int32 CI_LAB_ResetCounters(const CI_LAB_ResetCounters_t *data); +int32 CI_LAB_ReportHousekeeping(const CCSDS_CommandPacket_t *data); /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* CI_Lab_AppMain() -- Application entry point and main process loop */ @@ -89,31 +104,31 @@ void CI_Lab_AppMain(void) int32 status; uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; - CFE_ES_PerfLogEntry(CI_MAIN_TASK_PERF_ID); + CFE_ES_PerfLogEntry(CI_LAB_MAIN_TASK_PERF_ID); - CI_TaskInit(); + CI_LAB_TaskInit(); /* ** CI Runloop */ while (CFE_ES_RunLoop(&RunStatus) == true) { - CFE_ES_PerfLogExit(CI_MAIN_TASK_PERF_ID); + CFE_ES_PerfLogExit(CI_LAB_MAIN_TASK_PERF_ID); /* Pend on receipt of command packet -- timeout set to 500 millisecs */ - status = CFE_SB_RcvMsg(&CIMsgPtr, CI_CommandPipe, 500); + status = CFE_SB_RcvMsg(&CI_LAB_Global.MsgPtr, CI_LAB_Global.CommandPipe, 500); - CFE_ES_PerfLogEntry(CI_MAIN_TASK_PERF_ID); + CFE_ES_PerfLogEntry(CI_LAB_MAIN_TASK_PERF_ID); if (status == CFE_SUCCESS) { - CI_ProcessCommandPacket(); + CI_LAB_ProcessCommandPacket(); } /* Regardless of packet vs timeout, always process uplink queue */ - if (CI_SocketConnected) + if (CI_LAB_Global.SocketConnected) { - CI_ReadUpLink(); + CI_LAB_ReadUpLink(); } } @@ -126,73 +141,72 @@ void CI_Lab_AppMain(void) ** This function will be called in the event that the CI app is killed. ** It will close the network socket for CI */ -void CI_delete_callback(void) +void CI_LAB_delete_callback(void) { OS_printf("CI delete callback -- Closing CI Network socket.\n"); - close(CI_SocketID); + OS_close(CI_LAB_Global.SocketID); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* CI_TaskInit() -- CI initialization */ +/* CI_LAB_TaskInit() -- CI initialization */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_TaskInit(void) +void CI_LAB_TaskInit(void) { + int32 status; + + memset(&CI_LAB_Global, 0, sizeof(CI_LAB_Global)); + CFE_ES_RegisterApp(); - CFE_EVS_Register(CI_EventFilters, sizeof(CI_EventFilters) / sizeof(CFE_EVS_BinFilter_t), + CFE_EVS_Register(CI_LAB_EventFilters, sizeof(CI_LAB_EventFilters) / sizeof(CFE_EVS_BinFilter_t), CFE_EVS_EventFilter_BINARY); - CFE_SB_CreatePipe(&CI_CommandPipe, CI_PIPE_DEPTH, "CI_LAB_CMD_PIPE"); - CFE_SB_Subscribe(CI_LAB_CMD_MID, CI_CommandPipe); - CFE_SB_Subscribe(CI_LAB_SEND_HK_MID, CI_CommandPipe); + CFE_SB_CreatePipe(&CI_LAB_Global.CommandPipe, CI_LAB_PIPE_DEPTH, "CI_LAB_CMD_PIPE"); + CFE_SB_Subscribe(CI_LAB_CMD_MID, CI_LAB_Global.CommandPipe); + CFE_SB_Subscribe(CI_LAB_SEND_HK_MID, CI_LAB_Global.CommandPipe); - if ((CI_SocketID = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + status = OS_SocketOpen(&CI_LAB_Global.SocketID, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); + if (status != OS_SUCCESS) { - CFE_EVS_SendEvent(CI_SOCKETCREATE_ERR_EID, CFE_EVS_EventType_ERROR, "CI: create socket failed = %d", errno); + CFE_EVS_SendEvent(CI_LAB_SOCKETCREATE_ERR_EID, CFE_EVS_EventType_ERROR, "CI: create socket failed = %d", + (int)status); } else { - memset(&CI_SocketAddress, 0, sizeof(CI_SocketAddress)); - CI_SocketAddress.sin_family = AF_INET; - CI_SocketAddress.sin_addr.s_addr = htonl(INADDR_ANY); - CI_SocketAddress.sin_port = htons(cfgCI_PORT); + OS_SocketAddrInit(&CI_LAB_Global.SocketAddress, OS_SocketDomain_INET); + OS_SocketAddrSetPort(&CI_LAB_Global.SocketAddress, cfgCI_LAB_PORT); - if ((bind(CI_SocketID, (struct sockaddr *)&CI_SocketAddress, sizeof(CI_SocketAddress)) < 0)) + status = OS_SocketBind(CI_LAB_Global.SocketID, &CI_LAB_Global.SocketAddress); + + if (status != OS_SUCCESS) { - CFE_EVS_SendEvent(CI_SOCKETBIND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: bind socket failed = %d", errno); + CFE_EVS_SendEvent(CI_LAB_SOCKETBIND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: bind socket failed = %d", + (int)status); } else { - CI_SocketConnected = true; -#ifdef _HAVE_FCNTL_ - /* - ** Set the socket to non-blocking - ** This is not available to vxWorks, so it has to be - ** Conditionally compiled in - */ - fcntl(CI_SocketID, F_SETFL, O_NONBLOCK); -#endif + CI_LAB_Global.SocketConnected = true; } } - CI_ResetCounters(); + CI_LAB_ResetCounters_Internal(); /* ** Install the delete handler */ - OS_TaskInstallDeleteHandler(&CI_delete_callback); + OS_TaskInstallDeleteHandler(&CI_LAB_delete_callback); - CFE_SB_InitMsg(&CI_HkTelemetryPkt, CI_LAB_HK_TLM_MID, CI_LAB_HK_TLM_LNGTH, true); + CFE_SB_InitMsg(&CI_LAB_Global.HkBuffer.HkTlm, CI_LAB_HK_TLM_MID, CI_LAB_HK_TLM_LNGTH, true); - CFE_EVS_SendEvent(CI_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI Lab Initialized. Version %d.%d.%d.%d", + CFE_EVS_SendEvent(CI_LAB_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI Lab Initialized. Version %d.%d.%d.%d", CI_LAB_MAJOR_VERSION, CI_LAB_MINOR_VERSION, CI_LAB_REVISION, CI_LAB_MISSION_REV); -} /* End of CI_TaskInit() */ +} /* End of CI_LAB_TaskInit() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: CI_ProcessCommandPacket */ +/* Name: CI_LAB_ProcessCommandPacket */ /* */ /* Purpose: */ /* This routine will process any packet that is received on the CI command*/ @@ -203,74 +217,53 @@ void CI_TaskInit(void) /* 3. Request for housekeeping telemetry packet (from HS task) */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void CI_ProcessCommandPacket(void) +void CI_LAB_ProcessCommandPacket(void) { CFE_SB_MsgId_t MsgId; - MsgId = CFE_SB_GetMsgId(CIMsgPtr); + MsgId = CFE_SB_GetMsgId(CI_LAB_Global.MsgPtr); switch (MsgId) { case CI_LAB_CMD_MID: - CI_ProcessGroundCommand(); + CI_LAB_ProcessGroundCommand(); break; case CI_LAB_SEND_HK_MID: - CI_ReportHousekeeping(); + CI_LAB_ReportHousekeeping((const CCSDS_CommandPacket_t *)CI_LAB_Global.MsgPtr); break; default: - CI_HkTelemetryPkt.ci_command_error_count++; - CFE_EVS_SendEvent(CI_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x", + CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter++; + CFE_EVS_SendEvent(CI_LAB_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x", MsgId); break; } return; -} /* End CI_ProcessCommandPacket */ +} /* End CI_LAB_ProcessCommandPacket */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ -/* CI_ProcessGroundCommand() -- CI ground commands */ +/* CI_LAB_ProcessGroundCommand() -- CI ground commands */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_ProcessGroundCommand(void) +void CI_LAB_ProcessGroundCommand(void) { uint16 CommandCode; - CommandCode = CFE_SB_GetCmdCode(CIMsgPtr); + CommandCode = CFE_SB_GetCmdCode(CI_LAB_Global.MsgPtr); /* Process "known" CI task ground commands */ switch (CommandCode) { - case CI_NOOP_CC: - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command"); - break; - - case CI_RESET_COUNTERS_CC: - CI_ResetCounters(); - break; - - case CI_MODIFY_PDU_FILESIZE_CC: - CI_ModifyFileSizeCmd(CIMsgPtr); - break; - - case CI_CORRUPT_PDU_CHECKSUM_CC: - CI_CorruptChecksumCmd(CIMsgPtr); + case CI_LAB_NOOP_CC: + CI_LAB_Noop((const CI_LAB_Noop_t *)CI_LAB_Global.MsgPtr); break; - case CI_DROP_PDUS_CC: - CI_DropPDUCmd(CIMsgPtr); - break; - - case CI_CAPTURE_PDUS_CC: - CI_CapturePDUsCmd(CIMsgPtr); - break; - - case CI_STOP_PDU_CAPTURE_CC: - CI_StopPDUCaptureCmd(CIMsgPtr); + case CI_LAB_RESET_COUNTERS_CC: + CI_LAB_ResetCounters((const CI_LAB_ResetCounters_t *)CI_LAB_Global.MsgPtr); break; /* default case already found during FC vs length test */ @@ -280,10 +273,41 @@ void CI_ProcessGroundCommand(void) return; -} /* End of CI_ProcessGroundCommand() */ +} /* End of CI_LAB_ProcessGroundCommand() */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Name: CI_LAB_Noop */ +/* */ +/* Purpose: */ +/* Handle NOOP command packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 CI_LAB_Noop(const CI_LAB_Noop_t *data) +{ + /* Does everything the name implies */ + CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandCounter++; + + CFE_EVS_SendEvent(CI_LAB_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command"); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Name: CI_LAB_ResetCounters */ +/* */ +/* Purpose: */ +/* Handle ResetCounters command packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 CI_LAB_ResetCounters(const CI_LAB_ResetCounters_t *data) +{ + CFE_EVS_SendEvent(CI_LAB_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: RESET command"); + CI_LAB_ResetCounters_Internal(); + return CFE_SUCCESS; +} /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: CI_ReportHousekeeping */ +/* Name: CI_LAB_ReportHousekeeping */ /* */ /* Purpose: */ /* This function is triggered in response to a task telemetry request */ @@ -291,494 +315,82 @@ void CI_ProcessGroundCommand(void) /* telemetry, packetize it and send it to the housekeeping task via */ /* the software bus */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void CI_ReportHousekeeping(void) +int32 CI_LAB_ReportHousekeeping(const CCSDS_CommandPacket_t *data) { - CI_HkTelemetryPkt.SocketConnected = CI_SocketConnected; - CFE_SB_TimeStampMsg((CFE_SB_Msg_t *)&CI_HkTelemetryPkt); - CFE_SB_SendMsg((CFE_SB_Msg_t *)&CI_HkTelemetryPkt); - return; + CI_LAB_Global.HkBuffer.HkTlm.Payload.SocketConnected = CI_LAB_Global.SocketConnected; + CFE_SB_TimeStampMsg(&CI_LAB_Global.HkBuffer.MsgHdr); + CFE_SB_SendMsg(&CI_LAB_Global.HkBuffer.MsgHdr); + return CFE_SUCCESS; -} /* End of CI_ReportHousekeeping() */ +} /* End of CI_LAB_ReportHousekeeping() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: CI_ResetCounters */ +/* Name: CI_LAB_ResetCounters_Internal */ /* */ /* Purpose: */ /* This function resets all the global counter variables that are */ /* part of the task telemetry. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void CI_ResetCounters(void) +void CI_LAB_ResetCounters_Internal(void) { /* Status of commands processed by CI task */ - CI_HkTelemetryPkt.ci_command_count = 0; - CI_HkTelemetryPkt.ci_command_error_count = 0; - - /* Status of packets ingested by CI task */ - CI_HkTelemetryPkt.IngestPackets = 0; - CI_HkTelemetryPkt.IngestErrors = 0; + CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandCounter = 0; + CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter = 0; /* Status of packets ingested by CI task */ - CI_HkTelemetryPkt.FDPdusDropped = 0; - CI_HkTelemetryPkt.EOFPdusDropped = 0; - CI_HkTelemetryPkt.FINPdusDropped = 0; - CI_HkTelemetryPkt.ACKPdusDropped = 0; - CI_HkTelemetryPkt.MDPdusDropped = 0; - CI_HkTelemetryPkt.NAKPdusDropped = 0; - CI_HkTelemetryPkt.PDUsCaptured = 0; - - CFE_EVS_SendEvent(CI_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: RESET command"); - return; - -} /* End of CI_ResetCounters() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_ModifyFileSizeCmd() -- task ground command () */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_ModifyFileSizeCmd(CFE_SB_MsgPtr_t msg) -{ - uint16 ExpectedLength = sizeof(CI_ModifyFileSizeCmd_t); - CI_ModifyFileSizeCmd_t *CmdPtr; - - /* - ** Verify command packet length... - */ - if (CI_VerifyCmdLength(msg, ExpectedLength)) - { - CmdPtr = ((CI_ModifyFileSizeCmd_t *)msg); - - /* Get the direction to modify */ - if (CmdPtr->Direction == PDU_SIZE_ADD) - PDUFileSizeAdjustment = CmdPtr->Amount; - else - PDUFileSizeAdjustment = 0 - CmdPtr->Amount; - - /* Set the flag to modify File Size */ - adjustFileSize = true; - - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_MOD_PDU_FILESIZE_CMD_EID, CFE_EVS_EventType_DEBUG, "CI: Modify PDU File Size\n"); - } - - return; - -} /* End of CI_ModifyFileSizeCmd() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_CorruptChecksumCmd() -- task ground command () */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_CorruptChecksumCmd(CFE_SB_MsgPtr_t msg) -{ - uint16 ExpectedLength = sizeof(CI_NoArgsCmd_t); - - /* - ** Verify command packet length... - */ - if (CI_VerifyCmdLength(msg, ExpectedLength)) - { - /* Set the flag to modify File Size */ - corruptChecksum = true; - - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_CORRUPT_CHECKSUM_CMD_EID, CFE_EVS_EventType_DEBUG, "CI: Corrupt PDU Checksum\n"); - } - - return; - -} /* End of CI_CorruptChecksumCmd() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_DropPDUCmd() -- task ground command () */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_DropPDUCmd(CFE_SB_MsgPtr_t msg) -{ - uint16 ExpectedLength = sizeof(CI_DropPDUCmd_t); - CI_DropPDUCmd_t *CmdPtr; - - /* - ** Verify command packet length... - */ - if (CI_VerifyCmdLength(msg, ExpectedLength)) - { - CmdPtr = ((CI_DropPDUCmd_t *)msg); - - /* Get the PDU Type */ - if (CmdPtr->PDUType == FILE_DATA_PDU) - { - dropFileData = true; - dropFileDataCnt = CmdPtr->PDUsToDrop; - } - else if (CmdPtr->PDUType == EOF_PDU) - { - dropEOF = true; - dropEOFCnt = CmdPtr->PDUsToDrop; - } - else if (CmdPtr->PDUType == FIN_PDU) - { - dropFIN = true; - dropFINCnt = CmdPtr->PDUsToDrop; - } - else if (CmdPtr->PDUType == ACK_PDU) - { - dropACK = true; - dropACKCnt = CmdPtr->PDUsToDrop; - } - else if (CmdPtr->PDUType == META_DATA_PDU) - { - dropMetaData = true; - dropMetaDataCnt = CmdPtr->PDUsToDrop; - } - else if (CmdPtr->PDUType == NAK_PDU) - { - dropNAK = true; - dropNAKCnt = CmdPtr->PDUsToDrop; - } - - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_DROP_PDU_CMD_EID, CFE_EVS_EventType_DEBUG, "CI: Drop PDU\n"); - } + CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestPackets = 0; + CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestErrors = 0; return; -} /* End of CI_DropPDUCmd() */ +} /* End of CI_LAB_ResetCounters() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ -/* CI_CapturePDUsCmd() -- task ground command () */ +/* CI_LAB_ReadUpLink() -- */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_CapturePDUsCmd(CFE_SB_MsgPtr_t msg) +void CI_LAB_ReadUpLink(void) { - uint16 ExpectedLength = sizeof(CI_CapturePDUCmd_t); - CI_CapturePDUCmd_t *CmdPtr; - - /* - ** Verify command packet length... - */ - if (CI_VerifyCmdLength(msg, ExpectedLength)) - { - CmdPtr = ((CI_CapturePDUCmd_t *)msg); - - if (CmdPtr->PDUMsgID <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID) - { - /* Save the messageID in a global variable */ - PDUMessageID = CmdPtr->PDUMsgID; - - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_CAPTUREPDU_CMD_EID, CFE_EVS_EventType_DEBUG, - "CI: PDU Capture initialized for 0x%04X\n", CmdPtr->PDUMsgID); - } - else - { - CI_HkTelemetryPkt.ci_command_error_count++; - CFE_EVS_SendEvent(CI_INVALID_MSGID_ERR_EID, CFE_EVS_EventType_ERROR, "CI: Invalid PDU MsgID: 0x%04x\n", - CmdPtr->PDUMsgID); - } - } - - return; - -} /* End of CI_CapturePDUsCmd() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_StopPDUCaptureCmd() -- task ground command () */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_StopPDUCaptureCmd(CFE_SB_MsgPtr_t msg) -{ - uint16 ExpectedLength = sizeof(CI_NoArgsCmd_t); - - /* - ** Verify command packet length... - */ - if (CI_VerifyCmdLength(msg, ExpectedLength)) - { - if (PDUMessageID != 0) - { - CI_HkTelemetryPkt.ci_command_count++; - CFE_EVS_SendEvent(CI_STOP_PDUCAPTURE_CMD_EID, CFE_EVS_EventType_DEBUG, - "CI: PDU Capture stopped for 0x%04X\n", PDUMessageID); - - /* Set the global data back to there initial values */ - PDUMessageID = 0; - adjustFileSize = false; - PDUFileSizeAdjustment = 0; - dropFileData = false; - dropFileDataCnt = 0; - dropEOF = false; - dropEOFCnt = 0; - dropFIN = false; - dropFINCnt = 0; - dropACK = false; - dropACKCnt = 0; - dropMetaData = false; - dropMetaDataCnt = 0; - dropNAK = false; - dropNAKCnt = 0; - corruptChecksum = false; - } - else - { - CI_HkTelemetryPkt.ci_command_error_count++; - CFE_EVS_SendEvent(CI_NOCAPTURE_ERR_EID, CFE_EVS_EventType_ERROR, "CI: PDU Capture is not enabled\n"); - } - } - - return; - -} /* End of CI_StopPDUCaptureCmd() */ + int i; + int32 status; -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_ProcessPDU() -- */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_ProcessPDU(void) -{ - CF_PDU_Hdr_t * PduHdrPtr; - uint8 * PduDataPtr; - uint8 * IncomingPduPtr; - uint8 PduData0; - uint8 EntityIdBytes, TransSeqBytes, PduHdrBytes; - CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(CI_IngestPointer); - bool sendToSB = false; - uint32 * checkSumPtr; - uint32 * fileSizePtr; - - if (MessageID == PDUMessageID) + for (i = 0; i <= 10; i++) { - IncomingPduPtr = ((uint8 *)CI_IngestPointer); - if (CFE_TST(MessageID, 12) != 0) + status = OS_SocketRecvFrom(CI_LAB_Global.SocketID, CI_LAB_Global.IngestBuffer.bytes, + sizeof(CI_LAB_Global.IngestBuffer), &CI_LAB_Global.SocketAddress, OS_CHECK); + if (status >= ((int32)CFE_SB_CMD_HDR_SIZE) && status <= ((int32)CI_LAB_MAX_INGEST)) { - IncomingPduPtr += CFE_SB_CMD_HDR_SIZE; + CFE_ES_PerfLogEntry(CI_LAB_SOCKET_RCV_PERF_ID); + CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestPackets++; + status = CFE_SB_SendMsg(&CI_LAB_Global.IngestBuffer.MsgHdr); + CFE_ES_PerfLogExit(CI_LAB_SOCKET_RCV_PERF_ID); } - else + else if (status > 0) { - IncomingPduPtr += CFE_SB_TLM_HDR_SIZE; - } - - PduHdrPtr = (CF_PDU_Hdr_t *)IncomingPduPtr; - - /* calculate size of incoming pdu to ensure we don't overflow the buf */ - EntityIdBytes = ((PduHdrPtr->Octet4 >> 4) & 0x07) + 1; - TransSeqBytes = (PduHdrPtr->Octet4 & 0x07) + 1; - PduHdrBytes = 4 + (EntityIdBytes * 2) + TransSeqBytes; - - /* OS_printf("CI: Captured PDU with length = %d\n",PduHdrPtr->PDataLen); */ - - CI_HkTelemetryPkt.PDUsCaptured++; - - /* Check if a File Data PDU was rcv'd */ - if (CFE_TST(PduHdrPtr->Octet1, 4)) - { - OS_printf("CI: File Data PDU rcv'd\n"); - if ((dropFileData == true) && (dropFileDataCnt > 0)) - { - dropFileDataCnt--; - OS_printf("CI: File Data PDU dropped\n"); - CI_HkTelemetryPkt.FDPdusDropped++; - } - else - { - sendToSB = true; - dropFileData = false; - } + /* bad size, report as ingest error */ + CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestErrors++; + CFE_EVS_SendEvent(CI_LAB_INGEST_ERR_EID, CFE_EVS_EventType_ERROR, + "CI: L%d, cmd %0x %0x dropped, bad length=%d\n", __LINE__, + CI_LAB_Global.IngestBuffer.hwords[0], CI_LAB_Global.IngestBuffer.hwords[1], (int)status); } else { - /* Not a File Data PDU */ - PduDataPtr = (uint8 *)PduHdrPtr + PduHdrBytes; - PduData0 = *PduDataPtr; - - OS_printf("CI: PDU Data Type = %d\n", PduData0); - switch (PduData0) - { - case 4: - OS_printf("CI: EOF PDU rcv'd\n"); - if ((dropEOF == true) && (dropEOFCnt > 0)) - { - dropEOFCnt--; - OS_printf("CI: EOF PDU dropped\n"); - CI_HkTelemetryPkt.EOFPdusDropped++; - } - else - { - sendToSB = true; - dropEOF = false; - } - - PduDataPtr += 2; - checkSumPtr = (uint32 *)PduDataPtr; - fileSizePtr = checkSumPtr + 1; - - if (corruptChecksum == true) - { - OS_printf("CI: good checksum = %x\n", (unsigned int)*checkSumPtr); - /* Corrupt the checksum */ - *checkSumPtr = 0x12345678; - OS_printf("CI: corrupted checksum = %x\n", (unsigned int)*checkSumPtr); - corruptChecksum = false; - } - - if (adjustFileSize == true) - { - OS_printf("CI: good file size = %d\n", (int)*fileSizePtr); - /* Adjust the file size */ - *fileSizePtr += PDUFileSizeAdjustment; - OS_printf("CI: adjusted file size = %d\n", (int)*fileSizePtr); - adjustFileSize = false; - } - - break; - - case 5: - OS_printf("CI: FIN PDU rcv'd\n"); - if ((dropFIN == true) && (dropFINCnt > 0)) - { - dropFINCnt--; - OS_printf("CI: FIN PDU dropped\n"); - CI_HkTelemetryPkt.FINPdusDropped++; - } - else - { - sendToSB = true; - dropFIN = false; - } - - break; - - case 6: - OS_printf("CI: ACK PDU rcv'd\n"); - if ((dropACK == true) && (dropACKCnt > 0)) - { - dropACKCnt--; - OS_printf("CI: ACK PDU dropped\n"); - CI_HkTelemetryPkt.ACKPdusDropped++; - } - else - { - sendToSB = true; - dropACK = false; - } - - break; - - case 7: - OS_printf("CI: Meta Data PDU rcv'd\n"); - if ((dropMetaData == true) && (dropMetaDataCnt > 0)) - { - dropMetaDataCnt--; - OS_printf("CI: Meta Data PDU dropped\n"); - CI_HkTelemetryPkt.MDPdusDropped++; - } - else - { - sendToSB = true; - dropMetaData = false; - } - - break; - - case 8: - OS_printf("CI: NAK PDU rcv'd\n"); - if ((dropNAK == true) && (dropNAKCnt > 0)) - { - dropNAKCnt--; - OS_printf("CI: NAK PDU dropped\n"); - CI_HkTelemetryPkt.NAKPdusDropped++; - } - else - { - sendToSB = true; - dropNAK = false; - } - - break; - - default: - break; - } - } - } - else - { - sendToSB = true; - } - - if (sendToSB == true) - { - CFE_ES_PerfLogEntry(CI_SOCKET_RCV_PERF_ID); - CI_HkTelemetryPkt.IngestPackets++; - CFE_SB_SendMsg(CI_IngestPointer); - CFE_ES_PerfLogExit(CI_SOCKET_RCV_PERF_ID); - } - - return; - -} /* End of CI_ProcessPDU() */ - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI_ReadUpLink() -- */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_ReadUpLink(void) -{ - socklen_t addr_len; - int i; - int status; - - addr_len = sizeof(CI_SocketAddress); - - memset(&CI_SocketAddress, 0, sizeof(CI_SocketAddress)); - - for (i = 0; i <= 10; i++) - { - status = recvfrom(CI_SocketID, (char *)&CI_IngestBuffer[0], sizeof(CI_IngestBuffer), MSG_DONTWAIT, - (struct sockaddr *)&CI_SocketAddress, &addr_len); - - if ((status < 0) && (errno == EWOULDBLOCK)) break; /* no (more) messages */ - else - { - if (status <= CI_MAX_INGEST) - { - if (PDUMessageID != 0) - { - CI_ProcessPDU(); - } - else - { - CFE_ES_PerfLogEntry(CI_SOCKET_RCV_PERF_ID); - CI_HkTelemetryPkt.IngestPackets++; - CFE_SB_SendMsg(CI_IngestPointer); - CFE_ES_PerfLogExit(CI_SOCKET_RCV_PERF_ID); - } - } - else - { - CI_HkTelemetryPkt.IngestErrors++; - } } } return; -} /* End of CI_ReadUpLink() */ +} /* End of CI_LAB_ReadUpLink() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ -/* CI_VerifyCmdLength() -- Verify command packet length */ +/* CI_LAB_VerifyCmdLength() -- Verify command packet length */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -bool CI_VerifyCmdLength(CFE_SB_MsgPtr_t msg, uint16 ExpectedLength) +bool CI_LAB_VerifyCmdLength(CFE_SB_MsgPtr_t msg, uint16 ExpectedLength) { bool result = true; uint16 ActualLength = CFE_SB_GetTotalMsgLength(msg); @@ -791,13 +403,13 @@ bool CI_VerifyCmdLength(CFE_SB_MsgPtr_t msg, uint16 ExpectedLength) CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(msg); uint16 CommandCode = CFE_SB_GetCmdCode(msg); - CFE_EVS_SendEvent(CI_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(CI_LAB_LEN_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d", MessageID, CommandCode, ActualLength, ExpectedLength); result = false; - CI_HkTelemetryPkt.ci_command_error_count++; + CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter++; } return (result); -} /* End of CI_VerifyCmdLength() */ +} /* End of CI_LAB_VerifyCmdLength() */ diff --git a/fsw/src/ci_lab_app.h b/fsw/src/ci_lab_app.h index 6638fcd..8c169c2 100644 --- a/fsw/src/ci_lab_app.h +++ b/fsw/src/ci_lab_app.h @@ -31,7 +31,6 @@ /* ** Required header files... */ -#include "network_includes.h" #include "common_types.h" #include "cfe_error.h" #include "cfe_evs.h" @@ -47,45 +46,28 @@ /****************************************************************************/ -#define cfgCI_PORT 1234 -#define CI_MAX_INGEST 768 -#define CI_PIPE_DEPTH 32 +#define cfgCI_LAB_PORT 1234 +#define CI_LAB_MAX_INGEST 768 +#define CI_LAB_PIPE_DEPTH 32 /************************************************************************ ** Type Definitions *************************************************************************/ -typedef struct -{ - uint8 Octet1; - uint16 PDataLen; - uint8 Octet4; - uint16 SrcEntityId; - uint32 TransSeqNum; - uint16 DstEntityId; - -} OS_PACK CF_PDU_Hdr_t; /****************************************************************************/ /* ** Local function prototypes... ** -** Note: Except for the entry point (CI_task_main), these +** Note: Except for the entry point (CI_LAB_AppMain), these ** functions are not called from any other source module. */ -void CI_task_main(void); -void CI_TaskInit(void); -void CI_ProcessCommandPacket(void); -void CI_ProcessGroundCommand(void); -void CI_ReportHousekeeping(void); -void CI_ResetCounters(void); -void CI_ModifyFileSizeCmd(CFE_SB_MsgPtr_t msg); -void CI_CorruptChecksumCmd(CFE_SB_MsgPtr_t msg); -void CI_DropPDUCmd(CFE_SB_MsgPtr_t msg); -void CI_CapturePDUsCmd(CFE_SB_MsgPtr_t msg); -void CI_StopPDUCaptureCmd(CFE_SB_MsgPtr_t msg); -void CI_ProcessPDU(void); -void CI_ReadUpLink(void); +void CI_Lab_AppMain(void); +void CI_LAB_TaskInit(void); +void CI_LAB_ProcessCommandPacket(void); +void CI_LAB_ProcessGroundCommand(void); +void CI_LAB_ResetCounters_Internal(void); +void CI_LAB_ReadUpLink(void); -bool CI_VerifyCmdLength(CFE_SB_MsgPtr_t msg, uint16 ExpectedLength); +bool CI_LAB_VerifyCmdLength(CFE_SB_MsgPtr_t msg, uint16 ExpectedLength); #endif /* _ci_lab_app_h_ */ diff --git a/fsw/src/ci_lab_defs.h b/fsw/src/ci_lab_defs.h deleted file mode 100644 index 155b612..0000000 --- a/fsw/src/ci_lab_defs.h +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* -** -** GSC-18128-1, "Core Flight Executive Version 6.7" -** -** Copyright (c) 2006-2019 United States Government as represented by -** the Administrator of the National Aeronautics and Space Administration. -** All Rights Reserved. -** -** Licensed under the Apache License, Version 2.0 (the "License"); -** you may not use this file except in compliance with the License. -** You may obtain a copy of the License at -** -** http://www.apache.org/licenses/LICENSE-2.0 -** -** Unless required by applicable law or agreed to in writing, software -** distributed under the License is distributed on an "AS IS" BASIS, -** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -** See the License for the specific language governing permissions and -** limitations under the License. -** -** File: ci_lab_defs.h -** -** Purpose: -** Define CI Lab Definitions that other apps may need to use -** -** Notes: -** -*******************************************************************************/ -#ifndef _ci_lab_defs_h_ -#define _ci_lab_defs_h_ - -/* -** Definitions -*/ -/* File Size Command argument values */ -#define PDU_SIZE_ADD 0 -#define PDU_SIZE_SUBTRACT 1 - -/* PDU Type argument values */ -#define FILE_DATA_PDU 0 -#define EOF_PDU 1 -#define FIN_PDU 2 -#define ACK_PDU 3 -#define META_DATA_PDU 4 -#define NAK_PDU 5 - -#endif /* _ci_lab_defs_h_ */ - -/************************/ -/* End of File Comment */ -/************************/ diff --git a/fsw/src/ci_lab_events.h b/fsw/src/ci_lab_events.h index d75fee1..bb57812 100644 --- a/fsw/src/ci_lab_events.h +++ b/fsw/src/ci_lab_events.h @@ -29,23 +29,16 @@ #ifndef _ci_lab_events_h_ #define _ci_lab_events_h_ -#define CI_RESERVED_EID 0 -#define CI_SOCKETCREATE_ERR_EID 1 -#define CI_SOCKETBIND_ERR_EID 2 -#define CI_STARTUP_INF_EID 3 -#define CI_COMMAND_ERR_EID 4 -#define CI_COMMANDNOP_INF_EID 5 -#define CI_COMMANDRST_INF_EID 6 -#define CI_INGEST_INF_EID 7 -#define CI_INGEST_ERR_EID 8 -#define CI_MOD_PDU_FILESIZE_CMD_EID 9 -#define CI_CORRUPT_CHECKSUM_CMD_EID 10 -#define CI_DROP_PDU_CMD_EID 11 -#define CI_CAPTUREPDU_CMD_EID 12 -#define CI_INVALID_MSGID_ERR_EID 13 -#define CI_STOP_PDUCAPTURE_CMD_EID 14 -#define CI_NOCAPTURE_ERR_EID 15 -#define CI_LEN_ERR_EID 16 +#define CI_LAB_RESERVED_EID 0 +#define CI_LAB_SOCKETCREATE_ERR_EID 1 +#define CI_LAB_SOCKETBIND_ERR_EID 2 +#define CI_LAB_STARTUP_INF_EID 3 +#define CI_LAB_COMMAND_ERR_EID 4 +#define CI_LAB_COMMANDNOP_INF_EID 5 +#define CI_LAB_COMMANDRST_INF_EID 6 +#define CI_LAB_INGEST_INF_EID 7 +#define CI_LAB_INGEST_ERR_EID 8 +#define CI_LAB_LEN_ERR_EID 16 #endif /* _ci_lab_events_h_ */ diff --git a/fsw/src/ci_lab_msg.h b/fsw/src/ci_lab_msg.h index e9c19fd..971a7ff 100644 --- a/fsw/src/ci_lab_msg.h +++ b/fsw/src/ci_lab_msg.h @@ -30,15 +30,10 @@ #define _ci_lab_msg_h_ /* -** CI_Lab command codes +** CI_LAB_Lab command codes */ -#define CI_NOOP_CC 0 -#define CI_RESET_COUNTERS_CC 1 -#define CI_MODIFY_PDU_FILESIZE_CC 2 -#define CI_CORRUPT_PDU_CHECKSUM_CC 3 -#define CI_DROP_PDUS_CC 4 -#define CI_CAPTURE_PDUS_CC 5 -#define CI_STOP_PDU_CAPTURE_CC 6 +#define CI_LAB_NOOP_CC 0 +#define CI_LAB_RESET_COUNTERS_CC 1 /*************************************************************************/ /* @@ -48,66 +43,42 @@ typedef struct { uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE]; -} CI_NoArgsCmd_t; +} CI_LAB_NoArgsCmd_t; /* -** Type definition (Capture PDUs command structure) -*/ -typedef struct -{ - uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE]; - CFE_SB_MsgId_t PDUMsgID; /* Message ID of the downlinked PDUs to capture */ - -} CI_CapturePDUCmd_t; - -/* -** Type definition (Modify PDU file size command structure) -*/ -typedef struct -{ - uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE]; - uint16 Direction; /* Add or Subtract */ - uint16 Amount; /* The value to add or subtract from the file size*/ - -} CI_ModifyFileSizeCmd_t; - -/* -** Type definition (Drop PDU command structure) -*/ -typedef struct -{ - uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE]; - uint8 PDUType; /* The Type of PDU to capture and drop */ - uint8 PDUsToDrop; /* The # of rcvd PDUs of the type to drop */ - -} CI_DropPDUCmd_t; + * Neither the Noop nor ResetCounters command + * have any payload, but should still "reserve" a unique + * structure type to employ a consistent handler pattern. + * + * This matches the pattern in CFE core and other modules. + */ +typedef CI_LAB_NoArgsCmd_t CI_LAB_Noop_t; +typedef CI_LAB_NoArgsCmd_t CI_LAB_ResetCounters_t; /*************************************************************************/ /* -** Type definition (CI_Lab housekeeping)... +** Type definition (CI_LAB_Lab housekeeping)... */ typedef struct { - - uint8 TlmHeader[CFE_SB_TLM_HDR_SIZE]; - uint8 ci_command_error_count; - uint8 ci_command_count; - uint8 ci_xsums_enabled; + uint8 CommandErrorCounter; + uint8 CommandCounter; + uint8 EnableChecksums; uint8 SocketConnected; - uint8 FDPdusDropped; - uint8 EOFPdusDropped; - uint8 FINPdusDropped; - uint8 ACKPdusDropped; - uint8 MDPdusDropped; - uint8 NAKPdusDropped; - uint8 spare[2]; + uint8 Spare1[8]; uint32 IngestPackets; uint32 IngestErrors; - uint32 PDUsCaptured; + uint32 Spare2; + +} CI_LAB_HkTlm_Payload_t; -} OS_PACK ci_hk_tlm_t; +typedef struct +{ + uint8 TlmHeader[CFE_SB_TLM_HDR_SIZE]; + CI_LAB_HkTlm_Payload_t Payload; +} OS_PACK CI_LAB_HkTlm_t; -#define CI_LAB_HK_TLM_LNGTH sizeof(ci_hk_tlm_t) +#define CI_LAB_HK_TLM_LNGTH sizeof(CI_LAB_HkTlm_t) #endif /* _ci_lab_msg_h_ */