From 755590b43b63229c9b6cb37bfff502a600257c39 Mon Sep 17 00:00:00 2001 From: mverch67 Date: Fri, 20 Dec 2024 20:55:07 +0100 Subject: [PATCH] fix native issues --- include/ViewController.h | 2 +- source/LogRotate.cpp | 37 ++++++++++++++++++++----------------- source/TFTView_320x240.cpp | 2 +- source/ViewController.cpp | 11 +++++++---- 4 files changed, 29 insertions(+), 23 deletions(-) diff --git a/include/ViewController.h b/include/ViewController.h index 738f7ef..83d70b7 100644 --- a/include/ViewController.h +++ b/include/ViewController.h @@ -61,7 +61,7 @@ class ViewController virtual bool sendConfig(meshtastic_ModuleConfig_PaxcounterConfig &&paxCounter, uint32_t nodeId = 0); virtual bool sendConfig(const char ringtone[231], uint32_t nodeId = 0); - virtual void sendTextMessage(uint32_t to, uint8_t ch, uint8_t hopLimit, uint32_t requestId, bool usePkc, const char *textmsg); + virtual void sendTextMessage(uint32_t to, uint8_t ch, uint8_t hopLimit, uint32_t msgTime, uint32_t requestId, bool usePkc, const char *textmsg); virtual void removeTextMessages(uint32_t from, uint32_t to, uint8_t ch); virtual bool requestPosition(uint32_t to, uint8_t ch, uint32_t requestId); virtual void traceRoute(uint32_t to, uint8_t ch, uint8_t hopLimit, uint32_t requestId); diff --git a/source/LogRotate.cpp b/source/LogRotate.cpp index a0dc9a3..4b60e0b 100644 --- a/source/LogRotate.cpp +++ b/source/LogRotate.cpp @@ -8,7 +8,7 @@ LogRotate::LogRotate(fs::FS &fs, const char *logDir, uint32_t maxLen, uint32_t m : _fs(fs), numFiles(0), minLogNum(0), currentLogNum(0), currentSize(0), currentCount(0), totalSize(0), rootDirName(logDir), c_maxLen(maxLen), c_maxSize(maxSize), c_maxFiles(maxFiles), c_maxFileSize(maxFileSize) { - init(); + //init(); } void LogRotate::init(void) @@ -28,14 +28,15 @@ void LogRotate::init(void) currentSize = 0; } } + + ILOG_INFO("LogRotate: found %d log files using %d bytes (%d%%).", numFiles, totalSize, (totalSize * 100) / c_maxSize); if (minLogNum == 0) { numFiles = 1; minLogNum = 1; currentLogNum = 1; } currentLogName = logFileName(currentLogNum); - ILOG_INFO("LogRotate: found %d log files using %d bytes (%d%%). Logging to %s", numFiles - 1, totalSize, - (totalSize * 100) / c_maxSize, currentLogName.c_str()); + ILOG_INFO("Logging to %s", currentLogName.c_str()); } /** @@ -87,7 +88,7 @@ bool LogRotate::write(const ILogEntry &entry) } // elegant way to let the logentry do its work it knows best and pass just a temporary function for writing - File file = _fs.open(currentLogName, FILE_APPEND, true); + File file = _fs.open(currentLogName, FILE_APPEND); entry.serialize([&file](const uint8_t *buf, size_t size) { return file.write(buf, size); }); file.close(); @@ -201,19 +202,21 @@ void LogRotate::scanLogDir(uint32_t &num, uint32_t &minLog, uint32_t &maxLog, ui if (!rootDir) rootDir = _fs.open(rootDirName); File file = rootDir.openNextFile(); - while (file && !file.isDirectory()) { - num++; - size_t size = file.size(); - total += size; - ILOG_DEBUG(" %s(%d bytes)", file.name(), size); - uint32_t logNum = 0; - if (sscanf(file.name(), FILE_PREFIX "%u", &logNum) > 0 && logNum > 0) { - if (logNum < minLog) { - minLog = logNum; - } - if (logNum > maxLog) { - maxLog = logNum; - logSize = size; + while (file) { + if (!file.isDirectory()) { + num++; + size_t size = file.size(); + total += size; + ILOG_DEBUG(" %s(%d bytes)", file.name(), size); + uint32_t logNum = 0; + if (sscanf(file.name(), "%*s" FILE_PREFIX "%u.log", &logNum) > 0 && logNum > 0) { + if (logNum < minLog) { + minLog = logNum; + } + if (logNum > maxLog) { + maxLog = logNum; + logSize = size; + } } } file = rootDir.openNextFile(); diff --git a/source/TFTView_320x240.cpp b/source/TFTView_320x240.cpp index eb9e377..fa3d33d 100644 --- a/source/TFTView_320x240.cpp +++ b/source/TFTView_320x240.cpp @@ -3264,7 +3264,7 @@ void TFTView_320x240::handleAddMessage(char *msg) if (msg[i] == CR_REPLACEMENT) msg[i] = '\n'; - controller->sendTextMessage(to, ch, hopLimit, requestId, usePkc, msg); + controller->sendTextMessage(to, ch, hopLimit, actTime, requestId, usePkc, msg); addMessage(activeMsgContainer, actTime, requestId, msg, LogMessage::eDefault); } diff --git a/source/ViewController.cpp b/source/ViewController.cpp index 66e70c8..d2f91e5 100644 --- a/source/ViewController.cpp +++ b/source/ViewController.cpp @@ -35,7 +35,7 @@ void ViewController::init(MeshtasticView *gui, IClientBase *_client) client->init(); client->connect(); } - // log.init(); + log.init(); } /** @@ -427,13 +427,16 @@ void ViewController::setConfigRequested(bool required) requestConfigRequired = required; } -void ViewController::sendTextMessage(uint32_t to, uint8_t ch, uint8_t hopLimit, uint32_t requestId, bool usePkc, +void ViewController::sendTextMessage(uint32_t to, uint8_t ch, uint8_t hopLimit, uint32_t msgTime, uint32_t requestId, bool usePkc, const char *textmsg) { size_t msgLen = strlen(textmsg); assert(msgLen <= (size_t)DATA_PAYLOAD_LEN); - log.write(LogMessageEnv(myNodeNum, to, ch, 0L, LogMessage::eDefault, false, msgLen, (const uint8_t *)textmsg)); - send(to, ch, hopLimit, requestId, meshtastic_PortNum_TEXT_MESSAGE_APP, false, usePkc, (const uint8_t *)textmsg, msgLen); + + if (send(to, ch, hopLimit, requestId, meshtastic_PortNum_TEXT_MESSAGE_APP, false, usePkc, (const uint8_t *)textmsg, msgLen)) { + ILOG_DEBUG("storing msg to:0x%08x, ch:%d, time:%d, size:%d, '%s'", to, ch, msgTime, msgLen, textmsg); + log.write(LogMessageEnv(myNodeNum, to, ch, msgTime, LogMessage::eDefault, false, msgLen, (const uint8_t *)textmsg)); + } } bool ViewController::requestPosition(uint32_t to, uint8_t ch, uint32_t requestId)