Skip to content

Commit

Permalink
Fix nasa#169, initial inclusion of EDS file
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Dec 13, 2023
1 parent acb8d4b commit 4063026
Show file tree
Hide file tree
Showing 5 changed files with 402 additions and 1 deletion.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,20 @@ project(CFS_CI_LAB C)
set(APP_SRC_FILES
fsw/src/ci_lab_app.c
fsw/src/ci_lab_cmds.c
)

if (CFE_EDS_ENABLED_BUILD)
list(APPEND APP_SRC_FILES
fsw/src/ci_lab_eds_dispatch.c
fsw/src/ci_lab_eds_decode.c
)
else()
list(APPEND APP_SRC_FILES
fsw/src/ci_lab_dispatch.c
fsw/src/ci_lab_passthru_decode.c
)
)
endif()


# Create the app module
add_cfe_app(ci_lab ${APP_SRC_FILES})
Expand Down
32 changes: 32 additions & 0 deletions config/default_ci_lab_eds_msgids.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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 Application Message IDs
*/
#ifndef CI_LAB_MSGIDS_H
#define CI_LAB_MSGIDS_H

#include "cfe_msgids.h"

#define CI_LAB_CMD_MID CFE_PLATFORM_CMD_TOPICID_TO_MID(CFE_MISSION_CI_LAB_CMD_TOPICID)
#define CI_LAB_SEND_HK_MID CFE_PLATFORM_CMD_TOPICID_TO_MID(CFE_MISSION_CI_LAB_SEND_HK_TOPICID)
#define CI_LAB_HK_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MID(CFE_MISSION_CI_LAB_HK_TLM_TOPICID)

#endif
109 changes: 109 additions & 0 deletions eds/ci_lab.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
GSC-18128-1, "Core Flight Executive Version 6.7"
LEW-19710-1, "CCSDS electronic data sheet implementation"
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.
This document adheres to the Electronic Data Sheet (EDS) XML schema
as prescribed in CCSDS book 876.0.
Purpose:
This describes all interface objects for the Executive Services (CFE_ES)
core application
-->
<PackageFile xmlns="http://www.ccsds.org/schema/sois/seds">
<Package name="CI_LAB" shortDescription="Command Ingest">
<DataTypeSet>
<ContainerDataType name="HkTlm_Payload" shortDescription="CI_LAB_Lab housekeeping">
<EntryList>
<Entry name="CommandCounter" type="BASE_TYPES/uint8" />
<Entry name="CommandErrorCounter" type="BASE_TYPES/uint8" />
<Entry name="EnableChecksums" type="BASE_TYPES/uint8" />
<Entry name="SocketConnected" type="BASE_TYPES/uint8" />
<Entry name="IngestPackets" type="BASE_TYPES/uint32" />
<Entry name="IngestErrors" type="BASE_TYPES/uint32" />
</EntryList>
</ContainerDataType>

<ContainerDataType name="SendHkCmd" baseType="CFE_HDR/CommandHeader">
</ContainerDataType>

<ContainerDataType name="CommandBase" baseType="CFE_HDR/CommandHeader">
</ContainerDataType>

<ContainerDataType name="HkTlm" baseType="CFE_HDR/TelemetryHeader">
<EntryList>
<Entry type="HkTlm_Payload" name="Payload" />
</EntryList>
</ContainerDataType>


<ContainerDataType name="NoopCmd" baseType="CommandBase">
<ConstraintSet>
<ValueConstraint entry="Sec.FunctionCode" value="0" />
</ConstraintSet>
</ContainerDataType>

<ContainerDataType name="ResetCountersCmd" baseType="CommandBase">
<ConstraintSet>
<ValueConstraint entry="Sec.FunctionCode" value="1" />
</ConstraintSet>
</ContainerDataType>

</DataTypeSet>

<ComponentSet>
<Component name="Application">
<RequiredInterfaceSet>
<Interface name="CMD" shortDescription="Software bus telecommand interface" type="CFE_SB/Telecommand">
<GenericTypeMapSet>
<GenericTypeMap name="TelecommandDataType" type="CommandBase" />
</GenericTypeMapSet>
</Interface>
<Interface name="SEND_HK" shortDescription="Send telemetry command interface" type="CFE_SB/Telecommand">
<!-- This uses a bare spacepacket with no payload -->
<GenericTypeMapSet>
<GenericTypeMap name="TelecommandDataType" type="SendHkCmd" />
</GenericTypeMapSet>
</Interface>
<Interface name="HK_TLM" shortDescription="Software bus housekeeping telemetry interface" type="CFE_SB/Telemetry">
<GenericTypeMapSet>
<GenericTypeMap name="TelemetryDataType" type="HkTlm" />
</GenericTypeMapSet>
</Interface>
</RequiredInterfaceSet>
<Implementation>
<VariableSet>
<Variable type="BASE_TYPES/uint16" readOnly="true" name="CmdTopicId" initialValue="${CFE_MISSION/CI_LAB_CMD_TOPICID}" />
<Variable type="BASE_TYPES/uint16" readOnly="true" name="SendHkTopicId" initialValue="${CFE_MISSION/CI_LAB_SEND_HK_TOPICID}" />
<Variable type="BASE_TYPES/uint16" readOnly="true" name="HkTlmTopicId" initialValue="${CFE_MISSION/CI_LAB_HK_TLM_TOPICID}" />
</VariableSet>
<!-- Assign fixed numbers to the "TopicId" parameter of each interface -->
<ParameterMapSet>
<ParameterMap interface="CMD" parameter="TopicId" variableRef="CmdTopicId" />
<ParameterMap interface="SEND_HK" parameter="TopicId" variableRef="SendHkTopicId" />
<ParameterMap interface="HK_TLM" parameter="TopicId" variableRef="HkTlmTopicId" />
</ParameterMapSet>
</Implementation>
</Component>
</ComponentSet>

</Package>
</PackageFile>
167 changes: 167 additions & 0 deletions fsw/src/ci_lab_eds_decode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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
* This file contains the source code for the Command Ingest task.
*/

/*
** Include Files:
*/

#include "ci_lab_app.h"
#include "ci_lab_perfids.h"
#include "ci_lab_msgids.h"
#include "ci_lab_version.h"

#include "cfe_config.h"

#include "edslib_datatypedb.h"
#include "ci_lab_eds_typedefs.h"
#include "cfe_missionlib_api.h"
#include "cfe_missionlib_runtime.h"
#include "cfe_mission_eds_parameters.h"
#include "cfe_mission_eds_interface_parameters.h"


/*
* ---------------------------------------
* In an EDS configuration - the data from the network is encoded
* and needs to be read into an intermediate buffer first
* ---------------------------------------
*/
CFE_Status_t CI_LAB_GetInputBuffer(void **BufferOut, size_t *SizeOut)
{
static CFE_HDR_CommandHeader_PackedBuffer_t InputBuffer;

*BufferOut = &InputBuffer;
*SizeOut = sizeof(InputBuffer);

return CFE_SUCCESS;
}

/*
* ---------------------------------------
* In an EDS configuration - the data from the network is encoded
* and this function translates the intermediate buffer content
* to an instance of the CFE_SB_Buffer_t that can be sent to SB.
* ---------------------------------------
*/
CFE_Status_t CI_LAB_DecodeInputMessage(void *SourceBuffer, size_t SourceSize, CFE_SB_Buffer_t **DestBufferOut)
{
int32 EdsStatus;
uint32 BitSize;
CFE_SB_SoftwareBus_PubSub_Interface_t PubSubParams;
CFE_SB_Listener_Component_t ListenerParams;
EdsLib_DataTypeDB_TypeInfo_t CmdHdrInfo;
EdsLib_Id_t EdsId;
CFE_SB_Buffer_t * IngestBufPtr;
CFE_Status_t ResultStatus;

const EdsLib_DatabaseObject_t *EDS_DB = CFE_Config_GetObjPointer(CFE_CONFIGID_MISSION_EDS_DB);

ResultStatus = CFE_STATUS_VALIDATION_FAILURE;
IngestBufPtr = NULL;

do
{
EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY);
EdsStatus = EdsLib_DataTypeDB_GetTypeInfo(EDS_DB, EdsId, &CmdHdrInfo);
if (EdsStatus != EDSLIB_SUCCESS)
{
OS_printf("EdsLib_DataTypeDB_GetTypeInfo(): %d\n", (int)EdsStatus);
break;
}

/* sanity check - validate the incoming packet is at least the size of a command header */
BitSize = 8 * SourceSize;
if (BitSize < CmdHdrInfo.Size.Bits)
{
OS_printf("CI_LAB: Size mismatch, BitSize=%lu (packet) / %lu (min)\n",
(unsigned long)BitSize, (unsigned long)CmdHdrInfo.Size.Bits);

ResultStatus = CFE_STATUS_WRONG_MSG_LENGTH;
break;
}

/* Now get a SB Buffer, as a place to put the decoded data */
IngestBufPtr = CFE_SB_AllocateMessageBuffer(sizeof(CFE_HDR_CommandHeader_Buffer_t));
if (IngestBufPtr == NULL)
{
CFE_EVS_SendEvent(CI_LAB_INGEST_ALLOC_ERR_EID, CFE_EVS_EventType_ERROR,
"CI_LAB: buffer allocation failed\n");

ResultStatus = CFE_SB_BUF_ALOC_ERR;
break;
}

/* Packet is in external wire-format byte order - unpack it and copy */
EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY);
EdsStatus = EdsLib_DataTypeDB_UnpackPartialObject(EDS_DB, &EdsId, IngestBufPtr, SourceBuffer,
sizeof(CFE_HDR_CommandHeader_t), BitSize, 0);
if (EdsStatus != EDSLIB_SUCCESS)
{
OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(1): %d\n", (int)EdsStatus);
break;
}

/* Header decoded successfully - Now need to determine the type for the rest of the payload */
CFE_MissionLib_Get_PubSub_Parameters(&PubSubParams, &IngestBufPtr->Msg.BaseMsg);
CFE_MissionLib_UnmapListenerComponent(&ListenerParams, &PubSubParams);

EdsStatus = CFE_MissionLib_GetArgumentType(&CFE_SOFTWAREBUS_INTERFACE, CFE_SB_Telecommand_Interface_ID,
ListenerParams.Telecommand.TopicId, 1, 1, &EdsId);
if (EdsStatus != CFE_MISSIONLIB_SUCCESS)
{
OS_printf("CFE_MissionLib_GetArgumentType(): %d\n", (int)EdsStatus);
break;
}

EdsStatus = EdsLib_DataTypeDB_UnpackPartialObject(EDS_DB, &EdsId, IngestBufPtr, SourceBuffer,
sizeof(CFE_HDR_CommandHeader_Buffer_t), BitSize, sizeof(CFE_HDR_CommandHeader_t));
if (EdsStatus != EDSLIB_SUCCESS)
{
OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(2): %d\n", (int)EdsStatus);
break;
}

/* Verify that the checksum and basic fields are correct, and recompute the length entry */
EdsStatus = EdsLib_DataTypeDB_VerifyUnpackedObject(EDS_DB, EdsId, IngestBufPtr, SourceBuffer,
EDSLIB_DATATYPEDB_RECOMPUTE_LENGTH);
if (EdsStatus != EDSLIB_SUCCESS)
{
OS_printf("EdsLib_DataTypeDB_VerifyUnpackedObject(): %d\n", (int)EdsStatus);
break;
}

/* Finally - at this point, we should have a fully decoded buffer */
ResultStatus = CFE_SUCCESS;
}
while(false);

if (ResultStatus != CFE_SUCCESS && IngestBufPtr != NULL)
{
CFE_SB_ReleaseMessageBuffer(IngestBufPtr);
IngestBufPtr = NULL;
}

*DestBufferOut = IngestBufPtr;

return ResultStatus;
}
Loading

0 comments on commit 4063026

Please sign in to comment.