comntinued scex handler

This commit is contained in:
Irini Kosmidou 2022-06-21 16:44:14 +02:00
parent 521b17a8f8
commit 005e548059
14 changed files with 82 additions and 77 deletions

View File

@ -81,26 +81,24 @@ void initmission::initTasks() {
#if OBSW_ADD_SCEX == 1
PeriodicTaskIF* scexDevHandler = factory->createPeriodicTask(
"SCEX_DEV", 35, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 0.5, missedDeadlineFunc);
result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION);
result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::PERFORM_OPERATION);
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("SCEX_DEV", objects::SCEX);
}
result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE);
result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_WRITE);
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("SCEX_DEV", objects::SCEX);
}
result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE);
result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_WRITE);
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("SCEX_DEV", objects::SCEX);
}
result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ);
result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::SEND_READ);
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("SCEX_DEV", objects::SCEX);
}
result = tmtcPollingTask->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ);
#endif
result = scexDevHandler->addComponent(objects::SCEX, DeviceHandlerIF::GET_READ);
#if OBSW_ADD_SCEX_READER == 1
result = HasReturnvaluesIF::RETURN_OK;
PeriodicTaskIF* scexReaderTask = factory->createPeriodicTask(
"SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
@ -108,10 +106,6 @@ void initmission::initTasks() {
if (result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER);
}
sif::info << "Starting tasks.." << std::endl;
tmTcDistributor->startTask();
tmtcBridgeTask->startTask();
tmtcPollingTask->startTask();
#endif
/* PUS Services */
@ -148,6 +142,7 @@ void initmission::initTasks() {
#if OBSW_ADD_SCEX == 1
scexDevHandler->startTask();
scexReaderTask->startTask();
#endif
#if OBSW_ADD_TEST_PST == 1
if (startTestPst) {
@ -235,9 +230,12 @@ void initmission::createPstTasks(TaskFactory& factory,
"SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc);
result = pst::pstSpi(spiPst);
if (result != HasReturnvaluesIF::RETURN_OK) {
if (result != FixedTimeslotTaskIF::SLOT_LIST_EMPTY) {
sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl;
}
} else {
taskVec.push_back(spiPst);
}
#endif
}

View File

@ -55,6 +55,7 @@ namespace uart {
static constexpr size_t HYPERION_GPS_REPLY_MAX_BUFFER = 1024;
static constexpr UartBaudRate SYRLINKS_BAUD = UartBaudRate::RATE_38400;
static constexpr UartBaudRate SCEX_BAUD = UartBaudRate::RATE_57600;
static constexpr UartBaudRate GNSS_BAUD = UartBaudRate::RATE_9600;
static constexpr UartBaudRate PLOC_MPSOC_BAUD = UartBaudRate::RATE_115200;
static constexpr UartBaudRate PLOC_SUPV_BAUD = UartBaudRate::RATE_115200;

2
fsfw

@ -1 +1 @@
Subproject commit ebbe08639caae43667829d2cc2bcbdf91260e175
Subproject commit 1910a7838c712f1cf34031d2a8b53e2f7cd24f66

View File

@ -6,6 +6,7 @@
#include <fsfw_hal/common/gpio/gpioDefinitions.h>
#include <fsfw_hal/linux/spi/SpiComIF.h>
#include <fsfw_hal/linux/spi/SpiCookie.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/callbacks/gpioCallbacks.h>
#include <linux/devices/Max31865RtdLowlevelHandler.h>
#include <mission/devices/Max31865EiveHandler.h>
@ -323,10 +324,11 @@ void ObjectFactory::createRtdComponents(std::string spiDev, GpioIF* gpioComIF,
void ObjectFactory::createScexComponents(std::string uartDev, PowerSwitchIF* pwrSwitcher) {
// objekte anlegen
SdCardMountedIF* sdcMan = nullptr;
CookieIF* cookie = new CookieIF;
auto* cookie = new UartCookie(objects::SCEX, uartDev, uart::SCEX_BAUD, 4096);
auto scexUartReader = new ScexUartReader(objects::SCEX_UART_READER);
new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, sdcMan);
auto scexHandler = new ScexDeviceHandler(objects::SCEX, *scexUartReader, cookie, sdcMan);
scexHandler->setStartUpImmediately();
}
void ObjectFactory::gpioChecker(ReturnValue_t result, std::string output) {

View File

@ -1,5 +1,4 @@
#ifndef LINUX_DEVICES_SCEXDLEPARSER_H_
#define LINUX_DEVICES_SCEXDLEPARSER_H_
#pragma once
#include <fsfw/globalfunctions/DleParser.h>
@ -16,5 +15,3 @@ class ScexDleParser : public DleParser {
private:
};
#endif /* LINUX_DEVICES_SCEXDLEPARSER_H_ */

View File

@ -7,7 +7,6 @@
#include <fsfw/tasks/SemaphoreFactory.h>
#include <fsfw/tasks/TaskFactory.h>
#include <fsfw_hal/linux/uart/UartCookie.h>
#include <linux/devices/ScexDleParser.h>
#include <unistd.h> // write(), read(), close()
#include <cerrno> // Error integer and strerror() function
@ -21,7 +20,7 @@ ScexUartReader::ScexUartReader(object_id_t objectId)
ipcRingBuf(200 * 2048, true),
ipcQueue(200),
dleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, this) {
{decodedBuf.data(), decodedBuf.size()}, &foundDlePacketHandler, (void *)this) {
semaphore = SemaphoreFactory::instance()->createBinarySemaphore();
semaphore->acquire();
lock = MutexFactory::instance()->createMutex();
@ -80,8 +79,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
/* Get file descriptor */
serialPort = open(devname.c_str(), O_RDWR);
if (serialPort < 0) {
sif::warning << "open call failed with error [" << errno << ", " << strerror(errno)
<< std::endl;
sif::warning << "ScexUartReader::initializeInterface: open call failed with error [" << errno
<< ", " << strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
// Setting up UART parameters
@ -107,8 +106,8 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
#endif
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
sif::warning << "tcsetattr call failed with error [" << errno << ", " << strerror(errno)
<< std::endl;
sif::warning << "ScexUartReader::initializeInterface: tcsetattr call failed with error ["
<< errno << ", " << strerror(errno) << std::endl;
}
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
@ -117,6 +116,9 @@ ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
size_t sendLen) {
if (sendData == nullptr or sendLen == 0) {
return HasReturnvaluesIF::RETURN_FAILED;
}
lock->lockMutex();
if (state == States::NOT_READY or state == States::RUNNING) {
lock->unlockMutex();
@ -128,17 +130,18 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
ReturnValue_t result =
dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "UartTestClass::scexInit: Encoding failed" << std::endl;
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
return RETURN_FAILED;
}
size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen);
if (bytesWritten != encodedLen) {
sif::warning << "Sending ping command to solar experiment failed" << std::endl;
sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed"
<< std::endl;
return RETURN_FAILED;
}
result = semaphore->release();
if (result != HasReturnvaluesIF::RETURN_OK) {
std::cout << "ScexUartReader::sendMessag: Releasing semaphore failed" << std::endl;
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
}
return RETURN_OK;
}
@ -160,12 +163,12 @@ ReturnValue_t ScexUartReader::finish() {
return RETURN_OK;
}
void ScexUartReader::foundDlePacketHandler(const DleParser::Context &ctx) {
void ScexUartReader::foundDlePacketHandler(const ScexDleParser::Context &ctx) {
ScexUartReader *obj = reinterpret_cast<ScexUartReader *>(ctx.userArgs);
if (ctx.getType() == DleParser::ContextType::PACKET_FOUND) {
if (ctx.getType() == ScexDleParser::ContextType::PACKET_FOUND) {
obj->handleFoundDlePacket(ctx.decodedPacket.first, ctx.decodedPacket.second);
} else {
DleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
ScexDleParser::defaultErrorHandler(ctx.error.first, ctx.error.second);
}
}
@ -175,11 +178,11 @@ void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
MutexGuard mg(lock);
ReturnValue_t result = ipcQueue.insert(len);
if (result != RETURN_OK) {
sif::warning << "IPCQueue error" << std::endl;
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCQueue error" << std::endl;
}
result = ipcRingBuf.writeData(packet, len);
if (result != RETURN_OK) {
sif::warning << "IPCRingBuf error" << std::endl;
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCRingBuf error" << std::endl;
}
// sif::info << "DLE handler done" << std::endl;
}

View File

@ -1,5 +1,4 @@
#ifndef LINUX_DEVICES_SCEXUARTREADER_H_
#define LINUX_DEVICES_SCEXUARTREADER_H_
#pragma once
#include <fsfw/container/DynamicFIFO.h>
#include <fsfw/container/SimpleRingBuffer.h>
@ -58,5 +57,3 @@ class ScexUartReader : public SystemObject, // strg+shift+n
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
};
#endif /* LINUX_DEVICES_SCEXUARTREADER_H_ */

View File

@ -21,3 +21,5 @@ target_sources(
PayloadPcduHandler.cpp
SolarArrayDeploymentHandler.cpp
ScexDeviceHandler.cpp)
add_subdirectory(devicedefinitions)

View File

@ -14,7 +14,7 @@ using std::ofstream;
ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie,
SdCardMountedIF* sdcMan)
: DeviceHandlerBase(objectId, reader.getObjectId(), cookie), reader(reader), sdcMan(sdcMan) {}
: DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) {}
ScexDeviceHandler::~ScexDeviceHandler() {}
@ -42,48 +42,52 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
if (std::find(VALID_CMDS.begin(), VALID_CMDS.end(), deviceCommand) == VALID_CMDS.end()) {
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
if (commandDataLen < 1) {
return DeviceHandlerIF::INVALID_COMMAND_PARAMETER;
bool tempCheck = false;
if (commandDataLen == 1) {
tempCheck = commandData[0];
}
switch (deviceCommand) {
case (PING): {
// rawPacket = cmdBuf.data();
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
tempCheck);
break;
}
case (EXP_STATUS_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
tempCheck);
break;
}
case (ION_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
tempCheck);
break;
}
case (TEMP_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, {nullptr, 0},
tempCheck);
break;
}
case (FRAM): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1}, tempCheck);
break;
}
case (ONE_CELL): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1}, tempCheck);
break;
}
case (ALL_CELLS_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1});
return RETURN_OK;
prepareScexCmd(cmdTyped, {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1}, tempCheck);
break;
}
default: {
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
}
rawPacket = cmdBuf.data();
return RETURN_OK;
}

View File

@ -9,7 +9,6 @@ class SdCardMountedIF;
class ScexDeviceHandler : public DeviceHandlerBase {
public:
// ctor vervollständigen
ScexDeviceHandler(object_id_t objectId, ScexUartReader &reader, CookieIF *cookie,
SdCardMountedIF *sdcMan);
virtual ~ScexDeviceHandler();

View File

@ -8,8 +8,8 @@ uint8_t scex::createCmdByte(Cmds cmd, bool tempCheck) {
return (IDLE_BIT_0_DEF_STATE << 7) | (IDLE_BIT_1_DEF_STATE << 6) | (cmd << 1) | tempCheck;
}
ReturnValue_t scex::prepareScexCmd(Cmds cmd, bool tempCheck, std::pair<uint8_t*, size_t> cmdBufPair,
size_t& cmdLen, std::pair<const uint8_t*, size_t> usrDataPair) {
ReturnValue_t scex::prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
std::pair<const uint8_t*, size_t> usrDataPair, bool tempCheck) {
using namespace scex;
uint8_t* cmdBuf = cmdBufPair.first;
const uint8_t* userData = usrDataPair.first;

View File

@ -38,10 +38,10 @@ static constexpr uint8_t CRC_LEN = 2;
static constexpr uint8_t IDLE_BIT_0_DEF_STATE = 0;
static constexpr uint8_t IDLE_BIT_1_DEF_STATE = 1;
uint8_t createCmdByte(Cmds cmd, bool tempCheck);
uint8_t createCmdByte(Cmds cmd, bool tempCheck = false);
ReturnValue_t prepareScexCmd(Cmds cmd, bool tempCheck, std::pair<uint8_t*, size_t> cmdBufPair,
size_t& cmdLen, std::pair<const uint8_t*, size_t> usrDataPair);
ReturnValue_t prepareScexCmd(Cmds cmd, std::pair<uint8_t*, size_t> cmdBufPair, size_t& cmdLen,
std::pair<const uint8_t*, size_t> usrDataPair, bool tempCheck = false);
} // namespace scex

View File

@ -1,8 +1,10 @@
#!/bin/bash
echo "-L 1538:raspberrypi.local:1538 for Raspberry Pi connect with TCF agent"
echo "-L 1539:raspberrypi.local:22 for Raspberry Pi file transfers"
echo "-L 7301:raspberrypi.local:7301 for Raspberry Pi TMTC Commands"
ssh -L 1538:raspberrypi.local:1534 \
-L 1539:raspberrypi.local:22 \
-L 7301:raspberrypi.local:7301 \
eive@2001:7c0:2018:1099:babe:0:e1fe:f1a5 \
-t 'CONSOLE_PREFIX="[RPi Tunnel]" /bin/bash'

2
tmtc

@ -1 +1 @@
Subproject commit ef349856d614be7a408ffadf0c27c677d8be3157
Subproject commit 7012a6c41f6e211c060f583c21061fe7ca3f4c45