clean up op done
This commit is contained in:
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_ */
|
Reference in New Issue
Block a user