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

Implement (most of) the TODOS. Serious bug spotted, do not merge yet.

parent a02d7a48
No related branches found
No related tags found
No related merge requests found
...@@ -69,7 +69,11 @@ public: ...@@ -69,7 +69,11 @@ public:
/** /**
* A function received a Message that was not of the correct type * A function received a Message that was not of the correct type
*/ */
OtherMessageType = 9, OtherMessageType = 9,
/**
* Attempt to insert new function in a full function map (ST[08])
*/
FunctionMapFull = 10,
}; };
/** /**
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "Services/ParameterService.hpp" #include "Services/ParameterService.hpp"
#include "Services/TestService.hpp" #include "Services/TestService.hpp"
#include "Services/MemoryManagementService.hpp" #include "Services/MemoryManagementService.hpp"
#include "Services/FunctionManagementService.hpp"
/** /**
* Defines a class that contains instances of all Services. * Defines a class that contains instances of all Services.
...@@ -25,6 +26,7 @@ public: ...@@ -25,6 +26,7 @@ public:
EventActionService eventAction; EventActionService eventAction;
TestService testService; TestService testService;
ParameterService parameterManagement; ParameterService parameterManagement;
FunctionManagementService functionManagement;
/** /**
* The default ServicePool constructor * The default ServicePool constructor
......
#ifndef ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP #ifndef ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
#define ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP #define ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
#include <cstdint>
#include <iostream> // USED BY THE SAMPLE FUNCTIONS ONLY!!
#include <utility>
#include <typeinfo>
#include "etl/map.h" #include "etl/map.h"
#include "etl/String.hpp" #include "etl/String.hpp"
#include "Message.hpp" #include "Message.hpp"
#include "Service.hpp" #include "Service.hpp"
#include "ErrorHandler.hpp"
#define FUNC_MAP_SIZE 128 // size of the function map (number of elements) #define FUNC_MAP_SIZE 5 // size of the function map (number of elements)
#define FUNC_NAME_LENGTH 32 // max length of the function name #define FUNC_NAME_LENGTH 32 // max length of the function name
#define MAX_ARG_LENGTH 32 // maximum argument byte string length #define MAX_ARG_LENGTH 32 // maximum argument byte string length
/**
* @todo: Undef TESTMODE before flight!!!!
* @todo: Replace this with error handler code checking
*/
#define TESTMODE // REMOVE BEFORE FLIGHT!(used by Catch to gain visibility @ test)
/** /**
* Implementation of the ST[08] function management service * Implementation of the ST[08] function management service
* *
...@@ -67,13 +57,10 @@ FunctionMap; ...@@ -67,13 +57,10 @@ FunctionMap;
class FunctionManagementService : public Service { class FunctionManagementService : public Service {
/** /**
* Map of the function names to their respective pointers. Size controlled by FUNCMAPSIZE * Map of the function names to their respective pointers. Size controlled by FUNC_MAP_SIZE
*/ */
#ifdef TESTMODE
public: FunctionMap funcPtrIndex;
#else
FunctionMap funcPtrIndex; FunctionMap funcPtrIndex;
#endif
public: public:
/** /**
...@@ -90,18 +77,19 @@ public: ...@@ -90,18 +77,19 @@ public:
* int, for testing purposes. * int, for testing purposes.
* @param msg A TC[8,1] message * @param msg A TC[8,1] message
*/ */
int call(Message& msg); void call(Message& msg);
/** /**
* Includes a new function in the pointer map. This enables it to be called by way of a valid * Includes a new function in the pointer map. This enables it to be called by way of a valid
* TC [8,1] message. After inclusion it returns an unneeded int signalling insertion success * TC [8,1] message.
* (0) or failure (2). These returns are there for testing purposes only.
* *
* @param funcName the function's name. Max. length is FUNC_NAME_LENGTH bytes. * @param funcName the function's name. Max. length is FUNC_NAME_LENGTH bytes.
* @param ptr pointer to a function of void return type and a MAX_ARG_LENGTH-lengthed byte * @param ptr pointer to a function of void return type and a MAX_ARG_LENGTH-lengthed byte
* string as argument (which contains the actual arguments of the function) * string as argument (which contains the actual arguments of the function)
*/ */
int include(String<FUNC_NAME_LENGTH> funcName, void(*ptr)(String<MAX_ARG_LENGTH>)); void include(String<FUNC_NAME_LENGTH> funcName, void(*ptr)(String<MAX_ARG_LENGTH>));
int getMapSize() { return funcPtrIndex.size(); }
}; };
#endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP #endif //ECSS_SERVICES_FUNCTIONMANAGEMENTSERVICE_HPP
#include "Services/FunctionManagementService.hpp" #include "Services/FunctionManagementService.hpp"
int FunctionManagementService::call(Message& msg) { void FunctionManagementService::call(Message& msg) {
/**
* @todo: Add test for message and service type using the ErrorHandler
* @todo: Convert all functions to void (use error reports for tests instead of return numbers)
*/
msg.resetRead(); msg.resetRead();
ErrorHandler::assertInternal(msg.messageType == 1 && msg.serviceType == 8, ErrorHandler::assertRequest(msg.packetType == Message::TC, msg,
ErrorHandler::InternalErrorType::UnacceptablePacket); ErrorHandler::AcceptanceErrorType::UnacceptableMessage);
ErrorHandler::assertRequest(msg.messageType == 1, msg,
ErrorHandler::AcceptanceErrorType::UnacceptableMessage);
ErrorHandler::assertRequest(msg.serviceType == 8, msg,
ErrorHandler::AcceptanceErrorType::UnacceptableMessage);
uint8_t funcName[FUNC_NAME_LENGTH]; // the function's name uint8_t funcName[FUNC_NAME_LENGTH]; // the function's name
uint8_t funcArgs[MAX_ARG_LENGTH]; // arguments for the function uint8_t funcArgs[MAX_ARG_LENGTH]; // arguments for the function
...@@ -16,10 +16,10 @@ int FunctionManagementService::call(Message& msg) { ...@@ -16,10 +16,10 @@ int FunctionManagementService::call(Message& msg) {
msg.readString(funcArgs, MAX_ARG_LENGTH); msg.readString(funcArgs, MAX_ARG_LENGTH);
if (msg.dataSize > FUNC_NAME_LENGTH + MAX_ARG_LENGTH) { if (msg.dataSize > FUNC_NAME_LENGTH + MAX_ARG_LENGTH) {
/** ErrorHandler::reportError(msg,
* @todo Send failed start of execution (too long message) ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError); // report failed
*/ // start of execution as requested by the standard
return 4; // arbitrary return;
} }
// locate the appropriate function pointer // locate the appropriate function pointer
...@@ -30,29 +30,23 @@ int FunctionManagementService::call(Message& msg) { ...@@ -30,29 +30,23 @@ int FunctionManagementService::call(Message& msg) {
if (iter != funcPtrIndex.end()) { if (iter != funcPtrIndex.end()) {
selected = *iter->second; selected = *iter->second;
} else { } else {
/** ErrorHandler::reportError(msg,
* @todo Send failed start of execution (function not found) ErrorHandler::ExecutionStartErrorType::UnknownExecutionStartError);
*/ return;
return 1; // arbitrary
} }
// execute the function if there are no obvious flaws (defined in the standard, pg.158) // execute the function if there are no obvious flaws (defined in the standard, pg.158)
selected(funcArgs); selected(funcArgs);
return 0;
} }
int FunctionManagementService::include(String<FUNC_NAME_LENGTH> funcName, void(*ptr) void FunctionManagementService::include(String<FUNC_NAME_LENGTH> funcName, void(*ptr)
(String<MAX_ARG_LENGTH>)) { (String<MAX_ARG_LENGTH>)) {
if (funcPtrIndex.full()) { if (funcPtrIndex.full()) {
/** ErrorHandler::reportInternalError(ErrorHandler::InternalErrorType::FunctionMapFull);
* @todo Generate suitable notification (index is full) return;
*/
return 2; // arbitrary, for testing purposes
} }
funcName.append(FUNC_NAME_LENGTH - funcName.length(), '\0'); funcName.append(FUNC_NAME_LENGTH - funcName.length(), '\0');
funcPtrIndex.insert(std::make_pair(funcName, ptr)); funcPtrIndex.insert(std::make_pair(funcName, ptr));
return 0;
} }
#include "catch2/catch.hpp" #include "catch2/catch.hpp"
#include "Services/FunctionManagementService.hpp" #include "Services/FunctionManagementService.hpp"
#include "ServicePool.hpp"
#include "ServiceTests.hpp"
#include <iostream>
FunctionManagementService & fms = Services.functionManagement;
void test(String<MAX_ARG_LENGTH> a) { void test(String<MAX_ARG_LENGTH> a) {
std::cout << a.c_str() << std::endl; std::cout << a.c_str() << std::endl;
} }
TEST_CASE("ST[08] - Call Tests") { TEST_CASE("ST[08] - Call Tests") {
FunctionManagementService fms;
SECTION("Malformed name") { SECTION("Malformed name") {
ServiceTests::reset();
fms.include(String<FUNC_NAME_LENGTH>("test"), &test); fms.include(String<FUNC_NAME_LENGTH>("test"), &test);
Message msg(8, 1, Message::TC, 1); Message msg(8, 1, Message::TC, 1);
msg.appendString(String<FUNC_NAME_LENGTH>("t3st")); msg.appendString(String<FUNC_NAME_LENGTH>("t3st"));
CHECK(fms.call(msg) == 1); fms.call(msg);
CHECK(ServiceTests::get(0).messageType == 4);
CHECK(ServiceTests::get(0).serviceType == 1);
} }
SECTION("Too long message") { SECTION("Too long message") {
ServiceTests::reset();
fms.include(String<FUNC_NAME_LENGTH>("test"), &test); fms.include(String<FUNC_NAME_LENGTH>("test"), &test);
Message msg(8, 1, Message::TC, 1); Message msg(8, 1, Message::TC, 1);
msg.appendString(String<FUNC_NAME_LENGTH>("test")); msg.appendString(String<FUNC_NAME_LENGTH>("test"));
msg.appendString(String<65> msg.appendString(String<65>
("eqrhjweghjhwqgthjkrghthjkdsfhgsdfhjsdjsfdhgkjdfsghfjdgkdfsgdfgsgd")); ("eqrhjweghjhwqgthjkrghthjkdsfhgsdfhjsdjsfdhgkjdfsghfjdgkdfsgdfgsgd"));
CHECK(fms.call(msg) == 4); fms.call(msg);
} CHECK(ServiceTests::get(0).messageType == 4);
} CHECK(ServiceTests::get(0).serviceType == 1);
TEST_CASE("ST[08] - Insert Tests") {
SECTION("Insertion to full pointer map") {
FunctionManagementService fms;
std::string name; // FOR TESTING ONLY!
// make sure the pointer map is full to the brim
for (int i = 0; i < 15000; i++) {
name = "test" + i;
String<FUNC_NAME_LENGTH> funcName(name.c_str());
if (not fms.funcPtrIndex.full()) {
fms.include(funcName, &test);
}
else {
break;
}
}
CHECK(fms.include(String<FUNC_NAME_LENGTH>("testall"), &test) == 2);
} }
} }
/** // WARNING! include() is malfunctioning - do not merge!
* @todo Add more tests
*/ //TEST_CASE("ST[08] - Insert Tests") {
//
// SECTION("Insertion to full pointer map") {
// // make sure the pointer map is full to the brim
// ServiceTests::reset();
// std::string name = "test"; // FOR TESTING ONLY!
//
// }
//}
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