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

Complete basic implementation of parameter setting, untested

parent a8fd2802
No related branches found
No related tags found
No related merge requests found
......@@ -45,9 +45,9 @@ class ParameterService : public Service {
public:
ParameterService();
Message reportParameter(Message paramId);
Message reportParameterId(Message paramId);
//void setParamData(Message& newParamValues);
void setParamData(Message newParamValues);
};
......
......@@ -5,6 +5,7 @@
#ifdef DEMOMODE
#include <ctime>
#include <cstdlib>
#endif
......@@ -12,35 +13,32 @@ ParameterService::ParameterService() {
#ifdef DEMOMODE
/**
* Initializes the parameter list with some dummy values for now.
* This normally will be initialized with actual values on boot.
*/
for (int i = 0; i < CONFIGLENGTH; i++) {
paramsList[i].paramId = 0;
paramsList[i].settingData = 0;
paramsList[i].pfc = 1;
paramsList[i].ptc = 1;
}
// Test code, setting up one of the parameter fields
// Test code, setting up some of the parameter fields
time_t currTime = time(nullptr);
struct tm *today = localtime(&currTime);
paramsList[2].paramId = 341; // random parameter ID
paramsList[2].settingData = today->tm_min; // the minute of the current hour
paramsList[2].ptc = 3; // unsigned int
paramsList[2].pfc = 14; // 32 bits
paramsList[0].paramId = 341; // random parameter ID
paramsList[0].settingData = today->tm_hour; // the current hour
paramsList[0].ptc = 3; // unsigned int
paramsList[0].pfc = 14; // 32 bits
paramsList[1].paramId = 345; // random parameter ID
paramsList[1].settingData = today->tm_min; // the current minute
paramsList[1].ptc = 3; // unsigned int
paramsList[1].pfc = 14; // 32 bits
#endif
}
Message ParameterService::reportParameter(Message paramId) {
Message ParameterService::reportParameterId(Message paramId) {
/**
* This function receives a TC[20, 1] packet and returns a TM[20, 2] packet
* containing the current configuration. No error checking for now, just whether
* the package is of the correct type (in which case it returns an empty message)
* containing the current configuration **for the parameter specified in the carried ID**.
* No sophisticated error checking for now, just whether the package is of the correct type
* (in which case it returns an empty message)
*
* @param paramId: a valid TC[20, 1] packet carrying the requested parameter ID
* @return A TM[20, 2] packet containing the parameter ID
......@@ -57,8 +55,8 @@ Message ParameterService::reportParameter(Message paramId) {
if (paramsList[i].paramId == reqParamId) {
reqParam.appendUint16(paramsList[i].paramId);
reqParam.appendUint32(paramsList[i].settingData);
reqParam.appendUint16(paramsList[i].paramId); // first 16 bits are the parameter ID
reqParam.appendUint32(paramsList[i].settingData); // rest 32 are the current setting
break;
}
}
......@@ -67,6 +65,32 @@ Message ParameterService::reportParameter(Message paramId) {
return reqParam;
}
/*void ParameterService::setParamData(Message& newParamValues) {
void ParameterService::setParamData(Message newParamValues) {
/**
* This function receives a TC[20, 3] message and after checking whether its type is correct,
* replaces the setting specified in the settingData field of the parameter with the ID
* contained in the message with the value that the message carries. If the message type is
* not correct, the settings stay as they are.
*
* @param newParamValues: a valid TC[20, 3] message carrying parameter ID and replacement value
* @return None
* @todo Use pointers for changing and storing addresses to comply with the standard
*/
uint16_t reqParamId = newParamValues.readUint16();
if (newParamValues.packetType == Message::TC && newParamValues.serviceType == 20 &&
newParamValues.messageType == 1) {
}*/
//TODO: Separate searching from rest of code
for (int i = 0; i < CONFIGLENGTH; i++) {
if (paramsList[i].paramId == reqParamId) {
paramsList[i].settingData = newParamValues.readUint32();
break;
}
}
}
}
......@@ -31,6 +31,8 @@ int main() {
//ST[20] test
ParameterService paramService;
//Test code for reportParameter
Message sentPacket = Message(20, 1, Message::TC, 1); //application id is a dummy number (1)
sentPacket.appendUint16(341); //the packet sent contains the ID of the desired parameter
Message returnedPacket = paramService.reportParameter(sentPacket);
......
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