Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: LogRotate #29

Merged
merged 14 commits into from
Dec 31, 2024
3 changes: 2 additions & 1 deletion generated/ui_320x240/images.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "images.h"

const ext_img_desc_t images[68] = {
const ext_img_desc_t images[69] = {
{ "meshtastic_boot_logo_image", &img_meshtastic_boot_logo_image },
{ "settings_button_image", &img_settings_button_image },
{ "map_button_image", &img_map_button_image },
Expand Down Expand Up @@ -69,4 +69,5 @@ const ext_img_desc_t images[68] = {
{ "home_fair_signal_image", &img_home_fair_signal_image },
{ "home_strong_signal_image", &img_home_strong_signal_image },
{ "home_good_signal_image", &img_home_good_signal_image },
{ "lock_slash_image", &img_lock_slash_image },
};
3 changes: 2 additions & 1 deletion generated/ui_320x240/images.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extern const lv_img_dsc_t img_home_weak_signal_image;
extern const lv_img_dsc_t img_home_fair_signal_image;
extern const lv_img_dsc_t img_home_strong_signal_image;
extern const lv_img_dsc_t img_home_good_signal_image;
extern const lv_img_dsc_t img_lock_slash_image;

#ifndef EXT_IMG_DESC_T
#define EXT_IMG_DESC_T
Expand All @@ -84,7 +85,7 @@ typedef struct _ext_img_desc_t {
} ext_img_desc_t;
#endif

extern const ext_img_desc_t images[68];
extern const ext_img_desc_t images[69];


#ifdef __cplusplus
Expand Down
79 changes: 79 additions & 0 deletions generated/ui_320x240/ui_image_lock_slash_image.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifdef __has_include
#if __has_include("lvgl.h")
#ifndef LV_LVGL_H_INCLUDE_SIMPLE
#define LV_LVGL_H_INCLUDE_SIMPLE
#endif
#endif
#endif

#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include "lvgl.h"
#elif defined(LV_BUILD_TEST)
#include "../lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif


#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

#ifndef LV_ATTRIBUTE_IMG_LOCK_SLASH_IMAGE
#define LV_ATTRIBUTE_IMG_LOCK_SLASH_IMAGE
#endif

static const
LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_LARGE_CONST LV_ATTRIBUTE_IMG_LOCK_SLASH_IMAGE
uint8_t img_lock_slash_image_map[] = {

0xdb,0xde,0x3c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xdb,0xde,0x00,0x00,0x00,0x00,0xdb,0xde,0xba,0xd6,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xba,0xd6,0xdb,0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x3c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x3c,0xe7,0xdb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0xdb,0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0x3c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x9e,0xf7,0xdb,0xde,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x1c,0xe7,0x1c,0xe7,0xfb,0xde,0x1c,0xe7,0x3c,0xe7,0xfb,0xde,0x1c,0xe7,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0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0xfb,0xde,
0x00,0x00,0x00,0x00,0xfb,0xde,0xdb,0xde,0x1c,0xe7,0xdb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xdb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0x3c,0xe7,
0x00,0x00,0x00,0x00,0x00,0x00,0xba,0xd6,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0xfb,0xde,0x1c,0xe7,0xfb,0xde,0xfb,0xde,0x3c,0xe7,0xdb,0xde,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x0a,0x1b,0x1b,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x0e,0xac,0xb8,0x27,0x00,0x00,0x00,0x15,0x72,0xbf,0xde,0xde,0xbf,0x73,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0xb8,0xff,0xc3,0x26,0x00,0x00,0x85,0xff,0xfe,0xe8,0xe8,0xfe,0xff,0xc0,0x2d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x27,0xc3,0xff,0xc3,0x26,0x00,0x50,0xa6,0x59,0x25,0x25,0x58,0xc8,0xff,0xc0,0x17,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x02,0x00,0x00,0x00,0x00,0x22,0xc8,0xff,0x73,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x26,0xc2,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x58,0xfe,0xbf,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x34,0xea,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,0x00,0x24,0xe8,0xdd,0x1b,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1f,0xe1,0xff,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,0x33,0xe6,0xe4,0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0xac,0xfa,0xff,0xff,0xff,0xc3,0x26,0x00,0x00,0x41,0xdb,0xfe,0xfa,0xac,0x37,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x37,0xdd,0xff,0xee,0xe2,0xe0,0xea,0xff,0xc3,0x26,0x00,0x42,0xd7,0xe3,0xee,0xff,0xdd,0x37,0x00,0x00,0x00,0x00,0x00,0x04,0xa6,0xff,0xa7,0x32,0x20,0x1d,0x35,0xc2,0xff,0xc3,0x26,0x00,0x18,0x20,0x32,0xa7,0xff,0xa6,0x04,0x00,0x00,
0x00,0x00,0x15,0xd6,0xf0,0x32,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x00,0x00,0x32,0xf0,0xd6,0x15,0x00,0x00,0x00,0x00,0x1d,0xe1,0xe4,0x20,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x00,0x20,0xe5,0xe1,0x1e,0x00,0x00,
0x00,0x00,0x1f,0xe2,0xe2,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x18,0xd7,0xd7,0x18,0x00,0x00,0x00,0x00,0x1f,0xe2,0xe2,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x42,0x41,0x02,0x00,0x00,
0x00,0x00,0x1f,0xe2,0xe2,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1d,0xe1,0xe4,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0xc3,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,
0x00,0x00,0x15,0xd6,0xf0,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0xc0,0xff,0xc3,0x26,0x00,0x00,0x00,0x00,0x00,0x04,0xa6,0xff,0xa7,0x32,0x20,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1d,0x5a,0xee,0xff,0xc3,0x27,0x00,0x00,
0x00,0x00,0x00,0x37,0xdd,0xff,0xf0,0xe4,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe4,0xef,0xff,0xf9,0xff,0xb8,0x0e,0x00,0x00,0x00,0x00,0x00,0x37,0xa6,0xd6,0xe1,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe2,0xe1,0xd6,0xa4,0x56,0xb7,0xac,0x0e,0x00,
0x00,0x00,0x00,0x00,0x00,0x04,0x15,0x1d,0x1e,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1e,0x1d,0x15,0x04,0x00,0x0e,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

const lv_image_dsc_t img_lock_slash_image = {
.header.magic = LV_IMAGE_HEADER_MAGIC,
.header.cf = LV_COLOR_FORMAT_RGB565A8,
.header.flags = 0,
.header.w = 24,
.header.h = 24,
.header.stride = 48,
.data_size = sizeof(img_lock_slash_image_map),
.data = img_lock_slash_image_map,
};

23 changes: 23 additions & 0 deletions include/ILogEntry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <functional>
#include <stdint.h>

/**
* Generic interface base class for any log entries (stored via class LogRotate)
*/
class ILogEntry
{
public:
virtual size_t size(void) const = 0;
virtual size_t serialize(std::function<size_t(const uint8_t *, size_t)> write) const = 0;
virtual size_t deserialize(std::function<size_t(uint8_t *, size_t)> read) = 0;
virtual ~ILogEntry() = default;

protected:
ILogEntry(void) = default;

private:
ILogEntry(const ILogEntry &) = delete;
ILogEntry &operator=(const ILogEntry &) = delete;
};
4 changes: 2 additions & 2 deletions include/LGFXDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ template <class LGFX> void LGFXDriver<LGFX>::init_lgfx(void)
ILOG_INFO("Calibrating touch...");
#ifdef T_DECK
// FIXME: read calibration data from persistent storage using lfs_file_read
uint16_t parameters[8] = {11, 19, 6, 314, 218, 15, 229, 313};
uint16_t parameters[8] = {0, 2, 0, 314, 223, 5, 224, 314};
#elif defined(WT32_SC01)
uint16_t parameters[8] = {0, 2, 0, 479, 319, 0, 319, 479};
#elif defined(T_HMI)
Expand All @@ -324,7 +324,7 @@ template <class LGFX> void LGFXDriver<LGFX>::init_lgfx(void)
#elif defined(SENSECAP_INDICATOR)
uint16_t parameters[8] = {23, 3, 0, 479, 476, 2, 475, 479};
#else
uint16_t parameters[8] = {0, 0, 0, 0, 0, 0, 0, 0};
uint16_t parameters[8] = {0, 0, 0, 319, 239, 0, 239, 319};
ILOG_WARN("Touch screen has no calibration data!!!");
#endif

Expand Down
66 changes: 66 additions & 0 deletions include/LogMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include "ILogEntry.h"
#include <assert.h>
#include <ctime>
#include <memory.h>

constexpr uint32_t messagePayloadSize = 233;

/**
* @brief Header for storing message logs containing the actual size of the payload
* Note: this struct does have vtable pointers, i.e. sizeof(LogMessageHeader)-8 is the real data size
*/
struct LogMessageHeader : public ILogEntry {
uint16_t _size;
time_t time;
uint32_t from;
uint32_t to;
uint8_t ch;
enum MsgStatus : uint8_t { eNone, eDefault, eHeard, eNoResponse, eAcked, eFailed, eDeleted, eUnread } status;
bool trashFlag;
uint32_t reserved;
};

/**
* @brief Structure for storing message logs containing the actual payload
*/
struct LogMessage : public LogMessageHeader {
uint8_t bytes[messagePayloadSize];
};

/**
* Log message envelope that implements the actual interface for ILogEntry
* (size, serialize and deserialize)
*/
class LogMessageEnv : public LogMessage
{
public:
LogMessageEnv(void) = default;
LogMessageEnv(uint32_t _from, uint32_t _to, uint16_t _ch, time_t _time, MsgStatus _status, bool _trashFlag, uint32_t _len,
const uint8_t *msg)
{
assert(_len < messagePayloadSize);
_size = (uint16_t)_len;
time = _time;
from = _from;
to = _to;
ch = _ch;
status = _status;
trashFlag = _trashFlag;
reserved = 0;
memcpy(bytes, msg, _len);
}

size_t size(void) const override { return sizeof(LogMessageHeader) - 8 + _size; }

virtual size_t serialize(std::function<size_t(const uint8_t *, size_t)> write) const override
{
return write((uint8_t *)&_size, sizeof(LogMessageHeader) - 8) + write(bytes, _size);
}

virtual size_t deserialize(std::function<size_t(uint8_t *, size_t)> read) override
{
return read((uint8_t *)&_size, sizeof(LogMessageHeader) - 8) + read(bytes, _size);
}
};
69 changes: 69 additions & 0 deletions include/LogRotate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

Check failure on line 1 in include/LogRotate.h

View workflow job for this annotation

GitHub Actions / Trunk Check

clang-format

Incorrect formatting, autoformat by running 'trunk fmt'

#include "FS.h"
#include "ILogEntry.h"
#include <stdint.h>

/**
* Generic LogRotate class that writes log-rotation like files into (arduino) FS storage file system
* @param fs arduino file system FS/LittleFS or derived classes
* @param logDir directory to store the logs (absolute path)
* @param maxLen the maximum length of the variable log entry length
* The maximum storage is limited by:
* @param maxSize the total storage in bytes (default is 200kB)
* @param maxFiles number of log files (default is 50)
* @param maxFileSize per log file (default size is 4000 bytes to fit into a physical block
* including fs descriptor data)
*
* If the maximum storage is exceeded then old files are deleted to fit the new log entry.
* Note: for performance reasons the logs are not renumbered
*/
class LogRotate
{
public:
LogRotate(fs::FS &fs, const char *logDir, uint32_t maxLen,
uint32_t maxSize = 102400, uint32_t maxFiles = 25, uint32_t maxFileSize = 4000);
//uint32_t maxSize = 4096, uint32_t maxFiles = 10, uint32_t maxFileSize = 400);

// initialize the log directory
void init(void);
// write a log entry to fs
bool write(const ILogEntry &entry);
// read the next log entry from fs
bool readNext(ILogEntry &entry);
// remove all logs from fs
bool clear(void);
// request log count
uint32_t count(void);
// request current log number
uint32_t current(void);

private:
LogRotate(const LogRotate &) = delete;
LogRotate &operator=(const LogRotate &) = delete;

// create filename from number
String logFileName(uint32_t num);
// remove oldest log and return freed size
size_t removeLog(void);
// scan all files in logdir to get min/max log
void scanLogDir(uint32_t &num, uint32_t &minLog, uint32_t &maxLog, uint32_t &size, uint32_t &total);

const uint32_t c_maxLen; // maximum size a single log entry could be
const uint32_t c_maxSize; // max storage size in bytes (default is 100kB)
const uint32_t c_maxFiles; // max log files number (default is 50)
const uint32_t c_maxFileSize; // max file size per log file

fs::FS &_fs;
File rootDir; // directory (for reading logs)
File currentFile; // current file (when reading)
String rootDirName; // path of log directory
String currentLogName; // current log file name (when writing)
uint32_t numFiles; // number of log files
uint32_t minLogNum; // logfile with smallest number
uint32_t maxLogNum; // logfile with largest number after init()
uint32_t currentLogRead; // current log number (when reading)
uint32_t currentLogWrite; // current log number (when writing)
uint32_t currentSize; // size of current written log file
uint32_t totalSize; // size of all logs
};
10 changes: 7 additions & 3 deletions include/MeshtasticView.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "DeviceGUI.h"
#include "DisplayDriverConfig.h"
#include "LogMessage.h"
#include "ResponseHandler.h"
#include "lvgl.h"
#include "mesh-pb-constants.h"
Expand Down Expand Up @@ -47,7 +48,7 @@ class MeshtasticView : public DeviceGUI
};

// methods to update view
virtual void setupUIConfig(const meshtastic_DeviceUIConfig& uiconfig) {}
virtual void setupUIConfig(const meshtastic_DeviceUIConfig &uiconfig) {}
virtual void setMyInfo(uint32_t nodeNum);
virtual void setDeviceMetaData(int hw_model, const char *version, bool has_bluetooth, bool has_wifi, bool has_eth,
bool can_shutdown);
Expand All @@ -57,7 +58,7 @@ class MeshtasticView : public DeviceGUI
virtual void addNode(uint32_t nodeNum, uint8_t channel, const char *userShort, const char *userLong, uint32_t lastHeard,
eRole role, bool hasKey, bool viaMqtt);
virtual void updateNode(uint32_t nodeNum, uint8_t channel, const char *userShort, const char *userLong, uint32_t lastHeard,
eRole role, bool hasKey, bool viaMqtt);
eRole role, bool hasKey, bool viaMqtt);
virtual void updatePosition(uint32_t nodeNum, int32_t lat, int32_t lon, int32_t alt, uint32_t sats, uint32_t precision);
virtual void updateMetrics(uint32_t nodeNum, uint32_t bat_level, float voltage, float chUtil, float airUtil);
virtual void updateEnvironmentMetrics(uint32_t nodeNum, const meshtastic_EnvironmentMetrics &metrics) {}
Expand Down Expand Up @@ -102,7 +103,10 @@ class MeshtasticView : public DeviceGUI
virtual void handleResponse(uint32_t from, uint32_t id, const meshtastic_RouteDiscovery &route) {}
virtual void handlePositionResponse(uint32_t from, uint32_t request_id, int32_t rx_rssi, float rx_snr, bool isNeighbor) {}
virtual void packetReceived(const meshtastic_MeshPacket &p);
virtual void newMessage(uint32_t from, uint32_t to, uint8_t ch, const char *msg);
virtual void newMessage(uint32_t from, uint32_t to, uint8_t ch, const char *msg, uint32_t &msgtime, bool restore = false) {}
virtual void restoreMessage(const LogMessage &msg) {}
virtual void notifyRestoreMessages(int32_t percentage) {}
virtual void notifyMessagesRestored(void) {}
virtual void notifyResync(bool show);
virtual void notifyReboot(bool show);
virtual void notifyShutdown(void);
Expand Down
Loading
Loading