diff --git a/inc/Service.hpp b/inc/Service.hpp index 55aa5f83a4964eafef4e37ba0bc15efbd30cb9fa..3afd67fa73d6ce148555bd03ead9a8743666364c 100644 --- a/inc/Service.hpp +++ b/inc/Service.hpp @@ -16,7 +16,7 @@ class Service { private: uint16_t messageTypeCounter = 0; protected: - uint8_t serviceType; + uint8_t serviceType{}; /** * Creates a new empty telemetry package originating from this service diff --git a/inc/Services/ParameterService.hpp b/inc/Services/ParameterService.hpp index bcf61721baba5757c1a5d68dadaf2fabfaf38e2f..1d4ea05d0bf6ae35b327c694dfa2da76961c3dc4 100644 --- a/inc/Services/ParameterService.hpp +++ b/inc/Services/ParameterService.hpp @@ -1,10 +1,44 @@ #ifndef ECSS_SERVICES_PARAMETERSERVICE_HPP #define ECSS_SERVICES_PARAMETERSERVICE_HPP -#include <Service.hpp> +#include "Service.hpp" +#define CONFIGLENGTH 5 +/** + * Implementation of the ST[20] parameter management service, + * as defined in ECSS-E-ST-70-41C + * + * @author Grigoris Pavlakis <grigpavl@ece.auth.gr> + */ + +/** + * Generic parameter structure + * PTC and PFC for each parameter shall be specified as in + * ECSS-ECSS-E-ST-70-41C, chapter 7.3 + */ +struct Parameter { + + uint8_t ptc; //Packet field type code (PTC) + uint8_t pfc; //Packet field format code (PFC) + uint16_t paramId; //Unique ID of the parameter + + uint32_t settingData; //Actual data defining the operation of a peripheral or subsystem. + //Peripheral-dependent normally (memory address according to spec). Dummy AF for now. +}; + +/** + * Parameter manager + * Holds the list with the parameters and provides functions + * for parameter reporting and modification. + */ class ParameterService : public Service { + Parameter paramsList[CONFIGLENGTH]; //5 is just a dummy number + + public: + ParameterService(); + Message reportParameter(Message paramId); + void setParamData(Message newParamValues); }; diff --git a/src/Services/ParameterService.cpp b/src/Services/ParameterService.cpp index 7ecfbfa132217af3d56426d088063d7d9d878b55..731301d9b0886f0311a983244d05bc1c5914b471 100644 --- a/src/Services/ParameterService.cpp +++ b/src/Services/ParameterService.cpp @@ -1,4 +1,63 @@ -// -// Created by morpheus on 18/11/2018. -// +#include "Services/ParameterService.hpp" +#include <ctime> +ParameterService::ParameterService() { + + /** + * 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 < 5; 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 + + time_t currTime = time(NULL); + struct tm* today = localtime(&currTime); + + paramsList[2].paramId = 10; //random parameter ID + paramsList[2].settingData = today -> tm_year; //the current year + paramsList[2].ptc = 3; //unsigned int + paramsList[2].pfc = 14; //32 bits +} + +Message ParameterService::reportParameter(Message paramId) { + + /** + * This function receives a TC[20, 1] packet and returns a TM[20, 2] packet + * containing the current configuration. + * + * @param Message paramSpecifier: a valid TC[20, 1] packet carrying the requested parameter ID + */ + + Message reqParam(20, 2, Message::TM, 1); //empty TM[20, 2] parameter report message + //TODO: Try to have the parameter list always sorted so binary search can be a thing + + if (paramId.packetType == Message::TC) { + + if (paramId.serviceType == 20 && paramId.messageType == 1) { + + //if TC is of the wrong type return an empty message for now + for (int i = 0; i < CONFIGLENGTH; i++) { //5 is a dummy, as always + + if (paramsList[i].paramId == *paramId.data) { + + reqParam.appendHalfword(paramsList[i].paramId); + reqParam.appendWord(paramsList[i].settingData); + } + } + } + } + + return reqParam; +} + +void ParameterService::setParamData(Message paramId) { + +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index cc24193a9f71cec7719e7ce55e85cecf1e3aa968..81cd13823d06bb6decf3783853d3b7268480d2bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include <iostream> #include <Services/TestService.hpp> +#include "Services/ParameterService.hpp" #include "Message.hpp" int main() { @@ -27,5 +28,12 @@ int main() { receivedPacket.appendUint16(7); testService.onBoardConnection(receivedPacket); + //ST[20] test + ParameterService paramService; + Message sentPacket = Message(20, 1, Message::TC, 1); //application id is a dummy number (1) + sentPacket.appendByte(10); //the packet sent contains the ID of the desired parameter + Message returnedPacket = paramService.reportParameter(sentPacket); + std::cout << "Year: " << *returnedPacket.data << std::endl; + return 0; }