diff --git a/common/config/devConf.h b/common/config/devConf.h index 931d1ad1..beb01282 100644 --- a/common/config/devConf.h +++ b/common/config/devConf.h @@ -60,7 +60,7 @@ static constexpr UartBaudRate SYRLINKS_BAUD = UartBaudRate::RATE_38400; static constexpr UartBaudRate SCEX_BAUD = UartBaudRate::RATE_115200; static constexpr UartBaudRate GNSS_BAUD = UartBaudRate::RATE_9600; static constexpr UartBaudRate PLOC_MPSOC_BAUD = UartBaudRate::RATE_115200; -static constexpr UartBaudRate PLOC_SUPV_BAUD = UartBaudRate::RATE_115200; +static constexpr UartBaudRate PLOC_SUPV_BAUD = UartBaudRate::RATE_921600; static constexpr UartBaudRate STAR_TRACKER_BAUD = UartBaudRate::RATE_921600; } // namespace uart diff --git a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h index 68ac6447..cb0639fa 100644 --- a/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h +++ b/linux/devices/devicedefinitions/PlocSupervisorDefinitions.h @@ -122,6 +122,7 @@ static const DeviceCommandId_t RESET_PL = 58; static const DeviceCommandId_t ENABLE_NVMS = 59; static const DeviceCommandId_t CONTINUE_UPDATE = 60; static const DeviceCommandId_t MEMORY_CHECK_WITH_FILE = 61; +static constexpr DeviceCommandId_t MEMORY_CHECK = 62; /** Reply IDs */ enum ReplyId : DeviceCommandId_t { diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index b022f119..08c63b1a 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -411,6 +411,7 @@ void PlocSupervisorHandler::fillCommandAndReplyMap() { insertInCommandMap(SET_GPIO); insertInCommandMap(READ_GPIO); insertInCommandMap(FACTORY_RESET); + insertInCommandMap(MEMORY_CHECK); insertInCommandMap(SET_SHUTDOWN_TIMEOUT); insertInCommandMap(FACTORY_FLASH); insertInCommandMap(SET_ADC_ENABLED_CHANNELS); @@ -421,6 +422,7 @@ void PlocSupervisorHandler::fillCommandAndReplyMap() { // ACK replies, use countdown for them insertInReplyMap(ACK_REPORT, 0, nullptr, SIZE_ACK_REPORT, false, &acknowledgementReportTimeout); insertInReplyMap(EXE_REPORT, 0, nullptr, SIZE_EXE_REPORT, false, &executionReportTimeout); + insertInReplyMap(MEMORY_CHECK, 5, nullptr, 0, false); // TM replies insertInReplyMap(HK_REPORT, 3, &hkset, SIZE_HK_REPORT); @@ -507,6 +509,16 @@ ReturnValue_t PlocSupervisorHandler::enableReplyInReplyMap(DeviceCommandMap::ite } break; } + case MEMORY_CHECK: { + enabledReplies = 3; + result = + DeviceHandlerBase::enableReplyInReplyMap(command, enabledReplies, true, MEMORY_CHECK); + if (result != returnvalue::OK) { + sif::debug << "PlocSupervisorHandler::enableReplyInReplyMap: Reply with id " << MEMORY_CHECK + << " not in replyMap" << std::endl; + } + break; + } case START_MPSOC: case SHUTDOWN_MPSOC: case SEL_MPSOC_BOOT_IMAGE: @@ -625,10 +637,7 @@ ReturnValue_t PlocSupervisorHandler::scanForReply(const uint8_t* start, size_t r static_cast(supv::tm::MemManId::UPDATE_STATUS_REPORT)) { *foundLen = tmReader.getFullPacketLen(); *foundId = ReplyId::UPDATE_STATUS_REPORT; - // TODO: I think this will be handled by the uart manager? - // Actually, this is a bit tricky. Maybe the lower level will have two separate ring - // buffers, one for internally handled packets and one for packets which are handled - // here? + return OK; } } } @@ -667,6 +676,10 @@ ReturnValue_t PlocSupervisorHandler::interpretDeviceReply(DeviceCommandId_t id, result = handleExecutionReport(packet); break; } + case (UPDATE_STATUS_REPORT): { + // TODO: handle status report here + break; + } default: { sif::debug << "PlocSupervisorHandler::interpretDeviceReply: Unknown device reply id" << std::endl; diff --git a/linux/devices/ploc/PlocSupvUartMan.cpp b/linux/devices/ploc/PlocSupvUartMan.cpp index 890a1240..f2ce3b3b 100644 --- a/linux/devices/ploc/PlocSupvUartMan.cpp +++ b/linux/devices/ploc/PlocSupvUartMan.cpp @@ -116,7 +116,9 @@ ReturnValue_t PlocSupvUartManager::performOperation(uint8_t operationCode) { break; } case InternalState::DEDICATED_REQUEST: { + updateVtime(1); handleRunningLongerRequest(); + updateVtime(2); MutexGuard mg(lock); state = InternalState::DEFAULT; break; @@ -380,9 +382,9 @@ ReturnValue_t PlocSupvUartManager::writeUpdatePackets() { #endif /* OBSW_DEBUG_PLOC_SUPERVISOR == 1 */ uint8_t tempData[supv::WriteMemory::CHUNK_MAX + 1]{}; if (not std::filesystem::exists(update.file)) { - sif::error << "PlocSupvUartManager::writeUpdatePackets: File " - << update.file << " does not exist" << std::endl; - return HasFileSystemIF::FILE_DOES_NOT_EXIST; + sif::error << "PlocSupvUartManager::writeUpdatePackets: File " << update.file + << " does not exist" << std::endl; + return HasFileSystemIF::FILE_DOES_NOT_EXIST; } std::ifstream file(update.file, std::ifstream::binary); uint16_t dataLength = 0; @@ -553,6 +555,7 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( return result; } Countdown countdown(timeoutExecutionReport); + dur_millis_t currentDelay = 5; bool ackReceived = false; bool packetWasHandled = false; while (true) { @@ -590,7 +593,10 @@ ReturnValue_t PlocSupvUartManager::handlePacketTransmissionNoReply( decodedRingBuf.deleteData(packetLen); } } else { - TaskFactory::delayTask(20); + TaskFactory::delayTask(currentDelay); + if (currentDelay < 20) { + currentDelay *= 2; + } } if (countdown.hasTimedOut()) { return result::NO_REPLY_TIMEOUT; @@ -1095,9 +1101,11 @@ void PlocSupvUartManager::addHdlcFraming(const uint8_t* src, size_t slen, uint8_ } size_t dummy = 0; + uint8_t crcRaw[2]; // hdlc crc16 is in little endian format - SerializeAdapter::serialize(&crc16, dst + tlen, &dummy, maxDest, SerializeIF::Endianness::LITTLE); - tlen += dummy; + SerializeAdapter::serialize(&crc16, crcRaw, &dummy, maxDest, SerializeIF::Endianness::LITTLE); + hdlc_add_byte(crcRaw[0], dst, &tlen); + hdlc_add_byte(crcRaw[1], dst, &tlen); dst[tlen++] = 0x7C; *dlen = tlen; @@ -1141,3 +1149,9 @@ bool PlocSupvUartManager::longerRequestActive() const { MutexGuard mg(lock); return state == InternalState::DEDICATED_REQUEST; } + +void PlocSupvUartManager::updateVtime(uint8_t vtime) { + tcgetattr(serialPort, &tty); + tty.c_cc[VTIME] = vtime; + tcsetattr(serialPort, TCSANOW, &tty); +} diff --git a/linux/devices/ploc/PlocSupvUartMan.h b/linux/devices/ploc/PlocSupvUartMan.h index 9ebfac02..e1539c97 100644 --- a/linux/devices/ploc/PlocSupvUartMan.h +++ b/linux/devices/ploc/PlocSupvUartMan.h @@ -253,7 +253,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, std::array tmBuf{}; - bool printTc = true; + bool printTc = false; bool debugMode = false; bool timestamping = true; @@ -368,6 +368,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF, 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_ */