eive-obsw/linux/payload/plocMpsocHelpers.h

1221 lines
44 KiB
C
Raw Permalink Normal View History

#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_
2021-04-11 12:04:13 +02:00
2023-05-02 15:04:14 +02:00
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
2023-03-26 16:42:00 +02:00
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include <mission/payload/plocSpBase.h>
2024-04-30 15:14:22 +02:00
#include "eive/eventSubsystemIds.h"
#include "eive/resultClassIds.h"
#include "fsfw/action/HasActionsIF.h"
2024-05-06 13:19:15 +02:00
#include "fsfw/events/Event.h"
2024-04-30 15:14:22 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2022-03-27 10:44:32 +02:00
#include "fsfw/serialize/SerializeAdapter.h"
2024-04-30 15:14:22 +02:00
#include "fsfw/serialize/SerializeIF.h"
2021-04-11 12:04:13 +02:00
2022-01-05 11:26:01 +01:00
namespace mpsoc {
2021-04-11 12:04:13 +02:00
2024-04-30 15:37:53 +02:00
static constexpr bool MPSOC_TX_WIRETAPPING = false;
static constexpr bool MPSOC_RX_WIRETAPPING = false;
2024-04-30 15:14:22 +02:00
static constexpr size_t CRC_SIZE = 2;
/**
* @brief Abstract base class for TC space packet of MPSoC.
*/
class TcBase : public ploc::SpTcBase {
public:
virtual ~TcBase() = default;
// Initial length field of space packet. Will always be updated when packet is created.
static const uint16_t INIT_LENGTH = CRC_SIZE;
/**
* @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) {
payloadStart = spParams.buf + ccsds::HEADER_LEN;
spParams.setFullPayloadLen(INIT_LENGTH);
}
/**
* @brief Function to finsh and write the space packet. It is expected that the user has
* set the payload fields in the child class*
* @return returnvalue::OK if packet creation was successful, otherwise error return value
*/
ReturnValue_t finishPacket() {
updateSpFields();
ReturnValue_t res = checkSizeAndSerializeHeader();
if (res != returnvalue::OK) {
return res;
}
return calcAndSetCrc();
}
};
void printRxPacket(const SpacePacketReader& spReader);
void printTxPacket(const ploc::SpTcBase& tcBase);
static constexpr uint32_t DEFAULT_CMD_TIMEOUT_MS = 5000;
static constexpr uint32_t CMD_TIMEOUT_MKFS = 15000;
enum FlashId : uint8_t { FLASH_0 = 0, FLASH_1 = 1 };
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);
//! [EXPORT] : [COMMENT] Command has timed out.
static const ReturnValue_t COMMAND_TIMEOUT = MAKE_RETURN_CODE(0x10);
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);
//! [EXPORT] : [COMMENT] SUPV not on for boot or shutdown process. P1: 0 for OFF transition, 1 for
//! ON transition.
static constexpr Event SUPV_NOT_ON = event::makeEvent(SUBSYSTEM_ID, 7, severity::LOW);
2024-05-06 13:30:28 +02:00
//! [EXPORT] : [COMMENT] SUPV reply timeout.
2024-04-30 15:14:22 +02:00
static constexpr Event SUPV_REPLY_TIMEOUT = event::makeEvent(SUBSYSTEM_ID, 8, severity::LOW);
2024-05-06 13:19:15 +02:00
//! [EXPORT] : [COMMENT] Camera must be commanded on first.
static constexpr Event CAM_MUST_BE_ON_FOR_SNAPSHOT_MODE =
event::makeEvent(SUBSYSTEM_ID, 9, severity::LOW);
2024-04-30 15:14:22 +02:00
2024-01-24 14:34:34 +01:00
enum ParamId : uint8_t { SKIP_SUPV_ON_COMMANDING = 0x01 };
2023-05-17 18:33:48 +02:00
enum FileAccessModes : uint8_t {
// Opens a file, fails if the file does not exist.
2023-05-15 15:15:58 +02:00
OPEN_EXISTING = 0x00,
READ = 0x01,
WRITE = 0x02,
2023-05-17 18:33:48 +02:00
// Creates a new file, fails if it already exists.
2023-05-15 15:15:58 +02:00
CREATE_NEW = 0x04,
2023-05-17 18:33:48 +02:00
// Creates a new file, existing file is truncated and overwritten.
2023-05-15 15:15:58 +02:00
CREATE_ALWAYS = 0x08,
2023-05-17 18:33:48 +02:00
// Opens the file if it is existing. If not, a new file is created.
2023-05-15 15:15:58 +02:00
OPEN_ALWAYS = 0x10,
OPEN_APPEND = 0x30
};
2023-05-02 15:04:14 +02:00
static constexpr uint32_t HK_SET_ID = 0;
2024-04-30 15:14:22 +02:00
static constexpr uint32_t DEADBEEF_ADDR = 0x40000004;
static constexpr uint32_t DEADBEEF_VALUE = 0xdeadbeef;
2023-05-02 15:04:14 +02:00
namespace poolid {
enum {
STATUS = 0,
MODE = 1,
DOWNLINK_PWR_ON = 2,
DOWNLINK_REPLY_ACTIIVE = 3,
DOWNLINK_JESD_SYNC_STATUS = 4,
DOWNLINK_DAC_STATUS = 5,
CAM_STATUS = 6,
CAM_SDI_STATUS = 7,
CAM_FPGA_TEMP = 8,
CAM_SOC_TEMP = 9,
SYSMON_TEMP = 10,
SYSMON_VCCINT = 11,
SYSMON_VCCAUX = 12,
SYSMON_VCCBRAM = 13,
SYSMON_VCCPAUX = 14,
SYSMON_VCCPINT = 15,
SYSMON_VCCPDRO = 16,
SYSMON_MB12V = 17,
SYSMON_MB3V3 = 18,
SYSMON_MB1V8 = 19,
SYSMON_VCC12V = 20,
SYSMON_VCC5V = 21,
SYSMON_VCC3V3 = 22,
SYSMON_VCC3V3VA = 23,
SYSMON_VCC2V5DDR = 24,
SYSMON_VCC1V2DDR = 25,
SYSMON_VCC0V9 = 26,
SYSMON_VCC0V6VTT = 27,
SYSMON_SAFE_COTS_CUR = 28,
SYSMON_NVM4_XO_CUR = 29,
SEM_UNCORRECTABLE_ERRS = 30,
SEM_CORRECTABLE_ERRS = 31,
SEM_STATUS = 32,
REBOOT_MPSOC_REQUIRED = 33,
};
}
2022-01-05 11:26:01 +01:00
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;
2022-01-06 10:12:08 +01:00
static const DeviceCommandId_t TC_FLASHFCLOSE = 8;
2023-05-03 19:54:30 +02:00
static const DeviceCommandId_t TC_FLASH_WRITE_FULL_FILE = 9;
2022-03-21 08:35:28 +01:00
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;
2022-03-24 17:39:50 +01:00
static const DeviceCommandId_t TC_MODE_REPLAY = 16;
2022-04-20 21:33:39 +02:00
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;
2022-04-29 22:55:01 +02:00
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;
2024-04-30 15:14:22 +02:00
// Stream file down using E-Band component directly.
static const DeviceCommandId_t TC_SIMPLEX_STREAM_FILE = 23;
static const DeviceCommandId_t TC_DOWNLINK_DATA_MODULATE = 24;
2023-02-14 14:00:53 +01:00
static const DeviceCommandId_t TC_MODE_SNAPSHOT = 25;
2023-05-02 13:42:20 +02:00
static const DeviceCommandId_t TC_GET_HK_REPORT = 26;
static const DeviceCommandId_t TM_GET_HK_REPORT = 27;
2023-05-11 20:19:46 +02:00
static const DeviceCommandId_t TC_FLASH_GET_DIRECTORY_CONTENT = 28;
static const DeviceCommandId_t TM_FLASH_DIRECTORY_CONTENT = 29;
2023-05-03 19:54:30 +02:00
static constexpr DeviceCommandId_t TC_FLASH_READ_FULL_FILE = 30;
2024-04-30 15:14:22 +02:00
// Store file on MPSoC.
2024-05-06 14:17:25 +02:00
static const DeviceCommandId_t TC_SPLIT_FILE = 31;
2024-04-30 15:14:22 +02:00
static const DeviceCommandId_t TC_VERIFY_BOOT = 32;
static const DeviceCommandId_t TC_ENABLE_TC_EXECTION = 33;
static const DeviceCommandId_t TC_FLASH_MKFS = 34;
2022-04-29 22:55:01 +02:00
2024-04-30 15:14:22 +02:00
// Will reset the sequence count of the OBSW. Not required anymore after MPSoC update.
static const DeviceCommandId_t OBSW_RESET_SEQ_COUNT_LEGACY = 50;
2022-03-25 09:08:01 +01:00
2022-01-03 08:01:55 +01:00
static const uint16_t SIZE_ACK_REPORT = 14;
static const uint16_t SIZE_EXE_REPORT = 14;
2023-05-02 13:42:20 +02:00
static constexpr size_t SIZE_TM_HK_REPORT = 369;
2022-01-03 08:01:55 +01:00
2024-04-30 15:14:22 +02:00
enum Submode : uint8_t { IDLE_OR_NONE = 0, REPLAY = 1, SNAPSHOT = 2 };
// Setting the internal mode value to the actual telecommand ID
/*
enum InternalMode {
OFF = HasModesIF::MODE_OFF,
IDLE = ,
REPLAY = TC_MODE_REPLAY,
SNAPSHOT = TC_MODE_SNAPSHOT
};
*/
2022-01-03 08:01:55 +01:00
/**
* SpacePacket apids of PLOC telecommands and telemetry.
*/
2022-01-05 11:26:01 +01:00
namespace apid {
2022-03-26 20:47:25 +01:00
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;
2023-05-03 19:37:10 +02:00
static constexpr uint16_t TC_FLASHWRITE = 0x117;
static constexpr uint16_t TC_FLASHREAD = 0x118;
2022-03-26 20:47:25 +01:00
static const uint16_t TC_FLASHFOPEN = 0x119;
static const uint16_t TC_FLASHFCLOSE = 0x11A;
2023-05-11 20:19:46 +02:00
static constexpr uint16_t TC_FLASH_GET_DIRECTORY_CONTENT = 0x11B;
2022-03-26 20:47:25 +01:00
static const uint16_t TC_FLASHDELETE = 0x11C;
2023-05-11 20:20:47 +02:00
static constexpr uint16_t TC_FLASH_CREATE_DIR = 0x11D;
2022-04-20 21:33:39 +02:00
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;
2023-05-02 13:42:20 +02:00
static constexpr uint16_t TC_HK_GET_REPORT = 0x123;
2022-03-26 20:47:25 +01:00
static const uint16_t TC_DOWNLINK_PWR_OFF = 0x124;
2024-04-30 15:14:22 +02:00
static constexpr uint16_t TC_ENABLE_TC_EXECUTION = 0x129;
static constexpr uint16_t TC_FLASH_MKFS = 0x12A;
2022-04-20 21:33:39 +02:00
static const uint16_t TC_CAM_CMD_SEND = 0x12C;
2023-05-11 20:20:47 +02:00
static constexpr uint16_t TC_FLASH_COPY_FILE = 0x12E;
static const uint16_t TC_SIMPLEX_SEND_FILE = 0x130;
2023-05-11 20:20:47 +02:00
2022-03-26 20:47:25 +01:00
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;
2023-05-03 19:37:10 +02:00
static const uint16_t TM_MEMORY_READ_REPORT = 0x404;
static const uint16_t TM_FLASH_READ_REPORT = 0x405;
2023-05-11 20:19:46 +02:00
static constexpr uint16_t TM_FLASH_DIRECTORY_CONTENT = 0x406;
2022-04-20 21:33:39 +02:00
static const uint16_t TM_CAM_CMD_RPT = 0x407;
2023-05-11 20:20:47 +02:00
static constexpr uint16_t TM_HK_GET_REPORT = 0x408;
2022-03-26 20:47:25 +01:00
} // namespace apid
2022-01-05 11:26:01 +01:00
/** Offset from first byte in space packet to first byte of data field */
2022-01-03 08:01:55 +01:00
static const uint8_t DATA_FIELD_OFFSET = 6;
static const size_t MEM_READ_RPT_LEN_OFFSET = 10;
2022-03-26 20:47:25 +01:00
static const char NULL_TERMINATOR = '\0';
2022-04-20 21:33:39 +02:00
static const uint8_t MIN_SPACE_PACKET_LENGTH = 7;
static const uint8_t SPACE_PACKET_HEADER_SIZE = 6;
2022-01-03 08:01:55 +01:00
2023-05-15 15:15:58 +02:00
static const uint8_t STATUS_OFFSET = 10;
2022-01-03 08:01:55 +01:00
/**
* 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;
2022-01-03 08:01:55 +01:00
2024-04-30 15:14:22 +02:00
static const size_t FILENAME_FIELD_SIZE = 256;
// Subtract size of NULL terminator.
static const size_t MAX_FILENAME_SIZE = FILENAME_FIELD_SIZE - 1;
2022-01-05 11:26:01 +01:00
2022-01-03 08:01:55 +01:00
/**
* 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;
/**
2022-08-16 18:41:50 +02:00
* 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;
2023-05-03 19:37:10 +02:00
static constexpr size_t MAX_REPLY_SIZE = SP_MAX_SIZE * 3;
static constexpr size_t MAX_COMMAND_SIZE = SP_MAX_SIZE;
// 1016 bytes.
static constexpr size_t SP_MAX_DATA_SIZE = SP_MAX_SIZE - ccsds::HEADER_LEN - CRC_SIZE;
static constexpr size_t FLASH_READ_MIN_OVERHEAD = 16;
// 1000 bytes.
static const size_t MAX_FLASH_READ_DATA_SIZE = SP_MAX_DATA_SIZE - FLASH_READ_MIN_OVERHEAD;
2023-05-17 18:33:48 +02:00
// 1012 bytes, 4 bytes for the write length.
static constexpr size_t MAX_FLASH_WRITE_DATA_SIZE = SP_MAX_DATA_SIZE - sizeof(uint32_t);
2022-01-03 08:01:55 +01:00
2022-01-05 11:26:01 +01:00
/**
2022-03-21 16:21:51 +01:00
* The replay write sequence command has a maximum delay for the execution report which amounts to
2022-03-26 20:47:25 +01:00
* 30 seconds. (80 cycles * 0.5 seconds = 40 seconds).
2022-03-21 16:21:51 +01:00
*/
2022-03-26 20:47:25 +01:00
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;
2023-02-28 19:56:42 +01:00
static const uint16_t TC_SIMPLEX_SEND_FILE_DELAY = 80;
2022-03-21 16:21:51 +01:00
2024-04-30 15:14:22 +02:00
namespace statusCode {
static const uint16_t DEFAULT_ERROR_CODE = 0x1;
2024-04-30 15:14:22 +02:00
static constexpr uint16_t FLASH_DRIVE_ERROR = 0xb;
2022-06-17 08:31:36 +02:00
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;
2023-05-17 18:33:48 +02:00
static const uint16_t FLASH_FILE_ALREADY_OPEN = 0x5E6;
2022-06-17 08:31:36 +02:00
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;
2024-04-30 15:14:22 +02:00
} // namespace statusCode
2022-01-05 11:26:01 +01:00
2022-01-03 08:01:55 +01:00
/**
* @brief This class helps to build the memory read command for the PLOC.
*/
2024-04-30 15:14:22 +02:00
class TcMemRead : public mpsoc::TcBase {
2022-03-26 20:47:25 +01:00
public:
/**
* @brief Constructor
*/
2022-08-15 18:34:26 +02:00
TcMemRead(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_MEM_READ, sequenceCount) {
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(COMMAND_LENGTH + CRC_SIZE);
2022-03-26 20:47:25 +01:00
}
2021-04-11 12:04:13 +02:00
2022-03-26 20:47:25 +01:00
uint16_t getMemLen() const { return memLen; }
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-26 20:47:25 +01:00
result = lengthCheck(commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
std::memcpy(payloadStart, commandData, MEM_ADDRESS_SIZE);
std::memcpy(payloadStart + MEM_ADDRESS_SIZE, commandData + MEM_ADDRESS_SIZE, MEM_LEN_SIZE);
2022-03-26 20:47:25 +01:00
size_t size = sizeof(memLen);
const uint8_t* memLenPtr = commandData + MEM_ADDRESS_SIZE;
result =
SerializeAdapter::deSerialize(&memLen, &memLenPtr, &size, SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
return result;
}
2022-03-26 20:47:25 +01:00
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;
2022-03-26 20:47:25 +01:00
uint16_t memLen = 0;
2022-03-26 20:47:25 +01:00
ReturnValue_t lengthCheck(size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
if (commandDataLen != COMMAND_LENGTH or checkPayloadLen() != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return INVALID_LENGTH;
2022-01-03 08:01:55 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-01-03 08:01:55 +01:00
};
/**
2022-01-06 10:12:08 +01:00
* @brief This class helps to generate the space packet to write data to a memory address within
2022-01-03 08:01:55 +01:00
* the PLOC.
*/
2024-04-30 15:14:22 +02:00
class TcMemWrite : public mpsoc::TcBase {
2022-03-26 20:47:25 +01:00
public:
/**
* @brief Constructor
*/
2022-08-15 18:34:26 +02:00
TcMemWrite(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_MEM_WRITE, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-26 20:47:25 +01:00
result = lengthCheck(commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
uint16_t memLen =
*(commandData + MEM_ADDRESS_SIZE) << 8 | *(commandData + MEM_ADDRESS_SIZE + 1);
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(MIN_FIXED_PAYLOAD_LENGTH + memLen * 4 + CRC_SIZE);
2022-08-16 18:37:51 +02:00
result = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return result;
}
std::memcpy(payloadStart, commandData, commandDataLen);
2022-03-26 20:47:25 +01:00
return result;
}
private:
2022-08-16 18:02:32 +02:00
// 4 byte address, 2 byte mem length field
2022-03-26 20:47:25 +01:00
static const size_t MEM_ADDRESS_SIZE = 4;
2022-08-16 18:02:32 +02:00
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;
2022-03-26 20:47:25 +01:00
ReturnValue_t lengthCheck(size_t commandDataLen) {
if (commandDataLen < MIN_COMMAND_DATA_LENGTH) {
2022-08-18 15:32:24 +02:00
sif::warning << "TcMemWrite: Length " << commandDataLen << " smaller than minimum "
<< MIN_COMMAND_DATA_LENGTH << std::endl;
2022-08-16 18:02:32 +02:00
return INVALID_LENGTH;
}
2022-08-18 15:32:24 +02:00
if (commandDataLen + CRC_SIZE > spParams.maxSize) {
sif::warning << "TcMemWrite: Length " << commandDataLen << " larger than allowed "
<< spParams.maxSize - CRC_SIZE << std::endl;
2022-03-26 20:47:25 +01:00
return INVALID_LENGTH;
2022-01-03 08:01:55 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-01-05 11:26:01 +01:00
};
2021-04-11 12:04:13 +02:00
2022-01-05 11:26:01 +01:00
/**
2022-01-06 10:12:08 +01:00
* @brief Class to help creation of flash fopen command.
2022-01-05 11:26:01 +01:00
*/
2024-04-30 15:14:22 +02:00
class TcFlashFopen : public mpsoc::TcBase {
2022-03-26 20:47:25 +01:00
public:
2024-04-30 15:14:22 +02:00
TcFlashFopen(ploc::SpTcParams params, uint16_t sequenceCount)
2023-05-16 11:08:33 +02:00
: TcBase(params, apid::TC_FLASHFOPEN, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-17 18:33:48 +02:00
ReturnValue_t setPayload(std::string filename, uint8_t mode) {
2023-05-15 15:15:58 +02:00
accessMode = mode;
2022-08-16 18:37:51 +02:00
ReturnValue_t result = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return result;
}
2024-04-30 15:14:22 +02:00
std::memset(payloadStart, 0, FILENAME_FIELD_SIZE);
std::memcpy(payloadStart, filename.c_str(), filename.size());
payloadStart[FILENAME_FIELD_SIZE] = accessMode;
spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + 1 + CRC_SIZE);
2023-05-16 13:34:06 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
private:
2023-05-17 18:33:48 +02:00
uint8_t accessMode = FileAccessModes::OPEN_EXISTING;
2022-01-03 08:01:55 +01:00
};
2021-04-11 12:04:13 +02:00
2022-01-06 10:12:08 +01:00
/**
* @brief Class to help creation of flash fclose command.
*/
2024-04-30 15:14:22 +02:00
class TcFlashFclose : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2024-04-30 15:14:22 +02:00
TcFlashFclose(ploc::SpTcParams params, uint16_t sequenceCount)
2023-05-16 18:41:04 +02:00
: TcBase(params, apid::TC_FLASHFCLOSE, sequenceCount) {
spParams.setFullPayloadLen(CRC_SIZE);
}
2022-03-21 08:35:28 +01:00
};
2024-04-30 15:14:22 +02:00
class TcEnableTcExec : public TcBase {
public:
TcEnableTcExec(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_ENABLE_TC_EXECUTION, sequenceCount) {
spParams.setFullPayloadLen(CRC_SIZE);
}
ReturnValue_t setPayload(const uint8_t* cmdData, size_t cmdDataLen) {
if (cmdDataLen != 2) {
return HasActionsIF::INVALID_PARAMETERS;
}
std::memcpy(payloadStart, cmdData, 2);
spParams.setFullPayloadLen(2 + CRC_SIZE);
return returnvalue::OK;
}
};
class TcFlashMkfs : public TcBase {
public:
TcFlashMkfs(ploc::SpTcParams params, uint16_t sequenceCount, FlashId flashId)
: TcBase(params, apid::TC_FLASH_MKFS, sequenceCount) {
const char* flashIdStr = "0:\\";
if (flashId == FlashId::FLASH_1) {
flashIdStr = "1:\\";
}
std::memcpy(payloadStart, flashIdStr, 3);
// Null terminator
payloadStart[3] = 0;
spParams.setFullPayloadLen(4 + CRC_SIZE);
}
};
2022-03-21 16:21:51 +01:00
/**
* @brief Class to build flash write space packet.
*/
2023-05-16 11:08:33 +02:00
class TcFlashWrite : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2022-08-15 18:34:26 +02:00
TcFlashWrite(ploc::SpTcParams params, uint16_t sequenceCount)
2023-05-16 11:08:33 +02:00
: TcBase(params, apid::TC_FLASHWRITE, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 18:41:04 +02:00
ReturnValue_t setPayload(const uint8_t* writeData, uint32_t writeLen_) {
2022-03-26 20:47:25 +01:00
writeLen = writeLen_;
2023-05-17 18:33:48 +02:00
if (writeLen > MAX_FLASH_WRITE_DATA_SIZE) {
2023-05-03 19:37:10 +02:00
sif::error << "TcFlashWrite: Command data too big" << std::endl;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2022-03-26 20:47:25 +01:00
}
2023-05-17 18:33:48 +02:00
spParams.setFullPayloadLen(sizeof(uint32_t) + static_cast<uint16_t>(writeLen) + CRC_SIZE);
ReturnValue_t result = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return result;
}
2022-08-20 12:11:08 +02:00
size_t serializedSize = ccsds::HEADER_LEN;
result = SerializeAdapter::serialize(&writeLen, payloadStart, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::BIG);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
2023-05-17 18:33:48 +02:00
std::memcpy(payloadStart + sizeof(uint32_t), writeData, writeLen);
2022-08-15 18:58:56 +02:00
updateSpFields();
2023-05-03 19:37:10 +02:00
result = checkSizeAndSerializeHeader();
if (result != returnvalue::OK) {
return result;
2022-03-21 16:21:51 +01:00
}
2022-11-07 10:30:09 +01:00
return calcAndSetCrc();
2022-03-26 20:47:25 +01:00
}
private:
uint32_t writeLen = 0;
2022-03-21 16:21:51 +01:00
};
2023-05-16 11:08:33 +02:00
class TcFlashRead : public TcBase {
2023-05-03 19:37:10 +02:00
public:
TcFlashRead(ploc::SpTcParams params, uint16_t sequenceCount)
2023-05-17 16:33:52 +02:00
: TcBase(params, apid::TC_FLASHREAD, sequenceCount) {}
2023-05-03 19:37:10 +02:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(uint32_t readLen) {
2023-05-03 19:37:10 +02:00
if (readLen > MAX_FLASH_READ_DATA_SIZE) {
sif::error << "TcFlashRead: Read length " << readLen << " too large" << std::endl;
return returnvalue::FAILED;
}
2023-05-17 12:59:29 +02:00
spParams.setFullPayloadLen(sizeof(uint32_t) + CRC_SIZE);
2023-05-03 19:37:10 +02:00
ReturnValue_t result = checkPayloadLen();
if (result != returnvalue::OK) {
return result;
}
size_t serializedSize = ccsds::HEADER_LEN;
result = SerializeAdapter::serialize(&readLen, payloadStart, &serializedSize, spParams.maxSize,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
readSize = readLen;
return result;
}
uint32_t readSize = 0;
};
2022-03-21 08:35:28 +01:00
/**
2022-03-21 08:53:55 +01:00
* @brief Class to help creation of flash delete command.
2022-03-21 08:35:28 +01:00
*/
2023-05-16 11:08:33 +02:00
class TcFlashDelete : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2022-08-15 18:34:26 +02:00
TcFlashDelete(ploc::SpTcParams params, uint16_t sequenceCount)
2023-05-16 11:08:33 +02:00
: TcBase(params, apid::TC_FLASHDELETE, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(std::string filename) {
2022-03-26 20:47:25 +01:00
size_t nameSize = filename.size();
2024-04-30 15:14:22 +02:00
spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE);
2022-08-16 18:37:51 +02:00
auto res = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (res != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return res;
}
std::memcpy(payloadStart, filename.c_str(), nameSize);
*(payloadStart + nameSize) = NULL_TERMINATOR;
2024-04-30 15:14:22 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-01-06 10:12:08 +01:00
};
2022-01-06 18:05:21 +01:00
/**
2022-03-21 16:21:51 +01:00
* @brief Class to build replay stop space packet.
2022-01-06 18:05:21 +01:00
*/
2022-03-21 16:21:51 +01:00
class TcReplayStop : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2022-08-15 18:34:26 +02:00
TcReplayStop(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_REPLAY_STOP, sequenceCount) {}
2022-01-06 18:05:21 +01:00
};
2022-03-21 11:05:41 +01:00
/**
* @brief This class helps to build the replay start command.
*/
2022-03-26 20:47:25 +01:00
class TcReplayStart : public TcBase {
public:
/**
* @brief Constructor
*/
2022-08-15 18:34:26 +02:00
TcReplayStart(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_REPLAY_START, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
2022-03-26 20:47:25 +01:00
result = lengthCheck(commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
result = checkData(*commandData);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
std::memcpy(payloadStart, commandData, commandDataLen);
2022-03-26 20:47:25 +01:00
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) {
2022-08-26 14:28:06 +02:00
if (commandDataLen != COMMAND_DATA_LENGTH or checkPayloadLen() != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
sif::warning << "TcReplayStart: Command has invalid length " << commandDataLen << std::endl;
return INVALID_LENGTH;
2022-03-21 11:05:41 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
ReturnValue_t checkData(uint8_t replay) {
if (replay != REPEATING && replay != ONCE) {
sif::warning << "TcReplayStart::checkData: Invalid replay value" << std::endl;
return INVALID_PARAMETER;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-03-21 11:05:41 +01:00
};
/**
2022-03-21 16:21:51 +01:00
* @brief This class helps to build downlink power on command.
2022-03-21 11:05:41 +01:00
*/
2022-03-26 20:47:25 +01:00
class TcDownlinkPwrOn : public TcBase {
public:
/**
* @brief Constructor
*/
2022-08-15 18:34:26 +02:00
TcDownlinkPwrOn(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_DOWNLINK_PWR_ON, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-03-26 20:47:25 +01:00
result = lengthCheck(commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
result = modeCheck(*commandData);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
result = laneRateCheck(*(commandData + 1));
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(commandDataLen + sizeof(MAX_AMPLITUDE) + CRC_SIZE);
2022-08-16 18:37:51 +02:00
result = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return result;
}
std::memcpy(payloadStart, commandData, commandDataLen);
std::memcpy(payloadStart + commandDataLen, &MAX_AMPLITUDE, sizeof(MAX_AMPLITUDE));
2022-03-26 20:47:25 +01:00
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;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
ReturnValue_t modeCheck(uint8_t mode) {
if (mode > MAX_MODE) {
sif::warning << "TcDwonlinkPwrOn::modeCheck: Invalid JESD mode" << std::endl;
return INVALID_MODE;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
ReturnValue_t laneRateCheck(uint8_t laneRate) {
if (laneRate > MAX_LANE_RATE) {
sif::warning << "TcReplayStart::laneRateCheck: Invalid lane rate" << std::endl;
return INVALID_LANE_RATE;
2022-03-21 16:21:51 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-03-21 16:21:51 +01:00
};
2023-05-02 13:42:20 +02:00
class TcGetHkReport : public TcBase {
public:
TcGetHkReport(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_HK_GET_REPORT, sequenceCount) {}
};
2023-05-03 15:24:47 +02:00
class TcGetDirContent : public TcBase {
public:
TcGetDirContent(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_FLASH_GET_DIRECTORY_CONTENT, sequenceCount) {}
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2023-05-03 15:24:47 +02:00
ReturnValue_t result = returnvalue::OK;
2023-05-12 15:52:47 +02:00
// Yeah it needs to be 256.. even if the path is shorter.
spParams.setFullPayloadLen(256 + CRC_SIZE);
2023-05-03 15:24:47 +02:00
if (result != returnvalue::OK) {
return result;
}
2024-04-30 15:14:22 +02:00
std::memset(payloadStart, 0, 256);
2023-05-03 15:24:47 +02:00
std::memcpy(payloadStart, commandData, commandDataLen);
2024-04-30 15:14:22 +02:00
payloadStart[255] = 0;
2023-05-03 15:24:47 +02:00
return result;
}
};
2022-03-21 16:21:51 +01:00
/**
* @brief Class to build replay stop space packet.
*/
class TcDownlinkPwrOff : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2022-08-15 18:34:26 +02:00
TcDownlinkPwrOff(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_DOWNLINK_PWR_OFF, sequenceCount) {}
2022-03-21 16:21:51 +01:00
};
/**
* @brief This class helps to build the replay start command.
*/
2022-03-26 20:47:25 +01:00
class TcReplayWriteSeq : public TcBase {
public:
/**
* @brief Constructor
*/
2022-08-15 18:34:26 +02:00
TcReplayWriteSeq(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_REPLAY_WRITE_SEQUENCE, sequenceCount) {}
2022-03-26 20:47:25 +01:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(commandDataLen + sizeof(NULL_TERMINATOR) + CRC_SIZE);
2022-03-26 20:47:25 +01:00
result = lengthCheck(commandDataLen);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
return result;
}
std::memcpy(payloadStart, commandData, commandDataLen);
*(payloadStart + commandDataLen) = NULL_TERMINATOR;
2022-03-26 20:47:25 +01:00
return result;
}
2022-03-21 16:21:51 +01:00
2022-03-26 20:47:25 +01:00
private:
static const size_t USE_DECODING_LENGTH = 1;
2022-03-21 16:21:51 +01:00
2022-03-26 20:47:25 +01:00
ReturnValue_t lengthCheck(size_t commandDataLen) {
2024-04-30 15:14:22 +02:00
if (commandDataLen > USE_DECODING_LENGTH + FILENAME_FIELD_SIZE or
2022-08-24 17:27:47 +02:00
checkPayloadLen() != returnvalue::OK) {
2022-03-26 20:47:25 +01:00
sif::warning << "TcReplayWriteSeq: Command has invalid length " << commandDataLen
<< std::endl;
return INVALID_LENGTH;
2022-03-21 16:21:51 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-26 20:47:25 +01:00
}
2022-03-21 11:05:41 +01:00
};
2022-04-10 18:46:39 +02:00
/**
* @brief Helps to extract the fields of the flash write command from the PUS packet.
*/
2024-04-30 15:14:22 +02:00
class FlashBasePusCmd {
2022-03-22 11:35:44 +01:00
public:
2023-05-11 20:21:44 +02:00
FlashBasePusCmd() = default;
virtual ~FlashBasePusCmd() = default;
2022-03-22 11:35:44 +01:00
2023-05-11 20:21:44 +02:00
virtual ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) {
2024-04-30 15:14:22 +02:00
if (commandDataLen > FILENAME_FIELD_SIZE) {
2022-03-26 20:47:25 +01:00
return INVALID_LENGTH;
2022-03-22 11:35:44 +01:00
}
2023-05-11 20:21:44 +02:00
size_t fileLen = strnlen(reinterpret_cast<const char*>(commandData), commandDataLen);
2024-04-30 15:14:22 +02:00
if (fileLen > MAX_FILENAME_SIZE) {
2022-03-26 20:47:25 +01:00
return FILENAME_TOO_LONG;
2022-03-22 11:35:44 +01:00
}
2023-05-11 20:21:44 +02:00
obcFile = std::string(reinterpret_cast<const char*>(commandData), fileLen);
fileLen =
strnlen(reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR),
commandDataLen - obcFile.size() - 1);
2024-04-30 15:14:22 +02:00
if (fileLen > FILENAME_FIELD_SIZE) {
2022-03-26 20:47:25 +01:00
return MPSOC_FILENAME_TOO_LONG;
2022-03-22 11:35:44 +01:00
}
2023-05-11 20:21:44 +02:00
mpsocFile = std::string(
reinterpret_cast<const char*>(commandData + obcFile.size() + SIZE_NULL_TERMINATOR),
fileLen);
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-03-22 11:35:44 +01:00
}
2023-05-11 20:21:44 +02:00
const std::string& getObcFile() const { return obcFile; }
2022-03-22 11:35:44 +01:00
2024-04-30 15:14:22 +02:00
const std::string& getMpsocFile() const { return mpsocFile; }
2022-03-22 11:35:44 +01:00
2023-05-11 20:21:44 +02:00
protected:
size_t getParsedSize() const {
2024-04-30 15:14:22 +02:00
return getObcFile().size() + getMpsocFile().size() + 2 * SIZE_NULL_TERMINATOR;
2023-05-11 20:21:44 +02:00
}
static const size_t SIZE_NULL_TERMINATOR = 1;
2023-05-11 20:21:44 +02:00
private:
std::string obcFile;
std::string mpsocFile;
2022-03-22 11:35:44 +01:00
};
2022-03-24 17:39:50 +01:00
2023-05-11 20:21:44 +02:00
class FlashReadPusCmd : public FlashBasePusCmd {
public:
FlashReadPusCmd(){};
ReturnValue_t extractFields(const uint8_t* commandData, size_t commandDataLen) override {
ReturnValue_t result = FlashBasePusCmd::extractFields(commandData, commandDataLen);
if (result != returnvalue::OK) {
return result;
}
if (commandDataLen < (getParsedSize() + 4)) {
return returnvalue::FAILED;
}
size_t deserDummy = 4;
return SerializeAdapter::deSerialize(&readSize, commandData + getParsedSize(), &deserDummy,
SerializeIF::Endianness::NETWORK);
}
size_t getReadSize() const { return readSize; }
private:
size_t readSize = 0;
};
2022-03-24 17:39:50 +01:00
/**
* @brief Class to build replay stop space packet.
*/
class TcModeReplay : public TcBase {
2022-03-26 20:47:25 +01:00
public:
2022-08-15 18:34:26 +02:00
TcModeReplay(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_MODE_REPLAY, sequenceCount) {}
2022-03-24 17:39:50 +01:00
};
2022-04-20 21:33:39 +02:00
/**
* @brief Class to build mode idle command
*/
class TcModeIdle : public TcBase {
public:
2022-08-15 18:34:26 +02:00
TcModeIdle(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_MODE_IDLE, sequenceCount) {}
2022-04-20 21:33:39 +02:00
};
2023-02-14 14:00:53 +01:00
/**
* @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) {}
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2024-04-30 15:14:22 +02:00
const uint8_t** dataPtr = &commandData;
if (commandDataLen > FULL_PAYLOAD_SIZE) {
2023-03-13 11:05:21 +01:00
return INVALID_LENGTH;
}
2024-04-30 15:14:22 +02:00
size_t deserLen = commandDataLen;
size_t serLen = 0;
2024-06-17 16:09:55 +02:00
fileName = std::string(reinterpret_cast<const char*>(commandData));
2024-04-30 15:14:22 +02:00
if (fileName.size() > MAX_FILENAME_SIZE) {
2023-03-13 11:05:21 +01:00
return FILENAME_TOO_LONG;
}
2024-04-30 15:14:22 +02:00
deserLen -= fileName.length() + 1;
*dataPtr += fileName.length() + 1;
uint8_t** payloadPtr = &payloadStart;
2024-06-17 16:09:55 +02:00
memset(payloadStart, 0, FILENAME_FIELD_SIZE);
2024-04-30 15:14:22 +02:00
memcpy(payloadStart, fileName.data(), fileName.size());
*payloadPtr += FILENAME_FIELD_SIZE;
serLen += FILENAME_FIELD_SIZE;
ReturnValue_t result = SerializeAdapter::deSerialize(&encoderSettingY, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
2023-03-13 11:05:21 +01:00
}
2024-04-30 15:14:22 +02:00
result = SerializeAdapter::serialize(&encoderSettingY, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&quantizationY, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&quantizationY, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&encoderSettingsCb, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&encoderSettingsCb, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&quantizationCb, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&quantizationCb, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&encoderSettingsCr, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&encoderSettingsCr, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&quantizationCr, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&quantizationCr, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&bypassCompressor, dataPtr, &deserLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&bypassCompressor, payloadPtr, &serLen, FULL_PAYLOAD_SIZE,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
spParams.setFullPayloadLen(FULL_PAYLOAD_SIZE + CRC_SIZE);
2023-03-13 11:05:21 +01:00
return returnvalue::OK;
}
2024-04-30 15:14:22 +02:00
std::string fileName;
uint8_t encoderSettingY = 7;
uint64_t quantizationY = 0;
uint8_t encoderSettingsCb = 7;
uint64_t quantizationCb = 0;
uint8_t encoderSettingsCr = 7;
uint64_t quantizationCr = 0;
uint8_t bypassCompressor = 0;
2023-03-13 11:05:21 +01:00
private:
static const size_t PARAMETER_SIZE = 28;
2024-04-30 15:14:22 +02:00
static constexpr size_t FULL_PAYLOAD_SIZE = FILENAME_FIELD_SIZE + PARAMETER_SIZE;
};
/**
* @brief Class to build simplex send file command
*/
2024-04-30 15:14:22 +02:00
class TcSimplexStreamFile : public TcBase {
public:
2024-04-30 15:14:22 +02:00
TcSimplexStreamFile(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {}
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2024-04-30 15:14:22 +02:00
if (commandDataLen > MAX_FILENAME_SIZE) {
2023-03-13 11:05:21 +01:00
return INVALID_LENGTH;
}
2023-03-13 11:05:21 +01:00
std::string fileName(reinterpret_cast<const char*>(commandData));
2024-04-30 15:14:22 +02:00
if (fileName.size() > MAX_FILENAME_SIZE) {
2023-03-13 11:05:21 +01:00
return FILENAME_TOO_LONG;
}
2024-04-30 15:14:22 +02:00
std::memset(payloadStart, 0, FILENAME_FIELD_SIZE);
std::memcpy(payloadStart, fileName.data(), fileName.length());
payloadStart[fileName.length()] = 0;
spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE);
;
return returnvalue::OK;
}
private:
};
/**
* @brief Class to build simplex send file command
*/
2024-05-06 14:17:25 +02:00
class TcSplitFile : public TcBase {
2024-04-30 15:14:22 +02:00
public:
2024-05-06 14:17:25 +02:00
TcSplitFile(ploc::SpTcParams params, uint16_t sequenceCount)
2024-04-30 15:14:22 +02:00
: TcBase(params, apid::TC_SIMPLEX_SEND_FILE, sequenceCount) {}
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
if (commandDataLen < MIN_DATA_LENGTH) {
return INVALID_LENGTH;
}
if (commandDataLen > MAX_DATA_LENGTH) {
return INVALID_LENGTH;
}
const uint8_t** dataPtr = &commandData;
ReturnValue_t result = SerializeAdapter::deSerialize(&chunkParameter, dataPtr, &commandDataLen,
SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
/// No chunks makes no sense, and DIV str can not be longer than whats representable with 3
/// decimal digits.
if (chunkParameter == 0 or chunkParameter > 999) {
return INVALID_PARAMETER;
}
std::string fileName(reinterpret_cast<const char*>(*dataPtr));
if (fileName.size() > MAX_FILENAME_SIZE) {
return FILENAME_TOO_LONG;
}
char divStr[16]{};
sprintf(divStr, "DIV%03u", chunkParameter);
std::memcpy(payloadStart, divStr, DIV_STR_LEN);
payloadStart[DIV_STR_LEN] = 0;
std::memset(payloadStart + DIV_STR_LEN + 1, 0, FILENAME_FIELD_SIZE - DIV_STR_LEN - 1);
std::memcpy(payloadStart + DIV_STR_LEN + 1, fileName.data(), fileName.length());
spParams.setFullPayloadLen(FILENAME_FIELD_SIZE + CRC_SIZE);
2023-03-13 11:05:21 +01:00
return returnvalue::OK;
}
2023-03-13 11:05:21 +01:00
private:
2024-04-30 15:14:22 +02:00
uint32_t chunkParameter = 0;
static constexpr size_t MIN_DATA_LENGTH = 4;
static constexpr size_t DIV_STR_LEN = 6;
static constexpr size_t MAX_DATA_LENGTH = 4 + MAX_FILENAME_SIZE;
};
/**
* @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) {}
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2023-03-13 11:05:21 +01:00
if (commandDataLen > MAX_DATA_LENGTH) {
return INVALID_LENGTH;
}
2023-03-13 11:05:21 +01:00
spParams.setFullPayloadLen(commandDataLen + CRC_SIZE);
std::memcpy(payloadStart, commandData, commandDataLen);
return returnvalue::OK;
}
2023-03-13 11:05:21 +01:00
private:
static const size_t MAX_DATA_LENGTH = 11;
};
2022-04-20 21:33:39 +02:00
class TcCamcmdSend : public TcBase {
2022-04-22 14:09:08 +02:00
public:
2022-08-15 18:34:26 +02:00
TcCamcmdSend(ploc::SpTcParams params, uint16_t sequenceCount)
: TcBase(params, apid::TC_CAM_CMD_SEND, sequenceCount) {}
2022-04-20 21:33:39 +02:00
2023-05-16 13:34:06 +02:00
ReturnValue_t setPayload(const uint8_t* commandData, size_t commandDataLen) {
2022-04-22 14:09:08 +02:00
if (commandDataLen > MAX_DATA_LENGTH) {
return INVALID_LENGTH;
}
uint16_t dataLen = static_cast<uint16_t>(commandDataLen + sizeof(CARRIAGE_RETURN));
2022-11-07 10:30:09 +01:00
spParams.setFullPayloadLen(sizeof(dataLen) + commandDataLen + sizeof(CARRIAGE_RETURN) +
CRC_SIZE);
2022-08-16 18:37:51 +02:00
auto res = checkPayloadLen();
2022-08-24 17:27:47 +02:00
if (res != returnvalue::OK) {
2022-08-16 18:37:51 +02:00
return res;
}
2022-08-20 12:11:08 +02:00
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;
2022-08-16 18:37:51 +02:00
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-22 14:09:08 +02:00
}
2022-04-20 21:33:39 +02:00
2022-04-22 14:09:08 +02:00
private:
static const uint8_t MAX_DATA_LENGTH = 10;
static const uint8_t CARRIAGE_RETURN = 0xD;
2022-04-20 21:33:39 +02:00
};
2023-05-02 15:04:14 +02:00
class HkReport : public StaticLocalDataSet<36> {
public:
HkReport(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, HK_SET_ID) {}
HkReport(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, HK_SET_ID)) {}
lp_var_t<uint32_t> status = lp_var_t<uint32_t>(sid.objectId, mpsoc::poolid::STATUS, this);
lp_var_t<uint8_t> mode = lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::MODE, this);
lp_var_t<uint8_t> downlinkPwrOn =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::DOWNLINK_PWR_ON, this);
lp_var_t<uint8_t> downlinkReplyActive =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::DOWNLINK_REPLY_ACTIIVE, this);
lp_var_t<uint8_t> downlinkJesdSyncStatus =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::DOWNLINK_JESD_SYNC_STATUS, this);
lp_var_t<uint8_t> downlinkDacStatus =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::DOWNLINK_DAC_STATUS, this);
lp_var_t<uint8_t> camStatus = lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::CAM_STATUS, this);
lp_var_t<uint8_t> camSdiStatus =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::CAM_SDI_STATUS, this);
lp_var_t<float> camFpgaTemp = lp_var_t<float>(sid.objectId, mpsoc::poolid::CAM_FPGA_TEMP, this);
lp_var_t<float> camSocTemp = lp_var_t<float>(sid.objectId, mpsoc::poolid::CAM_SOC_TEMP, this);
lp_var_t<float> sysmonTemp = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_TEMP, this);
lp_var_t<float> sysmonVccInt = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCINT, this);
lp_var_t<float> sysmonVccAux = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCAUX, this);
lp_var_t<float> sysmonVccBram =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCBRAM, this);
lp_var_t<float> sysmonVccPaux =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCPAUX, this);
lp_var_t<float> sysmonVccPint =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCPINT, this);
lp_var_t<float> sysmonVccPdro =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCCPDRO, this);
lp_var_t<float> sysmonMb12V = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_MB12V, this);
lp_var_t<float> sysmonMb3V3 = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_MB3V3, this);
lp_var_t<float> sysmonMb1V8 = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_MB1V8, this);
lp_var_t<float> sysmonVcc12V = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC12V, this);
lp_var_t<float> sysmonVcc5V = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC5V, this);
lp_var_t<float> sysmonVcc3V3 = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC3V3, this);
lp_var_t<float> sysmonVcc3V3VA =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC3V3VA, this);
lp_var_t<float> sysmonVcc2V5DDR =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC2V5DDR, this);
lp_var_t<float> sysmonVcc1V2DDR =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC1V2DDR, this);
lp_var_t<float> sysmonVcc0V9 = lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC0V9, this);
lp_var_t<float> sysmonVcc0V6VTT =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_VCC0V6VTT, this);
lp_var_t<float> sysmonSafeCotsCur =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_SAFE_COTS_CUR, this);
lp_var_t<float> sysmonNvm4XoCur =
lp_var_t<float>(sid.objectId, mpsoc::poolid::SYSMON_NVM4_XO_CUR, this);
lp_var_t<uint16_t> semUncorrectableErrs =
lp_var_t<uint16_t>(sid.objectId, mpsoc::poolid::SEM_UNCORRECTABLE_ERRS, this);
lp_var_t<uint16_t> semCorrectableErrs =
lp_var_t<uint16_t>(sid.objectId, mpsoc::poolid::SEM_CORRECTABLE_ERRS, this);
2023-05-12 12:37:25 +02:00
lp_var_t<uint8_t> semStatus = lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::SEM_STATUS, this);
2023-05-02 15:04:14 +02:00
lp_var_t<uint8_t> rebootMpsocRequired =
lp_var_t<uint8_t>(sid.objectId, mpsoc::poolid::REBOOT_MPSOC_REQUIRED, this);
};
2023-05-15 15:15:58 +02:00
uint16_t getStatusFromRawData(const uint8_t* data);
std::string getStatusString(uint16_t status);
2023-05-15 14:40:14 +02:00
2022-03-26 20:47:25 +01:00
} // namespace mpsoc
2022-03-24 17:39:50 +01:00
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_PLOCMPSOCDEFINITIONS_H_ */