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

Fix an uncaught exception on addNewParameter()

Also update some of the tests
parent 89088dd4
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ class Parameter {
uint8_t ptc;
uint8_t pfc;
UpdatePtr ptr;
etl::bitset<NUM_OF_FLAGS> flags = {false};
etl::bitset<NUM_OF_FLAGS> flags;
ValueType currentValue = 0;
public:
......
......@@ -9,8 +9,13 @@ ParameterService::ParameterService() {
bool ParameterService::addNewParameter(uint8_t ptc, uint8_t pfc, uint32_t initialValue, UpdatePtr ptr) {
Parameter param = Parameter(ptc, pfc, initialValue, ptr);
return paramsList.insert(std::make_pair(paramsList.size() + 1, param)).second;
// second element of the returned std::pair is whether the given item was inserted or not
try {
// second element of the returned std::pair is whether the given item was inserted or not
return paramsList.insert(std::make_pair(paramsList.size() + 1, param)).second;
}
catch(etl::map_full) {
return false;
}
}
void ParameterService::reportParameterIds(Message& paramIds) {
......@@ -30,9 +35,9 @@ void ParameterService::reportParameterIds(Message& paramIds) {
ErrorHandler::AcceptanceErrorType::UnacceptableMessage);
uint16_t numOfIds = paramIds.readUint16(); // number of parameter IDs carried in the message
uint16_t numOfValidIds = 0; // number of IDs that are actually included in the list
reqParam.skipBytes(2); // skip the first 16 bits where the number of valid IDs will be included
//reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs
// uint16_t numOfValidIds = 0; // number of IDs that are actually included in the list
// reqParam.skipBytes(2); // skip the first 16 bits where the number of valid IDs will be included
reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs
for (uint16_t i = 0; i < numOfIds; i++) {
uint16_t currId = paramIds.readUint16(); // current ID to be appended
......@@ -40,16 +45,12 @@ void ParameterService::reportParameterIds(Message& paramIds) {
if (paramsList.find(currId) != paramsList.end()) {
reqParam.appendUint16(currId);
reqParam.appendUint32(paramsList[currId].getCurrentValue());
numOfValidIds++;
} else {
ErrorHandler::reportError(paramIds, ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError);
continue; // generate failed start of execution notification & ignore
}
}
reqParam.resetRead(); // reset the read/write position
reqParam.appendUint16(numOfValidIds);
storeMessage(reqParam);
}
......@@ -81,29 +82,28 @@ void ParameterService::setParameterIds(Message& newParamValues) {
}
}
}
// possibly useless
//uint16_t ParameterService::numOfValidIds(Message idMsg) {
// idMsg.resetRead();
// // start reading from the beginning of the idMsg object
// // (original obj. will not be influenced if this is called by value)
//
// uint16_t ids = idMsg.readUint16(); // first 16bits of the packet are # of IDs
// uint16_t validIds = 0;
//
// for (uint16_t i = 0; i < ids; i++) {
// uint16_t currId = idMsg.readUint16();
//
// if (idMsg.messageType == 3) {
// idMsg.readUint32(); // skip the 32bit settings blocks, we need only the IDs
// }
//
// if (paramsList.find(currId) != paramsList.end()) {
// validIds++;
// }
// }
//
// return validIds;
//}
uint16_t ParameterService::numOfValidIds(Message idMsg) {
idMsg.resetRead();
// start reading from the beginning of the idMsg object
// (original obj. will not be influenced if this is called by value)
uint16_t ids = idMsg.readUint16(); // first 16bits of the packet are # of IDs
uint16_t validIds = 0;
for (uint16_t i = 0; i < ids; i++) {
uint16_t currId = idMsg.readUint16();
if (idMsg.messageType == 3) {
idMsg.readUint32(); // skip the 32bit settings blocks, we need only the IDs
}
if (paramsList.find(currId) != paramsList.end()) {
validIds++;
}
}
return validIds;
}
void ParameterService::execute(Message& message) {
switch (message.messageType) {
......
......@@ -9,43 +9,49 @@ void foo(ValueType* bar) { // sample function
*bar = 0xDEADBEEF;
}
TEST_CASE("Parameter Report Subservice") {
SECTION("Insertion test") {
/* test ideas:
* parameter setting while flag is active
*
*
*/
TEST_CASE("Parameter Service - General") {
SECTION("Parameter Setup") {
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
}
SECTION("ID checking") {
Message request(20, 1, Message::TC, 1);
Message report(20, 2, Message::TM, 1);
request.appendUint16(2);
SECTION("Addition to full map") {
CHECK(pserv.addNewParameter(15, 5, 4));
}
}
TEST_CASE("Parameter Report Subservice") {
SECTION("Faulty Instruction Handling Test") {
Message request(20, 1, Message::TC, 1);
Message report(20, 2, Message::TM, 1);
request.appendUint16(2); // number of requested IDs
request.appendUint16(34672); // faulty ID in this context
request.appendUint16(65535); // faulty ID in this context
request.appendUint16(1); // valid
MessageParser::execute(request);
report = ServiceTests::get(0);
request.resetRead();
report.readUint16();
request.readUint16();
CHECK(((ServiceTests::get(0).messageType == 4) && (ServiceTests::get(0).serviceType == 1)));
// check for an ST[1,4] message caused by the faulty ID
CHECK((ServiceTests::thrownError(ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError)));
// check for the thrown UnknownExecutionStartError
CHECK(((ServiceTests::get(1).messageType == 2) && (ServiceTests::get(1).serviceType == 20)));
// check for an ST[20,2] message (the one that contains the settings)
while (report.readPosition <= report.dataSize) {
CHECK_FALSE(report.readUint16() == 34672); // fail if faulty ID is present in report
report.readUint32(); // ignore the carried settings
}
ServiceTests::reset();
}
// **WARNING**
// TODO: Update this test (and all tests in general) to use the error handler's output when
// checking for assertions.
......
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