From 5792aff5e318d93e916b48580408613a0274509e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Aug 2022 12:32:06 +0200 Subject: [PATCH] run afmt --- config/commonClassIds.h | 4 +- config/commonPollingSequenceFactory.cpp | 60 ++--- example/controller/FsfwTestController.cpp | 150 +++++------ example/controller/FsfwTestController.h | 16 +- example/core/GenericFactory.cpp | 62 ++--- example/core/GenericFactory.h | 2 +- example/test/FsfwExampleTask.cpp | 160 +++++------- example/test/FsfwExampleTask.h | 13 +- example/test/FsfwReaderTask.cpp | 13 +- example/test/FsfwReaderTask.h | 4 +- example/test/FsfwTestTask.h | 7 +- example/test/MutexExample.cpp | 15 +- example/test/testFmt.h | 87 +++---- .../test/testdefinitions/demoDefinitions.h | 22 +- example/utility/PusPacketCreator.h | 2 +- example/utility/TaskCreation.h | 7 +- example/utility/TmFunnel.cpp | 28 +- example/utility/TmFunnel.h | 15 +- example/utility/compile_time.h | 71 +++-- example/utility/utility.cpp | 6 +- stm32h7/STM32TestTask.cpp | 5 +- stm32h7/STM32TestTask.h | 7 +- stm32h7/networking/TmTcLwIpUdpBridge.cpp | 45 ++-- stm32h7/networking/TmTcLwIpUdpBridge.h | 19 +- stm32h7/networking/UdpTcLwIpPollingTask.cpp | 9 +- stm32h7/networking/UdpTcLwIpPollingTask.h | 7 +- stm32h7/networking/app_dhcp.cpp | 37 ++- stm32h7/networking/app_ethernet.cpp | 4 +- stm32h7/networking/app_ethernet.h | 2 +- stm32h7/networking/ethernetif.c | 245 ++++++++---------- stm32h7/networking/networking.cpp | 7 +- stm32h7/networking/networking.h | 2 +- 32 files changed, 476 insertions(+), 657 deletions(-) diff --git a/config/commonClassIds.h b/config/commonClassIds.h index 1f2b8fb..75b2cbd 100644 --- a/config/commonClassIds.h +++ b/config/commonClassIds.h @@ -6,8 +6,8 @@ namespace CLASS_ID { enum commonClassIds : uint8_t { COMMON_CLASS_ID_START = FW_CLASS_ID_COUNT, - DUMMY_HANDLER, // DDH - COMMON_CLASS_ID_END // [EXPORT] : [END] + DUMMY_HANDLER, // DDH + COMMON_CLASS_ID_END // [EXPORT] : [END] }; } diff --git a/config/commonPollingSequenceFactory.cpp b/config/commonPollingSequenceFactory.cpp index b3989b3..aea1633 100644 --- a/config/commonPollingSequenceFactory.cpp +++ b/config/commonPollingSequenceFactory.cpp @@ -9,12 +9,9 @@ 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, 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); @@ -23,22 +20,17 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF *thisSequence) { 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); + 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; + sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl; #else - sif::printError( - "pst::pollingSequenceInitFunction: Initialization errors!\n"); + sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n"); #endif return HasReturnvaluesIF::RETURN_FAILED; } @@ -47,40 +39,28 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF *thisSequence) { 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, DeviceHandlerIF::PERFORM_OPERATION); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0, DeviceHandlerIF::PERFORM_OPERATION); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.3 * length, - DeviceHandlerIF::SEND_WRITE); - thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3 * length, - DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0.3 * length, DeviceHandlerIF::SEND_WRITE); + thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3 * length, 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.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.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); + 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; + sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; #else - sif::printError( - "pst::pollingSequenceTestFunction: Initialization errors!\n"); + sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); #endif return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/example/controller/FsfwTestController.cpp b/example/controller/FsfwTestController.cpp index 218f7e8..6c915dc 100644 --- a/example/controller/FsfwTestController.cpp +++ b/example/controller/FsfwTestController.cpp @@ -2,21 +2,22 @@ #include -FsfwTestController::FsfwTestController(object_id_t objectId, - object_id_t device0, object_id_t device1, - uint8_t verboseLevel) - : TestController(objectId, objects::NO_OBJECT, 5), device0Id(device0), - device1Id(device1), deviceDataset0(device0), deviceDataset1(device1) {} +FsfwTestController::FsfwTestController(object_id_t objectId, object_id_t device0, + object_id_t device1, uint8_t verboseLevel) + : TestController(objectId, objects::NO_OBJECT, 5), + device0Id(device0), + device1Id(device1), + deviceDataset0(device0), + deviceDataset1(device1) {} FsfwTestController::~FsfwTestController() {} -ReturnValue_t -FsfwTestController::handleCommandMessage(CommandMessage *message) { +ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage *message) { return HasReturnvaluesIF::RETURN_OK; } -ReturnValue_t FsfwTestController::initializeLocalDataPool( - localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { +ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { return HasReturnvaluesIF::RETURN_OK; } @@ -27,36 +28,35 @@ void FsfwTestController::performControlOperation() { return; } switch (currentTraceType) { - case (NONE): { - break; - } - case (TRACE_DEV_0_UINT8): { - if (traceCounter == 0) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing finished" << std::endl; -#else - sif::printInfo("Tracing finished\n"); -#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - traceVariable = false; - traceCounter = traceCycles; - currentTraceType = TraceTypes::NONE; + case (NONE): { break; } - PoolReadGuard readHelper(&deviceDataset0.testUint8Var); + case (TRACE_DEV_0_UINT8): { + if (traceCounter == 0) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Tracing device 0 variable 0 (UINT8), current value: " - << static_cast(deviceDataset0.testUint8Var.value) - << std::endl; + sif::info << "Tracing finished" << std::endl; #else - sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", - deviceDataset0.testUint8Var.value); + sif::printInfo("Tracing finished\n"); +#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ + traceVariable = false; + traceCounter = traceCycles; + currentTraceType = TraceTypes::NONE; + break; + } + PoolReadGuard readHelper(&deviceDataset0.testUint8Var); +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::info << "Tracing device 0 variable 0 (UINT8), current value: " + << static_cast(deviceDataset0.testUint8Var.value) << std::endl; +#else + sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", + deviceDataset0.testUint8Var.value); #endif - traceCounter--; - break; - } - case (TRACE_DEV_0_VECTOR): { - break; - } + traceCounter--; + break; + } + case (TRACE_DEV_0_VECTOR): { + break; + } } } } @@ -68,14 +68,12 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() { return result; } HasLocalDataPoolIF *device0 = - ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); + ObjectManager::instance()->get(deviceDataset0.getCreatorObjectId()); if (device0 == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning - << "TestController::initializeAfterTaskCreation: Test device handler 0 " - "handle invalid!" - << std::endl; + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " + "handle invalid!" + << std::endl; #else sif::printWarning( "TestController::initializeAfterTaskCreation: Test device handler 0 " @@ -83,25 +81,22 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() { #endif return ObjectManagerIF::CHILD_INIT_FAILED; } - ProvidesDataPoolSubscriptionIF *subscriptionIF = - device0->getSubscriptionInterface(); + ProvidesDataPoolSubscriptionIF *subscriptionIF = device0->getSubscriptionInterface(); if (subscriptionIF != nullptr) { /* For DEVICE_0, we only subscribe for notifications */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), false); - subscriptionIF->subscribeForVariableUpdateMessage( - td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), false); + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), + false); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(), + getCommandQueue(), false); } HasLocalDataPoolIF *device1 = - ObjectManager::instance()->get( - deviceDataset0.getCreatorObjectId()); + ObjectManager::instance()->get(deviceDataset0.getCreatorObjectId()); if (device1 == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning - << "TestController::initializeAfterTaskCreation: Test device handler 1 " - "handle invalid!" - << std::endl; + sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " + "handle invalid!" + << std::endl; #else sif::printWarning( "TestController::initializeAfterTaskCreation: Test device handler 1 " @@ -112,26 +107,22 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() { subscriptionIF = device1->getSubscriptionInterface(); if (subscriptionIF != nullptr) { /* For DEVICE_1, we will subscribe for snapshots */ - subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), - getCommandQueue(), true); - subscriptionIF->subscribeForVariableUpdateMessage( - td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), true); + subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), + true); + subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(), + getCommandQueue(), true); } return result; } -LocalPoolDataSetBase *FsfwTestController::getDataSetHandle(sid_t sid) { - return nullptr; -} +LocalPoolDataSetBase *FsfwTestController::getDataSetHandle(sid_t sid) { return nullptr; } -ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode, - Submode_t submode, +ReturnValue_t FsfwTestController::checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) { return HasReturnvaluesIF::RETURN_OK; } -void FsfwTestController::handleChangedDataset(sid_t sid, - store_address_t storeId, +void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId, bool *clearMessage) { using namespace std; @@ -146,9 +137,8 @@ void FsfwTestController::handleChangedDataset(sid_t sid, sif::info << "FsfwTestController::handleChangedDataset: " << printout << " update" "from object ID " - << setw(8) << setfill('0') << hex << sid.objectId - << " and set ID " << sid.ownerSetId << dec << setfill(' ') - << endl; + << setw(8) << setfill('0') << hex << sid.objectId << " and set ID " << sid.ownerSetId + << dec << setfill(' ') << endl; #else sif::printInfo( "FsfwTestController::handleChangedPoolVariable: %s update from" @@ -164,11 +154,11 @@ void FsfwTestController::handleChangedDataset(sid_t sid, floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " - << floatVec[1] << ", " << floatVec[2] << "]" << std::endl; + sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << floatVec[1] + << ", " << floatVec[2] << "]" << std::endl; #else - sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", - floatVec[0], floatVec[1], floatVec[2]); + sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", floatVec[0], floatVec[1], + floatVec[2]); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ } } @@ -182,8 +172,7 @@ void FsfwTestController::handleChangedDataset(sid_t sid, } } -void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, - store_address_t storeId, +void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, bool *clearMessage) { using namespace std; @@ -199,14 +188,14 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, sif::info << "TestController::handleChangedPoolVariable: " << printout << " update from object " "ID 0x" - << setw(8) << setfill('0') << hex << globPoolId.objectId - << " and local pool ID " << globPoolId.localPoolId << dec - << setfill(' ') << endl; + << setw(8) << setfill('0') << hex << globPoolId.objectId << " and local pool ID " + << globPoolId.localPoolId << dec << setfill(' ') << endl; #else - sif::printInfo("TestController::handleChangedPoolVariable: %s update from " - "object ID 0x%08x and " - "local pool ID %lu\n", - printout, globPoolId.objectId, globPoolId.localPoolId); + sif::printInfo( + "TestController::handleChangedPoolVariable: %s update from " + "object ID 0x%08x and " + "local pool ID %lu\n", + printout, globPoolId.objectId, globPoolId.localPoolId); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ if (storeId == store_address_t::invalid()) { @@ -214,8 +203,7 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, PoolReadGuard readHelper(&deviceDataset0.testUint8Var); #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::info << "Current test variable 0 (UINT8) value: " - << static_cast(deviceDataset0.testUint8Var.value) - << std::endl; + << static_cast(deviceDataset0.testUint8Var.value) << std::endl; #else sif::printInfo("Current test variable 0 (UINT8) value %d\n", deviceDataset0.testUint8Var.value); diff --git a/example/controller/FsfwTestController.h b/example/controller/FsfwTestController.h index 614ee10..a977fdf 100644 --- a/example/controller/FsfwTestController.h +++ b/example/controller/FsfwTestController.h @@ -5,9 +5,9 @@ #include "fsfw_tests/integration/controller/TestController.h" class FsfwTestController : public TestController { -public: - FsfwTestController(object_id_t objectId, object_id_t device0, - object_id_t device1, uint8_t verboseLevel = 0); + public: + FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1, + uint8_t verboseLevel = 0); virtual ~FsfwTestController(); ReturnValue_t handleCommandMessage(CommandMessage *message) override; @@ -16,7 +16,7 @@ public: */ void performControlOperation() override; -private: + private: object_id_t device0Id; object_id_t device1Id; testdevice::TestDataSet deviceDataset0; @@ -31,13 +31,11 @@ private: TraceTypes currentTraceType = TraceTypes::NONE; ReturnValue_t initializeAfterTaskCreation() override; - void handleChangedDataset(sid_t sid, store_address_t storeId, - bool *clearMessage) override; + void handleChangedDataset(sid_t sid, store_address_t storeId, bool *clearMessage) override; void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, bool *clearMessage) override; - ReturnValue_t - initializeLocalDataPool(localpool::DataPool &localDataPoolMap, - LocalDataPoolManager &poolManager) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override; ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) override; diff --git a/example/core/GenericFactory.cpp b/example/core/GenericFactory.cpp index 9438784..a3a5d7e 100644 --- a/example/core/GenericFactory.cpp +++ b/example/core/GenericFactory.cpp @@ -40,34 +40,29 @@ void ObjectFactory::produceGenericObjects() { new EventManager(objects::EVENT_MANAGER); new HealthTable(objects::HEALTH_TABLE); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); - auto* stamperAndReader = new CdsShortTimeStamper(objects::TIME_STAMPER); + auto *stamperAndReader = new CdsShortTimeStamper(objects::TIME_STAMPER); new VerificationReporter(nullptr); - auto *ccsdsDistrib = - new CcsdsDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR); - new PusDistributor(apid::APID, objects::PUS_DISTRIBUTOR, - ccsdsDistrib); + auto *ccsdsDistrib = new CcsdsDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR); + new PusDistributor(apid::APID, objects::PUS_DISTRIBUTOR, ccsdsDistrib); new TmFunnel(*stamperAndReader, objects::TM_FUNNEL); #endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ /* PUS stack */ #if OBSW_ADD_PUS_STACK == 1 - new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, - apid::APID, pus::PUS_SERVICE_1, - objects::TM_FUNNEL, 5); - new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::APID, - pus::PUS_SERVICE_2, 3, 10); - new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID, - pus::PUS_SERVICE_3); - new Service5EventReporting(PsbParams(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::APID, - pus::PUS_SERVICE_5), 20 , 40); - new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, - apid::APID, pus::PUS_SERVICE_8, 3, 10); - new Service9TimeManagement(PsbParams(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID, - pus::PUS_SERVICE_9)); - new Service17Test(PsbParams(objects::PUS_SERVICE_17_TEST, apid::APID, - pus::PUS_SERVICE_17)); - new Service20ParameterManagement(objects::PUS_SERVICE_20_PARAMETERS, - apid::APID, pus::PUS_SERVICE_20); + new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, apid::APID, + pus::PUS_SERVICE_1, objects::TM_FUNNEL, 5); + new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::APID, pus::PUS_SERVICE_2, 3, + 10); + new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID, pus::PUS_SERVICE_3); + new Service5EventReporting( + PsbParams(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::APID, pus::PUS_SERVICE_5), 20, 40); + new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, apid::APID, + pus::PUS_SERVICE_8, 3, 10); + new Service9TimeManagement( + PsbParams(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID, pus::PUS_SERVICE_9)); + new Service17Test(PsbParams(objects::PUS_SERVICE_17_TEST, apid::APID, pus::PUS_SERVICE_17)); + new Service20ParameterManagement(objects::PUS_SERVICE_20_PARAMETERS, apid::APID, + pus::PUS_SERVICE_20); #if OBSW_ADD_CORE_COMPONENTS == 1 new Service11TelecommandScheduling( PsbParams(objects::PUS_SERVICE_11_TC_SCHEDULER, apid::APID, pus::PUS_SERVICE_11), @@ -100,22 +95,17 @@ void ObjectFactory::produceGenericObjects() { /* Demo device handler object */ size_t expectedMaxReplyLen = 64; - CookieIF *testCookie = - new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_0), - expectedMaxReplyLen); + CookieIF *testCookie = new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_0), + expectedMaxReplyLen); new TestEchoComIF(objects::TEST_ECHO_COM_IF); - new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, - testCookie, testdevice::DeviceIndex::DEVICE_0, - enableInfoPrintout); - testCookie = - new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_1), - expectedMaxReplyLen); - new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, - testCookie, testdevice::DeviceIndex::DEVICE_1, - enableInfoPrintout); + new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, testCookie, + testdevice::DeviceIndex::DEVICE_0, enableInfoPrintout); + testCookie = new TestCookie(static_cast(testdevice::DeviceIndex::DEVICE_1), + expectedMaxReplyLen); + new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie, + testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout); - new TestAssembly(objects::TEST_ASSEMBLY, objects::NO_OBJECT, - objects::TEST_DEVICE_HANDLER_0, + new TestAssembly(objects::TEST_ASSEMBLY, objects::NO_OBJECT, objects::TEST_DEVICE_HANDLER_0, objects::TEST_DEVICE_HANDLER_1); #endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */ diff --git a/example/core/GenericFactory.h b/example/core/GenericFactory.h index 4bbcf2c..3cf5d41 100644 --- a/example/core/GenericFactory.h +++ b/example/core/GenericFactory.h @@ -11,6 +11,6 @@ namespace ObjectFactory { */ void produceGenericObjects(); -} // namespace ObjectFactory +} // namespace ObjectFactory #endif /* MISSION_CORE_GENERICFACTORY_H_ */ diff --git a/example/test/FsfwExampleTask.cpp b/example/test/FsfwExampleTask.cpp index e0dd1fb..edfaf07 100644 --- a/example/test/FsfwExampleTask.cpp +++ b/example/test/FsfwExampleTask.cpp @@ -11,11 +11,11 @@ #include "objects/systemObjectList.h" FsfwExampleTask::FsfwExampleTask(object_id_t objectId) - : SystemObject(objectId), poolManager(this, nullptr), demoSet(this), - monitor(objectId, MONITOR_ID, - gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) { - commandQueue = QueueFactory::instance()->createMessageQueue( - 10, CommandMessage::MAX_MESSAGE_SIZE); + : SystemObject(objectId), + poolManager(this, nullptr), + demoSet(this), + monitor(objectId, MONITOR_ID, gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) { + commandQueue = QueueFactory::instance()->createMessageQueue(10, CommandMessage::MAX_MESSAGE_SIZE); } FsfwExampleTask::~FsfwExampleTask() {} @@ -47,45 +47,43 @@ ReturnValue_t FsfwExampleTask::performOperation(uint8_t operationCode) { object_id_t FsfwExampleTask::getNextRecipient() { switch (this->getObjectId()) { - case (objects::TEST_DUMMY_1): { - return objects::TEST_DUMMY_2; - } - case (objects::TEST_DUMMY_2): { - return objects::TEST_DUMMY_3; - } - case (objects::TEST_DUMMY_3): { - return objects::TEST_DUMMY_1; - } - default: - return objects::TEST_DUMMY_1; + case (objects::TEST_DUMMY_1): { + return objects::TEST_DUMMY_2; + } + case (objects::TEST_DUMMY_2): { + return objects::TEST_DUMMY_3; + } + case (objects::TEST_DUMMY_3): { + return objects::TEST_DUMMY_1; + } + default: + return objects::TEST_DUMMY_1; } } object_id_t FsfwExampleTask::getSender() { switch (this->getObjectId()) { - case (objects::TEST_DUMMY_1): { - return objects::TEST_DUMMY_3; - } - case (objects::TEST_DUMMY_2): { - return objects::TEST_DUMMY_1; - } - case (objects::TEST_DUMMY_3): { - return objects::TEST_DUMMY_2; - } - default: - return objects::TEST_DUMMY_1; + case (objects::TEST_DUMMY_1): { + return objects::TEST_DUMMY_3; + } + case (objects::TEST_DUMMY_2): { + return objects::TEST_DUMMY_1; + } + case (objects::TEST_DUMMY_3): { + return objects::TEST_DUMMY_2; + } + default: + return objects::TEST_DUMMY_1; } } ReturnValue_t FsfwExampleTask::initialize() { // Get the dataset of the sender. Will be cached for later checks. object_id_t sender = getSender(); - HasLocalDataPoolIF *senderIF = - ObjectManager::instance()->get(sender); + HasLocalDataPoolIF *senderIF = ObjectManager::instance()->get(sender); if (senderIF == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::initialize: Sender object invalid!" - << std::endl; + sif::error << "FsfwDemoTask::initialize: Sender object invalid!" << std::endl; #else sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n"); #endif @@ -97,8 +95,7 @@ ReturnValue_t FsfwExampleTask::initialize() { senderSet = new FsfwDemoSet(senderIF); if (senderSet == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::initialize: Sender dataset invalid!" - << std::endl; + sif::error << "FsfwDemoTask::initialize: Sender dataset invalid!" << std::endl; #else sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n"); #endif @@ -111,45 +108,31 @@ ReturnValue_t FsfwExampleTask::initializeAfterTaskCreation() { return poolManager.initializeAfterTaskCreation(); } -object_id_t FsfwExampleTask::getObjectId() const { - return SystemObject::getObjectId(); -} +object_id_t FsfwExampleTask::getObjectId() const { return SystemObject::getObjectId(); } -MessageQueueId_t FsfwExampleTask::getMessageQueueId() { - return commandQueue->getId(); -} +MessageQueueId_t FsfwExampleTask::getMessageQueueId() { return commandQueue->getId(); } void FsfwExampleTask::setTaskIF(PeriodicTaskIF *task) { this->task = task; } -LocalPoolDataSetBase *FsfwExampleTask::getDataSetHandle(sid_t sid) { - return &demoSet; -} +LocalPoolDataSetBase *FsfwExampleTask::getDataSetHandle(sid_t sid) { return &demoSet; } -uint32_t FsfwExampleTask::getPeriodicOperationFrequency() const { - return task->getPeriodMs(); -} +uint32_t FsfwExampleTask::getPeriodicOperationFrequency() const { return task->getPeriodMs(); } -ReturnValue_t -FsfwExampleTask::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, - LocalDataPoolManager &poolManager) { - localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, - new PoolEntry({0})); - localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, - new PoolEntry({0})); +ReturnValue_t FsfwExampleTask::initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) { + localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, new PoolEntry({0})); + localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, new PoolEntry({0})); return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t FsfwExampleTask::performMonitoringDemo() { - ReturnValue_t result = - demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20); + ReturnValue_t result = demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20); if (result != HasReturnvaluesIF::RETURN_OK) { /* Configuration error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "DummyObject::performOperation: Could not read variableLimit!" - << std::endl; + sif::error << "DummyObject::performOperation: Could not read variableLimit!" << std::endl; #else - sif::printError( - "DummyObject::performOperation: Could not read variableLimit!\n"); + sif::printError("DummyObject::performOperation: Could not read variableLimit!\n"); #endif return result; } @@ -166,17 +149,13 @@ ReturnValue_t FsfwExampleTask::performMonitoringDemo() { ReturnValue_t FsfwExampleTask::performSendOperation() { object_id_t nextRecipient = getNextRecipient(); - FsfwExampleTask *target = - ObjectManager::instance()->get(nextRecipient); + FsfwExampleTask *target = ObjectManager::instance()->get(nextRecipient); if (target == nullptr) { /* Configuration error */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error - << "DummyObject::performOperation: Next recipient does not exist!" - << std::endl; + sif::error << "DummyObject::performOperation: Next recipient does not exist!" << std::endl; #else - sif::printError( - "DummyObject::performOperation: Next recipient does not exist!\n"); + sif::printError("DummyObject::performOperation: Next recipient does not exist!\n"); #endif return HasReturnvaluesIF::RETURN_FAILED; } @@ -187,30 +166,23 @@ ReturnValue_t FsfwExampleTask::performSendOperation() { message.setParameter2(this->getMessageQueueId()); /* Send message using own message queue */ - ReturnValue_t result = - commandQueue->sendMessage(target->getMessageQueueId(), &message); - if (result != HasReturnvaluesIF::RETURN_OK && - result != MessageQueueIF::FULL) { + ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message); + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performSendOperation: Send failed with " - << result << std::endl; + sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl; #else - sif::printError( - "FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); + sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); #endif } /* Send message without via MessageQueueSenderIF */ - result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), - &message, commandQueue->getId()); - if (result != HasReturnvaluesIF::RETURN_OK && - result != MessageQueueIF::FULL) { + result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message, + commandQueue->getId()); + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performSendOperation: Send failed with " - << result << std::endl; + sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl; #else - sif::printError( - "FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); + sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); #endif } @@ -225,8 +197,7 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() { while (result != MessageQueueIF::EMPTY) { CommandMessage receivedMessage; result = commandQueue->receiveMessage(&receivedMessage); - if (result != HasReturnvaluesIF::RETURN_OK && - result != MessageQueueIF::EMPTY) { + if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::EMPTY) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "Receive failed with " << result << std::endl; #endif @@ -236,9 +207,8 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() { #if FSFW_CPP_OSTREAM_ENABLED == 1 #if OBSW_VERBOSE_LEVEL >= 2 sif::debug << "Message Received by " << getObjectId() << " from Queue " - << receivedMessage.getSender() << " ObjectId " - << receivedMessage.getParameter() << " Queue " - << receivedMessage.getParameter2() << std::endl; + << receivedMessage.getSender() << " ObjectId " << receivedMessage.getParameter() + << " Queue " << receivedMessage.getParameter2() << std::endl; #endif #endif @@ -252,13 +222,11 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() { } if (senderSet->variableRead.value != receivedMessage.getParameter()) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "FsfwDemoTask::performReceiveOperation: Variable " - << std::hex << "0x" - << senderSet->variableRead.getDataPoolId() << std::dec - << " has wrong value." << std::endl; - sif::error << "Value: " << demoSet.variableRead.value - << ", expected: " << receivedMessage.getParameter() + sif::error << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << "0x" + << senderSet->variableRead.getDataPoolId() << std::dec << " has wrong value." << std::endl; + sif::error << "Value: " << demoSet.variableRead.value + << ", expected: " << receivedMessage.getParameter() << std::endl; #endif } } @@ -266,10 +234,6 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() { return result; } -MessageQueueId_t FsfwExampleTask::getCommandQueue() const { - return commandQueue->getId(); -} +MessageQueueId_t FsfwExampleTask::getCommandQueue() const { return commandQueue->getId(); } -LocalDataPoolManager *FsfwExampleTask::getHkManagerHandle() { - return &poolManager; -} +LocalDataPoolManager *FsfwExampleTask::getHkManagerHandle() { return &poolManager; } diff --git a/example/test/FsfwExampleTask.h b/example/test/FsfwExampleTask.h index 345d2f3..07c7355 100644 --- a/example/test/FsfwExampleTask.h +++ b/example/test/FsfwExampleTask.h @@ -24,10 +24,8 @@ class PeriodicTaskIF; * value directly from the sender via the local data pool interface. * If the timing is set up correctly, the values will always be the same. */ -class FsfwExampleTask : public ExecutableObjectIF, - public SystemObject, - public HasLocalDataPoolIF { -public: +class FsfwExampleTask : public ExecutableObjectIF, public SystemObject, public HasLocalDataPoolIF { + public: enum OpCodes { SEND_RAND_NUM, RECEIVE_RAND_NUM, DELAY_SHORT }; static constexpr uint8_t MONITOR_ID = 2; @@ -80,7 +78,7 @@ public: MessageQueueId_t getMessageQueueId(); -private: + private: LocalDataPoolManager poolManager; FsfwDemoSet *senderSet = nullptr; FsfwDemoSet demoSet; @@ -92,9 +90,8 @@ private: MessageQueueId_t getCommandQueue() const override; LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override; uint32_t getPeriodicOperationFrequency() const override; - ReturnValue_t - initializeLocalDataPool(localpool::DataPool &localDataPoolMap, - LocalDataPoolManager &poolManager) override; + ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, + LocalDataPoolManager &poolManager) override; LocalDataPoolManager *getHkManagerHandle() override; object_id_t getNextRecipient(); diff --git a/example/test/FsfwReaderTask.cpp b/example/test/FsfwReaderTask.cpp index 6e6ac76..f80b4f1 100644 --- a/example/test/FsfwReaderTask.cpp +++ b/example/test/FsfwReaderTask.cpp @@ -7,9 +7,10 @@ #include FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout) - : SystemObject(objectId), printoutEnabled(enablePrintout), opDivider(10), - readSet(this->getObjectId(), - gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE), + : SystemObject(objectId), + printoutEnabled(enablePrintout), + opDivider(10), + readSet(this->getObjectId(), gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE), gp_id_t(objects::TEST_DUMMY_2, FsfwDemoSet::PoolIds::VARIABLE), gp_id_t(objects::TEST_DUMMY_3, FsfwDemoSet::PoolIds::VARIABLE)) { /* Special protection for set reading because each variable is read from a @@ -35,14 +36,12 @@ ReturnValue_t FsfwReaderTask::performOperation(uint8_t operationCode) { #if OBSW_VERBOSE_LEVEL >= 1 if (opDivider.checkAndIncrement() and printoutEnabled) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "FsfwPeriodicTask::performOperation: Reading variables." - << std::endl; + sif::info << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl; sif::info << "Variable read from demo object 1: " << variable1 << std::endl; sif::info << "Variable read from demo object 2: " << variable2 << std::endl; sif::info << "Variable read from demo object 3: " << variable3 << std::endl; #else - sif::printInfo( - "FsfwPeriodicTask::performOperation: Reading variables.\n\r"); + sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r"); sif::printInfo("Variable read from demo object 1: %d\n\r", variable1); sif::printInfo("Variable read from demo object 2: %d\n\r", variable2); sif::printInfo("Variable read from demo object 3: %d\n\r", variable3); diff --git a/example/test/FsfwReaderTask.h b/example/test/FsfwReaderTask.h index 636e9b9..419435e 100644 --- a/example/test/FsfwReaderTask.h +++ b/example/test/FsfwReaderTask.h @@ -8,14 +8,14 @@ #include "testdefinitions/demoDefinitions.h" class FsfwReaderTask : public ExecutableObjectIF, public SystemObject { -public: + public: FsfwReaderTask(object_id_t objectId, bool enablePrintout); ~FsfwReaderTask() override; ReturnValue_t initializeAfterTaskCreation() override; ReturnValue_t performOperation(uint8_t operationCode = 0) override; -private: + private: bool printoutEnabled = false; PeriodicOperationDivider opDivider; CompleteDemoReadSet readSet; diff --git a/example/test/FsfwTestTask.h b/example/test/FsfwTestTask.h index 24125b1..285add9 100644 --- a/example/test/FsfwTestTask.h +++ b/example/test/FsfwTestTask.h @@ -6,16 +6,15 @@ #include "fsfw_tests/integration/task/TestTask.h" class FsfwTestTask : public TestTask { -public: + public: FsfwTestTask(object_id_t objectId, bool periodicEvent); ReturnValue_t performPeriodicAction() override; -private: + private: bool periodicEvent = false; static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; - static constexpr Event TEST_EVENT = - event::makeEvent(subsystemId, 0, severity::INFO); + static constexpr Event TEST_EVENT = event::makeEvent(subsystemId, 0, severity::INFO); }; #endif /* EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ */ diff --git a/example/test/MutexExample.cpp b/example/test/MutexExample.cpp index 7bf7565..8de182c 100644 --- a/example/test/MutexExample.cpp +++ b/example/test/MutexExample.cpp @@ -7,12 +7,10 @@ void MutexExample::example() { MutexIF *mutex = MutexFactory::instance()->createMutex(); MutexIF *mutex2 = MutexFactory::instance()->createMutex(); - ReturnValue_t result = - mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000); + ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Lock Failed with " << result - << std::endl; + sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; #else sif::printError("MutexExample::example: Lock Failed with %hu\n", result); #endif @@ -21,8 +19,7 @@ void MutexExample::example() { result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Lock Failed with " << result - << std::endl; + sif::error << "MutexExample::example: Lock Failed with " << result << std::endl; #else sif::printError("MutexExample::example: Lock Failed with %hu\n", result); #endif @@ -31,8 +28,7 @@ void MutexExample::example() { result = mutex->unlockMutex(); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Unlock Failed with " << result - << std::endl; + sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; #else sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); #endif @@ -41,8 +37,7 @@ void MutexExample::example() { result = mutex2->unlockMutex(); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexExample::example: Unlock Failed with " << result - << std::endl; + sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl; #else sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); #endif diff --git a/example/test/testFmt.h b/example/test/testFmt.h index 5cbe66a..cfe04d5 100644 --- a/example/test/testFmt.h +++ b/example/test/testFmt.h @@ -15,8 +15,7 @@ #include "fsfw/timemanager/Clock.h" #define __FILENAME_REL__ (((const char *)__FILE__ + SOURCE_PATH_SIZE)) -#define __FILENAME__ \ - (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) void fmtTests(); @@ -29,34 +28,26 @@ static const char DEBUG_PREFIX[] = "DEBUG"; static const char WARNING_PREFIX[] = "WARNING"; static const char ERROR_PREFIX[] = "ERROR"; -enum class LogLevel : unsigned int { - DEBUG = 0, - INFO = 1, - WARNING = 2, - ERROR = 3 -}; +enum class LogLevel : unsigned int { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3 }; -static const char *PREFIX_ARR[4] = {DEBUG_PREFIX, INFO_PREFIX, WARNING_PREFIX, - ERROR_PREFIX}; +static const char *PREFIX_ARR[4] = {DEBUG_PREFIX, INFO_PREFIX, WARNING_PREFIX, ERROR_PREFIX}; static const std::array LOG_COLOR_ARR = { - fmt::color::deep_sky_blue, fmt::color::forest_green, fmt::color::orange_red, - fmt::color::red}; + fmt::color::deep_sky_blue, fmt::color::forest_green, fmt::color::orange_red, fmt::color::red}; static MutexIF *PRINT_MUTEX = MutexFactory::instance()->createMutex(); static size_t writeTypePrefix(LogLevel level) { auto idx = static_cast(level); - const auto result = fmt::format_to_n( - PRINT_BUF.begin(), PRINT_BUF.size() - 1, - fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx]))); + const auto result = + fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, + fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx]))); return result.size; } template -size_t logTraced(LogLevel level, const char *file, unsigned int line, - bool timed, fmt::format_string fmt, - T &&...args) noexcept { +size_t logTraced(LogLevel level, const char *file, unsigned int line, bool timed, + fmt::format_string fmt, T &&...args) noexcept { try { MutexGuard mg(PRINT_MUTEX); size_t bufPos = writeTypePrefix(level); @@ -64,17 +55,16 @@ size_t logTraced(LogLevel level, const char *file, unsigned int line, if (timed) { Clock::TimeOfDay_t logTime; Clock::getDateAndTime(&logTime); - const auto result = - fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, - " | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file, - line, logTime.hour, logTime.minute, logTime.second, - logTime.usecond / 1000, fmt::format(fmt, args...)); + const auto result = fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, + " | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file, line, + logTime.hour, logTime.minute, logTime.second, + logTime.usecond / 1000, fmt::format(fmt, args...)); *result.out = '\0'; bufPos += result.size; } else { - const auto result = fmt::format_to_n( - currentIter, PRINT_BUF.size() - 1 - bufPos, " | {}[l.{}] | {}", file, - line, fmt::format(fmt, args...)); + const auto result = + fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, " | {}[l.{}] | {}", file, + line, fmt::format(fmt, args...)); *result.out = '\0'; bufPos += result.size; } @@ -88,8 +78,7 @@ size_t logTraced(LogLevel level, const char *file, unsigned int line, } template -size_t log(LogLevel level, bool timed, fmt::format_string fmt, - T &&...args) noexcept { +size_t log(LogLevel level, bool timed, fmt::format_string fmt, T &&...args) noexcept { try { MutexGuard mg(PRINT_MUTEX); size_t bufPos = writeTypePrefix(level); @@ -98,9 +87,8 @@ size_t log(LogLevel level, bool timed, fmt::format_string fmt, Clock::TimeOfDay_t logTime; Clock::getDateAndTime(&logTime); const auto result = fmt::format_to_n( - currentIter, PRINT_BUF.size() - bufPos, - " | {:02}:{:02}:{:02}.{:03} | {}", logTime.hour, logTime.minute, - logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...)); + currentIter, PRINT_BUF.size() - bufPos, " | {:02}:{:02}:{:02}.{:03} | {}", logTime.hour, + logTime.minute, logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...)); bufPos += result.size; } fmt::print(fmt::runtime(PRINT_BUF.data())); @@ -128,56 +116,47 @@ void finfo_t(fmt::format_string fmt, T &&...args) { log(LogLevel::INFO, true, fmt, args...); } -template void finfo(fmt::format_string fmt, T &&...args) { +template +void finfo(fmt::format_string fmt, T &&...args) { log(LogLevel::INFO, false, fmt, args...); } template -void fwarning(const char *file, unsigned int line, fmt::format_string fmt, - T &&...args) { +void fwarning(const char *file, unsigned int line, fmt::format_string fmt, T &&...args) { logTraced(LogLevel::WARNING, file, line, false, fmt, args...); } template -void fwarning_t(const char *file, unsigned int line, - fmt::format_string fmt, T &&...args) { +void fwarning_t(const char *file, unsigned int line, fmt::format_string fmt, T &&...args) { logTraced(LogLevel::WARNING, file, line, true, fmt, args...); } template -void ferror(const char *file, unsigned int line, fmt::format_string fmt, - T &&...args) { +void ferror(const char *file, unsigned int line, fmt::format_string fmt, T &&...args) { logTraced(LogLevel::ERROR, file, line, false, fmt, args...); } template -void ferror_t(const char *file, unsigned int line, fmt::format_string fmt, - T &&...args) { +void ferror_t(const char *file, unsigned int line, fmt::format_string fmt, T &&...args) { logTraced(LogLevel::ERROR, file, line, true, fmt, args...); } -} // namespace sif +} // namespace sif #define FSFW_LOGI(format, ...) finfo(FMT_STRING(format), __VA_ARGS__) #define FSFW_LOGIT(format, ...) finfo_t(FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGD(format, ...) \ - sif::fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGD(format, ...) sif::fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGDT(format, ...) \ - fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGDT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGW(format, ...) \ - fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGW(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGWT(format, ...) \ - fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGWT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGE(format, ...) \ - fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGE(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#define FSFW_LOGET(format, ...) \ - fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) +#define FSFW_LOGET(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) -#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H +#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H diff --git a/example/test/testdefinitions/demoDefinitions.h b/example/test/testdefinitions/demoDefinitions.h index bd35ce0..25eb440 100644 --- a/example/test/testdefinitions/demoDefinitions.h +++ b/example/test/testdefinitions/demoDefinitions.h @@ -12,22 +12,21 @@ * pool variables (for read and write access respectively). */ class FsfwDemoSet : public StaticLocalDataSet<3> { -public: + public: static constexpr uint32_t DEMO_SET_ID = 0; enum PoolIds { VARIABLE, VARIABLE_LIMIT }; - FsfwDemoSet(HasLocalDataPoolIF *hkOwner) - : StaticLocalDataSet(hkOwner, DEMO_SET_ID) {} + FsfwDemoSet(HasLocalDataPoolIF *hkOwner) : StaticLocalDataSet(hkOwner, DEMO_SET_ID) {} - lp_var_t variableRead = lp_var_t( - sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ); - lp_var_t variableWrite = lp_var_t( - sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE); + lp_var_t variableRead = + lp_var_t(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ); + lp_var_t variableWrite = + lp_var_t(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE); lp_var_t variableLimit = lp_var_t(sid.objectId, PoolIds::VARIABLE_LIMIT, this); -private: + private: }; /** @@ -36,11 +35,10 @@ private: * which reads multiple sensor values at once. */ class CompleteDemoReadSet : public StaticLocalDataSet<3> { -public: + public: static constexpr uint32_t DEMO_SET_ID = 0; - CompleteDemoReadSet(object_id_t owner, gp_id_t variable1, gp_id_t variable2, - gp_id_t variable3) + CompleteDemoReadSet(object_id_t owner, gp_id_t variable1, gp_id_t variable2, gp_id_t variable3) : StaticLocalDataSet(sid_t(owner, DEMO_SET_ID)), variable1(variable1, this, pool_rwm_t::VAR_READ), variable2(variable2, this, pool_rwm_t::VAR_READ), @@ -50,7 +48,7 @@ public: lp_var_t variable2; lp_var_t variable3; -private: + private: }; #endif /* MISSION_DEMO_DEMODEFINITIONS_H_ */ diff --git a/example/utility/PusPacketCreator.h b/example/utility/PusPacketCreator.h index 1aed730..7fa46b7 100644 --- a/example/utility/PusPacketCreator.h +++ b/example/utility/PusPacketCreator.h @@ -9,7 +9,7 @@ #define MISSION_UTILITY_PUSPACKETCREATOR_H_ class PusPacketCreator { -public: + public: static void createPusPacketAndPrint(); }; diff --git a/example/utility/TaskCreation.h b/example/utility/TaskCreation.h index 337c1f7..377cd0f 100644 --- a/example/utility/TaskCreation.h +++ b/example/utility/TaskCreation.h @@ -8,15 +8,14 @@ namespace task { void printInitError(const char *objName, object_id_t objectId) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8) - << std::setfill('0') << std::hex << objectId << std::dec - << ") failed." << std::endl; + sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8) << std::setfill('0') + << std::hex << objectId << std::dec << ") failed." << std::endl; #else sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", objName, static_cast(objectId)); #endif } -} // namespace task +} // namespace task #endif /* MISSION_UTILITY_TASKCREATION_H_ */ diff --git a/example/utility/TmFunnel.cpp b/example/utility/TmFunnel.cpp index 59fa0a8..0dd0eb3 100644 --- a/example/utility/TmFunnel.cpp +++ b/example/utility/TmFunnel.cpp @@ -1,18 +1,19 @@ #include "TmFunnel.h" #include -#include "fsfw/tmtcpacket/pus/tm.h" #include #include #include +#include "fsfw/tmtcpacket/pus/tm.h" + object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT; object_id_t TmFunnel::storageDestination = objects::NO_OBJECT; -TmFunnel::TmFunnel(TimeReaderIF& timeReader, object_id_t objectId, uint32_t messageDepth) +TmFunnel::TmFunnel(TimeReaderIF &timeReader, object_id_t objectId, uint32_t messageDepth) : SystemObject(objectId), timeReader(timeReader), messageDepth(messageDepth) { - tmQueue = QueueFactory::instance()->createMessageQueue( - messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE); + tmQueue = QueueFactory::instance()->createMessageQueue(messageDepth, + MessageQueueMessage::MAX_MESSAGE_SIZE); storageQueue = QueueFactory::instance()->createMessageQueue( messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE); } @@ -45,14 +46,13 @@ ReturnValue_t TmFunnel::performOperation(uint8_t operationCode) { ReturnValue_t TmFunnel::handlePacket(TmTcMessage *message) { uint8_t *packetData = nullptr; size_t size = 0; - ReturnValue_t result = - tmPool->modifyData(message->getStorageId(), &packetData, &size); + ReturnValue_t result = tmPool->modifyData(message->getStorageId(), &packetData, &size); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } PusTmZeroCopyWriter packet(timeReader, packetData, size); result = packet.parseDataWithoutCrcCheck(); - if(result != HasReturnvaluesIF::RETURN_OK) { + if (result != HasReturnvaluesIF::RETURN_OK) { return result; } packet.setSequenceCount(sourceSequenceCount++); @@ -73,8 +73,7 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage *message) { if (result != HasReturnvaluesIF::RETURN_OK) { tmPool->deleteData(message->getStorageId()); #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::handlePacket: Error sending to storage handler" - << std::endl; + sif::error << "TmFunnel::handlePacket: Error sending to storage handler" << std::endl; #endif return result; } @@ -98,8 +97,7 @@ ReturnValue_t TmFunnel::initialize() { ObjectManager::instance()->get(downlinkDestination); if (tmTarget == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmFunnel::initialize: Downlink Destination not set." - << std::endl; + sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl; sif::error << "Make sure the downlink destination object is set up " "properly and implements " "AcceptsTelemetryIF" @@ -114,12 +112,12 @@ ReturnValue_t TmFunnel::initialize() { return SystemObject::initialize(); } - AcceptsTelemetryIF *storageTarget = - ObjectManager::instance()->get(storageDestination); + auto *storageTarget = ObjectManager::instance()->get(storageDestination); if (storageTarget != nullptr) { - storageQueue->setDefaultDestination( - storageTarget->getReportReceptionQueue()); + storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue()); } return SystemObject::initialize(); } + +const char *TmFunnel::getName() const { return "TM Funnel"; } diff --git a/example/utility/TmFunnel.h b/example/utility/TmFunnel.h index 6dca3b4..e74e48e 100644 --- a/example/utility/TmFunnel.h +++ b/example/utility/TmFunnel.h @@ -21,26 +21,25 @@ void setStaticFrameworkObjectIds(); * @ingroup utility * @author J. Meier */ -class TmFunnel : public AcceptsTelemetryIF, - public ExecutableObjectIF, - public SystemObject { +class TmFunnel : public AcceptsTelemetryIF, public ExecutableObjectIF, public SystemObject { friend void(Factory::setStaticFrameworkObjectIds)(); -public: - explicit TmFunnel(TimeReaderIF& timeReader, object_id_t objectId, uint32_t messageDepth = 20); + public: + explicit TmFunnel(TimeReaderIF &timeReader, object_id_t objectId, uint32_t messageDepth = 20); + const char *getName() const override; ~TmFunnel() override; MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; ReturnValue_t performOperation(uint8_t operationCode) override; ReturnValue_t initialize() override; -protected: + protected: static object_id_t downlinkDestination; static object_id_t storageDestination; -private: + private: uint16_t sourceSequenceCount = 0; - TimeReaderIF& timeReader; + TimeReaderIF &timeReader; MessageQueueIF *tmQueue = nullptr; MessageQueueIF *storageQueue = nullptr; diff --git a/example/utility/compile_time.h b/example/utility/compile_time.h index 8d9f9e0..ad1afc0 100644 --- a/example/utility/compile_time.h +++ b/example/utility/compile_time.h @@ -39,19 +39,19 @@ #define CONV_STR2DEC_4(str, i) (CONV_STR2DEC_3(str, i) * 10 + str[i + 3] - '0') // Custom "glue logic" to convert the month name to a usable number -#define GET_MONTH(str, i) \ - (str[i] == 'J' && str[i + 1] == 'a' && str[i + 2] == 'n' ? 1 \ - : str[i] == 'F' && str[i + 1] == 'e' && str[i + 2] == 'b' ? 2 \ - : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'r' ? 3 \ - : str[i] == 'A' && str[i + 1] == 'p' && str[i + 2] == 'r' ? 4 \ - : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'y' ? 5 \ - : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'n' ? 6 \ - : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'l' ? 7 \ - : str[i] == 'A' && str[i + 1] == 'u' && str[i + 2] == 'g' ? 8 \ - : str[i] == 'S' && str[i + 1] == 'e' && str[i + 2] == 'p' ? 9 \ - : str[i] == 'O' && str[i + 1] == 'c' && str[i + 2] == 't' ? 10 \ - : str[i] == 'N' && str[i + 1] == 'o' && str[i + 2] == 'v' ? 11 \ - : str[i] == 'D' && str[i + 1] == 'e' && str[i + 2] == 'c' ? 12 \ +#define GET_MONTH(str, i) \ + (str[i] == 'J' && str[i + 1] == 'a' && str[i + 2] == 'n' ? 1 \ + : str[i] == 'F' && str[i + 1] == 'e' && str[i + 2] == 'b' ? 2 \ + : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'r' ? 3 \ + : str[i] == 'A' && str[i + 1] == 'p' && str[i + 2] == 'r' ? 4 \ + : str[i] == 'M' && str[i + 1] == 'a' && str[i + 2] == 'y' ? 5 \ + : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'n' ? 6 \ + : str[i] == 'J' && str[i + 1] == 'u' && str[i + 2] == 'l' ? 7 \ + : str[i] == 'A' && str[i + 1] == 'u' && str[i + 2] == 'g' ? 8 \ + : str[i] == 'S' && str[i + 1] == 'e' && str[i + 2] == 'p' ? 9 \ + : str[i] == 'O' && str[i + 1] == 'c' && str[i + 2] == 't' ? 10 \ + : str[i] == 'N' && str[i + 1] == 'o' && str[i + 2] == 'v' ? 11 \ + : str[i] == 'D' && str[i + 1] == 'e' && str[i + 2] == 'c' ? 12 \ : 0) // extract the information from the time string given by __TIME__ and __DATE__ @@ -63,37 +63,30 @@ #define __TIME_YEARS__ CONV_STR2DEC_4(__DATE__, 7) // Days in February -#define _UNIX_TIMESTAMP_FDAY(year) \ - (((year) % 400) == 0UL \ - ? 29UL \ - : (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL))) +#define _UNIX_TIMESTAMP_FDAY(year) \ + (((year) % 400) == 0UL ? 29UL \ + : (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL))) // Days in the year -#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ - (/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \ - (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \ - (month >= 4 ? 31UL : 0UL) /* May */ + \ - (month >= 5 ? 30UL : 0UL) /* June */ + \ - (month >= 6 ? 31UL : 0UL) /* July */ + \ - (month >= 7 ? 30UL : 0UL) /* August */ + \ - (month >= 8 ? 31UL : 0UL) /* September */ + \ - (month >= 9 ? 31UL : 0UL) /* October */ + \ - (month >= 10 ? 30UL : 0UL) /* November */ + \ - (month >= 11 ? 31UL : 0UL) /* December */ + (month >= 12 ? 30UL : 0UL)) +#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ + (/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \ + (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \ + (month >= 4 ? 31UL : 0UL) /* May */ + (month >= 5 ? 30UL : 0UL) /* June */ + \ + (month >= 6 ? 31UL : 0UL) /* July */ + (month >= 7 ? 30UL : 0UL) /* August */ + \ + (month >= 8 ? 31UL : 0UL) /* September */ + (month >= 9 ? 31UL : 0UL) /* October */ + \ + (month >= 10 ? 30UL : 0UL) /* November */ + (month >= 11 ? 31UL : 0UL) /* December */ + \ + (month >= 12 ? 30UL : 0UL)) // get the UNIX timestamp from a digits representation -#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ - (/* time */ second + minute * SEC_PER_MIN + hour * SEC_PER_HOUR + \ - /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * \ - SEC_PER_DAY + \ - /* year */ (year - 1970UL) * SEC_PER_YEAR + \ - ((year - 1969UL) / 4UL) * SEC_PER_DAY - \ - ((year - 1901UL) / 100UL) * SEC_PER_DAY + \ - ((year - 1601UL) / 400UL) * SEC_PER_DAY) +#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ + (/* time */ second + minute * SEC_PER_MIN + hour * SEC_PER_HOUR + \ + /* year day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * SEC_PER_DAY + \ + /* year */ (year - 1970UL) * SEC_PER_YEAR + ((year - 1969UL) / 4UL) * SEC_PER_DAY - \ + ((year - 1901UL) / 100UL) * SEC_PER_DAY + ((year - 1601UL) / 400UL) * SEC_PER_DAY) // the UNIX timestamp -#define UNIX_TIMESTAMP \ - (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, \ - __TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__)) +#define UNIX_TIMESTAMP \ + (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, \ + __TIME_MINUTES__, __TIME_SECONDS__)) #endif diff --git a/example/utility/utility.cpp b/example/utility/utility.cpp index 451eb96..ed56ad9 100644 --- a/example/utility/utility.cpp +++ b/example/utility/utility.cpp @@ -10,11 +10,9 @@ void utility::commonInitPrint(const char *const os, const char *const board) { } #if FSFW_CPP_OSTREAM_ENABLED == 1 std::cout << "-- FSFW Example (" << os << ") v" << FSFW_EXAMPLE_VERSION << "." - << FSFW_EXAMPLE_SUBVERSION << "." << FSFW_EXAMPLE_REVISION << " --" - << std::endl; + << FSFW_EXAMPLE_SUBVERSION << "." << FSFW_EXAMPLE_REVISION << " --" << std::endl; std::cout << "-- Compiled for " << board << " --" << std::endl; - std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --" - << 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); diff --git a/stm32h7/STM32TestTask.cpp b/stm32h7/STM32TestTask.cpp index c41810e..a2e5526 100644 --- a/stm32h7/STM32TestTask.cpp +++ b/stm32h7/STM32TestTask.cpp @@ -3,8 +3,7 @@ #include "OBSWConfig.h" #include "stm32h7xx_nucleo.h" -STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, - bool blinkyLed) +STM32TestTask::STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed) : TestTask(objectId), blinkyLed(blinkyLed) { BSP_LED_Init(LED1); BSP_LED_Init(LED2); @@ -21,7 +20,7 @@ ReturnValue_t STM32TestTask::initialize() { ReturnValue_t STM32TestTask::performPeriodicAction() { if (blinkyLed) { -#if OBSW_ETHERNET_USE_LED1_LED2 == 0 +#if OBSW_ETHERNET_USE_LED1_LED2 == 0 BSP_LED_Toggle(LED1); BSP_LED_Toggle(LED2); #endif diff --git a/stm32h7/STM32TestTask.h b/stm32h7/STM32TestTask.h index 4cb2a72..66f37d0 100644 --- a/stm32h7/STM32TestTask.h +++ b/stm32h7/STM32TestTask.h @@ -5,14 +5,13 @@ #include "fsfw_tests/integration/task/TestTask.h" class STM32TestTask : public TestTask { -public: - STM32TestTask(object_id_t objectId, bool enablePrintout, - bool blinkyLed = true); + public: + STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed = true); ReturnValue_t initialize() override; ReturnValue_t performPeriodicAction() override; -private: + private: SpiComIF *spiComIF = nullptr; SpiTest *spiTest = nullptr; diff --git a/stm32h7/networking/TmTcLwIpUdpBridge.cpp b/stm32h7/networking/TmTcLwIpUdpBridge.cpp index 8f66606..97cbb76 100644 --- a/stm32h7/networking/TmTcLwIpUdpBridge.cpp +++ b/stm32h7/networking/TmTcLwIpUdpBridge.cpp @@ -1,6 +1,5 @@ #include "TmTcLwIpUdpBridge.h" - #include #include #include @@ -8,10 +7,8 @@ #include "app_ethernet.h" #include "udp_config.h" -TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, - object_id_t ccsdsPacketDistributor, - object_id_t tmStoreId, - object_id_t tcStoreId) +TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, + object_id_t tmStoreId, object_id_t tcStoreId) : TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) { TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY; } @@ -40,8 +37,7 @@ ReturnValue_t TmTcLwIpUdpBridge::udp_server_init() { if (err == ERR_OK) { /* Set a receive callback for the upcb */ - udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback, - (void *)this); + udp_recv(TmTcLwIpUdpBridge::upcb, &udp_server_receive_callback, (void *)this); return RETURN_OK; } else { udp_remove(TmTcLwIpUdpBridge::upcb); @@ -64,15 +60,13 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) { int ipAddress4 = ipAddress & 0xFF; #if OBSW_VERBOSE_LEVEL == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec - << ipAddress4 << "." << ipAddress3 << "." << ipAddress2 << "." - << ipAddress1 << std::endl; + sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec << ipAddress4 << "." + << ipAddress3 << "." << ipAddress2 << "." << ipAddress1 << std::endl; uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); - sif::info << "TmTcLwIpUdpBridge: Client IP Port " << (int)portSwapped - << std::endl; + sif::info << "TmTcLwIpUdpBridge: Client IP Port " << (int)portSwapped << std::endl; #else - sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", - ipAddress4, ipAddress3, ipAddress2, ipAddress1); + sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", ipAddress4, ipAddress3, + ipAddress2, ipAddress1); uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped); #endif @@ -86,8 +80,7 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) { ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { struct pbuf *p_tx = pbuf_alloc(PBUF_TRANSPORT, dataLen, PBUF_RAM); - if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && - (upcb != nullptr)) { + if ((p_tx != nullptr) && (lastAdd.addr != IPADDR_TYPE_ANY) && (upcb != nullptr)) { /* copy data to pbuf */ err_t err = pbuf_take(p_tx, (const char *)data, dataLen); if (err != ERR_OK) { @@ -115,20 +108,18 @@ ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { return RETURN_OK; } -void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, - struct udp_pcb *upcb_, - struct pbuf *p, - const ip_addr_t *addr, +void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, struct udp_pcb *upcb_, + struct pbuf *p, const ip_addr_t *addr, u16_t port) { auto udpBridge = reinterpret_cast(arg); if (udpBridge == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning - << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!" - << std::endl; + sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!" + << std::endl; #else - sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid " - "UDP bridge!\n"); + sif::printWarning( + "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid " + "UDP bridge!\n"); #endif } /* allocate pbuf from RAM*/ @@ -159,8 +150,8 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg, #endif store_address_t storeId; - ReturnValue_t returnValue = udpBridge->tcStore->addData( - &storeId, reinterpret_cast(p->payload), p->len); + ReturnValue_t returnValue = + udpBridge->tcStore->addData(&storeId, reinterpret_cast(p->payload), p->len); if (returnValue != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "UDP Server: Data storage failed" << std::endl; diff --git a/stm32h7/networking/TmTcLwIpUdpBridge.h b/stm32h7/networking/TmTcLwIpUdpBridge.h index 61e80cc..d9a2366 100644 --- a/stm32h7/networking/TmTcLwIpUdpBridge.h +++ b/stm32h7/networking/TmTcLwIpUdpBridge.h @@ -1,12 +1,12 @@ #ifndef BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ #define BSP_STM32_RTEMS_NETWORKING_TMTCUDPBRIDGE_H_ -#include "fsfw/tmtcservices/TmTcBridge.h" -#include "commonConfig.h" - #include #include +#include "commonConfig.h" +#include "fsfw/tmtcservices/TmTcBridge.h" + /** * This bridge is used to forward TMTC packets received via LwIP UDP to the * internal software bus. @@ -14,9 +14,9 @@ class TmTcLwIpUdpBridge : public TmTcBridge { friend class UdpTcLwIpPollingTask; -public: - TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, - object_id_t tmStoreId, object_id_t tcStoreId); + public: + TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, object_id_t tmStoreId, + object_id_t tcStoreId); ~TmTcLwIpUdpBridge() override; ReturnValue_t initialize() override; @@ -45,9 +45,8 @@ public: * @param addr Source address which will be bound to TmTcUdpBridge::lastAdd * @param port */ - static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_, - struct pbuf *p, const ip_addr_t *addr, - u16_t port); + static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_, struct pbuf *p, + const ip_addr_t *addr, u16_t port); /** * Check whether the communication link is up. @@ -56,7 +55,7 @@ public: */ [[nodiscard]] bool comLinkUp() const; -private: + private: struct udp_pcb *upcb = nullptr; ip_addr_t lastAdd{}; u16_t lastPort = 0; diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.cpp b/stm32h7/networking/UdpTcLwIpPollingTask.cpp index 9b426f8..8b9bb2e 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.cpp +++ b/stm32h7/networking/UdpTcLwIpPollingTask.cpp @@ -10,11 +10,9 @@ #include "lwip/timeouts.h" #include "networking.h" -UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, - object_id_t bridgeId, +UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif *gnetif) - : SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), - gnetif(gnetif) {} + : SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {} UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() = default; @@ -47,8 +45,7 @@ ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) { /* In case ethernet cable is disconnected */ if (not networking::getEthCableConnected() and udpBridge->comLinkUp()) { udpBridge->physicalConnectStatusChange(false); - } else if (networking::getEthCableConnected() and - not udpBridge->comLinkUp()) { + } else if (networking::getEthCableConnected() and not udpBridge->comLinkUp()) { udpBridge->physicalConnectStatusChange(true); } } diff --git a/stm32h7/networking/UdpTcLwIpPollingTask.h b/stm32h7/networking/UdpTcLwIpPollingTask.h index 40f688e..5b66b7e 100644 --- a/stm32h7/networking/UdpTcLwIpPollingTask.h +++ b/stm32h7/networking/UdpTcLwIpPollingTask.h @@ -14,9 +14,8 @@ class TmTcLwIpUdpBridge; class UdpTcLwIpPollingTask : public SystemObject, public ExecutableObjectIF, public HasReturnvaluesIF { -public: - UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, - struct netif *gnetif); + public: + UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif *gnetif); ~UdpTcLwIpPollingTask() override; ReturnValue_t initialize() override; @@ -28,7 +27,7 @@ public: */ ReturnValue_t performOperation(uint8_t operationCode) override; -private: + private: static const uint8_t PERIODIC_HANDLE_TRIGGER = 5; uint8_t periodicHandleCounter; object_id_t bridgeId = 0; diff --git a/stm32h7/networking/app_dhcp.cpp b/stm32h7/networking/app_dhcp.cpp index 6f53c7c..c210a4b 100644 --- a/stm32h7/networking/app_dhcp.cpp +++ b/stm32h7/networking/app_dhcp.cpp @@ -24,22 +24,22 @@ void handle_dhcp_down(struct netif *netif); void DHCP_Process(struct netif *netif) { struct dhcp *dhcp = nullptr; switch (DHCP_state) { - case DHCP_START: { - handle_dhcp_start(netif); - break; - } - case DHCP_WAIT_ADDRESS: { - handle_dhcp_wait(netif, &dhcp); - break; - } + case DHCP_START: { + handle_dhcp_start(netif); + break; + } + case DHCP_WAIT_ADDRESS: { + handle_dhcp_wait(netif, &dhcp); + break; + } - case DHCP_LINK_DOWN: { - handle_dhcp_down(netif); - break; - } - default: { - break; - } + case DHCP_LINK_DOWN: { + handle_dhcp_down(netif); + break; + } + default: { + break; + } } } @@ -107,8 +107,7 @@ void handle_dhcp_start(struct netif *netif) { void handle_dhcp_wait(struct netif *netif, struct dhcp **dhcp) { if (dhcp_supplied_address(netif)) { DHCP_state = DHCP_ADDRESS_ASSIGNED; - printf("IP address assigned by a DHCP server: %s\n\r", - ip4addr_ntoa(netif_ip4_addr(netif))); + printf("IP address assigned by a DHCP server: %s\n\r", ip4addr_ntoa(netif_ip4_addr(netif))); printf("Listener port: %d\n\r", UDP_SERVER_PORT); #if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1 @@ -117,8 +116,8 @@ void handle_dhcp_wait(struct netif *netif, struct dhcp **dhcp) { #endif #endif } else { - *dhcp = static_cast(netif_get_client_data( - netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)); + *dhcp = + static_cast(netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP)); /* DHCP timeout */ if ((*dhcp)->tries > MAX_DHCP_TRIES) { diff --git a/stm32h7/networking/app_ethernet.cpp b/stm32h7/networking/app_ethernet.cpp index 5edc1ad..e137647 100644 --- a/stm32h7/networking/app_ethernet.cpp +++ b/stm32h7/networking/app_ethernet.cpp @@ -47,8 +47,8 @@ void handle_status_change(struct netif *netif, bool link_up) { #else uint8_t iptxt[20]; sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); - printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r", - iptxt, UDP_SERVER_PORT); + printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r", iptxt, + UDP_SERVER_PORT); #if OBSW_ETHERNET_USE_LED1_LED2 == 1 BSP_LED_On(LED1); BSP_LED_Off(LED2); diff --git a/stm32h7/networking/app_ethernet.h b/stm32h7/networking/app_ethernet.h index 2867659..4662ff3 100644 --- a/stm32h7/networking/app_ethernet.h +++ b/stm32h7/networking/app_ethernet.h @@ -65,7 +65,7 @@ namespace networking { void ethernetLinkStatusUpdated(struct netif *netif); void ethernetLinkPeriodicHandle(struct netif *netif); -} // namespace networking +} // namespace networking #ifdef __cplusplus } diff --git a/stm32h7/networking/ethernetif.c b/stm32h7/networking/ethernetif.c index 38f21dc..31df942 100644 --- a/stm32h7/networking/ethernetif.c +++ b/stm32h7/networking/ethernetif.c @@ -44,17 +44,18 @@ */ /* Includes ------------------------------------------------------------------*/ -#include "stm32h7xx_hal.h" -#include "lwip/opt.h" -#include "lwip/timeouts.h" -#include "lwip/netif.h" -#include "netif/etharp.h" #include "ethernetif.h" -#include "lan8742.h" -#include #include +#include + #include "fsfw/FSFW.h" +#include "lan8742.h" +#include "lwip/netif.h" +#include "lwip/opt.h" +#include "lwip/timeouts.h" +#include "netif/etharp.h" +#include "stm32h7xx_hal.h" #ifdef FSFW_OSAL_RTEMS #include @@ -66,11 +67,11 @@ #define IFNAME0 's' #define IFNAME1 't' -#define ETH_DMA_TRANSMIT_TIMEOUT (20U) +#define ETH_DMA_TRANSMIT_TIMEOUT (20U) -#define ETH_RX_BUFFER_SIZE 1536U -#define ETH_RX_BUFFER_CNT 12U -#define ETH_TX_BUFFER_MAX ((ETH_TX_DESC_CNT) * 2U) +#define ETH_RX_BUFFER_SIZE 1536U +#define ETH_RX_BUFFER_CNT 12U +#define ETH_TX_BUFFER_MAX ((ETH_TX_DESC_CNT)*2U) #define DMA_DESCRIPTOR_ALIGNMENT 0x20 @@ -93,49 +94,47 @@ stack they will return back to DMA after been processed by the stack. 2.b. Rx Buffers must have the same size: ETH_RX_BUFFER_SIZE, this value must passed to ETH DMA in the init field (EthHandle.Init.RxBuffLen) */ -typedef enum -{ - RX_ALLOC_OK = 0x00, - RX_ALLOC_ERROR = 0x01 -} RxAllocStatusTypeDef; +typedef enum { RX_ALLOC_OK = 0x00, RX_ALLOC_ERROR = 0x01 } RxAllocStatusTypeDef; -typedef struct -{ +typedef struct { struct pbuf_custom pbuf_custom; uint8_t buff[(ETH_RX_BUFFER_SIZE + 31) & ~31] __ALIGNED(32); } RxBuff_t; #if defined(__ICCARM__) /*!< IAR Compiler */ -#pragma location=0x30000000 -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ -#pragma location=0x30000200 -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ - +#pragma location = 0x30000000 +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ +#pragma location = 0x30000200 +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ #elif defined(__CC_ARM) /* MDK ARM Compiler */ -__attribute__((section(".RxDecripSection"))) ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ -__attribute__((section(".TxDecripSection"))) ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ +__attribute__((section(".RxDecripSection"))) +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ +__attribute__((section(".TxDecripSection"))) +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ #elif defined(__GNUC__) /* GNU Compiler */ #ifdef FSFW_OSAL_RTEMS /* Put into special RTEMS section and align correctly */ -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__(( - section(".bsp_nocache"), - __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] + __attribute__((section(".bsp_nocache"), + __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ /* Put into special RTEMS section and align correctly */ -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__(( - section(".bsp_nocache"), - __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] + __attribute__((section(".bsp_nocache"), + __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ /* Ethernet Receive Buffers. Just place somewhere is BSS instead of explicitely * placing it */ uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; #elif defined FSFW_OSAL_FREERTOS -ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ -ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ +ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] + __attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ +ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] + __attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ #endif /* FSFW_OSAL_RTEMS */ @@ -144,14 +143,14 @@ ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((section(".TxDecr /* Memory Pool Declaration */ LWIP_MEMPOOL_DECLARE(RX_POOL, ETH_RX_BUFFER_CNT, sizeof(RxBuff_t), "Zero-copy RX PBUF pool"); -#if defined ( __ICCARM__ ) /*!< IAR Compiler */ +#if defined(__ICCARM__) /*!< IAR Compiler */ #pragma location = 0x30000400 extern u8_t memp_memory_RX_POOL_base[]; -#elif defined ( __CC_ARM ) /* MDK ARM Compiler */ +#elif defined(__CC_ARM) /* MDK ARM Compiler */ __attribute__((section(".Rx_PoolSection"))) extern u8_t memp_memory_RX_POOL_base[]; -#elif defined ( __GNUC__ ) /* GNU Compiler */ +#elif defined(__GNUC__) /* GNU Compiler */ __attribute__((section(".Rx_PoolSection"))) extern u8_t memp_memory_RX_POOL_base[]; #endif @@ -170,17 +169,14 @@ ETH_TxPacketConfig TxConfig; u32_t sys_now(void); extern void Error_Handler(void); int32_t ETH_PHY_IO_Init(void); -int32_t ETH_PHY_IO_DeInit (void); +int32_t ETH_PHY_IO_DeInit(void); int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal); int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal); int32_t ETH_PHY_IO_GetTick(void); lan8742_Object_t LAN8742; -lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, - ETH_PHY_IO_DeInit, - ETH_PHY_IO_WriteReg, - ETH_PHY_IO_ReadReg, - ETH_PHY_IO_GetTick}; +lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, ETH_PHY_IO_DeInit, ETH_PHY_IO_WriteReg, + ETH_PHY_IO_ReadReg, ETH_PHY_IO_GetTick}; /* Private functions ---------------------------------------------------------*/ void pbuf_free_custom(struct pbuf *p); @@ -195,7 +191,8 @@ void pbuf_free_custom(struct pbuf *p); * for this ethernetif */ static void low_level_init(struct netif *netif) { - uint8_t macaddress[6]= {ETH_MAC_ADDR0, ETH_MAC_ADDR1, ETH_MAC_ADDR2, ETH_MAC_ADDR3, ETH_MAC_ADDR4, ETH_MAC_ADDR5}; + uint8_t macaddress[6] = {ETH_MAC_ADDR0, ETH_MAC_ADDR1, ETH_MAC_ADDR2, + ETH_MAC_ADDR3, ETH_MAC_ADDR4, ETH_MAC_ADDR5}; EthHandle.Instance = ETH; EthHandle.Init.MACAddr = macaddress; @@ -211,12 +208,12 @@ static void low_level_init(struct netif *netif) { netif->hwaddr_len = ETH_HWADDR_LEN; /* set MAC hardware address */ - netif->hwaddr[0] = ETH_MAC_ADDR0; - netif->hwaddr[1] = ETH_MAC_ADDR1; - netif->hwaddr[2] = ETH_MAC_ADDR2; - netif->hwaddr[3] = ETH_MAC_ADDR3; - netif->hwaddr[4] = ETH_MAC_ADDR4; - netif->hwaddr[5] = ETH_MAC_ADDR5; + netif->hwaddr[0] = ETH_MAC_ADDR0; + netif->hwaddr[1] = ETH_MAC_ADDR1; + netif->hwaddr[2] = ETH_MAC_ADDR2; + netif->hwaddr[3] = ETH_MAC_ADDR3; + netif->hwaddr[4] = ETH_MAC_ADDR4; + netif->hwaddr[5] = ETH_MAC_ADDR5; /* maximum transfer unit */ netif->mtu = ETH_MAX_PAYLOAD; @@ -229,7 +226,7 @@ static void low_level_init(struct netif *netif) { LWIP_MEMPOOL_INIT(RX_POOL); /* Set Tx packet config common parameters */ - memset(&TxConfig, 0 , sizeof(ETH_TxPacketConfig)); + memset(&TxConfig, 0, sizeof(ETH_TxPacketConfig)); TxConfig.Attributes = ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD; TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC; TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT; @@ -265,23 +262,19 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { err_t errval = ERR_OK; ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT] = {0}; - memset(Txbuffer, 0 , ETH_TX_DESC_CNT*sizeof(ETH_BufferTypeDef)); + memset(Txbuffer, 0, ETH_TX_DESC_CNT * sizeof(ETH_BufferTypeDef)); - for(q = p; q != NULL; q = q->next) - { - if(i >= ETH_TX_DESC_CNT) - return ERR_IF; + for (q = p; q != NULL; q = q->next) { + if (i >= ETH_TX_DESC_CNT) return ERR_IF; Txbuffer[i].buffer = q->payload; Txbuffer[i].len = q->len; - if(i>0) - { - Txbuffer[i-1].next = &Txbuffer[i]; + if (i > 0) { + Txbuffer[i - 1].next = &Txbuffer[i]; } - if(q->next == NULL) - { + if (q->next == NULL) { Txbuffer[i].next = NULL; } @@ -294,8 +287,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, ETH_DMA_TRANSMIT_TIMEOUT); if (ret != HAL_OK) { - printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r", - ret); + printf("low_level_output: Could not transmit ethernet packet, code %d!\n\r", ret); } return errval; } @@ -311,8 +303,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { static struct pbuf *low_level_input(struct netif *netif) { struct pbuf *p = NULL; - if(RxAllocStatus == RX_ALLOC_OK) - { + if (RxAllocStatus == RX_ALLOC_OK) { HAL_ETH_ReadData(&EthHandle, (void **)&p); } @@ -331,19 +322,15 @@ static struct pbuf *low_level_input(struct netif *netif) { void ethernetif_input(struct netif *netif) { struct pbuf *p = NULL; - do - { - p = low_level_input( netif ); - if (p != NULL) - { - if (netif->input( p, netif) != ERR_OK ) - { + do { + p = low_level_input(netif); + if (p != NULL) { + if (netif->input(p, netif) != ERR_OK) { pbuf_free(p); } } - } while(p!=NULL); - + } while (p != NULL); } /** @@ -388,12 +375,11 @@ err_t ethernetif_init(struct netif *netif) { * @retval None */ void pbuf_free_custom(struct pbuf *p) { - struct pbuf_custom* custom_pbuf = (struct pbuf_custom*)p; + struct pbuf_custom *custom_pbuf = (struct pbuf_custom *)p; LWIP_MEMPOOL_FREE(RX_POOL, custom_pbuf); /* If the Rx Buffer Pool was exhausted, signal the ethernetif_input task to * call HAL_ETH_GetRxDataBuffer to rebuild the Rx descriptors. */ - if (RxAllocStatus == RX_ALLOC_ERROR) - { + if (RxAllocStatus == RX_ALLOC_ERROR) { RxAllocStatus = RX_ALLOC_OK; } } @@ -505,10 +491,8 @@ int32_t ETH_PHY_IO_DeInit(void) { return 0; } * @param pRegVal: pointer to hold the register value * @retval 0 if OK -1 if Error */ -int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, - uint32_t *pRegVal) { - if (HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) != - HAL_OK) { +int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal) { + if (HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) != HAL_OK) { return -1; } @@ -522,10 +506,8 @@ int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, * @param RegVal: Value to be written * @retval 0 if OK -1 if Error */ -int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, - uint32_t RegVal) { - if (HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) != - HAL_OK) { +int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal) { + if (HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) != HAL_OK) { return -1; } @@ -549,42 +531,37 @@ void ethernet_link_check_state(struct netif *netif) { PHYLinkState = LAN8742_GetLinkState(&LAN8742); - if(netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN)) - { + if (netif_is_link_up(netif) && (PHYLinkState <= LAN8742_STATUS_LINK_DOWN)) { HAL_ETH_Stop_IT(&EthHandle); netif_set_down(netif); netif_set_link_down(netif); - } - else if(!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) - { - switch (PHYLinkState) - { - case LAN8742_STATUS_100MBITS_FULLDUPLEX: - duplex = ETH_FULLDUPLEX_MODE; - speed = ETH_SPEED_100M; - linkchanged = 1; - break; - case LAN8742_STATUS_100MBITS_HALFDUPLEX: - duplex = ETH_HALFDUPLEX_MODE; - speed = ETH_SPEED_100M; - linkchanged = 1; - break; - case LAN8742_STATUS_10MBITS_FULLDUPLEX: - duplex = ETH_FULLDUPLEX_MODE; - speed = ETH_SPEED_10M; - linkchanged = 1; - break; - case LAN8742_STATUS_10MBITS_HALFDUPLEX: - duplex = ETH_HALFDUPLEX_MODE; - speed = ETH_SPEED_10M; - linkchanged = 1; - break; - default: - break; + } else if (!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) { + switch (PHYLinkState) { + case LAN8742_STATUS_100MBITS_FULLDUPLEX: + duplex = ETH_FULLDUPLEX_MODE; + speed = ETH_SPEED_100M; + linkchanged = 1; + break; + case LAN8742_STATUS_100MBITS_HALFDUPLEX: + duplex = ETH_HALFDUPLEX_MODE; + speed = ETH_SPEED_100M; + linkchanged = 1; + break; + case LAN8742_STATUS_10MBITS_FULLDUPLEX: + duplex = ETH_FULLDUPLEX_MODE; + speed = ETH_SPEED_10M; + linkchanged = 1; + break; + case LAN8742_STATUS_10MBITS_HALFDUPLEX: + duplex = ETH_HALFDUPLEX_MODE; + speed = ETH_SPEED_10M; + linkchanged = 1; + break; + default: + break; } - if(linkchanged) - { + if (linkchanged) { /* Get MAC Config MAC */ HAL_ETH_GetMACConfig(&EthHandle, &MACConf); MACConf.DuplexMode = duplex; @@ -597,28 +574,23 @@ void ethernet_link_check_state(struct netif *netif) { } } -void HAL_ETH_RxAllocateCallback(uint8_t **buff) -{ +void HAL_ETH_RxAllocateCallback(uint8_t **buff) { struct pbuf_custom *p = LWIP_MEMPOOL_ALLOC(RX_POOL); - if (p) - { + if (p) { /* Get the buff from the struct pbuf address. */ *buff = (uint8_t *)p + offsetof(RxBuff_t, buff); p->custom_free_function = pbuf_free_custom; /* Initialize the struct pbuf. - * This must be performed whenever a buffer's allocated because it may be - * changed by lwIP or the app, e.g., pbuf_free decrements ref. */ + * This must be performed whenever a buffer's allocated because it may be + * changed by lwIP or the app, e.g., pbuf_free decrements ref. */ pbuf_alloced_custom(PBUF_RAW, 0, PBUF_REF, p, *buff, ETH_RX_BUFFER_SIZE); - } - else - { + } else { RxAllocStatus = RX_ALLOC_ERROR; *buff = NULL; } } -void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length) -{ +void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t Length) { struct pbuf **ppStart = (struct pbuf **)pStart; struct pbuf **ppEnd = (struct pbuf **)pEnd; struct pbuf *p = NULL; @@ -630,22 +602,18 @@ void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t p->len = Length; /* Chain the buffer. */ - if (!*ppStart) - { + if (!*ppStart) { /* The first buffer of the packet. */ *ppStart = p; - } - else - { + } else { /* Chain the buffer to the end of the packet. */ (*ppEnd)->next = p; } - *ppEnd = p; + *ppEnd = p; - /* Update the total length of all the buffers of the chain. Each pbuf in the chain should have its tot_len - * set to its own length, plus the length of all the following pbufs in the chain. */ - for (p = *ppStart; p != NULL; p = p->next) - { + /* Update the total length of all the buffers of the chain. Each pbuf in the chain should have its + * tot_len set to its own length, plus the length of all the following pbufs in the chain. */ + for (p = *ppStart; p != NULL; p = p->next) { p->tot_len += Length; } @@ -653,10 +621,7 @@ void HAL_ETH_RxLinkCallback(void **pStart, void **pEnd, uint8_t *buff, uint16_t SCB_InvalidateDCache_by_Addr((uint32_t *)buff, Length); } -void HAL_ETH_TxFreeCallback(uint32_t * buff) -{ - pbuf_free((struct pbuf *)buff); -} +void HAL_ETH_TxFreeCallback(uint32_t *buff) { pbuf_free((struct pbuf *)buff); } ETH_HandleTypeDef *getEthernetHandle() { return &EthHandle; } diff --git a/stm32h7/networking/networking.cpp b/stm32h7/networking/networking.cpp index dfa4ad7..01e72ea 100644 --- a/stm32h7/networking/networking.cpp +++ b/stm32h7/networking/networking.cpp @@ -4,14 +4,11 @@ bool ethernetCableConnected = false; -void networking::setEthCableConnected(bool status) { - ethernetCableConnected = status; -} +void networking::setEthCableConnected(bool status) { ethernetCableConnected = status; } bool networking::getEthCableConnected() { return ethernetCableConnected; } -void networking::setLwipAddresses(ip_addr_t *ipaddr, ip_addr_t *netmask, - ip_addr_t *gw) { +void networking::setLwipAddresses(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) { IP4_ADDR(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); diff --git a/stm32h7/networking/networking.h b/stm32h7/networking/networking.h index 9e53408..14760ef 100644 --- a/stm32h7/networking/networking.h +++ b/stm32h7/networking/networking.h @@ -9,6 +9,6 @@ void setEthCableConnected(bool status); bool getEthCableConnected(); void setLwipAddresses(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw); -} // namespace networking +} // namespace networking #endif /* BSP_STM32H7_RTEMS_NETWORKING_NETWORKING_H_ */