moved transmitter timer and event handling of carrier and bitlock to ComSubsystem
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
#include "CcsdsIpCoreHandler.h"
|
||||
|
||||
#include <fsfw/subsystem/helper.h>
|
||||
#include <linux/ipcore/PdecHandler.h>
|
||||
#include <linux/ipcore/PtmeConfig.h>
|
||||
#include <mission/config/comCfg.h>
|
||||
|
||||
#include "eive/definitions.h"
|
||||
#include "fsfw/events/EventManagerIF.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serialize/SerializeAdapter.h"
|
||||
@ -16,8 +14,7 @@
|
||||
|
||||
CcsdsIpCoreHandler::CcsdsIpCoreHandler(object_id_t objectId, object_id_t ptmeId,
|
||||
object_id_t tcDestination, PtmeConfig* ptmeConfig,
|
||||
GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData,
|
||||
uint32_t transmitterTimeout)
|
||||
GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData)
|
||||
: SystemObject(objectId),
|
||||
ptmeId(ptmeId),
|
||||
tcDestination(tcDestination),
|
||||
@ -27,8 +24,7 @@ CcsdsIpCoreHandler::CcsdsIpCoreHandler(object_id_t objectId, object_id_t ptmeId,
|
||||
ptmeConfig(ptmeConfig),
|
||||
gpioIF(gpioIF),
|
||||
enTxClock(enTxClock),
|
||||
enTxData(enTxData),
|
||||
transmitterTimeout(transmitterTimeout) {
|
||||
enTxData(enTxData) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(QUEUE_SIZE);
|
||||
auto mqArgs = MqArgs(objectId, static_cast<void*>(this));
|
||||
eventQueue =
|
||||
@ -38,11 +34,9 @@ CcsdsIpCoreHandler::CcsdsIpCoreHandler(object_id_t objectId, object_id_t ptmeId,
|
||||
CcsdsIpCoreHandler::~CcsdsIpCoreHandler() {}
|
||||
|
||||
ReturnValue_t CcsdsIpCoreHandler::performOperation(uint8_t operationCode) {
|
||||
checkEvents();
|
||||
readCommandQueue();
|
||||
handleTelemetry();
|
||||
handleTelecommands();
|
||||
checkTxTimer();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
@ -98,34 +92,6 @@ ReturnValue_t CcsdsIpCoreHandler::initialize() {
|
||||
iter->second->setPtmeObject(ptme);
|
||||
}
|
||||
|
||||
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
|
||||
if (manager == nullptr) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "CcsdsHandler::initialize: Invalid event manager" << std::endl;
|
||||
#endif
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
result = manager->registerListener(eventQueue->getId());
|
||||
if (result != returnvalue::OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::warning << "CcsdsHandler::initialize: Failed to register CCSDS handler as event "
|
||||
"listener"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
;
|
||||
}
|
||||
result = manager->subscribeToEventRange(eventQueue->getId(),
|
||||
event::getEventId(PdecHandler::CARRIER_LOCK),
|
||||
event::getEventId(PdecHandler::BIT_LOCK_PDEC));
|
||||
if (result != returnvalue::OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "CcsdsHandler::initialize: Failed to subscribe to events from PDEC "
|
||||
"handler"
|
||||
<< std::endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
result = ptmeConfig->initialize();
|
||||
if (result != returnvalue::OK) {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
@ -135,9 +101,6 @@ ReturnValue_t CcsdsIpCoreHandler::initialize() {
|
||||
return ObjectManagerIF::CHILD_INIT_FAILED;
|
||||
}
|
||||
|
||||
transmitterCountdown.setTimeout(transmitterTimeout);
|
||||
transmitterCountdown.timeOut();
|
||||
|
||||
#if OBSW_SYRLINKS_SIMULATED == 1
|
||||
// Update data on rising edge
|
||||
ptmeConfig->invertTxClock(false);
|
||||
@ -286,54 +249,6 @@ ReturnValue_t CcsdsIpCoreHandler::executeAction(ActionId_t actionId, MessageQueu
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::checkEvents() {
|
||||
EventMessage event;
|
||||
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == returnvalue::OK;
|
||||
result = eventQueue->receiveMessage(&event)) {
|
||||
switch (event.getMessageId()) {
|
||||
case EventMessage::EVENT_MESSAGE:
|
||||
handleEvent(&event);
|
||||
break;
|
||||
default:
|
||||
sif::debug << "CcsdsHandler::checkEvents: Did not subscribe to this event message"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::handleEvent(EventMessage* eventMessage) {
|
||||
Event event = eventMessage->getEvent();
|
||||
switch (event) {
|
||||
case PdecHandler::BIT_LOCK_PDEC: {
|
||||
handleBitLockEvent();
|
||||
break;
|
||||
}
|
||||
case PdecHandler::CARRIER_LOCK: {
|
||||
handleCarrierLockEvent();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "CcsdsHandler::handleEvent: Did not subscribe to this event" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::handleBitLockEvent() {
|
||||
if (transmitterCountdown.isBusy()) {
|
||||
// Transmitter already enabled
|
||||
return;
|
||||
}
|
||||
enableTransmit();
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::handleCarrierLockEvent() {
|
||||
if (!enableTxWhenCarrierLock) {
|
||||
return;
|
||||
}
|
||||
enableTransmit();
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::forwardLinkstate() {
|
||||
VirtualChannelMapIter iter;
|
||||
for (iter = virtualChannelMap.begin(); iter != virtualChannelMap.end(); iter++) {
|
||||
@ -342,27 +257,12 @@ void CcsdsIpCoreHandler::forwardLinkstate() {
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::enableTransmit() {
|
||||
if (transmitterCountdown.isBusy()) {
|
||||
// Transmitter already enabled
|
||||
return;
|
||||
}
|
||||
#ifndef TE0720_1CFA
|
||||
gpioIF->pullHigh(enTxClock);
|
||||
gpioIF->pullHigh(enTxData);
|
||||
#endif
|
||||
linkState = UP;
|
||||
forwardLinkstate();
|
||||
transmitterCountdown.resetTimer();
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::checkTxTimer() {
|
||||
if (linkState == DOWN) {
|
||||
return;
|
||||
}
|
||||
if (transmitterCountdown.hasTimedOut()) {
|
||||
disableTransmit();
|
||||
//TODO: set mode to off (move timer to subsystem)
|
||||
}
|
||||
}
|
||||
|
||||
void CcsdsIpCoreHandler::getMode(Mode_t* mode, Submode_t* submode) {
|
||||
@ -431,7 +331,6 @@ void CcsdsIpCoreHandler::disableTransmit() {
|
||||
#endif
|
||||
linkState = DOWN;
|
||||
forwardLinkstate();
|
||||
transmitterCountdown.timeOut();
|
||||
}
|
||||
|
||||
const char* CcsdsIpCoreHandler::getName() const { return "CCSDS Handler"; }
|
||||
|
@ -59,8 +59,7 @@ class CcsdsIpCoreHandler : public SystemObject,
|
||||
* @param enTxData GPIO ID of RS485 tx data enable
|
||||
*/
|
||||
CcsdsIpCoreHandler(object_id_t objectId, object_id_t ptmeId, object_id_t tcDestination,
|
||||
PtmeConfig* ptmeConfig, GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData,
|
||||
uint32_t transmitterTimeout = 900000);
|
||||
PtmeConfig* ptmeConfig, GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData);
|
||||
|
||||
~CcsdsIpCoreHandler();
|
||||
|
||||
@ -154,29 +153,16 @@ class CcsdsIpCoreHandler : public SystemObject,
|
||||
PtmeConfig* ptmeConfig = nullptr;
|
||||
|
||||
GpioIF* gpioIF = nullptr;
|
||||
// GPIO to enable RS485 transceiver for TX clock
|
||||
gpioId_t enTxClock = gpio::NO_GPIO;
|
||||
// GPIO to enable RS485 transceiver for TX data signal
|
||||
gpioId_t enTxData = gpio::NO_GPIO;
|
||||
|
||||
// Syrlinks must not be transmitting more than 15 minutes (according to datasheet)
|
||||
// Value initialized by constructor argument
|
||||
const uint32_t transmitterTimeout = 0;
|
||||
|
||||
// Countdown to disable transmitter after 15 minutes
|
||||
Countdown transmitterCountdown;
|
||||
|
||||
// When true transmitting is started as soon as carrier lock has been detected
|
||||
bool enableTxWhenCarrierLock = false;
|
||||
|
||||
bool linkState = DOWN;
|
||||
|
||||
void readCommandQueue(void);
|
||||
void handleTelemetry();
|
||||
void handleTelecommands();
|
||||
void checkEvents();
|
||||
void handleEvent(EventMessage* eventMessage);
|
||||
|
||||
void handleBitLockEvent();
|
||||
void handleCarrierLockEvent();
|
||||
|
||||
/**
|
||||
* @brief Forward link state to virtual channels.
|
||||
@ -188,12 +174,6 @@ class CcsdsIpCoreHandler : public SystemObject,
|
||||
*/
|
||||
void enableTransmit();
|
||||
|
||||
/**
|
||||
* @brief Checks Tx timer for timeout and disables RS485 tx clock and tx data in case
|
||||
* timer has expired.
|
||||
*/
|
||||
void checkTxTimer();
|
||||
|
||||
/**
|
||||
* @brief Disables the transmitter by pulling the enable tx clock and tx data pin of the
|
||||
* RS485 transceiver chips to high.
|
||||
|
Reference in New Issue
Block a user