Skip to content
Snippets Groups Projects
Unverified Commit 7f7c18bc authored by Grigoris Pavlakis's avatar Grigoris Pavlakis
Browse files

Implement preliminary flag feature

Other changes:
Tweaked addNewParameter() in order for the IDs to be arbitrary (insertion
of already existing ID test incoming) according to suggestion by @kongr45gpen
parent c979e30a
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "etl/bitset.h" #include "etl/bitset.h"
// Number of binary flags in every parameter. Final number TBD. // Number of binary flags in every parameter. Final number TBD.
#define NUM_OF_FLAGS 5 #define NUM_OF_FLAGS 3
/** /**
* Implementation of a Parameter field, as specified in ECSS-E-ST-70-41C. * Implementation of a Parameter field, as specified in ECSS-E-ST-70-41C.
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
typedef uint16_t ParamId; typedef uint16_t ParamId;
typedef uint32_t ValueType; typedef uint32_t ValueType;
typedef void(*UpdatePtr)(ValueType*); typedef void(*UpdatePtr)(ValueType*);
typedef etl::bitset<NUM_OF_FLAGS> Flags;
/** /**
* Parameter class - Breakdown of fields * Parameter class - Breakdown of fields
...@@ -36,18 +37,20 @@ typedef void(*UpdatePtr)(ValueType*); ...@@ -36,18 +37,20 @@ typedef void(*UpdatePtr)(ValueType*);
* @todo: Find a way to store arbitrary types in currentValue * @todo: Find a way to store arbitrary types in currentValue
* *
* Additional features (not included in standard): * Additional features (not included in standard):
* @private flags: Various binary flags (number and meaning TBD). Ideas: * @private flags: Various binary flags (number and meaning TBD).
* update with priority, do not poll, do not allow manual manipulation etc. * Current flag meanings (starting from LSB, big-endian):
* Index 0: update with priority
* Index 1: manual update available
* Index 2: automatic update available
* *
* *
* Methods: * Methods:
* @public Parameter(): default constructor, do not use.
* @public Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue = 0, UpdatePtr newPtr = nullptr): * @public Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue = 0, UpdatePtr newPtr = nullptr):
* Create a new Parameter object with newPtc PTC, newPfc PFC, initialValue as its starting value and newPtr * Create a new Parameter object with newPtc PTC, newPfc PFC, initialValue as its starting value and newPtr
* as its update function pointer. Arguments initialValue and newPtr are optional, and have default values of * as its update function pointer. Arguments initialValue and newPtr are optional, and have default values of
* 0 and nullptr respectively. * 0 and nullptr respectively.
* *
* @public setCurrentValue(): Changes the current value of the parameter (todo: if the respective flag is not set) * @public setCurrentValue(): Changes the current value of the parameter
* @public getCurrentValue(): Gets the current value of the parameter * @public getCurrentValue(): Gets the current value of the parameter
* @public getPTC(), getPFC(): Returns the PFC and PTC of the parameter * @public getPTC(), getPFC(): Returns the PFC and PTC of the parameter
*/ */
...@@ -55,14 +58,14 @@ class Parameter { ...@@ -55,14 +58,14 @@ class Parameter {
uint8_t ptc; uint8_t ptc;
uint8_t pfc; uint8_t pfc;
UpdatePtr ptr; UpdatePtr ptr;
etl::bitset<NUM_OF_FLAGS> flags; Flags flags;
ValueType currentValue = 0; ValueType currentValue = 0;
public: public:
Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue = 0, UpdatePtr newPtr = nullptr); Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue = 0, UpdatePtr newPtr = nullptr);
void setCurrentValue(ValueType newVal); void setCurrentValue(ValueType newVal);
void setFlag(etl::bitset<NUM_OF_FLAGS> flags); void setFlag(const char* flags);
ValueType getCurrentValue(); ValueType getCurrentValue();
uint8_t getPTC(); uint8_t getPTC();
......
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
* exists in it) then returns false. * exists in it) then returns false.
* The parameter IDs are given sequentially, starting from 0. * The parameter IDs are given sequentially, starting from 0.
*/ */
bool addNewParameter(uint8_t ptc, uint8_t pfc, uint32_t initialValue = 0, UpdatePtr ptr = nullptr); bool addNewParameter(uint8_t id, Parameter param, const char* flags = "110");
/** /**
* This function receives a TC[20, 1] packet and returns a TM[20, 2] packet * This function receives a TC[20, 1] packet and returns a TM[20, 2] packet
......
#include "Services/Parameter.hpp" #include "Services/Parameter.hpp"
Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue, UpdatePtr newPtr) { Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, UpdatePtr newPtr) {
ptc = newPtc; ptc = newPtc;
pfc = newPfc; pfc = newPfc;
ptr = newPtr; ptr = newPtr;
// see Parameter.hpp for explanation on flags
// by default: no update priority, manual and automatic update available
if (ptr != nullptr) { if (ptr != nullptr) {
(*ptr)(&currentValue); // call the update function for the initial value (*ptr)(&currentValue); // call the update function for the initial value
} else { } else {
...@@ -13,7 +16,10 @@ Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue, Upda ...@@ -13,7 +16,10 @@ Parameter::Parameter(uint8_t newPtc, uint8_t newPfc, uint32_t initialValue, Upda
} }
void Parameter::setCurrentValue(ValueType newVal) { void Parameter::setCurrentValue(ValueType newVal) {
currentValue = newVal; // set the value only if the parameter can be updated manually
if (flags[2]) {
currentValue = newVal;
}
} }
ValueType Parameter::getCurrentValue() { ValueType Parameter::getCurrentValue() {
...@@ -28,6 +34,6 @@ uint8_t Parameter::getPFC() { ...@@ -28,6 +34,6 @@ uint8_t Parameter::getPFC() {
return pfc; return pfc;
} }
void Parameter::setFlag(etl::bitset<NUM_OF_FLAGS> flags) { void Parameter::setFlag(const char* flags) {
this->flags |= flags; this->flags = Flags(flags);
} }
...@@ -7,11 +7,11 @@ ParameterService::ParameterService() { ...@@ -7,11 +7,11 @@ ParameterService::ParameterService() {
// addNewParameter(3, 14); // addNewParameter(3, 14);
} }
bool ParameterService::addNewParameter(uint8_t ptc, uint8_t pfc, uint32_t initialValue, UpdatePtr ptr) { bool ParameterService::addNewParameter(uint8_t id, Parameter param, const char* flags) {
Parameter param = Parameter(ptc, pfc, initialValue, ptr);
try { try {
// second element of the returned std::pair is whether the given item was inserted or not // second element of the returned std::pair is whether the given item was inserted or not
paramsList.insert(std::make_pair(paramsList.size(), param)); param.setFlag(flags);
paramsList.insert(std::make_pair(id, param));
return true; return true;
} }
catch (etl::map_full &mapFull) { catch (etl::map_full &mapFull) {
...@@ -82,8 +82,7 @@ void ParameterService::setParameterIds(Message& newParamValues) { ...@@ -82,8 +82,7 @@ void ParameterService::setParameterIds(Message& newParamValues) {
for (uint16_t i = 0; i < numOfIds; i++) { for (uint16_t i = 0; i < numOfIds; i++) {
uint16_t currId = newParamValues.readUint16(); uint16_t currId = newParamValues.readUint16();
// the parameter is checked for read-only status and manual update availability
// TODO: add a check here with the new flag functionality
try { try {
paramsList.at(currId).setCurrentValue(newParamValues.readUint32()); paramsList.at(currId).setCurrentValue(newParamValues.readUint32());
} }
......
...@@ -17,13 +17,22 @@ void foo(ValueType* bar) { // sample function ...@@ -17,13 +17,22 @@ void foo(ValueType* bar) { // sample function
TEST_CASE("Parameter Service - General") { TEST_CASE("Parameter Service - General") {
SECTION("Addition to full map") { SECTION("Addition to full map") {
pserv.addNewParameter(3, 14); // this one has ID 0
pserv.addNewParameter(1, 7, 12); // this one has 1
pserv.addNewParameter(4, 12, 3, nullptr); // this one has 2
pserv.addNewParameter(12, 3, 6, &foo); // this one has 3
pserv.addNewParameter(15, 7, 3, &foo); //and this one 4
REQUIRE_FALSE(pserv.addNewParameter(15, 5, 4)); // addNewParameter should return false Parameter param0 = Parameter(3, 14);
Parameter param1 = Parameter(1, 7, 12);
Parameter param2 = Parameter(4, 12, 3, nullptr);
Parameter param3 = Parameter(12, 3, 6, &foo);
Parameter param4 = Parameter(15, 7, 3, &foo);
Parameter param5 = Parameter(15, 5, 4);
pserv.addNewParameter(0, param0);
pserv.addNewParameter(1, param1);
pserv.addNewParameter(2, param2);
pserv.addNewParameter(3, param3);
pserv.addNewParameter(4, param4);
REQUIRE_FALSE(pserv.addNewParameter(5, param5)); // addNewParameter should return false
Services.reset(); // reset all services Services.reset(); // reset all services
} }
...@@ -41,9 +50,12 @@ TEST_CASE("Parameter Report Subservice") { ...@@ -41,9 +50,12 @@ TEST_CASE("Parameter Report Subservice") {
// } // }
SECTION("Faulty instruction handling") { SECTION("Faulty instruction handling") {
pserv.addNewParameter(3, 14); // ID 0 Parameter param0 = Parameter(3, 14);
pserv.addNewParameter(1, 7, 12); // ID 1 Parameter param1 = Parameter(1, 7, 12);
pserv.addNewParameter(4, 12, 3, nullptr); // ID 2 Parameter param2 = Parameter(4, 12, 3, nullptr);
pserv.addNewParameter(0, param0);
pserv.addNewParameter(1, param1);
pserv.addNewParameter(2, param2);
Message request(20, 1, Message::TC, 1); Message request(20, 1, Message::TC, 1);
request.appendUint16(2); // number of requested IDs request.appendUint16(2); // number of requested IDs
...@@ -86,9 +98,12 @@ TEST_CASE("Parameter Report Subservice") { ...@@ -86,9 +98,12 @@ TEST_CASE("Parameter Report Subservice") {
TEST_CASE("Parameter Setting Subservice") { TEST_CASE("Parameter Setting Subservice") {
SECTION("Faulty Instruction Handling Test") { SECTION("Faulty Instruction Handling Test") {
pserv.addNewParameter(3, 14); // ID 0 Parameter param0 = Parameter(3, 14);
pserv.addNewParameter(1, 7, 12); // ID 1 Parameter param1 = Parameter(1, 7, 12);
pserv.addNewParameter(4, 12, 3, nullptr); // ID 2 Parameter param2 = Parameter(4, 12, 3, nullptr);
pserv.addNewParameter(0, param0);
pserv.addNewParameter(1, param1);
pserv.addNewParameter(2, param2);
Message setRequest(20, 3, Message::TC, 1); Message setRequest(20, 3, Message::TC, 1);
setRequest.appendUint16(2); // total number of IDs setRequest.appendUint16(2); // total number of IDs
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment