|
| 1 | +/************************************************************************ |
| 2 | + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” |
| 3 | + * |
| 4 | + * Copyright (c) 2020 United States Government as represented by the |
| 5 | + * Administrator of the National Aeronautics and Space Administration. |
| 6 | + * All Rights Reserved. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | + * not use this file except in compliance with the License. You may obtain |
| 10 | + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + ************************************************************************/ |
| 18 | + |
| 19 | +/** |
| 20 | + * @file |
| 21 | + * |
| 22 | + * Msg pipe dispatcher routines for CFE ES |
| 23 | + */ |
| 24 | + |
| 25 | +/* |
| 26 | + * Includes |
| 27 | + */ |
| 28 | +#include "cfe_es_module_all.h" |
| 29 | + |
| 30 | +#include "cfe_version.h" |
| 31 | +#include "target_config.h" |
| 32 | +#include "cfe_es_verify.h" |
| 33 | + |
| 34 | +#include "cfe_config.h" |
| 35 | + |
| 36 | +#include <string.h> |
| 37 | + |
| 38 | +/*---------------------------------------------------------------- |
| 39 | + * |
| 40 | + * Application-scope internal function |
| 41 | + * See description in header file for argument/return detail |
| 42 | + * |
| 43 | + *-----------------------------------------------------------------*/ |
| 44 | +bool CFE_ES_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) |
| 45 | +{ |
| 46 | + bool result = true; |
| 47 | + CFE_MSG_Size_t ActualLength = 0; |
| 48 | + CFE_MSG_FcnCode_t FcnCode = 0; |
| 49 | + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; |
| 50 | + |
| 51 | + CFE_MSG_GetSize(MsgPtr, &ActualLength); |
| 52 | + |
| 53 | + /* |
| 54 | + ** Verify the command packet length |
| 55 | + */ |
| 56 | + if (ExpectedLength != ActualLength) |
| 57 | + { |
| 58 | + CFE_MSG_GetMsgId(MsgPtr, &MsgId); |
| 59 | + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); |
| 60 | + |
| 61 | + CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR, |
| 62 | + "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", |
| 63 | + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, |
| 64 | + (unsigned int)ExpectedLength); |
| 65 | + result = false; |
| 66 | + CFE_ES_Global.TaskData.CommandErrorCounter++; |
| 67 | + } |
| 68 | + |
| 69 | + return result; |
| 70 | +} |
| 71 | + |
| 72 | +/*---------------------------------------------------------------- |
| 73 | + * |
| 74 | + * Application-scope internal function |
| 75 | + * See description in header file for argument/return detail |
| 76 | + * |
| 77 | + *-----------------------------------------------------------------*/ |
| 78 | +void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) |
| 79 | +{ |
| 80 | + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; |
| 81 | + CFE_MSG_FcnCode_t CommandCode = 0; |
| 82 | + |
| 83 | + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); |
| 84 | + switch (CFE_SB_MsgIdToValue(MessageID)) |
| 85 | + { |
| 86 | + /* |
| 87 | + ** Housekeeping telemetry request |
| 88 | + */ |
| 89 | + case CFE_ES_SEND_HK_MID: |
| 90 | + CFE_ES_HousekeepingCmd((const CFE_ES_SendHkCmd_t *)SBBufPtr); |
| 91 | + break; |
| 92 | + |
| 93 | + /* |
| 94 | + ** ES task ground commands |
| 95 | + */ |
| 96 | + case CFE_ES_CMD_MID: |
| 97 | + |
| 98 | + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); |
| 99 | + switch (CommandCode) |
| 100 | + { |
| 101 | + case CFE_ES_NOOP_CC: |
| 102 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t))) |
| 103 | + { |
| 104 | + CFE_ES_NoopCmd((const CFE_ES_NoopCmd_t *)SBBufPtr); |
| 105 | + } |
| 106 | + break; |
| 107 | + |
| 108 | + case CFE_ES_RESET_COUNTERS_CC: |
| 109 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t))) |
| 110 | + { |
| 111 | + CFE_ES_ResetCountersCmd((const CFE_ES_ResetCountersCmd_t *)SBBufPtr); |
| 112 | + } |
| 113 | + break; |
| 114 | + |
| 115 | + case CFE_ES_RESTART_CC: |
| 116 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t))) |
| 117 | + { |
| 118 | + CFE_ES_RestartCmd((const CFE_ES_RestartCmd_t *)SBBufPtr); |
| 119 | + } |
| 120 | + break; |
| 121 | + |
| 122 | + case CFE_ES_START_APP_CC: |
| 123 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t))) |
| 124 | + { |
| 125 | + CFE_ES_StartAppCmd((const CFE_ES_StartAppCmd_t *)SBBufPtr); |
| 126 | + } |
| 127 | + break; |
| 128 | + |
| 129 | + case CFE_ES_STOP_APP_CC: |
| 130 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t))) |
| 131 | + { |
| 132 | + CFE_ES_StopAppCmd((const CFE_ES_StopAppCmd_t *)SBBufPtr); |
| 133 | + } |
| 134 | + break; |
| 135 | + |
| 136 | + case CFE_ES_RESTART_APP_CC: |
| 137 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t))) |
| 138 | + { |
| 139 | + CFE_ES_RestartAppCmd((const CFE_ES_RestartAppCmd_t *)SBBufPtr); |
| 140 | + } |
| 141 | + break; |
| 142 | + |
| 143 | + case CFE_ES_RELOAD_APP_CC: |
| 144 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t))) |
| 145 | + { |
| 146 | + CFE_ES_ReloadAppCmd((const CFE_ES_ReloadAppCmd_t *)SBBufPtr); |
| 147 | + } |
| 148 | + break; |
| 149 | + |
| 150 | + case CFE_ES_QUERY_ONE_CC: |
| 151 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t))) |
| 152 | + { |
| 153 | + CFE_ES_QueryOneCmd((const CFE_ES_QueryOneCmd_t *)SBBufPtr); |
| 154 | + } |
| 155 | + break; |
| 156 | + |
| 157 | + case CFE_ES_QUERY_ALL_CC: |
| 158 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t))) |
| 159 | + { |
| 160 | + CFE_ES_QueryAllCmd((const CFE_ES_QueryAllCmd_t *)SBBufPtr); |
| 161 | + } |
| 162 | + break; |
| 163 | + |
| 164 | + case CFE_ES_QUERY_ALL_TASKS_CC: |
| 165 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t))) |
| 166 | + { |
| 167 | + CFE_ES_QueryAllTasksCmd((const CFE_ES_QueryAllTasksCmd_t *)SBBufPtr); |
| 168 | + } |
| 169 | + break; |
| 170 | + |
| 171 | + case CFE_ES_CLEAR_SYSLOG_CC: |
| 172 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t))) |
| 173 | + { |
| 174 | + CFE_ES_ClearSysLogCmd((const CFE_ES_ClearSysLogCmd_t *)SBBufPtr); |
| 175 | + } |
| 176 | + break; |
| 177 | + |
| 178 | + case CFE_ES_WRITE_SYSLOG_CC: |
| 179 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t))) |
| 180 | + { |
| 181 | + CFE_ES_WriteSysLogCmd((const CFE_ES_WriteSysLogCmd_t *)SBBufPtr); |
| 182 | + } |
| 183 | + break; |
| 184 | + |
| 185 | + case CFE_ES_OVER_WRITE_SYSLOG_CC: |
| 186 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t))) |
| 187 | + { |
| 188 | + CFE_ES_OverWriteSysLogCmd((const CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr); |
| 189 | + } |
| 190 | + break; |
| 191 | + |
| 192 | + case CFE_ES_CLEAR_ER_LOG_CC: |
| 193 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t))) |
| 194 | + { |
| 195 | + CFE_ES_ClearERLogCmd((const CFE_ES_ClearERLogCmd_t *)SBBufPtr); |
| 196 | + } |
| 197 | + break; |
| 198 | + |
| 199 | + case CFE_ES_WRITE_ER_LOG_CC: |
| 200 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t))) |
| 201 | + { |
| 202 | + CFE_ES_WriteERLogCmd((const CFE_ES_WriteERLogCmd_t *)SBBufPtr); |
| 203 | + } |
| 204 | + break; |
| 205 | + |
| 206 | + case CFE_ES_START_PERF_DATA_CC: |
| 207 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t))) |
| 208 | + { |
| 209 | + CFE_ES_StartPerfDataCmd((const CFE_ES_StartPerfDataCmd_t *)SBBufPtr); |
| 210 | + } |
| 211 | + break; |
| 212 | + |
| 213 | + case CFE_ES_STOP_PERF_DATA_CC: |
| 214 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t))) |
| 215 | + { |
| 216 | + CFE_ES_StopPerfDataCmd((const CFE_ES_StopPerfDataCmd_t *)SBBufPtr); |
| 217 | + } |
| 218 | + break; |
| 219 | + |
| 220 | + case CFE_ES_SET_PERF_FILTER_MASK_CC: |
| 221 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t))) |
| 222 | + { |
| 223 | + CFE_ES_SetPerfFilterMaskCmd((const CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr); |
| 224 | + } |
| 225 | + break; |
| 226 | + |
| 227 | + case CFE_ES_SET_PERF_TRIGGER_MASK_CC: |
| 228 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t))) |
| 229 | + { |
| 230 | + CFE_ES_SetPerfTriggerMaskCmd((const CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr); |
| 231 | + } |
| 232 | + break; |
| 233 | + |
| 234 | + case CFE_ES_RESET_PR_COUNT_CC: |
| 235 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t))) |
| 236 | + { |
| 237 | + CFE_ES_ResetPRCountCmd((const CFE_ES_ResetPRCountCmd_t *)SBBufPtr); |
| 238 | + } |
| 239 | + break; |
| 240 | + |
| 241 | + case CFE_ES_SET_MAX_PR_COUNT_CC: |
| 242 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t))) |
| 243 | + { |
| 244 | + CFE_ES_SetMaxPRCountCmd((const CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr); |
| 245 | + } |
| 246 | + break; |
| 247 | + |
| 248 | + case CFE_ES_DELETE_CDS_CC: |
| 249 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t))) |
| 250 | + { |
| 251 | + CFE_ES_DeleteCDSCmd((const CFE_ES_DeleteCDSCmd_t *)SBBufPtr); |
| 252 | + } |
| 253 | + break; |
| 254 | + |
| 255 | + case CFE_ES_SEND_MEM_POOL_STATS_CC: |
| 256 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t))) |
| 257 | + { |
| 258 | + CFE_ES_SendMemPoolStatsCmd((const CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr); |
| 259 | + } |
| 260 | + break; |
| 261 | + |
| 262 | + case CFE_ES_DUMP_CDS_REGISTRY_CC: |
| 263 | + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t))) |
| 264 | + { |
| 265 | + CFE_ES_DumpCDSRegistryCmd((const CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr); |
| 266 | + } |
| 267 | + break; |
| 268 | + |
| 269 | + default: |
| 270 | + CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR, |
| 271 | + "Invalid ground command code: ID = 0x%X, CC = %d", |
| 272 | + (unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode); |
| 273 | + CFE_ES_Global.TaskData.CommandErrorCounter++; |
| 274 | + break; |
| 275 | + } |
| 276 | + break; |
| 277 | + |
| 278 | + default: |
| 279 | + |
| 280 | + CFE_EVS_SendEvent(CFE_ES_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%X", |
| 281 | + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); |
| 282 | + CFE_ES_Global.TaskData.CommandErrorCounter++; |
| 283 | + break; |
| 284 | + } |
| 285 | +} |
0 commit comments