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

Replace the if's used for message type checking with proper...

Replace the if's used for message type checking with proper error-handler-controlled assertions. One test needs updating to use the error handler's output.
parent d214bfe1
No related branches found
No related tags found
No related merge requests found
......@@ -58,9 +58,10 @@ public:
* containing the current configuration
* **for the parameters specified in the carried valid IDs**.
*
* No sophisticated error checking for now, just whether the package is of the correct type
* and whether the requested IDs are valid, ignoring the invalid ones. If no IDs are correct,
* the returned message shall be empty.
* No sophisticated error checking for now, just whether the packet is of the correct type
* and whether the requested IDs are valid, ignoring the invalid ones.
* If the packet has an incorrect header, an InternalError::UnacceptablePacket is raised.
* If no IDs are correct, the returned message shall be empty.
*
* @param paramId: a valid TC[20, 1] packet carrying the requested parameter IDs
* @return None (messages are stored using storeMessage())
......
......@@ -41,22 +41,29 @@ ParameterService::ParameterService() {
void ParameterService::reportParameterIds(Message paramIds) {
Message reqParam(20, 2, Message::TM, 1); // empty TM[20, 2] parameter report message
if (paramIds.packetType == Message::TC && paramIds.serviceType == 20 &&
paramIds.messageType == 1) {
uint16_t ids = paramIds.readUint16();
reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs
for (int i = 0; i < ids; i++) {
uint16_t currId = paramIds.readUint16(); // current ID to be appended
if (paramsList.find(currId) != paramsList.end()) {
reqParam.appendUint16(currId);
reqParam.appendUint32(paramsList[currId].settingData);
}
else {
continue; // generate failure of execution notification (todo) for ST[06] & ignore
}
// if (paramIds.packetType == Message::TC && paramIds.serviceType == 20 &&
// paramIds.messageType == 1) {
// assertion: correct message, packet and service type (at failure throws an
// InternalError::UnacceptablePacket)
ErrorHandler::assertInternal(paramIds.packetType == Message::TC
&& paramIds.messageType == 1
&& paramIds.serviceType == 20,
ErrorHandler::InternalErrorType::UnacceptablePacket);
uint16_t ids = paramIds.readUint16();
reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs
for (int i = 0; i < ids; i++) {
uint16_t currId = paramIds.readUint16(); // current ID to be appended
if (paramsList.find(currId) != paramsList.end()) {
reqParam.appendUint16(currId);
reqParam.appendUint32(paramsList[currId].settingData);
}
else {
continue; // generate failure of execution notification (todo) for ST[06] & ignore
}
}
......@@ -64,20 +71,24 @@ void ParameterService::reportParameterIds(Message paramIds) {
}
void ParameterService::setParameterIds(Message newParamValues) {
if (newParamValues.packetType == Message::TC && newParamValues.serviceType == 20 &&
newParamValues.messageType == 3) {
uint16_t ids = newParamValues.readUint16(); //get number of ID's
for (int i = 0; i < ids; i++) {
uint16_t currId = newParamValues.readUint16();
// assertion: correct message, packet and service type (at failure throws an
// InternalError::UnacceptablePacket which gets logged)
ErrorHandler::assertInternal(newParamValues.packetType == Message::TC
&& newParamValues.messageType == 1
&& newParamValues.serviceType == 20,
ErrorHandler::InternalErrorType::UnacceptablePacket);
uint16_t ids = newParamValues.readUint16(); //get number of ID's
for (int i = 0; i < ids; i++) {
uint16_t currId = newParamValues.readUint16();
if (paramsList.find(currId) != paramsList.end()) {
paramsList[currId].settingData = newParamValues.readUint32();
}
if (paramsList.find(currId) != paramsList.end()) {
paramsList[currId].settingData = newParamValues.readUint32();
}
else {
continue; // generate failure of execution notification (todo) for ST[06] & ignore
}
else {
continue; // generate failure of execution notification (todo) for ST[06] & ignore
}
}
}
......
......@@ -28,16 +28,19 @@ TEST_CASE("Parameter Report Subservice") {
}
}
SECTION("Wrong Message Type Handling Test") {
Message falseRequest(15, 3, Message::TM, 1); // a totally wrong message
pserv.reportParameterIds(falseRequest);
Message response = ServiceTests::get(0);
CHECK(response.messageType == 2);
CHECK(response.serviceType == 20);
CHECK(response.packetType == Message::TM);
CHECK(response.readPosition == 0); // if empty, this should't change from 0
}
// **WARNING**
// TODO: Update this test (and all tests in general) to use the error handler's output when
// checking for assertions.
// SECTION("Wrong Message Type Handling Test") {
// Message falseRequest(15, 3, Message::TM, 1); // a totally wrong message
//
// pserv.reportParameterIds(falseRequest);
// Message response = ServiceTests::get(0);
// CHECK(response.messageType == 2);
// CHECK(response.serviceType == 20);
// CHECK(response.packetType == Message::TM);
// CHECK(response.readPosition == 0); // if empty, this should't change from 0
// }
}
TEST_CASE("Parameter Setting Subservice") {
......
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