2022-02-25 11:58:02 +01:00
|
|
|
#include "ComSubsystem.h"
|
2022-04-14 09:54:07 +02:00
|
|
|
|
2023-03-15 17:13:25 +01:00
|
|
|
#include <fsfw/events/Event.h>
|
2023-02-02 15:33:04 +01:00
|
|
|
#include <fsfw/events/EventManagerIF.h>
|
2023-01-27 18:38:36 +01:00
|
|
|
#include <fsfw/ipc/MutexGuard.h>
|
2023-02-02 15:33:04 +01:00
|
|
|
#include <fsfw/ipc/QueueFactory.h>
|
|
|
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
|
|
|
#include <linux/ipcore/PdecHandler.h>
|
2023-02-22 13:02:40 +01:00
|
|
|
#include <mission/comDefs.h>
|
2023-02-02 15:33:04 +01:00
|
|
|
#include <mission/config/comCfg.h>
|
2023-03-15 17:13:25 +01:00
|
|
|
#include <mission/controller/controllerdefinitions/tcsCtrlDefs.h>
|
2023-01-27 18:38:36 +01:00
|
|
|
|
2023-02-22 13:02:40 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2022-09-29 19:40:00 +02:00
|
|
|
ComSubsystem::ComSubsystem(object_id_t setObjectId, uint32_t maxNumberOfSequences,
|
2023-02-02 15:33:04 +01:00
|
|
|
uint32_t maxNumberOfTables, uint32_t transmitterTimeout)
|
2023-01-27 18:38:36 +01:00
|
|
|
: Subsystem(setObjectId, maxNumberOfSequences, maxNumberOfTables), paramHelper(this) {
|
|
|
|
com::setCurrentDatarate(com::Datarate::LOW_RATE_MODULATION_BPSK);
|
2023-02-02 15:33:04 +01:00
|
|
|
auto mqArgs = MqArgs(setObjectId, static_cast<void *>(this));
|
|
|
|
eventQueue =
|
|
|
|
QueueFactory::instance()->createMessageQueue(10, EventMessage::EVENT_MESSAGE_SIZE, &mqArgs);
|
|
|
|
transmitterCountdown.setTimeout(transmitterTimeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComSubsystem::performChildOperation() {
|
|
|
|
readEventQueue();
|
2023-03-16 18:05:23 +01:00
|
|
|
if (performRecoveryToRxOnly and not isInTransition) {
|
|
|
|
startRxOnlyRecovery(true);
|
|
|
|
// To avoid immediately enabling TX after falling back.
|
|
|
|
rememberBitLock = false;
|
|
|
|
}
|
2023-02-22 13:02:40 +01:00
|
|
|
// Execute default rate sequence after transition has been completed
|
|
|
|
if (rememberBitLock and not isInTransition) {
|
|
|
|
startRxAndTxLowRateSeq();
|
|
|
|
rememberBitLock = false;
|
|
|
|
}
|
2023-02-22 09:53:09 +01:00
|
|
|
if (countdownActive) {
|
2023-02-22 13:02:40 +01:00
|
|
|
checkTransmitterCountdown();
|
2023-02-16 13:40:15 +01:00
|
|
|
}
|
2023-03-01 18:06:36 +01:00
|
|
|
|
2023-02-22 09:53:09 +01:00
|
|
|
Subsystem::performChildOperation();
|
2023-01-27 18:38:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t ComSubsystem::getCommandQueue() const { return Subsystem::getCommandQueue(); }
|
|
|
|
|
|
|
|
ReturnValue_t ComSubsystem::getParameter(uint8_t domainId, uint8_t uniqueIdentifier,
|
|
|
|
ParameterWrapper *parameterWrapper,
|
|
|
|
const ParameterWrapper *newValues, uint16_t startAtIndex) {
|
|
|
|
if ((domainId == 0) and (uniqueIdentifier == static_cast<uint8_t>(com::ParameterId::DATARATE))) {
|
|
|
|
uint8_t newVal = 0;
|
|
|
|
ReturnValue_t result = newValues->getElement(&newVal);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (newVal >= static_cast<uint8_t>(com::Datarate::NUM_DATARATES)) {
|
|
|
|
return HasParametersIF::INVALID_VALUE;
|
|
|
|
}
|
|
|
|
parameterWrapper->set(datarateCfg);
|
|
|
|
com::setCurrentDatarate(static_cast<com::Datarate>(newVal));
|
|
|
|
return returnvalue::OK;
|
2023-02-22 13:02:40 +01:00
|
|
|
} else if ((domainId == 0) and
|
|
|
|
(uniqueIdentifier == static_cast<uint8_t>(com::ParameterId::TRANSMITTER_TIMEOUT))) {
|
|
|
|
uint32_t newVal = 0;
|
|
|
|
ReturnValue_t result = newValues->getElement(&newVal);
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
parameterWrapper->set(transmitterTimeout);
|
|
|
|
transmitterTimeout = newVal;
|
|
|
|
transmitterCountdown.setTimeout(transmitterTimeout);
|
|
|
|
return returnvalue::OK;
|
2023-02-02 16:00:53 +01:00
|
|
|
}
|
2023-01-27 18:38:36 +01:00
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
2023-01-28 14:49:28 +01:00
|
|
|
|
|
|
|
ReturnValue_t ComSubsystem::handleCommandMessage(CommandMessage *message) {
|
|
|
|
ReturnValue_t result = paramHelper.handleParameterMessage(message);
|
|
|
|
if (result == returnvalue::OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return Subsystem::handleCommandMessage(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t ComSubsystem::initialize() {
|
|
|
|
ReturnValue_t result = paramHelper.initialize();
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2023-02-22 13:02:40 +01:00
|
|
|
EventManagerIF *manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
|
|
|
if (manager == nullptr) {
|
2023-02-02 15:33:04 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2023-02-22 13:02:40 +01:00
|
|
|
sif::error << "ComSubsystem::initialize: Invalid event manager" << std::endl;
|
2023-02-02 15:33:04 +01:00
|
|
|
#endif
|
2023-02-22 13:02:40 +01:00
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
|
|
|
}
|
|
|
|
result = manager->registerListener(eventQueue->getId());
|
|
|
|
if (result != returnvalue::OK) {
|
2023-02-02 15:33:04 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2023-02-22 13:02:40 +01:00
|
|
|
sif::warning << "ComSubsystem::initialize: Failed to register Com Subsystem as event "
|
|
|
|
"listener"
|
|
|
|
<< std::endl;
|
2023-02-02 15:33:04 +01:00
|
|
|
#endif
|
2023-03-15 17:13:25 +01:00
|
|
|
}
|
|
|
|
result = manager->subscribeToEvent(eventQueue->getId(),
|
|
|
|
event::getEventId(tcsCtrl::SYRLINKS_OVERHEATING));
|
|
|
|
if (result != returnvalue::OK) {
|
|
|
|
return ObjectManager::CHILD_INIT_FAILED;
|
2023-02-22 13:02:40 +01:00
|
|
|
}
|
|
|
|
result = manager->subscribeToEventRange(eventQueue->getId(),
|
|
|
|
event::getEventId(PdecHandler::CARRIER_LOCK),
|
|
|
|
event::getEventId(PdecHandler::BIT_LOCK_PDEC));
|
|
|
|
if (result != returnvalue::OK) {
|
2023-02-02 15:33:04 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2023-02-22 13:02:40 +01:00
|
|
|
sif::error << "ComSubsystem::initialize: Failed to subscribe to events from PDEC "
|
|
|
|
"handler"
|
|
|
|
<< std::endl;
|
2023-02-02 15:33:04 +01:00
|
|
|
#endif
|
2023-02-22 13:02:40 +01:00
|
|
|
return result;
|
|
|
|
}
|
2023-01-28 14:49:28 +01:00
|
|
|
return Subsystem::initialize();
|
|
|
|
}
|
2023-02-02 15:33:04 +01:00
|
|
|
|
|
|
|
void ComSubsystem::startTransition(Mode_t mode, Submode_t submode) {
|
2023-02-16 13:40:15 +01:00
|
|
|
// Depending on the submode the transmitter timeout is enabled or
|
2023-02-02 15:33:04 +01:00
|
|
|
// disabled here
|
2023-02-22 13:02:40 +01:00
|
|
|
if (mode == com::Submode::RX_ONLY) {
|
2023-02-02 15:33:04 +01:00
|
|
|
transmitterCountdown.timeOut();
|
2023-02-22 09:53:09 +01:00
|
|
|
countdownActive = false;
|
2023-02-22 13:02:40 +01:00
|
|
|
} else if (isTxMode(mode)) {
|
2023-02-22 19:45:41 +01:00
|
|
|
// Only start transmitter countdown if transmitter is not already on
|
|
|
|
if (not isTxMode(this->mode)) {
|
|
|
|
transmitterCountdown.resetTimer();
|
|
|
|
countdownActive = true;
|
|
|
|
}
|
2023-02-02 15:33:04 +01:00
|
|
|
}
|
|
|
|
Subsystem::startTransition(mode, submode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComSubsystem::readEventQueue() {
|
|
|
|
EventMessage event;
|
|
|
|
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == returnvalue::OK;
|
|
|
|
result = eventQueue->receiveMessage(&event)) {
|
|
|
|
switch (event.getMessageId()) {
|
|
|
|
case EventMessage::EVENT_MESSAGE:
|
|
|
|
handleEventMessage(&event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sif::debug << "CcsdsHandler::checkEvents: Did not subscribe to this event message"
|
|
|
|
<< std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComSubsystem::handleEventMessage(EventMessage *eventMessage) {
|
|
|
|
Event event = eventMessage->getEvent();
|
|
|
|
switch (event) {
|
2023-03-15 17:13:25 +01:00
|
|
|
case tcsCtrl::SYRLINKS_OVERHEATING: {
|
2023-03-16 18:05:23 +01:00
|
|
|
// This event overrides the bit lock.
|
|
|
|
rememberBitLock = false;
|
|
|
|
if (mode == com::RX_ONLY) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isInTransition) {
|
|
|
|
performRecoveryToRxOnly = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
startRxOnlyRecovery(true);
|
2023-03-15 17:13:25 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-02-02 15:33:04 +01:00
|
|
|
case PdecHandler::BIT_LOCK_PDEC: {
|
|
|
|
handleBitLockEvent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PdecHandler::CARRIER_LOCK: {
|
|
|
|
handleCarrierLockEvent();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
sif::debug << "ComSubsystem::handleEvent: Did not subscribe to this event" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-22 13:02:40 +01:00
|
|
|
void ComSubsystem::handleBitLockEvent() {
|
|
|
|
if (isTxMode(mode)) {
|
|
|
|
// Tx already on
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isInTransition) {
|
|
|
|
rememberBitLock = true;
|
|
|
|
return;
|
|
|
|
}
|
2023-02-27 07:49:09 +01:00
|
|
|
triggerEvent(BIT_LOCK_TX_ON);
|
2023-02-22 13:02:40 +01:00
|
|
|
startRxAndTxLowRateSeq();
|
|
|
|
}
|
2023-02-02 15:33:04 +01:00
|
|
|
|
|
|
|
void ComSubsystem::handleCarrierLockEvent() {
|
|
|
|
if (!enableTxWhenCarrierLock) {
|
|
|
|
return;
|
|
|
|
}
|
2023-02-22 13:02:40 +01:00
|
|
|
startRxAndTxLowRateSeq();
|
2023-02-02 15:33:04 +01:00
|
|
|
}
|
|
|
|
|
2023-02-22 13:02:40 +01:00
|
|
|
void ComSubsystem::startRxAndTxLowRateSeq() {
|
2023-02-02 15:33:04 +01:00
|
|
|
// Turns transmitter on
|
2023-02-22 13:02:40 +01:00
|
|
|
startTransition(com::Submode::RX_AND_TX_LOW_DATARATE, SUBMODE_NONE);
|
2023-02-02 15:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComSubsystem::checkTransmitterCountdown() {
|
|
|
|
if (transmitterCountdown.hasTimedOut()) {
|
2023-03-01 18:06:36 +01:00
|
|
|
triggerEvent(TX_TIMER_EXPIRED, transmitterTimeout);
|
2023-02-22 13:02:40 +01:00
|
|
|
startTransition(com::Submode::RX_ONLY, SUBMODE_NONE);
|
2023-02-22 09:53:09 +01:00
|
|
|
countdownActive = false;
|
2023-02-02 15:33:04 +01:00
|
|
|
}
|
|
|
|
}
|
2023-02-22 13:02:40 +01:00
|
|
|
|
2023-03-16 18:05:23 +01:00
|
|
|
void ComSubsystem::startRxOnlyRecovery(bool forced) {
|
|
|
|
modeHelper.setForced(forced);
|
|
|
|
startTransition(com::RX_ONLY, 0);
|
|
|
|
performRecoveryToRxOnly = false;
|
|
|
|
}
|
|
|
|
|
2023-02-22 13:02:40 +01:00
|
|
|
bool ComSubsystem::isTxMode(Mode_t mode) {
|
2023-02-22 19:45:41 +01:00
|
|
|
if ((mode == com::Submode::RX_AND_TX_DEFAULT_DATARATE) ||
|
|
|
|
(mode == com::Submode::RX_AND_TX_LOW_DATARATE) ||
|
|
|
|
(mode == com::Submode::RX_AND_TX_HIGH_DATARATE)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2023-02-22 13:02:40 +01:00
|
|
|
}
|