run auto-formatter

This commit is contained in:
Robin Müller 2022-05-22 15:30:08 +02:00
parent b53aed9cf9
commit d34effb278
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
34 changed files with 697 additions and 512 deletions

View File

@ -6,12 +6,15 @@
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"
#include "pollingsequence/pollingSequenceFactory.h" #include "pollingsequence/pollingSequenceFactory.h"
ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) { ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF *thisSequence) {
uint32_t length = thisSequence->getPeriodMs(); uint32_t length = thisSequence->getPeriodMs();
thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0, FsfwExampleTask::OpCodes::SEND_RAND_NUM); thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0,
thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0, FsfwExampleTask::OpCodes::SEND_RAND_NUM); FsfwExampleTask::OpCodes::SEND_RAND_NUM);
thisSequence->addSlot(objects::TEST_DUMMY_3, 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, thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.2,
FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM);
@ -20,47 +23,64 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) {
thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.2, thisSequence->addSlot(objects::TEST_DUMMY_3, length * 0.2,
FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM); FsfwExampleTask::OpCodes::RECEIVE_RAND_NUM);
thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.5, FsfwExampleTask::OpCodes::DELAY_SHORT); thisSequence->addSlot(objects::TEST_DUMMY_1, length * 0.5,
thisSequence->addSlot(objects::TEST_DUMMY_2, length * 0.5, FsfwExampleTask::OpCodes::DELAY_SHORT); FsfwExampleTask::OpCodes::DELAY_SHORT);
thisSequence->addSlot(objects::TEST_DUMMY_3, 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) { if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl; sif::error << "pst::pollingSequenceInitFunction: Initialization errors!"
<< std::endl;
#else #else
sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n"); sif::printError(
"pst::pollingSequenceInitFunction: Initialization errors!\n");
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF* thisSequence) { ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF *thisSequence) {
uint32_t length = thisSequence->getPeriodMs(); uint32_t length = thisSequence->getPeriodMs();
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0, DeviceHandlerIF::PERFORM_OPERATION); thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_0, 0,
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0, DeviceHandlerIF::PERFORM_OPERATION); 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_0, 0.3 * length,
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.3 * length, DeviceHandlerIF::SEND_WRITE); 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_0, 0.45 * length,
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.45 * length, DeviceHandlerIF::GET_WRITE); 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_0, 0.6 * length,
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.6 * length, DeviceHandlerIF::SEND_READ); 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_0, 0.8 * length,
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.8 * length, DeviceHandlerIF::GET_READ); DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::TEST_DEVICE_HANDLER_1, 0.8 * length,
DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; sif::error << "pst::pollingSequenceTestFunction: Initialization errors!"
<< std::endl;
#else #else
sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); sif::printError(
"pst::pollingSequenceTestFunction: Initialization errors!\n");
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }

View File

@ -2,22 +2,21 @@
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
FsfwTestController::FsfwTestController(object_id_t objectId, object_id_t device0, FsfwTestController::FsfwTestController(object_id_t objectId,
object_id_t device1, uint8_t verboseLevel) object_id_t device0, object_id_t device1,
: TestController(objectId, objects::NO_OBJECT, 5), uint8_t verboseLevel)
device0Id(device0), : TestController(objectId, objects::NO_OBJECT, 5), device0Id(device0),
device1Id(device1), device1Id(device1), deviceDataset0(device0), deviceDataset1(device1) {}
deviceDataset0(device0),
deviceDataset1(device1) {}
FsfwTestController::~FsfwTestController() {} FsfwTestController::~FsfwTestController() {}
ReturnValue_t FsfwTestController::handleCommandMessage(CommandMessage* message) { ReturnValue_t
FsfwTestController::handleCommandMessage(CommandMessage *message) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t FsfwTestController::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, ReturnValue_t FsfwTestController::initializeLocalDataPool(
LocalDataPoolManager& poolManager) { localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -46,7 +45,8 @@ void FsfwTestController::performControlOperation() {
PoolReadGuard readHelper(&deviceDataset0.testUint8Var); PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Tracing device 0 variable 0 (UINT8), current value: " sif::info << "Tracing device 0 variable 0 (UINT8), current value: "
<< static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl; << static_cast<int>(deviceDataset0.testUint8Var.value)
<< std::endl;
#else #else
sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n", sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n",
deviceDataset0.testUint8Var.value); deviceDataset0.testUint8Var.value);
@ -67,11 +67,13 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
HasLocalDataPoolIF* device0 = HasLocalDataPoolIF *device0 =
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId()); ObjectManager::instance()->get<HasLocalDataPoolIF>(
deviceDataset0.getCreatorObjectId());
if (device0 == nullptr) { if (device0 == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 " sif::warning
<< "TestController::initializeAfterTaskCreation: Test device handler 0 "
"handle invalid!" "handle invalid!"
<< std::endl; << std::endl;
#else #else
@ -81,20 +83,23 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); ProvidesDataPoolSubscriptionIF *subscriptionIF =
device0->getSubscriptionInterface();
if (subscriptionIF != nullptr) { if (subscriptionIF != nullptr) {
/* For DEVICE_0, we only subscribe for notifications */ /* For DEVICE_0, we only subscribe for notifications */
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
false);
subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(),
getCommandQueue(), false); getCommandQueue(), false);
subscriptionIF->subscribeForVariableUpdateMessage(
td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), false);
} }
HasLocalDataPoolIF* device1 = HasLocalDataPoolIF *device1 =
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId()); ObjectManager::instance()->get<HasLocalDataPoolIF>(
deviceDataset0.getCreatorObjectId());
if (device1 == nullptr) { if (device1 == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 " sif::warning
<< "TestController::initializeAfterTaskCreation: Test device handler 1 "
"handle invalid!" "handle invalid!"
<< std::endl; << std::endl;
#else #else
@ -107,27 +112,31 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
subscriptionIF = device1->getSubscriptionInterface(); subscriptionIF = device1->getSubscriptionInterface();
if (subscriptionIF != nullptr) { if (subscriptionIF != nullptr) {
/* For DEVICE_1, we will subscribe for snapshots */ /* For DEVICE_1, we will subscribe for snapshots */
subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(), getCommandQueue(), subscriptionIF->subscribeForSetUpdateMessage(td::TEST_SET_ID, getObjectId(),
true);
subscriptionIF->subscribeForVariableUpdateMessage(td::PoolIds::TEST_UINT8_ID, getObjectId(),
getCommandQueue(), true); getCommandQueue(), true);
subscriptionIF->subscribeForVariableUpdateMessage(
td::PoolIds::TEST_UINT8_ID, getObjectId(), getCommandQueue(), true);
} }
return result; 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,
uint32_t* msToReachTheMode) { Submode_t submode,
uint32_t *msToReachTheMode) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId, void FsfwTestController::handleChangedDataset(sid_t sid,
bool* clearMessage) { store_address_t storeId,
bool *clearMessage) {
using namespace std; using namespace std;
if (verboseLevel >= 1) { if (verboseLevel >= 1) {
char const* printout = nullptr; char const *printout = nullptr;
if (storeId == storeId::INVALID_STORE_ADDRESS) { if (storeId == storeId::INVALID_STORE_ADDRESS) {
printout = "Notification"; printout = "Notification";
} else { } else {
@ -137,8 +146,9 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
sif::info << "FsfwTestController::handleChangedDataset: " << printout sif::info << "FsfwTestController::handleChangedDataset: " << printout
<< " update" << " update"
"from object ID " "from object ID "
<< setw(8) << setfill('0') << hex << sid.objectId << " and set ID " << sid.ownerSetId << setw(8) << setfill('0') << hex << sid.objectId
<< dec << setfill(' ') << endl; << " and set ID " << sid.ownerSetId << dec << setfill(' ')
<< endl;
#else #else
sif::printInfo( sif::printInfo(
"FsfwTestController::handleChangedPoolVariable: %s update from" "FsfwTestController::handleChangedPoolVariable: %s update from"
@ -154,11 +164,11 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; floatVec[1] = deviceDataset0.testFloat3Vec.value[1];
floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; floatVec[2] = deviceDataset0.testFloat3Vec.value[2];
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << floatVec[1] sif::info << "Current float vector (3) values: [" << floatVec[0] << ", "
<< ", " << floatVec[2] << "]" << std::endl; << floatVec[1] << ", " << floatVec[2] << "]" << std::endl;
#else #else
sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", floatVec[0], floatVec[1], sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n",
floatVec[2]); floatVec[0], floatVec[1], floatVec[2]);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
} }
} }
@ -172,12 +182,13 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
} }
} }
void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId, void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId,
bool* clearMessage) { store_address_t storeId,
bool *clearMessage) {
using namespace std; using namespace std;
if (verboseLevel >= 1) { if (verboseLevel >= 1) {
char const* printout = nullptr; char const *printout = nullptr;
if (storeId == storeId::INVALID_STORE_ADDRESS) { if (storeId == storeId::INVALID_STORE_ADDRESS) {
printout = "Notification"; printout = "Notification";
} else { } else {
@ -188,11 +199,12 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_add
sif::info << "TestController::handleChangedPoolVariable: " << printout sif::info << "TestController::handleChangedPoolVariable: " << printout
<< " update from object " << " update from object "
"ID 0x" "ID 0x"
<< setw(8) << setfill('0') << hex << globPoolId.objectId << " and local pool ID " << setw(8) << setfill('0') << hex << globPoolId.objectId
<< globPoolId.localPoolId << dec << setfill(' ') << endl; << " and local pool ID " << globPoolId.localPoolId << dec
<< setfill(' ') << endl;
#else #else
sif::printInfo( sif::printInfo("TestController::handleChangedPoolVariable: %s update from "
"TestController::handleChangedPoolVariable: %s update from object ID 0x%08x and " "object ID 0x%08x and "
"local pool ID %lu\n", "local pool ID %lu\n",
printout, globPoolId.objectId, globPoolId.localPoolId); printout, globPoolId.objectId, globPoolId.localPoolId);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
@ -202,7 +214,8 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_add
PoolReadGuard readHelper(&deviceDataset0.testUint8Var); PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Current test variable 0 (UINT8) value: " sif::info << "Current test variable 0 (UINT8) value: "
<< static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl; << static_cast<int>(deviceDataset0.testUint8Var.value)
<< std::endl;
#else #else
sif::printInfo("Current test variable 0 (UINT8) value %d\n", sif::printInfo("Current test variable 0 (UINT8) value %d\n",
deviceDataset0.testUint8Var.value); deviceDataset0.testUint8Var.value);

View File

@ -5,18 +5,18 @@
#include "fsfw_tests/integration/controller/TestController.h" #include "fsfw_tests/integration/controller/TestController.h"
class FsfwTestController : public TestController { class FsfwTestController : public TestController {
public: public:
FsfwTestController(object_id_t objectId, object_id_t device0, object_id_t device1, FsfwTestController(object_id_t objectId, object_id_t device0,
uint8_t verboseLevel = 0); object_id_t device1, uint8_t verboseLevel = 0);
virtual ~FsfwTestController(); virtual ~FsfwTestController();
ReturnValue_t handleCommandMessage(CommandMessage* message) override; ReturnValue_t handleCommandMessage(CommandMessage *message) override;
/** /**
* Periodic helper from ControllerBase, implemented by child class. * Periodic helper from ControllerBase, implemented by child class.
*/ */
void performControlOperation() override; void performControlOperation() override;
private: private:
object_id_t device0Id; object_id_t device0Id;
object_id_t device1Id; object_id_t device1Id;
testdevice::TestDataSet deviceDataset0; testdevice::TestDataSet deviceDataset0;
@ -31,14 +31,16 @@ class FsfwTestController : public TestController {
TraceTypes currentTraceType = TraceTypes::NONE; TraceTypes currentTraceType = TraceTypes::NONE;
ReturnValue_t initializeAfterTaskCreation() override; 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, void handleChangedPoolVariable(gp_id_t globPoolId, store_address_t storeId,
bool* clearMessage) override; bool *clearMessage) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, ReturnValue_t
LocalDataPoolManager& poolManager) override; initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; LocalDataPoolManager &poolManager) override;
LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override;
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) override; uint32_t *msToReachTheMode) override;
}; };
#endif /* EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_ */ #endif /* EXAMPLE_COMMON_EXAMPLE_CONTROLLER_FSFWTESTCONTROLLER_H_ */

View File

@ -40,28 +40,35 @@ void ObjectFactory::produceGenericObjects() {
new HealthTable(objects::HEALTH_TABLE); new HealthTable(objects::HEALTH_TABLE);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER);
new TimeStamper(objects::TIME_STAMPER); new TimeStamper(objects::TIME_STAMPER);
auto* ccsdsDistrib = new CCSDSDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR); auto *ccsdsDistrib =
new PUSDistributor(apid::APID, objects::PUS_DISTRIBUTOR, objects::CCSDS_DISTRIBUTOR); new CCSDSDistributor(apid::APID, objects::CCSDS_DISTRIBUTOR);
new PUSDistributor(apid::APID, objects::PUS_DISTRIBUTOR,
objects::CCSDS_DISTRIBUTOR);
new TmFunnel(objects::TM_FUNNEL); new TmFunnel(objects::TM_FUNNEL);
#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */ #endif /* OBSW_ADD_CORE_COMPONENTS == 1 */
/* PUS stack */ /* PUS stack */
#if OBSW_ADD_PUS_STACK == 1 #if OBSW_ADD_PUS_STACK == 1
new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION, apid::APID, new Service1TelecommandVerification(objects::PUS_SERVICE_1_VERIFICATION,
pus::PUS_SERVICE_1, objects::TM_FUNNEL, 5); apid::APID, pus::PUS_SERVICE_1,
new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::APID, pus::PUS_SERVICE_2, 3, objects::TM_FUNNEL, 5);
10); new Service2DeviceAccess(objects::PUS_SERVICE_2_DEVICE_ACCESS, apid::APID,
new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID, pus::PUS_SERVICE_3); pus::PUS_SERVICE_2, 3, 10);
new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::APID, pus::PUS_SERVICE_5, new Service3Housekeeping(objects::PUS_SERVICE_3_HOUSEKEEPING, apid::APID,
50); pus::PUS_SERVICE_3);
new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT, apid::APID, new Service5EventReporting(objects::PUS_SERVICE_5_EVENT_REPORTING, apid::APID,
pus::PUS_SERVICE_8, 3, 10); pus::PUS_SERVICE_5, 50);
new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID, pus::PUS_SERVICE_9); new Service8FunctionManagement(objects::PUS_SERVICE_8_FUNCTION_MGMT,
new Service17Test(objects::PUS_SERVICE_17_TEST, apid::APID, pus::PUS_SERVICE_17); apid::APID, pus::PUS_SERVICE_8, 3, 10);
new Service20ParameterManagement(objects::PUS_SERVICE_20_PARAMETERS, apid::APID, new Service9TimeManagement(objects::PUS_SERVICE_9_TIME_MGMT, apid::APID,
pus::PUS_SERVICE_20); pus::PUS_SERVICE_9);
new Service17Test(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 Service11TelecommandScheduling<cfg::OBSW_MAX_SCHEDULED_TCS>( new Service11TelecommandScheduling<cfg::OBSW_MAX_SCHEDULED_TCS>(
objects::PUS_SERVICE_11_TC_SCHEDULER, apid::APID, pus::PUS_SERVICE_11, ccsdsDistrib); objects::PUS_SERVICE_11_TC_SCHEDULER, apid::APID, pus::PUS_SERVICE_11,
ccsdsDistrib);
new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, apid::APID, new CService200ModeCommanding(objects::PUS_SERVICE_200_MODE_MGMT, apid::APID,
pus::PUS_SERVICE_200); pus::PUS_SERVICE_200);
#endif /* OBSW_ADD_PUS_STACK == 1 */ #endif /* OBSW_ADD_PUS_STACK == 1 */
@ -89,17 +96,22 @@ void ObjectFactory::produceGenericObjects() {
/* Demo device handler object */ /* Demo device handler object */
size_t expectedMaxReplyLen = 64; size_t expectedMaxReplyLen = 64;
CookieIF* testCookie = new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_0), CookieIF *testCookie =
new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_0),
expectedMaxReplyLen); expectedMaxReplyLen);
new TestEchoComIF(objects::TEST_ECHO_COM_IF); new TestEchoComIF(objects::TEST_ECHO_COM_IF);
new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF, testCookie, new TestDevice(objects::TEST_DEVICE_HANDLER_0, objects::TEST_ECHO_COM_IF,
testdevice::DeviceIndex::DEVICE_0, enableInfoPrintout); testCookie, testdevice::DeviceIndex::DEVICE_0,
testCookie = new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_1), enableInfoPrintout);
testCookie =
new TestCookie(static_cast<address_t>(testdevice::DeviceIndex::DEVICE_1),
expectedMaxReplyLen); expectedMaxReplyLen);
new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF, testCookie, new TestDevice(objects::TEST_DEVICE_HANDLER_1, objects::TEST_ECHO_COM_IF,
testdevice::DeviceIndex::DEVICE_1, enableInfoPrintout); 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); objects::TEST_DEVICE_HANDLER_1);
#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */ #endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */

View File

@ -11,11 +11,11 @@
#include "objects/systemObjectList.h" #include "objects/systemObjectList.h"
FsfwExampleTask::FsfwExampleTask(object_id_t objectId) FsfwExampleTask::FsfwExampleTask(object_id_t objectId)
: SystemObject(objectId), : SystemObject(objectId), poolManager(this, nullptr), demoSet(this),
poolManager(this, nullptr), monitor(objectId, MONITOR_ID,
demoSet(this), gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) {
monitor(objectId, MONITOR_ID, gp_id_t(objectId, FsfwDemoSet::VARIABLE_LIMIT), 30, 10) { commandQueue = QueueFactory::instance()->createMessageQueue(
commandQueue = QueueFactory::instance()->createMessageQueue(10, CommandMessage::MAX_MESSAGE_SIZE); 10, CommandMessage::MAX_MESSAGE_SIZE);
} }
FsfwExampleTask::~FsfwExampleTask() {} FsfwExampleTask::~FsfwExampleTask() {}
@ -80,21 +80,25 @@ object_id_t FsfwExampleTask::getSender() {
ReturnValue_t FsfwExampleTask::initialize() { ReturnValue_t FsfwExampleTask::initialize() {
// Get the dataset of the sender. Will be cached for later checks. // Get the dataset of the sender. Will be cached for later checks.
object_id_t sender = getSender(); object_id_t sender = getSender();
HasLocalDataPoolIF* senderIF = ObjectManager::instance()->get<HasLocalDataPoolIF>(sender); HasLocalDataPoolIF *senderIF =
ObjectManager::instance()->get<HasLocalDataPoolIF>(sender);
if (senderIF == nullptr) { if (senderIF == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n"); sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n");
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
// we need a private copy of the previous dataset.. or we use the shared dataset. // we need a private copy of the previous dataset.. or we use the shared
// dataset.
senderSet = new FsfwDemoSet(senderIF); senderSet = new FsfwDemoSet(senderIF);
if (senderSet == nullptr) { if (senderSet == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n"); sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n");
#endif #endif
@ -107,31 +111,45 @@ ReturnValue_t FsfwExampleTask::initializeAfterTaskCreation() {
return poolManager.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; } 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, ReturnValue_t
LocalDataPoolManager& poolManager) { FsfwExampleTask::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE, new PoolEntry<uint32_t>({0})); LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT, new PoolEntry<uint16_t>({0})); localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE,
new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(FsfwDemoSet::PoolIds::VARIABLE_LIMIT,
new PoolEntry<uint16_t>({0}));
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t FsfwExampleTask::performMonitoringDemo() { 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) { if (result != HasReturnvaluesIF::RETURN_OK) {
/* Configuration error */ /* Configuration error */
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("DummyObject::performOperation: Could not read variableLimit!\n"); sif::printError(
"DummyObject::performOperation: Could not read variableLimit!\n");
#endif #endif
return result; return result;
} }
@ -148,13 +166,17 @@ ReturnValue_t FsfwExampleTask::performMonitoringDemo() {
ReturnValue_t FsfwExampleTask::performSendOperation() { ReturnValue_t FsfwExampleTask::performSendOperation() {
object_id_t nextRecipient = getNextRecipient(); object_id_t nextRecipient = getNextRecipient();
FsfwExampleTask* target = ObjectManager::instance()->get<FsfwExampleTask>(nextRecipient); FsfwExampleTask *target =
ObjectManager::instance()->get<FsfwExampleTask>(nextRecipient);
if (target == nullptr) { if (target == nullptr) {
/* Configuration error */ /* Configuration error */
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("DummyObject::performOperation: Next recipient does not exist!\n"); sif::printError(
"DummyObject::performOperation: Next recipient does not exist!\n");
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -165,23 +187,30 @@ ReturnValue_t FsfwExampleTask::performSendOperation() {
message.setParameter2(this->getMessageQueueId()); message.setParameter2(this->getMessageQueueId());
/* Send message using own message queue */ /* Send message using own message queue */
ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message); ReturnValue_t result =
if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { commandQueue->sendMessage(target->getMessageQueueId(), &message);
if (result != HasReturnvaluesIF::RETURN_OK &&
result != MessageQueueIF::FULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); sif::printError(
"FsfwDemoTask::performSendOperation: Send failed with %hu\n", result);
#endif #endif
} }
/* Send message without via MessageQueueSenderIF */ /* Send message without via MessageQueueSenderIF */
result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message, result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(),
commandQueue->getId()); &message, commandQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { if (result != HasReturnvaluesIF::RETURN_OK &&
result != MessageQueueIF::FULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result); sif::printError(
"FsfwDemoTask::performSendOperation: Send failed with %hu\n", result);
#endif #endif
} }
@ -196,7 +225,8 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
while (result != MessageQueueIF::EMPTY) { while (result != MessageQueueIF::EMPTY) {
CommandMessage receivedMessage; CommandMessage receivedMessage;
result = commandQueue->receiveMessage(&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 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Receive failed with " << result << std::endl; sif::debug << "Receive failed with " << result << std::endl;
#endif #endif
@ -206,8 +236,9 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
#if OBSW_VERBOSE_LEVEL >= 2 #if OBSW_VERBOSE_LEVEL >= 2
sif::debug << "Message Received by " << getObjectId() << " from Queue " sif::debug << "Message Received by " << getObjectId() << " from Queue "
<< receivedMessage.getSender() << " ObjectId " << receivedMessage.getParameter() << receivedMessage.getSender() << " ObjectId "
<< " Queue " << receivedMessage.getParameter2() << std::endl; << receivedMessage.getParameter() << " Queue "
<< receivedMessage.getParameter2() << std::endl;
#endif #endif
#endif #endif
@ -221,11 +252,13 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
} }
if (senderSet->variableRead.value != receivedMessage.getParameter()) { if (senderSet->variableRead.value != receivedMessage.getParameter()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << "0x" sif::error << "FsfwDemoTask::performReceiveOperation: Variable "
<< senderSet->variableRead.getDataPoolId() << std::dec << " has wrong value." << std::hex << "0x"
<< std::endl; << senderSet->variableRead.getDataPoolId() << std::dec
<< " has wrong value." << std::endl;
sif::error << "Value: " << demoSet.variableRead.value sif::error << "Value: " << demoSet.variableRead.value
<< ", expected: " << receivedMessage.getParameter() << std::endl; << ", expected: " << receivedMessage.getParameter()
<< std::endl;
#endif #endif
} }
} }
@ -233,6 +266,10 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
return result; 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;
}

View File

@ -24,8 +24,10 @@ class PeriodicTaskIF;
* value directly from the sender via the local data pool interface. * 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. * If the timing is set up correctly, the values will always be the same.
*/ */
class FsfwExampleTask : public ExecutableObjectIF, public SystemObject, public HasLocalDataPoolIF { class FsfwExampleTask : public ExecutableObjectIF,
public: public SystemObject,
public HasLocalDataPoolIF {
public:
enum OpCodes { SEND_RAND_NUM, RECEIVE_RAND_NUM, DELAY_SHORT }; enum OpCodes { SEND_RAND_NUM, RECEIVE_RAND_NUM, DELAY_SHORT };
static constexpr uint8_t MONITOR_ID = 2; static constexpr uint8_t MONITOR_ID = 2;
@ -72,27 +74,28 @@ class FsfwExampleTask : public ExecutableObjectIF, public SystemObject, public H
* task interface handle can be cached to access task specific properties. * task interface handle can be cached to access task specific properties.
* @param task * @param task
*/ */
void setTaskIF(PeriodicTaskIF* task) override; void setTaskIF(PeriodicTaskIF *task) override;
object_id_t getObjectId() const override; object_id_t getObjectId() const override;
MessageQueueId_t getMessageQueueId(); MessageQueueId_t getMessageQueueId();
private: private:
LocalDataPoolManager poolManager; LocalDataPoolManager poolManager;
FsfwDemoSet* senderSet = nullptr; FsfwDemoSet *senderSet = nullptr;
FsfwDemoSet demoSet; FsfwDemoSet demoSet;
AbsLimitMonitor<int32_t> monitor; AbsLimitMonitor<int32_t> monitor;
PeriodicTaskIF* task = nullptr; PeriodicTaskIF *task = nullptr;
MessageQueueIF* commandQueue = nullptr; MessageQueueIF *commandQueue = nullptr;
/* HasLocalDatapoolIF overrides */ /* HasLocalDatapoolIF overrides */
MessageQueueId_t getCommandQueue() const override; MessageQueueId_t getCommandQueue() const override;
LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; LocalPoolDataSetBase *getDataSetHandle(sid_t sid) override;
uint32_t getPeriodicOperationFrequency() const override; uint32_t getPeriodicOperationFrequency() const override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, ReturnValue_t
LocalDataPoolManager& poolManager) override; initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager* getHkManagerHandle() override; LocalDataPoolManager &poolManager) override;
LocalDataPoolManager *getHkManagerHandle() override;
object_id_t getNextRecipient(); object_id_t getNextRecipient();
object_id_t getSender(); object_id_t getSender();

View File

@ -7,13 +7,13 @@
#include <fsfw/timemanager/Stopwatch.h> #include <fsfw/timemanager/Stopwatch.h>
FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout) FsfwReaderTask::FsfwReaderTask(object_id_t objectId, bool enablePrintout)
: SystemObject(objectId), : SystemObject(objectId), printoutEnabled(enablePrintout), opDivider(10),
printoutEnabled(enablePrintout), readSet(this->getObjectId(),
opDivider(10), gp_id_t(objects::TEST_DUMMY_1, FsfwDemoSet::PoolIds::VARIABLE),
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_2, FsfwDemoSet::PoolIds::VARIABLE),
gp_id_t(objects::TEST_DUMMY_3, 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 different pool */ /* Special protection for set reading because each variable is read from a
* different pool */
readSet.setReadCommitProtectionBehaviour(true); readSet.setReadCommitProtectionBehaviour(true);
} }
@ -35,12 +35,14 @@ ReturnValue_t FsfwReaderTask::performOperation(uint8_t operationCode) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
if (opDivider.checkAndIncrement() and printoutEnabled) { if (opDivider.checkAndIncrement() and printoutEnabled) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 1: " << variable1 << std::endl;
sif::info << "Variable read from demo object 2: " << variable2 << std::endl; sif::info << "Variable read from demo object 2: " << variable2 << std::endl;
sif::info << "Variable read from demo object 3: " << variable3 << std::endl; sif::info << "Variable read from demo object 3: " << variable3 << std::endl;
#else #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 1: %d\n\r", variable1);
sif::printInfo("Variable read from demo object 2: %d\n\r", variable2); sif::printInfo("Variable read from demo object 2: %d\n\r", variable2);
sif::printInfo("Variable read from demo object 3: %d\n\r", variable3); sif::printInfo("Variable read from demo object 3: %d\n\r", variable3);

View File

@ -8,14 +8,14 @@
#include "testdefinitions/demoDefinitions.h" #include "testdefinitions/demoDefinitions.h"
class FsfwReaderTask : public ExecutableObjectIF, public SystemObject { class FsfwReaderTask : public ExecutableObjectIF, public SystemObject {
public: public:
FsfwReaderTask(object_id_t objectId, bool enablePrintout); FsfwReaderTask(object_id_t objectId, bool enablePrintout);
~FsfwReaderTask() override; ~FsfwReaderTask() override;
ReturnValue_t initializeAfterTaskCreation() override; ReturnValue_t initializeAfterTaskCreation() override;
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;
private: private:
bool printoutEnabled = false; bool printoutEnabled = false;
PeriodicOperationDivider opDivider; PeriodicOperationDivider opDivider;
CompleteDemoReadSet readSet; CompleteDemoReadSet readSet;

View File

@ -6,15 +6,16 @@
#include "fsfw_tests/integration/task/TestTask.h" #include "fsfw_tests/integration/task/TestTask.h"
class FsfwTestTask : public TestTask { class FsfwTestTask : public TestTask {
public: public:
FsfwTestTask(object_id_t objectId, bool periodicEvent); FsfwTestTask(object_id_t objectId, bool periodicEvent);
ReturnValue_t performPeriodicAction() override; ReturnValue_t performPeriodicAction() override;
private: private:
bool periodicEvent = false; bool periodicEvent = false;
static constexpr uint8_t subsystemId = SUBSYSTEM_ID::TEST_TASK_ID; 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_ */ #endif /* EXAMPLE_COMMON_EXAMPLE_TEST_FSFWTESTTASK_H_ */

View File

@ -4,13 +4,15 @@
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface/ServiceInterface.h>
void MutexExample::example() { void MutexExample::example() {
MutexIF* mutex = MutexFactory::instance()->createMutex(); MutexIF *mutex = MutexFactory::instance()->createMutex();
MutexIF* mutex2 = 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 (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("MutexExample::example: Lock Failed with %hu\n", result); sif::printError("MutexExample::example: Lock Failed with %hu\n", result);
#endif #endif
@ -19,7 +21,8 @@ void MutexExample::example() {
result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING); result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("MutexExample::example: Lock Failed with %hu\n", result); sif::printError("MutexExample::example: Lock Failed with %hu\n", result);
#endif #endif
@ -28,7 +31,8 @@ void MutexExample::example() {
result = mutex->unlockMutex(); result = mutex->unlockMutex();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); sif::printError("MutexExample::example: Unlock Failed with %hu\n", result);
#endif #endif
@ -37,7 +41,8 @@ void MutexExample::example() {
result = mutex2->unlockMutex(); result = mutex2->unlockMutex();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #else
sif::printError("MutexExample::example: Unlock Failed with %hu\n", result); sif::printError("MutexExample::example: Unlock Failed with %hu\n", result);
#endif #endif

View File

@ -14,8 +14,9 @@
#include "fsfw/ipc/MutexIF.h" #include "fsfw/ipc/MutexIF.h"
#include "fsfw/timemanager/Clock.h" #include "fsfw/timemanager/Clock.h"
#define __FILENAME_REL__ (((const char*)__FILE__ + SOURCE_PATH_SIZE)) #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(); void fmtTests();
@ -28,26 +29,34 @@ static const char DEBUG_PREFIX[] = "DEBUG";
static const char WARNING_PREFIX[] = "WARNING"; static const char WARNING_PREFIX[] = "WARNING";
static const char ERROR_PREFIX[] = "ERROR"; 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<fmt::color, 4> LOG_COLOR_ARR = { static const std::array<fmt::color, 4> 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 MutexIF *PRINT_MUTEX = MutexFactory::instance()->createMutex();
static size_t writeTypePrefix(LogLevel level) { static size_t writeTypePrefix(LogLevel level) {
auto idx = static_cast<unsigned int>(level); auto idx = static_cast<unsigned int>(level);
const auto result = const auto result = fmt::format_to_n(
fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, PRINT_BUF.begin(), PRINT_BUF.size() - 1,
fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx]))); fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx])));
return result.size; return result.size;
} }
template <typename... T> template <typename... T>
size_t logTraced(LogLevel level, const char* file, unsigned int line, bool timed, size_t logTraced(LogLevel level, const char *file, unsigned int line,
fmt::format_string<T...> fmt, T&&... args) noexcept { bool timed, fmt::format_string<T...> fmt,
T &&...args) noexcept {
try { try {
MutexGuard mg(PRINT_MUTEX); MutexGuard mg(PRINT_MUTEX);
size_t bufPos = writeTypePrefix(level); size_t bufPos = writeTypePrefix(level);
@ -55,15 +64,16 @@ size_t logTraced(LogLevel level, const char* file, unsigned int line, bool timed
if (timed) { if (timed) {
Clock::TimeOfDay_t logTime; Clock::TimeOfDay_t logTime;
Clock::getDateAndTime(&logTime); Clock::getDateAndTime(&logTime);
const auto result = fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, const auto result =
" | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file, line, fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos,
logTime.hour, logTime.minute, logTime.second, " | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file,
line, logTime.hour, logTime.minute, logTime.second,
logTime.usecond / 1000, fmt::format(fmt, args...)); logTime.usecond / 1000, fmt::format(fmt, args...));
*result.out = '\0'; *result.out = '\0';
bufPos += result.size; bufPos += result.size;
} else { } else {
const auto result = const auto result = fmt::format_to_n(
fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, " | {}[l.{}] | {}", file, currentIter, PRINT_BUF.size() - 1 - bufPos, " | {}[l.{}] | {}", file,
line, fmt::format(fmt, args...)); line, fmt::format(fmt, args...));
*result.out = '\0'; *result.out = '\0';
bufPos += result.size; bufPos += result.size;
@ -71,14 +81,15 @@ size_t logTraced(LogLevel level, const char* file, unsigned int line, bool timed
fmt::print(fmt::runtime(PRINT_BUF.data())); fmt::print(fmt::runtime(PRINT_BUF.data()));
return bufPos; return bufPos;
} catch (const fmt::v8::format_error& e) { } catch (const fmt::v8::format_error &e) {
fmt::print("Printing failed with error: {}\n", e.what()); fmt::print("Printing failed with error: {}\n", e.what());
return 0; return 0;
} }
} }
template <typename... T> template <typename... T>
size_t log(LogLevel level, bool timed, fmt::format_string<T...> fmt, T&&... args) noexcept { size_t log(LogLevel level, bool timed, fmt::format_string<T...> fmt,
T &&...args) noexcept {
try { try {
MutexGuard mg(PRINT_MUTEX); MutexGuard mg(PRINT_MUTEX);
size_t bufPos = writeTypePrefix(level); size_t bufPos = writeTypePrefix(level);
@ -87,57 +98,61 @@ size_t log(LogLevel level, bool timed, fmt::format_string<T...> fmt, T&&... args
Clock::TimeOfDay_t logTime; Clock::TimeOfDay_t logTime;
Clock::getDateAndTime(&logTime); Clock::getDateAndTime(&logTime);
const auto result = fmt::format_to_n( const auto result = fmt::format_to_n(
currentIter, PRINT_BUF.size() - bufPos, " | {:02}:{:02}:{:02}.{:03} | {}", logTime.hour, currentIter, PRINT_BUF.size() - bufPos,
logTime.minute, logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...)); " | {:02}:{:02}:{:02}.{:03} | {}", logTime.hour, logTime.minute,
logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...));
bufPos += result.size; bufPos += result.size;
} }
fmt::print(fmt::runtime(PRINT_BUF.data())); fmt::print(fmt::runtime(PRINT_BUF.data()));
return bufPos; return bufPos;
} catch (const fmt::v8::format_error& e) { } catch (const fmt::v8::format_error &e) {
fmt::print("Printing failed with error: {}\n", e.what()); fmt::print("Printing failed with error: {}\n", e.what());
return 0; return 0;
} }
} }
template <typename... T> template <typename... T>
void fdebug(const char* file, unsigned int line, fmt::format_string<T...> fmt, void fdebug(const char *file, unsigned int line, fmt::format_string<T...> fmt,
T&&... args) noexcept { T &&...args) noexcept {
logTraced(LogLevel::DEBUG, file, line, false, fmt, args...); logTraced(LogLevel::DEBUG, file, line, false, fmt, args...);
} }
template <typename... T> template <typename... T>
void fdebug_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, void fdebug_t(const char *file, unsigned int line, fmt::format_string<T...> fmt,
T&&... args) noexcept { T &&...args) noexcept {
logTraced(LogLevel::DEBUG, file, line, true, fmt, args...); logTraced(LogLevel::DEBUG, file, line, true, fmt, args...);
} }
template <typename... T> template <typename... T>
void finfo_t(fmt::format_string<T...> fmt, T&&... args) { void finfo_t(fmt::format_string<T...> fmt, T &&...args) {
log(LogLevel::INFO, true, fmt, args...); log(LogLevel::INFO, true, fmt, args...);
} }
template <typename... T> template <typename... T> void finfo(fmt::format_string<T...> fmt, T &&...args) {
void finfo(fmt::format_string<T...> fmt, T&&... args) {
log(LogLevel::INFO, false, fmt, args...); log(LogLevel::INFO, false, fmt, args...);
} }
template <typename... T> template <typename... T>
void fwarning(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { void fwarning(const char *file, unsigned int line, fmt::format_string<T...> fmt,
T &&...args) {
logTraced(LogLevel::WARNING, file, line, false, fmt, args...); logTraced(LogLevel::WARNING, file, line, false, fmt, args...);
} }
template <typename... T> template <typename... T>
void fwarning_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { void fwarning_t(const char *file, unsigned int line,
fmt::format_string<T...> fmt, T &&...args) {
logTraced(LogLevel::WARNING, file, line, true, fmt, args...); logTraced(LogLevel::WARNING, file, line, true, fmt, args...);
} }
template <typename... T> template <typename... T>
void ferror(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { void ferror(const char *file, unsigned int line, fmt::format_string<T...> fmt,
T &&...args) {
logTraced(LogLevel::ERROR, file, line, false, fmt, args...); logTraced(LogLevel::ERROR, file, line, false, fmt, args...);
} }
template <typename... T> template <typename... T>
void ferror_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { void ferror_t(const char *file, unsigned int line, fmt::format_string<T...> fmt,
T &&...args) {
logTraced(LogLevel::ERROR, file, line, true, fmt, args...); logTraced(LogLevel::ERROR, file, line, true, fmt, args...);
} }
@ -147,16 +162,22 @@ void ferror_t(const char* file, unsigned int line, fmt::format_string<T...> fmt,
#define FSFW_LOGIT(format, ...) finfo_t(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

View File

@ -12,21 +12,22 @@
* pool variables (for read and write access respectively). * pool variables (for read and write access respectively).
*/ */
class FsfwDemoSet : public StaticLocalDataSet<3> { class FsfwDemoSet : public StaticLocalDataSet<3> {
public: public:
static constexpr uint32_t DEMO_SET_ID = 0; static constexpr uint32_t DEMO_SET_ID = 0;
enum PoolIds { VARIABLE, VARIABLE_LIMIT }; enum PoolIds { VARIABLE, VARIABLE_LIMIT };
FsfwDemoSet(HasLocalDataPoolIF* hkOwner) : StaticLocalDataSet(hkOwner, DEMO_SET_ID) {} FsfwDemoSet(HasLocalDataPoolIF *hkOwner)
: StaticLocalDataSet(hkOwner, DEMO_SET_ID) {}
lp_var_t<uint32_t> variableRead = lp_var_t<uint32_t> variableRead = lp_var_t<uint32_t>(
lp_var_t<uint32_t>(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ); sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_READ);
lp_var_t<uint32_t> variableWrite = lp_var_t<uint32_t> variableWrite = lp_var_t<uint32_t>(
lp_var_t<uint32_t>(sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE); sid.objectId, PoolIds::VARIABLE, this, pool_rwm_t::VAR_WRITE);
lp_var_t<uint16_t> variableLimit = lp_var_t<uint16_t> variableLimit =
lp_var_t<uint16_t>(sid.objectId, PoolIds::VARIABLE_LIMIT, this); lp_var_t<uint16_t>(sid.objectId, PoolIds::VARIABLE_LIMIT, this);
private: private:
}; };
/** /**
@ -35,10 +36,11 @@ class FsfwDemoSet : public StaticLocalDataSet<3> {
* which reads multiple sensor values at once. * which reads multiple sensor values at once.
*/ */
class CompleteDemoReadSet : public StaticLocalDataSet<3> { class CompleteDemoReadSet : public StaticLocalDataSet<3> {
public: public:
static constexpr uint32_t DEMO_SET_ID = 0; 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)), : StaticLocalDataSet(sid_t(owner, DEMO_SET_ID)),
variable1(variable1, this, pool_rwm_t::VAR_READ), variable1(variable1, this, pool_rwm_t::VAR_READ),
variable2(variable2, this, pool_rwm_t::VAR_READ), variable2(variable2, this, pool_rwm_t::VAR_READ),
@ -48,7 +50,7 @@ class CompleteDemoReadSet : public StaticLocalDataSet<3> {
lp_var_t<uint32_t> variable2; lp_var_t<uint32_t> variable2;
lp_var_t<uint32_t> variable3; lp_var_t<uint32_t> variable3;
private: private:
}; };
#endif /* MISSION_DEMO_DEMODEFINITIONS_H_ */ #endif /* MISSION_DEMO_DEMODEFINITIONS_H_ */

View File

@ -9,7 +9,7 @@
#define MISSION_UTILITY_PUSPACKETCREATOR_H_ #define MISSION_UTILITY_PUSPACKETCREATOR_H_
class PusPacketCreator { class PusPacketCreator {
public: public:
static void createPusPacketAndPrint(); static void createPusPacketAndPrint();
}; };

View File

@ -6,10 +6,11 @@
namespace task { namespace task {
void printInitError(const char* objName, object_id_t objectId) { void printInitError(const char *objName, object_id_t objectId) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8) << std::setfill('0') sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8)
<< std::hex << objectId << std::dec << ") failed." << std::endl; << std::setfill('0') << std::hex << objectId << std::dec
<< ") failed." << std::endl;
#else #else
sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", objName, sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", objName,
static_cast<unsigned int>(objectId)); static_cast<unsigned int>(objectId));

View File

@ -10,8 +10,8 @@ object_id_t TmFunnel::storageDestination = objects::NO_OBJECT;
TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth) TmFunnel::TmFunnel(object_id_t objectId, uint32_t messageDepth)
: SystemObject(objectId), messageDepth(messageDepth) { : SystemObject(objectId), messageDepth(messageDepth) {
tmQueue = QueueFactory::instance()->createMessageQueue(messageDepth, tmQueue = QueueFactory::instance()->createMessageQueue(
MessageQueueMessage::MAX_MESSAGE_SIZE); messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE);
storageQueue = QueueFactory::instance()->createMessageQueue( storageQueue = QueueFactory::instance()->createMessageQueue(
messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE); messageDepth, MessageQueueMessage::MAX_MESSAGE_SIZE);
} }
@ -40,24 +40,27 @@ ReturnValue_t TmFunnel::performOperation(uint8_t operationCode) {
} }
} }
ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) { ReturnValue_t TmFunnel::handlePacket(TmTcMessage *message) {
uint8_t* packetData = nullptr; uint8_t *packetData = nullptr;
size_t size = 0; 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) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
TmPacketPusC packet(packetData); TmPacketPusC packet(packetData);
packet.setPacketSequenceCount(this->sourceSequenceCount); packet.setPacketSequenceCount(this->sourceSequenceCount);
sourceSequenceCount++; sourceSequenceCount++;
sourceSequenceCount = sourceSequenceCount % SpacePacketBase::LIMIT_SEQUENCE_COUNT; sourceSequenceCount =
sourceSequenceCount % SpacePacketBase::LIMIT_SEQUENCE_COUNT;
packet.setErrorControl(); packet.setErrorControl();
result = tmQueue->sendToDefault(message); result = tmQueue->sendToDefault(message);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
tmPool->deleteData(message->getStorageId()); tmPool->deleteData(message->getStorageId());
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmFunnel::handlePacket: Error sending to downlink handler" << std::endl; sif::error << "TmFunnel::handlePacket: Error sending to downlink handler"
<< std::endl;
#endif #endif
return result; return result;
} }
@ -67,7 +70,8 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
tmPool->deleteData(message->getStorageId()); tmPool->deleteData(message->getStorageId());
#if FSFW_CPP_OSTREAM_ENABLED == 1 #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 #endif
return result; return result;
} }
@ -80,18 +84,21 @@ ReturnValue_t TmFunnel::initialize() {
if (tmPool == nullptr) { if (tmPool == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmFunnel::initialize: TM store not set." << std::endl; sif::error << "TmFunnel::initialize: TM store not set." << std::endl;
sif::error << "Make sure the tm store is set up properly and implements StorageManagerIF" sif::error << "Make sure the tm store is set up properly and implements "
"StorageManagerIF"
<< std::endl; << std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
AcceptsTelemetryIF* tmTarget = AcceptsTelemetryIF *tmTarget =
ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination); ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination);
if (tmTarget == nullptr) { if (tmTarget == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl; sif::error << "TmFunnel::initialize: Downlink Destination not set."
sif::error << "Make sure the downlink destination object is set up properly and implements " << std::endl;
sif::error << "Make sure the downlink destination object is set up "
"properly and implements "
"AcceptsTelemetryIF" "AcceptsTelemetryIF"
<< std::endl; << std::endl;
#endif #endif
@ -104,10 +111,11 @@ ReturnValue_t TmFunnel::initialize() {
return SystemObject::initialize(); return SystemObject::initialize();
} }
AcceptsTelemetryIF* storageTarget = AcceptsTelemetryIF *storageTarget =
ObjectManager::instance()->get<AcceptsTelemetryIF>(storageDestination); ObjectManager::instance()->get<AcceptsTelemetryIF>(storageDestination);
if (storageTarget != nullptr) { if (storageTarget != nullptr) {
storageQueue->setDefaultDestination(storageTarget->getReportReceptionQueue()); storageQueue->setDefaultDestination(
storageTarget->getReportReceptionQueue());
} }
return SystemObject::initialize(); return SystemObject::initialize();

View File

@ -19,30 +19,33 @@ void setStaticFrameworkObjectIds();
* @ingroup utility * @ingroup utility
* @author J. Meier * @author J. Meier
*/ */
class TmFunnel : public AcceptsTelemetryIF, public ExecutableObjectIF, public SystemObject { class TmFunnel : public AcceptsTelemetryIF,
public ExecutableObjectIF,
public SystemObject {
friend void(Factory::setStaticFrameworkObjectIds)(); friend void(Factory::setStaticFrameworkObjectIds)();
public: public:
TmFunnel(object_id_t objectId, uint32_t messageDepth = 20); TmFunnel(object_id_t objectId, uint32_t messageDepth = 20);
virtual ~TmFunnel(); virtual ~TmFunnel();
virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) override; virtual MessageQueueId_t
getReportReceptionQueue(uint8_t virtualChannel = 0) override;
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
protected: protected:
static object_id_t downlinkDestination; static object_id_t downlinkDestination;
static object_id_t storageDestination; static object_id_t storageDestination;
private: private:
uint16_t sourceSequenceCount = 0; uint16_t sourceSequenceCount = 0;
MessageQueueIF* tmQueue = nullptr; MessageQueueIF *tmQueue = nullptr;
MessageQueueIF* storageQueue = nullptr; MessageQueueIF *storageQueue = nullptr;
StorageManagerIF* tmPool = nullptr; StorageManagerIF *tmPool = nullptr;
uint32_t messageDepth = 0; uint32_t messageDepth = 0;
ReturnValue_t handlePacket(TmTcMessage* message); ReturnValue_t handlePacket(TmTcMessage *message);
}; };
#endif /* MISSION_UTILITY_TMFUNNEL_H_ */ #endif /* MISSION_UTILITY_TMFUNNEL_H_ */

View File

@ -13,11 +13,13 @@
* *
* Assembled by Jean Rabault * Assembled by Jean Rabault
* *
* UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds since 1st Jan 1970) of * UNIX_TIMESTAMP gives the UNIX timestamp (unsigned long integer of seconds
* compilation from macros using the compiler defined __TIME__ macro. This should include Gregorian * since 1st Jan 1970) of compilation from macros using the compiler defined
* calendar leap days, in particular the 29ths of February, 100 and 400 years modulo leaps. * __TIME__ macro. This should include Gregorian calendar leap days, in
* particular the 29ths of February, 100 and 400 years modulo leaps.
* *
* Careful: __TIME__ is the local time of the computer, NOT the UTC time in general! * Careful: __TIME__ is the local time of the computer, NOT the UTC time in
* general!
* *
*/ */
@ -62,29 +64,36 @@
// Days in February // Days in February
#define _UNIX_TIMESTAMP_FDAY(year) \ #define _UNIX_TIMESTAMP_FDAY(year) \
(((year) % 400) == 0UL ? 29UL \ (((year) % 400) == 0UL \
? 29UL \
: (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL))) : (((year) % 100) == 0UL ? 28UL : (((year) % 4) == 0UL ? 29UL : 28UL)))
// Days in the year // Days in the year
#define _UNIX_TIMESTAMP_YDAY(year, month, day) \ #define _UNIX_TIMESTAMP_YDAY(year, month, day) \
(/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \ (/* January */ day /* February */ + (month >= 2 ? 31UL : 0UL) /* March */ + \
(month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \ (month >= 3 ? _UNIX_TIMESTAMP_FDAY(year) : 0UL) /* April */ + \
(month >= 4 ? 31UL : 0UL) /* May */ + (month >= 5 ? 30UL : 0UL) /* June */ + \ (month >= 4 ? 31UL : 0UL) /* May */ + \
(month >= 6 ? 31UL : 0UL) /* July */ + (month >= 7 ? 30UL : 0UL) /* August */ + \ (month >= 5 ? 30UL : 0UL) /* June */ + \
(month >= 8 ? 31UL : 0UL) /* September */ + (month >= 9 ? 31UL : 0UL) /* October */ + \ (month >= 6 ? 31UL : 0UL) /* July */ + \
(month >= 10 ? 30UL : 0UL) /* November */ + (month >= 11 ? 31UL : 0UL) /* December */ + \ (month >= 7 ? 30UL : 0UL) /* August */ + \
(month >= 12 ? 30UL : 0UL)) (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 // get the UNIX timestamp from a digits representation
#define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \ #define _UNIX_TIMESTAMP(year, month, day, hour, minute, second) \
(/* time */ second + minute * SEC_PER_MIN + hour * SEC_PER_HOUR + \ (/* 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 day (month + day) */ (_UNIX_TIMESTAMP_YDAY(year, month, day) - 1) * \
/* year */ (year - 1970UL) * SEC_PER_YEAR + ((year - 1969UL) / 4UL) * SEC_PER_DAY - \ SEC_PER_DAY + \
((year - 1901UL) / 100UL) * SEC_PER_DAY + ((year - 1601UL) / 400UL) * 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 // the UNIX timestamp
#define UNIX_TIMESTAMP \ #define UNIX_TIMESTAMP \
(_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, __TIME_HOURS__, \ (_UNIX_TIMESTAMP(__TIME_YEARS__, __TIME_MONTH__, __TIME_DAYS__, \
__TIME_MINUTES__, __TIME_SECONDS__)) __TIME_HOURS__, __TIME_MINUTES__, __TIME_SECONDS__))
#endif #endif

View File

@ -4,15 +4,17 @@
#include <OBSWVersion.h> #include <OBSWVersion.h>
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface/ServiceInterface.h>
void utility::commonInitPrint(const char* const os, const char* const board) { void utility::commonInitPrint(const char *const os, const char *const board) {
if (os == nullptr or board == nullptr) { if (os == nullptr or board == nullptr) {
return; return;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
std::cout << "-- FSFW Example (" << os << ") v" << FSFW_EXAMPLE_VERSION << "." 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 for " << board << " --" << std::endl;
std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --" << std::endl; std::cout << "-- Compiled on " << __DATE__ << " " << __TIME__ << " --"
<< std::endl;
#else #else
printf("\n\r-- FSFW Example (%s) v%d.%d.%d --\n", os, FSFW_EXAMPLE_VERSION, printf("\n\r-- FSFW Example (%s) v%d.%d.%d --\n", os, FSFW_EXAMPLE_VERSION,
FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION); FSFW_EXAMPLE_SUBVERSION, FSFW_EXAMPLE_REVISION);

View File

@ -3,7 +3,7 @@
namespace utility { namespace utility {
void commonInitPrint(const char* const os, const char* const board); void commonInitPrint(const char *const os, const char *const board);
} }

View File

@ -3,7 +3,8 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "stm32h7xx_nucleo.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) { : TestTask(objectId), blinkyLed(blinkyLed) {
BSP_LED_Init(LED1); BSP_LED_Init(LED1);
BSP_LED_Init(LED2); BSP_LED_Init(LED2);

View File

@ -5,15 +5,16 @@
#include "fsfw_tests/integration/task/TestTask.h" #include "fsfw_tests/integration/task/TestTask.h"
class STM32TestTask : public TestTask { class STM32TestTask : public TestTask {
public: public:
STM32TestTask(object_id_t objectId, bool enablePrintout, bool blinkyLed = true); STM32TestTask(object_id_t objectId, bool enablePrintout,
bool blinkyLed = true);
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
ReturnValue_t performPeriodicAction() override; ReturnValue_t performPeriodicAction() override;
private: private:
SpiComIF* spiComIF = nullptr; SpiComIF *spiComIF = nullptr;
SpiTest* spiTest = nullptr; SpiTest *spiTest = nullptr;
bool blinkyLed = false; bool blinkyLed = false;
bool testSpi = true; bool testSpi = true;

View File

@ -9,8 +9,10 @@
#include "ethernetif.h" #include "ethernetif.h"
#include "udp_config.h" #include "udp_config.h"
TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, TmTcLwIpUdpBridge::TmTcLwIpUdpBridge(object_id_t objectId,
object_id_t tmStoreId, object_id_t tcStoreId) object_id_t ccsdsPacketDistributor,
object_id_t tmStoreId,
object_id_t tcStoreId)
: TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) { : TmTcBridge(objectId, ccsdsPacketDistributor, tmStoreId, tcStoreId) {
TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY; TmTcLwIpUdpBridge::lastAdd.addr = IPADDR_TYPE_ANY;
} }
@ -38,7 +40,8 @@ ReturnValue_t TmTcLwIpUdpBridge::udp_server_init(void) {
if (err == ERR_OK) { if (err == ERR_OK) {
/* Set a receive callback for the upcb */ /* 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; return RETURN_OK;
} else { } else {
udp_remove(TmTcLwIpUdpBridge::upcb); udp_remove(TmTcLwIpUdpBridge::upcb);
@ -54,20 +57,22 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
#if TCPIP_RECV_WIRETAPPING == 1 #if TCPIP_RECV_WIRETAPPING == 1
if (connectFlag) { if (connectFlag) {
uint32_t ipAddress = ((ip4_addr*)&lastAdd)->addr; uint32_t ipAddress = ((ip4_addr *)&lastAdd)->addr;
int ipAddress1 = (ipAddress & 0xFF000000) >> 24; int ipAddress1 = (ipAddress & 0xFF000000) >> 24;
int ipAddress2 = (ipAddress & 0xFF0000) >> 16; int ipAddress2 = (ipAddress & 0xFF0000) >> 16;
int ipAddress3 = (ipAddress & 0xFF00) >> 8; int ipAddress3 = (ipAddress & 0xFF00) >> 8;
int ipAddress4 = ipAddress & 0xFF; int ipAddress4 = ipAddress & 0xFF;
#if OBSW_VERBOSE_LEVEL == 1 #if OBSW_VERBOSE_LEVEL == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec << ipAddress4 << "." sif::info << "TmTcLwIpUdpBridge: Client IP Address " << std::dec
<< ipAddress3 << "." << ipAddress2 << "." << ipAddress1 << std::endl; << ipAddress4 << "." << ipAddress3 << "." << ipAddress2 << "."
<< ipAddress1 << std::endl;
uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); 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 #else
sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n", ipAddress4, ipAddress3, sif::printInfo("TmTcLwIpUdpBridge: Client IP Address %d.%d.%d.%d\n",
ipAddress2, ipAddress1); ipAddress4, ipAddress3, ipAddress2, ipAddress1);
uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort); uint16_t portSwapped = EndianConverter::convertBigEndian(lastPort);
sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped); sif::printInfo("TmTcLwIpUdpBridge: Client IP Port: %d\n", portSwapped);
#endif #endif
@ -79,11 +84,12 @@ ReturnValue_t TmTcLwIpUdpBridge::performOperation(uint8_t operationCode) {
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t* data, size_t dataLen) { ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t *data, size_t dataLen) {
struct pbuf* p_tx = pbuf_alloc(PBUF_TRANSPORT, dataLen, PBUF_RAM); 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 */ /* copy data to pbuf */
err_t err = pbuf_take(p_tx, (char*)data, dataLen); err_t err = pbuf_take(p_tx, (char *)data, dataLen);
if (err != ERR_OK) { if (err != ERR_OK) {
pbuf_free(p_tx); pbuf_free(p_tx);
return err; return err;
@ -109,17 +115,21 @@ ReturnValue_t TmTcLwIpUdpBridge::sendTm(const uint8_t* data, size_t dataLen) {
return RETURN_OK; return RETURN_OK;
} }
void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* upcb_, void TmTcLwIpUdpBridge::udp_server_receive_callback(void *arg,
struct pbuf* p, const ip_addr_t* addr, struct udp_pcb *upcb_,
struct pbuf *p,
const ip_addr_t *addr,
u16_t port) { u16_t port) {
struct pbuf* p_tx = nullptr; struct pbuf *p_tx = nullptr;
auto udpBridge = reinterpret_cast<TmTcLwIpUdpBridge*>(arg); auto udpBridge = reinterpret_cast<TmTcLwIpUdpBridge *>(arg);
if (udpBridge == nullptr) { if (udpBridge == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!" sif::warning
<< "TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!"
<< std::endl; << std::endl;
#else #else
sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid UDP bridge!\n"); sif::printWarning("TmTcLwIpUdpBridge::udp_server_receive_callback: Invalid "
"UDP bridge!\n");
#endif #endif
} }
/* allocate pbuf from RAM*/ /* allocate pbuf from RAM*/
@ -140,9 +150,9 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* u
udpBridge->physicalConnectStatusChange(true); udpBridge->physicalConnectStatusChange(true);
} }
} }
pbuf_take(p_tx, (char*)p->payload, p->len); pbuf_take(p_tx, (char *)p->payload, p->len);
/* send the received data to the uart port */ /* send the received data to the uart port */
char* data = reinterpret_cast<char*>(p_tx->payload); char *data = reinterpret_cast<char *>(p_tx->payload);
*(data + p_tx->len) = '\0'; *(data + p_tx->len) = '\0';
#if TCPIP_RECV_WIRETAPPING == 1 #if TCPIP_RECV_WIRETAPPING == 1
@ -150,8 +160,8 @@ void TmTcLwIpUdpBridge::udp_server_receive_callback(void* arg, struct udp_pcb* u
#endif #endif
store_address_t storeId; store_address_t storeId;
ReturnValue_t returnValue = ReturnValue_t returnValue = udpBridge->tcStore->addData(
udpBridge->tcStore->addData(&storeId, reinterpret_cast<uint8_t*>(p->payload), p->len); &storeId, reinterpret_cast<uint8_t *>(p->payload), p->len);
if (returnValue != RETURN_OK) { if (returnValue != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "UDP Server: Data storage failed" << std::endl; sif::warning << "UDP Server: Data storage failed" << std::endl;
@ -178,8 +188,8 @@ bool TmTcLwIpUdpBridge::comLinkUp() const { return communicationLinkUp; }
/* Caller must ensure thread-safety */ /* Caller must ensure thread-safety */
void TmTcLwIpUdpBridge::physicalConnectStatusChange(bool connect) { void TmTcLwIpUdpBridge::physicalConnectStatusChange(bool connect) {
if (connect) { if (connect) {
/* Physical connection does not mean there is a recipient to send packets too. /* Physical connection does not mean there is a recipient to send packets
This will be done by the receive callback! */ too. This will be done by the receive callback! */
physicalConnection = true; physicalConnection = true;
} else { } else {
physicalConnection = false; physicalConnection = false;

View File

@ -8,14 +8,15 @@
#define TCPIP_RECV_WIRETAPPING 0 #define TCPIP_RECV_WIRETAPPING 0
/** /**
* This bridge is used to forward TMTC packets received via LwIP UDP to the internal software bus. * This bridge is used to forward TMTC packets received via LwIP UDP to the
* internal software bus.
*/ */
class TmTcLwIpUdpBridge : public TmTcBridge { class TmTcLwIpUdpBridge : public TmTcBridge {
friend class UdpTcLwIpPollingTask; friend class UdpTcLwIpPollingTask;
public: public:
TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor, object_id_t tmStoreId, TmTcLwIpUdpBridge(object_id_t objectId, object_id_t ccsdsPacketDistributor,
object_id_t tcStoreId); object_id_t tmStoreId, object_id_t tcStoreId);
virtual ~TmTcLwIpUdpBridge(); virtual ~TmTcLwIpUdpBridge();
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
@ -44,8 +45,9 @@ class TmTcLwIpUdpBridge : public TmTcBridge {
* @param addr Source address which will be bound to TmTcUdpBridge::lastAdd * @param addr Source address which will be bound to TmTcUdpBridge::lastAdd
* @param port * @param port
*/ */
static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_, struct pbuf *p, static void udp_server_receive_callback(void *arg, struct udp_pcb *upcb_,
const ip_addr_t *addr, u16_t port); struct pbuf *p, const ip_addr_t *addr,
u16_t port);
/** /**
* Check whether the communication link is up. * Check whether the communication link is up.
@ -54,7 +56,7 @@ class TmTcLwIpUdpBridge : public TmTcBridge {
*/ */
bool comLinkUp() const; bool comLinkUp() const;
private: private:
struct udp_pcb *upcb = nullptr; struct udp_pcb *upcb = nullptr;
ip_addr_t lastAdd; ip_addr_t lastAdd;
u16_t lastPort = 0; u16_t lastPort = 0;
@ -67,9 +69,9 @@ class TmTcLwIpUdpBridge : public TmTcBridge {
/** /**
* Used to notify bridge about change in the physical ethernet connection. * Used to notify bridge about change in the physical ethernet connection.
* Connection does not mean that replies are possible (recipient not set yet), but * Connection does not mean that replies are possible (recipient not set yet),
* disconnect means that we can't send anything. Caller must ensure thread-safety * but disconnect means that we can't send anything. Caller must ensure
* by using the bridge lock. * thread-safety by using the bridge lock.
*/ */
void physicalConnectStatusChange(bool connect); void physicalConnectStatusChange(bool connect);
}; };

View File

@ -12,9 +12,11 @@
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
#include "networking.h" #include "networking.h"
UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, UdpTcLwIpPollingTask::UdpTcLwIpPollingTask(object_id_t objectId,
struct netif* gnetif) object_id_t bridgeId,
: SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId), gnetif(gnetif) {} struct netif *gnetif)
: SystemObject(objectId), periodicHandleCounter(0), bridgeId(bridgeId),
gnetif(gnetif) {}
UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {} UdpTcLwIpPollingTask::~UdpTcLwIpPollingTask() {}
@ -47,7 +49,8 @@ ReturnValue_t UdpTcLwIpPollingTask::performOperation(uint8_t operationCode) {
/* In case ethernet cable is disconnected */ /* In case ethernet cable is disconnected */
if (not networking::getEthCableConnected() and udpBridge->comLinkUp()) { if (not networking::getEthCableConnected() and udpBridge->comLinkUp()) {
udpBridge->physicalConnectStatusChange(false); udpBridge->physicalConnectStatusChange(false);
} else if (networking::getEthCableConnected() and not udpBridge->comLinkUp()) { } else if (networking::getEthCableConnected() and
not udpBridge->comLinkUp()) {
udpBridge->physicalConnectStatusChange(true); udpBridge->physicalConnectStatusChange(true);
} }
} }

View File

@ -15,8 +15,9 @@ class TmTcLwIpUdpBridge;
class UdpTcLwIpPollingTask : public SystemObject, class UdpTcLwIpPollingTask : public SystemObject,
public ExecutableObjectIF, public ExecutableObjectIF,
public HasReturnvaluesIF { public HasReturnvaluesIF {
public: public:
UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId, struct netif* gnetif); UdpTcLwIpPollingTask(object_id_t objectId, object_id_t bridgeId,
struct netif *gnetif);
virtual ~UdpTcLwIpPollingTask(); virtual ~UdpTcLwIpPollingTask();
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
@ -28,12 +29,12 @@ class UdpTcLwIpPollingTask : public SystemObject,
*/ */
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override;
private: private:
static const uint8_t PERIODIC_HANDLE_TRIGGER = 5; static const uint8_t PERIODIC_HANDLE_TRIGGER = 5;
uint8_t periodicHandleCounter; uint8_t periodicHandleCounter;
object_id_t bridgeId = 0; object_id_t bridgeId = 0;
TmTcLwIpUdpBridge* udpBridge = nullptr; TmTcLwIpUdpBridge *udpBridge = nullptr;
struct netif* gnetif = nullptr; struct netif *gnetif = nullptr;
}; };
#endif /* BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ */ #endif /* BSP_STM32_RTEMS_EMACPOLLINGTASK_H_ */

View File

@ -13,18 +13,18 @@
uint8_t DHCP_state = DHCP_OFF; uint8_t DHCP_state = DHCP_OFF;
uint32_t DHCPfineTimer = 0; uint32_t DHCPfineTimer = 0;
void handle_dhcp_timeout(struct netif* netif); void handle_dhcp_timeout(struct netif *netif);
void handle_dhcp_start(struct netif* netif); void handle_dhcp_start(struct netif *netif);
void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp); void handle_dhcp_wait(struct netif *netif, struct dhcp **dhcp);
void handle_dhcp_down(struct netif* netif); void handle_dhcp_down(struct netif *netif);
/** /**
* @brief DHCP_Process_Handle * @brief DHCP_Process_Handle
* @param None * @param None
* @retval None * @retval None
*/ */
void DHCP_Process(struct netif* netif) { void DHCP_Process(struct netif *netif) {
struct dhcp* dhcp = NULL; struct dhcp *dhcp = NULL;
switch (DHCP_state) { switch (DHCP_state) {
case DHCP_START: { case DHCP_START: {
handle_dhcp_start(netif); handle_dhcp_start(netif);
@ -45,7 +45,7 @@ void DHCP_Process(struct netif* netif) {
} }
} }
void handle_dhcp_timeout(struct netif* netif) { void handle_dhcp_timeout(struct netif *netif) {
ip_addr_t ipaddr; ip_addr_t ipaddr;
ip_addr_t netmask; ip_addr_t netmask;
ip_addr_t gw; ip_addr_t gw;
@ -61,11 +61,11 @@ void handle_dhcp_timeout(struct netif* netif) {
printf("DHCP Timeout\n\r"); printf("DHCP Timeout\n\r");
uint8_t iptxt[20]; uint8_t iptxt[20];
sprintf((char*)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif)));
printf("Assigning static IP address: %s\n", iptxt); printf("Assigning static IP address: %s\n", iptxt);
#if defined FSFW_OSAL_FREERTOS #if defined FSFW_OSAL_FREERTOS
ETH_HandleTypeDef* handle = getEthernetHandle(); ETH_HandleTypeDef *handle = getEthernetHandle();
handle->gState = HAL_ETH_STATE_READY; handle->gState = HAL_ETH_STATE_READY;
#endif #endif
@ -82,7 +82,7 @@ void handle_dhcp_timeout(struct netif* netif) {
* @param netif * @param netif
* @retval None * @retval None
*/ */
void DHCP_Periodic_Handle(struct netif* netif) { void DHCP_Periodic_Handle(struct netif *netif) {
/* Fine DHCP periodic process every 500ms */ /* Fine DHCP periodic process every 500ms */
if (HAL_GetTick() - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) { if (HAL_GetTick() - DHCPfineTimer >= DHCP_FINE_TIMER_MSECS) {
DHCPfineTimer = HAL_GetTick(); DHCPfineTimer = HAL_GetTick();
@ -91,7 +91,7 @@ void DHCP_Periodic_Handle(struct netif* netif) {
} }
} }
void handle_dhcp_start(struct netif* netif) { void handle_dhcp_start(struct netif *netif) {
printf("handle_dhcp_start: Looking for DHCP server ...\n\r"); printf("handle_dhcp_start: Looking for DHCP server ...\n\r");
#if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_TMTC_COMMANDING == 1
#if OBSW_ETHERNET_USE_LED1_LED2 == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1
@ -106,10 +106,11 @@ void handle_dhcp_start(struct netif* netif) {
DHCP_state = DHCP_WAIT_ADDRESS; DHCP_state = DHCP_WAIT_ADDRESS;
} }
void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) { void handle_dhcp_wait(struct netif *netif, struct dhcp **dhcp) {
if (dhcp_supplied_address(netif)) { if (dhcp_supplied_address(netif)) {
DHCP_state = DHCP_ADDRESS_ASSIGNED; 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); printf("Listener port: %d\n\r", UDP_SERVER_PORT);
#if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_TMTC_COMMANDING == 1
#if OBSW_ETHERNET_USE_LED1_LED2 == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1
@ -118,7 +119,8 @@ void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) {
#endif #endif
#endif #endif
} else { } else {
*dhcp = (struct dhcp*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP); *dhcp = (struct dhcp *)netif_get_client_data(
netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP);
/* DHCP timeout */ /* DHCP timeout */
if ((*dhcp)->tries > MAX_DHCP_TRIES) { if ((*dhcp)->tries > MAX_DHCP_TRIES) {
@ -127,7 +129,7 @@ void handle_dhcp_wait(struct netif* netif, struct dhcp** dhcp) {
} }
} }
void handle_dhcp_down(struct netif* netif) { void handle_dhcp_down(struct netif *netif) {
DHCP_state = DHCP_OFF; DHCP_state = DHCP_OFF;
#if OBSW_ETHERNET_TMTC_COMMANDING == 1 #if OBSW_ETHERNET_TMTC_COMMANDING == 1
printf("DHCP_Process: The network cable is not connected.\n\r"); printf("DHCP_Process: The network cable is not connected.\n\r");

View File

@ -21,7 +21,7 @@
uint32_t ethernetLinkTimer = 0; uint32_t ethernetLinkTimer = 0;
/* Private function prototypes -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
void handle_status_change(struct netif* netif, bool link_up); void handle_status_change(struct netif *netif, bool link_up);
/* Private functions ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
/** /**
@ -29,7 +29,7 @@ void handle_status_change(struct netif* netif, bool link_up);
* @param netif: the network interface * @param netif: the network interface
* @retval None * @retval None
*/ */
void networking::ethernetLinkStatusUpdated(struct netif* netif) { void networking::ethernetLinkStatusUpdated(struct netif *netif) {
if (netif_is_link_up(netif)) { if (netif_is_link_up(netif)) {
networking::setEthCableConnected(true); networking::setEthCableConnected(true);
handle_status_change(netif, true); handle_status_change(netif, true);
@ -39,16 +39,16 @@ void networking::ethernetLinkStatusUpdated(struct netif* netif) {
} }
} }
void handle_status_change(struct netif* netif, bool link_up) { void handle_status_change(struct netif *netif, bool link_up) {
if (link_up) { if (link_up) {
#if LWIP_DHCP #if LWIP_DHCP
/* Update DHCP state machine */ /* Update DHCP state machine */
set_dhcp_state(DHCP_START); set_dhcp_state(DHCP_START);
#else #else
uint8_t iptxt[20]; uint8_t iptxt[20];
sprintf((char*)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif))); sprintf((char *)iptxt, "%s", ip4addr_ntoa(netif_ip4_addr(netif)));
printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r", iptxt, printf("\rNetwork cable connected. Static IP address: %s | Port: %d\n\r",
UDP_SERVER_PORT); iptxt, UDP_SERVER_PORT);
#if OBSW_ETHERNET_USE_LED1_LED2 == 1 #if OBSW_ETHERNET_USE_LED1_LED2 == 1
BSP_LED_On(LED1); BSP_LED_On(LED1);
BSP_LED_Off(LED2); BSP_LED_Off(LED2);
@ -75,7 +75,7 @@ void handle_status_change(struct netif* netif, bool link_up) {
* @param netif * @param netif
* @retval None * @retval None
*/ */
void networking::ethernetLinkPeriodicHandle(struct netif* netif) { void networking::ethernetLinkPeriodicHandle(struct netif *netif) {
/* Ethernet Link every 100ms */ /* Ethernet Link every 100ms */
if (HAL_GetTick() - ethernetLinkTimer >= 100) { if (HAL_GetTick() - ethernetLinkTimer >= 100) {
ethernetLinkTimer = HAL_GetTick(); ethernetLinkTimer = HAL_GetTick();

View File

@ -72,8 +72,8 @@
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* /*
@Note: This interface is implemented to operate in zero-copy mode only: @Note: This interface is implemented to operate in zero-copy mode only:
- Rx buffers are allocated statically and passed directly to the LwIP stack - Rx buffers are allocated statically and passed directly to the LwIP
they will return back to DMA after been processed by the stack. stack they will return back to DMA after been processed by the stack.
- Tx Buffers will be allocated from LwIP stack memory heap, - Tx Buffers will be allocated from LwIP stack memory heap,
then passed to ETH HAL driver. then passed to ETH HAL driver.
@ -91,40 +91,44 @@
#if defined(__ICCARM__) /*!< IAR Compiler */ #if defined(__ICCARM__) /*!< IAR Compiler */
#pragma location = 0x30040000 #pragma location = 0x30040000
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ ETH_DMADescTypeDef
DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
#pragma location = 0x30040060 #pragma location = 0x30040060
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ ETH_DMADescTypeDef
DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
#pragma location = 0x30040200 #pragma location = 0x30040200
uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffers */ uint8_t Rx_Buff[ETH_RX_DESC_CNT]
[ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffers */
#elif defined(__CC_ARM) /* MDK ARM Compiler */ #elif defined(__CC_ARM) /* MDK ARM Compiler */
__attribute__((section(".RxDecripSection"))) __attribute__((section(".RxDecripSection"))) ETH_DMADescTypeDef
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */ DMARxDscrTab[ETH_RX_DESC_CNT]; /* Ethernet Rx DMA Descriptors */
__attribute__((section(".TxDecripSection"))) __attribute__((section(".TxDecripSection"))) ETH_DMADescTypeDef
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */ DMATxDscrTab[ETH_TX_DESC_CNT]; /* Ethernet Tx DMA Descriptors */
__attribute__((section(".RxArraySection"))) __attribute__((section(".RxArraySection"))) uint8_t
uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffer */ Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]; /* Ethernet Receive Buffer */
#elif defined(__GNUC__) /* GNU Compiler */ #elif defined(__GNUC__) /* GNU Compiler */
#ifdef FSFW_OSAL_RTEMS #ifdef FSFW_OSAL_RTEMS
/* Put into special RTEMS section and align correctly */ /* Put into special RTEMS section and align correctly */
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((
__attribute__((section(".bsp_nocache"), section(".bsp_nocache"),
__aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */ __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Rx DMA Descriptors */
/* Put into special RTEMS section and align correctly */ /* Put into special RTEMS section and align correctly */
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((
__attribute__((section(".bsp_nocache"), section(".bsp_nocache"),
__aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */ __aligned__(DMA_DESCRIPTOR_ALIGNMENT))); /* Ethernet Tx DMA Descriptors */
/* Ethernet Receive Buffers. Just place somewhere is BSS instead of explicitely placing it */ /* 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]; uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE];
#elif defined FSFW_OSAL_FREERTOS #elif defined FSFW_OSAL_FREERTOS
/* Placement and alignment specified in linker script here */ /* Placement and alignment specified in linker script here */
ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] ETH_DMADescTypeDef DMARxDscrTab[ETH_RX_DESC_CNT] __attribute__((
__attribute__((section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */ section(".RxDecripSection"))); /* Ethernet Rx DMA Descriptors */
ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] ETH_DMADescTypeDef DMATxDscrTab[ETH_TX_DESC_CNT] __attribute__((
__attribute__((section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */ section(".TxDecripSection"))); /* Ethernet Tx DMA Descriptors */
uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE] uint8_t Rx_Buff[ETH_RX_DESC_CNT][ETH_RX_BUFFER_SIZE]
__attribute__((section(".RxArraySection"))); /* Ethernet Receive Buffers */ __attribute__((section(".RxArraySection"))); /* Ethernet Receive Buffers */
#endif /* FSFW_FREERTOS */ #endif /* FSFW_FREERTOS */
@ -148,12 +152,15 @@ void pbuf_free_custom(struct pbuf *p);
int32_t ETH_PHY_IO_Init(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_ReadReg(uint32_t DevAddr, uint32_t RegAddr,
int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal); 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); int32_t ETH_PHY_IO_GetTick(void);
lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, ETH_PHY_IO_DeInit, ETH_PHY_IO_WriteReg, lan8742_IOCtx_t LAN8742_IOCtx = {ETH_PHY_IO_Init, ETH_PHY_IO_DeInit,
ETH_PHY_IO_ReadReg, ETH_PHY_IO_GetTick}; ETH_PHY_IO_WriteReg, ETH_PHY_IO_ReadReg,
ETH_PHY_IO_GetTick};
/* Private functions ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/
/******************************************************************************* /*******************************************************************************
LL Driver Interface ( LwIP stack --> ETH) LL Driver Interface ( LwIP stack --> ETH)
@ -207,7 +214,8 @@ static void low_level_init(struct netif *netif) {
/* Set Tx packet config common parameters */ /* 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.Attributes =
ETH_TX_PACKETS_FEATURES_CSUM | ETH_TX_PACKETS_FEATURES_CRCPAD;
TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC; TxConfig.ChecksumCtrl = ETH_CHECKSUM_IPHDR_PAYLOAD_INSERT_PHDR_CALC;
TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT; TxConfig.CRCPadCtrl = ETH_CRC_PAD_INSERT;
@ -221,12 +229,13 @@ static void low_level_init(struct netif *netif) {
} }
/** /**
* @brief This function should do the actual transmission of the packet. The packet is * @brief This function should do the actual transmission of the packet. The
* contained in the pbuf that is passed to the function. This pbuf * packet is contained in the pbuf that is passed to the function. This pbuf
* might be chained. * might be chained.
* *
* @param netif the lwip network interface structure for this ethernetif * @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) * @param p the MAC packet to send (e.g. IP packet including MAC addresses and
* type)
* @return ERR_OK if the packet could be sent * @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent * an err_t value if the packet couldn't be sent
* *
@ -242,7 +251,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT]; ETH_BufferTypeDef Txbuffer[ETH_TX_DESC_CNT];
for (q = p; q != NULL; q = q->next) { for (q = p; q != NULL; q = q->next) {
if (i >= ETH_TX_DESC_CNT) return ERR_IF; if (i >= ETH_TX_DESC_CNT)
return ERR_IF;
Txbuffer[i].buffer = q->payload; Txbuffer[i].buffer = q->payload;
Txbuffer[i].len = q->len; Txbuffer[i].len = q->len;
@ -265,7 +275,8 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) {
HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, 20); HAL_StatusTypeDef ret = HAL_ETH_Transmit(&EthHandle, &TxConfig, 20);
if (ret != HAL_OK) { 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; return errval;
@ -289,10 +300,12 @@ static struct pbuf *low_level_input(struct netif *netif) {
HAL_ETH_GetRxDataLength(&EthHandle, &framelength); HAL_ETH_GetRxDataLength(&EthHandle, &framelength);
/* Invalidate data cache for ETH Rx Buffers */ /* Invalidate data cache for ETH Rx Buffers */
SCB_InvalidateDCache_by_Addr((uint32_t *)Rx_Buff, (ETH_RX_DESC_CNT * ETH_RX_BUFFER_SIZE)); SCB_InvalidateDCache_by_Addr((uint32_t *)Rx_Buff,
(ETH_RX_DESC_CNT * ETH_RX_BUFFER_SIZE));
p = pbuf_alloced_custom(PBUF_RAW, framelength, PBUF_POOL, &rx_pbuf[current_pbuf_idx], p = pbuf_alloced_custom(PBUF_RAW, framelength, PBUF_POOL,
RxBuff.buffer, ETH_RX_BUFFER_SIZE); &rx_pbuf[current_pbuf_idx], RxBuff.buffer,
ETH_RX_BUFFER_SIZE);
if (current_pbuf_idx < (ETH_RX_DESC_CNT - 1)) { if (current_pbuf_idx < (ETH_RX_DESC_CNT - 1)) {
current_pbuf_idx++; current_pbuf_idx++;
} else { } else {
@ -306,11 +319,11 @@ static struct pbuf *low_level_input(struct netif *netif) {
} }
/** /**
* @brief This function is the ethernetif_input task, it is processed when a packet * @brief This function is the ethernetif_input task, it is processed when a
* is ready to be read from the interface. It uses the function low_level_input() * packet is ready to be read from the interface. It uses the function
* that should handle the actual reception of bytes from the network * low_level_input() that should handle the actual reception of bytes from the
* interface. Then the type of the received packet is determined and * network interface. Then the type of the received packet is determined and the
* the appropriate input function is called. * appropriate input function is called.
* *
* @param netif the lwip network interface structure for this ethernetif * @param netif the lwip network interface structure for this ethernetif
*/ */
@ -322,7 +335,8 @@ void ethernetif_input(struct netif *netif) {
p = low_level_input(netif); p = low_level_input(netif);
/* no packet could be read, silently ignore this */ /* no packet could be read, silently ignore this */
if (p == NULL) return; if (p == NULL)
return;
/* entry point to the LwIP stack */ /* entry point to the LwIP stack */
err = netif->input(p, netif); err = netif->input(p, netif);
@ -413,7 +427,8 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) {
__HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE(); __HAL_RCC_GPIOG_CLK_ENABLE();
/* Ethernet pins configuration ************************************************/ /* Ethernet pins configuration
* ************************************************/
/* /*
RMII_REF_CLK ----------------------> PA1 RMII_REF_CLK ----------------------> PA1
RMII_MDIO -------------------------> PA2 RMII_MDIO -------------------------> PA2
@ -492,8 +507,10 @@ int32_t ETH_PHY_IO_DeInit(void) { return 0; }
* @param pRegVal: pointer to hold the register value * @param pRegVal: pointer to hold the register value
* @retval 0 if OK -1 if Error * @retval 0 if OK -1 if Error
*/ */
int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal) { int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr,
if (HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) != HAL_OK) { uint32_t *pRegVal) {
if (HAL_ETH_ReadPHYRegister(&EthHandle, DevAddr, RegAddr, pRegVal) !=
HAL_OK) {
return -1; return -1;
} }
@ -507,8 +524,10 @@ int32_t ETH_PHY_IO_ReadReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t *pRegVal
* @param RegVal: Value to be written * @param RegVal: Value to be written
* @retval 0 if OK -1 if Error * @retval 0 if OK -1 if Error
*/ */
int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr, uint32_t RegVal) { int32_t ETH_PHY_IO_WriteReg(uint32_t DevAddr, uint32_t RegAddr,
if (HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) != HAL_OK) { uint32_t RegVal) {
if (HAL_ETH_WritePHYRegister(&EthHandle, DevAddr, RegAddr, RegVal) !=
HAL_OK) {
return -1; return -1;
} }
@ -536,7 +555,8 @@ void ethernet_link_check_state(struct netif *netif) {
HAL_ETH_Stop(&EthHandle); HAL_ETH_Stop(&EthHandle);
netif_set_down(netif); netif_set_down(netif);
netif_set_link_down(netif); netif_set_link_down(netif);
} else if (!netif_is_link_up(netif) && (PHYLinkState > LAN8742_STATUS_LINK_DOWN)) { } else if (!netif_is_link_up(netif) &&
(PHYLinkState > LAN8742_STATUS_LINK_DOWN)) {
switch (PHYLinkState) { switch (PHYLinkState) {
case LAN8742_STATUS_100MBITS_FULLDUPLEX: case LAN8742_STATUS_100MBITS_FULLDUPLEX:
duplex = ETH_FULLDUPLEX_MODE; duplex = ETH_FULLDUPLEX_MODE;

View File

@ -4,11 +4,14 @@
bool ethernetCableConnected = false; bool ethernetCableConnected = false;
void networking::setEthCableConnected(bool status) { ethernetCableConnected = status; } void networking::setEthCableConnected(bool status) {
ethernetCableConnected = status;
}
bool networking::getEthCableConnected() { return ethernetCableConnected; } 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(ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2, NETMASK_ADDR3);
IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);

View File

@ -7,7 +7,7 @@ namespace networking {
void setEthCableConnected(bool status); void setEthCableConnected(bool status);
bool getEthCableConnected(); bool getEthCableConnected();
void setLwipAddresses(ip_addr_t* ipaddr, ip_addr_t* netmask, ip_addr_t* gw); void setLwipAddresses(ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw);
} // namespace networking } // namespace networking

View File

@ -8,7 +8,8 @@ extern "C" {
/* UDP local connection port. Client needs to bind to this port */ /* UDP local connection port. Client needs to bind to this port */
#define UDP_SERVER_PORT 7 #define UDP_SERVER_PORT 7
/*Static DEST IP ADDRESS: DEST_IP_ADDR0.DEST_IP_ADDR1.DEST_IP_ADDR2.DEST_IP_ADDR3 */ /*Static DEST IP ADDRESS:
* DEST_IP_ADDR0.DEST_IP_ADDR1.DEST_IP_ADDR2.DEST_IP_ADDR3 */
#define DEST_IP_ADDR0 ((uint8_t)169U) #define DEST_IP_ADDR0 ((uint8_t)169U)
#define DEST_IP_ADDR1 ((uint8_t)254U) #define DEST_IP_ADDR1 ((uint8_t)254U)
#define DEST_IP_ADDR2 ((uint8_t)39U) #define DEST_IP_ADDR2 ((uint8_t)39U)