Skip to content
Snippets Groups Projects
Commit 1466bd56 authored by Grigoris Pavlakis's avatar Grigoris Pavlakis Committed by kongr45gpen
Browse files

Solve the pointer storage problem to the map, storing them as void*. Retrieval...

Solve the pointer storage problem to the map, storing them as void*. Retrieval tested with explicit casts, now looking for a way to store type information of functions in a retrievable way

Make clang-tidy happy again, attempt #1

Attempt #2 at calming down clang-tidy
parent 2395d291
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#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
......
#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)
}
}
......@@ -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;
}
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