Branch data Line data Source code
1 : : /************************************************************************ 2 : : * NASA Docket No. GSC-18,919-1, and identified as “Core Flight 3 : : * System (cFS) Housekeeping (HK) Application version 2.5.1” 4 : : * 5 : : * Copyright (c) 2021 United States Government as represented by the 6 : : * Administrator of the National Aeronautics and Space Administration. 7 : : * All Rights Reserved. 8 : : * 9 : : * Licensed under the Apache License, Version 2.0 (the "License"); you may 10 : : * not use this file except in compliance with the License. You may obtain 11 : : * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 12 : : * 13 : : * Unless required by applicable law or agreed to in writing, software 14 : : * distributed under the License is distributed on an "AS IS" BASIS, 15 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 : : * See the License for the specific language governing permissions and 17 : : * limitations under the License. 18 : : ************************************************************************/ 19 : : 20 : : /** 21 : : * @file 22 : : * The CFS Housekeeping (HK) Application file containing the application 23 : : * initialization routines, the main routine and the command interface. 24 : : */ 25 : : 26 : : /************************************************************************ 27 : : ** Includes 28 : : *************************************************************************/ 29 : : #include "hk_app.h" 30 : : #include "hk_events.h" 31 : : #include "hk_msgids.h" 32 : : #include "hk_dispatch.h" 33 : : #include "hk_utils.h" 34 : : 35 : : #include <string.h> 36 : : 37 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 38 : : /* */ 39 : : /* Verify Command Length */ 40 : : /* */ 41 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 42 : 4 : int32 HK_VerifyCmdLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) 43 : : { 44 : 4 : int32 Status = HK_SUCCESS; 45 : 4 : CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ 46 : 4 : CFE_MSG_FcnCode_t CommandCode = 0; 47 : 4 : size_t ActualLength = 0; 48 : : 49 : 4 : CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); 50 : : 51 [ + + ]: 4 : if (ExpectedLength != ActualLength) 52 : : { 53 : 2 : CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); 54 : 2 : CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); 55 : : 56 : 2 : CFE_EVS_SendEvent(HK_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, 57 : : "Cmd Msg with Bad length Rcvd: ID = 0x%08lX, CC = %d, Exp Len = %d, Len = %d", 58 : 2 : (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode, (int)ExpectedLength, 59 : : (int)ActualLength); 60 : : 61 : 2 : Status = HK_BAD_MSG_LENGTH_RC; 62 : : } 63 : : 64 : 4 : return Status; 65 : : } 66 : : 67 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 68 : : /* */ 69 : : /* Verify Non-Command Msg Length (Event is differnt) */ 70 : : /* */ 71 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 72 : 5 : int32 HK_VerifyMsgLength(const CFE_SB_Buffer_t *BufPtr, size_t ExpectedLength) 73 : : { 74 : 5 : int32 Status = HK_SUCCESS; 75 : 5 : CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ 76 : 5 : size_t ActualLength = 0; 77 : : 78 : 5 : CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); 79 : : 80 [ + + ]: 5 : if (ExpectedLength != ActualLength) 81 : : { 82 : 2 : CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); 83 : : 84 : 2 : CFE_EVS_SendEvent(HK_MSG_LEN_ERR_EID, CFE_EVS_EventType_ERROR, 85 : : "Msg with Bad length Rcvd: ID = 0x%08lX, Exp Len = %u, Len = %u", 86 : 2 : (unsigned long)CFE_SB_MsgIdToValue(MessageID), (unsigned int)ExpectedLength, 87 : : (unsigned int)ActualLength); 88 : : 89 : 2 : Status = HK_BAD_MSG_LENGTH_RC; 90 : : } 91 : : 92 : 5 : return Status; 93 : : } 94 : : 95 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 96 : : /* */ 97 : : /* Send Combined Housekeeping Packet */ 98 : : /* */ 99 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 100 : 2 : void HK_SendCombinedPktVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) 101 : : { 102 [ + + ]: 2 : if (HK_VerifyMsgLength(BufPtr, sizeof(HK_SendCombinedPktCmd_t)) == HK_SUCCESS) 103 : : { 104 : 1 : HK_SendCombinedPktCmd(BufPtr); 105 : : } 106 : 2 : } 107 : : 108 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 109 : : /* */ 110 : : /* Housekeeping request */ 111 : : /* */ 112 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 113 : 3 : void HK_SendHkVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) 114 : : { 115 [ + + ]: 3 : if (HK_VerifyMsgLength(BufPtr, sizeof(HK_SendHkCmd_t)) == HK_SUCCESS) 116 : : { 117 : 2 : HK_SendHkCmd(BufPtr); 118 : : } 119 : 3 : } 120 : : 121 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 122 : : /* */ 123 : : /* Noop command */ 124 : : /* */ 125 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 126 : 2 : void HK_NoopVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) 127 : : { 128 : 2 : size_t ExpectedLength = sizeof(HK_NoopCmd_t); 129 : : 130 [ + + ]: 2 : if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_SUCCESS) 131 : : { 132 : 1 : HK_NoopCmd(BufPtr); 133 : : } 134 : : else 135 : : { 136 : 1 : HK_AppData.ErrCounter++; 137 : : } 138 : 2 : } 139 : : 140 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 141 : : /* */ 142 : : /* Reset counters command */ 143 : : /* */ 144 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 145 : 2 : void HK_ResetCountersVerifyDispatch(const CFE_SB_Buffer_t *BufPtr) 146 : : { 147 : 2 : size_t ExpectedLength = sizeof(HK_ResetCountersCmd_t); 148 : : 149 [ + + ]: 2 : if (HK_VerifyCmdLength(BufPtr, ExpectedLength) == HK_SUCCESS) 150 : : { 151 : 1 : HK_ResetCountersCmd(BufPtr); 152 : : } 153 : : else 154 : : { 155 : 1 : HK_AppData.ErrCounter++; 156 : : } 157 : 2 : } 158 : : 159 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 160 : : /* */ 161 : : /* Process a command pipe message */ 162 : : /* */ 163 : : /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 164 : 11 : void HK_AppPipe(const CFE_SB_Buffer_t *BufPtr) 165 : : { 166 : 11 : CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; /* Init to invalid value */ 167 : 11 : CFE_MSG_FcnCode_t CommandCode = 0; 168 : : 169 : 11 : CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID); 170 : : 171 [ + + + + ]: 11 : switch (CFE_SB_MsgIdToValue(MessageID)) 172 : : { 173 : 2 : case HK_SEND_COMBINED_PKT_MID: 174 : 2 : HK_SendCombinedPktVerifyDispatch(BufPtr); 175 : 2 : break; 176 : : 177 : : /* Request for HK's Housekeeping data... */ 178 : 3 : case HK_SEND_HK_MID: 179 : : /* Send out HK's housekeeping data */ 180 : 3 : HK_SendHkVerifyDispatch(BufPtr); 181 : : 182 : : /* Check for copy table load and runtime dump request */ 183 [ + + ]: 3 : if (HK_CheckStatusOfTables() != HK_SUCCESS) 184 : : { 185 : 1 : HK_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; 186 : : } 187 : 3 : break; 188 : : 189 : : /* HK ground commands */ 190 : 5 : case HK_CMD_MID: 191 : : 192 : 5 : CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode); 193 : : 194 [ + + + ]: 5 : switch (CommandCode) 195 : : { 196 : 2 : case HK_NOOP_CC: 197 : 2 : HK_NoopVerifyDispatch(BufPtr); 198 : 2 : break; 199 : : 200 : 2 : case HK_RESET_COUNTERS_CC: 201 : 2 : HK_ResetCountersVerifyDispatch(BufPtr); 202 : 2 : break; 203 : : 204 : 1 : default: 205 : 1 : CFE_EVS_SendEvent(HK_CC_ERR_EID, CFE_EVS_EventType_ERROR, 206 : : "Cmd Msg with Invalid command code Rcvd -- ID = 0x%08lX, CC = %d", 207 : 1 : (unsigned long)CFE_SB_MsgIdToValue(MessageID), CommandCode); 208 : 1 : HK_AppData.ErrCounter++; 209 : 1 : break; 210 : : } 211 : 5 : break; 212 : : 213 : : /* Incoming housekeeping data from other Subsystems... */ 214 : 1 : default: 215 : 1 : HK_ProcessIncomingHkData(BufPtr); 216 : 1 : break; 217 : : } 218 : 11 : }