-
Notifications
You must be signed in to change notification settings - Fork 1
Raw Datalogger #340
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
Open
AarC10
wants to merge
75
commits into
main
Choose a base branch
from
feature/Aaron/FlashLogger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Raw Datalogger #340
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 b0b2cca
Define functions
AarC10 3183697
Implementation for CRawDatalogger
AarC10 6674a02
Simplify
AarC10 92c4a5b
Introduce several modes for hitting EOF
AarC10 223199b
ReadMetaData and Find functions
AarC10 c18a762
grab filesize
AarC10 d1b01a5
Fix compile errors
AarC10 cdcf5db
MRead metadata and fix formatting and use off_t
AarC10 5c9b02c
Add sample for testing
AarC10 e4e445b
Blind write a sample for testing the logger
AarC10 69c89f6
Fix compile errors
AarC10 4e5355f
Fix temporary nullptr arg and add native sim overlay
AarC10 0a60059
Native sim overlay for sample
AarC10 e66047a
Grab flash controller
AarC10 cca7431
Add log statements
AarC10 bebd018
Fix starting offset
AarC10 229269f
Dont need a massive partition
AarC10 f8fb6bf
blast lfs
AarC10 ca0b897
Erase flash
AarC10 3e3417d
Log when data was successfully written
AarC10 a44b0ba
update datalogger metadata print statements for debugging why we aren…
AarC10 9568805
Update spaceleft, by having offset immediately account for the metadata
AarC10 7b4538a
Force flushes
AarC10 f0f32b3
Reset buffers function
AarC10 41ce2af
reset buffers
AarC10 9b6708a
Blast rotating file support
AarC10 9ac27ca
Passing fixed logger and linked fixed logger
AarC10 ee7a3cf
Need to figure out writing after intermediate
AarC10 867e58b
print num
AarC10 019c785
try seeking for next available space
AarC10 440cd94
seek functions and have prepMetadata do the flash write
AarC10 88a4402
Link to next file
AarC10 5d51e22
Check flash size first
AarC10 2bc7601
Get rid of warning by doing some fun casting
AarC10 7c12aa0
FindLinkedSpace needs LinkedFixed to check if the entire region it ne…
AarC10 d5bea74
add a hash for filename as part of the metadata
AarC10 89ab290
Make suer we select hash func to prevent linker error
AarC10 51fcba5
Rm jumping to next file while searching
AarC10 9ba4d2f
Fix jumping
AarC10 4f5c4c5
Bugfixes for writing new metadata
AarC10 1675960
delete flush function
AarC10 817a28a
remove metadata prep raw calls after we just called the function for it
AarC10 a1f6eaf
Closer to a working linked fixed implementation. Wrote a new file set
AarC10 b7acb16
Working linked fixed writing. Removed overwriting correct current fil…
AarC10 c65f512
Update test to increment addr to where we expect for truncate test
AarC10 89cbfb4
Jump better for fixed case. Store original file size for when we link…
AarC10 b196f46
Try simplifying finding linked space and try lowering file size for t…
AarC10 d8cc3b4
Fix looping in read metadata
AarC10 3200e4b
Rename file to log to avoid confusion
AarC10 7a0d59f
make findLinkedSpace private
AarC10 2b447b7
Properly search for metadata and prevent early exit
AarC10 65f3199
Remove debug prints
AarC10 4371474
clamp to prevent truncate from trying to write past flash size
AarC10 3a95500
Destructor
AarC10 f9c45b6
Cleanup data logger class and reorg some things
AarC10 baca359
Some docstrings. Dont give user the right to write for now :)
AarC10 ebc49d7
More docstrings. Simplify prepMetadata
AarC10 3c3b8ff
docstrings. Make looking for seeking and updating metadata return an …
AarC10 e3eab14
const
AarC10 224d16c
Reorder
AarC10 da776e8
shorten metadata to 32 bytes from 48
AarC10 48d0d98
make sure we only hash the size of the log name in case no null term
AarC10 ee056e5
add sample to CI
AarC10 bf17079
blast evil
AarC10 46fc5a4
missing docstring
AarC10 b073289
Merge branch 'main' into feature/Aaron/FlashLogger
AarC10 019dd74
null term log name in the metadata
AarC10 96db6aa
Merge branch 'feature/Aaron/FlashLogger' of https://github.com/RIT-La…
AarC10 d5ca0c3
should not be writing enxtLogAddress size fix that bug
AarC10 32d69c7
fix prj.conf for datalogger prj
AarC10 eae1369
fix sample include
AarC10 0486556
Lower datalogger queue
AarC10 0cd02ff
Blast heap mempool kconfig in sample
AarC10 9d3ae64
Macro
AarC10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| source "Kconfig.zephyr" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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>; | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
There was a problem hiding this comment.
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