Skip to content

Commit

Permalink
More questions than answers..
Browse files Browse the repository at this point in the history
  • Loading branch information
stojadin2701 committed Jul 13, 2023
1 parent eeb3768 commit fe45226
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
25 changes: 17 additions & 8 deletions flight_computer/src/usb/msc/emfat_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static const emfat_entry_t entriesPredefined[] = {
#define README_FILE_IDX 1

// We are limited to 50 flight logs & 50 stats files due to RAM memory limits
// TODO: It seems the number has to be 1 more than the actual limit, this should be investigated
#define EMFAT_MAX_LOG_ENTRY 100
#define EMFAT_MAX_ENTRY (PREDEFINED_ENTRY_COUNT + EMFAT_MAX_LOG_ENTRY)

Expand Down Expand Up @@ -144,21 +145,24 @@ static void emfat_add_log(emfat_entry_t *entry, int number, uint32_t size, const
/**
* @brief Add file from path, returns 0 on success.
*/
static int add_logs_from_path(emfat_entry_t *entry, const char *path, log_type_e log_type, int log_count) {
static int add_logs_from_path(emfat_entry_t **entry, const char *path, log_type_e log_type, int log_count,
int start_idx) {
struct lfs_info info;
lfs_dir_t dir;
int err = lfs_dir_open(&lfs, &dir, path);
if (err < 0) {
return err;
}

// +2 because '.' and '..' are read first
for (int i = 0; i < log_count + 2; i++) {
lfs_dir_read(&lfs, &dir, &info);

if (i > 1) {
// Set the default timestamp
entry->cma_time[0] = cmaTime;
emfat_add_log(entry++, i - 1, info.size, info.name, log_type);
(*entry)->cma_time[0] = cmaTime;
// TODO: why - 1??
emfat_add_log((*entry)++, i + start_idx - 1, info.size, info.name, log_type);
}
}

Expand All @@ -178,22 +182,27 @@ static int emfat_find_logs(emfat_entry_t *entry) {
return 0;
}

if (add_logs_from_path(entry, flight_path, FLIGHT_LOG, flight_log_count) != 0) {
if (add_logs_from_path(&entry, flight_path, FLIGHT_LOG, flight_log_count, 0) != 0) {
return 0;
}

if (add_logs_from_path(entry, stats_path, STATS_LOG, stats_log_count) != 0) {
// flight_log_count is the start index here
if (add_logs_from_path(&entry, stats_path, STATS_LOG, stats_log_count, flight_log_count) != 0) {
return 0;
}

return flight_log_count + stats_log_count;
}

void emfat_init_files() {
/**
* @return true on success, false on failure
*/
bool emfat_init_files() {
//TODO: this should be a tri-state of 'not initialized', 'succeeded', 'failed'
static bool initialized = false;

if (initialized) {
return;
return true;
}

memset(entries, 0, sizeof(entries));
Expand All @@ -217,5 +226,5 @@ void emfat_init_files() {
entries[README_FILE_IDX].max_size = (total_sz_kb - curr_sz_kb) * 1024;

initialized = true;
emfat_init(&emfat, "CATS", entries);
return emfat_init(&emfat, "CATS", entries);
}
4 changes: 3 additions & 1 deletion flight_computer/src/usb/msc/emfat_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@

#pragma once

void emfat_init_files();
#include <stdbool.h>

bool emfat_init_files();
4 changes: 1 addition & 3 deletions flight_computer/src/usb/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16
// return true allowing host to read/write this LUN e.g SD card inserted
bool tud_msc_test_unit_ready_cb(uint8_t lun) {
(void)lun;
emfat_init_files();

return true;
return emfat_init_files();
}

// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
Expand Down

0 comments on commit fe45226

Please sign in to comment.