Skip to content

Commit

Permalink
fix native issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mverch67 committed Dec 20, 2024
1 parent 6f58fb4 commit 755590b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 20 additions & 17 deletions source/LogRotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion source/TFTView_320x240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 7 additions & 4 deletions source/ViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void ViewController::init(MeshtasticView *gui, IClientBase *_client)
client->init();
client->connect();
}
// log.init();
log.init();
}

/**
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 755590b

Please sign in to comment.