Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
f3eba86
Rename CDataLogger to CFsDataLogger and add a CRawDataLogger class
AarC10 Sep 27, 2025
b0b2cca
Define functions
AarC10 Sep 27, 2025
3183697
Implementation for CRawDatalogger
AarC10 Sep 27, 2025
6674a02
Simplify
AarC10 Sep 27, 2025
92c4a5b
Introduce several modes for hitting EOF
AarC10 Sep 27, 2025
223199b
ReadMetaData and Find functions
AarC10 Sep 27, 2025
c18a762
grab filesize
AarC10 Sep 29, 2025
d1b01a5
Fix compile errors
AarC10 Sep 29, 2025
cdcf5db
MRead metadata and fix formatting and use off_t
AarC10 Sep 29, 2025
5c9b02c
Add sample for testing
AarC10 Sep 29, 2025
e4e445b
Blind write a sample for testing the logger
AarC10 Sep 30, 2025
69c89f6
Fix compile errors
AarC10 Sep 30, 2025
4e5355f
Fix temporary nullptr arg and add native sim overlay
AarC10 Sep 30, 2025
0a60059
Native sim overlay for sample
AarC10 Oct 1, 2025
e66047a
Grab flash controller
AarC10 Oct 3, 2025
cca7431
Add log statements
AarC10 Oct 3, 2025
bebd018
Fix starting offset
AarC10 Oct 3, 2025
229269f
Dont need a massive partition
AarC10 Oct 3, 2025
f8fb6bf
blast lfs
AarC10 Oct 3, 2025
ca0b897
Erase flash
AarC10 Oct 3, 2025
3e3417d
Log when data was successfully written
AarC10 Oct 9, 2025
a44b0ba
update datalogger metadata print statements for debugging why we aren…
AarC10 Oct 9, 2025
9568805
Update spaceleft, by having offset immediately account for the metadata
AarC10 Oct 9, 2025
7b4538a
Force flushes
AarC10 Oct 9, 2025
f0f32b3
Reset buffers function
AarC10 Oct 9, 2025
41ce2af
reset buffers
AarC10 Oct 9, 2025
9b6708a
Blast rotating file support
AarC10 Oct 9, 2025
9ac27ca
Passing fixed logger and linked fixed logger
AarC10 Oct 9, 2025
ee7a3cf
Need to figure out writing after intermediate
AarC10 Oct 9, 2025
867e58b
print num
AarC10 Oct 10, 2025
019c785
try seeking for next available space
AarC10 Oct 10, 2025
440cd94
seek functions and have prepMetadata do the flash write
AarC10 Oct 10, 2025
88a4402
Link to next file
AarC10 Oct 10, 2025
5d51e22
Check flash size first
AarC10 Oct 10, 2025
2bc7601
Get rid of warning by doing some fun casting
AarC10 Oct 10, 2025
7c12aa0
FindLinkedSpace needs LinkedFixed to check if the entire region it ne…
AarC10 Oct 10, 2025
d5bea74
add a hash for filename as part of the metadata
AarC10 Oct 10, 2025
89ab290
Make suer we select hash func to prevent linker error
AarC10 Oct 10, 2025
51fcba5
Rm jumping to next file while searching
AarC10 Oct 10, 2025
9ba4d2f
Fix jumping
AarC10 Oct 10, 2025
4f5c4c5
Bugfixes for writing new metadata
AarC10 Oct 10, 2025
1675960
delete flush function
AarC10 Oct 10, 2025
817a28a
remove metadata prep raw calls after we just called the function for it
AarC10 Oct 10, 2025
a1f6eaf
Closer to a working linked fixed implementation. Wrote a new file set
AarC10 Oct 10, 2025
b7acb16
Working linked fixed writing. Removed overwriting correct current fil…
AarC10 Oct 10, 2025
c65f512
Update test to increment addr to where we expect for truncate test
AarC10 Oct 10, 2025
89cbfb4
Jump better for fixed case. Store original file size for when we link…
AarC10 Oct 10, 2025
b196f46
Try simplifying finding linked space and try lowering file size for t…
AarC10 Oct 10, 2025
d8cc3b4
Fix looping in read metadata
AarC10 Oct 10, 2025
3200e4b
Rename file to log to avoid confusion
AarC10 Oct 10, 2025
7a0d59f
make findLinkedSpace private
AarC10 Oct 10, 2025
2b447b7
Properly search for metadata and prevent early exit
AarC10 Oct 10, 2025
65f3199
Remove debug prints
AarC10 Oct 10, 2025
4371474
clamp to prevent truncate from trying to write past flash size
AarC10 Oct 10, 2025
3a95500
Destructor
AarC10 Oct 10, 2025
f9c45b6
Cleanup data logger class and reorg some things
AarC10 Oct 10, 2025
baca359
Some docstrings. Dont give user the right to write for now :)
AarC10 Oct 10, 2025
ebc49d7
More docstrings. Simplify prepMetadata
AarC10 Oct 10, 2025
3c3b8ff
docstrings. Make looking for seeking and updating metadata return an …
AarC10 Oct 10, 2025
e3eab14
const
AarC10 Oct 10, 2025
224d16c
Reorder
AarC10 Oct 10, 2025
da776e8
shorten metadata to 32 bytes from 48
AarC10 Oct 10, 2025
48d0d98
make sure we only hash the size of the log name in case no null term
AarC10 Oct 10, 2025
ee056e5
add sample to CI
AarC10 Oct 10, 2025
bf17079
blast evil
AarC10 Oct 10, 2025
46fc5a4
missing docstring
AarC10 Oct 10, 2025
b073289
Merge branch 'main' into feature/Aaron/FlashLogger
AarC10 Oct 11, 2025
019dd74
null term log name in the metadata
AarC10 Oct 13, 2025
96db6aa
Merge branch 'feature/Aaron/FlashLogger' of https://github.com/RIT-La…
AarC10 Oct 13, 2025
d5ca0c3
should not be writing enxtLogAddress size fix that bug
AarC10 Oct 13, 2025
32d69c7
fix prj.conf for datalogger prj
AarC10 Oct 13, 2025
eae1369
fix sample include
AarC10 Oct 13, 2025
0486556
Lower datalogger queue
AarC10 Oct 25, 2025
0cd02ff
Blast heap mempool kconfig in sample
AarC10 Oct 25, 2025
9d3ae64
Macro
AarC10 Oct 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/sample-roots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ app/samples/horus:
app/samples/compression:
- paths:
- "app/samples/compression/**"
app/samples/raw_datalogger:
- paths:
- "app/samples/raw_datalogger/**"
ALL:
- paths:
- "include/f_core/**"
Expand Down
2 changes: 1 addition & 1 deletion app/backplane/power_module/include/c_power_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CPowerModule : public CProjectConfiguration {
"Broadcast Tenant", ipAddrStr, downlinkBroadcastPort, downlinkBroadcastPort, sensorDataDownlinkMessagePort
};

CDataLoggerTenant<NTypes::TimestampedSensorData> dataLoggerTenant{
CFsDataLoggerTenant<NTypes::TimestampedSensorData> dataLoggerTenant{
"Data Logger Tenant", "/lfs/sensor_data.bin", LogMode::Growing, 0, sensorDataLogMessagePort, K_SECONDS(60), 5
};
CUdpAlertTenant alertTenant{"Alert Tenant", ipAddrStr, NNetworkDefs::ALERT_PORT};
Expand Down
2 changes: 1 addition & 1 deletion app/backplane/radio_module/include/c_radio_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CRadioModule : public CProjectConfiguration {
CLoraTransmitTenant loraTransmitTenant{"LoRa Transmit Tenant", lora, &loraBroadcastMessagePort};
CLoraReceiveTenant loraReceiveTenant{"LoRa Receive Tenant", loraTransmitTenant, ipAddrStr, radioModuleSourcePort};
#endif
CDataLoggerTenant<NTypes::GnssData> dataLoggerTenant{"Data Logger Tenant", "/lfs/gps_data.bin", LogMode::Growing, 0, gnssDataLogMessagePort, K_SECONDS(15), 5};
CFsDataLoggerTenant<NTypes::GnssData> dataLoggerTenant{"Data Logger Tenant", "/lfs/gps_data.bin", LogMode::Growing, 0, gnssDataLogMessagePort, K_SECONDS(15), 5};
CStateMachineUpdater stateMachineUpdater;

// Tasks
Expand Down
1 change: 1 addition & 0 deletions app/backplane/sensor_module/.idea/editor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions app/backplane/sensor_module/.idea/sensor-module.iml

This file was deleted.

2 changes: 1 addition & 1 deletion app/backplane/sensor_module/include/c_sensor_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CSensorModule : public CProjectConfiguration {
CUdpBroadcastTenant<NTypes::SensorData> broadcastTenant{"Broadcast Tenant", ipAddrStr.c_str(), telemetryBroadcastPort, telemetryBroadcastPort, sensorDataBroadcastMessagePort};
CUdpBroadcastTenant<NTypes::LoRaBroadcastSensorData> downlinkTelemTenant{"Telemetry Downlink Tenant", ipAddrStr.c_str(), telemetryDownlinkPort, telemetryDownlinkPort, downlinkMessagePort};
CUdpBroadcastTenant<NAlerts::AlertPacket> udpAlertTenant{"UDP Alert Tenant", ipAddrStr.c_str(), alertPort, alertPort, alertMessagePort};
CDataLoggerTenant<NTypes::TimestampedSensorData> dataLoggerTenant{"Data Logger Tenant", "/lfs/sensor_module_data.bin", LogMode::Growing, 0, sensorDataLogMessagePort, K_SECONDS(3), 64};
CFsDataLoggerTenant<NTypes::TimestampedSensorData> dataLoggerTenant{"Data Logger Tenant", "/lfs/sensor_module_data.bin", LogMode::Growing, 0, sensorDataLogMessagePort, K_SECONDS(3), 64};

// Tasks
CTask networkTask{"Networking Task", 15, 3072, 0};
Expand Down
3 changes: 2 additions & 1 deletion app/backplane/sensor_module/src/c_sensor_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <f_core/messaging/c_msgq_message_port.h>
#include <f_core/os/n_rtos.h>
#include <f_core/utils/n_time_utils.h>
#include <f_core/os/c_raw_datalogger.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make the 512 on line 17 something like 12

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im making hw give you less ram next time so you learn

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(sensor_module);

Expand All @@ -13,7 +14,7 @@ static auto broadcastMsgQueue = CMsgqMessagePort<NTypes::SensorData>(broadcastQu
K_MSGQ_DEFINE(downlinkQueue, sizeof(NTypes::LoRaBroadcastSensorData), 10, 4);
static auto downlinkMsgQueue = CMsgqMessagePort<NTypes::LoRaBroadcastSensorData>(downlinkQueue);

K_MSGQ_DEFINE(dataLogQueue, sizeof(NTypes::TimestampedSensorData), 512, 4);
K_MSGQ_DEFINE(dataLogQueue, sizeof(NTypes::TimestampedSensorData), 10, 4);
static auto dataLogMsgQueue = CMsgqMessagePort<NTypes::TimestampedSensorData>(dataLogQueue);

K_MSGQ_DEFINE(alertQueue, sizeof(NAlerts::AlertPacket), 4, 4);
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion app/samples/benchmark_littlefs_datalogger/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ template <typename T>
void benchmarkDataloggerMode(const char *testName, const char *filePath, LogMode mode, size_t maxPackets = 1000, size_t syncFrequency = 10) {
LOG_INF("\n\n=== %s ===", testName);

CDataLogger<T> logger(filePath, mode, maxPackets);
CFsDataLogger<T> logger(filePath, mode, maxPackets);

uint64_t totalWriteCycles = 0;
uint64_t totalSyncCycles = 0;
Expand Down
5 changes: 5 additions & 0 deletions app/samples/datalogger/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/ {
chosen {
flashcontroller = &flash0;
storage = &flash0;
logfs = &lfs1;
};

aliases {
storage = &flash0;
};


fstab {
compatible = "zephyr,fstab";
Expand Down
8 changes: 4 additions & 4 deletions app/samples/datalogger/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "f_core/os/c_datalogger.h"
#include "f_core/os/c_fs_datalogger.h"

#include <zephyr/kernel.h>

struct Packet {
uint8_t a;
uint8_t b;
};
CDataLogger<Packet> expand_logger{"/lfs/expand.bin"};
CDataLogger<Packet> fill_logger{"/lfs/fill.bin", LogMode::FixedSize, 10};
CDataLogger<Packet> wrap_logger{"/lfs/wrap.bin", LogMode::Circular, 10};
CFsDataLogger<Packet> expand_logger{"/lfs/expand.bin"};
CFsDataLogger<Packet> fill_logger{"/lfs/fill.bin", LogMode::FixedSize, 10};
CFsDataLogger<Packet> wrap_logger{"/lfs/wrap.bin", LogMode::Circular, 10};

int main() {
for (uint8_t i = 0; i < 100; i++) {
Expand Down
10 changes: 10 additions & 0 deletions app/samples/raw_datalogger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.20.0)

set(FSW_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(raw_datalogger LANGUAGES CXX)

target_compile_options(app PRIVATE -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-ignored-qualifiers)
FILE(GLOB app_sources src/*.cpp)
target_sources(app PRIVATE ${app_sources})
1 change: 1 addition & 0 deletions app/samples/raw_datalogger/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source "Kconfig.zephyr"
27 changes: 27 additions & 0 deletions app/samples/raw_datalogger/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/ {
chosen {
storage = &flash0;
};

aliases {
storage = &flash0;
};
};

&flashcontroller0 {
status = "okay";
compatible = "zephyr,sim-flash";
reg = <0x00000000 0x00100000>;

#address-cells = <1>;
#size-cells = <1>;
erase-value = <0xff>;

flash0: flash@0 {
status = "okay";
compatible = "soc-nv-flash";
erase-block-size = <4096>;
write-block-size = <1>;
reg = <0x00000000 0x00100000>;
};
};
24 changes: 24 additions & 0 deletions app/samples/raw_datalogger/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CONFIG_CPP=y
CONFIG_REQUIRES_FULL_LIBCPP=y
CONFIG_STD_CPP20=y

CONFIG_F_CORE=y
CONFIG_F_CORE_OS=y

# outputs
CONFIG_SERIAL=y
CONFIG_HEAP_MEM_POOL_SIZE=8192

CONFIG_DEBUG=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_MAIN_STACK_SIZE=8192
CONFIG_FLASH=y
CONFIG_SHELL=y
CONFIG_FLASH_SHELL=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_SIMULATOR=y
CONFIG_STREAM_FLASH=y

CONFIG_LOG=y
10 changes: 10 additions & 0 deletions app/samples/raw_datalogger/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sample:
description:
name: raw_datalogger
common:
build_only: true
platform_allow:
- native_sim
- nucleo_f446re
tests:
samples.template.default: {}
139 changes: 139 additions & 0 deletions app/samples/raw_datalogger/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "zephyr/logging/log.h"

#include <f_core/os/c_raw_datalogger.h>
#include <zephyr/kernel.h>

LOG_MODULE_REGISTER(main);

struct TestData {
const char name[16];
int a;
int b;
int c;
int d;
};

int main() {
const device* flash = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_controller));
if (!device_is_ready(flash)) {
LOG_ERR("Flash device not ready!");
return -1;
} else {
// Print flash size
uint64_t flashSize = 0;
int ret = flash_get_size(flash, &flashSize);
if (ret < 0) {
LOG_ERR("Failed to get flash size: %d", ret);
return -1;
}

LOG_INF("Flash Size: %llu bytes", flashSize);
}
off_t start_addr = 0x00000000;
size_t erase_size = 0x00100000; // 1 MiB

int err = flash_erase(flash, start_addr, erase_size);
if (err < 0) {
LOG_ERR("Failed to erase flash: %d", err);
return -1;
}

// Fixed
off_t nextAddr = 0x00000000;
const int packetsInFixedFile = 5;
const size_t fixedFileSize = sizeof(TestData) * packetsInFixedFile + sizeof(DataloggerMetadata);
CRawDataLogger<TestData, 3> fixedLogger(flash, nextAddr, fixedFileSize, "test_fixed", DataloggerMode::Fixed);
for (int i = 0; i < packetsInFixedFile; ++i) {
char iter = '0' + i;
TestData data = { "fixed", iter, iter, iter, iter };
int ret = fixedLogger.Write(data);
if (ret < 0) {
LOG_ERR("Error writing data for fixed: %d", ret);
} else {
LOG_INF("Successfully wrote %d entries to fixed logger", i + 1);
}
}
LOG_INF("Finished writing data for fixed logger.");
if (fixedLogger.Write(TestData{ "fixed_overflow", 'B', 'A', 'D', '!' }) != -ENOSPC) {
LOG_ERR("Error: Should not have been able to write more data to fixed logger");
}

nextAddr += fixedFileSize;

// LinkedFixed
const size_t linkedFixedFileSize = (sizeof(TestData) * 5) + sizeof(DataloggerMetadata);
CRawDataLogger<TestData, 3> linkedFixedLogger(flash, nextAddr, linkedFixedFileSize, "test_link_fixed", DataloggerMode::LinkedFixed);
for (int i = 0; i < 5; ++i) {
char iter = '0' + i;
TestData data = { "linked_fixed", iter, iter, iter, iter };
int ret = linkedFixedLogger.Write(data);
if (ret < 0) {
LOG_ERR("Error writing data for linked fixed: %d", ret);
} else {
LOG_INF("Successfully wrote %d entries to linked fix logger", i + 1);
}
}

LOG_INF("Finished writing data for linked fixed logger.");


nextAddr += linkedFixedFileSize;
// Add a file in between to test finding next linked space using a fixed logger
const size_t intermediateFileSize = sizeof(TestData) + sizeof(DataloggerMetadata);
CRawDataLogger<TestData, 1> intermediateLogger(flash, nextAddr, intermediateFileSize, "intermediate", DataloggerMode::Fixed);
TestData intermediateData = { "intermediate", 'I', 'N', 'T', 'R' };
intermediateLogger.Write(intermediateData);
if (intermediateLogger.GetLastError() != 0) {
LOG_ERR("Error writing intermediate data: %d", intermediateLogger.GetLastError());
}

LOG_INF("Finished writing data for intermediate fixed logger");

// LinkedFixed should skip the intermediate file and create 2 new files consecutively
for (int i = 0; i < 10; ++i) {
char iter = '0' + i;

TestData data = { "linked_fixed2", iter, iter, iter, iter };
int ret = linkedFixedLogger.Write(data);
if (ret < 0) {
LOG_ERR("Error writing data for linked fixed 2: %d", ret);
} else {
LOG_INF("Successfully wrote %d entries to linked fixed logger", i + 1);
}
}

LOG_INF("Finished writing more data for linked fixed logger.");

nextAddr += intermediateFileSize + (2 * linkedFixedFileSize); // Move past the intermediate and 2 linked fixed files

// Test LinkedTruncate
const size_t linkedTruncateFileSize = (sizeof(TestData) * 5) + sizeof(DataloggerMetadata);
CRawDataLogger<TestData, 3> linkedTruncateLogger(flash, nextAddr, linkedTruncateFileSize, "test_link_trunc", DataloggerMode::LinkedTruncate);

nextAddr += ((linkedTruncateFileSize * 2) + sizeof(DataloggerMetadata)) - (sizeof(TestData) * 2); // Leave space for 2 files minus 2 entries to test truncation
CRawDataLogger<TestData, 1> anotherIntermediateLogger(flash, nextAddr, intermediateFileSize, "intermediate2", DataloggerMode::Fixed);
anotherIntermediateLogger.Write(intermediateData);

if (anotherIntermediateLogger.GetLastError() != 0) {
LOG_ERR("Error writing another intermediate data: %d", anotherIntermediateLogger.GetLastError());
}
LOG_INF("Finished writing data for another intermediate fixed logger");


for (int i = 0; i < 15; ++i) {
char iter = '0' + (i % 10);

TestData data = { "linked_truncate", iter, iter, iter, iter };
int ret = linkedTruncateLogger.Write(data);

if (ret < 0) {
LOG_ERR("Error writing data for linked truncate: %d", ret);
} else {
LOG_INF("Successfully wrote %d entries to linked truncate logger", i + 1);
}
}

LOG_INF("Finished writing data for linked truncate logger");

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

enum class LogMode { Growing, Circular, FixedSize };

/// @brief Internal, type-unsafe datalogger. Don't use this directly. Use CDataLogger instead
/// @brief Internal, type-unsafe datalogger. Don't use this directly. Use CFsDataLogger instead
namespace detail {
class datalogger {
public:
Expand All @@ -32,7 +32,7 @@ class datalogger {
* This class is implemented as a type safe wrapper to detail::datalogger.
*/
template <typename T>
class CDataLogger {
class CFsDataLogger {
public:
using PacketType = T;
static_assert(std::is_trivially_copyable<PacketType>::value,
Expand All @@ -46,14 +46,14 @@ class CDataLogger {
* The logger will use the "Growing" mode and will expand as you write more data until your filesystem runs out of space.
* @param filename the name of the file to write to
*/
CDataLogger(const char *filename) : internal(filename, LogMode::Growing, 0) {}
CFsDataLogger(const char *filename) : internal(filename, LogMode::Growing, 0) {}
/**
* Construct a Datalogger for the specified filename, grow mode, and size
* @param filename the name of the file to write to
* @param mode the logging mode to use
* @param the number of packets to log (only used if mode is Circular or FixedSize)
*/
CDataLogger(const char *filename, LogMode mode, std::size_t num_packets) : internal(filename, mode, num_packets) {}
CFsDataLogger(const char *filename, LogMode mode, std::size_t num_packets) : internal(filename, mode, num_packets) {}

/**
* Write a packet to the file
Expand Down
Loading
Loading