Merge remote-tracking branch 'upstream/mueller/master' into mueller/master

This commit is contained in:
Robin Müller 2021-04-24 22:48:43 +02:00
commit cac9a0eecd
45 changed files with 1646 additions and 930 deletions

View File

@ -184,6 +184,7 @@ endif()
target_include_directories(${LIB_FSFW_NAME} INTERFACE
${CMAKE_SOURCE_DIR}
${FSFW_CONFIG_PATH_ABSOLUTE}
${FSFW_ADD_INC_PATHS_ABS}
)
# Includes path required to compile FSFW itself as well

View File

@ -17,6 +17,8 @@
#define FSFW_DISABLE_PRINTOUT 0
#endif
#define FSFW_USE_PUS_C_TELEMETRY 1
//! Can be used to disable the ANSI color sequences for C stdio.
#define FSFW_COLORED_OUTPUT 1
@ -40,10 +42,17 @@
//! Specify whether a special mode store is used for Subsystem components.
#define FSFW_USE_MODESTORE 0
//! Defines if the real time scheduler for linux should be used.
//! If set to 0, this will also disable priority settings for linux
//! as most systems will not allow to set nice values without privileges
//! For embedded linux system set this to 1.
//! If set to 1 the binary needs "cap_sys_nice=eip" privileges to run
#define FSFW_USE_REALTIME_FOR_LINUX 1
namespace fsfwconfig {
//! Default timestamp size. The default timestamp will be an eight byte CDC
//! short timestamp.
static constexpr uint8_t FSFW_MISSION_TIMESTAMP_SIZE = 8;
//! Default timestamp size. The default timestamp will be an seven byte CDC short timestamp.
static constexpr uint8_t FSFW_MISSION_TIMESTAMP_SIZE = 7;
//! Configure the allocated pool sizes for the event manager.
static constexpr size_t FSFW_EVENTMGMR_MATCHTREE_NODES = 240;
@ -52,11 +61,12 @@ static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120;
//! Defines the FIFO depth of each commanding service base which
//! also determines how many commands a CSB service can handle in one cycle
//! simulataneously. This will increase the required RAM for
//! simultaneously. This will increase the required RAM for
//! each CSB service !
static constexpr uint8_t FSFW_CSB_FIFO_DEPTH = 6;
static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124;
}
#endif /* CONFIG_FSFWCONFIG_H_ */

View File

@ -24,6 +24,13 @@
* 1. check logic when active-> checkChildrenStateOn
* 2. transition logic to change the mode -> commandChildren
*
* Important:
*
* The implementation must call registerChild(object_id_t child)
* for all commanded children during initialization.
* The implementation must call the initialization function of the base class.
* (This will call the function in SubsystemBase)
*
*/
class AssemblyBase: public SubsystemBase {
public:
@ -41,9 +48,6 @@ public:
virtual ~AssemblyBase();
protected:
// SHOULDDO: Change that OVERWRITE_HEALTH may be returned
// (or return internalState directly?)
/**
* Command children to reach [mode,submode] combination
* Can be done by setting #commandsOutstanding correctly,
@ -68,6 +72,18 @@ protected:
virtual ReturnValue_t checkChildrenStateOn(Mode_t wantedMode,
Submode_t wantedSubmode) = 0;
/**
* Check whether a combination of mode and submode is valid.
*
* Ground Controller like precise return values from HasModesIF.
* So, please return any of them.
*
* @param mode The targeted mode
* @param submode The targeted submmode
* @return Any information why this combination is invalid from HasModesIF
* like HasModesIF::INVALID_SUBMODE.
* On success return HasReturnvaluesIF::RETURN_OK
*/
virtual ReturnValue_t isModeCombinationValid(Mode_t mode,
Submode_t submode) = 0;

View File

@ -16,9 +16,9 @@ ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
healthHelper.handleHealthCommand(&command);
result = healthHelper.handleHealthCommand(&command);
}
return HasReturnvaluesIF::RETURN_OK;
return result;
}
ReturnValue_t HealthDevice::initialize() {

View File

@ -81,11 +81,17 @@ void HealthTable::printAll(uint8_t* pointer, size_t maxSize) {
return;
}
for (const auto& health: healthMap) {
SerializeAdapter::serialize(&health.first,
result = SerializeAdapter::serialize(&health.first,
&pointer, &size, maxSize, SerializeIF::Endianness::BIG);
if(result != HasReturnvaluesIF::RETURN_OK) {
return;
}
uint8_t healthValue = health.second;
SerializeAdapter::serialize(&healthValue, &pointer, &size,
result = SerializeAdapter::serialize(&healthValue, &pointer, &size,
maxSize, SerializeIF::Endianness::BIG);
if(result != HasReturnvaluesIF::RETURN_OK) {
return;
}
}
}
@ -96,7 +102,7 @@ ReturnValue_t HealthTable::iterate(HealthEntry *value, bool reset) {
mapIterator = healthMap.begin();
}
if (mapIterator == healthMap.end()) {
result = HasReturnvaluesIF::RETURN_FAILED;
return HasReturnvaluesIF::RETURN_FAILED;
}
*value = *mapIterator;
mapIterator++;

View File

@ -15,7 +15,7 @@
#endif
//! Debugging preprocessor define.
#define FSFW_UDP_RCV_WIRETAPPING_ENABLED 0
#define FSFW_UDP_RECV_WIRETAPPING_ENABLED 0
UdpTcPollingTask::UdpTcPollingTask(object_id_t objectId,
object_id_t tmtcUnixUdpBridge, size_t maxRecvSize,
@ -66,10 +66,13 @@ ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) {
tcpip::handleError(tcpip::Protocol::UDP, tcpip::ErrorSources::RECVFROM_CALL, 1000);
continue;
}
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
#if FSFW_UDP_RECV_WIRETAPPING_ENABLED == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "UdpTcPollingTask::performOperation: " << bytesReceived <<
" bytes received" << std::endl;
#else
#endif
#endif /* FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1 */
ReturnValue_t result = handleSuccessfullTcRead(bytesReceived);
if(result != HasReturnvaluesIF::RETURN_FAILED) {
@ -84,7 +87,7 @@ ReturnValue_t UdpTcPollingTask::performOperation(uint8_t opCode) {
ReturnValue_t UdpTcPollingTask::handleSuccessfullTcRead(size_t bytesRead) {
store_address_t storeId;
#if FSFW_UDP_RCV_WIRETAPPING_ENABLED == 1
#if FSFW_UDP_RECV_WIRETAPPING_ENABLED == 1
arrayprinter::print(receptionBuffer.data(), bytesRead);
#endif

View File

@ -70,6 +70,7 @@ ReturnValue_t UdpTmTcBridge::initialize() {
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_flags = AI_PASSIVE;
/* Set up UDP socket:
https://en.wikipedia.org/wiki/Getaddrinfo
@ -95,6 +96,10 @@ ReturnValue_t UdpTmTcBridge::initialize() {
return HasReturnvaluesIF::RETURN_FAILED;
}
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
tcpip::printAddress(addrResult->ai_addr);
#endif
retval = bind(serverSocket, addrResult->ai_addr, static_cast<int>(addrResult->ai_addrlen));
if(retval != 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -121,10 +126,8 @@ ReturnValue_t UdpTmTcBridge::sendTm(const uint8_t *data, size_t dataLen) {
/* The target address can be set by different threads so this lock ensures thread-safety */
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
char ipAddress [15];
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
tcpip::printAddress(&clientAddress);
#endif
int bytesSent = sendto(
@ -152,13 +155,11 @@ void UdpTmTcBridge::checkAndSetClientAddress(sockaddr& newAddress) {
/* The target address can be set by different threads so this lock ensures thread-safety */
MutexGuard lock(mutex, timeoutType, mutexTimeoutMs);
#if FSFW_CPP_OSTREAM_ENABLED == 1 && FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
char ipAddress [15];
sif::debug << "IP Address Sender: "<< inet_ntop(AF_INET,
&newAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
sif::debug << "IP Address Old: " << inet_ntop(AF_INET,
&clientAddress.sin_addr.s_addr, ipAddress, 15) << std::endl;
#if FSFW_UDP_SEND_WIRETAPPING_ENABLED == 1
tcpip::printAddress(&newAddress);
tcpip::printAddress(&clientAddress);
#endif
registerCommConnect();
/* Set new IP address to reply to */

View File

@ -1,4 +1,9 @@
#include "tcpipCommon.h"
#include <fsfw/serviceinterface/ServiceInterface.h>
#ifdef _WIN32
#include <ws2tcpip.h>
#endif
void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string &protStr,
std::string &srcString) {
@ -34,3 +39,37 @@ void tcpip::determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std:
srcString = "unknown call";
}
}
void tcpip::printAddress(struct sockaddr* addr) {
char ipAddress[INET6_ADDRSTRLEN] = {};
const char* stringPtr = NULL;
switch(addr->sa_family) {
case AF_INET: {
struct sockaddr_in *addrIn = reinterpret_cast<struct sockaddr_in*>(addr);
stringPtr = inet_ntop(AF_INET, &(addrIn->sin_addr), ipAddress, INET_ADDRSTRLEN);
break;
}
case AF_INET6: {
struct sockaddr_in6 *addrIn = reinterpret_cast<struct sockaddr_in6*>(addr);
stringPtr = inet_ntop(AF_INET6, &(addrIn->sin6_addr), ipAddress, INET6_ADDRSTRLEN);
break;
}
}
#if FSFW_CPP_OSTREAM_ENABLED == 1
if(stringPtr == NULL) {
sif::debug << "Could not convert IP address to text representation, error code "
<< errno << std::endl;
}
else {
sif::debug << "IP Address Sender: " << ipAddress << std::endl;
}
#else
if(stringPtr == NULL) {
sif::printDebug("Could not convert IP address to text representation, error code %d\n",
errno);
}
else {
sif::printDebug("IP Address Sender: %s\n", ipAddress);
}
#endif
}

View File

@ -4,6 +4,13 @@
#include "../../timemanager/clockDefinitions.h"
#include <string>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <netdb.h>
#include <arpa/inet.h>
#endif
namespace tcpip {
const char* const DEFAULT_SERVER_PORT = "7301";
@ -28,8 +35,8 @@ enum class ErrorSources {
void determineErrorStrings(Protocol protocol, ErrorSources errorSrc, std::string& protStr,
std::string& srcString);
void printAddress(struct sockaddr* addr);
}
#endif /* FSFW_OSAL_COMMON_TCPIPCOMMON_H_ */

View File

@ -3,7 +3,7 @@
#include "../../ipc/MutexFactory.h"
#include "../../osal/host/Mutex.h"
#include "../../osal/host/FixedTimeslotTask.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../tasks/ExecutableObjectIF.h"
#include <thread>

View File

@ -21,7 +21,7 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
void (*setDeadlineMissedFunc)()) :
started(false), taskName(name), period(setPeriod),
deadlineMissedFunc(setDeadlineMissedFunc) {
// It is propably possible to set task priorities by using the native
// It is probably possible to set task priorities by using the native
// task handles for Windows / Linux
mainThread = std::thread(&PeriodicTask::taskEntryPoint, this, this);
#if defined(_WIN32)

View File

@ -181,11 +181,14 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
sif::error << "Posix Thread attribute setinheritsched failed with: " <<
strerror(status) << std::endl;
#endif
}
// TODO FIFO -> This needs root privileges for the process
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
if(status != 0){
}
#ifndef FSFW_USE_REALTIME_FOR_LINUX
#error "Please define FSFW_USE_REALTIME_FOR_LINUX with either 0 or 1"
#endif
#if FSFW_USE_REALTIME_FOR_LINUX == 1
// FIFO -> This needs root privileges for the process
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
if(status != 0){
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Posix Thread attribute schedule policy failed with: " <<
strerror(status) << std::endl;
@ -200,14 +203,14 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
sif::error << "Posix Thread attribute schedule params failed with: " <<
strerror(status) << std::endl;
#endif
}
//Set Signal Mask for suspend until startTask is called
sigset_t waitSignal;
sigemptyset(&waitSignal);
sigaddset(&waitSignal, SIGUSR1);
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
if(status != 0){
}
#endif
//Set Signal Mask for suspend until startTask is called
sigset_t waitSignal;
sigemptyset(&waitSignal);
sigaddset(&waitSignal, SIGUSR1);
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
if(status != 0){
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Posix Thread sigmask failed failed with: " <<
strerror(status) << " errno: " << strerror(errno) << std::endl;
@ -218,8 +221,16 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
status = pthread_create(&thread,&attributes,fnc_,arg_);
if(status != 0){
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Posix Thread create failed with: " <<
strerror(status) << std::endl;
sif::error << "PosixThread::createTask: Failed with: " <<
strerror(status) << std::endl;
sif::error << "For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call " <<
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
"/etc/security/limit.conf" << std::endl;
#else
sif::printError("PosixThread::createTask: Create failed with: %s\n", strerror(status));
sif::printError("For FSFW_USE_REALTIME_FOR_LINUX == 1 make sure to call "
"\"all sudo setcap 'cap_sys_nice=eip'\" on the application or set "
"/etc/security/limit.conf\n");
#endif
}

View File

@ -99,8 +99,8 @@ void tcpip::handleError(Protocol protocol, ErrorSources errorSrc, dur_millis_t s
sif::warning << "tcpip::handleError: " << protocolString << " | " << errorSrcString <<
" | " << infoString << std::endl;
#else
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString,
errorSrcString, infoString);
sif::printWarning("tcpip::handleError: %s | %s | %s\n", protocolString.c_str(),
errorSrcString.c_str(), infoString.c_str());
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
if(sleepDuration > 0) {

View File

@ -1,6 +1,7 @@
#include "Service17Test.h"
#include <FSFWConfig.h>
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../serviceinterface/ServiceInterface.h"
#include "../objectmanager/SystemObject.h"
#include "../tmtcpacket/pus/TmPacketStored.h"
@ -17,15 +18,25 @@ Service17Test::~Service17Test() {
ReturnValue_t Service17Test::handleRequest(uint8_t subservice) {
switch(subservice) {
case Subservice::CONNECTION_TEST: {
TmPacketStored connectionPacket(apid, serviceId,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
#else
TmPacketStoredPusC connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
#endif
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
requestQueue->getId());
return HasReturnvaluesIF::RETURN_OK;
}
case Subservice::EVENT_TRIGGER_TEST: {
TmPacketStored connectionPacket(apid, serviceId,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
#else
TmPacketStoredPusC connectionPacket(apid, serviceId,
Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
#endif
connectionPacket.sendPacket(requestQueue->getDefaultDestination(),
requestQueue->getId());
triggerEvent(TEST, 1234, 5678);

View File

@ -68,8 +68,13 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport(
message->getTcSequenceControl(), message->getStep(),
message->getErrorCode(), message->getParameter1(),
message->getParameter2());
TmPacketStored tmPacket(apid, serviceId, message->getReportId(),
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
#else
TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
#endif
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(),
tmQueue->getId());
return result;
@ -79,8 +84,13 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport(
PusVerificationMessage *message) {
SuccessReport report(message->getReportId(),message->getTcPacketId(),
message->getTcSequenceControl(),message->getStep());
TmPacketStored tmPacket(apid, serviceId, message->getReportId(),
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
#else
TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(),
packetSubCounter++, &report);
#endif
ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(),
tmQueue->getId());
return result;

View File

@ -52,8 +52,13 @@ ReturnValue_t Service5EventReporting::generateEventReport(
{
EventReport report(message.getEventId(),message.getReporter(),
message.getParameter1(),message.getParameter2());
TmPacketStored tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
#else
TmPacketStoredPusC tmPacket(PusServiceBase::apid, PusServiceBase::serviceId,
message.getSeverity(), packetSubCounter++, &report);
#endif
ReturnValue_t result = tmPacket.sendPacket(
requestQueue->getDefaultDestination(),requestQueue->getId());
if(result != HasReturnvaluesIF::RETURN_OK) {

View File

@ -5,8 +5,7 @@
SubsystemBase::SubsystemBase(object_id_t setObjectId, object_id_t parent,
Mode_t initialMode, uint16_t commandQueueDepth) :
SystemObject(setObjectId), mode(initialMode), submode(SUBMODE_NONE),
childrenChangedMode(false),
SystemObject(setObjectId), mode(initialMode),
commandQueue(QueueFactory::instance()->createMessageQueue(
commandQueueDepth, CommandMessage::MAX_MESSAGE_SIZE)),
healthHelper(this, setObjectId), modeHelper(this), parentId(parent) {
@ -167,16 +166,16 @@ MessageQueueId_t SubsystemBase::getCommandQueue() const {
}
ReturnValue_t SubsystemBase::initialize() {
MessageQueueId_t parentQueue = 0;
MessageQueueId_t parentQueue = MessageQueueIF::NO_QUEUE;
ReturnValue_t result = SystemObject::initialize();
if (result != RETURN_OK) {
return result;
}
if (parentId != 0) {
if (parentId != objects::NO_OBJECT) {
SubsystemBase *parent = objectManager->get<SubsystemBase>(parentId);
if (parent == NULL) {
if (parent == nullptr) {
return RETURN_FAILED;
}
parentQueue = parent->getCommandQueue();

View File

@ -37,6 +37,17 @@ public:
virtual MessageQueueId_t getCommandQueue() const override;
/**
* Function to register the child objects.
* Performs a checks if the child does implement HasHealthIF and/or HasModesIF
*
* Also adds them to the internal childrenMap.
*
* @param objectId
* @return RETURN_OK if successful
* CHILD_DOESNT_HAVE_MODES if Child is no HasHealthIF and no HasModesIF
* COULD_NOT_INSERT_CHILD If the Child could not be added to the ChildrenMap
*/
ReturnValue_t registerChild(object_id_t objectId);
virtual ReturnValue_t initialize() override;
@ -56,9 +67,9 @@ protected:
Mode_t mode;
Submode_t submode;
Submode_t submode = SUBMODE_NONE;
bool childrenChangedMode;
bool childrenChangedMode = false;
/**
* Always check this against <=0, so you are robust against too many replies

View File

@ -1,350 +1,352 @@
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
#include "Heater.h"
#include "../devicehandlers/DeviceHandlerFailureIsolation.h"
#include "../power/Fuse.h"
#include "../ipc/QueueFactory.h"
Heater::Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1) :
HealthDevice(objectId, 0), internalState(STATE_OFF), powerSwitcher(
NULL), pcduQueueId(0), switch0(switch0), switch1(switch1), wasOn(
false), timedOut(false), reactedToBeingFaulty(false), passive(
false), eventQueue(NULL), heaterOnCountdown(10800000)/*about two orbits*/, parameterHelper(
this), lastAction(CLEAR) {
eventQueue = QueueFactory::instance()->createMessageQueue();
HealthDevice(objectId, 0), internalState(STATE_OFF), switch0(switch0), switch1(switch1),
heaterOnCountdown(10800000)/*about two orbits*/,
parameterHelper(this) {
eventQueue = QueueFactory::instance()->createMessageQueue();
}
Heater::~Heater() {
QueueFactory::instance()->deleteMessageQueue(eventQueue);
QueueFactory::instance()->deleteMessageQueue(eventQueue);
}
ReturnValue_t Heater::set() {
passive = false;
//wait for clear before doing anything
if (internalState == STATE_WAIT) {
return HasReturnvaluesIF::RETURN_OK;
}
if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(SET);
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){
return HasReturnvaluesIF::RETURN_FAILED;
} else {
return HasReturnvaluesIF::RETURN_OK;
}
} else {
if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true;
doAction(CLEAR);
}
}
return HasReturnvaluesIF::RETURN_FAILED;
}
passive = false;
//wait for clear before doing anything
if (internalState == STATE_WAIT) {
return HasReturnvaluesIF::RETURN_OK;
}
if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(SET);
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)){
return HasReturnvaluesIF::RETURN_FAILED;
} else {
return HasReturnvaluesIF::RETURN_OK;
}
} else {
if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true;
doAction(CLEAR);
}
}
return HasReturnvaluesIF::RETURN_FAILED;
}
}
void Heater::clear(bool passive) {
this->passive = passive;
//Force switching off
if (internalState == STATE_WAIT) {
internalState = STATE_ON;
}
if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(CLEAR);
} else if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true;
doAction(CLEAR);
}
}
this->passive = passive;
//Force switching off
if (internalState == STATE_WAIT) {
internalState = STATE_ON;
}
if (healthHelper.healthTable->isHealthy(getObjectId())) {
doAction(CLEAR);
} else if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (!reactedToBeingFaulty) {
reactedToBeingFaulty = true;
doAction(CLEAR);
}
}
}
void Heater::doAction(Action action) {
//only act if we are not in the right state or in a transition
if (action == SET) {
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)
|| (internalState == STATE_EXTERNAL_CONTROL)) {
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
internalState = STATE_WAIT_FOR_SWITCHES_ON;
powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON);
powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON);
}
} else { //clear
if ((internalState == STATE_ON) || (internalState == STATE_FAULTY)
|| (internalState == STATE_EXTERNAL_CONTROL)) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF);
}
}
//only act if we are not in the right state or in a transition
if (action == SET) {
if ((internalState == STATE_OFF) || (internalState == STATE_PASSIVE)
|| (internalState == STATE_EXTERNAL_CONTROL)) {
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
internalState = STATE_WAIT_FOR_SWITCHES_ON;
powerSwitcher->sendSwitchCommand(switch0, PowerSwitchIF::SWITCH_ON);
powerSwitcher->sendSwitchCommand(switch1, PowerSwitchIF::SWITCH_ON);
}
} else { //clear
if ((internalState == STATE_ON) || (internalState == STATE_FAULTY)
|| (internalState == STATE_EXTERNAL_CONTROL)) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF);
}
}
}
void Heater::setPowerSwitcher(PowerSwitchIF* powerSwitch) {
this->powerSwitcher = powerSwitch;
this->powerSwitcher = powerSwitch;
}
ReturnValue_t Heater::performOperation(uint8_t opCode) {
handleQueue();
handleEventQueue();
handleQueue();
handleEventQueue();
if (!healthHelper.healthTable->isFaulty(getObjectId())) {
reactedToBeingFaulty = false;
}
if (!healthHelper.healthTable->isFaulty(getObjectId())) {
reactedToBeingFaulty = false;
}
switch (internalState) {
case STATE_ON:
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) {
//switch went off on its own
//trigger event. FDIR can confirm if it is caused by MniOps and decide on the action
//do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF);
} else {
internalState = STATE_EXTERNAL_CONTROL;
}
}
break;
case STATE_OFF:
//check if heater is on, ie both switches are on
//if so, just command it to off, to resolve the situation or force a switch stayed on event
//But, only do anything if not already faulty (state off is the stable point for being faulty)
if ((!healthHelper.healthTable->isFaulty(getObjectId()))
&& (powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
//do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF);
} else {
internalState = STATE_EXTERNAL_CONTROL;
}
}
break;
case STATE_PASSIVE:
break;
case STATE_WAIT_FOR_SWITCHES_ON:
if (switchCountdown.hasTimedOut()) {
if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) {
triggerEvent(HEATER_STAYED_OFF);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else {
triggerEvent(HEATER_ON);
internalState = STATE_ON;
}
}
break;
case STATE_WAIT_FOR_SWITCHES_OFF:
if (switchCountdown.hasTimedOut()) {
//only check for both being on (ie heater still on)
if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (passive) {
internalState = STATE_PASSIVE;
} else {
internalState = STATE_OFF; //just accept it
}
triggerEvent(HEATER_ON); //but throw an event to make it more visible
break;
}
triggerEvent(HEATER_STAYED_ON);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else {
triggerEvent(HEATER_OFF);
if (passive) {
internalState = STATE_PASSIVE;
} else {
internalState = STATE_OFF;
}
}
}
break;
default:
break;
}
switch (internalState) {
case STATE_ON:
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) {
//switch went off on its own
//trigger event. FDIR can confirm if it is caused by MniOps and decide on the action
//do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
triggerEvent(PowerSwitchIF::SWITCH_WENT_OFF);
} else {
internalState = STATE_EXTERNAL_CONTROL;
}
}
break;
case STATE_OFF:
//check if heater is on, ie both switches are on
//if so, just command it to off, to resolve the situation or force a switch stayed on event
//But, only do anything if not already faulty (state off is the stable point for being faulty)
if ((!healthHelper.healthTable->isFaulty(getObjectId()))
&& (powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
//do not trigger FD events when under external control
if (healthHelper.getHealth() != EXTERNAL_CONTROL) {
internalState = STATE_WAIT_FOR_SWITCHES_OFF;
switchCountdown.setTimeout(powerSwitcher->getSwitchDelayMs());
powerSwitcher->sendSwitchCommand(switch0,
PowerSwitchIF::SWITCH_OFF);
powerSwitcher->sendSwitchCommand(switch1,
PowerSwitchIF::SWITCH_OFF);
} else {
internalState = STATE_EXTERNAL_CONTROL;
}
}
break;
case STATE_PASSIVE:
break;
case STATE_WAIT_FOR_SWITCHES_ON:
if (switchCountdown.hasTimedOut()) {
if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_OFF)
|| (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_OFF)) {
triggerEvent(HEATER_STAYED_OFF);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else {
triggerEvent(HEATER_ON);
internalState = STATE_ON;
}
}
break;
case STATE_WAIT_FOR_SWITCHES_OFF:
if (switchCountdown.hasTimedOut()) {
//only check for both being on (ie heater still on)
if ((powerSwitcher->getSwitchState(switch0)
== PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
if (healthHelper.healthTable->isFaulty(getObjectId())) {
if (passive) {
internalState = STATE_PASSIVE;
} else {
internalState = STATE_OFF; //just accept it
}
triggerEvent(HEATER_ON); //but throw an event to make it more visible
break;
}
triggerEvent(HEATER_STAYED_ON);
internalState = STATE_WAIT_FOR_FDIR; //wait before retrying or anything
} else {
triggerEvent(HEATER_OFF);
if (passive) {
internalState = STATE_PASSIVE;
} else {
internalState = STATE_OFF;
}
}
}
break;
default:
break;
}
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
if (wasOn) {
if (heaterOnCountdown.hasTimedOut()) {
//SHOULDDO this means if a heater fails in single mode, the timeout will start again
//I am not sure if this is a bug, but atm I have no idea how to fix this and think
//it will be ok. whatcouldpossiblygowrong™
if (!timedOut) {
triggerEvent(HEATER_TIMEOUT);
timedOut = true;
}
}
} else {
wasOn = true;
heaterOnCountdown.resetTimer();
timedOut = false;
}
} else {
wasOn = false;
}
if ((powerSwitcher->getSwitchState(switch0) == PowerSwitchIF::SWITCH_ON)
&& (powerSwitcher->getSwitchState(switch1)
== PowerSwitchIF::SWITCH_ON)) {
if (wasOn) {
if (heaterOnCountdown.hasTimedOut()) {
//SHOULDDO this means if a heater fails in single mode, the timeout will start again
//I am not sure if this is a bug, but atm I have no idea how to fix this and think
//it will be ok. whatcouldpossiblygowrong™
if (!timedOut) {
triggerEvent(HEATER_TIMEOUT);
timedOut = true;
}
}
} else {
wasOn = true;
heaterOnCountdown.resetTimer();
timedOut = false;
}
} else {
wasOn = false;
}
return HasReturnvaluesIF::RETURN_OK;
return HasReturnvaluesIF::RETURN_OK;
}
void Heater::setSwitch(uint8_t number, ReturnValue_t state,
uint32_t* uptimeOfSwitching) {
if (powerSwitcher == NULL) {
return;
}
if (powerSwitcher->getSwitchState(number) == state) {
*uptimeOfSwitching = INVALID_UPTIME;
} else {
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
powerSwitcher->sendSwitchCommand(number, state);
Clock::getUptime(uptimeOfSwitching);
} else {
uint32_t currentUptime;
Clock::getUptime(&currentUptime);
if (currentUptime - *uptimeOfSwitching
> powerSwitcher->getSwitchDelayMs()) {
*uptimeOfSwitching = INVALID_UPTIME;
if (healthHelper.healthTable->isHealthy(getObjectId())) {
if (state == PowerSwitchIF::SWITCH_ON) {
triggerEvent(HEATER_STAYED_OFF);
} else {
triggerEvent(HEATER_STAYED_ON);
}
}
//SHOULDDO MiniOps during switch timeout leads to a faulty switch
}
}
}
uint32_t* uptimeOfSwitching) {
if (powerSwitcher == NULL) {
return;
}
if (powerSwitcher->getSwitchState(number) == state) {
*uptimeOfSwitching = INVALID_UPTIME;
} else {
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
powerSwitcher->sendSwitchCommand(number, state);
Clock::getUptime(uptimeOfSwitching);
} else {
uint32_t currentUptime;
Clock::getUptime(&currentUptime);
if (currentUptime - *uptimeOfSwitching
> powerSwitcher->getSwitchDelayMs()) {
*uptimeOfSwitching = INVALID_UPTIME;
if (healthHelper.healthTable->isHealthy(getObjectId())) {
if (state == PowerSwitchIF::SWITCH_ON) {
triggerEvent(HEATER_STAYED_OFF);
} else {
triggerEvent(HEATER_STAYED_ON);
}
}
}
}
}
}
MessageQueueId_t Heater::getCommandQueue() const {
return commandQueue->getId();
return commandQueue->getId();
}
ReturnValue_t Heater::initialize() {
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
ReturnValue_t result = SystemObject::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
EventManagerIF* manager = objectManager->get<EventManagerIF>(
objects::EVENT_MANAGER);
if (manager == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
result = manager->registerListener(eventQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
EventManagerIF* manager = objectManager->get<EventManagerIF>(
objects::EVENT_MANAGER);
if (manager == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
result = manager->registerListener(eventQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>(
DeviceHandlerFailureIsolation::powerConfirmationId);
if (pcdu == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
pcduQueueId = pcdu->getEventReceptionQueue();
ConfirmsFailuresIF* pcdu = objectManager->get<ConfirmsFailuresIF>(
DeviceHandlerFailureIsolation::powerConfirmationId);
if (pcdu == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
pcduQueueId = pcdu->getEventReceptionQueue();
result = manager->subscribeToAllEventsFrom(eventQueue->getId(),
getObjectId());
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = manager->subscribeToAllEventsFrom(eventQueue->getId(),
getObjectId());
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = parameterHelper.initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = parameterHelper.initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = healthHelper.initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = healthHelper.initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return HasReturnvaluesIF::RETURN_OK;
return HasReturnvaluesIF::RETURN_OK;
}
void Heater::handleQueue() {
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
result = healthHelper.handleHealthCommand(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
return;
}
parameterHelper.handleParameterMessage(&command);
}
CommandMessage command;
ReturnValue_t result = commandQueue->receiveMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
result = healthHelper.handleHealthCommand(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
return;
}
result = parameterHelper.handleParameterMessage(&command);
if (result == HasReturnvaluesIF::RETURN_OK) {
return;
}
}
}
ReturnValue_t Heater::getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues,
uint16_t startAtIndex) {
if (domainId != DOMAIN_ID_BASE) {
return INVALID_DOMAIN_ID;
}
switch (uniqueId) {
case 0:
parameterWrapper->set(heaterOnCountdown.timeout);
break;
default:
return INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
uint16_t startAtIndex) {
if (domainId != DOMAIN_ID_BASE) {
return INVALID_DOMAIN_ID;
}
switch (uniqueId) {
case 0:
parameterWrapper->set(heaterOnCountdown.timeout);
break;
default:
return INVALID_IDENTIFIER_ID;
}
return HasReturnvaluesIF::RETURN_OK;
}
void Heater::handleEventQueue() {
EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
result == HasReturnvaluesIF::RETURN_OK;
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
switch (event.getEvent()) {
case Fuse::FUSE_WENT_OFF:
case HEATER_STAYED_OFF:
case HEATER_STAYED_ON://Setting it faulty does not help, but we need to reach a stable state and can check for being faulty before throwing this event again.
if (healthHelper.healthTable->isCommandable(getObjectId())) {
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
}
break;
case PowerSwitchIF::SWITCH_WENT_OFF:
internalState = STATE_WAIT;
event.setMessageId(EventMessage::CONFIRMATION_REQUEST);
if (pcduQueueId != 0) {
eventQueue->sendMessage(pcduQueueId, &event);
} else {
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
}
break;
default:
return;
}
break;
case EventMessage::YOUR_FAULT:
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
break;
case EventMessage::MY_FAULT:
//do nothing, we are already in STATE_WAIT and wait for a clear()
break;
default:
return;
}
}
EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
result == HasReturnvaluesIF::RETURN_OK;
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
switch (event.getEvent()) {
case Fuse::FUSE_WENT_OFF:
case HEATER_STAYED_OFF:
// HEATER_STAYED_ON is a setting if faulty does not help, but we need to reach a stable state and can check
// for being faulty before throwing this event again.
case HEATER_STAYED_ON:
if (healthHelper.healthTable->isCommandable(getObjectId())) {
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
}
break;
case PowerSwitchIF::SWITCH_WENT_OFF:
internalState = STATE_WAIT;
event.setMessageId(EventMessage::CONFIRMATION_REQUEST);
if (pcduQueueId != 0) {
eventQueue->sendMessage(pcduQueueId, &event);
} else {
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
}
break;
default:
return;
}
break;
case EventMessage::YOUR_FAULT:
healthHelper.setHealth(HasHealthIF::FAULTY);
internalState = STATE_FAULTY;
break;
case EventMessage::MY_FAULT:
//do nothing, we are already in STATE_WAIT and wait for a clear()
break;
default:
return;
}
}
}

View File

@ -1,90 +1,93 @@
#ifndef FRAMEWORK_THERMAL_HEATER_H_
#define FRAMEWORK_THERMAL_HEATER_H_
#ifndef FSFW_THERMAL_HEATER_H_
#define FSFW_THERMAL_HEATER_H_
#include "../devicehandlers/HealthDevice.h"
#include "../parameters/ParameterHelper.h"
#include "../power/PowerSwitchIF.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../timemanager/Countdown.h"
#include <stdint.h>
//class RedundantHeater;
#include <cstdint>
class Heater: public HealthDevice, public ReceivesParameterMessagesIF {
friend class RedundantHeater;
friend class RedundantHeater;
public:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER;
static const Event HEATER_ON = MAKE_EVENT(0, severity::INFO);
static const Event HEATER_OFF = MAKE_EVENT(1, severity::INFO);
static const Event HEATER_TIMEOUT = MAKE_EVENT(2, severity::LOW);
static const Event HEATER_STAYED_ON = MAKE_EVENT(3, severity::LOW);
static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, severity::LOW);
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER;
static const Event HEATER_ON = MAKE_EVENT(0, severity::INFO);
static const Event HEATER_OFF = MAKE_EVENT(1, severity::INFO);
static const Event HEATER_TIMEOUT = MAKE_EVENT(2, severity::LOW);
static const Event HEATER_STAYED_ON = MAKE_EVENT(3, severity::LOW);
static const Event HEATER_STAYED_OFF = MAKE_EVENT(4, severity::LOW);
Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1);
virtual ~Heater();
Heater(uint32_t objectId, uint8_t switch0, uint8_t switch1);
virtual ~Heater();
ReturnValue_t performOperation(uint8_t opCode);
ReturnValue_t performOperation(uint8_t opCode);
ReturnValue_t initialize();
ReturnValue_t initialize();
ReturnValue_t set();
void clear(bool passive);
ReturnValue_t set();
void clear(bool passive);
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
void setPowerSwitcher(PowerSwitchIF *powerSwitch);
MessageQueueId_t getCommandQueue() const;
MessageQueueId_t getCommandQueue() const;
ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex);
ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
ParameterWrapper *parameterWrapper,
const ParameterWrapper *newValues, uint16_t startAtIndex);
protected:
static const uint32_t INVALID_UPTIME = 0;
static const uint32_t INVALID_UPTIME = 0;
enum InternalState {
STATE_ON,
STATE_OFF,
STATE_PASSIVE,
STATE_WAIT_FOR_SWITCHES_ON,
STATE_WAIT_FOR_SWITCHES_OFF,
STATE_WAIT_FOR_FDIR, //used to avoid doing anything until fdir decided what to do
STATE_FAULTY,
STATE_WAIT, //used when waiting for system to recover from miniops
STATE_EXTERNAL_CONTROL //entered when under external control and a fdir reaction would be triggered. This is useful when leaving external control into an unknown state
//if no fdir reaction is triggered under external control the state is still ok and no need for any special treatment is needed
} internalState;
enum InternalState {
STATE_ON,
STATE_OFF,
STATE_PASSIVE,
STATE_WAIT_FOR_SWITCHES_ON,
STATE_WAIT_FOR_SWITCHES_OFF,
STATE_WAIT_FOR_FDIR, // Used to avoid doing anything until fdir decided what to do
STATE_FAULTY,
STATE_WAIT, // Used when waiting for system to recover from miniops
// Entered when under external control and a fdir reaction would be triggered.
// This is useful when leaving external control into an unknown state
STATE_EXTERNAL_CONTROL
// If no fdir reaction is triggered under external control the state is still ok and
// no need for any special treatment is needed
} internalState;
PowerSwitchIF *powerSwitcher;
MessageQueueId_t pcduQueueId;
PowerSwitchIF *powerSwitcher = nullptr;
MessageQueueId_t pcduQueueId = MessageQueueIF::NO_QUEUE;
uint8_t switch0;
uint8_t switch1;
uint8_t switch0;
uint8_t switch1;
bool wasOn;
bool wasOn = false;
bool timedOut;
bool timedOut = false;
bool reactedToBeingFaulty;
bool reactedToBeingFaulty = false;
bool passive;
bool passive = false;
MessageQueueIF* eventQueue;
Countdown heaterOnCountdown;
Countdown switchCountdown;
ParameterHelper parameterHelper;
MessageQueueIF* eventQueue = nullptr;
Countdown heaterOnCountdown;
Countdown switchCountdown;
ParameterHelper parameterHelper;
enum Action {
SET, CLEAR
} lastAction;
enum Action {
SET, CLEAR
} lastAction = CLEAR;
void doAction(Action action);
void doAction(Action action);
void setSwitch(uint8_t number, ReturnValue_t state,
uint32_t *upTimeOfSwitching);
void setSwitch(uint8_t number, ReturnValue_t state,
uint32_t *upTimeOfSwitching);
void handleQueue();
void handleQueue();
void handleEventQueue();
void handleEventQueue();
};
#endif /* FRAMEWORK_THERMAL_HEATER_H_ */
#endif /* FSFW_THERMAL_HEATER_H_ */

View File

@ -1,5 +1,5 @@
#ifndef TEMPERATURESENSOR_H_
#define TEMPERATURESENSOR_H_
#ifndef FSFW_THERMAL_TEMPERATURESENSOR_H_
#define FSFW_THERMAL_TEMPERATURESENSOR_H_
#include "tcsDefinitions.h"
#include "AbstractTemperatureSensor.h"
@ -60,23 +60,22 @@ public:
/**
* Instantiate Temperature Sensor Object.
* @param setObjectid objectId of the sensor object
* @param inputValue Pointer to input value which is converted to a temperature
* @param variableGpid Global Pool ID of the output value
* @param inputVariable Input variable handle
* @param vectorIndex Vector Index for the sensor monitor
* @param parameters Calculation parameters, temperature limits, gradient limit
* @param outputSet Output dataset for the output temperature to fetch it with read()
* @param thermalModule respective thermal module, if it has one
* @param setObjectid objectId of the sensor object
* @param inputTemperature Pointer to a raw input value which is converted to an floating
* point C output temperature
* @param outputGpid Global Pool ID of the output value
* @param vectorIndex Vector Index for the sensor monitor
* @param parameters Calculation parameters, temperature limits, gradient limit
* @param outputSet Output dataset for the output temperature to fetch it with read()
* @param thermalModule Respective thermal module, if it has one
*/
TemperatureSensor(object_id_t setObjectid,
inputType *inputValue, gp_id_t variableGpid, PoolVariableIF* inputVariable,
uint8_t vectorIndex, Parameters parameters = {0, 0, 0, 0, 0, 0},
LocalPoolDataSetBase *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) :
TemperatureSensor(object_id_t setObjectid,lp_var_t<limitType>* inputTemperature,
gp_id_t outputGpid, uint8_t vectorIndex, Parameters parameters = {0, 0, 0, 0, 0, 0},
LocalPoolDataSetBase *outputSet = nullptr, ThermalModuleIF *thermalModule = nullptr) :
AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters),
inputValue(inputValue), poolVariable(inputVariable),
outputTemperature(variableGpid, outputSet, PoolVariableIF::VAR_WRITE),
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, poolVariable,
inputTemperature(inputTemperature),
outputTemperature(outputGpid, outputSet, PoolVariableIF::VAR_WRITE),
sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, outputGpid,
DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit,
TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH),
oldTemperature(20), uptimeOfOldTemperature({ thermal::INVALID_TEMPERATURE, 0 }) {
@ -110,10 +109,7 @@ protected:
UsedParameters parameters;
inputType* inputValue;
PoolVariableIF* poolVariable;
lp_var_t<limitType>* inputTemperature;
lp_var_t<float> outputTemperature;
LimitMonitor<limitType> sensorMonitor;
@ -122,22 +118,27 @@ protected:
timeval uptimeOfOldTemperature;
void doChildOperation() {
if ((not poolVariable->isValid()) or
ReturnValue_t result = inputTemperature->read(MutexIF::TimeoutType::WAITING, 20);
if(result != HasReturnvaluesIF::RETURN_OK) {
return;
}
if ((not inputTemperature->isValid()) or
(not healthHelper.healthTable->isHealthy(getObjectId()))) {
setInvalid();
return;
}
outputTemperature = calculateOutputTemperature(*inputValue);
outputTemperature = calculateOutputTemperature(inputTemperature->value);
outputTemperature.setValid(PoolVariableIF::VALID);
timeval uptime;
Clock::getUptime(&uptime);
if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) {
//In theory, we could use an AbsValueMonitor to monitor the gradient.
//But this would require storing the maxGradient in DP and quite some overhead.
//The concept of delta limits is a bit strange anyway.
// In theory, we could use an AbsValueMonitor to monitor the gradient.
// But this would require storing the maxGradient in DP and quite some overhead.
// The concept of delta limits is a bit strange anyway.
float deltaTime;
float deltaTemp;
@ -150,11 +151,11 @@ protected:
}
if (parameters.gradient < deltaTemp / deltaTime) {
triggerEvent(TEMP_SENSOR_GRADIENT);
//Don't set invalid, as we did not recognize it as invalid with full authority, let FDIR handle it
// Don't set invalid, as we did not recognize it as invalid with full authority,
// let FDIR handle it
}
}
//Check is done against raw limits. SHOULDDO: Why? Using C would be more easy to handle.
sensorMonitor.doCheck(outputTemperature.value);
if (sensorMonitor.isOutOfLimits()) {
@ -181,7 +182,10 @@ public:
static const uint16_t ADDRESS_C = 2;
static const uint16_t ADDRESS_GRADIENT = 3;
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1; //!< Changed due to issue with later temperature checking even tough the sensor monitor was confirming already (Was 10 before with comment = Correlates to a 10s confirmation time. Chosen rather large, should not be so bad for components and helps survive glitches.)
//! Changed due to issue with later temperature checking even tough the sensor monitor was
//! confirming already (Was 10 before with comment = Correlates to a 10s confirmation time.
//! Chosen rather large, should not be so bad for components and helps survive glitches.)
static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1;
static const uint8_t DOMAIN_ID_SENSOR = 1;
@ -221,4 +225,4 @@ public:
};
#endif /* TEMPERATURESENSOR_H_ */
#endif /* FSFW_THERMAL_TEMPERATURESENSOR_H_ */

View File

@ -25,6 +25,6 @@ uint32_t TimeMessage::getCounterValue() {
return temp;
}
size_t TimeMessage::getMinimumMessageSize() {
size_t TimeMessage::getMinimumMessageSize() const {
return this->MAX_SIZE;
}

View File

@ -11,7 +11,7 @@ protected:
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + \c sizeof(timeval) + sizeof(uint32_t).
*/
size_t getMinimumMessageSize();
size_t getMinimumMessageSize() const override;
public:
/**

View File

@ -1,6 +1,7 @@
#ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#include <FSFWConfig.h>
#include "../returnvalues/HasReturnvaluesIF.h"
/**
@ -16,8 +17,8 @@ public:
//! This is a mission-specific constant and determines the total
//! size reserved for timestamps.
//! TODO: Default define in FSFWConfig ?
static const uint8_t MISSION_TIMESTAMP_SIZE = 8;
static const uint8_t MISSION_TIMESTAMP_SIZE = fsfwconfig::FSFW_MISSION_TIMESTAMP_SIZE;
virtual ReturnValue_t addTimeStamp(uint8_t* buffer,
const uint8_t maxSize) = 0;
virtual ~TimeStamperIF() {}

View File

@ -4,5 +4,9 @@ target_sources(${LIB_FSFW_NAME}
TcPacketStored.cpp
TmPacketBase.cpp
TmPacketMinimal.cpp
TmPacketStored.cpp
TmPacketStoredPusA.cpp
TmPacketStoredPusC.cpp
TmPacketPusA.cpp
TmPacketPusC.cpp
TmPacketStoredBase.cpp
)

View File

@ -3,119 +3,66 @@
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../timemanager/CCSDSTime.h"
#include <cstring>
TimeStamperIF* TmPacketBase::timeStamper = nullptr;
object_id_t TmPacketBase::timeStamperId = 0;
object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT;
TmPacketBase::TmPacketBase(uint8_t* setData) :
SpacePacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointer*>(setData);
TmPacketBase::TmPacketBase(uint8_t* setData):
SpacePacketBase(setData) {
}
TmPacketBase::~TmPacketBase() {
//Nothing to do.
//Nothing to do.
}
uint8_t TmPacketBase::getService() {
return tmData->data_field.service_type;
}
uint8_t TmPacketBase::getSubService() {
return tmData->data_field.service_subtype;
}
uint8_t* TmPacketBase::getSourceData() {
return &tmData->data;
}
uint16_t TmPacketBase::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->data_field)
- CRC_SIZE + 1;
return getPacketDataLength() - getDataFieldSize() - CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tmData->data;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = getSourceData();
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TmPacketBase::setErrorControl() {
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getSourceDataSize();
getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH
getSourceData()[size + 1] = (crc) & 0X00FF; // CRCL
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getSourceDataSize();
getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH
getSourceData()[size + 1] = (crc) & 0X00FF; // CRCL
}
void TmPacketBase::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tmData = (TmPacketPointer*) p_Data;
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
size_t tempSize = 0;
return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(),
&tempSize, getTimestampSize());
}
void TmPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "TmPacketBase::print: " << std::endl;
sif::debug << "TmPacketBase::print: " << std::endl;
#endif
arrayprinter::print(getWholeData(), getFullSize());
arrayprinter::print(getWholeData(), getFullSize());
}
bool TmPacketBase::checkAndSetStamper() {
if (timeStamper == NULL) {
timeStamper = objectManager->get<TimeStamperIF>(timeStamperId);
if (timeStamper == NULL) {
if (timeStamper == NULL) {
timeStamper = objectManager->get<TimeStamperIF>(timeStamperId);
if (timeStamper == NULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmPacketBase::checkAndSetStamper: Stamper not found!"
<< std::endl;
sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
#else
sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n");
#endif
return false;
}
}
return true;
return false;
}
}
return true;
}
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
size_t tempSize = 0;
return CCSDSTime::convertFromCcsds(timestamp, tmData->data_field.time,
&tempSize, sizeof(tmData->data_field.time));
}
uint8_t* TmPacketBase::getPacketTimeRaw() const{
return tmData->data_field.time;
}
void TmPacketBase::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter) {
//Set primary header:
initSpacePacketHeader(false, true, apid);
//Set data Field Header:
//First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits.
// The other 4 bits of the first byte are the spacecraft time reference
// status. To change to PUS-C, set 0b00100000.
// Set CCSDS_secondary header flag to 0, version number to 001 and ack
// to 0000
tmData->data_field.version_type_ack = 0b00010000;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
//Timestamp packet
if (checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->data_field.time,
sizeof(tmData->data_field.time));
}
}
void TmPacketBase::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
}
size_t TmPacketBase::getTimestampSize() const {
return sizeof(tmData->data_field.time);
}

View File

@ -10,32 +10,6 @@ namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* This struct defines a byte-wise structured PUS TM Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, no Destination field is present, but an eigth-byte representation
* for a time tag.
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeader {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
// uint8_t destination;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketPointer {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeader data_field;
uint8_t data;
};
/**
* This class is the basic data handler for any ECSS PUS Telemetry packet.
@ -49,61 +23,83 @@ struct TmPacketPointer {
* @ingroup tmtcpackets
*/
class TmPacketBase : public SpacePacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeader) + 2);
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
//! First byte of secondary header for PUS-A packets.
//! TODO: Maybe also support PUS-C via config?
static const uint8_t VERSION_NUMBER_BYTE_PUS_A = 0b00010000;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketBase( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketBase();
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
//! First four bits of first byte of secondary header
static const uint8_t VERSION_NUMBER_BYTE = 0b00010000;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
uint8_t getService();
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
uint8_t getSubService();
/**
* This is a getter for a pointer to the packet's Source data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's source data.
* @return A pointer to the PUS Source Data.
*/
uint8_t* getSourceData();
/**
* This method calculates the size of the PUS Source data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Source Data (without Error Control field)
*/
uint16_t getSourceDataSize();
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketBase( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketBase();
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() = 0;
/**
* This is a getter for a pointer to the packet's Source data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's source data.
* @return A pointer to the PUS Source Data.
*/
virtual uint8_t* getSourceData() = 0;
/**
* This method calculates the size of the PUS Source data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Source Data (without Error Control field)
*/
virtual uint16_t getSourceDataSize() = 0;
/**
* Get size of data field which can differ based on implementation
* @return
*/
virtual uint16_t getDataFieldSize() = 0;
virtual size_t getPacketMinimumSize() const = 0;
/**
* Interprets the "time"-field in the secondary header and returns it in
* timeval format.
* @return Converted timestamp of packet.
*/
virtual ReturnValue_t getPacketTime(timeval* timestamp) const;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
virtual uint8_t* getPacketTimeRaw() const = 0;
virtual size_t getTimestampSize() const = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet. This method is not protected because
@ -111,79 +107,24 @@ public:
* like the sequence count.
*/
void setErrorControl();
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Source Data. If no
* Source Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
uint16_t getErrorControl();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* Interprets the "time"-field in the secondary header and returns it in
* timeval format.
* @return Converted timestamp of packet.
*/
ReturnValue_t getPacketTime(timeval* timestamp) const;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const;
size_t getTimestampSize() const;
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Source Data. If no
* Source Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
uint16_t getErrorControl();
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointer* tmData;
/**
* The timeStamper is responsible for adding a timestamp to the packet.
* It is initialized lazy.
*/
static TimeStamperIF* timeStamper;
//! The ID to use when looking for a time stamper.
static object_id_t timeStamperId;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
* The timeStamper is responsible for adding a timestamp to the packet.
* It is initialized lazy.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
void setData( const uint8_t* pData );
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
static TimeStamperIF* timeStamper;
//! The ID to use when looking for a time stamper.
static object_id_t timeStamperId;
/**
* Checks if a time stamper is available and tries to set it if not.

View File

@ -0,0 +1,87 @@
#include "TmPacketPusA.h"
#include "TmPacketBase.h"
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../timemanager/CCSDSTime.h"
#include <cstring>
TmPacketPusA::TmPacketPusA(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusA*>(setData);
}
TmPacketPusA::~TmPacketPusA() {
//Nothing to do.
}
uint8_t TmPacketPusA::getService() {
return tmData->data_field.service_type;
}
uint8_t TmPacketPusA::getSubService() {
return tmData->data_field.service_subtype;
}
uint8_t* TmPacketPusA::getSourceData() {
return &tmData->data;
}
uint16_t TmPacketPusA::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->data_field)
- CRC_SIZE + 1;
}
void TmPacketPusA::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tmData = (TmPacketPointerPusA*) p_Data;
}
size_t TmPacketPusA::getPacketMinimumSize() const {
return TM_PACKET_MIN_SIZE;
}
uint16_t TmPacketPusA::getDataFieldSize() {
return sizeof(PUSTmDataFieldHeaderPusA);
}
uint8_t* TmPacketPusA::getPacketTimeRaw() const {
return tmData->data_field.time;
}
void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter) {
//Set primary header:
initSpacePacketHeader(false, true, apid);
//Set data Field Header:
//First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits.
// The other 4 bits of the first byte are the spacecraft time reference
// status. To change to PUS-C, set 0b00100000.
// Set CCSDS_secondary header flag to 0, version number to 001 and ack
// to 0000
tmData->data_field.version_type_ack = 0b00010000;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
//Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->data_field.time,
sizeof(tmData->data_field.time));
}
}
void TmPacketPusA::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
size_t TmPacketPusA::getTimestampSize() const {
return sizeof(tmData->data_field.time);
}

View File

@ -0,0 +1,129 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_
#include "TmPacketBase.h"
#include "../SpacePacketBase.h"
#include "../../timemanager/TimeStamperIF.h"
#include "../../timemanager/Clock.h"
#include "../../objectmanager/SystemObjectIF.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* This struct defines a byte-wise structured PUS TM Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, no Destination field is present, but an eigth-byte representation
* for a time tag.
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeaderPusA {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
// uint8_t destination;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusA {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusA data_field;
uint8_t data;
};
/**
* PUS A packet implementation
* @ingroup tmtcpackets
*/
class TmPacketPusA: public TmPacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeaderPusA) + 2);
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusA( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusA();
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
size_t getPacketMinimumSize() const override;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusA* tmData;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
void setData( const uint8_t* pData );
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ */

View File

@ -0,0 +1,87 @@
#include "TmPacketPusC.h"
#include "TmPacketBase.h"
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../timemanager/CCSDSTime.h"
#include <cstring>
TmPacketPusC::TmPacketPusC(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusC*>(setData);
}
TmPacketPusC::~TmPacketPusC() {
//Nothing to do.
}
uint8_t TmPacketPusC::getService() {
return tmData->dataField.serviceType;
}
uint8_t TmPacketPusC::getSubService() {
return tmData->dataField.serviceSubtype;
}
uint8_t* TmPacketPusC::getSourceData() {
return &tmData->data;
}
uint16_t TmPacketPusC::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->dataField) - CRC_SIZE + 1;
}
void TmPacketPusC::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tmData = (TmPacketPointerPusC*) p_Data;
}
size_t TmPacketPusC::getPacketMinimumSize() const {
return TM_PACKET_MIN_SIZE;
}
uint16_t TmPacketPusC::getDataFieldSize() {
return sizeof(PUSTmDataFieldHeaderPusC);
}
uint8_t* TmPacketPusC::getPacketTimeRaw() const{
return tmData->dataField.time;
}
void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) {
//Set primary header:
initSpacePacketHeader(false, true, apid);
//Set data Field Header:
//First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
/* Only account for last 4 bytes for time reference field */
timeRefField &= 0b1111;
tmData->dataField.versionTimeReferenceField = VERSION_NUMBER_BYTE | timeRefField;
tmData->dataField.serviceType = service;
tmData->dataField.serviceSubtype = subservice;
tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;
tmData->dataField.subcounterLsb = packetSubcounter & 0xff;
tmData->dataField.destinationIdMsb = destinationId << 8 & 0xff;
tmData->dataField.destinationIdLsb = destinationId & 0xff;
//Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->dataField.time,
sizeof(tmData->dataField.time));
}
}
void TmPacketPusC::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
size_t TmPacketPusC::getTimestampSize() const {
return sizeof(tmData->dataField.time);
}

View File

@ -0,0 +1,126 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_
#include "TmPacketBase.h"
#include "../SpacePacketBase.h"
#include "../../timemanager/TimeStamperIF.h"
#include "../../timemanager/Clock.h"
#include "../../objectmanager/SystemObjectIF.h"
namespace Factory{
void setStaticFrameworkObjectIds();
}
/**
* This struct defines a byte-wise structured PUS TM Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, no Destination field is present, but an eigth-byte representation
* for a time tag.
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeaderPusC {
uint8_t versionTimeReferenceField;
uint8_t serviceType;
uint8_t serviceSubtype;
uint8_t subcounterMsb;
uint8_t subcounterLsb;
uint8_t destinationIdMsb;
uint8_t destinationIdLsb;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusC {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusC dataField;
uint8_t data;
};
/**
* PUS A packet implementation
* @ingroup tmtcpackets
*/
class TmPacketPusC: public TmPacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeaderPusC) + 2);
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusC( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusC();
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
size_t getPacketMinimumSize() const override;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusC* tmData;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
void setData( const uint8_t* pData );
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ */

View File

@ -1,147 +0,0 @@
#include "TmPacketStored.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tmtcservices/TmTcMessage.h"
#include <cstring>
StorageManagerIF *TmPacketStored::store = nullptr;
InternalErrorReporterIF *TmPacketStored::internalErrorReporter = nullptr;
TmPacketStored::TmPacketStored(store_address_t setAddress) :
TmPacketBase(nullptr), storeAddress(setAddress) {
setStoreAddress(storeAddress);
}
TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) :
TmPacketBase(NULL) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData);
if (returnValue != store->RETURN_OK) {
checkAndReportLostTm();
return;
}
setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(
size + headerSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
}
TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) :
TmPacketBase(NULL) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != NULL) {
sourceDataSize += content->getSerializedSize();
}
if (header != NULL) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *p_data = NULL;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(TmPacketBase::TM_PACKET_MIN_SIZE + sourceDataSize), &p_data);
if (returnValue != store->RETURN_OK) {
checkAndReportLostTm();
}
setData(p_data);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != NULL) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != NULL) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(
sourceDataSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
}
store_address_t TmPacketStored::getStoreAddress() {
return storeAddress;
}
void TmPacketStored::deletePacket() {
store->deleteData(storeAddress);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
setData(nullptr);
}
void TmPacketStored::setStoreAddress(store_address_t setAddress) {
storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
if (not checkAndSetStore()) {
return;
}
ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize);
if (status == StorageManagerIF::RETURN_OK) {
setData(tempData);
} else {
setData(nullptr);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
bool TmPacketStored::checkAndSetStore() {
if (store == nullptr) {
store = objectManager->get<StorageManagerIF>(objects::TM_STORE);
if (store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
<< std::endl;
#endif
return false;
}
}
return true;
}
ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting) {
if (getWholeData() == nullptr) {
//SHOULDDO: More decent code.
return HasReturnvaluesIF::RETURN_FAILED;
}
TmTcMessage tmMessage(getStoreAddress());
ReturnValue_t result = MessageQueueSenderIF::sendMessage(destination,
&tmMessage, sentFrom);
if (result != HasReturnvaluesIF::RETURN_OK) {
deletePacket();
if (doErrorReporting) {
checkAndReportLostTm();
}
return result;
}
//SHOULDDO: In many cases, some counter is incremented for successfully sent packets. The check is often not done, but just incremented.
return HasReturnvaluesIF::RETURN_OK;
}
void TmPacketStored::checkAndReportLostTm() {
if (internalErrorReporter == nullptr) {
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
}
if (internalErrorReporter != nullptr) {
internalErrorReporter->lostTm();
}
}

View File

@ -1,108 +1,13 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_
#include "TmPacketBase.h"
#include <FSFWConfig.h>
#include "../../serialize/SerializeIF.h"
#include "../../storagemanager/StorageManagerIF.h"
#include "../../internalError/InternalErrorReporterIF.h"
#include "../../ipc/MessageQueueSenderIF.h"
/**
* This class generates a ECSS PUS Telemetry packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStored : public TmPacketBase {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStored( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate
* data sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
*/
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr);
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
*/
void deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress( store_address_t setAddress );
ReturnValue_t sendPacket( MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting = true );
private:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
static InternalErrorReporterIF *internalErrorReporter;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
void checkAndReportLostTm();
};
#if FSFW_USE_PUS_C_TELEMETRY == 1
#include "TmPacketStoredPusC.h"
#else
#include "TmPacketStoredPusA.h"
#endif
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_ */

View File

@ -0,0 +1,94 @@
#include "TmPacketStoredBase.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../tmtcservices/TmTcMessage.h"
#include <cstring>
StorageManagerIF *TmPacketStoredBase::store = nullptr;
InternalErrorReporterIF *TmPacketStoredBase::internalErrorReporter = nullptr;
TmPacketStoredBase::TmPacketStoredBase(store_address_t setAddress): storeAddress(setAddress) {
setStoreAddress(storeAddress);
}
TmPacketStoredBase::TmPacketStoredBase() {
}
TmPacketStoredBase::~TmPacketStoredBase() {
}
store_address_t TmPacketStoredBase::getStoreAddress() {
return storeAddress;
}
void TmPacketStoredBase::deletePacket() {
store->deleteData(storeAddress);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
setDataPointer(nullptr);
}
void TmPacketStoredBase::setStoreAddress(store_address_t setAddress) {
storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
if (not checkAndSetStore()) {
return;
}
ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize);
if (status == StorageManagerIF::RETURN_OK) {
setDataPointer(tempData);
} else {
setDataPointer(nullptr);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
bool TmPacketStoredBase::checkAndSetStore() {
if (store == nullptr) {
store = objectManager->get<StorageManagerIF>(objects::TM_STORE);
if (store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
<< std::endl;
#endif
return false;
}
}
return true;
}
ReturnValue_t TmPacketStoredBase::sendPacket(MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting) {
if (getAllTmData() == nullptr) {
//SHOULDDO: More decent code.
return HasReturnvaluesIF::RETURN_FAILED;
}
TmTcMessage tmMessage(getStoreAddress());
ReturnValue_t result = MessageQueueSenderIF::sendMessage(destination,
&tmMessage, sentFrom);
if (result != HasReturnvaluesIF::RETURN_OK) {
deletePacket();
if (doErrorReporting) {
checkAndReportLostTm();
}
return result;
}
//SHOULDDO: In many cases, some counter is incremented for successfully sent packets. The check is often not done, but just incremented.
return HasReturnvaluesIF::RETURN_OK;
}
void TmPacketStoredBase::checkAndReportLostTm() {
if (internalErrorReporter == nullptr) {
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
}
if (internalErrorReporter != nullptr) {
internalErrorReporter->lostTm();
}
}

View File

@ -0,0 +1,89 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_
#include "TmPacketBase.h"
#include "TmPacketStoredBase.h"
#include <FSFWConfig.h>
#include "../../tmtcpacket/pus/TmPacketPusA.h"
#include "../../serialize/SerializeIF.h"
#include "../../storagemanager/StorageManagerIF.h"
#include "../../internalError/InternalErrorReporterIF.h"
#include "../../ipc/MessageQueueSenderIF.h"
/**
* This class generates a ECSS PUS Telemetry packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredBase {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredBase( store_address_t setAddress );
TmPacketStoredBase();
virtual ~TmPacketStoredBase();
virtual uint8_t* getAllTmData() = 0;
virtual void setDataPointer(const uint8_t* newPointer) = 0;
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
*/
void deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress(store_address_t setAddress);
ReturnValue_t sendPacket(MessageQueueId_t destination, MessageQueueId_t sentFrom,
bool doErrorReporting = true);
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
static InternalErrorReporterIF *internalErrorReporter;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
void checkAndReportLostTm();
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ */

View File

@ -0,0 +1,79 @@
#include "TmPacketStoredPusA.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../tmtcservices/TmTcMessage.h"
#include <cstring>
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) :
TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){
}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) :
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + size + headerSize), &pData);
if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm();
return;
}
setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(
size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) :
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != NULL) {
sourceDataSize += content->getSerializedSize();
}
if (header != NULL) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *p_data = NULL;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + sourceDataSize), &p_data);
if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm();
}
setData(p_data);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != NULL) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != NULL) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
uint8_t* TmPacketStoredPusA::getAllTmData() {
return getWholeData();
}
void TmPacketStoredPusA::setDataPointer(const uint8_t *newPointer) {
setData(newPointer);
}

View File

@ -0,0 +1,65 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#include "TmPacketStoredBase.h"
#include "TmPacketPusA.h"
#include <FSFWConfig.h>
/**
* This class generates a ECSS PUS A Telemetry packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredPusA :
public TmPacketStoredBase,
public TmPacketPusA {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusA( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate
* data sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
*/
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr);
uint8_t* getAllTmData() override;
void setDataPointer(const uint8_t* newPointer) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ */

View File

@ -0,0 +1,80 @@
#include "TmPacketStoredPusC.h"
#include "../../serviceinterface/ServiceInterface.h"
#include "../../tmtcservices/TmTcMessage.h"
#include <cstring>
TmPacketStoredPusC::TmPacketStoredPusC(store_address_t setAddress) :
TmPacketStoredBase(setAddress), TmPacketPusC(nullptr){
}
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize, uint16_t destinationId,
uint8_t timeRefField) :
TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + size + headerSize), &pData);
if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm();
return;
}
setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(
size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, SerializeIF *content,
SerializeIF *header, uint16_t destinationId, uint8_t timeRefField) :
TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != NULL) {
sourceDataSize += content->getSerializedSize();
}
if (header != NULL) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *p_data = NULL;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + sourceDataSize), &p_data);
if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm();
}
setData(p_data);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != NULL) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != NULL) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
uint8_t* TmPacketStoredPusC::getAllTmData() {
return getWholeData();
}
void TmPacketStoredPusC::setDataPointer(const uint8_t *newPointer) {
setData(newPointer);
}

View File

@ -0,0 +1,68 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
#include <fsfw/tmtcpacket/pus/TmPacketPusC.h>
#include <fsfw/tmtcpacket/pus/TmPacketStoredBase.h>
/**
* This class generates a ECSS PUS C Telemetry packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredPusC:
public TmPacketStoredBase,
public TmPacketPusC {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusC( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate
* data sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
* @param destinationId Destination ID containing the application process ID as specified
* by PUS C
* @param timeRefField 4 bit time reference field as specified by PUS C
*/
TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetCounter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0, uint16_t destinationId = 0, uint8_t timeRefField = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetCounter, SerializeIF* content,
SerializeIF* header = nullptr, uint16_t destinationId = 0, uint8_t timeRefField = 0);
uint8_t* getAllTmData() override;
void setDataPointer(const uint8_t* newPointer) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */

View File

@ -1,6 +1,7 @@
#include "AcceptsTelemetryIF.h"
#include "CommandingServiceBase.h"
#include "TmTcMessage.h"
#include <FSFWConfig.h>
#include "../tcdistribution/PUSDistributorIF.h"
#include "../objectmanager/ObjectManagerIF.h"
@ -293,8 +294,13 @@ void CommandingServiceBase::handleRequestQueue() {
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
const uint8_t* data, size_t dataLen, const uint8_t* headerData,
size_t headerSize) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize);
#else
TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, headerData, headerSize);
#endif
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
@ -311,8 +317,13 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
size_t size = 0;
SerializeAdapter::serialize(&objectId, &pBuffer, &size,
sizeof(object_id_t), SerializeIF::Endianness::BIG);
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, buffer, size);
#else
TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, data, dataLen, buffer, size);
#endif
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {
@ -324,8 +335,13 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice,
SerializeIF* content, SerializeIF* header) {
TmPacketStored tmPacketStored(this->apid, this->service, subservice,
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, content, header);
#else
TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice,
this->tmPacketCounter, content, header);
#endif
ReturnValue_t result = tmPacketStored.sendPacket(
requestQueue->getDefaultDestination(), requestQueue->getId());
if (result == HasReturnvaluesIF::RETURN_OK) {

View File

@ -21,7 +21,7 @@ TmTcMessage::TmTcMessage(store_address_t storeId) {
this->setStorageId(storeId);
}
size_t TmTcMessage::getMinimumMessageSize() {
size_t TmTcMessage::getMinimumMessageSize() const {
return this->HEADER_SIZE + sizeof(store_address_t);
}

View File

@ -18,7 +18,7 @@ protected:
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + @c sizeof(store_address_t).
*/
size_t getMinimumMessageSize();
size_t getMinimumMessageSize() const override;
public:
/**
* @brief In the default constructor, only the message_size is set.

View File

@ -0,0 +1,3 @@
target_sources(${TARGET_NAME} PRIVATE
PusTmTest.cpp
)

View File

@ -0,0 +1,3 @@

View File

@ -1,6 +1,6 @@
#include "CatchFactory.h"
#include <fsfw/datapoollocal/LocalDataPoolManager.h>
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include "CatchFactory.h"
#include <fsfw/events/EventManager.h>
#include <fsfw/health/HealthTable.h>
@ -74,7 +74,7 @@ void Factory::setStaticFrameworkObjectIds() {
DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT;
TmPacketStored::timeStamperId = objects::NO_OBJECT;
TmPacketBase::timeStamperId = objects::NO_OBJECT;
}