PLOC SUPV Update to newer firmware #316

Merged
muellerr merged 99 commits from mueller/tas_ploc_supv_update into develop 2022-11-18 14:27:13 +01:00
2 changed files with 131 additions and 49 deletions
Showing only changes of commit 45c95e559e - Show all commits

View File

@ -36,6 +36,45 @@ PlocSupvHelper::PlocSupvHelper(object_id_t objectId)
PlocSupvHelper::~PlocSupvHelper() = default; PlocSupvHelper::~PlocSupvHelper() = default;
ReturnValue_t PlocSupvHelper::initializeInterface(CookieIF* cookie) {
UartCookie* uartCookie = dynamic_cast<UartCookie*>(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
uart::setParity(tty, uartCookie->getParity());
uart::setStopbits(tty, uartCookie->getStopBits());
uart::setBitsPerWord(tty, BitsPerWord::BITS_8);
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
uart::enableRead(tty);
uart::ignoreCtrlLines(tty);
// Use non-canonical mode and clear echo flag
tty.c_lflag &= ~(ICANON | ECHO);
// Non-blocking mode, 0.5 seconds timeout
tty.c_cc[VTIME] = 5;
tty.c_cc[VMIN] = 0;
uart::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 PlocSupvHelper::initialize() { ReturnValue_t PlocSupvHelper::initialize() {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
sdcMan = SdCardManager::instance(); sdcMan = SdCardManager::instance();
@ -856,45 +895,6 @@ ReturnValue_t PlocSupvHelper::handleEventBufferReception(ploc::SpTmReader& reade
void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; } void PlocSupvHelper::resetSpParams() { spParams.buf = commandBuffer; }
ReturnValue_t PlocSupvHelper::initializeInterface(CookieIF* cookie) {
UartCookie* uartCookie = dynamic_cast<UartCookie*>(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
uart::setParity(tty, uartCookie->getParity());
uart::setStopbits(tty, uartCookie->getStopBits());
uart::setBitsPerWord(tty, BitsPerWord::BITS_8);
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
uart::enableRead(tty);
uart::ignoreCtrlLines(tty);
// Use non-canonical mode and clear echo flag
tty.c_lflag &= ~(ICANON | ECHO);
// Non-blocking mode, 0.5 seconds timeout
tty.c_cc[VTIME] = 5;
tty.c_cc[VMIN] = 0;
uart::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 PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData, ReturnValue_t PlocSupvHelper::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) { size_t sendLen) {
return returnvalue::OK; return returnvalue::OK;
@ -910,3 +910,77 @@ ReturnValue_t PlocSupvHelper::readReceivedMessage(CookieIF* cookie, uint8_t** bu
size_t* size) { size_t* size) {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t PlocSupvHelper::parseRecRingBufForHdlc() {
size_t availableData = recRingBuf.getAvailableReadData();
if (availableData == 0) {
return NO_PACKET_FOUND;
}
if(availableData > encodedBuf.size()) {
return DECODE_BUF_TOO_SMALL;
}
ReturnValue_t result = recRingBuf.readData(encodedBuf.data(), availableData);
if(result != returnvalue::OK) {
return result;
}
bool startMarkerFound = false;
size_t startIdx = 0;
return returnvalue::OK;
// if (result != returnvalue::OK) {
// ErrorInfo info;
// info.res = result;
// setErrorContext(ErrorTypes::RING_BUF_ERROR, info);
// return result;
// }
// bool stxFound = false;
// size_t stxIdx = 0;
// for (size_t vectorIdx = 0; vectorIdx < availableData; vectorIdx++) {
// // handle STX char
// if (encodedBuf.first[vectorIdx] == DleEncoder::STX_CHAR) {
// if (not stxFound) {
// stxFound = true;
// stxIdx = vectorIdx;
// } else {
// // might be lost packet, so we should advance the read pointer
// // without skipping the STX
// readSize = vectorIdx;
// ErrorInfo info;
// setErrorContext(ErrorTypes::CONSECUTIVE_STX_CHARS, info);
// return POSSIBLE_PACKET_LOSS;
// }
// }
// // handle ETX char
// if (encodedBuf.first[vectorIdx] == DleEncoder::ETX_CHAR) {
// if (stxFound) {
// // This is propably a packet, so we decode it.
// size_t decodedLen = 0;
// size_t dummy = 0;
//
// ReturnValue_t result =
// decoder.decode(&encodedBuf.first[stxIdx], availableData - stxIdx, &dummy,
// decodedBuf.first, decodedBuf.second,
//&decodedLen); if (result == returnvalue::OK) { ctx.setType(ContextType::PACKET_FOUND);
// ctx.decodedPacket.first = decodedBuf.first;
// ctx.decodedPacket.second = decodedLen;
// readSize = ++vectorIdx;
// return returnvalue::OK;
// } else {
// // invalid packet, skip.
// readSize = ++vectorIdx;
// ErrorInfo info;
// info.res = result;
// setErrorContext(ErrorTypes::DECODE_ERROR, info);
// return POSSIBLE_PACKET_LOSS;
// }
// } else {
// // might be lost packet, so we should advance the read pointer
// readSize = ++vectorIdx;
// ErrorInfo info;
// info.len = 0;
// setErrorContext(ErrorTypes::CONSECUTIVE_ETX_CHARS, info);
// return POSSIBLE_PACKET_LOSS;
// }
// }
// }
// return NO_PACKET_FOUND;
}

View File

@ -28,6 +28,17 @@ class PlocSupvHelper : public DeviceCommunicationIF,
public SystemObject, public SystemObject,
public ExecutableObjectIF { public ExecutableObjectIF {
public: 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; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PLOC_SUPV_HELPER;
//! [EXPORT] : [COMMENT] update failed //! [EXPORT] : [COMMENT] update failed
@ -146,17 +157,9 @@ class PlocSupvHelper : public DeviceCommunicationIF,
static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount); static uint32_t buildProgParams1(uint8_t percent, uint16_t seqCount);
private: private:
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 constexpr ReturnValue_t NO_PACKET_FOUND = returnvalue::makeCode(1, 0);
static constexpr ReturnValue_t DECODE_BUF_TOO_SMALL = returnvalue::makeCode(1, 1);
static const uint16_t CRC16_INIT = 0xFFFF; static const uint16_t CRC16_INIT = 0xFFFF;
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with // Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with
// 192 bytes // 192 bytes
@ -166,6 +169,9 @@ class PlocSupvHelper : public DeviceCommunicationIF,
static const uint32_t CRC_EXECUTION_TIMEOUT = 60000; static const uint32_t CRC_EXECUTION_TIMEOUT = 60000;
static const uint32_t PREPARE_UPDATE_EXECUTION_REPORT = 2000; static const uint32_t PREPARE_UPDATE_EXECUTION_REPORT = 2000;
static constexpr uint8_t HDLC_START_MARKER = 0x7C;
static constexpr uint8_t HDLC_END_MARKER = 0x7E;
struct Update { struct Update {
uint8_t memoryId; uint8_t memoryId;
uint32_t startAddress; uint32_t startAddress;
@ -216,6 +222,7 @@ class PlocSupvHelper : public DeviceCommunicationIF,
SdCardManager* sdcMan = nullptr; SdCardManager* sdcMan = nullptr;
#endif #endif
std::array<uint8_t, 2048> recBuf = {}; std::array<uint8_t, 2048> recBuf = {};
std::array<uint8_t, 2048> encodedBuf = {};
SimpleRingBuffer recRingBuf; SimpleRingBuffer recRingBuf;
uint8_t commandBuffer[supv::MAX_COMMAND_SIZE]{}; uint8_t commandBuffer[supv::MAX_COMMAND_SIZE]{};
SpacePacketCreator creator; SpacePacketCreator creator;
@ -239,6 +246,7 @@ class PlocSupvHelper : public DeviceCommunicationIF,
void executeFullCheckMemoryCommand(); void executeFullCheckMemoryCommand();
ReturnValue_t parseRecRingBufForHdlc();
ReturnValue_t executeUpdate(); ReturnValue_t executeUpdate();
ReturnValue_t continueUpdate(); ReturnValue_t continueUpdate();
ReturnValue_t updateOperation(); ReturnValue_t updateOperation();