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

Revert reportParameterIds() to original in order to not break the flow of...

Revert reportParameterIds() to original in order to not break the flow of testing until storeMessage() stores the messages somewhere. Also fixed formatting to conform to voted code style.
parent 1dfbfbc3
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
* ECSS-E-ST-70-41C, chapter 7.3 * ECSS-E-ST-70-41C, chapter 7.3
*/ */
struct Parameter { struct Parameter {
uint8_t ptc; // Packet field type code (PTC) uint8_t ptc; // Packet field type code (PTC)
uint8_t pfc; // Packet field format code (PFC) uint8_t pfc; // Packet field format code (PFC)
uint16_t paramId; // Unique ID of the parameter uint16_t paramId; // Unique ID of the parameter
...@@ -36,6 +35,7 @@ struct Parameter { ...@@ -36,6 +35,7 @@ struct Parameter {
* for parameter reporting and modification. * for parameter reporting and modification.
* *
* @todo Ensure that the parameter list is sorted by ID * @todo Ensure that the parameter list is sorted by ID
* @todo Convert reportParameterIds() to void when storeMessage() stores and doesn't print
*/ */
class ParameterService : public Service { class ParameterService : public Service {
...@@ -47,7 +47,7 @@ private: ...@@ -47,7 +47,7 @@ private:
public: public:
ParameterService(); ParameterService();
void reportParameterIds(Message paramIds); Message reportParameterIds(Message paramIds);
void setParameterIds(Message newParamValues); void setParameterIds(Message newParamValues);
......
...@@ -32,8 +32,7 @@ ParameterService::ParameterService() { ...@@ -32,8 +32,7 @@ ParameterService::ParameterService() {
#endif #endif
} }
void ParameterService::reportParameterIds(Message paramIds) { Message ParameterService::reportParameterIds(Message paramIds) {
/** /**
* 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
* containing the current configuration * containing the current configuration
...@@ -59,20 +58,16 @@ void ParameterService::reportParameterIds(Message paramIds) { ...@@ -59,20 +58,16 @@ void ParameterService::reportParameterIds(Message paramIds) {
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(); uint16_t ids = paramIds.readUint16();
reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs reqParam.appendUint16(numOfValidIds(paramIds)); // include the number of valid IDs
for (int i = 0; i < ids; i++) { for (int i = 0; i < ids; i++) {
uint16_t currId = paramIds.readUint16(); // current ID to be appended uint16_t currId = paramIds.readUint16(); // current ID to be appended
if (currId < CONFIGLENGTH) { // check to prevent out-of-bounds access due to invalid id if (currId < CONFIGLENGTH) { // check to prevent out-of-bounds access due to invalid id
reqParam.appendUint16(currId); reqParam.appendUint16(currId);
reqParam.appendUint32(paramsList[currId].settingData); reqParam.appendUint32(paramsList[currId].settingData);
} else { } else {
// generate failure of execution notification for ST[06] // generate failure of execution notification for ST[06]
continue; //ignore the invalid ID continue; //ignore the invalid ID
} }
...@@ -80,10 +75,10 @@ void ParameterService::reportParameterIds(Message paramIds) { ...@@ -80,10 +75,10 @@ void ParameterService::reportParameterIds(Message paramIds) {
} }
storeMessage(reqParam); storeMessage(reqParam);
return reqParam; // this has to stay for now because no other way for testing
} }
void ParameterService::setParameterIds(Message newParamValues) { void ParameterService::setParameterIds(Message newParamValues) {
/** /**
* This function receives a TC[20, 3] message and after checking whether its type is correct, * This function receives a TC[20, 3] message and after checking whether its type is correct,
* iterates over all contained parameter IDs and replaces the settings for each valid parameter, * iterates over all contained parameter IDs and replaces the settings for each valid parameter,
...@@ -98,18 +93,14 @@ void ParameterService::setParameterIds(Message newParamValues) { ...@@ -98,18 +93,14 @@ void ParameterService::setParameterIds(Message newParamValues) {
if (newParamValues.packetType == Message::TC && newParamValues.serviceType == 20 && if (newParamValues.packetType == Message::TC && newParamValues.serviceType == 20 &&
newParamValues.messageType == 3) { newParamValues.messageType == 3) {
uint16_t ids = newParamValues.readUint16(); //get number of ID's uint16_t ids = newParamValues.readUint16(); //get number of ID's
for (int i = 0; i < ids; i++) { for (int i = 0; i < ids; i++) {
uint16_t currId = newParamValues.readUint16(); uint16_t currId = newParamValues.readUint16();
if (currId < CONFIGLENGTH) { if (currId < CONFIGLENGTH) {
paramsList[currId].settingData = newParamValues.readUint32(); paramsList[currId].settingData = newParamValues.readUint32();
} else { } else {
// generate failure of execution notification for ST[06] // generate failure of execution notification for ST[06]
continue; // ignore the invalid ID continue; // ignore the invalid ID
} }
...@@ -118,7 +109,6 @@ void ParameterService::setParameterIds(Message newParamValues) { ...@@ -118,7 +109,6 @@ void ParameterService::setParameterIds(Message newParamValues) {
} }
uint16_t ParameterService::numOfValidIds(Message idMsg) { uint16_t ParameterService::numOfValidIds(Message idMsg) {
idMsg.resetRead(); idMsg.resetRead();
// start reading from the beginning of the idMsg object // start reading from the beginning of the idMsg object
// (original obj. will not be influenced if this is called by value) // (original obj. will not be influenced if this is called by value)
...@@ -127,21 +117,16 @@ uint16_t ParameterService::numOfValidIds(Message idMsg) { ...@@ -127,21 +117,16 @@ uint16_t ParameterService::numOfValidIds(Message idMsg) {
uint16_t validIds = 0; uint16_t validIds = 0;
for (int i = 0; i < ids; i++) { for (int i = 0; i < ids; i++) {
uint16_t currId = idMsg.readUint16(); uint16_t currId = idMsg.readUint16();
if (idMsg.messageType == 3) { if (idMsg.messageType == 3) {
idMsg.readUint32(); //skip the 32bit settings blocks, we need only the IDs idMsg.readUint32(); //skip the 32bit settings blocks, we need only the IDs
} }
if (currId < CONFIGLENGTH) { if (currId < CONFIGLENGTH) {
validIds++; validIds++;
} }
} }
return validIds; return validIds;
} }
...@@ -39,21 +39,7 @@ int main() { ...@@ -39,21 +39,7 @@ int main() {
sentPacket.appendUint16(2); //number of contained IDs sentPacket.appendUint16(2); //number of contained IDs
sentPacket.appendUint16(0); //first ID sentPacket.appendUint16(0); //first ID
sentPacket.appendUint16(1); //second ID sentPacket.appendUint16(1); //second ID
paramService.reportParameterIds(sentPacket); Message returnedPacket = paramService.reportParameterIds(sentPacket);
/*
uint16_t numOfIds = returnedPacket.readUint16();
std::cout << std::endl << "Number of contained configs: " << numOfIds << std::endl;
for (int i = 0; i < numOfIds; i++) {
std::cout << "Parameter ID: " << std::dec << returnedPacket.readUint16() << std::endl
<< "Parameter value: " << std::dec << returnedPacket.readUint32() << std::endl;
}
std::cout << std::endl << "(First value is hours, second is minutes)" << std::endl;
//Test code for setParameter //Test code for setParameter
Message sentPacket2 = Message(20, 3, Message::TC, 1); //application id is a dummy number (1) Message sentPacket2 = Message(20, 3, Message::TC, 1); //application id is a dummy number (1)
...@@ -66,15 +52,6 @@ int main() { ...@@ -66,15 +52,6 @@ int main() {
paramService.setParameterIds(sentPacket2); paramService.setParameterIds(sentPacket2);
returnedPacket = paramService.reportParameterIds(sentPacket); returnedPacket = paramService.reportParameterIds(sentPacket);
numOfIds = returnedPacket.readUint16();
for (int i = 0; i < numOfIds; i++) {
std::cout << "Parameter ID: " << std::dec << returnedPacket.readUint16() << std::endl
<< "Parameter value: " << std::dec << returnedPacket.readUint32() << std::endl;
}*/
// ST[01] test // ST[01] test
// parameters take random values and works as expected // parameters take random values and works as expected
RequestVerificationService reqVerifService; RequestVerificationService reqVerifService;
......
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