clean up op done
This commit is contained in:
10
linux/payload/CMakeLists.txt
Normal file
10
linux/payload/CMakeLists.txt
Normal file
@ -0,0 +1,10 @@
|
||||
target_sources(
|
||||
${OBSW_NAME}
|
||||
PUBLIC PlocMemoryDumper.cpp
|
||||
PlocMpsocHandler.cpp
|
||||
PlocMpsocHelper.cpp
|
||||
PlocSupervisorHandler.cpp
|
||||
PlocSupvUartMan.cpp
|
||||
ScexDleParser.cpp
|
||||
ScexHelper.cpp
|
||||
ScexUartReader.cpp)
|
195
linux/payload/PlocMemoryDumper.cpp
Normal file
195
linux/payload/PlocMemoryDumper.cpp
Normal file
@ -0,0 +1,195 @@
|
||||
#include <fsfw/src/fsfw/serialize/SerializeAdapter.h>
|
||||
#include <linux/payload/PlocMemoryDumper.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
|
||||
PlocMemoryDumper::PlocMemoryDumper(object_id_t objectId)
|
||||
: SystemObject(objectId), commandActionHelper(this), actionHelper(this, nullptr) {
|
||||
auto mqArgs = MqArgs(this->getObjectId());
|
||||
commandQueue = QueueFactory::instance()->createMessageQueue(
|
||||
QUEUE_SIZE, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
}
|
||||
|
||||
PlocMemoryDumper::~PlocMemoryDumper() {}
|
||||
|
||||
ReturnValue_t PlocMemoryDumper::initialize() {
|
||||
ReturnValue_t result = SystemObject::initialize();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = commandActionHelper.initialize();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = actionHelper.initialize(commandQueue);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMemoryDumper::performOperation(uint8_t operationCode) {
|
||||
readCommandQueue();
|
||||
doStateMachine();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMemoryDumper::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) {
|
||||
if (state != State::IDLE) {
|
||||
return IS_BUSY;
|
||||
}
|
||||
|
||||
switch (actionId) {
|
||||
case DUMP_MRAM: {
|
||||
size_t deserializeSize = sizeof(mram.startAddress) + sizeof(mram.endAddress);
|
||||
SerializeAdapter::deSerialize(&mram.startAddress, &data, &deserializeSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
SerializeAdapter::deSerialize(&mram.endAddress, &data, &deserializeSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (mram.endAddress > MAX_MRAM_ADDRESS) {
|
||||
return MRAM_ADDRESS_TOO_HIGH;
|
||||
}
|
||||
if (mram.endAddress <= mram.startAddress) {
|
||||
return MRAM_INVALID_ADDRESS_COMBINATION;
|
||||
}
|
||||
state = State::COMMAND_FIRST_MRAM_DUMP;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
sif::warning << "PlocMemoryDumper::executeAction: Received command with invalid action id"
|
||||
<< std::endl;
|
||||
return INVALID_ACTION_ID;
|
||||
}
|
||||
}
|
||||
|
||||
return EXECUTION_FINISHED;
|
||||
}
|
||||
|
||||
MessageQueueId_t PlocMemoryDumper::getCommandQueue() const { return commandQueue->getId(); }
|
||||
|
||||
MessageQueueIF* PlocMemoryDumper::getCommandQueuePtr() { return commandQueue; }
|
||||
|
||||
void PlocMemoryDumper::readCommandQueue() {
|
||||
CommandMessage message;
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
|
||||
for (result = commandQueue->receiveMessage(&message); result == returnvalue::OK;
|
||||
result = commandQueue->receiveMessage(&message)) {
|
||||
if (result != returnvalue::OK) {
|
||||
continue;
|
||||
}
|
||||
result = actionHelper.handleActionMessage(&message);
|
||||
if (result == returnvalue::OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result = commandActionHelper.handleReply(&message);
|
||||
if (result == returnvalue::OK) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sif::debug << "PlocMemoryDumper::readCommandQueue: Received message with invalid format"
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void PlocMemoryDumper::doStateMachine() {
|
||||
switch (state) {
|
||||
case State::IDLE:
|
||||
break;
|
||||
case State::COMMAND_FIRST_MRAM_DUMP:
|
||||
commandNextMramDump(supv::FIRST_MRAM_DUMP);
|
||||
break;
|
||||
case State::COMMAND_CONSECUTIVE_MRAM_DUMP:
|
||||
commandNextMramDump(supv::CONSECUTIVE_MRAM_DUMP);
|
||||
break;
|
||||
case State::EXECUTING_MRAM_DUMP:
|
||||
break;
|
||||
default:
|
||||
sif::debug << "PlocMemoryDumper::doStateMachine: Invalid state" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PlocMemoryDumper::stepSuccessfulReceived(ActionId_t actionId, uint8_t step) {}
|
||||
|
||||
void PlocMemoryDumper::stepFailedReceived(ActionId_t actionId, uint8_t step,
|
||||
ReturnValue_t returnCode) {
|
||||
triggerEvent(MRAM_DUMP_FAILED);
|
||||
state = State::IDLE;
|
||||
}
|
||||
|
||||
void PlocMemoryDumper::dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) {}
|
||||
|
||||
void PlocMemoryDumper::completionSuccessfulReceived(ActionId_t actionId) {
|
||||
switch (pendingCommand) {
|
||||
case (supv::FIRST_MRAM_DUMP):
|
||||
case (supv::CONSECUTIVE_MRAM_DUMP):
|
||||
if (mram.endAddress == mram.startAddress) {
|
||||
triggerEvent(MRAM_DUMP_FINISHED);
|
||||
state = State::IDLE;
|
||||
} else {
|
||||
state = State::COMMAND_CONSECUTIVE_MRAM_DUMP;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sif::debug << "PlocMemoryDumper::completionSuccessfulReceived: Invalid pending command"
|
||||
<< std::endl;
|
||||
state = State::IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PlocMemoryDumper::completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) {
|
||||
switch (pendingCommand) {
|
||||
case (supv::FIRST_MRAM_DUMP):
|
||||
case (supv::CONSECUTIVE_MRAM_DUMP):
|
||||
triggerEvent(MRAM_DUMP_FAILED, mram.lastStartAddress);
|
||||
pendingCommand = NONE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = State::IDLE;
|
||||
}
|
||||
|
||||
void PlocMemoryDumper::commandNextMramDump(ActionId_t dumpCommand) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
|
||||
uint32_t tempStartAddress = 0;
|
||||
uint32_t tempEndAddress = 0;
|
||||
|
||||
if (mram.endAddress - mram.startAddress > MAX_MRAM_DUMP_SIZE) {
|
||||
tempStartAddress = mram.startAddress;
|
||||
tempEndAddress = mram.startAddress + MAX_MRAM_DUMP_SIZE;
|
||||
mram.startAddress += MAX_MRAM_DUMP_SIZE;
|
||||
} else {
|
||||
tempStartAddress = mram.startAddress;
|
||||
tempEndAddress = mram.endAddress;
|
||||
mram.startAddress = mram.endAddress;
|
||||
}
|
||||
mram.lastStartAddress = tempStartAddress;
|
||||
|
||||
MemoryParams params(tempStartAddress, tempEndAddress);
|
||||
|
||||
result =
|
||||
commandActionHelper.commandAction(objects::PLOC_SUPERVISOR_HANDLER, dumpCommand, ¶ms);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "PlocMemoryDumper::commandNextMramDump: Failed to send mram dump command "
|
||||
<< "with start address " << tempStartAddress << " and end address "
|
||||
<< tempEndAddress << std::endl;
|
||||
triggerEvent(SEND_MRAM_DUMP_FAILED, result, tempStartAddress);
|
||||
state = State::IDLE;
|
||||
pendingCommand = NONE;
|
||||
return;
|
||||
}
|
||||
state = State::EXECUTING_MRAM_DUMP;
|
||||
pendingCommand = dumpCommand;
|
||||
return;
|
||||
}
|
117
linux/payload/PlocMemoryDumper.h
Normal file
117
linux/payload/PlocMemoryDumper.h
Normal file
@ -0,0 +1,117 @@
|
||||
#ifndef MISSION_DEVICES_PLOCMEMORYDUMPER_H_
|
||||
#define MISSION_DEVICES_PLOCMEMORYDUMPER_H_
|
||||
|
||||
#include <linux/payload/plocMemDumpDefs.h>
|
||||
#include <linux/payload/plocSupvDefs.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/SdCardManager.h"
|
||||
#endif
|
||||
|
||||
#include "eive/eventSubsystemIds.h"
|
||||
#include "fsfw/action/ActionHelper.h"
|
||||
#include "fsfw/action/CommandActionHelper.h"
|
||||
#include "fsfw/action/CommandsActionsIF.h"
|
||||
#include "fsfw/action/HasActionsIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "objects/systemObjectList.h"
|
||||
|
||||
/**
|
||||
* @brief Because the buffer of the linux tty driver is limited to 2 x 65535 bytes, this class is
|
||||
* created to perform large dumps of PLOC memories.
|
||||
*
|
||||
* @details Currently the PLOC supervisor only implements the functionality to dump the MRAM.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class PlocMemoryDumper : public SystemObject,
|
||||
public HasActionsIF,
|
||||
public ExecutableObjectIF,
|
||||
public CommandsActionsIF {
|
||||
public:
|
||||
static const ActionId_t NONE = 0;
|
||||
static const ActionId_t DUMP_MRAM = 1;
|
||||
|
||||
PlocMemoryDumper(object_id_t objectId);
|
||||
virtual ~PlocMemoryDumper();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size);
|
||||
MessageQueueId_t getCommandQueue() const;
|
||||
ReturnValue_t initialize() override;
|
||||
MessageQueueIF* getCommandQueuePtr() override;
|
||||
void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override;
|
||||
void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override;
|
||||
void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override;
|
||||
void completionSuccessfulReceived(ActionId_t actionId) override;
|
||||
void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override;
|
||||
|
||||
private:
|
||||
static const uint32_t QUEUE_SIZE = 10;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MEMORY_DUMPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] The capacity of the MRAM amounts to 512 kB. Thus the maximum address must
|
||||
//! not be higher than 0x7d000.
|
||||
static const ReturnValue_t MRAM_ADDRESS_TOO_HIGH = MAKE_RETURN_CODE(0xA0);
|
||||
//! [EXPORT] : [COMMENT] The specified end address is lower than the start address
|
||||
static const ReturnValue_t MRAM_INVALID_ADDRESS_COMBINATION = MAKE_RETURN_CODE(0xA1);
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MEMORY_DUMPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Failed to send mram dump command to supervisor handler
|
||||
//! P1: Return value of commandAction function
|
||||
//! P2: Start address of MRAM to dump with this command
|
||||
static const Event SEND_MRAM_DUMP_FAILED = MAKE_EVENT(0, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Received completion failure report form PLOC supervisor handler
|
||||
//! P1: MRAM start address of failing dump command
|
||||
static const Event MRAM_DUMP_FAILED = MAKE_EVENT(1, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] MRAM dump finished successfully
|
||||
static const Event MRAM_DUMP_FINISHED = MAKE_EVENT(2, severity::LOW);
|
||||
|
||||
// Maximum size of mram dump which can be retrieved with one command
|
||||
static const uint32_t MAX_MRAM_DUMP_SIZE = 100000;
|
||||
static const uint32_t MAX_MRAM_ADDRESS = 0x7d000;
|
||||
|
||||
MessageQueueIF* commandQueue = nullptr;
|
||||
|
||||
CommandActionHelper commandActionHelper;
|
||||
|
||||
ActionHelper actionHelper;
|
||||
|
||||
enum class State : uint8_t {
|
||||
IDLE,
|
||||
COMMAND_FIRST_MRAM_DUMP,
|
||||
COMMAND_CONSECUTIVE_MRAM_DUMP,
|
||||
EXECUTING_MRAM_DUMP
|
||||
};
|
||||
|
||||
State state = State::IDLE;
|
||||
|
||||
ActionId_t pendingCommand = NONE;
|
||||
|
||||
typedef struct MemoryInfo {
|
||||
// Stores the start address of the next memory range to dump
|
||||
uint32_t startAddress;
|
||||
uint32_t endAddress;
|
||||
// Stores the start address of the last sent dump command
|
||||
uint32_t lastStartAddress;
|
||||
} MemoryInfo_t;
|
||||
|
||||
MemoryInfo_t mram = {0, 0, 0};
|
||||
|
||||
void readCommandQueue();
|
||||
void doStateMachine();
|
||||
|
||||
/**
|
||||
* @brief Sends the next mram dump command to the PLOC supervisor handler.
|
||||
*/
|
||||
void commandNextMramDump(ActionId_t dumpCommand);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_PLOCMEMORYDUMPER_H_ */
|
1196
linux/payload/PlocMpsocHandler.cpp
Normal file
1196
linux/payload/PlocMpsocHandler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
269
linux/payload/PlocMpsocHandler.h
Normal file
269
linux/payload/PlocMpsocHandler.h
Normal file
@ -0,0 +1,269 @@
|
||||
#ifndef BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
|
||||
#define BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_
|
||||
|
||||
#include <linux/payload/PlocMpsocHelper.h>
|
||||
#include <linux/payload/mpsocRetvals.h>
|
||||
#include <linux/payload/plocMpscoDefs.h>
|
||||
#include <linux/payload/plocSupvDefs.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fsfw/action/CommandActionHelper.h"
|
||||
#include "fsfw/action/CommandsActionsIF.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/tmtcservices/SourceSequenceCounter.h"
|
||||
#include "fsfw_hal/linux/gpio/Gpio.h"
|
||||
#include "fsfw_hal/linux/serial/SerialComIF.h"
|
||||
|
||||
/**
|
||||
* @brief This is the device handler for the MPSoC of the payload computer.
|
||||
*
|
||||
* @details The PLOC uses the space packet protocol for communication. Each command will be
|
||||
* answered with at least one acknowledgment and one execution report.
|
||||
* Flight manual:
|
||||
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/PLOC_MPSoC ICD:
|
||||
* https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_TAS-ILH-IRS/ICD-PLOC/ILH&fileid=1030263
|
||||
*
|
||||
* @note The sequence count in the space packets must be incremented with each received and sent
|
||||
* packet otherwise the MPSoC will reply with an acknowledgment failure report.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class PlocMPSoCHandler : public DeviceHandlerBase, public CommandsActionsIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param ojectId Object ID of the MPSoC handler
|
||||
* @param uartcomIFid Object ID of the UART communication interface
|
||||
* @param comCookie UART communication cookie
|
||||
* @param plocMPSoCHelper Pointer to MPSoC helper object
|
||||
* @param uartIsolatorSwitch Gpio object representing the GPIO connected to the UART isolator
|
||||
* module in the programmable logic
|
||||
* @param supervisorHandler Object ID of the supervisor handler
|
||||
*/
|
||||
PlocMPSoCHandler(object_id_t objectId, object_id_t uartComIFid, CookieIF* comCookie,
|
||||
PlocMPSoCHelper* plocMPSoCHelper, Gpio uartIsolatorSwitch,
|
||||
object_id_t supervisorHandler);
|
||||
virtual ~PlocMPSoCHandler();
|
||||
virtual ReturnValue_t initialize() override;
|
||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) override;
|
||||
void performOperationHook() override;
|
||||
MessageQueueIF* getCommandQueuePtr() override;
|
||||
void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) override;
|
||||
void stepFailedReceived(ActionId_t actionId, uint8_t step, ReturnValue_t returnCode) override;
|
||||
void dataReceived(ActionId_t actionId, const uint8_t* data, uint32_t size) override;
|
||||
void completionSuccessfulReceived(ActionId_t actionId) override;
|
||||
void completionFailedReceived(ActionId_t actionId, ReturnValue_t returnCode) override;
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId,
|
||||
size_t* foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) override;
|
||||
void setNormalDatapoolEntriesInvalid() override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator command,
|
||||
uint8_t expectedReplies = 1, bool useAlternateId = false,
|
||||
DeviceCommandId_t alternateReplyID = 0) override;
|
||||
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
|
||||
virtual ReturnValue_t doSendReadHook() override;
|
||||
|
||||
private:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HANDLER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] PLOC crc failure in telemetry packet
|
||||
static const Event MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC receive acknowledgment failure report
|
||||
//! P1: Command Id which leads the acknowledgment failure report
|
||||
//! P2: The status field inserted by the MPSoC into the data field
|
||||
static const Event ACK_FAILURE = MAKE_EVENT(2, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC receive execution failure report
|
||||
//! P1: Command Id which leads the execution failure report
|
||||
//! P2: The status field inserted by the MPSoC into the data field
|
||||
static const Event EXE_FAILURE = MAKE_EVENT(3, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC reply has invalid crc
|
||||
static const Event MPSOC_HANDLER_CRC_FAILURE = MAKE_EVENT(4, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Packet sequence count in received space packet does not match expected
|
||||
//! count P1: Expected sequence count P2: Received sequence count
|
||||
static const Event MPSOC_HANDLER_SEQUENCE_COUNT_MISMATCH = MAKE_EVENT(5, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor fails to shutdown MPSoC. Requires to power off the PLOC and
|
||||
//! thus also to shutdown the supervisor.
|
||||
static const Event MPSOC_SHUTDOWN_FAILED = MAKE_EVENT(6, severity::HIGH);
|
||||
|
||||
static const uint16_t APID_MASK = 0x7FF;
|
||||
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
|
||||
static const uint8_t STATUS_OFFSET = 10;
|
||||
|
||||
MessageQueueIF* eventQueue = nullptr;
|
||||
MessageQueueIF* commandActionHelperQueue = nullptr;
|
||||
|
||||
SourceSequenceCounter sequenceCount = SourceSequenceCounter(0);
|
||||
|
||||
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
|
||||
SpacePacketCreator creator;
|
||||
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
|
||||
|
||||
/**
|
||||
* This variable is used to store the id of the next reply to receive. This is necessary
|
||||
* because the PLOC sends as reply to each command at least one acknowledgment and execution
|
||||
* report.
|
||||
*/
|
||||
DeviceCommandId_t nextReplyId = mpsoc::NONE;
|
||||
|
||||
SerialComIF* uartComIf = nullptr;
|
||||
|
||||
PlocMPSoCHelper* plocMPSoCHelper = nullptr;
|
||||
Gpio uartIsolatorSwitch;
|
||||
object_id_t supervisorHandler = 0;
|
||||
CommandActionHelper commandActionHelper;
|
||||
|
||||
// Used to block incoming commands when MPSoC helper class is currently executing a command
|
||||
bool plocMPSoCHelperExecuting = false;
|
||||
|
||||
struct TmMemReadReport {
|
||||
static const uint8_t FIX_SIZE = 14;
|
||||
size_t rememberRequestedSize = 0;
|
||||
};
|
||||
|
||||
TmMemReadReport tmMemReadReport;
|
||||
|
||||
struct TmCamCmdRpt {
|
||||
size_t rememberSpacePacketSize = 0;
|
||||
};
|
||||
|
||||
TmCamCmdRpt tmCamCmdRpt;
|
||||
|
||||
struct TelemetryBuffer {
|
||||
uint16_t length = 0;
|
||||
uint8_t buffer[mpsoc::SP_MAX_SIZE];
|
||||
};
|
||||
|
||||
TelemetryBuffer tmBuffer;
|
||||
|
||||
enum class PowerState { OFF, BOOTING, SHUTDOWN, ON };
|
||||
|
||||
PowerState powerState = PowerState::OFF;
|
||||
|
||||
/**
|
||||
* @brief Handles events received from the PLOC MPSoC helper
|
||||
*/
|
||||
void handleEvent(EventMessage* eventMessage);
|
||||
|
||||
ReturnValue_t prepareTcMemWrite(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcMemRead(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcFlashDelete(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcReplayStart(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcReplayStop();
|
||||
ReturnValue_t prepareTcDownlinkPwrOn(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcDownlinkPwrOff();
|
||||
ReturnValue_t prepareTcReplayWriteSequence(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcCamCmdSend(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcModeIdle();
|
||||
ReturnValue_t prepareTcCamTakePic(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcSimplexSendFile(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcDownlinkDataModulate(const uint8_t* commandData, size_t commandDataLen);
|
||||
ReturnValue_t prepareTcModeSnapshot();
|
||||
void finishTcPrep(size_t packetLen);
|
||||
|
||||
/**
|
||||
* @brief This function checks the crc of the received PLOC reply.
|
||||
*
|
||||
* @param start Pointer to the first byte of the reply.
|
||||
* @param foundLen Pointer to the length of the whole packet.
|
||||
*
|
||||
* @return returnvalue::OK if CRC is ok, otherwise CRC_FAILURE.
|
||||
*/
|
||||
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
|
||||
|
||||
/**
|
||||
* @brief This function handles the acknowledgment report.
|
||||
*
|
||||
* @param data Pointer to the data holding the acknowledgment report.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleAckReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief This function handles the data of a execution report.
|
||||
*
|
||||
* @param data Pointer to the received data packet.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleExecutionReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief This function handles the memory read report.
|
||||
*
|
||||
* @param data Pointer to the data buffer holding the memory read report.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleMemoryReadReport(const uint8_t* data);
|
||||
|
||||
ReturnValue_t handleCamCmdRpt(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief Depending on the current active command, this function sets the reply id of the
|
||||
* next reply after a successful acknowledgment report has been received. This is
|
||||
* required by the function getNextReplyLength() to identify the length of the next
|
||||
* reply to read.
|
||||
*/
|
||||
void setNextReplyId();
|
||||
|
||||
/**
|
||||
* @brief This function handles action message replies in case the telemetry has been
|
||||
* requested by another object.
|
||||
*
|
||||
* @param data Pointer to the telemetry data.
|
||||
* @param dataSize Size of telemetry in bytes.
|
||||
* @param replyId Id of the reply. This will be added to the ActionMessage.
|
||||
*/
|
||||
void handleDeviceTM(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId);
|
||||
|
||||
/**
|
||||
* @brief In case an acknowledgment failure reply has been received this function disables
|
||||
* all previously enabled commands and resets the exepected replies variable of an
|
||||
* active command.
|
||||
*/
|
||||
void disableAllReplies();
|
||||
|
||||
/**
|
||||
* @brief This function sends a failure report if the active action was commanded by an other
|
||||
* object.
|
||||
*
|
||||
* @param replyId The id of the reply which signals a failure.
|
||||
* @param status A status byte which gives information about the failure type.
|
||||
*/
|
||||
void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status);
|
||||
|
||||
/**
|
||||
* @brief This function disables the execution report reply. Within this function also the
|
||||
* the variable expectedReplies of an active command will be set to 0.
|
||||
*/
|
||||
void disableExeReportReply();
|
||||
|
||||
void printStatus(const uint8_t* data);
|
||||
|
||||
ReturnValue_t prepareTcModeReplay();
|
||||
|
||||
uint16_t getStatus(const uint8_t* data);
|
||||
|
||||
void handleActionCommandFailure(ActionId_t actionId);
|
||||
|
||||
std::string getStatusString(uint16_t status);
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_DEVICES_PLOC_PLOCMPSOCHANDLER_H_ */
|
355
linux/payload/PlocMpsocHelper.cpp
Normal file
355
linux/payload/PlocMpsocHelper.cpp
Normal file
@ -0,0 +1,355 @@
|
||||
#include <linux/payload/PlocMpsocHelper.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/FilesystemHelper.h"
|
||||
#endif
|
||||
|
||||
#include "mission/utility/Timestamp.h"
|
||||
|
||||
using namespace ploc;
|
||||
|
||||
PlocMPSoCHelper::PlocMPSoCHelper(object_id_t objectId) : SystemObject(objectId) {
|
||||
spParams.buf = commandBuffer;
|
||||
spParams.maxSize = sizeof(commandBuffer);
|
||||
}
|
||||
|
||||
PlocMPSoCHelper::~PlocMPSoCHelper() {}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::initialize() {
|
||||
#ifdef XIPHOS_Q7S
|
||||
sdcMan = SdCardManager::instance();
|
||||
if (sdcMan == nullptr) {
|
||||
sif::warning << "PlocMPSoCHelper::initialize: Invalid SD Card Manager" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
#endif
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::performOperation(uint8_t operationCode) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
semaphore.acquire();
|
||||
while (true) {
|
||||
#if OBSW_THREAD_TRACING == 1
|
||||
trace::threadTrace(opCounter, "PLOC MPSOC Helper");
|
||||
#endif
|
||||
switch (internalState) {
|
||||
case InternalState::IDLE: {
|
||||
semaphore.acquire();
|
||||
break;
|
||||
}
|
||||
case InternalState::FLASH_WRITE: {
|
||||
result = performFlashWrite();
|
||||
if (result == returnvalue::OK) {
|
||||
triggerEvent(MPSOC_FLASH_WRITE_SUCCESSFUL);
|
||||
} else {
|
||||
triggerEvent(MPSOC_FLASH_WRITE_FAILED);
|
||||
}
|
||||
internalState = InternalState::IDLE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sif::debug << "PlocMPSoCHelper::performOperation: Invalid state" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::setComIF(DeviceCommunicationIF* communicationInterface_) {
|
||||
uartComIF = dynamic_cast<SerialComIF*>(communicationInterface_);
|
||||
if (uartComIF == nullptr) {
|
||||
sif::warning << "PlocMPSoCHelper::initialize: Invalid uart com if" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void PlocMPSoCHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
|
||||
|
||||
void PlocMPSoCHelper::setSequenceCount(SourceSequenceCounter* sequenceCount_) {
|
||||
sequenceCount = sequenceCount_;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::startFlashWrite(std::string obcFile, std::string mpsocFile) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
#ifdef XIPHOS_Q7S
|
||||
result = FilesystemHelper::checkPath(obcFile);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = FilesystemHelper::fileExists(mpsocFile);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#ifdef TE0720_1CFA
|
||||
if (not std::filesystem::exists(obcFile)) {
|
||||
sif::warning << "PlocMPSoCHelper::startFlashWrite: File " << obcFile << "does not exist"
|
||||
<< std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
flashWrite.obcFile = obcFile;
|
||||
flashWrite.mpsocFile = mpsocFile;
|
||||
internalState = InternalState::FLASH_WRITE;
|
||||
result = resetHelper();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::resetHelper() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
semaphore.release();
|
||||
spParams.buf = commandBuffer;
|
||||
terminate = false;
|
||||
result = uartComIF->flushUartRxBuffer(comCookie);
|
||||
return result;
|
||||
}
|
||||
|
||||
void PlocMPSoCHelper::stopProcess() { terminate = true; }
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::performFlashWrite() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = flashfopen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
uint8_t tempData[mpsoc::MAX_DATA_SIZE];
|
||||
std::ifstream file(flashWrite.obcFile, std::ifstream::binary);
|
||||
// Set position of next character to end of file input stream
|
||||
file.seekg(0, file.end);
|
||||
// tellg returns position of character in input stream
|
||||
size_t remainingSize = file.tellg();
|
||||
size_t dataLength = 0;
|
||||
size_t bytesRead = 0;
|
||||
while (remainingSize > 0) {
|
||||
if (terminate) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
if (remainingSize > mpsoc::MAX_DATA_SIZE) {
|
||||
dataLength = mpsoc::MAX_DATA_SIZE;
|
||||
} else {
|
||||
dataLength = remainingSize;
|
||||
}
|
||||
if (file.is_open()) {
|
||||
file.seekg(bytesRead, file.beg);
|
||||
file.read(reinterpret_cast<char*>(tempData), dataLength);
|
||||
bytesRead += dataLength;
|
||||
remainingSize -= dataLength;
|
||||
} else {
|
||||
return FILE_CLOSED_ACCIDENTALLY;
|
||||
}
|
||||
(*sequenceCount)++;
|
||||
mpsoc::TcFlashWrite tc(spParams, *sequenceCount);
|
||||
result = tc.buildPacket(tempData, dataLength);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = handlePacketTransmission(tc);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
result = flashfclose();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::flashfopen() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
spParams.buf = commandBuffer;
|
||||
(*sequenceCount)++;
|
||||
mpsoc::FlashFopen flashFopen(spParams, *sequenceCount);
|
||||
result = flashFopen.createPacket(flashWrite.mpsocFile, mpsoc::FlashFopen::APPEND);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = handlePacketTransmission(flashFopen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::flashfclose() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
spParams.buf = commandBuffer;
|
||||
(*sequenceCount)++;
|
||||
mpsoc::FlashFclose flashFclose(spParams, *sequenceCount);
|
||||
result = flashFclose.createPacket(flashWrite.mpsocFile);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = handlePacketTransmission(flashFclose);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::handlePacketTransmission(ploc::SpTcBase& tc) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = sendCommand(tc);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = handleAck();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = handleExe();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::sendCommand(ploc::SpTcBase& tc) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = uartComIF->sendMessage(comCookie, tc.getFullPacket(), tc.getFullPacketLen());
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "PlocMPSoCHelper::sendCommand: Failed to send command" << std::endl;
|
||||
triggerEvent(MPSOC_SENDING_COMMAND_FAILED, result, static_cast<uint32_t>(internalState));
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::handleAck() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = handleTmReception(mpsoc::SIZE_ACK_REPORT);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
SpTmReader tmPacket(tmBuf.data(), tmBuf.size());
|
||||
result = checkReceivedTm(tmPacket);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
uint16_t apid = tmPacket.getApid();
|
||||
if (apid != mpsoc::apid::ACK_SUCCESS) {
|
||||
handleAckApidFailure(apid);
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void PlocMPSoCHelper::handleAckApidFailure(uint16_t apid) {
|
||||
if (apid == mpsoc::apid::ACK_FAILURE) {
|
||||
triggerEvent(MPSOC_ACK_FAILURE_REPORT, static_cast<uint32_t>(internalState));
|
||||
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Received acknowledgement failure "
|
||||
<< "report" << std::endl;
|
||||
} else {
|
||||
triggerEvent(MPSOC_ACK_INVALID_APID, apid, static_cast<uint32_t>(internalState));
|
||||
sif::warning << "PlocMPSoCHelper::handleAckApidFailure: Expected acknowledgement report "
|
||||
<< "but received space packet with apid " << std::hex << apid << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::handleExe() {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
|
||||
result = handleTmReception(mpsoc::SIZE_EXE_REPORT);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
ploc::SpTmReader tmPacket(tmBuf.data(), tmBuf.size());
|
||||
result = checkReceivedTm(tmPacket);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
uint16_t apid = tmPacket.getApid();
|
||||
if (apid != mpsoc::apid::EXE_SUCCESS) {
|
||||
handleExeApidFailure(apid);
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void PlocMPSoCHelper::handleExeApidFailure(uint16_t apid) {
|
||||
if (apid == mpsoc::apid::EXE_FAILURE) {
|
||||
triggerEvent(MPSOC_EXE_FAILURE_REPORT, static_cast<uint32_t>(internalState));
|
||||
sif::warning << "PlocMPSoCHelper::handleExeApidFailure: Received execution failure "
|
||||
<< "report" << std::endl;
|
||||
} else {
|
||||
triggerEvent(MPSOC_EXE_INVALID_APID, apid, static_cast<uint32_t>(internalState));
|
||||
sif::warning << "PlocMPSoCHelper::handleExeApidFailure: Expected execution report "
|
||||
<< "but received space packet with apid " << std::hex << apid << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::handleTmReception(size_t remainingBytes) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
size_t readBytes = 0;
|
||||
size_t currentBytes = 0;
|
||||
for (int retries = 0; retries < RETRIES; retries++) {
|
||||
result = receive(tmBuf.data() + readBytes, ¤tBytes, remainingBytes);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
readBytes += currentBytes;
|
||||
remainingBytes = remainingBytes - currentBytes;
|
||||
if (remainingBytes == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (remainingBytes != 0) {
|
||||
sif::warning << "PlocMPSoCHelper::handleTmReception: Failed to receive reply" << std::endl;
|
||||
triggerEvent(MPSOC_MISSING_EXE, remainingBytes, static_cast<uint32_t>(internalState));
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::checkReceivedTm(SpTmReader& reader) {
|
||||
ReturnValue_t result = reader.checkSize();
|
||||
if (result != returnvalue::OK) {
|
||||
sif::error << "PlocMPSoCHelper::handleTmReception: Size check on received TM failed"
|
||||
<< std::endl;
|
||||
triggerEvent(MPSOC_TM_SIZE_ERROR);
|
||||
return result;
|
||||
}
|
||||
reader.checkCrc();
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "PlocMPSoCHelper::handleTmReception: CRC check failed" << std::endl;
|
||||
triggerEvent(MPSOC_TM_CRC_MISSMATCH, *sequenceCount);
|
||||
return result;
|
||||
}
|
||||
(*sequenceCount)++;
|
||||
uint16_t recvSeqCnt = reader.getSequenceCount();
|
||||
if (recvSeqCnt != *sequenceCount) {
|
||||
triggerEvent(MPSOC_HELPER_SEQ_CNT_MISMATCH, *sequenceCount, recvSeqCnt);
|
||||
*sequenceCount = recvSeqCnt;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t PlocMPSoCHelper::receive(uint8_t* data, size_t* readBytes, size_t requestBytes) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
uint8_t* buffer = nullptr;
|
||||
result = uartComIF->requestReceiveMessage(comCookie, requestBytes);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "PlocMPSoCHelper::receive: Failed to request reply" << std::endl;
|
||||
triggerEvent(MPSOC_HELPER_REQUESTING_REPLY_FAILED, result,
|
||||
static_cast<uint32_t>(static_cast<uint32_t>(internalState)));
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
result = uartComIF->readReceivedMessage(comCookie, &buffer, readBytes);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "PlocMPSoCHelper::receive: Failed to read received message" << std::endl;
|
||||
triggerEvent(MPSOC_HELPER_READING_REPLY_FAILED, result, static_cast<uint32_t>(internalState));
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
if (*readBytes > 0) {
|
||||
std::memcpy(data, buffer, *readBytes);
|
||||
}
|
||||
return result;
|
||||
}
|
166
linux/payload/PlocMpsocHelper.h
Normal file
166
linux/payload/PlocMpsocHelper.h
Normal file
@ -0,0 +1,166 @@
|
||||
#ifndef BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_
|
||||
#define BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_
|
||||
|
||||
#include <linux/payload/plocMpscoDefs.h>
|
||||
#include <mission/utility/trace.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/osal/linux/BinarySemaphore.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw/tmtcservices/SourceSequenceCounter.h"
|
||||
#include "fsfw_hal/linux/serial/SerialComIF.h"
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/SdCardManager.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Helper class for MPSoC of PLOC intended to accelerate large data transfers between
|
||||
* MPSoC and OBC.
|
||||
* @author J. Meier
|
||||
*/
|
||||
class PlocMPSoCHelper : public SystemObject, public ExecutableObjectIF {
|
||||
public:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_MPSOC_HELPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Flash write fails
|
||||
static const Event MPSOC_FLASH_WRITE_FAILED = MAKE_EVENT(0, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Flash write successful
|
||||
static const Event MPSOC_FLASH_WRITE_SUCCESSFUL = MAKE_EVENT(1, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command
|
||||
//! to the MPSoC
|
||||
//! P1: Return value returned by the communication interface sendMessage function
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event MPSOC_SENDING_COMMAND_FAILED = MAKE_EVENT(2, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Request receive message of communication interface failed
|
||||
//! P1: Return value returned by the communication interface requestReceiveMessage function
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event MPSOC_HELPER_REQUESTING_REPLY_FAILED = MAKE_EVENT(3, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Reading receive message of communication interface failed
|
||||
//! P1: Return value returned by the communication interface readingReceivedMessage function
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event MPSOC_HELPER_READING_REPLY_FAILED = MAKE_EVENT(4, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Did not receive acknowledgment report
|
||||
//! P1: Number of bytes missing
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event MPSOC_MISSING_ACK = MAKE_EVENT(5, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Did not receive execution report
|
||||
//! P1: Number of bytes missing
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event MPSOC_MISSING_EXE = MAKE_EVENT(6, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Received acknowledgment failure report
|
||||
//! P1: Internal state of MPSoC
|
||||
static const Event MPSOC_ACK_FAILURE_REPORT = MAKE_EVENT(7, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Received execution failure report
|
||||
//! P1: Internal state of MPSoC
|
||||
static const Event MPSOC_EXE_FAILURE_REPORT = MAKE_EVENT(8, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Expected acknowledgment report but received space packet with other apid
|
||||
//! P1: Apid of received space packet
|
||||
//! P2: Internal state of MPSoC
|
||||
static const Event MPSOC_ACK_INVALID_APID = MAKE_EVENT(9, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Expected execution report but received space packet with other apid
|
||||
//! P1: Apid of received space packet
|
||||
//! P2: Internal state of MPSoC
|
||||
static const Event MPSOC_EXE_INVALID_APID = MAKE_EVENT(10, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Received sequence count does not match expected sequence count
|
||||
//! P1: Expected sequence count
|
||||
//! P2: Received sequence count
|
||||
static const Event MPSOC_HELPER_SEQ_CNT_MISMATCH = MAKE_EVENT(11, severity::LOW);
|
||||
static const Event MPSOC_TM_SIZE_ERROR = MAKE_EVENT(12, severity::LOW);
|
||||
static const Event MPSOC_TM_CRC_MISSMATCH = MAKE_EVENT(13, severity::LOW);
|
||||
|
||||
PlocMPSoCHelper(object_id_t objectId);
|
||||
virtual ~PlocMPSoCHelper();
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
|
||||
ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_);
|
||||
void setComCookie(CookieIF* comCookie_);
|
||||
|
||||
/**
|
||||
* @brief Starts flash write sequence
|
||||
*
|
||||
* @param obcFile File where to read from the data
|
||||
* @param mpsocFile The file of the MPSoC where should be written to
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise error return value
|
||||
*/
|
||||
ReturnValue_t startFlashWrite(std::string obcFile, std::string mpsocFile);
|
||||
|
||||
/**
|
||||
* @brief Can be used to interrupt a running data transfer.
|
||||
*/
|
||||
void stopProcess();
|
||||
|
||||
/**
|
||||
* @brief Sets the sequence count object responsible for the sequence count handling
|
||||
*/
|
||||
void setSequenceCount(SourceSequenceCounter* sequenceCount_);
|
||||
|
||||
private:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_MPSOC_HELPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] File accidentally close
|
||||
static const ReturnValue_t FILE_CLOSED_ACCIDENTALLY = MAKE_RETURN_CODE(0xA0);
|
||||
|
||||
// Maximum number of times the communication interface retries polling data from the reply
|
||||
// buffer
|
||||
static const int RETRIES = 10000;
|
||||
|
||||
struct FlashWrite {
|
||||
std::string obcFile;
|
||||
std::string mpsocFile;
|
||||
};
|
||||
|
||||
struct FlashWrite flashWrite;
|
||||
|
||||
#if OBSW_THREAD_TRACING == 1
|
||||
uint32_t opCounter = 0;
|
||||
#endif
|
||||
|
||||
enum class InternalState { IDLE, FLASH_WRITE, FLASH_READ };
|
||||
|
||||
InternalState internalState = InternalState::IDLE;
|
||||
|
||||
BinarySemaphore semaphore;
|
||||
#ifdef XIPHOS_Q7S
|
||||
SdCardManager* sdcMan = nullptr;
|
||||
#endif
|
||||
uint8_t commandBuffer[mpsoc::MAX_COMMAND_SIZE];
|
||||
SpacePacketCreator creator;
|
||||
ploc::SpTcParams spParams = ploc::SpTcParams(creator);
|
||||
|
||||
std::array<uint8_t, mpsoc::MAX_REPLY_SIZE> tmBuf;
|
||||
|
||||
bool terminate = false;
|
||||
|
||||
/**
|
||||
* Communication interface of MPSoC responsible for low level access. Must be set by the
|
||||
* MPSoC Handler.
|
||||
*/
|
||||
SerialComIF* uartComIF = nullptr;
|
||||
// Communication cookie. Must be set by the MPSoC Handler
|
||||
CookieIF* comCookie = nullptr;
|
||||
// Sequence count, must be set by Ploc MPSoC Handler
|
||||
SourceSequenceCounter* sequenceCount = nullptr;
|
||||
|
||||
ReturnValue_t resetHelper();
|
||||
ReturnValue_t performFlashWrite();
|
||||
ReturnValue_t flashfopen();
|
||||
ReturnValue_t flashfclose();
|
||||
ReturnValue_t handlePacketTransmission(ploc::SpTcBase& tc);
|
||||
ReturnValue_t sendCommand(ploc::SpTcBase& tc);
|
||||
ReturnValue_t receive(uint8_t* data, size_t* readBytes, size_t requestBytes);
|
||||
ReturnValue_t handleAck();
|
||||
ReturnValue_t handleExe();
|
||||
void handleAckApidFailure(uint16_t apid);
|
||||
void handleExeApidFailure(uint16_t apid);
|
||||
ReturnValue_t handleTmReception(size_t remainingBytes);
|
||||
ReturnValue_t checkReceivedTm(ploc::SpTmReader& reader);
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_DEVICES_PLOCMPSOCHELPER_H_ */
|
2100
linux/payload/PlocSupervisorHandler.cpp
Normal file
2100
linux/payload/PlocSupervisorHandler.cpp
Normal file
File diff suppressed because it is too large
Load Diff
393
linux/payload/PlocSupervisorHandler.h
Normal file
393
linux/payload/PlocSupervisorHandler.h
Normal file
@ -0,0 +1,393 @@
|
||||
#ifndef MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
|
||||
#define MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_
|
||||
|
||||
#include <linux/payload/PlocSupvUartMan.h>
|
||||
#include <linux/payload/plocSupvDefs.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "devices/powerSwitcherList.h"
|
||||
#include "fsfw/devicehandlers/DeviceHandlerBase.h"
|
||||
#include "fsfw/timemanager/Countdown.h"
|
||||
#include "fsfw_hal/linux/gpio/Gpio.h"
|
||||
#include "fsfw_hal/linux/gpio/LinuxLibgpioIF.h"
|
||||
#include "fsfw_hal/linux/serial/SerialComIF.h"
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/SdCardManager.h"
|
||||
#endif
|
||||
|
||||
using supv::ExecutionReport;
|
||||
|
||||
/**
|
||||
* @brief This is the device handler for the supervisor of the PLOC which is programmed by
|
||||
* Thales.
|
||||
*
|
||||
* @details The PLOC uses the space packet protocol for communication. On each command the PLOC
|
||||
* answers with at least one acknowledgment and one execution report.
|
||||
* Flight manual:
|
||||
* https://egit.irs.uni-stuttgart.de/redmine/projects/eive-flight-manual/wiki/PLOC_Commands
|
||||
* ILH ICD: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/
|
||||
* Arbeitsdaten/08_Used%20Components/PLOC&fileid=940960
|
||||
* @author J. Meier
|
||||
*/
|
||||
class PlocSupervisorHandler : public DeviceHandlerBase {
|
||||
public:
|
||||
PlocSupervisorHandler(object_id_t objectId, CookieIF* comCookie, Gpio uartIsolatorSwitch,
|
||||
power::Switch_t powerSwitch, PlocSupvUartManager& supvHelper);
|
||||
virtual ~PlocSupervisorHandler();
|
||||
|
||||
virtual ReturnValue_t initialize() override;
|
||||
void performOperationHook() override;
|
||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
||||
const uint8_t* data, size_t size) override;
|
||||
|
||||
protected:
|
||||
void doStartUp() override;
|
||||
void doShutDown() override;
|
||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t* id) override;
|
||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t* id) override;
|
||||
void fillCommandAndReplyMap() override;
|
||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t* commandData,
|
||||
size_t commandDataLen) override;
|
||||
ReturnValue_t scanForReply(const uint8_t* start, size_t remainingSize, DeviceCommandId_t* foundId,
|
||||
size_t* foundLen) override;
|
||||
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t* packet) override;
|
||||
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
|
||||
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
|
||||
LocalDataPoolManager& poolManager) override;
|
||||
ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator command,
|
||||
uint8_t expectedReplies = 1, bool useAlternateId = false,
|
||||
DeviceCommandId_t alternateReplyID = 0) override;
|
||||
size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
|
||||
// ReturnValue_t doSendReadHook() override;
|
||||
void doOffActivity() override;
|
||||
|
||||
private:
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_SUPERVISOR_HANDLER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] PLOC supervisor crc failure in telemetry packet
|
||||
static const Event SUPV_MEMORY_READ_RPT_CRC_FAILURE = MAKE_EVENT(1, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Unhandled event. P1: APID, P2: Service ID
|
||||
static constexpr Event SUPV_UNKNOWN_TM = MAKE_EVENT(2, severity::LOW);
|
||||
static constexpr Event SUPV_UNINIMPLEMENTED_TM = MAKE_EVENT(3, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC supervisor received acknowledgment failure report
|
||||
static const Event SUPV_ACK_FAILURE = MAKE_EVENT(4, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC received execution failure report
|
||||
//! P1: ID of command for which the execution failed
|
||||
//! P2: Status code sent by the supervisor handler
|
||||
static const Event SUPV_EXE_FAILURE = MAKE_EVENT(5, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] PLOC supervisor reply has invalid crc
|
||||
static const Event SUPV_CRC_FAILURE_EVENT = MAKE_EVENT(6, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor helper currently executing a command
|
||||
static const Event SUPV_HELPER_EXECUTING = MAKE_EVENT(7, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Failed to build the command to shutdown the MPSoC
|
||||
static const Event SUPV_MPSOC_SHUTDOWN_BUILD_FAILED = MAKE_EVENT(8, severity::LOW);
|
||||
|
||||
static const uint16_t APID_MASK = 0x7FF;
|
||||
static const uint16_t PACKET_SEQUENCE_COUNT_MASK = 0x3FFF;
|
||||
static const uint8_t EXE_STATUS_OFFSET = 10;
|
||||
static const uint8_t SIZE_NULL_TERMINATOR = 1;
|
||||
// 5 s
|
||||
static const uint32_t EXECUTION_DEFAULT_TIMEOUT = 5000;
|
||||
// 70 S
|
||||
static const uint32_t ACKNOWLEDGE_DEFAULT_TIMEOUT = 70000;
|
||||
// 60 s
|
||||
static const uint32_t MRAM_DUMP_EXECUTION_TIMEOUT = 60000;
|
||||
// 70 s
|
||||
static const uint32_t COPY_ADC_TO_MRAM_TIMEOUT = 70000;
|
||||
// 60 s
|
||||
static const uint32_t MRAM_DUMP_TIMEOUT = 60000;
|
||||
// 4 s
|
||||
static const uint32_t BOOT_TIMEOUT = 4000;
|
||||
enum class StartupState : uint8_t { OFF, BOOTING, SET_TIME, SET_TIME_EXECUTING, ON };
|
||||
|
||||
static constexpr bool SET_TIME_DURING_BOOT = true;
|
||||
|
||||
StartupState startupState = StartupState::OFF;
|
||||
|
||||
uint8_t commandBuffer[supv::MAX_COMMAND_SIZE];
|
||||
SpacePacketCreator creator;
|
||||
supv::TcParams spParams = supv::TcParams(creator);
|
||||
|
||||
/**
|
||||
* This variable is used to store the id of the next reply to receive. This is necessary
|
||||
* because the PLOC sends as reply to each command at least one acknowledgment and execution
|
||||
* report.
|
||||
*/
|
||||
DeviceCommandId_t nextReplyId = supv::NONE;
|
||||
|
||||
SerialComIF* uartComIf = nullptr;
|
||||
LinuxLibgpioIF* gpioComIF = nullptr;
|
||||
Gpio uartIsolatorSwitch;
|
||||
bool shutdownCmdSent = false;
|
||||
|
||||
supv::HkSet hkset;
|
||||
supv::BootStatusReport bootStatusReport;
|
||||
supv::LatchupStatusReport latchupStatusReport;
|
||||
supv::LoggingReport loggingReport;
|
||||
supv::AdcReport adcReport;
|
||||
|
||||
const power::Switch_t powerSwitch = power::NO_SWITCH;
|
||||
supv::TmBase tmReader;
|
||||
|
||||
PlocSupvUartManager& uartManager;
|
||||
MessageQueueIF* eventQueue = nullptr;
|
||||
|
||||
/** Number of expected replies following the MRAM dump command */
|
||||
uint32_t expectedMramDumpPackets = 0;
|
||||
uint32_t receivedMramDumpPackets = 0;
|
||||
/** Set to true as soon as a complete space packet is present in the spacePacketBuffer */
|
||||
bool packetInBuffer = false;
|
||||
|
||||
/** This buffer is used to concatenate space packets received in two different read steps */
|
||||
uint8_t spacePacketBuffer[supv::MAX_PACKET_SIZE];
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
SdCardManager* sdcMan = nullptr;
|
||||
#endif
|
||||
|
||||
// Path to supervisor specific files on SD card
|
||||
std::string supervisorFilePath = "ploc/supervisor";
|
||||
std::string activeMramFile;
|
||||
|
||||
Countdown executionReportTimeout = Countdown(EXECUTION_DEFAULT_TIMEOUT, false);
|
||||
Countdown acknowledgementReportTimeout = Countdown(ACKNOWLEDGE_DEFAULT_TIMEOUT, false);
|
||||
// Vorago nees some time to boot properly
|
||||
Countdown bootTimeout = Countdown(BOOT_TIMEOUT);
|
||||
Countdown mramDumpTimeout = Countdown(MRAM_DUMP_TIMEOUT);
|
||||
|
||||
PoolEntry<uint8_t> fmcStateEntry = PoolEntry<uint8_t>(1);
|
||||
PoolEntry<uint8_t> bootStateEntry = PoolEntry<uint8_t>(1);
|
||||
PoolEntry<uint8_t> bootCyclesEntry = PoolEntry<uint8_t>(1);
|
||||
PoolEntry<uint32_t> tempSupEntry = PoolEntry<uint32_t>(1);
|
||||
|
||||
/**
|
||||
* @brief Adjusts the timeout of the execution report dependent on command
|
||||
*/
|
||||
void setExecutionTimeout(DeviceCommandId_t command);
|
||||
|
||||
/**
|
||||
* @brief Handles event messages received from the supervisor helper
|
||||
*/
|
||||
void handleEvent(EventMessage* eventMessage);
|
||||
|
||||
ReturnValue_t getSwitches(const uint8_t** switches, uint8_t* numberOfSwitches);
|
||||
|
||||
/**
|
||||
* @brief This function checks the crc of the received PLOC reply.
|
||||
*
|
||||
* @param start Pointer to the first byte of the reply.
|
||||
* @param foundLen Pointer to the length of the whole packet.
|
||||
*
|
||||
* @return returnvalue::OK if CRC is ok, otherwise CRC_FAILURE.
|
||||
*/
|
||||
ReturnValue_t verifyPacket(const uint8_t* start, size_t foundLen);
|
||||
|
||||
/**
|
||||
* @brief This function handles the acknowledgment report.
|
||||
*
|
||||
* @param data Pointer to the data holding the acknowledgment report.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleAckReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief This function handles the data of a execution report.
|
||||
*
|
||||
* @param data Pointer to the received data packet.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleExecutionReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief This function handles the housekeeping report. This means verifying the CRC of the
|
||||
* reply and filling the appropriate dataset.
|
||||
*
|
||||
* @param data Pointer to the data buffer holding the housekeeping read report.
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise an error code.
|
||||
*/
|
||||
ReturnValue_t handleHkReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief This function calls the function to check the CRC of the received boot status report
|
||||
* and fills the associated dataset with the boot status information.
|
||||
*/
|
||||
ReturnValue_t handleBootStatusReport(const uint8_t* data);
|
||||
|
||||
ReturnValue_t handleLatchupStatusReport(const uint8_t* data);
|
||||
void handleBadApidServiceCombination(Event result, unsigned int apid, unsigned int serviceId);
|
||||
// ReturnValue_t handleLoggingReport(const uint8_t* data);
|
||||
ReturnValue_t handleAdcReport(const uint8_t* data);
|
||||
|
||||
/**
|
||||
* @brief Depending on the current active command, this function sets the reply id of the
|
||||
* next reply after a successful acknowledgment report has been received. This is
|
||||
* required by the function getNextReplyLength() to identify the length of the next
|
||||
* reply to read.
|
||||
*/
|
||||
void setNextReplyId();
|
||||
|
||||
/**
|
||||
* @brief This function handles action message replies in case the telemetry has been
|
||||
* requested by another object.
|
||||
*
|
||||
* @param data Pointer to the telemetry data.
|
||||
* @param dataSize Size of telemetry in bytes.
|
||||
* @param replyId Id of the reply. This will be added to the ActionMessage.
|
||||
*/
|
||||
void handleDeviceTm(const uint8_t* data, size_t dataSize, DeviceCommandId_t replyId);
|
||||
|
||||
/**
|
||||
* @brief This function prepares a space packet which does not transport any data in the
|
||||
* packet data field apart from the crc.
|
||||
*/
|
||||
ReturnValue_t prepareEmptyCmd(uint16_t apid, uint8_t serviceId);
|
||||
|
||||
/**
|
||||
* @brief This function initializes the space packet to select the boot image of the MPSoC.
|
||||
*/
|
||||
ReturnValue_t prepareSelBootImageCmd(const uint8_t* commandData);
|
||||
|
||||
ReturnValue_t prepareDisableHk();
|
||||
|
||||
/**
|
||||
* @brief This function fills the commandBuffer with the data to update the time of the
|
||||
* PLOC supervisor.
|
||||
*/
|
||||
ReturnValue_t prepareSetTimeRefCmd();
|
||||
|
||||
/**
|
||||
* @brief This function fills the commandBuffer with the data to change the boot timeout
|
||||
* value in the PLOC supervisor.
|
||||
*/
|
||||
ReturnValue_t prepareSetBootTimeoutCmd(const uint8_t* commandData);
|
||||
|
||||
ReturnValue_t prepareRestartTriesCmd(const uint8_t* commandData);
|
||||
|
||||
ReturnValue_t prepareFactoryResetCmd(const uint8_t* commandData, size_t len);
|
||||
|
||||
/**
|
||||
* @brief This function fills the command buffer with the packet to enable or disable the
|
||||
* watchdogs on the PLOC.
|
||||
*/
|
||||
void prepareWatchdogsEnableCmd(const uint8_t* commandData);
|
||||
|
||||
/**
|
||||
* @brief This function fills the command buffer with the packet to set the watchdog timer
|
||||
* of one of the three watchdogs (PS, PL, INT).
|
||||
*/
|
||||
ReturnValue_t prepareWatchdogsConfigTimeoutCmd(const uint8_t* commandData);
|
||||
|
||||
ReturnValue_t prepareLatchupConfigCmd(const uint8_t* commandData,
|
||||
DeviceCommandId_t deviceCommand);
|
||||
ReturnValue_t prepareSetAlertLimitCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareSetAdcEnabledChannelsCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareSetAdcWindowAndStrideCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareSetAdcThresholdCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareRunAutoEmTest(const uint8_t* commandData);
|
||||
ReturnValue_t prepareWipeMramCmd(const uint8_t* commandData);
|
||||
// ReturnValue_t prepareDumpMramCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareSetGpioCmd(const uint8_t* commandData);
|
||||
ReturnValue_t prepareReadGpioCmd(const uint8_t* commandData);
|
||||
// ReturnValue_t prepareLoggingRequest(const uint8_t* commandData, size_t commandDataLen);
|
||||
// ReturnValue_t prepareEnableNvmsCommand(const uint8_t* commandData);
|
||||
|
||||
/**
|
||||
* @brief Copies the content of a space packet to the command buffer.
|
||||
*/
|
||||
void finishTcPrep(size_t packetLen);
|
||||
|
||||
/**
|
||||
* @brief In case an acknowledgment failure reply has been received this function disables
|
||||
* all previously enabled commands and resets the exepected replies variable of an
|
||||
* active command.
|
||||
*/
|
||||
void disableAllReplies();
|
||||
|
||||
void disableReply(DeviceCommandId_t replyId);
|
||||
|
||||
/**
|
||||
* @brief This function sends a failure report if the active action was commanded by an other
|
||||
* object.
|
||||
*
|
||||
* @param replyId The id of the reply which signals a failure.
|
||||
* @param status A status byte which gives information about the failure type.
|
||||
*/
|
||||
void sendFailureReport(DeviceCommandId_t replyId, ReturnValue_t status);
|
||||
|
||||
/**
|
||||
* @brief This function disables the execution report reply. Within this function also the
|
||||
* the variable expectedReplies of an active command will be set to 0.
|
||||
*/
|
||||
void disableExeReportReply();
|
||||
|
||||
/**
|
||||
* @brief Function is called in scanForReply and fills the spacePacketBuffer with the read
|
||||
* data until a full packet has been received.
|
||||
*/
|
||||
// ReturnValue_t parseMramPackets(const uint8_t* packet, size_t remainingSize, size_t* foundlen);
|
||||
|
||||
/**
|
||||
* @brief This function generates the Service 8 packets for the MRAM dump data.
|
||||
*/
|
||||
ReturnValue_t handleMramDumpPacket(DeviceCommandId_t id);
|
||||
|
||||
/**
|
||||
* @brief With this function the number of expected replies following an MRAM dump command
|
||||
* will be increased. This is necessary to release the command in case not all replies
|
||||
* have been received.
|
||||
*/
|
||||
void increaseExpectedMramReplies(DeviceCommandId_t id);
|
||||
|
||||
/**
|
||||
* @brief Function checks if the packet written to the space packet buffer is really a
|
||||
* MRAM dump packet.
|
||||
*/
|
||||
// ReturnValue_t checkMramPacketApid();
|
||||
|
||||
/**
|
||||
* @brief Writes the data of the MRAM dump to a file. The file will be created when receiving
|
||||
* the first packet.
|
||||
*/
|
||||
ReturnValue_t handleMramDumpFile(DeviceCommandId_t id);
|
||||
|
||||
/**
|
||||
* @brief Extracts the length field of a spacePacket referenced by the spacePacket pointer.
|
||||
*
|
||||
* @param spacePacket Pointer to the buffer holding the space packet.
|
||||
*
|
||||
* @return The value stored in the length field of the data field.
|
||||
*/
|
||||
uint16_t readSpacePacketLength(uint8_t* spacePacket);
|
||||
|
||||
/**
|
||||
* @brief Extracts the sequence flags from a space packet referenced by the spacePacket
|
||||
* pointer.
|
||||
*
|
||||
* @param spacePacket Pointer to the buffer holding the space packet.
|
||||
*
|
||||
* @return uint8_t where the two least significant bits hold the sequence flags.
|
||||
*/
|
||||
uint8_t readSequenceFlags(uint8_t* spacePacket);
|
||||
|
||||
ReturnValue_t createMramDumpFile();
|
||||
ReturnValue_t getTimeStampString(std::string& timeStamp);
|
||||
|
||||
ReturnValue_t prepareSetShutdownTimeoutCmd(const uint8_t* commandData);
|
||||
|
||||
ReturnValue_t extractUpdateCommand(const uint8_t* commandData, size_t size,
|
||||
supv::UpdateParams& params);
|
||||
ReturnValue_t extractBaseParams(const uint8_t** commandData, size_t& remSize,
|
||||
supv::UpdateParams& params);
|
||||
ReturnValue_t eventSubscription();
|
||||
|
||||
ReturnValue_t handleExecutionSuccessReport(ExecutionReport& report);
|
||||
void handleExecutionFailureReport(ExecutionReport& report);
|
||||
|
||||
void printAckFailureInfo(uint16_t statusCode, DeviceCommandId_t commandId);
|
||||
};
|
||||
|
||||
#endif /* MISSION_DEVICES_PLOCSUPERVISORHANDLER_H_ */
|
1164
linux/payload/PlocSupvUartMan.cpp
Normal file
1164
linux/payload/PlocSupvUartMan.cpp
Normal file
File diff suppressed because it is too large
Load Diff
378
linux/payload/PlocSupvUartMan.h
Normal file
378
linux/payload/PlocSupvUartMan.h
Normal file
@ -0,0 +1,378 @@
|
||||
#ifndef BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_
|
||||
#define BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_
|
||||
|
||||
#include <fsfw/container/SimpleRingBuffer.h>
|
||||
#include <linux/payload/plocSupvDefs.h>
|
||||
#include <mission/utility/trace.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/container/FIFO.h"
|
||||
#include "fsfw/devicehandlers/CookieIF.h"
|
||||
#include "fsfw/objectmanager/SystemObject.h"
|
||||
#include "fsfw/osal/linux/BinarySemaphore.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
#include "fsfw/tasks/ExecutableObjectIF.h"
|
||||
#include "fsfw_hal/linux/serial/SerialComIF.h"
|
||||
#include "tas/crc.h"
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
#include "bsp_q7s/fs/SdCardManager.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Helper class for supervisor of PLOC intended to accelerate large data transfers between
|
||||
* the supervisor and the OBC.
|
||||
* @author J. Meier
|
||||
*/
|
||||
class PlocSupvUartManager : public DeviceCommunicationIF,
|
||||
public SystemObject,
|
||||
public ExecutableObjectIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::PLOC_SUPV_HELPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] File accidentally close
|
||||
static const ReturnValue_t FILE_CLOSED_ACCIDENTALLY = MAKE_RETURN_CODE(0xA0);
|
||||
//! [EXPORT] : [COMMENT] Process has been terminated by command
|
||||
static const ReturnValue_t PROCESS_TERMINATED = MAKE_RETURN_CODE(0xA1);
|
||||
//! [EXPORT] : [COMMENT] Received command with invalid pathname
|
||||
static const ReturnValue_t PATH_NOT_EXISTS = MAKE_RETURN_CODE(0xA2);
|
||||
//! [EXPORT] : [COMMENT] Expected event buffer TM but received space packet with other APID
|
||||
static const ReturnValue_t EVENT_BUFFER_REPLY_INVALID_APID = MAKE_RETURN_CODE(0xA3);
|
||||
|
||||
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_SUPV_HELPER;
|
||||
|
||||
//! [EXPORT] : [COMMENT] update failed
|
||||
static const Event SUPV_UPDATE_FAILED = MAKE_EVENT(0, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] update successful
|
||||
static const Event SUPV_UPDATE_SUCCESSFUL = MAKE_EVENT(1, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Continue update command failed
|
||||
static const Event SUPV_CONTINUE_UPDATE_FAILED = MAKE_EVENT(2, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Continue update command successful
|
||||
static const Event SUPV_CONTINUE_UPDATE_SUCCESSFUL = MAKE_EVENT(3, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Terminated update procedure by command
|
||||
static const Event TERMINATED_UPDATE_PROCEDURE = MAKE_EVENT(4, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Requesting event buffer was successful
|
||||
static const Event SUPV_EVENT_BUFFER_REQUEST_SUCCESSFUL = MAKE_EVENT(5, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Requesting event buffer failed
|
||||
static const Event SUPV_EVENT_BUFFER_REQUEST_FAILED = MAKE_EVENT(6, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Terminated event buffer request by command
|
||||
//! P1: Number of packets read before process was terminated
|
||||
static const Event SUPV_EVENT_BUFFER_REQUEST_TERMINATED = MAKE_EVENT(7, severity::LOW);
|
||||
//! Status of memory check command
|
||||
//! P1: Returncode, 0 for success, other value with returncode for failure
|
||||
static constexpr Event SUPV_MEM_CHECK_OK = MAKE_EVENT(8, severity::INFO);
|
||||
static constexpr Event SUPV_MEM_CHECK_FAIL = MAKE_EVENT(9, severity::INFO);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Communication interface returned failure when trying to send the command
|
||||
//! to the supervisor
|
||||
//! P1: Return value returned by the communication interface sendMessage function
|
||||
//! P2: Internal state of supervisor helper
|
||||
static const Event SUPV_SENDING_COMMAND_FAILED = MAKE_EVENT(16, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Request receive message of communication interface failed
|
||||
//! P1: Return value returned by the communication interface requestReceiveMessage function
|
||||
//! P2: Internal state of supervisor helper
|
||||
static const Event SUPV_HELPER_REQUESTING_REPLY_FAILED = MAKE_EVENT(17, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Reading receive message of communication interface failed
|
||||
//! P1: Return value returned by the communication interface readingReceivedMessage function
|
||||
//! P2: Internal state of supervisor helper
|
||||
static const Event SUPV_HELPER_READING_REPLY_FAILED = MAKE_EVENT(18, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Did not receive acknowledgement report
|
||||
//! P1: Number of bytes missing
|
||||
//! P2: Internal state of MPSoC helper
|
||||
static const Event SUPV_MISSING_ACK = MAKE_EVENT(19, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor did not receive execution report
|
||||
//! P1: Number of bytes missing
|
||||
//! P2: Internal state of supervisor helper
|
||||
static const Event SUPV_MISSING_EXE = MAKE_EVENT(20, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor received acknowledgment failure report
|
||||
//! P1: Internal state of supervisor helper
|
||||
static const Event SUPV_ACK_FAILURE_REPORT = MAKE_EVENT(21, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Execution report failure
|
||||
//! P1:
|
||||
static const Event SUPV_EXE_FAILURE_REPORT = MAKE_EVENT(22, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor expected acknowledgment report but received space packet with
|
||||
//! other apid P1: Apid of received space packet P2: Internal state of supervisor helper
|
||||
static const Event SUPV_ACK_INVALID_APID = MAKE_EVENT(23, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Supervisor helper expected execution report but received space packet
|
||||
//! with other apid P1: Apid of received space packet P2: Internal state of supervisor helper
|
||||
static const Event SUPV_EXE_INVALID_APID = MAKE_EVENT(24, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Failed to receive acknowledgment report
|
||||
//! P1: Return value
|
||||
//! P2: Apid of command for which the reception of the acknowledgment report failed
|
||||
static const Event ACK_RECEPTION_FAILURE = MAKE_EVENT(25, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Failed to receive execution report
|
||||
//! P1: Return value
|
||||
//! P2: Apid of command for which the reception of the execution report failed
|
||||
static const Event EXE_RECEPTION_FAILURE = MAKE_EVENT(26, severity::LOW);
|
||||
//! [EXPORT] : [COMMENT] Update procedure failed when sending packet.
|
||||
//! P1: First byte percent, third and fourth byte Sequence Count, P2: Bytes written
|
||||
static const Event WRITE_MEMORY_FAILED = MAKE_EVENT(27, severity::LOW);
|
||||
static const Event SUPV_REPLY_SIZE_MISSMATCH = MAKE_EVENT(28, severity::LOW);
|
||||
static const Event SUPV_REPLY_CRC_MISSMATCH = MAKE_EVENT(29, severity::LOW);
|
||||
|
||||
//! [EXPORT] : [COMMENT] Will be triggered every 5 percent of the update progress.
|
||||
//! P1: First byte percent, third and fourth byte Sequence Count, P2: Bytes written
|
||||
static constexpr Event SUPV_UPDATE_PROGRESS = MAKE_EVENT(30, severity::INFO);
|
||||
static constexpr Event HDLC_FRAME_REMOVAL_ERROR = MAKE_EVENT(31, severity::INFO);
|
||||
static constexpr Event HDLC_CRC_ERROR = MAKE_EVENT(32, severity::INFO);
|
||||
|
||||
PlocSupvUartManager(object_id_t objectId);
|
||||
virtual ~PlocSupvUartManager();
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
|
||||
/**
|
||||
* @brief Starts update procedure
|
||||
*
|
||||
* @param file File containing the update data
|
||||
* @param memoryId ID of the memory where to write to
|
||||
* @param startAddress Address where to write data
|
||||
*
|
||||
* @return returnvalue::OK if successful, otherwise error return value
|
||||
*/
|
||||
ReturnValue_t performUpdate(const supv::UpdateParams& params);
|
||||
ReturnValue_t startUpdate(std::string file, uint8_t memoryId, uint32_t startAddress);
|
||||
|
||||
ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress,
|
||||
size_t sizeToCheck, bool checkCrc);
|
||||
ReturnValue_t performMemCheck(std::string file, uint8_t memoryId, uint32_t startAddress);
|
||||
|
||||
/**
|
||||
* @brief This initiate the continuation of a failed update.
|
||||
*/
|
||||
ReturnValue_t initiateUpdateContinuation();
|
||||
|
||||
/**
|
||||
* @brief Calling this function will initiate the procedure to request the event buffer
|
||||
*/
|
||||
// ReturnValue_t startEventBufferRequest(std::string path);
|
||||
|
||||
/**
|
||||
* @brief Can be used to stop the UART reception and put the task to sleep
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* @brief Can be used to start the UART reception
|
||||
*/
|
||||
void start();
|
||||
bool longerRequestActive() const;
|
||||
|
||||
static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount);
|
||||
static uint32_t buildApidServiceParam1(uint8_t apid, uint8_t serviceId);
|
||||
|
||||
private:
|
||||
static constexpr ReturnValue_t REQUEST_DONE = returnvalue::makeCode(1, 0);
|
||||
static constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 1);
|
||||
static constexpr ReturnValue_t DECODE_BUF_TOO_SMALL = returnvalue::makeCode(1, 2);
|
||||
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START =
|
||||
returnvalue::makeCode(1, 3);
|
||||
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_END = returnvalue::makeCode(1, 4);
|
||||
static constexpr ReturnValue_t HDLC_ERROR = returnvalue::makeCode(1, 5);
|
||||
|
||||
static const uint16_t CRC16_INIT = 0xFFFF;
|
||||
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with
|
||||
// 192 bytes
|
||||
static const uint8_t NUM_EVENT_BUFFER_PACKETS = 25;
|
||||
static const size_t SIZE_EVENT_BUFFER_FULL_PACKET = 1024;
|
||||
static const size_t SIZE_EVENT_BUFFER_LAST_PACKET = 200;
|
||||
static const uint32_t PREPARE_UPDATE_EXECUTION_REPORT = 2000;
|
||||
|
||||
static constexpr uint8_t MAX_STORED_DECODED_PACKETS = 4;
|
||||
static constexpr uint8_t HDLC_START_MARKER = 0x7E;
|
||||
static constexpr uint8_t HDLC_END_MARKER = 0x7C;
|
||||
|
||||
struct Update {
|
||||
uint8_t memoryId;
|
||||
uint32_t startAddress;
|
||||
// Absolute name of file containing update data
|
||||
std::string file;
|
||||
// Length of full file
|
||||
size_t fullFileSize = 0;
|
||||
// Size of update
|
||||
uint32_t length = 0;
|
||||
uint32_t crc = 0;
|
||||
bool crcShouldBeChecked = true;
|
||||
size_t bytesWritten;
|
||||
uint32_t packetNum;
|
||||
uint16_t sequenceCount;
|
||||
uint8_t progressPercent;
|
||||
bool deleteMemory = false;
|
||||
};
|
||||
|
||||
struct Update update;
|
||||
|
||||
SemaphoreIF* semaphore;
|
||||
MutexIF* lock;
|
||||
MutexIF* ipcLock;
|
||||
supv::TmBase tmReader;
|
||||
int serialPort = 0;
|
||||
struct termios tty = {};
|
||||
#if OBSW_THREAD_TRACING == 1
|
||||
uint32_t opCounter = 0;
|
||||
#endif
|
||||
|
||||
struct EventBufferRequest {
|
||||
std::string path = "";
|
||||
// Default name of file where event buffer data will be written to. Timestamp will be added to
|
||||
// name when new file is created
|
||||
std::string filename = "event-buffer.bin";
|
||||
};
|
||||
|
||||
EventBufferRequest eventBufferReq;
|
||||
|
||||
enum class InternalState { SLEEPING, DEFAULT, DEDICATED_REQUEST, GO_TO_SLEEP };
|
||||
|
||||
enum class Request {
|
||||
DEFAULT,
|
||||
UPDATE,
|
||||
CONTINUE_UPDATE,
|
||||
REQUEST_EVENT_BUFFER,
|
||||
CHECK_MEMORY,
|
||||
};
|
||||
InternalState state = InternalState::SLEEPING;
|
||||
Request request = Request::DEFAULT;
|
||||
|
||||
#ifdef XIPHOS_Q7S
|
||||
SdCardManager* sdcMan = nullptr;
|
||||
#endif
|
||||
SimpleRingBuffer recRingBuf;
|
||||
std::array<uint8_t, 1200> cmdBuf = {};
|
||||
std::array<uint8_t, 2048> encodedSendBuf = {};
|
||||
std::array<uint8_t, 2048> recBuf = {};
|
||||
std::array<uint8_t, 2048> encodedBuf = {};
|
||||
std::array<uint8_t, 1200> decodedBuf = {};
|
||||
SimpleRingBuffer decodedRingBuf;
|
||||
FIFO<size_t, MAX_STORED_DECODED_PACKETS> decodedQueue;
|
||||
std::array<uint8_t, 1200> ipcBuffer = {};
|
||||
SimpleRingBuffer ipcRingBuf;
|
||||
FIFO<size_t, MAX_STORED_DECODED_PACKETS> ipcQueue;
|
||||
|
||||
SpacePacketCreator creator;
|
||||
supv::TcParams spParams = supv::TcParams(creator);
|
||||
|
||||
std::array<uint8_t, supv::MAX_COMMAND_SIZE> tmBuf{};
|
||||
|
||||
bool printTc = false;
|
||||
bool debugMode = false;
|
||||
bool timestamping = true;
|
||||
|
||||
// Remembers APID to know at which command a procedure failed
|
||||
uint16_t rememberApid = 0;
|
||||
|
||||
ReturnValue_t handleRunningLongerRequest();
|
||||
ReturnValue_t handleUartReception();
|
||||
void addHdlcFraming(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen, size_t maxDest);
|
||||
int removeHdlcFramingWithCrcCheck(const uint8_t* src, size_t slen, uint8_t* dst, size_t* dlen);
|
||||
|
||||
ReturnValue_t encodeAndSendPacket(const uint8_t* sendData, size_t sendLen);
|
||||
void executeFullCheckMemoryCommand();
|
||||
|
||||
ReturnValue_t tryHdlcParsing();
|
||||
ReturnValue_t parseRecRingBufForHdlc(size_t& readSize, size_t& decodedLen);
|
||||
ReturnValue_t executeUpdate();
|
||||
ReturnValue_t continueUpdate();
|
||||
ReturnValue_t updateOperation();
|
||||
ReturnValue_t writeUpdatePackets();
|
||||
// ReturnValue_t performEventBufferRequest();
|
||||
ReturnValue_t handlePacketTransmissionNoReply(supv::TcBase& packet,
|
||||
uint32_t timeoutExecutionReport);
|
||||
int handleAckReception(supv::TcBase& tc, size_t packetLen);
|
||||
int handleExeAckReception(supv::TcBase& tc, size_t packetLen);
|
||||
|
||||
/**
|
||||
* @brief Handles reading of TM packets from the communication interface
|
||||
*
|
||||
* @param tmPacket Pointer to space packet where received data will be written to
|
||||
* @param reaminingBytes Number of bytes to read in the space packet
|
||||
* @param timeout Receive timeout in milliseconds
|
||||
*
|
||||
* @note It can take up to 70 seconds until the supervisor replies with an acknowledgment
|
||||
* failure report.
|
||||
*/
|
||||
ReturnValue_t handleTmReception(size_t remainingBytes, uint8_t* readBuf = nullptr,
|
||||
uint32_t timeout = 70000);
|
||||
ReturnValue_t checkReceivedTm();
|
||||
|
||||
ReturnValue_t selectMemory();
|
||||
ReturnValue_t prepareUpdate();
|
||||
ReturnValue_t eraseMemory();
|
||||
// Calculates CRC over image. Will be used for verification after update writing has
|
||||
// finished.
|
||||
ReturnValue_t calcImageCrc();
|
||||
ReturnValue_t handleCheckMemoryCommand(uint8_t failStep);
|
||||
ReturnValue_t exeReportHandling();
|
||||
/**
|
||||
* @brief Return size of file with name filename
|
||||
*
|
||||
* @param filename
|
||||
*
|
||||
* @return The size of the file
|
||||
*/
|
||||
uint32_t getFileSize(std::string filename);
|
||||
ReturnValue_t handleEventBufferReception(ploc::SpTmReader& reader);
|
||||
|
||||
void resetSpParams();
|
||||
void pushIpcData(const uint8_t* data, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Device specific initialization, using the cookie.
|
||||
* @details
|
||||
* The cookie is already prepared in the factory. If the communication
|
||||
* interface needs to be set up in some way and requires cookie information,
|
||||
* this can be performed in this function, which is called on device handler
|
||||
* initialization.
|
||||
* @param cookie
|
||||
* @return
|
||||
* - @c returnvalue::OK if initialization was successfull
|
||||
* - Everything else triggers failure event with returnvalue as parameter 1
|
||||
*/
|
||||
ReturnValue_t initializeInterface(CookieIF* cookie) override;
|
||||
|
||||
/**
|
||||
* Called by DHB in the SEND_WRITE doSendWrite().
|
||||
* This function is used to send data to the physical device
|
||||
* by implementing and calling related drivers or wrapper functions.
|
||||
* @param cookie
|
||||
* @param data
|
||||
* @param len If this is 0, nothing shall be sent.
|
||||
* @return
|
||||
* - @c returnvalue::OK for successfull send
|
||||
* - Everything else triggers failure event with returnvalue as parameter 1
|
||||
*/
|
||||
ReturnValue_t sendMessage(CookieIF* cookie, const uint8_t* sendData, size_t sendLen) override;
|
||||
/**
|
||||
* Called by DHB in the GET_WRITE doGetWrite().
|
||||
* Get send confirmation that the data in sendMessage() was sent successfully.
|
||||
* @param cookie
|
||||
* @return
|
||||
* - @c returnvalue::OK if data was sent successfully but a reply is expected
|
||||
* - NO_REPLY_EXPECTED if data was sent successfully and no reply is expected
|
||||
* - Everything else to indicate failure
|
||||
*/
|
||||
ReturnValue_t getSendSuccess(CookieIF* cookie) override;
|
||||
/**
|
||||
* Called by DHB in the SEND_WRITE doSendRead().
|
||||
* It is assumed that it is always possible to request a reply
|
||||
* from a device. If a requestLen of 0 is supplied, no reply was enabled
|
||||
* and communication specific action should be taken (e.g. read nothing
|
||||
* or read everything).
|
||||
*
|
||||
* @param cookie
|
||||
* @param requestLen Size of data to read
|
||||
* @return - @c returnvalue::OK to confirm the request for data has been sent.
|
||||
* - Everything else triggers failure event with
|
||||
* returnvalue as parameter 1
|
||||
*/
|
||||
ReturnValue_t requestReceiveMessage(CookieIF* cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) override;
|
||||
|
||||
void performUartShutdown();
|
||||
void updateVtime(uint8_t vtime);
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_DEVICES_PLOCSUPVHELPER_H_ */
|
7
linux/payload/ScexDleParser.cpp
Normal file
7
linux/payload/ScexDleParser.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include <linux/payload/ScexDleParser.h>
|
||||
|
||||
ScexDleParser::ScexDleParser(SimpleRingBuffer &decodeRingBuf, DleEncoder &decoder,
|
||||
BufPair encodedBuf, BufPair decodedBuf)
|
||||
: DleParser(decodeRingBuf, decoder, encodedBuf, decodedBuf){};
|
||||
|
||||
ScexDleParser::~ScexDleParser(){};
|
13
linux/payload/ScexDleParser.h
Normal file
13
linux/payload/ScexDleParser.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/globalfunctions/DleParser.h>
|
||||
|
||||
class ScexDleParser : public DleParser {
|
||||
public:
|
||||
ScexDleParser(SimpleRingBuffer &decodeRingBuf, DleEncoder &decoder, BufPair encodedBuf,
|
||||
BufPair decodedBuf);
|
||||
|
||||
virtual ~ScexDleParser();
|
||||
|
||||
private:
|
||||
};
|
85
linux/payload/ScexHelper.cpp
Normal file
85
linux/payload/ScexHelper.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include <fsfw/globalfunctions/CRC.h>
|
||||
#include <linux/payload/ScexHelper.h>
|
||||
|
||||
#include "fsfw/serviceinterface.h"
|
||||
|
||||
using namespace returnvalue;
|
||||
|
||||
ScexHelper::ScexHelper() {}
|
||||
|
||||
ReturnValue_t ScexHelper::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
|
||||
Endianness streamEndianness) const {
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
size_t ScexHelper::getSerializedSize() const { return totalPacketLen; }
|
||||
|
||||
ReturnValue_t ScexHelper::deSerialize(const uint8_t** buffer, size_t* size,
|
||||
Endianness streamEndianness) {
|
||||
if (buffer == nullptr or size == nullptr) {
|
||||
return FAILED;
|
||||
}
|
||||
if (*size < 7) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
start = *buffer;
|
||||
cmdByteRaw = **buffer;
|
||||
cmd = static_cast<scex::Cmds>((cmdByteRaw >> 1) & 0b11111);
|
||||
|
||||
*buffer += 1;
|
||||
packetCounter = **buffer;
|
||||
|
||||
*buffer += 1;
|
||||
totalPacketCounter = **buffer;
|
||||
|
||||
*buffer += 1;
|
||||
payloadLen = (**buffer << 8) | *(*buffer + 1);
|
||||
|
||||
*buffer += 2;
|
||||
payloadStart = *buffer;
|
||||
totalPacketLen = payloadLen + scex::HEADER_LEN + scex::CRC_LEN;
|
||||
if (totalPacketLen >= *size) {
|
||||
return STREAM_TOO_SHORT;
|
||||
}
|
||||
*buffer += payloadLen;
|
||||
crc = (**buffer << 8) | *(*buffer + 1);
|
||||
if (CRC::crc16ccitt(start, totalPacketLen) != 0) {
|
||||
return INVALID_CRC;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
scex::Cmds ScexHelper::getCmd() const { return cmd; }
|
||||
|
||||
uint8_t ScexHelper::getCmdByteRaw() const { return cmdByteRaw; }
|
||||
|
||||
uint16_t ScexHelper::getCrc() const { return crc; }
|
||||
|
||||
size_t ScexHelper::getExpectedPacketLen() const { return totalPacketLen; }
|
||||
|
||||
uint8_t ScexHelper::getPacketCounter() const { return packetCounter; }
|
||||
|
||||
uint16_t ScexHelper::getPayloadLen() const { return payloadLen; }
|
||||
|
||||
const uint8_t* ScexHelper::getStart() const { return start; }
|
||||
|
||||
uint8_t ScexHelper::getTotalPacketCounter() const { return totalPacketCounter; }
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const ScexHelper& h) {
|
||||
using namespace std;
|
||||
sif::info << "Command Byte Raw: 0x" << std::setw(2) << std::setfill('0') << std::hex
|
||||
<< (int)h.cmdByteRaw << " | Command: 0x" << std::setw(2) << std::setfill('0')
|
||||
<< std::hex << static_cast<int>(h.cmd) << std::dec << std::endl;
|
||||
sif::info << "PacketCounter: " << h.packetCounter << endl;
|
||||
sif::info << "TotalPacketCount: " << h.totalPacketCounter << endl;
|
||||
sif::info << "PayloadLength: " << h.payloadLen << endl;
|
||||
sif::info << "TotalPacketLength: " << h.totalPacketLen;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ofstream& operator<<(std::ofstream& of, const ScexHelper& h) {
|
||||
of.write(reinterpret_cast<const char*>(h.start), h.getSerializedSize());
|
||||
|
||||
return of;
|
||||
}
|
46
linux/payload/ScexHelper.h
Normal file
46
linux/payload/ScexHelper.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef LINUX_PAYLOAD_SCEXHELPER_H_
|
||||
#define LINUX_PAYLOAD_SCEXHELPER_H_
|
||||
#include <fsfw/serialize/SerializeIF.h>
|
||||
#include <mission/payload/scexHelpers.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
class ScexHelper : public SerializeIF {
|
||||
public:
|
||||
static const ReturnValue_t INVALID_CRC = returnvalue::makeCode(0, 2);
|
||||
|
||||
ScexHelper();
|
||||
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
Endianness streamEndianness) const override;
|
||||
|
||||
size_t getSerializedSize() const override;
|
||||
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
|
||||
Endianness streamEndianness = Endianness::BIG) override;
|
||||
friend std::ostream &operator<<(std::ostream &os, const ScexHelper &h);
|
||||
friend std::ofstream &operator<<(std::ofstream &os, const ScexHelper &h);
|
||||
|
||||
scex::Cmds getCmd() const;
|
||||
uint8_t getCmdByteRaw() const;
|
||||
uint16_t getCrc() const;
|
||||
size_t getExpectedPacketLen() const;
|
||||
uint8_t getPacketCounter() const;
|
||||
uint16_t getPayloadLen() const;
|
||||
const uint8_t *getStart() const;
|
||||
uint8_t getTotalPacketCounter() const;
|
||||
|
||||
private:
|
||||
const uint8_t *start = nullptr;
|
||||
uint16_t crc = 0;
|
||||
uint8_t cmdByteRaw = 0;
|
||||
scex::Cmds cmd = scex::Cmds::INVALID;
|
||||
int packetCounter = 0;
|
||||
int totalPacketCounter = 0;
|
||||
uint16_t payloadLen = 0;
|
||||
const uint8_t *payloadStart = 0;
|
||||
size_t totalPacketLen = 0;
|
||||
};
|
||||
|
||||
#endif /* LINUX_PAYLOAD_SCEXHELPER_H_ */
|
228
linux/payload/ScexUartReader.cpp
Normal file
228
linux/payload/ScexUartReader.cpp
Normal file
@ -0,0 +1,228 @@
|
||||
#include <fcntl.h> // Contains file controls like O_RDWR
|
||||
#include <fsfw/globalfunctions/arrayprinter.h>
|
||||
#include <fsfw/ipc/MutexFactory.h>
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
#include <fsfw/tasks/SemaphoreFactory.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw_hal/linux/serial/SerialCookie.h>
|
||||
#include <linux/payload/ScexUartReader.h>
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include <cerrno> // Error integer and strerror() function
|
||||
#include <iostream>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
|
||||
using namespace returnvalue;
|
||||
|
||||
ScexUartReader::ScexUartReader(object_id_t objectId)
|
||||
: SystemObject(objectId),
|
||||
decodeRingBuf(4096, true),
|
||||
ipcRingBuf(200 * 2048, true),
|
||||
ipcQueue(200),
|
||||
dleParser(decodeRingBuf, dleEncoder, {encodedBuf.data(), encodedBuf.size()},
|
||||
{decodedBuf.data(), decodedBuf.size()}) {
|
||||
semaphore = SemaphoreFactory::instance()->createBinarySemaphore();
|
||||
semaphore->acquire();
|
||||
lock = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::performOperation(uint8_t operationCode) {
|
||||
lock->lockMutex();
|
||||
state = States::IDLE;
|
||||
lock->unlockMutex();
|
||||
while (true) {
|
||||
semaphore->acquire();
|
||||
int bytesRead = 0;
|
||||
// debugMode = true;
|
||||
while (true) {
|
||||
bytesRead = read(serialPort, reinterpret_cast<void *>(recBuf.data()),
|
||||
static_cast<unsigned int>(recBuf.size()));
|
||||
if (bytesRead == 0) {
|
||||
{
|
||||
MutexGuard mg(lock);
|
||||
if (state == States::FINISH) {
|
||||
dleParser.reset();
|
||||
// Flush received and unread data
|
||||
tcflush(serialPort, TCIOFLUSH);
|
||||
state = States::IDLE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
// Can be used to read frame, parity and overrun errors
|
||||
// serial_icounter_struct icounter{};
|
||||
// uart::readCountersAndErrors(serialPort, icounter);
|
||||
while (result != DleParser::NO_PACKET_FOUND) {
|
||||
result = tryDleParsing();
|
||||
}
|
||||
|
||||
TaskFactory::delayTask(150);
|
||||
} else if (bytesRead < 0) {
|
||||
sif::warning << "ScexUartReader::performOperation: read call failed with error [" << errno
|
||||
<< ", " << strerror(errno) << "]" << std::endl;
|
||||
break;
|
||||
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
|
||||
sif::error << "ScexUartReader::performOperation: Receive buffer too small for " << bytesRead
|
||||
<< " bytes" << std::endl;
|
||||
} else if (bytesRead > 0) {
|
||||
if (debugMode) {
|
||||
sif::info << "Received " << bytesRead
|
||||
<< " bytes from the Solar Cell Experiment:" << std::endl;
|
||||
}
|
||||
ReturnValue_t result = dleParser.passData(recBuf.data(), bytesRead);
|
||||
if (result != OK) {
|
||||
sif::warning << "ScexUartReader::performOperation: Passing data to DLE parser failed"
|
||||
<< std::endl;
|
||||
}
|
||||
result = tryDleParsing();
|
||||
}
|
||||
};
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::initializeInterface(CookieIF *cookie) {
|
||||
SerialCookie *uartCookie = dynamic_cast<SerialCookie *>(cookie);
|
||||
if (uartCookie == nullptr) {
|
||||
return FAILED;
|
||||
}
|
||||
std::string devname = uartCookie->getDeviceFile();
|
||||
/* Get file descriptor */
|
||||
serialPort = open(devname.c_str(), O_RDWR);
|
||||
if (serialPort < 0) {
|
||||
sif::warning << "ScexUartReader::initializeInterface: open call failed with error [" << errno
|
||||
<< ", " << strerror(errno) << std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
// Setting up UART parameters
|
||||
tty.c_cflag &= ~PARENB; // Clear parity bit
|
||||
serial::setStopbits(tty, uartCookie->getStopBits());
|
||||
serial::setBitsPerWord(tty, BitsPerWord::BITS_8);
|
||||
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
|
||||
serial::enableRead(tty);
|
||||
serial::ignoreCtrlLines(tty);
|
||||
|
||||
// Use non-canonical mode and clear echo flag
|
||||
tty.c_lflag &= ~(ICANON | ECHO);
|
||||
|
||||
// Non-blocking mode, use polling
|
||||
tty.c_cc[VTIME] = 0;
|
||||
tty.c_cc[VMIN] = 0;
|
||||
|
||||
serial::setBaudrate(tty, uartCookie->getBaudrate());
|
||||
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
|
||||
sif::warning << "ScexUartReader::initializeInterface: tcsetattr call failed with error ["
|
||||
<< errno << ", " << strerror(errno) << std::endl;
|
||||
}
|
||||
// Flush received and unread data
|
||||
tcflush(serialPort, TCIOFLUSH);
|
||||
return OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendData,
|
||||
size_t sendLen) {
|
||||
ReturnValue_t result;
|
||||
if (sendData == nullptr or sendLen == 0) {
|
||||
return FAILED;
|
||||
}
|
||||
lock->lockMutex();
|
||||
if (state == States::NOT_READY or state == States::RUNNING) {
|
||||
lock->unlockMutex();
|
||||
return FAILED;
|
||||
}
|
||||
tcflush(serialPort, TCIFLUSH);
|
||||
state = States::RUNNING;
|
||||
lock->unlockMutex();
|
||||
|
||||
result = semaphore->release();
|
||||
if (result != OK) {
|
||||
std::cout << "ScexUartReader::sendMessage: Releasing semaphore failed" << std::endl;
|
||||
}
|
||||
size_t encodedLen = 0;
|
||||
result = dleEncoder.encode(sendData, sendLen, cmdbuf.data(), cmdbuf.size(), &encodedLen, true);
|
||||
if (result != OK) {
|
||||
sif::warning << "ScexUartReader::sendMessage: Encoding failed" << std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen);
|
||||
if (bytesWritten != encodedLen) {
|
||||
sif::warning << "ScexUartReader::sendMessage: Sending command failed" << std::endl;
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::getSendSuccess(CookieIF *cookie) { return OK; }
|
||||
|
||||
ReturnValue_t ScexUartReader::requestReceiveMessage(CookieIF *cookie, size_t requestLen) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ScexUartReader::setDebugMode(bool enable) { this->debugMode = enable; }
|
||||
|
||||
ReturnValue_t ScexUartReader::finish() {
|
||||
MutexGuard mg(lock);
|
||||
if (state == States::IDLE) {
|
||||
return FAILED;
|
||||
}
|
||||
state = States::FINISH;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ScexUartReader::handleFoundDlePacket(uint8_t *packet, size_t len) {
|
||||
MutexGuard mg(lock);
|
||||
ReturnValue_t result = ipcQueue.insert(len);
|
||||
if (result != OK) {
|
||||
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCQueue error" << std::endl;
|
||||
}
|
||||
result = ipcRingBuf.writeData(packet, len);
|
||||
if (result != OK) {
|
||||
sif::warning << "ScexUartReader::handleFoundDlePacket: IPCRingBuf error" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::tryDleParsing() {
|
||||
size_t bytesRead = 0;
|
||||
ReturnValue_t result = dleParser.parseRingBuf(bytesRead);
|
||||
if (result == returnvalue::OK) {
|
||||
// Packet found, advance read pointer.
|
||||
auto &decodedPacket = dleParser.getContext().decodedPacket;
|
||||
handleFoundDlePacket(decodedPacket.first, decodedPacket.second);
|
||||
dleParser.confirmBytesRead(bytesRead);
|
||||
} else if (result != DleParser::NO_PACKET_FOUND) {
|
||||
sif::warning << "ScexUartReader::performOperation: Possible packet loss" << std::endl;
|
||||
// Markers found at wrong place
|
||||
// which might be a hint for a possibly lost packet.
|
||||
dleParser.defaultErrorHandler();
|
||||
dleParser.confirmBytesRead(bytesRead);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void ScexUartReader::reset() {
|
||||
lock->lockMutex();
|
||||
state = States::FINISH;
|
||||
ipcRingBuf.clear();
|
||||
while (not ipcQueue.empty()) {
|
||||
ipcQueue.pop();
|
||||
}
|
||||
lock->unlockMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t ScexUartReader::readReceivedMessage(CookieIF *cookie, uint8_t **buffer,
|
||||
size_t *size) {
|
||||
MutexGuard mg(lock);
|
||||
if (ipcQueue.empty()) {
|
||||
*size = 0;
|
||||
return OK;
|
||||
}
|
||||
ipcQueue.retrieve(size);
|
||||
*buffer = ipcBuffer.data();
|
||||
ReturnValue_t result = ipcRingBuf.readData(ipcBuffer.data(), *size, true);
|
||||
if (result != OK) {
|
||||
sif::warning << "ScexUartReader::readReceivedMessage: Reading RingBuffer failed" << std::endl;
|
||||
}
|
||||
return OK;
|
||||
}
|
61
linux/payload/ScexUartReader.h
Normal file
61
linux/payload/ScexUartReader.h
Normal file
@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/container/DynamicFIFO.h>
|
||||
#include <fsfw/container/SimpleRingBuffer.h>
|
||||
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
|
||||
#include <fsfw/globalfunctions/DleEncoder.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
#include <linux/payload/ScexDleParser.h>
|
||||
#include <termios.h> // Contains POSIX terminal control definitions
|
||||
|
||||
class SemaphoreIF;
|
||||
class MutexIF;
|
||||
|
||||
class ScexUartReader : public SystemObject,
|
||||
public ExecutableObjectIF,
|
||||
public DeviceCommunicationIF {
|
||||
friend class UartTestClass;
|
||||
|
||||
public:
|
||||
enum class States { NOT_READY, IDLE, RUNNING, FINISH };
|
||||
ScexUartReader(object_id_t objectId);
|
||||
|
||||
void reset();
|
||||
ReturnValue_t finish();
|
||||
void setDebugMode(bool enable);
|
||||
|
||||
private:
|
||||
SemaphoreIF *semaphore;
|
||||
bool debugMode = false;
|
||||
MutexIF *lock;
|
||||
int serialPort = 0;
|
||||
States state = States::IDLE;
|
||||
struct termios tty = {};
|
||||
bool doFinish = false;
|
||||
DleEncoder dleEncoder = DleEncoder();
|
||||
SimpleRingBuffer decodeRingBuf;
|
||||
|
||||
std::array<uint8_t, 256> cmdbuf = {};
|
||||
std::array<uint8_t, 4096> recBuf = {};
|
||||
std::array<uint8_t, 4096> encodedBuf = {};
|
||||
std::array<uint8_t, 4096> decodedBuf = {};
|
||||
std::array<uint8_t, 4096> ipcBuffer = {};
|
||||
SimpleRingBuffer ipcRingBuf;
|
||||
DynamicFIFO<size_t> ipcQueue;
|
||||
ScexDleParser dleParser;
|
||||
|
||||
static void foundDlePacketHandler(const DleParser::Context &ctx);
|
||||
void handleFoundDlePacket(uint8_t *packet, size_t len);
|
||||
ReturnValue_t tryDleParsing();
|
||||
|
||||
ReturnValue_t performOperation(uint8_t operationCode = 0) override;
|
||||
|
||||
// DeviceCommunicationIF implementation
|
||||
ReturnValue_t initializeInterface(CookieIF *cookie) override;
|
||||
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
|
||||
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
|
||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
|
||||
};
|
33
linux/payload/mpsocRetvals.h
Normal file
33
linux/payload/mpsocRetvals.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef MPSOC_RETURN_VALUES_IF_H_
|
||||
#define MPSOC_RETURN_VALUES_IF_H_
|
||||
|
||||
#include "eive/resultClassIds.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
class MPSoCReturnValuesIF {
|
||||
public:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::MPSOC_RETURN_VALUES_IF;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Space Packet received from PLOC has invalid CRC
|
||||
static const ReturnValue_t CRC_FAILURE = MAKE_RETURN_CODE(0xA0);
|
||||
//! [EXPORT] : [COMMENT] Received ACK failure reply from PLOC
|
||||
static const ReturnValue_t RECEIVED_ACK_FAILURE = MAKE_RETURN_CODE(0xA1);
|
||||
//! [EXPORT] : [COMMENT] Received execution failure reply from PLOC
|
||||
static const ReturnValue_t RECEIVED_EXE_FAILURE = MAKE_RETURN_CODE(0xA2);
|
||||
//! [EXPORT] : [COMMENT] Received space packet with invalid APID from PLOC
|
||||
static const ReturnValue_t INVALID_APID = MAKE_RETURN_CODE(0xA3);
|
||||
//! [EXPORT] : [COMMENT] Received command with invalid length
|
||||
static const ReturnValue_t INVALID_LENGTH = MAKE_RETURN_CODE(0xA4);
|
||||
//! [EXPORT] : [COMMENT] Filename of file in OBC filesystem is too long
|
||||
static const ReturnValue_t FILENAME_TOO_LONG = MAKE_RETURN_CODE(0xA5);
|
||||
//! [EXPORT] : [COMMENT] MPSoC helper is currently executing a command
|
||||
static const ReturnValue_t MPSOC_HELPER_EXECUTING = MAKE_RETURN_CODE(0xA6);
|
||||
//! [EXPORT] : [COMMENT] Filename of MPSoC file is to long (max. 256 bytes)
|
||||
static const ReturnValue_t MPSOC_FILENAME_TOO_LONG = MAKE_RETURN_CODE(0xA7);
|
||||
//! [EXPORT] : [COMMENT] Command has invalid parameter
|
||||
static const ReturnValue_t INVALID_PARAMETER = MAKE_RETURN_CODE(0xA8);
|
||||
//! [EXPORT] : [COMMENT] Received command has file string with invalid length
|
||||
static const ReturnValue_t NAME_TOO_LONG = MAKE_RETURN_CODE(0xA9);
|
||||
};
|
||||
|
||||
#endif /* MPSOC_RETURN_VALUES_IF_H_ */
|
28
linux/payload/plocMemDumpDefs.h
Normal file
28
linux/payload/plocMemDumpDefs.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef BSP_Q7S_DEVICES_DEVICEDEFINITIONS_PLOCMEMDUMPDEFINITIONS_H_
|
||||
#define BSP_Q7S_DEVICES_DEVICEDEFINITIONS_PLOCMEMDUMPDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/src/fsfw/serialize/SerialLinkedListAdapter.h>
|
||||
|
||||
class MemoryParams : public SerialLinkedListAdapter<SerializeIF> {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param startAddress Start of address range to dump
|
||||
* @param endAddress End of address range to dump
|
||||
*/
|
||||
MemoryParams(uint32_t startAddress, uint32_t endAddress)
|
||||
: startAddress(startAddress), endAddress(endAddress) {
|
||||
setLinks();
|
||||
}
|
||||
|
||||
private:
|
||||
void setLinks() {
|
||||
setStart(&startAddress);
|
||||
startAddress.setNext(&endAddress);
|
||||
}
|
||||
|
||||
SerializeElement<uint32_t> startAddress;
|
||||
SerializeElement<uint32_t> endAddress;
|
||||
};
|
||||
|
||||
#endif /* BSP_Q7S_DEVICES_DEVICEDEFINITIONS_PLOCMEMDUMPDEFINITIONS_H_ */
|
779
linux/payload/plocMpscoDefs.h
Normal file
779
linux/payload/plocMpscoDefs.h
Normal file
@ -0,0 +1,779 @@
|
||||
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
|
||||
#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
|
||||
|
||||
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
|
||||
#include <linux/payload/mpsocRetvals.h>
|
||||
#include <mission/payload/plocSpBase.h>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "eive/definitions.h"
|
||||
#include "fsfw/globalfunctions/CRC.h"
|
||||
#include "fsfw/serialize/SerializeAdapter.h"
|
||||
|
||||
namespace mpsoc {
|
||||
|
||||
static const DeviceCommandId_t NONE = 0;
|
||||
static const DeviceCommandId_t TC_MEM_WRITE = 1;
|
||||
static const DeviceCommandId_t TC_MEM_READ = 2;
|
||||
static const DeviceCommandId_t ACK_REPORT = 3;
|
||||
static const DeviceCommandId_t EXE_REPORT = 5;
|
||||
static const DeviceCommandId_t TM_MEMORY_READ_REPORT = 6;
|
||||
static const DeviceCommandId_t TC_FLASHFOPEN = 7;
|
||||
static const DeviceCommandId_t TC_FLASHFCLOSE = 8;
|
||||
static const DeviceCommandId_t TC_FLASHWRITE = 9;
|
||||
static const DeviceCommandId_t TC_FLASHDELETE = 10;
|
||||
static const DeviceCommandId_t TC_REPLAY_START = 11;
|
||||
static const DeviceCommandId_t TC_REPLAY_STOP = 12;
|
||||
static const DeviceCommandId_t TC_REPLAY_WRITE_SEQUENCE = 13;
|
||||
static const DeviceCommandId_t TC_DOWNLINK_PWR_ON = 14;
|
||||
static const DeviceCommandId_t TC_DOWNLINK_PWR_OFF = 15;
|
||||
static const DeviceCommandId_t TC_MODE_REPLAY = 16;
|
||||
static const DeviceCommandId_t TC_CAM_CMD_SEND = 17;
|
||||
static const DeviceCommandId_t TC_MODE_IDLE = 18;
|
||||
static const DeviceCommandId_t TM_CAM_CMD_RPT = 19;
|
||||
static const DeviceCommandId_t SET_UART_TX_TRISTATE = 20;
|
||||
static const DeviceCommandId_t RELEASE_UART_TX = 21;
|
||||
static const DeviceCommandId_t TC_CAM_TAKE_PIC = 22;
|
||||
static const DeviceCommandId_t TC_SIMPLEX_SEND_FILE = 23;
|
||||
static const DeviceCommandId_t TC_DOWNLINK_DATA_MODULATE = 24;
|
||||
static const DeviceCommandId_t TC_MODE_SNAPSHOT = 25;
|
||||
|
||||
// Will reset the sequence count of the OBSW
|
||||
static const DeviceCommandId_t OBSW_RESET_SEQ_COUNT = 50;
|
||||
|
||||
static const uint16_t SIZE_ACK_REPORT = 14;
|
||||
static const uint16_t SIZE_EXE_REPORT = 14;
|
||||
static const uint16_t SIZE_TM_MEM_READ_REPORT = 18;
|
||||
static const uint16_t SIZE_TM_CAM_CMD_RPT = 18;
|
||||
|
||||
/**
|
||||
* SpacePacket apids of PLOC telecommands and telemetry.
|
||||
*/
|
||||
namespace apid {
|
||||
static const uint16_t TC_REPLAY_START = 0x110;
|
||||
static const uint16_t TC_REPLAY_STOP = 0x111;
|
||||
static const uint16_t TC_REPLAY_WRITE_SEQUENCE = 0x112;
|
||||
static const uint16_t TC_DOWNLINK_PWR_ON = 0x113;
|
||||
static const uint16_t TC_MEM_WRITE = 0x114;
|
||||
static const uint16_t TC_MEM_READ = 0x115;
|
||||
static const uint16_t TC_CAM_TAKE_PIC = 0x116;
|
||||
static const uint16_t TC_FLASHWRITE = 0x117;
|
||||
static const uint16_t TC_FLASHFOPEN = 0x119;
|
||||
static const uint16_t TC_FLASHFCLOSE = 0x11A;
|
||||
static const uint16_t TC_FLASHDELETE = 0x11C;
|
||||
static const uint16_t TC_MODE_IDLE = 0x11E;
|
||||
static const uint16_t TC_MODE_REPLAY = 0x11F;
|
||||
static const uint16_t TC_MODE_SNAPSHOT = 0x120;
|
||||
static const uint16_t TC_DOWNLINK_DATA_MODULATE = 0x121;
|
||||
static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124;
|
||||
static const uint16_t TC_CAM_CMD_SEND = 0x12C;
|
||||
static const uint16_t TC_SIMPLEX_SEND_FILE = 0x130;
|
||||
static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
|
||||
static const uint16_t ACK_SUCCESS = 0x400;
|
||||
static const uint16_t ACK_FAILURE = 0x401;
|
||||
static const uint16_t EXE_SUCCESS = 0x402;
|
||||
static const uint16_t EXE_FAILURE = 0x403;
|
||||
static const uint16_t TM_CAM_CMD_RPT = 0x407;
|
||||
} // namespace apid
|
||||
|
||||
/** Offset from first byte in space packet to first byte of data field */
|
||||
static const uint8_t DATA_FIELD_OFFSET = 6;
|
||||
static const size_t MEM_READ_RPT_LEN_OFFSET = 10;
|
||||
static const char NULL_TERMINATOR = '\0';
|
||||
static const uint8_t MIN_SPACE_PACKET_LENGTH = 7;
|
||||
static const uint8_t SPACE_PACKET_HEADER_SIZE = 6;
|
||||
|
||||
static constexpr size_t CRC_SIZE = 2;
|
||||
|
||||
/**
|
||||
* The size of payload data which will be forwarded to the requesting object. e.g. PUS Service
|
||||
* 8.
|
||||
*/
|
||||
static const uint8_t SIZE_MEM_READ_RPT_FIX = 6;
|
||||
|
||||
static const size_t MAX_FILENAME_SIZE = 256;
|
||||
|
||||
/**
|
||||
* PLOC space packet length for fixed size packets. This is the size of the whole packet data
|
||||
* field. For the length field in the space packet this size will be substracted by one.
|
||||
*/
|
||||
static const uint16_t LENGTH_TC_MEM_WRITE = 12;
|
||||
static const uint16_t LENGTH_TC_MEM_READ = 8;
|
||||
|
||||
/**
|
||||
* Maximum SP packet size as specified in the TAS Supversior ICD.
|
||||
* https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_TAS-ILH-IRS/ICD-PLOC/TAS&fileid=942896
|
||||
* at sheet README
|
||||
*/
|
||||
static constexpr size_t SP_MAX_SIZE = 1024;
|
||||
static const size_t MAX_REPLY_SIZE = SP_MAX_SIZE * 3;
|
||||
static const size_t MAX_COMMAND_SIZE = SP_MAX_SIZE;
|
||||
static const size_t MAX_DATA_SIZE = 1016;
|
||||
|
||||
/**
|
||||
* The replay write sequence command has a maximum delay for the execution report which amounts to
|
||||
* 30 seconds. (80 cycles * 0.5 seconds = 40 seconds).
|
||||
*/
|
||||
static const uint16_t TC_WRITE_SEQ_EXECUTION_DELAY = 80;
|
||||
// Requires approx. 2 seconds for execution. 8 => 4 seconds
|
||||
static const uint16_t TC_DOWNLINK_PWR_ON_EXECUTION_DELAY = 8;
|
||||
static const uint16_t TC_CAM_TAKE_PIC_EXECUTION_DELAY = 20;
|
||||
static const uint16_t TC_SIMPLEX_SEND_FILE_DELAY = 80;
|
||||
|
||||
namespace status_code {
|
||||
static const uint16_t DEFAULT_ERROR_CODE = 0x1;
|
||||
static const uint16_t UNKNOWN_APID = 0x5DD;
|
||||
static const uint16_t INCORRECT_LENGTH = 0x5DE;
|
||||
static const uint16_t INCORRECT_CRC = 0x5DF;
|
||||
static const uint16_t INCORRECT_PKT_SEQ_CNT = 0x5E0;
|
||||
static const uint16_t TC_NOT_ALLOWED_IN_MODE = 0x5E1;
|
||||
static const uint16_t TC_EXEUTION_DISABLED = 0x5E2;
|
||||
static const uint16_t FLASH_MOUNT_FAILED = 0x5E3;
|
||||
static const uint16_t FLASH_FILE_ALREADY_CLOSED = 0x5E4;
|
||||
static const uint16_t FLASH_FILE_OPEN_FAILED = 0x5E5;
|
||||
static const uint16_t FLASH_FILE_ALREDY_OPEN = 0x5E6;
|
||||
static const uint16_t FLASH_FILE_NOT_OPEN = 0x5E7;
|
||||
static const uint16_t FLASH_UNMOUNT_FAILED = 0x5E8;
|
||||
static const uint16_t HEAP_ALLOCATION_FAILED = 0x5E9;
|
||||
static const uint16_t INVALID_PARAMETER = 0x5EA;
|
||||
static const uint16_t NOT_INITIALIZED = 0x5EB;
|
||||
static const uint16_t REBOOT_IMMINENT = 0x5EC;
|
||||
static const uint16_t CORRUPT_DATA = 0x5ED;
|
||||
static const uint16_t FLASH_CORRECTABLE_MISMATCH = 0x5EE;
|
||||
static const uint16_t FLASH_UNCORRECTABLE_MISMATCH = 0x5EF;
|
||||
static const uint16_t RESERVED_0 = 0x5F0;
|
||||
static const uint16_t RESERVED_1 = 0x5F1;
|
||||
static const uint16_t RESERVED_2 = 0x5F2;
|
||||
static const uint16_t RESERVED_3 = 0x5F3;
|
||||
static const uint16_t RESERVED_4 = 0x5F4;
|
||||
} // namespace status_code
|
||||
|
||||
/**
|
||||
* @brief Abstract base class for TC space packet of MPSoC.
|
||||
*/
|
||||
class TcBase : public ploc::SpTcBase, public MPSoCReturnValuesIF {
|
||||
public:
|
||||
virtual ~TcBase() = default;
|
||||
|
||||
// Initial length field of space packet. Will always be updated when packet is created.
|
||||
static const uint16_t INIT_LENGTH = 2;
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param sequenceCount Sequence count of space packet which will be incremented with each
|
||||
* sent and received packets.
|
||||
*/
|
||||
TcBase(ploc::SpTcParams params, uint16_t apid, uint16_t sequenceCount)
|
||||
: ploc::SpTcBase(params, apid, 0, sequenceCount) {
|
||||
spParams.setFullPayloadLen(INIT_LENGTH);
|
||||
}
|
||||
|
||||
ReturnValue_t buildPacket() { return buildPacket(nullptr, 0); }
|
||||
|
||||
/**
|
||||
* @brief Function to initialize the space packet
|
||||
*
|
||||
* @param commandData Pointer to command specific data
|
||||
* @param commandDataLen Length of command data
|
||||
*
|
||||
* @return returnvalue::OK if packet creation was successful, otherwise error return value
|
||||
*/
|
||||
ReturnValue_t buildPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
payloadStart = spParams.buf + ccsds::HEADER_LEN;
|
||||
ReturnValue_t res;
|
||||
if (commandData != nullptr and commandDataLen > 0) {
|
||||
res = initPacket(commandData, commandDataLen);
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
updateSpFields();
|
||||
res = checkSizeAndSerializeHeader();
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
return calcAndSetCrc();
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Must be overwritten by the child class to define the command specific parameters
|
||||
*
|
||||
* @param commandData Pointer to received command data
|
||||
* @param commandDataLen Length of received command data
|
||||
*/
|
||||
virtual ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to build the memory read command for the PLOC.
|
||||
*/
|
||||
class TcMemRead : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TcMemRead(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_MEM_READ, sequenceCount) {
|
||||
spParams.setFullPayloadLen(COMMAND_LENGTH + CRC_SIZE);
|
||||
}
|
||||
|
||||
uint16_t getMemLen() const { return memLen; }
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, commandData, MEM_ADDRESS_SIZE);
|
||||
std::memcpy(payloadStart + MEM_ADDRESS_SIZE, commandData + MEM_ADDRESS_SIZE, MEM_LEN_SIZE);
|
||||
size_t size = sizeof(memLen);
|
||||
const uint8_t* memLenPtr = commandData + MEM_ADDRESS_SIZE;
|
||||
result =
|
||||
SerializeAdapter::deSerialize(&memLen, &memLenPtr, &size, SerializeIF::Endianness::BIG);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t COMMAND_LENGTH = 6;
|
||||
static const size_t MEM_ADDRESS_SIZE = 4;
|
||||
static const size_t MEM_LEN_SIZE = 2;
|
||||
static const uint16_t PACKET_LENGTH = 7;
|
||||
|
||||
uint16_t memLen = 0;
|
||||
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen != COMMAND_LENGTH or checkPayloadLen() != returnvalue::OK) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to generate the space packet to write data to a memory address within
|
||||
* the PLOC.
|
||||
*/
|
||||
class TcMemWrite : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TcMemWrite(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_MEM_WRITE, sequenceCount) {}
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
uint16_t memLen =
|
||||
*(commandData + MEM_ADDRESS_SIZE) << 8 | *(commandData + MEM_ADDRESS_SIZE + 1);
|
||||
spParams.setFullPayloadLen(MIN_FIXED_PAYLOAD_LENGTH + memLen * 4 + CRC_SIZE);
|
||||
result = checkPayloadLen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
// 4 byte address, 2 byte mem length field
|
||||
static const size_t MEM_ADDRESS_SIZE = 4;
|
||||
static const size_t MIN_FIXED_PAYLOAD_LENGTH = MEM_ADDRESS_SIZE + 2;
|
||||
// Min length consists of 4 byte address, 2 byte mem length field, 4 byte data (1 word)
|
||||
static const size_t MIN_COMMAND_DATA_LENGTH = MIN_FIXED_PAYLOAD_LENGTH + 4;
|
||||
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen < MIN_COMMAND_DATA_LENGTH) {
|
||||
sif::warning << "TcMemWrite: Length " << commandDataLen << " smaller than minimum "
|
||||
<< MIN_COMMAND_DATA_LENGTH << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
if (commandDataLen + CRC_SIZE > spParams.maxSize) {
|
||||
sif::warning << "TcMemWrite: Length " << commandDataLen << " larger than allowed "
|
||||
<< spParams.maxSize - CRC_SIZE << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to help creation of flash fopen command.
|
||||
*/
|
||||
class FlashFopen : public ploc::SpTcBase {
|
||||
public:
|
||||
FlashFopen(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: ploc::SpTcBase(params, apid::TC_FLASHFOPEN, sequenceCount) {}
|
||||
|
||||
static const char APPEND = 'a';
|
||||
static const char WRITE = 'w';
|
||||
static const char READ = 'r';
|
||||
|
||||
ReturnValue_t createPacket(std::string filename, char accessMode_) {
|
||||
accessMode = accessMode_;
|
||||
size_t nameSize = filename.size();
|
||||
spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + sizeof(accessMode) + CRC_SIZE);
|
||||
ReturnValue_t result = checkPayloadLen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, filename.c_str(), nameSize);
|
||||
*(spParams.buf + nameSize) = NULL_TERMINATOR;
|
||||
std::memcpy(payloadStart + nameSize + sizeof(NULL_TERMINATOR), &accessMode, sizeof(accessMode));
|
||||
updateSpFields();
|
||||
return calcAndSetCrc();
|
||||
}
|
||||
|
||||
private:
|
||||
char accessMode = APPEND;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to help creation of flash fclose command.
|
||||
*/
|
||||
class FlashFclose : public ploc::SpTcBase {
|
||||
public:
|
||||
FlashFclose(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: ploc::SpTcBase(params, apid::TC_FLASHFCLOSE, sequenceCount) {}
|
||||
|
||||
ReturnValue_t createPacket(std::string filename) {
|
||||
size_t nameSize = filename.size();
|
||||
spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE);
|
||||
ReturnValue_t result = checkPayloadLen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, filename.c_str(), nameSize);
|
||||
*(payloadStart + nameSize) = NULL_TERMINATOR;
|
||||
return calcAndSetCrc();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build flash write space packet.
|
||||
*/
|
||||
class TcFlashWrite : public ploc::SpTcBase {
|
||||
public:
|
||||
TcFlashWrite(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: ploc::SpTcBase(params, apid::TC_FLASHWRITE, sequenceCount) {}
|
||||
|
||||
ReturnValue_t buildPacket(const uint8_t* writeData, uint32_t writeLen_) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
writeLen = writeLen_;
|
||||
if (writeLen > MAX_DATA_SIZE) {
|
||||
sif::debug << "FlashWrite::createPacket: Command data too big" << std::endl;
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
spParams.setFullPayloadLen(static_cast<uint16_t>(writeLen) + 4 + CRC_SIZE);
|
||||
result = checkPayloadLen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
size_t serializedSize = ccsds::HEADER_LEN;
|
||||
result = SerializeAdapter::serialize(&writeLen, payloadStart, &serializedSize, spParams.maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart + sizeof(writeLen), writeData, writeLen);
|
||||
updateSpFields();
|
||||
auto res = checkSizeAndSerializeHeader();
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
return calcAndSetCrc();
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t writeLen = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to help creation of flash delete command.
|
||||
*/
|
||||
class TcFlashDelete : public ploc::SpTcBase {
|
||||
public:
|
||||
TcFlashDelete(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: ploc::SpTcBase(params, apid::TC_FLASHDELETE, sequenceCount) {}
|
||||
|
||||
ReturnValue_t buildPacket(std::string filename) {
|
||||
size_t nameSize = filename.size();
|
||||
spParams.setFullPayloadLen(nameSize + sizeof(NULL_TERMINATOR) + CRC_SIZE);
|
||||
auto res = checkPayloadLen();
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
std::memcpy(payloadStart, filename.c_str(), nameSize);
|
||||
*(payloadStart + nameSize) = NULL_TERMINATOR;
|
||||
|
||||
updateSpFields();
|
||||
res = checkSizeAndSerializeHeader();
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
return calcAndSetCrc();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build replay stop space packet.
|
||||
*/
|
||||
class TcReplayStop : public TcBase {
|
||||
public:
|
||||
TcReplayStop(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_REPLAY_STOP, sequenceCount) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to build the replay start command.
|
||||
*/
|
||||
class TcReplayStart : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TcReplayStart(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_REPLAY_START, sequenceCount) {}
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = checkData(*commandData);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t COMMAND_DATA_LENGTH = 1;
|
||||
static const uint8_t REPEATING = 0;
|
||||
static const uint8_t ONCE = 1;
|
||||
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen != COMMAND_DATA_LENGTH or checkPayloadLen() != returnvalue::OK) {
|
||||
sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t checkData(uint8_t replay) {
|
||||
if (replay != REPEATING && replay != ONCE) {
|
||||
sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl;
|
||||
return INVALID_PARAMETER;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to build downlink power on command.
|
||||
*/
|
||||
class TcDownlinkPwrOn : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TcDownlinkPwrOn(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_DOWNLINK_PWR_ON, sequenceCount) {}
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = modeCheck(*commandData);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
result = laneRateCheck(*(commandData + 1));
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
spParams.setFullPayloadLen(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE);
|
||||
result = checkPayloadLen();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
std::memcpy(payloadStart + commandDataLen, &MAX_AMPLITUDE, sizeof(MAX_AMPLITUDE));
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::DWLPWRON_CMD;
|
||||
|
||||
//! [EXPORT] : [COMMENT] Received command has invalid JESD mode (valid modes are 0 - 5)
|
||||
static const ReturnValue_t INVALID_MODE = MAKE_RETURN_CODE(0xE0);
|
||||
//! [EXPORT] : [COMMENT] Received command has invalid lane rate (valid lane rate are 0 - 9)
|
||||
static const ReturnValue_t INVALID_LANE_RATE = MAKE_RETURN_CODE(0xE1);
|
||||
|
||||
static const size_t COMMAND_DATA_LENGTH = 2;
|
||||
static const uint8_t MAX_MODE = 5;
|
||||
static const uint8_t MAX_LANE_RATE = 9;
|
||||
static const uint16_t MAX_AMPLITUDE = 0;
|
||||
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen != COMMAND_DATA_LENGTH) {
|
||||
sif::warning << "TcDownlinkPwrOn: Command has invalid length " << commandDataLen << std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t modeCheck(uint8_t mode) {
|
||||
if (mode > MAX_MODE) {
|
||||
sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl;
|
||||
return INVALID_MODE;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t laneRateCheck(uint8_t laneRate) {
|
||||
if (laneRate > MAX_LANE_RATE) {
|
||||
sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl;
|
||||
return INVALID_LANE_RATE;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build replay stop space packet.
|
||||
*/
|
||||
class TcDownlinkPwrOff : public TcBase {
|
||||
public:
|
||||
TcDownlinkPwrOff(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_DOWNLINK_PWR_OFF, sequenceCount) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class helps to build the replay start command.
|
||||
*/
|
||||
class TcReplayWriteSeq : public TcBase {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
TcReplayWriteSeq(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {}
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
spParams.setFullPayloadLen(commandDataLen + sizeof(NULL_TERMINATOR) + CRC_SIZE);
|
||||
result = lengthCheck(commandDataLen);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
*(payloadStart + commandDataLen) = NULL_TERMINATOR;
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t USE_DECODING_LENGTH = 1;
|
||||
|
||||
ReturnValue_t lengthCheck(size_t commandDataLen) {
|
||||
if (commandDataLen > USE_DECODING_LENGTH + MAX_FILENAME_SIZE or
|
||||
checkPayloadLen() != returnvalue::OK) {
|
||||
sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen
|
||||
<< std::endl;
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Helps to extract the fields of the flash write command from the PUS packet.
|
||||
*/
|
||||
class FlashWritePusCmd : public MPSoCReturnValuesIF {
|
||||
public:
|
||||
FlashWritePusCmd(){};
|
||||
|
||||
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) {
|
||||
if (commandDataLen > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE + MAX_FILENAME_SIZE)) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
obcFile = std::string(reinterpret_cast<const char*>(commandData));
|
||||
if (obcFile.size() > (config::MAX_PATH_SIZE + config::MAX_FILENAME_SIZE)) {
|
||||
return FILENAME_TOO_LONG;
|
||||
}
|
||||
mpsocFile = std::string(
|
||||
reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR));
|
||||
if (mpsocFile.size() > MAX_FILENAME_SIZE) {
|
||||
return MPSOC_FILENAME_TOO_LONG;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
std::string getObcFile() { return obcFile; }
|
||||
|
||||
std::string getMPSoCFile() { return mpsocFile; }
|
||||
|
||||
private:
|
||||
static const size_t SIZE_NULL_TERMINATOR = 1;
|
||||
std::string obcFile = "";
|
||||
std::string mpsocFile = "";
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build replay stop space packet.
|
||||
*/
|
||||
class TcModeReplay : public TcBase {
|
||||
public:
|
||||
TcModeReplay(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_MODE_REPLAY, sequenceCount) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build mode idle command
|
||||
*/
|
||||
class TcModeIdle : public TcBase {
|
||||
public:
|
||||
TcModeIdle(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_MODE_IDLE, sequenceCount) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build mode idle command
|
||||
*/
|
||||
class TcModeSnapshot : public TcBase {
|
||||
public:
|
||||
TcModeSnapshot(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_MODE_SNAPSHOT, sequenceCount) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build camera take picture command
|
||||
*/
|
||||
class TcCamTakePic : public TcBase {
|
||||
public:
|
||||
TcCamTakePic(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_CAM_TAKE_PIC, sequenceCount) {}
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
if (commandDataLen > MAX_DATA_LENGTH) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
std::string fileName(reinterpret_cast<const char*>(commandData));
|
||||
if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) {
|
||||
return FILENAME_TOO_LONG;
|
||||
}
|
||||
if (commandDataLen - (fileName.size() + sizeof(NULL_TERMINATOR)) != PARAMETER_SIZE) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t MAX_DATA_LENGTH = 286;
|
||||
static const size_t PARAMETER_SIZE = 28;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build simplex send file command
|
||||
*/
|
||||
class TcSimplexSendFile : public TcBase {
|
||||
public:
|
||||
TcSimplexSendFile(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {}
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
if (commandDataLen > MAX_DATA_LENGTH) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
std::string fileName(reinterpret_cast<const char*>(commandData));
|
||||
if (fileName.size() + sizeof(NULL_TERMINATOR) > MAX_FILENAME_SIZE) {
|
||||
return FILENAME_TOO_LONG;
|
||||
}
|
||||
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t MAX_DATA_LENGTH = 256;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Class to build downlink data modulate command
|
||||
*/
|
||||
class TcDownlinkDataModulate : public TcBase {
|
||||
public:
|
||||
TcDownlinkDataModulate(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_DOWNLINK_DATA_MODULATE, sequenceCount) {}
|
||||
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
if (commandDataLen > MAX_DATA_LENGTH) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
|
||||
std::memcpy(payloadStart, commandData, commandDataLen);
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
private:
|
||||
static const size_t MAX_DATA_LENGTH = 11;
|
||||
};
|
||||
|
||||
class TcCamcmdSend : public TcBase {
|
||||
public:
|
||||
TcCamcmdSend(ploc::SpTcParams params, uint16_t sequenceCount)
|
||||
: TcBase(params, apid::TC_CAM_CMD_SEND, sequenceCount) {}
|
||||
|
||||
protected:
|
||||
ReturnValue_t initPacket(const uint8_t* commandData, size_t commandDataLen) override {
|
||||
if (commandDataLen > MAX_DATA_LENGTH) {
|
||||
return INVALID_LENGTH;
|
||||
}
|
||||
uint16_t dataLen = static_cast<uint16_t>(commandDataLen + sizeof(CARRIAGE_RETURN));
|
||||
spParams.setFullPayloadLen(sizeof(dataLen) + commandDataLen + sizeof(CARRIAGE_RETURN) +
|
||||
CRC_SIZE);
|
||||
auto res = checkPayloadLen();
|
||||
if (res != returnvalue::OK) {
|
||||
return res;
|
||||
}
|
||||
size_t size = ccsds::HEADER_LEN;
|
||||
SerializeAdapter::serialize(&dataLen, payloadStart, &size, spParams.maxSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
std::memcpy(payloadStart + sizeof(dataLen), commandData, commandDataLen);
|
||||
*(payloadStart + sizeof(dataLen) + commandDataLen) = CARRIAGE_RETURN;
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint8_t MAX_DATA_LENGTH = 10;
|
||||
static const uint8_t CARRIAGE_RETURN = 0xD;
|
||||
};
|
||||
|
||||
} // namespace mpsoc
|
||||
|
||||
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */
|
2152
linux/payload/plocSupvDefs.h
Normal file
2152
linux/payload/plocSupvDefs.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user