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