Skip to content

Commit

Permalink
Merge pull request #65 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
ci_lab Integration Candidate: 2020-12-08
  • Loading branch information
astrogeco authored Dec 9, 2020
2 parents aa805af + 5a7e2b4 commit adc0edb
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 62 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ ci_lab is a simple command uplink application that accepts CCSDS telecommand pac

## Version History

### Development Build: 2.4.0-rc1+dev14

- Aligns messages according to changes in cFE <https://github.com/nasa/cFE/issues/1009>. Uses the "raw" message cmd/tlm types in definition
- See <https://github.com/nasa/ci_lab/pull/65>

### Development Build: 2.4.0-rc1+dev8

- Replaces deprecated SB API's with MSG
Expand Down
104 changes: 53 additions & 51 deletions fsw/src/ci_lab_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,18 @@
*/
typedef union
{
CFE_MSG_Message_t MsgHdr;
CFE_MSG_Message_t Msg;
uint8 bytes[CI_LAB_MAX_INGEST];
uint16 hwords[2];
} CI_LAB_IngestBuffer_t;

typedef union
{
CFE_MSG_Message_t MsgHdr;
CI_LAB_HkTlm_t HkTlm;
} CI_LAB_HkTlm_Buffer_t;

typedef struct
{
bool SocketConnected;
CFE_SB_PipeId_t CommandPipe;
CFE_MSG_Message_t *MsgPtr;
osal_id_t SocketID;
OS_SockAddr_t SocketAddress;
bool SocketConnected;
CFE_SB_PipeId_t CommandPipe;
osal_id_t SocketID;
OS_SockAddr_t SocketAddress;

CI_LAB_HkTlm_Buffer_t HkBuffer;
CI_LAB_HkTlm_t HkTlm;
CI_LAB_IngestBuffer_t IngestBuffer;
} CI_LAB_GlobalData_t;

Expand All @@ -85,9 +77,11 @@ static CFE_EVS_BinFilter_t CI_LAB_EventFilters[] =
* 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 CFE_SB_CmdHdr_t *data);
int32 CI_LAB_Noop(const CI_LAB_NoopCmd_t *data);
int32 CI_LAB_ResetCounters(const CI_LAB_ResetCountersCmd_t *data);

/* Housekeeping message handler */
int32 CI_LAB_ReportHousekeeping(const CFE_MSG_CommandHeader_t *data);

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* CI_Lab_AppMain() -- Application entry point and main process loop */
Expand All @@ -101,8 +95,9 @@ int32 CI_LAB_ReportHousekeeping(const CFE_SB_CmdHdr_t *data);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void CI_Lab_AppMain(void)
{
int32 status;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
int32 status;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
CFE_SB_Buffer_t *SBBufPtr;

CFE_ES_PerfLogEntry(CI_LAB_MAIN_TASK_PERF_ID);

Expand All @@ -116,13 +111,13 @@ void CI_Lab_AppMain(void)
CFE_ES_PerfLogExit(CI_LAB_MAIN_TASK_PERF_ID);

/* Pend on receipt of command packet -- timeout set to 500 millisecs */
status = CFE_SB_RcvMsg(&CI_LAB_Global.MsgPtr, CI_LAB_Global.CommandPipe, 500);
status = CFE_SB_ReceiveBuffer(&SBBufPtr, CI_LAB_Global.CommandPipe, 500);

CFE_ES_PerfLogEntry(CI_LAB_MAIN_TASK_PERF_ID);

if (status == CFE_SUCCESS)
{
CI_LAB_ProcessCommandPacket();
CI_LAB_ProcessCommandPacket(SBBufPtr);
}

/* Regardless of packet vs timeout, always process uplink queue */
Expand Down Expand Up @@ -201,7 +196,7 @@ void CI_LAB_TaskInit(void)
*/
OS_TaskInstallDeleteHandler(&CI_LAB_delete_callback);

CFE_MSG_Init(&CI_LAB_Global.HkBuffer.HkTlm.TlmHeader.BaseMsg, CI_LAB_HK_TLM_MID, CI_LAB_HK_TLM_LNGTH);
CFE_MSG_Init(&CI_LAB_Global.HkTlm.TlmHeader.Msg, CI_LAB_HK_TLM_MID, sizeof(CI_LAB_Global.HkTlm));

CFE_EVS_SendEvent(CI_LAB_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI Lab Initialized.%s",
CI_LAB_VERSION_STRING);
Expand All @@ -220,24 +215,24 @@ void CI_LAB_TaskInit(void)
/* 3. Request for housekeeping telemetry packet (from HS task) */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CI_LAB_ProcessCommandPacket(void)
void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetMsgId(CI_LAB_Global.MsgPtr, &MsgId);
CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId);

switch (CFE_SB_MsgIdToValue(MsgId))
{
case CI_LAB_CMD_MID:
CI_LAB_ProcessGroundCommand();
CI_LAB_ProcessGroundCommand(SBBufPtr);
break;

case CI_LAB_SEND_HK_MID:
CI_LAB_ReportHousekeeping((const CFE_SB_CmdHdr_t *)CI_LAB_Global.MsgPtr);
CI_LAB_ReportHousekeeping((const CFE_MSG_CommandHeader_t *)SBBufPtr);
break;

default:
CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter++;
CI_LAB_Global.HkTlm.Payload.CommandErrorCounter++;
CFE_EVS_SendEvent(CI_LAB_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
break;
Expand All @@ -253,21 +248,27 @@ void CI_LAB_ProcessCommandPacket(void)
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/

void CI_LAB_ProcessGroundCommand(void)
void CI_LAB_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(CI_LAB_Global.MsgPtr, &CommandCode);
CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);

/* Process "known" CI task ground commands */
switch (CommandCode)
{
case CI_LAB_NOOP_CC:
CI_LAB_Noop((const CI_LAB_Noop_t *)CI_LAB_Global.MsgPtr);
if (CI_LAB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CI_LAB_NoopCmd_t)))
{
CI_LAB_Noop((const CI_LAB_NoopCmd_t *)SBBufPtr);
}
break;

case CI_LAB_RESET_COUNTERS_CC:
CI_LAB_ResetCounters((const CI_LAB_ResetCounters_t *)CI_LAB_Global.MsgPtr);
if (CI_LAB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CI_LAB_ResetCountersCmd_t)))
{
CI_LAB_ResetCounters((const CI_LAB_ResetCountersCmd_t *)SBBufPtr);
}
break;

/* default case already found during FC vs length test */
Expand All @@ -286,10 +287,10 @@ void CI_LAB_ProcessGroundCommand(void)
/* Handle NOOP command packets */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CI_LAB_Noop(const CI_LAB_Noop_t *data)
int32 CI_LAB_Noop(const CI_LAB_NoopCmd_t *data)
{
/* Does everything the name implies */
CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandCounter++;
CI_LAB_Global.HkTlm.Payload.CommandCounter++;

CFE_EVS_SendEvent(CI_LAB_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command");

Expand All @@ -303,7 +304,7 @@ int32 CI_LAB_Noop(const CI_LAB_Noop_t *data)
/* Handle ResetCounters command packets */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CI_LAB_ResetCounters(const CI_LAB_ResetCounters_t *data)
int32 CI_LAB_ResetCounters(const CI_LAB_ResetCountersCmd_t *data)
{
CFE_EVS_SendEvent(CI_LAB_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: RESET command");
CI_LAB_ResetCounters_Internal();
Expand All @@ -319,11 +320,11 @@ int32 CI_LAB_ResetCounters(const CI_LAB_ResetCounters_t *data)
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CI_LAB_ReportHousekeeping(const CFE_SB_CmdHdr_t *data)
int32 CI_LAB_ReportHousekeeping(const CFE_MSG_CommandHeader_t *data)
{
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);
CI_LAB_Global.HkTlm.Payload.SocketConnected = CI_LAB_Global.SocketConnected;
CFE_SB_TimeStampMsg(&CI_LAB_Global.HkTlm.TlmHeader.Msg);
CFE_SB_TransmitMsg(&CI_LAB_Global.HkTlm.TlmHeader.Msg, true);
return CFE_SUCCESS;

} /* End of CI_LAB_ReportHousekeeping() */
Expand All @@ -339,12 +340,12 @@ int32 CI_LAB_ReportHousekeeping(const CFE_SB_CmdHdr_t *data)
void CI_LAB_ResetCounters_Internal(void)
{
/* Status of commands processed by CI task */
CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandCounter = 0;
CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter = 0;
CI_LAB_Global.HkTlm.Payload.CommandCounter = 0;
CI_LAB_Global.HkTlm.Payload.CommandErrorCounter = 0;

/* Status of packets ingested by CI task */
CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestPackets = 0;
CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestErrors = 0;
CI_LAB_Global.HkTlm.Payload.IngestPackets = 0;
CI_LAB_Global.HkTlm.Payload.IngestErrors = 0;

return;

Expand All @@ -364,20 +365,21 @@ void CI_LAB_ReadUpLink(void)
{
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))
if (status >= (int32)sizeof(CFE_MSG_CommandHeader_t) && status <= ((int32)CI_LAB_MAX_INGEST))
{
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);
CI_LAB_Global.HkTlm.Payload.IngestPackets++;
status = CFE_SB_TransmitMsg(&CI_LAB_Global.IngestBuffer.Msg, false);
CFE_ES_PerfLogExit(CI_LAB_SOCKET_RCV_PERF_ID);
}
else if (status > 0)
{
/* bad size, report as ingest error */
CI_LAB_Global.HkBuffer.HkTlm.Payload.IngestErrors++;
CI_LAB_Global.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);
"CI: L%d, cmd %0x%0x %0x%0x dropped, bad length=%d\n", __LINE__,
CI_LAB_Global.IngestBuffer.bytes[0], CI_LAB_Global.IngestBuffer.bytes[1],
CI_LAB_Global.IngestBuffer.bytes[2], CI_LAB_Global.IngestBuffer.bytes[3], (int)status);
}
else
{
Expand All @@ -394,10 +396,10 @@ void CI_LAB_ReadUpLink(void)
/* CI_LAB_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

Expand All @@ -416,7 +418,7 @@ bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLe
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength,
(unsigned int)ExpectedLength);
result = false;
CI_LAB_Global.HkBuffer.HkTlm.Payload.CommandErrorCounter++;
CI_LAB_Global.HkTlm.Payload.CommandErrorCounter++;
}

return (result);
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/ci_lab_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
*/
void CI_Lab_AppMain(void);
void CI_LAB_TaskInit(void);
void CI_LAB_ProcessCommandPacket(void);
void CI_LAB_ProcessGroundCommand(void);
void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr);
void CI_LAB_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr);
void CI_LAB_ResetCounters_Internal(void);
void CI_LAB_ReadUpLink(void);

bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);
bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);

#endif /* _ci_lab_app_h_ */
12 changes: 5 additions & 7 deletions fsw/src/ci_lab_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
typedef struct
{
uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE];
CFE_MSG_CommandHeader_t CmdHeader;

} CI_LAB_NoArgsCmd_t;

Expand All @@ -52,8 +52,8 @@ typedef struct
*
* 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;
typedef CI_LAB_NoArgsCmd_t CI_LAB_NoopCmd_t;
typedef CI_LAB_NoArgsCmd_t CI_LAB_ResetCountersCmd_t;

/*************************************************************************/
/*
Expand All @@ -74,12 +74,10 @@ typedef struct

typedef struct
{
CFE_SB_TlmHdr_t TlmHeader;
CI_LAB_HkTlm_Payload_t Payload;
CFE_MSG_TelemetryHeader_t TlmHeader;
CI_LAB_HkTlm_Payload_t Payload;
} CI_LAB_HkTlm_t;

#define CI_LAB_HK_TLM_LNGTH sizeof(CI_LAB_HkTlm_t)

#endif /* _ci_lab_msg_h_ */

/************************/
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/ci_lab_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/* Development Build Macro Definitions */

#define CI_LAB_BUILD_NUMBER 8 /*!< Development Build: Number of commits since baseline */
#define CI_LAB_BUILD_NUMBER 14 /*!< Development Build: Number of commits since baseline */
#define CI_LAB_BUILD_BASELINE \
"v2.4.0-rc1" /*!< Development Build: git tag that is the base for the current development */

Expand Down

0 comments on commit adc0edb

Please sign in to comment.