From 51475efaab014e72410973a57ed2e801bcb0b1d2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 8 Jun 2021 13:46:45 +0200 Subject: [PATCH] added common folder --- common/CMakeLists.txt | 3 + common/config/CMakeLists.txt | 7 ++ common/config/OBSWVersion.h | 8 ++ common/config/commonClassIds.h | 14 ++++ common/config/commonConfig.h.in | 64 +++++++++++++++ .../config/commonPollingSequenceFactory.cpp | 81 +++++++++++++++++++ common/config/commonSubsystemIds.h | 17 ++++ common/config/commonSystemObjects.h | 40 +++++++++ common/utility/CMakeLists.txt | 3 + common/utility/utility.cpp | 22 +++++ common/utility/utility.h | 11 +++ 11 files changed, 270 insertions(+) create mode 100644 common/CMakeLists.txt create mode 100644 common/config/CMakeLists.txt create mode 100644 common/config/OBSWVersion.h create mode 100644 common/config/commonClassIds.h create mode 100644 common/config/commonConfig.h.in create mode 100644 common/config/commonPollingSequenceFactory.cpp create mode 100644 common/config/commonSubsystemIds.h create mode 100644 common/config/commonSystemObjects.h create mode 100644 common/utility/CMakeLists.txt create mode 100644 common/utility/utility.cpp create mode 100644 common/utility/utility.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 0000000..40f33d4 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(config) +add_subdirectory(utility) + diff --git a/common/config/CMakeLists.txt b/common/config/CMakeLists.txt new file mode 100644 index 0000000..bac32c4 --- /dev/null +++ b/common/config/CMakeLists.txt @@ -0,0 +1,7 @@ +target_sources(${TARGET_NAME} PRIVATE + commonPollingSequenceFactory.cpp +) + +target_include_directories(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/common/config/OBSWVersion.h b/common/config/OBSWVersion.h new file mode 100644 index 0000000..4ae99b0 --- /dev/null +++ b/common/config/OBSWVersion.h @@ -0,0 +1,8 @@ +#ifndef COMMON_OBSWVERSION_H_ +#define COMMON_OBSWVERSION_H_ + +#define FSFW_EXAMPLE_VERSION 1 +#define FSFW_EXAMPLE_SUBVERSION 1 +#define FSFW_EXAMPLE_REVISION 0 + +#endif /* COMMON_OBSWVERSION_H_ */ diff --git a/common/config/commonClassIds.h b/common/config/commonClassIds.h new file mode 100644 index 0000000..6baae60 --- /dev/null +++ b/common/config/commonClassIds.h @@ -0,0 +1,14 @@ +#ifndef COMMON_CONFIG_COMMONCLASSIDS_H_ +#define COMMON_CONFIG_COMMONCLASSIDS_H_ + +#include "fsfw/returnvalues/FwClassIds.h" + +namespace CLASS_ID { +enum commonClassIds: uint8_t { + COMMON_CLASS_ID_START = FW_CLASS_ID_COUNT, + DUMMY_HANDLER, //DDH + COMMON_CLASS_ID_END // [EXPORT] : [END] +}; +} + +#endif /* COMMON_CONFIG_COMMONCLASSIDS_H_ */ diff --git a/common/config/commonConfig.h.in b/common/config/commonConfig.h.in new file mode 100644 index 0000000..c79a07d --- /dev/null +++ b/common/config/commonConfig.h.in @@ -0,0 +1,64 @@ +/** + * @brief This file will contain configuration constants which are used across all BSPs + */ +#ifndef COMMON_COMMONCONFIG_H_ +#define COMMON_COMMONCONFIG_H_ + +#include + +//! Specify the debug output verbose level +#define OBSW_VERBOSE_LEVEL 1 + +#define OBSW_PRINT_MISSED_DEADLINES 0 + +//! Add core components for the FSFW and for TMTC communication +#define OBSW_ADD_CORE_COMPONENTS 1 + +//! Add the PUS service stack +#define OBSW_ADD_PUS_STACK 1 +#define OBSW_PUS_PRINTOUT 0 + +//! Add the task examples +#define OBSW_ADD_TASK_EXAMPLE 1 +#define OBSW_TASK_EXAMPLE_PRINTOUT 0 + +//! Add the demo device handler object +#define OBSW_ADD_DEVICE_HANDLER_DEMO 1 +#define OBSW_DEVICE_HANDLER_PRINTOUT 1 + +//! Add the demo controller object +#define OBSW_ADD_CONTROLLER_DEMO 1 +#define OBSW_CONTROLLER_PRINTOUT 1 + +/** + * The APID is a 14 bit identifier which can be used to distinguish processes and applications + * on a spacecraft. For more details, see the related ECSS/CCSDS standards. + * For this example, we are going to use a constant APID +*/ +static const uint16_t COMMON_APID = 0xEF; + +#ifdef __cplusplus + +#include +#include + +/** + * Enumerations for used PUS service IDs. + */ +namespace pus { +enum ServiceIds: uint8_t { + PUS_SERVICE_1 = 1, + PUS_SERVICE_2 = 2, + PUS_SERVICE_3 = 3, + PUS_SERVICE_5 = 5, + PUS_SERVICE_8 = 8, + PUS_SERVICE_9 = 9, + PUS_SERVICE_17 = 17, + PUS_SERVICE_20 = 20, + PUS_SERVICE_200 = 200 +}; +} + +#endif /* __cplusplus */ + +#endif /* COMMON_COMMONCONFIG_H_ */ diff --git a/common/config/commonPollingSequenceFactory.cpp b/common/config/commonPollingSequenceFactory.cpp new file mode 100644 index 0000000..c8183fa --- /dev/null +++ b/common/config/commonPollingSequenceFactory.cpp @@ -0,0 +1,81 @@ +#include +#include + +#include +#include +#include +#include + +ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) { + uint32_t length = thisSequence->getPeriodMs(); + + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0, + FsfwExampleTask::OpCodes::SEND_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0, + FsfwExampleTask::OpCodes::SEND_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0, + FsfwExampleTask::OpCodes::SEND_RAND_NUM); + + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.2, + FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); + + thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.5, + FsfwExampleTask::OpCodes::DELAY_SHORT); + thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.5, + FsfwExampleTask::OpCodes::DELAY_SHORT); + thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.5, + FsfwExampleTask::OpCodes::DELAY_SHORT); + + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_OK; + } + else { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl; +#else + sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n"); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } +} + +ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF *thisSequence) { + uint32_t length = thisSequence->getPeriodMs(); + + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0, DeviceHandlerIF::PERFORM_OPERATION); + + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.3, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3, DeviceHandlerIF::SEND_WRITE); + + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.45 * length, + DeviceHandlerIF::GET_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.45 * length, + DeviceHandlerIF::GET_WRITE); + + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.6 * length, DeviceHandlerIF::SEND_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.6 * length, DeviceHandlerIF::SEND_READ); + + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.8 * length, DeviceHandlerIF::GET_READ); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.8 * length, DeviceHandlerIF::GET_READ); + + if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_OK; + } + else { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; +#else + sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); +#endif + return HasReturnvaluesIF::RETURN_FAILED; + } +} + + + + diff --git a/common/config/commonSubsystemIds.h b/common/config/commonSubsystemIds.h new file mode 100644 index 0000000..a26a03d --- /dev/null +++ b/common/config/commonSubsystemIds.h @@ -0,0 +1,17 @@ +#ifndef COMMON_CONFIG_COMMONSUBSYSTEMIDS_H_ +#define COMMON_CONFIG_COMMONSUBSYSTEMIDS_H_ + +#include "fsfw/events/fwSubsystemIdRanges.h" + +/** + * The subsystem IDs will be part of the event IDs used throughout the FSFW. + */ +namespace SUBSYSTEM_ID { +enum commonSubsystemId: uint8_t { + COMMON_SUBSYSTEM_ID_START = FW_SUBSYSTEM_ID_RANGE, + COMMON_SUBSYSTEM_ID_END +}; +} + + +#endif /* COMMON_CONFIG_COMMONSUBSYSTEMIDS_H_ */ diff --git a/common/config/commonSystemObjects.h b/common/config/commonSystemObjects.h new file mode 100644 index 0000000..07cd239 --- /dev/null +++ b/common/config/commonSystemObjects.h @@ -0,0 +1,40 @@ +#ifndef COMMON_COMMONSYSTEMOBJECTS_H_ +#define COMMON_COMMONSYSTEMOBJECTS_H_ + +#include +#include + +namespace objects { +enum commonObjects: object_id_t { + + /* 0x41 ('A') for Assemblies */ + TEST_ASSEMBLY = 0x4100CAFE, + + /* 0x43 ('C') for Controllers */ + TEST_CONTROLLER = 0x4301CAFE, + + /* 0x44 ('D') for Device Handlers */ + TEST_DEVICE_HANDLER_0 = 0x4401AFFE, + TEST_DEVICE_HANDLER_1 = 0x4402AFFE, + + /* 0x49 ('I') for Communication Interfaces */ + TEST_ECHO_COM_IF = 0x4900AFFE, + + /* 0x63 ('C') for core objects */ + CCSDS_DISTRIBUTOR = 0x63000000, + PUS_DISTRIBUTOR = 0x63000001, + TM_FUNNEL = 0x63000002, + + /* 0x74 ('t') for test and example objects */ + TEST_TASK = 0x7400CAFE, + TEST_DUMMY_1 = 0x74000001, + TEST_DUMMY_2 = 0x74000002, + TEST_DUMMY_3= 0x74000003, + TEST_DUMMY_4 = 0x74000004, + TEST_DUMMY_5 = 0x74000005, +}; +} + + + +#endif /* COMMON_COMMONSYSTEMOBJECTS_H_ */ diff --git a/common/utility/CMakeLists.txt b/common/utility/CMakeLists.txt new file mode 100644 index 0000000..330db4a --- /dev/null +++ b/common/utility/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(${TARGET_NAME} PRIVATE + utility.cpp +) diff --git a/common/utility/utility.cpp b/common/utility/utility.cpp new file mode 100644 index 0000000..26481db --- /dev/null +++ b/common/utility/utility.cpp @@ -0,0 +1,22 @@ +#include "utility.h" +#include +#include + +#include + +void utility::commonInitPrint(const char *const os, const char* const board) { + if(os == nullptr or board == nullptr) { + return; + } +#if FSFW_CPP_OSTREAM_ENABLED == 1 + std::cout << "-- FSFW Example (" << os<< ") v" << FSFW_EXAMPLE_VERSION << "." << + FSFW_EXAMPLE_SUBVERSION << "." << FSFW_EXAMPLE_REVISION << " --" << std::endl; + std::cout << "-- Compiled for " << board << " --" << std::endl; + std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --" << std::endl; +#else + printf("\n\r-- FSFW Example (%s) v%d.%d.%d --\n", os, FSFW_EXAMPLE_VERSION, + FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION); + printf("-- Compiled for %s --\n", board); + printf("-- Compiled on %s %s --\n", __DATE__, __TIME__); +#endif +} diff --git a/common/utility/utility.h b/common/utility/utility.h new file mode 100644 index 0000000..6cf6f35 --- /dev/null +++ b/common/utility/utility.h @@ -0,0 +1,11 @@ +#ifndef COMMON_UTILITY_UTILITY_H_ +#define COMMON_UTILITY_UTILITY_H_ + +namespace utility { + +void commonInitPrint(const char *const os, const char* const board); + +} + + +#endif /* COMMON_UTILITY_UTILITY_H_ */