Skip to content
Snippets Groups Projects
Commit df07ef0b authored by kongr45gpen's avatar kongr45gpen
Browse files

Add basic implementation of ST[17] test

parent c7bc0d48
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ project(ecss_services) ...@@ -5,7 +5,7 @@ project(ecss_services)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
# Specify the directories for #includes # Specify the directories for #includes
include_directories ("${PROJECT_SOURCE_DIR}/inc") include_directories("${PROJECT_SOURCE_DIR}/inc")
# Specify the .cpp files for the executables # Specify the .cpp files for the executables
add_executable(ecss_services src/main.cpp src/Message.cpp) add_executable(ecss_services src/main.cpp src/Message.cpp src/Service.cpp src/Services/TestService.cpp)
...@@ -17,7 +17,7 @@ Checks: > ...@@ -17,7 +17,7 @@ Checks: >
-misc-non-private-member-variables-in-classes, -misc-non-private-member-variables-in-classes,
performance-*, performance-*,
readability-*, readability-*,
WarningsAsErrors: '*,-misc-unused-parameters,-llvm-header-guard,-cppcoreguidelines-pro-type-member-init' WarningsAsErrors: '*,-misc-unused-parameters,-llvm-header-guard,-cppcoreguidelines-pro-type-member-init, -google-runtime-references'
HeaderFilterRegex: '.*' HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
... ...
......
#ifndef ECSS_SERVICES_SERVICE_HPP
#define ECSS_SERVICES_SERVICE_HPP
#include <cstdint>
#include "Message.hpp"
/**
* A spacecraft service, as defined in ECSS-E-ST-70-41C
*
* A member of the Service class should be used as a singleton, i.e. must be created only once in
* the code
*
* @todo Disable copy constructor
*/
class Service {
private:
uint16_t messageTypeCounter = 0;
protected:
uint8_t serviceType;
/**
* Creates a new empty telemetry package originating from this service
*
* @param messageType The ID of the message type, as specified in the standard. For example,
* the TC[17,3] message has `messageType = 3`.
* @todo See if the Message must be returned by reference
* @todo Set the application ID to the current application
* @todo Use the messageTypeCounter
*/
Message createTM(uint8_t messageType) {
return Message(serviceType, messageType, Message::TM, 0);
}
/**
* Stores a message so that it can be transmitted to the ground station
*
* Note: For now, since we don't have any mechanisms to queue messages and send them later,
* we just print the message to the screen
*/
void storeMessage(const Message& message);
};
#endif //ECSS_SERVICES_SERVICE_HPP
#ifndef ECSS_SERVICES_TESTSERVICE_HPP
#define ECSS_SERVICES_TESTSERVICE_HPP
#include "Service.hpp"
/**
* Implementation of the ST[17] test service
*/
class TestService : public Service {
public:
TestService() {
serviceType = 17;
}
/**
* TC[17,1] perform an are-you-alive connection test
*/
void areYouAlive(const Message & message);
};
#endif //ECSS_SERVICES_TESTSERVICE_HPP
#include <iostream>
#include <iomanip>
#include "Service.hpp"
void Service::storeMessage(const Message &message) {
// Just print it to the screen
std::cout << "New " << ((message.packetType == Message::TM) ? "TM" : "TC") << "[" << std::dec
<< static_cast<int>(message.serviceType) << ","
<< static_cast<int>(message.messageType) << "] message!\n";
std::cout << std::hex << std::setfill('0') << std::setw(2);
for (int i = 0; i < message.dataSize; i++) {
std::cout << static_cast<int>(message.data[i]);
}
std::cout << std::endl;
}
#include "Services/TestService.hpp"
void TestService::areYouAlive(const Message &message) {
// TM[17,2] are-you-alive connection test report
Message report = createTM(2);
storeMessage(report);
}
#include <iostream> #include <iostream>
#include <Services/TestService.hpp>
#include "Message.hpp" #include "Message.hpp"
int main() { int main() {
...@@ -11,6 +12,12 @@ int main() { ...@@ -11,6 +12,12 @@ int main() {
std::cout << "Hello, World!" << std::endl; std::cout << "Hello, World!" << std::endl;
std::cout << std::hex << packet.data << std::endl; // packet data must be 'helloQQ' std::cout << std::hex << packet.data << std::endl; // packet data must be 'helloQQ'
// std::cout << *(reinterpret_cast<float*>(packet.data + 7)) << std::endl;
// ST[17] test
TestService testService;
Message receivedPacket = Message(17, 1, Message::TC, 1);
testService.areYouAlive(receivedPacket);
return 0; 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