transmit enable and timeout
This commit is contained in:
@@ -1,24 +1,32 @@
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
#include "fsfw/serviceinterface/serviceInterfaceDefintions.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/events/EventManagerIF.h"
|
||||
|
||||
#include <linux/obc/PdecHandler.h>
|
||||
|
||||
#include "CCSDSHandler.h"
|
||||
|
||||
CCSDSHandler::CCSDSHandler(object_id_t objectId, object_id_t ptmeId, object_id_t tcDestination,
|
||||
TxRateSetterIF* txRateSetterIF) :
|
||||
TxRateSetterIF* txRateSetterIF, GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData) :
|
||||
SystemObject(objectId), ptmeId(ptmeId), tcDestination(tcDestination), parameterHelper(this), actionHelper(
|
||||
this, nullptr), txRateSetterIF(txRateSetterIF) {
|
||||
this, nullptr), txRateSetterIF(txRateSetterIF), gpioIF(gpioIF), enTxClock(
|
||||
enTxClock), enTxData(enTxData) {
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(QUEUE_SIZE);
|
||||
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 2);
|
||||
}
|
||||
|
||||
CCSDSHandler::~CCSDSHandler() {
|
||||
}
|
||||
|
||||
ReturnValue_t CCSDSHandler::performOperation(uint8_t operationCode) {
|
||||
checkEvents();
|
||||
readCommandQueue();
|
||||
handleTelemetry();
|
||||
handleTelecommands();
|
||||
checkTxTimer();
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
@@ -71,6 +79,27 @@ ReturnValue_t CCSDSHandler::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 RETURN_FAILED;
|
||||
}
|
||||
result = manager->registerListener(eventQueue->getId());
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
result = manager->subscribeToEventRange(eventQueue->getId(),
|
||||
event::getEventId(PdecHandler::CARRIER_LOCK), event::getEventId(PdecHandler::BIT_LOCK));
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "CCSDSHandler::initialize: Failed to subscribe to events from PDEC "
|
||||
"handler" << std::endl;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -157,13 +186,113 @@ ReturnValue_t CCSDSHandler::executeAction(ActionId_t actionId,
|
||||
MessageQueueId_t commandedBy, const uint8_t* data, size_t size) {
|
||||
|
||||
switch(actionId) {
|
||||
case SET_LOW_RATE:
|
||||
case SET_LOW_RATE: {
|
||||
txRateSetterIF->setRate(BitRates::RATE_400KHZ);
|
||||
return EXECUTION_FINISHED;
|
||||
case SET_HIGH_RATE:
|
||||
}
|
||||
case SET_HIGH_RATE: {
|
||||
txRateSetterIF->setRate(BitRates::RATE_2000KHZ);
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
case EN_TRANSMITTER: {
|
||||
enableTransmit();
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
case DIS_TRANSMITTER: {
|
||||
disableTransmit();
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
default:
|
||||
return COMMAND_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
void CCSDSHandler::checkEvents() {
|
||||
EventMessage event;
|
||||
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
|
||||
result == RETURN_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 CCSDSHandler::handleEvent(EventMessage* eventMessage) {
|
||||
Event event = eventMessage->getEvent();
|
||||
switch(event){
|
||||
case PdecHandler::BIT_LOCK: {
|
||||
handleBitLockEvent();
|
||||
break;
|
||||
}
|
||||
case PdecHandler::CARRIER_LOCK: {
|
||||
handleCarrierLockEvent();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "CCSDSHandler::handleEvent: Did not subscribe to this event"
|
||||
<< std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CCSDSHandler::handleBitLockEvent() {
|
||||
if(transmitterCountdown.isBusy()) {
|
||||
// Transmitter already enabled
|
||||
return;
|
||||
}
|
||||
enableTransmit();
|
||||
}
|
||||
|
||||
void CCSDSHandler::handleCarrierLockEvent() {
|
||||
if (!enableTxWhenCarrierLock) {
|
||||
return;
|
||||
}
|
||||
enableTransmit();
|
||||
}
|
||||
|
||||
void CCSDSHandler::forwardLinkstate() {
|
||||
VirtualChannelMapIter iter;
|
||||
for(iter = virtualChannelMap.begin(); iter != virtualChannelMap.end(); iter++) {
|
||||
iter->second->setLinkState(linkState);
|
||||
}
|
||||
}
|
||||
|
||||
void CCSDSHandler::enableTransmit() {
|
||||
if(transmitterCountdown.isBusy()) {
|
||||
// Transmitter already enabled
|
||||
return;
|
||||
}
|
||||
transmitterCountdown.setTimeout(TRANSMITTER_TIMEOUT);
|
||||
#if BOARD_TE0720 == 0
|
||||
gpioIF->pullLow(enTxClock);
|
||||
gpioIF->pullLow(enTxData);
|
||||
#endif /* BOARD_TE0720 == 0 */
|
||||
linkState = UP;
|
||||
// Set link state of all virtual channels to link up
|
||||
forwardLinkstate();
|
||||
}
|
||||
|
||||
void CCSDSHandler::checkTxTimer() {
|
||||
if(linkState == DOWN) {
|
||||
return;
|
||||
}
|
||||
if (transmitterCountdown.hasTimedOut()) {
|
||||
disableTransmit();
|
||||
}
|
||||
}
|
||||
|
||||
void CCSDSHandler::disableTransmit() {
|
||||
#if BOARD_TE0720 == 0
|
||||
gpioIF->pullHigh(enTxClock);
|
||||
gpioIF->pullHigh(enTxData);
|
||||
#endif /* BOARD_TE0720 == 0 */
|
||||
linkState = DOWN;
|
||||
forwardLinkstate();
|
||||
}
|
||||
|
@@ -10,7 +10,11 @@
|
||||
#include "fsfw/parameters/ParameterHelper.h"
|
||||
#include "fsfw/action/ActionHelper.h"
|
||||
#include "fsfw/action/HasActionsIF.h"
|
||||
#include "fsfw/timemanager/Countdown.h"
|
||||
#include "fsfw/events/EventMessage.h"
|
||||
#include "linux/obc/TxRateSetterIF.h"
|
||||
#include "fsfw_hal/common/gpio/gpioDefinitions.h"
|
||||
#include "fsfw_hal/common/gpio/GpioIF.h"
|
||||
#include "VirtualChannel.h"
|
||||
#include <unordered_map>
|
||||
|
||||
@@ -39,9 +43,12 @@ public:
|
||||
* @param tcDestination Object ID of object handling received TC space packets
|
||||
* @param txRateSetter Object providing the functionality to switch the input bitrate of
|
||||
* the S-Band transceiver.
|
||||
* @param gpioIF Required to enable TX data and TX clock RS485 transceiver chips.
|
||||
* @param enTxClock GPIO ID of RS485 tx clock enable
|
||||
* @param enTxData GPIO ID of RS485 tx data enable
|
||||
*/
|
||||
CCSDSHandler(object_id_t objectId, object_id_t ptmeId, object_id_t tcDestination,
|
||||
TxRateSetterIF* txRateSetterIF);
|
||||
TxRateSetterIF* txRateSetterIF, GpioIF* gpioIF, gpioId_t enTxClock, gpioId_t enTxData);
|
||||
|
||||
~CCSDSHandler();
|
||||
|
||||
@@ -76,10 +83,19 @@ private:
|
||||
|
||||
static const ActionId_t SET_LOW_RATE = 0;
|
||||
static const ActionId_t SET_HIGH_RATE = 1;
|
||||
static const ActionId_t EN_TRANSMITTER = 2;
|
||||
static const ActionId_t DIS_TRANSMITTER = 3;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Received action message with unknown action id
|
||||
static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xA0);
|
||||
|
||||
// syrlinks must not be transmitting more than 15 minutes (according to datasheet)
|
||||
// static const uint32_t TRANSMITTER_TIMEOUT = 900000; //900000 ms = 15 min
|
||||
static const uint32_t TRANSMITTER_TIMEOUT = 10000; //900000 ms = 15 min
|
||||
|
||||
static const bool UP = true;
|
||||
static const bool DOWN = false;
|
||||
|
||||
using VirtualChannelMap = std::unordered_map<VcId_t, VirtualChannel*>;
|
||||
using VirtualChannelMapIter = VirtualChannelMap::iterator;
|
||||
|
||||
@@ -91,6 +107,7 @@ private:
|
||||
object_id_t tcDestination;
|
||||
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
MessageQueueIF* eventQueue = nullptr;
|
||||
|
||||
ParameterHelper parameterHelper;
|
||||
|
||||
@@ -100,9 +117,48 @@ private:
|
||||
|
||||
TxRateSetterIF* txRateSetterIF = nullptr;
|
||||
|
||||
GpioIF* gpioIF = nullptr;
|
||||
gpioId_t enTxClock = gpio::NO_GPIO;
|
||||
gpioId_t enTxData = gpio::NO_GPIO;
|
||||
|
||||
// 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.
|
||||
*/
|
||||
void forwardLinkstate();
|
||||
|
||||
/**
|
||||
* @brief Starts transmit timer and enables transmitter.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
void disableTransmit();
|
||||
};
|
||||
|
||||
#endif /* CCSDSHANDLER_H_ */
|
||||
|
Reference in New Issue
Block a user