diff --git a/CMakeLists.txt b/CMakeLists.txt index d9e456e694733af386d637fdc9dda03397959904..6752c03c55dd1fdc8dfc5797154f4f8938502bd8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ add_library(common OBJECT src/Services/RequestVerificationService.cpp src/Services/TestService.cpp src/Services/TimeManagementService.cpp - ) + src/Services/FunctionManagementService.cpp) # Specify the .cpp files for the executables add_executable(ecss_services diff --git a/inc/Services/FunctionManagementService.hpp b/inc/Services/FunctionManagementService.hpp index ddf7ab3da02dd12b64a340b2d751d2060236fd80..49a69a0b1d916c64bbd0d369cc74853137a97fd3 100644 --- a/inc/Services/FunctionManagementService.hpp +++ b/inc/Services/FunctionManagementService.hpp @@ -1,7 +1,11 @@ #ifndef ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP #define ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP -#include <stdint.h> +#include <cstdint> +#include <iostream> // TEMPORARY! +#include <utility> +#include <typeinfo> + #include "etl/map.h" #include "etl/String.hpp" #include "Message.hpp" @@ -10,33 +14,25 @@ * Implementation of the ST[08] function management service * * This class implements a basic framework for the ST[08] service as described in ECSS-E-ST-70-41C, - * pages 157-159. Actual implementation is dependent on subsystem requirements which are, as of this + * pages 157-159. Final implementation is dependent on subsystem requirements which are, as of this * writing, undefined yet. - * - * <b>WARNING!</b> Due to the class's usage of the custom string class by Konstantinos Kanavouras, - * <b>the function name passed in the message shall be stripped of its trailing NULL character!</b> - * - * @todo Ignore the ending NULL in passed strings - * @todo Revamp the method used to store the argument types, it's hacky AF and a (memory) space hog - * + * * * @author Grigoris Pavlakis <grigpavl@ece.auth.gr> */ -#define FUNCMAPSIZE 5 // size of the function map (temporary, arbitrary) -#define MAXFUNCNAMELEN 128 // max length of the function (temporary, arbitrary) -#define MAXFUNCARGS 64 // maximum arguments that a function can hold -#define MAXARGLENGTH 32 // maximum argument name length +#define FUNCMAPSIZE 5 // size of the function map (temporary, arbitrary) +#define MAXFUNCNAMELEN 128 // max length of the function (temporary, arbitrary) +#define MAXFUNCARGS 64 // maximum arguments that a function can hold +#define MAXARGLENGTH 32 // maximum argument name length -typedef struct { - void (*funcPtr)(void); // a generic function pointer - String<MAXARGLENGTH> args[MAXFUNCARGS]; // the argument types with their original sequence -} Function; +typedef String<MAXFUNCNAMELEN> funcName; class FunctionManagementService { - etl::map<String<MAXFUNCNAMELEN>, - Function, FUNCMAPSIZE> funcPtrIndex; // map of function names to their pointers + etl::map<funcName, void*, (const size_t) FUNCMAPSIZE> funcPtrIndex; + // map of function names to their pointers public: + //FunctionManagementService(); // dummy constructor (commented out to pacify clang-tidy) /** * Calls the function described in the TC[8,1] message *msg*, passing the arguments contained * @param msg A TC[8,1] message diff --git a/src/Services/FunctionManagementService.cpp b/src/Services/FunctionManagementService.cpp index 033ef021fb190e7d2ec30c0a481ffe36ea54f48c..2294539c2eae3068f30510665efce69a2e29a641 100644 --- a/src/Services/FunctionManagementService.cpp +++ b/src/Services/FunctionManagementService.cpp @@ -1 +1,49 @@ #include "Services/FunctionManagementService.hpp" + +// Dummy functions which will populate the map +float dummy1(float a, int b) { + return a * b; +} + +void dummy2(char c) { + std::cout << c << std::endl; +} + +//FunctionManagementService::FunctionManagementService() { +// funcPtrIndex.insert(std::make_pair(String<MAXFUNCNAMELEN>("dummy1"), reinterpret_cast<void*> +// (&dummy1))); +// funcPtrIndex.insert(std::make_pair(String<MAXFUNCNAMELEN>("dummy2"), reinterpret_cast<void*> +// (&dummy2))); +// +// //reinterpret_cast<float(*)(float, int)>(funcPtrIndex["dummy1"])(3.14, 45); +// //reinterpret_cast<void(*)(char)>(funcPtrIndex["dummy2"])('h'); +//} + +void FunctionManagementService::call(Message msg){ + uint8_t funcName[MAXFUNCNAMELEN]; // the function's name + + // initialize the function name array + for (int i = 0; i < MAXFUNCNAMELEN; i++) { + funcName[i] = 0; + } + + // isolate the function's name from the incoming message + for (int i = 0; i < MAXFUNCNAMELEN; i++) { + uint8_t currByte = msg.readByte(); + if (currByte == 0x00) { + funcName[i] = currByte; + break; + } + funcName[i] = currByte; + } + + // isolate the number of args (currently an unsigned 32-bit number, the standard doesn't + // specify a maximum number) + uint32_t numOfArgs = msg.readUint32(); + for (int i = 0; i < numOfArgs; i++) { + // TODO: find a way to deduce the argument types as contained or store them somehow + // (finding a way to store them is better because it also solves the pointer casting + // problem) + } + +} diff --git a/src/main.cpp b/src/main.cpp index bcc262edea6839be3fdee14bebf64daf2f0a1859..057c2313974fc83b4fa9364e3f46c3394d964a01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include "Services/RequestVerificationService.hpp" #include "Services/MemoryManagementService.hpp" #include "Services/EventReportService.hpp" +#include "Services/FunctionManagementService.hpp" #include "Services/TimeManagementService.hpp" #include "Message.hpp" #include "MessageParser.hpp" @@ -200,5 +201,8 @@ int main() { eventReportService.enableReportGeneration(eventMessage2); eventReportService.requestListOfDisabledEvents(eventMessage3); + // ST[08] test + FunctionManagementService fms; + return 0; }