From e8a17efea1a5eb240b761a23ec797950d56f2825 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Thu, 20 Oct 2022 14:33:59 +0100 Subject: [PATCH 01/12] Fixed debug prompt not closing --- firmware/src/cmd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/src/cmd.c b/firmware/src/cmd.c index 0f4139c..3339a43 100644 --- a/firmware/src/cmd.c +++ b/firmware/src/cmd.c @@ -79,7 +79,11 @@ static void debugPrint(void) { latest.mag[0], latest.mag[1], latest.mag[2], goStr[2], latest.pres, temp, goStr[3]); + if (getchar_timeout_us(0) != PICO_ERROR_TIMEOUT) { + break; + } sleep_ms(UPDATE_PERIOD); + } clearTTY(); From 89142f44a0be372c62d8492b5a9a0903db497bbe Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Thu, 20 Oct 2022 15:45:52 +0100 Subject: [PATCH 02/12] Moved stateDetect to sensors.c for easier testing --- firmware/CMakeLists.txt | 1 + firmware/src/main.c | 45 ++--------------------------------------- firmware/src/sensors.c | 39 +++++++++++++++++++++++++++++++++++ firmware/src/states.h | 11 ++++++++++ 4 files changed, 53 insertions(+), 43 deletions(-) create mode 100644 firmware/src/states.h diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index a6022fe..4b6aedd 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -11,6 +11,7 @@ set(sources src/main.c src/cmd.c src/cmd.h src/ansi.h + src/states.h src/sensors.c src/sensors.h src/dataBuf.c diff --git a/firmware/src/main.c b/firmware/src/main.c index 28caf8d..3c61b99 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -1,4 +1,5 @@ #include + #include "pico/stdlib.h" #include "hardware/i2c.h" #include "hardware/irq.h" @@ -7,52 +8,10 @@ #include "sensors.h" #include "cmd.h" #include "dataBuf.h" - -// Pressure threshold for a launch -#define PRES_L -100 // About 10m -// Acceleration threshold for a launch -#define ACCL_L (gToAccel(10)) -// Pressure threshold to detect apogee -#define PRES_A 100 // About 10m -// Pressure threshold for landing -#define PRES_G 100 - -enum states { - CONNECTED, // If system is connected over usb - GROUNDED, // If system is not connected, but not in flight - ASCENDING, - DESENDING -}; +#include "states.h" volatile uint8_t state = GROUNDED; -/* Takes a data packet and decides if state changes are needed */ -void stateDetect(data_t cur) { - int16_t accel_mag; - // Figure out if state changes are required. - switch (state) { - case GROUNDED: - if (deltaPres(100) < PRES_L || - magnitude(cur.accel) > ACCL_L) { - state = ASCENDING; - cur.status |= LAUNCH; - } - break; - case ASCENDING: - if (deltaPres(100) > PRES_A) { - state = DESENDING; - cur.status |= APOGEE; - } - break; - case DESENDING: - if (abs(deltaPres(1000)) < PRES_G) { - state = GROUNDED; - cur.status |= LANDING; - } - } - -} - /* The code that runs on core 1 */ void core1Entry(void) { data_t d; diff --git a/firmware/src/sensors.c b/firmware/src/sensors.c index 409532d..f20b110 100644 --- a/firmware/src/sensors.c +++ b/firmware/src/sensors.c @@ -10,6 +10,16 @@ #include #include #include "dataBuf.h" +#include "states.h" + +// Pressure threshold for a launch +#define PRES_L -100 // About 10m +// Acceleration threshold for a launch +#define ACCL_L (gToAccel(10)) +// Pressure threshold to detect apogee +#define PRES_A 100 // About 10m +// Pressure threshold for landing +#define PRES_G 100 // Constants defining constants is... mildly cursed, but its the nicest way // I could think of to set these universally @@ -17,6 +27,8 @@ static const enum QMIGyroScale GYRO_SCALE = QMI_GYRO_256DPS; static const enum QMIAccelScale ACC_SCALE = QMI_ACC_16G; static const enum QMCScale COMP_SCALE = QMC_SCALE_2G; +extern volatile uint8_t state; + // Sensor structs static hp203_t hp203; static qmc_t qmc; @@ -192,3 +204,30 @@ int32_t deltaPres(size_t t) { uint32_t pastPres = past.pres; return currPres - pastPres; } + +/* Takes a data packet and decides if state changes are needed */ +void stateDetect(data_t cur) { + int16_t accel_mag; + // Figure out if state changes are required. + switch (state) { + case GROUNDED: + if (deltaPres(100) < PRES_L || + magnitude(cur.accel) > ACCL_L) { + state = ASCENDING; + cur.status |= LAUNCH; + } + break; + case ASCENDING: + if (deltaPres(100) > PRES_A) { + state = DESENDING; + cur.status |= APOGEE; + } + break; + case DESENDING: + if (abs(deltaPres(1000)) < PRES_G) { + state = GROUNDED; + cur.status |= LANDING; + } + } + +} diff --git a/firmware/src/states.h b/firmware/src/states.h new file mode 100644 index 0000000..f5dc150 --- /dev/null +++ b/firmware/src/states.h @@ -0,0 +1,11 @@ +#ifndef STATES_H +#define STATES_H + +enum states { + CONNECTED, // If system is connected over usb + GROUNDED, // If system is not connected, but not in flight + ASCENDING, + DESENDING +}; + +#endif From be39e3ca7032ae1f5d250e64db624cfd14661241 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Fri, 21 Oct 2022 14:23:30 +0100 Subject: [PATCH 03/12] Started work on flash storage --- firmware/CMakeLists.txt | 4 ++ firmware/lib/spiffs | 2 +- firmware/src/cmd.c | 21 +++++- firmware/src/logger.c | 144 ++++++++++++++++++++++++++++++++++++++++ firmware/src/logger.h | 22 ++++++ firmware/src/main.c | 42 ++++++++++++ firmware/src/sensors.c | 36 ---------- firmware/src/sensors.h | 4 ++ 8 files changed, 237 insertions(+), 38 deletions(-) create mode 100644 firmware/src/logger.c create mode 100644 firmware/src/logger.h diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index 4b6aedd..58f36a1 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -14,6 +14,8 @@ set(sources src/main.c src/states.h src/sensors.c src/sensors.h + src/logger.c + src/logger.h src/dataBuf.c src/dataBuf.h) @@ -21,6 +23,7 @@ add_executable(Bob src/main.c src/cmd.c src/sensors.c + src/logger.c src/dataBuf.c ) @@ -32,3 +35,4 @@ pico_enable_stdio_usb(Bob 1) pico_add_extra_outputs(Bob) +pico_set_binary_type(Bob copy_to_ram) diff --git a/firmware/lib/spiffs b/firmware/lib/spiffs index 397170c..9e28c29 160000 --- a/firmware/lib/spiffs +++ b/firmware/lib/spiffs @@ -1 +1 @@ -Subproject commit 397170cf61cd1ff545d5296e9bd5fc606e7699e5 +Subproject commit 9e28c29c5a5a1c5b57b3ee9ef13772d2921729d8 diff --git a/firmware/src/cmd.c b/firmware/src/cmd.c index 3339a43..d4409aa 100644 --- a/firmware/src/cmd.c +++ b/firmware/src/cmd.c @@ -6,6 +6,7 @@ #include "dataBuf.h" #include "ansi.h" +#include "logger.h" // How fast should updatey bits be updated? #define UPDATE_PERIOD 200 @@ -90,6 +91,16 @@ static void debugPrint(void) { showCursor(true); } +static void manualLogger(void) { + newLog(); + printf("Press any key to exit logging\n"); + while(getchar_timeout_us(0) != PICO_ERROR_TIMEOUT) { + logData(); + } + closeLog(); +} + + /* Polls stdin and interprets what it gets. */ void pollUsb(void) { static const char helpText[] = @@ -98,7 +109,9 @@ void pollUsb(void) { "b to enter bootsel mode\n" "c to clear this tty\n" "d to show the debug prompt\n" - "h to display this help text\n"; + "h to display this help text\n" + "l to start manual logging\n" + "r to read files\n"; switch(getchar_timeout_us(0)) { case PICO_ERROR_TIMEOUT: // If there is no char, just break. @@ -116,6 +129,12 @@ void pollUsb(void) { case 'h': printf(helpText, __TIME__, __DATE__); break; + case 'l': + manualLogger(); + break; + case 'r': + dumpLogs(); + break; default: printf("?\n"); break; diff --git a/firmware/src/logger.c b/firmware/src/logger.c new file mode 100644 index 0000000..697009d --- /dev/null +++ b/firmware/src/logger.c @@ -0,0 +1,144 @@ +#include "spiffs/xip.h" +#include + +#include "dataBuf.h" + +extern spiffs fs; +spiffs_file f; + +static int8_t countLogs(void) { + int8_t logs = 0; + char *prefix = "log_"; + spiffs_DIR d; + struct spiffs_dirent e; + struct spiffs_dirent *pe = &e; + + SPIFFS_opendir(&fs, "/", &d); + while ((pe = SPIFFS_readdir(&d, pe))) { + if (0 == strncmp(prefix, (char *)pe->name, strlen(prefix))) { + logs++; + } + } + SPIFFS_closedir(&d); + return logs; +} + +/* Opens a new log file */ +void newLog(void) { + char fileName[32]; + int8_t logs = countLogs(); + snprintf(fileName, 32, "log_%d", logs); + f = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | + SPIFFS_TRUNC | + SPIFFS_RDWR, 0); +} + +void closeLog(void) { + SPIFFS_close(&fs, f); +} + +/* Moves all data from the buffer to the file. */ +void logData(void) { + data_t data; + while (dataPop(&data) > 0) { + // Spiffs has caches built in, so no need to buffer anything here. + if(SPIFFS_write(&fs, f, &data, sizeof(data_t)) < 0) { + break; // If something breaks, come back later? Maybe its fixed. + } + } +} + +/* Dumps all the logs to stdout */ +void dumpLogs(void) { + // remove all files starting with "tmp_" + char *search_prefix = "log_"; + spiffs_DIR d; + struct spiffs_dirent e; + struct spiffs_dirent *pe = &e; + int res; + + data_t cur; + + float accel[3]; + float gyro[3]; + float temp; + + spiffs_file fd = -1; + + SPIFFS_opendir(&fs, "/", &d); + while ((pe = SPIFFS_readdir(&d, pe))) { + if (0 == strncmp(search_prefix, (char *)pe->name, strlen(search_prefix))) { + // found one + fd = SPIFFS_open_by_dirent(&fs, pe, SPIFFS_RDWR, 0); + if (fd < 0) { + printf("errno %i\n", SPIFFS_errno(&fs)); + return; + } + printf("-- %s --\n", (char *)pe->name); + printf("Time, Ax, Ay, Az, Gx, Gy, Gz, Mx, My, Mz, Pa, °C\n"); + + while(SPIFFS_read(&fs, fd, &cur, sizeof(data_t)) > 0) { + + accel[0] = accelToG(cur.accel[0]); + accel[1] = accelToG(cur.accel[1]); + accel[2] = accelToG(cur.accel[2]); + + gyro[0] = gyroToDps(cur.gyro[0]); + gyro[1] = gyroToDps(cur.gyro[1]); + gyro[2] = gyroToDps(cur.gyro[2]); + + temp = (float)cur.temp/100; + + printf("%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %f\n", + cur.time, + accel[0], accel[1], accel[2], + gyro[0], gyro[1], gyro[2], + cur.mag[0], cur.mag[1], cur.mag[2], + cur.pres, cur.temp + ); + } + + res = SPIFFS_close(&fs, fd); + if (res < 0) { + printf("errno %i\n", SPIFFS_errno(&fs)); + return; + } + } + } + SPIFFS_closedir(&d); +} + +/* Deletes all the log files + * Blatantly stolen from the SPIFFS examples. */ +void clearLogs(void) { + char *search_prefix = "log_"; + spiffs_DIR d; + struct spiffs_dirent e; + struct spiffs_dirent *pe = &e; + int res; + + spiffs_file fd = -1; + + SPIFFS_opendir(&fs, "/", &d); + while ((pe = SPIFFS_readdir(&d, pe))) { + if (0 == strncmp(search_prefix, (char *)pe->name, strlen(search_prefix))) { + // found one + fd = SPIFFS_open_by_dirent(&fs, pe, SPIFFS_RDWR, 0); + if (fd < 0) { + printf("errno %i\n", SPIFFS_errno(&fs)); + return; + } + res = SPIFFS_fremove(&fs, fd); + if (res < 0) { + printf("errno %i\n", SPIFFS_errno(&fs)); + return; + } + res = SPIFFS_close(&fs, fd); + if (res < 0) { + printf("errno %i\n", SPIFFS_errno(&fs)); + return; + } + } + } + SPIFFS_closedir(&d); +} diff --git a/firmware/src/logger.h b/firmware/src/logger.h new file mode 100644 index 0000000..e708676 --- /dev/null +++ b/firmware/src/logger.h @@ -0,0 +1,22 @@ +#ifndef LOGGER_H +#define LOGGER_H + +#include "sensors.h" +#include "spiffs/xip.h" + +/* Opens a new log file, returns its file handle */ +void newLog(void); + +/* Moves all data from the buffer to the file. */ +void logData(void); + +/* Dumps all the logs to stdout */ +void dumpLogs(void); + +/* Deletes all the log files + * Blatantly stolen from the SPIFFS examples. */ +void clearLogs(void); + +void closeLog(void); + +#endif diff --git a/firmware/src/main.c b/firmware/src/main.c index 3c61b99..9485611 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -5,12 +5,50 @@ #include "hardware/irq.h" #include "pico/multicore.h" + +#include "spiffs/xip.h" #include "sensors.h" #include "cmd.h" #include "dataBuf.h" #include "states.h" volatile uint8_t state = GROUNDED; +spiffs fs; + +// Pressure threshold for a launch +#define PRES_L -100 // About 10m +// Acceleration threshold for a launch +#define ACCL_L (gToAccel(10)) +// Pressure threshold to detect apogee +#define PRES_A 100 // About 10m +// Pressure threshold for landing +#define PRES_G 100 + +/* Takes a data packet and decides if state changes are needed */ +void stateDetect(data_t cur) { + int16_t accel_mag; + // Figure out if state changes are required. + switch (state) { + case GROUNDED: + if (deltaPres(100) < PRES_L || + magnitude(cur.accel) > ACCL_L) { + state = ASCENDING; + cur.status |= LAUNCH; + } + break; + case ASCENDING: + if (deltaPres(100) > PRES_A) { + state = DESENDING; + cur.status |= APOGEE; + } + break; + case DESENDING: + if (abs(deltaPres(1000)) < PRES_G) { + state = GROUNDED; + cur.status |= LANDING; + } + } +} /* The code that runs on core 1 */ void core1Entry(void) { @@ -35,8 +73,12 @@ int main() { stdio_init_all(); + sleep_ms(10000); + printf("Hello world!"); multicore_launch_core1(core1Entry); + XIPQuickMount(&fs); + while (true) { switch (state) { case CONNECTED: diff --git a/firmware/src/sensors.c b/firmware/src/sensors.c index f20b110..9a11ecb 100644 --- a/firmware/src/sensors.c +++ b/firmware/src/sensors.c @@ -12,15 +12,6 @@ #include "dataBuf.h" #include "states.h" -// Pressure threshold for a launch -#define PRES_L -100 // About 10m -// Acceleration threshold for a launch -#define ACCL_L (gToAccel(10)) -// Pressure threshold to detect apogee -#define PRES_A 100 // About 10m -// Pressure threshold for landing -#define PRES_G 100 - // Constants defining constants is... mildly cursed, but its the nicest way // I could think of to set these universally static const enum QMIGyroScale GYRO_SCALE = QMI_GYRO_256DPS; @@ -204,30 +195,3 @@ int32_t deltaPres(size_t t) { uint32_t pastPres = past.pres; return currPres - pastPres; } - -/* Takes a data packet and decides if state changes are needed */ -void stateDetect(data_t cur) { - int16_t accel_mag; - // Figure out if state changes are required. - switch (state) { - case GROUNDED: - if (deltaPres(100) < PRES_L || - magnitude(cur.accel) > ACCL_L) { - state = ASCENDING; - cur.status |= LAUNCH; - } - break; - case ASCENDING: - if (deltaPres(100) > PRES_A) { - state = DESENDING; - cur.status |= APOGEE; - } - break; - case DESENDING: - if (abs(deltaPres(1000)) < PRES_G) { - state = GROUNDED; - cur.status |= LANDING; - } - } - -} diff --git a/firmware/src/sensors.h b/firmware/src/sensors.h index 06d519c..9cf8d34 100644 --- a/firmware/src/sensors.h +++ b/firmware/src/sensors.h @@ -6,6 +6,7 @@ * dependent on the configuration of the sensors. */ #include +#include typedef struct { uint32_t pres; // Pressure in pascals @@ -64,4 +65,7 @@ float gyroToDps(int16_t gyro); /* Applies calibration coefficients to a magnetometer reading */ void compCalib(int16_t * reading[3], int16_t calib[3]); +/* Finds the difference in pressure between the most recent + * data packet and the one that was t samples ago . */ +int32_t deltaPres(size_t t); #endif From f5a6726e1ba28eacb0384c65d7fb3a1bfa78f81b Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Mon, 31 Oct 2022 13:39:01 +0000 Subject: [PATCH 04/12] Tried to get SPIFFs working --- firmware/src/bob.h | 12 ++++++++++-- firmware/src/main.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/firmware/src/bob.h b/firmware/src/bob.h index 11131bf..1f6a17e 100644 --- a/firmware/src/bob.h +++ b/firmware/src/bob.h @@ -1,5 +1,5 @@ -/* Header file containing bob-specific constants - * This overrides a lot of things that the SDK sets by default +/* Header file containing bob-specific constants + * This overrides a lot of things that the SDK sets by default * You dont have to include this in any code you write; the SDK * should include it by default. */ #ifndef BOB_H @@ -32,6 +32,14 @@ #define PICO_FLASH_SIZE_BYTES (64 * 1024 * 1024) #endif +#ifndef XIP_FS_SIZE +#define XIP_FS_SIZE (7 * 8 * 1024 * 1024) +#endif + +#ifndef XIP_INTERRUPTS +#define XIP_INTERRUPTS 1 +#endif + // Buzzer #define BOB_BUZZER 7 diff --git a/firmware/src/main.c b/firmware/src/main.c index 9485611..272ffeb 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -77,7 +77,7 @@ int main() { printf("Hello world!"); multicore_launch_core1(core1Entry); - XIPQuickMount(&fs); + XIPQuickMount(&fs, 4*1024*1024, true); while (true) { switch (state) { From 74aa4636e3f2e0b163025a0b147f6776a0be8eff Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Mon, 31 Oct 2022 13:52:20 +0000 Subject: [PATCH 05/12] Removed PICO_SPIFFS; it doesn't work ahyugsdjugadhjsgahjsdgashjasdggasdhj --- .gitmodules | 3 --- firmware/CMakeLists.txt | 2 +- firmware/lib/CMakeLists.txt | 1 - firmware/lib/spiffs | 1 - 4 files changed, 1 insertion(+), 6 deletions(-) delete mode 160000 firmware/lib/spiffs diff --git a/.gitmodules b/.gitmodules index 76f1e5a..0321d47 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "kicad/YAR-Kicad-Libs"] path = kicad/YAR-Kicad-Libs url = https://github.com/yorkaerospace/YAR-Kicad-Libs.git -[submodule "firmware/lib/spiffs"] - path = firmware/lib/spiffs - url = https://github.com/ProtonNumber/spiffs-pico.git diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index 58f36a1..00b12ea 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -29,7 +29,7 @@ add_executable(Bob add_subdirectory(lib) -target_link_libraries(Bob QMI8658C HP203B QMC5883L pico_stdlib pico_multicore hardware_i2c PICO_SPIFFS) +target_link_libraries(Bob QMI8658C HP203B QMC5883L pico_stdlib pico_multicore hardware_i2c) pico_enable_stdio_usb(Bob 1) diff --git a/firmware/lib/CMakeLists.txt b/firmware/lib/CMakeLists.txt index d1fe444..1073d84 100644 --- a/firmware/lib/CMakeLists.txt +++ b/firmware/lib/CMakeLists.txt @@ -1,4 +1,3 @@ add_subdirectory(hp203b) add_subdirectory(qmc5883l) add_subdirectory(qmi8658c) -add_subdirectory(spiffs) diff --git a/firmware/lib/spiffs b/firmware/lib/spiffs deleted file mode 160000 index 9e28c29..0000000 --- a/firmware/lib/spiffs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9e28c29c5a5a1c5b57b3ee9ef13772d2921729d8 From b2f18500e6b0048c08f957f3bbf6e31af5d6f51b Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Fri, 4 Nov 2022 19:13:09 +0000 Subject: [PATCH 06/12] Flailed around trying to make the fs work --- firmware/genBin.sh | 2 +- firmware/src/ansi.h | 6 + firmware/src/bob.h | 8 -- firmware/src/cmd.c | 32 ++++- firmware/src/dataBuf.c | 10 +- firmware/src/dataBuf.h | 2 +- firmware/src/logger.c | 240 ++++++++++++++++++----------------- firmware/src/logger.h | 32 +++-- firmware/src/main.c | 7 +- firmware/test/dataBuf/main.c | 7 + firmware/test/dataBuf/test.h | 12 ++ firmware/test/minuinit.h | 7 + 12 files changed, 208 insertions(+), 157 deletions(-) create mode 100644 firmware/test/dataBuf/main.c create mode 100644 firmware/test/dataBuf/test.h create mode 100644 firmware/test/minuinit.h diff --git a/firmware/genBin.sh b/firmware/genBin.sh index 5f6838d..a919ae9 100755 --- a/firmware/genBin.sh +++ b/firmware/genBin.sh @@ -12,7 +12,7 @@ cd $SCRIPT_DIR git submodule init git submodule update -CMAKE_ARGS="-DPICO_BOARD=bob -DPICO_BOARD_HEADER_DIRS=$SCRIPT_DIR/src $@" +CMAKE_ARGS="-DPICO_BOARD=bob -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DPICO_BOARD_HEADER_DIRS=$SCRIPT_DIR/src $@" mkdir -p bin diff --git a/firmware/src/ansi.h b/firmware/src/ansi.h index 5b99450..41258c0 100644 --- a/firmware/src/ansi.h +++ b/firmware/src/ansi.h @@ -6,6 +6,8 @@ #define MOV_EC(n) "\x1b[0K\x1b[999C\x1b[" #n "D" // Moves the cursor to row, column #define MOV(r, c) "\x1b[" #r ":" #c "H" +// Moves the cursor to column c +#define CHA(c) "\x1b[" #c "G" // Clears from the cursor to the end of the line. Inserts a newline. #define CLRLN "\x1b[0k\n" // Sets text to be rendered neither bold nor faint @@ -17,4 +19,8 @@ #define GREEN "\x1b[32;1m" #define BLUE "\x1b[34;1m" +// Save and restore cursor positions +#define SCP "\x1b[s" +#define RCP "\x1b[u" + #endif diff --git a/firmware/src/bob.h b/firmware/src/bob.h index 1f6a17e..6076bf2 100644 --- a/firmware/src/bob.h +++ b/firmware/src/bob.h @@ -32,14 +32,6 @@ #define PICO_FLASH_SIZE_BYTES (64 * 1024 * 1024) #endif -#ifndef XIP_FS_SIZE -#define XIP_FS_SIZE (7 * 8 * 1024 * 1024) -#endif - -#ifndef XIP_INTERRUPTS -#define XIP_INTERRUPTS 1 -#endif - // Buzzer #define BOB_BUZZER 7 diff --git a/firmware/src/cmd.c b/firmware/src/cmd.c index d4409aa..8c7722b 100644 --- a/firmware/src/cmd.c +++ b/firmware/src/cmd.c @@ -92,12 +92,30 @@ static void debugPrint(void) { } static void manualLogger(void) { - newLog(); - printf("Press any key to exit logging\n"); - while(getchar_timeout_us(0) != PICO_ERROR_TIMEOUT) { - logData(); + int n = 0; + printf("Press any key to stop logging. \n"); + while(getchar_timeout_us(0) == PICO_ERROR_TIMEOUT) { + n = n + writeAll(); + //printf( NORM "Structs written: %d\n", n); + } + printf("\nExiting Logging!\n"); +} + +static void clearPrompt(void) { + printf(NORM + "Are you sure you wish to clear the flash? " + "["GREEN "Y" WHITE "/" RED "N" WHITE "]\n" + NORM); + switch(getchar_timeout_us(30000000)){ + case PICO_ERROR_TIMEOUT: + printf("Timed out due to lack of response, please try again\n"); + break; + case 'y': + printf("Clearing flash. (This may take a while) \n"); + clearData(); + printf("Done!\n"); + break; } - closeLog(); } @@ -107,7 +125,7 @@ void pollUsb(void) { "Bob Rev 3 running build: %s %s\n" "Press:\n" "b to enter bootsel mode\n" - "c to clear this tty\n" + "c to clear the contents of the flash\n" "d to show the debug prompt\n" "h to display this help text\n" "l to start manual logging\n" @@ -121,7 +139,7 @@ void pollUsb(void) { reset_usb_boot(0,0); break; case 'c': - clearTTY(); + clearPrompt(); break; case 'd': debugPrint(); diff --git a/firmware/src/dataBuf.c b/firmware/src/dataBuf.c index 1c017eb..fefd437 100644 --- a/firmware/src/dataBuf.c +++ b/firmware/src/dataBuf.c @@ -11,7 +11,6 @@ #include "dataBuf.h" - // Simple circular buffer. static volatile data_t dataBuf[BUF_SIZE]; static volatile uint16_t tail = 0; @@ -56,8 +55,8 @@ int8_t dataPush(data_t d){ /* Returns the amount of data in the buffer */ uint16_t dataSize(void) { return head >= tail ? - head - tail : - BUF_SIZE - (tail - head); + head - tail - 1: + BUF_SIZE - (tail - head) - 1; } /* Pops a piece of data from the end of the buffer @@ -66,8 +65,11 @@ uint16_t dataSize(void) { * 0 if successful * -1 if no data is in the buffer */ int8_t dataPop(data_t * ptr) { + printf("Entering mutex\n"); mutex_enter_blocking(&mtx); - if(head == tail + 1) { + printf("%d, %d \n", head, tail); + if(head == incIndex(tail)) { + mutex_exit(&mtx); return -1; } else { *ptr = dataBuf[tail]; diff --git a/firmware/src/dataBuf.h b/firmware/src/dataBuf.h index 8043d4c..de295d9 100644 --- a/firmware/src/dataBuf.h +++ b/firmware/src/dataBuf.h @@ -11,7 +11,7 @@ #include "sensors.h" // A 10 second buffer should be ~30 kB -#define BUF_SIZE 10 * 100 +#define BUF_SIZE (10 * 100) #define BUF_TIMEOUT 1 /* Pushes a piece of data into the buffer. diff --git a/firmware/src/logger.c b/firmware/src/logger.c index 697009d..4c94fe9 100644 --- a/firmware/src/logger.c +++ b/firmware/src/logger.c @@ -1,144 +1,146 @@ -#include "spiffs/xip.h" #include +#include +#include +#include +#include +#include +#include + +#include "sensors.h" #include "dataBuf.h" -extern spiffs fs; -spiffs_file f; +// Should be about 7, but may change if more stuff is added to data_t +// One byte is reserved for metadata. +#define STRUCTS_PER_PAGE 255/sizeof(data_t) -static int8_t countLogs(void) { - int8_t logs = 0; - char *prefix = "log_"; - spiffs_DIR d; - struct spiffs_dirent e; - struct spiffs_dirent *pe = &e; +// How much space should be reserved for program code? +#define PROG_RESERVED (1024 * 1024) - SPIFFS_opendir(&fs, "/", &d); - while ((pe = SPIFFS_readdir(&d, pe))) { - if (0 == strncmp(prefix, (char *)pe->name, strlen(prefix))) { - logs++; - } - } - SPIFFS_closedir(&d); - return logs; -} +// Unions are weird, they're like a struct, but everything is in the same place. +// This *does* give us a very nice way to pad a struct out to a certian size, +// as the union will reserve enough space for its biggest member. +typedef union { + struct contents { + uint8_t metadata; + data_t data[STRUCTS_PER_PAGE] + }; + struct contents contents; + uint8_t padding[256]; +} page; + +// Just to be safe, perhaps someone did something weird to data_t. +static_assert(sizeof(page) == 256, "Page struct isnt the size of a page!!!"); + +// A pointer to the start of the data, as an XIP address +static const page * dataStart = (void *) XIP_BASE + PROG_RESERVED; + +// A blank page struct used as a buffer. +static page buf; -/* Opens a new log file */ -void newLog(void) { - char fileName[32]; - int8_t logs = countLogs(); - snprintf(fileName, 32, "log_%d", logs); - f = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | - SPIFFS_TRUNC | - SPIFFS_RDWR, 0); +static uint32_t writeIndex = 0; + + +/* Clears data from the flash. + * Has no error checking because apparently the SDK thinks we dont need that. */ +void clearData(void) { + flash_range_erase(PROG_RESERVED, 7*1024*1024); + writeIndex = 0; } -void closeLog(void) { - SPIFFS_close(&fs, f); + +/* Flushes the page buffer into the flash proper. + * Returns: + * The number of data structs written if successful + * -1 if an error occured. + * + * Will also probably hardfault if an error occurs >:( */ +uint8_t flushData(void) { + page * cur = dataStart + writeIndex; + uint32_t ints; + + uint64_t t1, t2; + + // Skip past all the written blocks + while(cur->contents.metadata != 0xFF) { + writeIndex++; + cur++; + } + printf("Writing to %X\n", cur); + ints = save_and_disable_interrupts(); + multicore_lockout_start_blocking(); + //flash_range_program(PROG_RESERVED + 256 * writeIndex, &buf, 256); + multicore_lockout_end_blocking(); + restore_interrupts(ints); + buf.contents.metadata = 0; + return cur->contents.metadata; } -/* Moves all data from the buffer to the file. */ -void logData(void) { - data_t data; - while (dataPop(&data) > 0) { - // Spiffs has caches built in, so no need to buffer anything here. - if(SPIFFS_write(&fs, f, &data, sizeof(data_t)) < 0) { - break; // If something breaks, come back later? Maybe its fixed. +/* Pushes data to the write buffer, then flushes it if it's full + * Returns: + * 1 if data was written to flash + * 0 if data was buffered + * -1 if an error occured during a write */ +uint8_t writeData(data_t data) { + buf.contents.data[buf.contents.metadata] = data; + buf.contents.metadata++; + if (buf.contents.metadata >= STRUCTS_PER_PAGE) { + if(flushData() != -1) { + return 1; + } else { + buf.contents.metadata = 0; + return -1; } } + return 0; } -/* Dumps all the logs to stdout */ -void dumpLogs(void) { - // remove all files starting with "tmp_" - char *search_prefix = "log_"; - spiffs_DIR d; - struct spiffs_dirent e; - struct spiffs_dirent *pe = &e; - int res; - +/* Writes all the data in databuf to the flash + * Returns the number of structs written. */ +uint8_t writeAll(void) { data_t cur; + uint8_t i = 0; + while(dataSize() != 0) { + dataPop(&cur); + writeData(cur); + i++; + } + return i; +} +/* Writes the logs to STDOUT as a nice CSV */ +void dumpLogs(void) { + uint32_t j = 0; + + data_t latest; float accel[3]; float gyro[3]; float temp; + page * cur = dataStart; - spiffs_file fd = -1; - - SPIFFS_opendir(&fs, "/", &d); - while ((pe = SPIFFS_readdir(&d, pe))) { - if (0 == strncmp(search_prefix, (char *)pe->name, strlen(search_prefix))) { - // found one - fd = SPIFFS_open_by_dirent(&fs, pe, SPIFFS_RDWR, 0); - if (fd < 0) { - printf("errno %i\n", SPIFFS_errno(&fs)); - return; - } - printf("-- %s --\n", (char *)pe->name); - printf("Time, Ax, Ay, Az, Gx, Gy, Gz, Mx, My, Mz, Pa, °C\n"); - - while(SPIFFS_read(&fs, fd, &cur, sizeof(data_t)) > 0) { - - accel[0] = accelToG(cur.accel[0]); - accel[1] = accelToG(cur.accel[1]); - accel[2] = accelToG(cur.accel[2]); - - gyro[0] = gyroToDps(cur.gyro[0]); - gyro[1] = gyroToDps(cur.gyro[1]); - gyro[2] = gyroToDps(cur.gyro[2]); - - temp = (float)cur.temp/100; - - printf("%d, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %f\n", - cur.time, - accel[0], accel[1], accel[2], - gyro[0], gyro[1], gyro[2], - cur.mag[0], cur.mag[1], cur.mag[2], - cur.pres, cur.temp - ); - } - - res = SPIFFS_close(&fs, fd); - if (res < 0) { - printf("errno %i\n", SPIFFS_errno(&fs)); - return; - } - } - } - SPIFFS_closedir(&d); -} + printf("Timestamp, Flags, AX, AY, AZ, GX, GY, GZ, CX, CY, CZ, P, T\n"); + + while(cur->contents.metadata != 0xFF) { + for(j = 0; j < cur->contents.metadata; j++) { + latest = cur->contents.data[j]; + + accel[0] = accelToG(latest.accel[0]); + accel[1] = accelToG(latest.accel[1]); + accel[2] = accelToG(latest.accel[2]); + + gyro[0] = gyroToDps(latest.gyro[0]); + gyro[1] = gyroToDps(latest.gyro[1]); + gyro[2] = gyroToDps(latest.gyro[2]); + + temp = (float)latest.temp / 100; -/* Deletes all the log files - * Blatantly stolen from the SPIFFS examples. */ -void clearLogs(void) { - char *search_prefix = "log_"; - spiffs_DIR d; - struct spiffs_dirent e; - struct spiffs_dirent *pe = &e; - int res; - - spiffs_file fd = -1; - - SPIFFS_opendir(&fs, "/", &d); - while ((pe = SPIFFS_readdir(&d, pe))) { - if (0 == strncmp(search_prefix, (char *)pe->name, strlen(search_prefix))) { - // found one - fd = SPIFFS_open_by_dirent(&fs, pe, SPIFFS_RDWR, 0); - if (fd < 0) { - printf("errno %i\n", SPIFFS_errno(&fs)); - return; - } - res = SPIFFS_fremove(&fs, fd); - if (res < 0) { - printf("errno %i\n", SPIFFS_errno(&fs)); - return; - } - res = SPIFFS_close(&fs, fd); - if (res < 0) { - printf("errno %i\n", SPIFFS_errno(&fs)); - return; - } + printf("%d, %X, %f, %f, %f, %f, %f, %f, %d, %d, %d, %d, %f\n", + latest.time, latest.status, + accel[0], accel[1], accel[2], + gyro[0], gyro[1], gyro[2], + latest.mag[0], latest.mag[1], latest.mag[2], + latest.pres, temp); } + cur++; } - SPIFFS_closedir(&d); } diff --git a/firmware/src/logger.h b/firmware/src/logger.h index e708676..44376b6 100644 --- a/firmware/src/logger.h +++ b/firmware/src/logger.h @@ -2,21 +2,31 @@ #define LOGGER_H #include "sensors.h" -#include "spiffs/xip.h" -/* Opens a new log file, returns its file handle */ -void newLog(void); +/* Clears data from the flash. + * Has no error checking because apparently the SDK thinks we dont need that. */ +void clearData(void); -/* Moves all data from the buffer to the file. */ -void logData(void); +/* Flushes the page buffer into the flash proper. + * Returns: + * The number of data structs written if successful + * -1 if an error occured. + * + * Will also probably hardfault if an error occurs >:( */ +uint8_t flushData(void); -/* Dumps all the logs to stdout */ -void dumpLogs(void); +/* Pushes data to the write buffer, then flushes it if it's full + * Returns: + * 1 if data was written to flash + * 0 if data was buffered + * -1 if an error occured during a write */ +uint8_t writeData(data_t data); -/* Deletes all the log files - * Blatantly stolen from the SPIFFS examples. */ -void clearLogs(void); +/* Writes all the data in databuf to the flash + * Returns the number of structs written. */ +uint8_t writeAll(void); -void closeLog(void); +/* Writes the logs to STDOUT as a nice CSV */ +void dumpLogs(void); #endif diff --git a/firmware/src/main.c b/firmware/src/main.c index 272ffeb..f7b2718 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -6,14 +6,12 @@ #include "pico/multicore.h" -#include "spiffs/xip.h" #include "sensors.h" #include "cmd.h" #include "dataBuf.h" #include "states.h" volatile uint8_t state = GROUNDED; -spiffs fs; // Pressure threshold for a launch #define PRES_L -100 // About 10m @@ -58,6 +56,7 @@ void core1Entry(void) { configureSensors(); status = testSensors(); + multicore_lockout_victim_init(); while (true) { nextPoll = make_timeout_time_ms(10); @@ -73,12 +72,8 @@ int main() { stdio_init_all(); - sleep_ms(10000); - printf("Hello world!"); multicore_launch_core1(core1Entry); - XIPQuickMount(&fs, 4*1024*1024, true); - while (true) { switch (state) { case CONNECTED: diff --git a/firmware/test/dataBuf/main.c b/firmware/test/dataBuf/main.c new file mode 100644 index 0000000..38f3d5f --- /dev/null +++ b/firmware/test/dataBuf/main.c @@ -0,0 +1,7 @@ +#include "stdio.h" +#include "stdint.h" +#include "../../src/dataBuf.h" + +int main(void) { + +} diff --git a/firmware/test/dataBuf/test.h b/firmware/test/dataBuf/test.h new file mode 100644 index 0000000..b8073f7 --- /dev/null +++ b/firmware/test/dataBuf/test.h @@ -0,0 +1,12 @@ +/* Dummy functions for testing the data buffer */ +#ifndef TEST_H +#define TEST_H + +#define BUF_SIZE 10 + +typedef int data_t; +typedef int mtx; + +data_t dataBuf[BUF_SIZE]; + +#endif diff --git a/firmware/test/minuinit.h b/firmware/test/minuinit.h new file mode 100644 index 0000000..8e44d38 --- /dev/null +++ b/firmware/test/minuinit.h @@ -0,0 +1,7 @@ +/* file: minunit.h + * source: https://jera.com/techinfo/jtns/jtn002 + * license: see above. */ +#define mu_assert(message, test) do { if (!(test)) return message; } while (0) +#define mu_run_test(test) do { char *message = test(); tests_run++; \ + if (message) return message; } while (0) +extern int tests_run; From d2a162db1c285674d3513c1d75cff8cfd32e9acb Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Fri, 4 Nov 2022 19:13:41 +0000 Subject: [PATCH 07/12] Yeah there's nothing good here just ignore it --- firmware/test/dataBuf/main.c | 7 ------- firmware/test/dataBuf/test.h | 12 ------------ firmware/test/minuinit.h | 7 ------- 3 files changed, 26 deletions(-) delete mode 100644 firmware/test/dataBuf/main.c delete mode 100644 firmware/test/dataBuf/test.h delete mode 100644 firmware/test/minuinit.h diff --git a/firmware/test/dataBuf/main.c b/firmware/test/dataBuf/main.c deleted file mode 100644 index 38f3d5f..0000000 --- a/firmware/test/dataBuf/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "stdio.h" -#include "stdint.h" -#include "../../src/dataBuf.h" - -int main(void) { - -} diff --git a/firmware/test/dataBuf/test.h b/firmware/test/dataBuf/test.h deleted file mode 100644 index b8073f7..0000000 --- a/firmware/test/dataBuf/test.h +++ /dev/null @@ -1,12 +0,0 @@ -/* Dummy functions for testing the data buffer */ -#ifndef TEST_H -#define TEST_H - -#define BUF_SIZE 10 - -typedef int data_t; -typedef int mtx; - -data_t dataBuf[BUF_SIZE]; - -#endif diff --git a/firmware/test/minuinit.h b/firmware/test/minuinit.h deleted file mode 100644 index 8e44d38..0000000 --- a/firmware/test/minuinit.h +++ /dev/null @@ -1,7 +0,0 @@ -/* file: minunit.h - * source: https://jera.com/techinfo/jtns/jtn002 - * license: see above. */ -#define mu_assert(message, test) do { if (!(test)) return message; } while (0) -#define mu_run_test(test) do { char *message = test(); tests_run++; \ - if (message) return message; } while (0) -extern int tests_run; From 06e8d578e80fed51c20752ae11644aa9c32e1688 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Sat, 5 Nov 2022 00:11:06 +0000 Subject: [PATCH 08/12] Created a very shitty shell script to yeet the serial stuff into a file --- drivers/.gitignore | 1 + drivers/readData.sh | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 drivers/.gitignore create mode 100755 drivers/readData.sh diff --git a/drivers/.gitignore b/drivers/.gitignore new file mode 100644 index 0000000..338bb66 --- /dev/null +++ b/drivers/.gitignore @@ -0,0 +1 @@ +log.csv diff --git a/drivers/readData.sh b/drivers/readData.sh new file mode 100755 index 0000000..26b0da7 --- /dev/null +++ b/drivers/readData.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo "r" -> /dev/ttyACM0; +stdbuf -o0 cat /dev/ttyACM0 >> log.csv + From 4b982ca9ced282700cc232df966bc1a45c9e7885 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Sat, 5 Nov 2022 00:12:16 +0000 Subject: [PATCH 09/12] Renamed mtx to bufMtx to avoid confusion --- firmware/src/dataBuf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/firmware/src/dataBuf.c b/firmware/src/dataBuf.c index fefd437..009c723 100644 --- a/firmware/src/dataBuf.c +++ b/firmware/src/dataBuf.c @@ -16,7 +16,7 @@ static volatile data_t dataBuf[BUF_SIZE]; static volatile uint16_t tail = 0; static volatile uint16_t head = 0; -auto_init_mutex(mtx); +auto_init_mutex(bufMtx); /* Increments an index with looping */ static inline uint16_t incIndex(uint16_t i) { @@ -35,7 +35,7 @@ static inline uint16_t incIndex(uint16_t i) { * 1 if data has been overwritten */ int8_t dataPush(data_t d){ int8_t res; - if(mutex_enter_timeout_ms(&mtx, BUF_TIMEOUT)) { + if(mutex_enter_timeout_ms(&bufMtx, BUF_TIMEOUT)) { head = incIndex(head); dataBuf[head] = d; // Increment tail if we've overwritten data @@ -45,7 +45,7 @@ int8_t dataPush(data_t d){ } else { res = 0; } - mutex_exit(&mtx); + mutex_exit(&bufMtx); return res; } else { return -1; @@ -66,15 +66,15 @@ uint16_t dataSize(void) { * -1 if no data is in the buffer */ int8_t dataPop(data_t * ptr) { printf("Entering mutex\n"); - mutex_enter_blocking(&mtx); + mutex_enter_blocking(&bufMtx); printf("%d, %d \n", head, tail); if(head == incIndex(tail)) { - mutex_exit(&mtx); + mutex_exit(&bufMtx); return -1; } else { *ptr = dataBuf[tail]; tail = incIndex(tail); - mutex_exit(&mtx); + mutex_exit(&bufMtx); return 0; } } @@ -82,14 +82,14 @@ int8_t dataPop(data_t * ptr) { /* Gets the data at the head of the buffer * Blocks indefinitely. */ void dataHead(data_t * ptr) { - mutex_enter_blocking(&mtx); + mutex_enter_blocking(&bufMtx); *ptr = dataBuf[head]; - mutex_exit(&mtx); + mutex_exit(&bufMtx); } /* Gets the data that was offset samples ago */ void dataRel(data_t * ptr, size_t offset) { - mutex_enter_blocking(&mtx); + mutex_enter_blocking(&bufMtx); *ptr = dataBuf[(head - offset) % BUF_SIZE]; - mutex_exit(&mtx); + mutex_exit(&bufMtx); } From 78f7d90f60819e5403a639e06ab914290bc3c8c6 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Sat, 5 Nov 2022 00:12:34 +0000 Subject: [PATCH 10/12] GOT SOMETHING WORKING POGPOGPOG --- firmware/src/logger.c | 12 +++++++----- firmware/src/main.c | 10 ++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/firmware/src/logger.c b/firmware/src/logger.c index 4c94fe9..ea2ae08 100644 --- a/firmware/src/logger.c +++ b/firmware/src/logger.c @@ -40,6 +40,8 @@ static page buf; static uint32_t writeIndex = 0; +extern mutex_t flashMtx; + /* Clears data from the flash. * Has no error checking because apparently the SDK thinks we dont need that. */ @@ -59,19 +61,19 @@ uint8_t flushData(void) { page * cur = dataStart + writeIndex; uint32_t ints; - uint64_t t1, t2; - + printf("Reading from flash\n"); // Skip past all the written blocks while(cur->contents.metadata != 0xFF) { writeIndex++; cur++; } printf("Writing to %X\n", cur); + mutex_enter_blocking(&flashMtx); + printf("Mutex claimed\n"); ints = save_and_disable_interrupts(); - multicore_lockout_start_blocking(); - //flash_range_program(PROG_RESERVED + 256 * writeIndex, &buf, 256); - multicore_lockout_end_blocking(); + flash_range_program(PROG_RESERVED + 256 * writeIndex, &buf, 256); restore_interrupts(ints); + mutex_exit(&flashMtx); buf.contents.metadata = 0; return cur->contents.metadata; } diff --git a/firmware/src/main.c b/firmware/src/main.c index f7b2718..4994d46 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -4,6 +4,7 @@ #include "hardware/i2c.h" #include "hardware/irq.h" #include "pico/multicore.h" +#include "pico/bootrom.h" #include "sensors.h" @@ -12,6 +13,7 @@ #include "states.h" volatile uint8_t state = GROUNDED; +mutex_t flashMtx; // Pressure threshold for a launch #define PRES_L -100 // About 10m @@ -56,15 +58,17 @@ void core1Entry(void) { configureSensors(); status = testSensors(); - multicore_lockout_victim_init(); while (true) { + mutex_enter_blocking(&flashMtx); nextPoll = make_timeout_time_ms(10); d = pollSensors(status); dataPush(d); stateDetect(d); - sleep_until(nextPoll); status = d.status; + mutex_exit(&flashMtx); + sleep_until(nextPoll); + } } @@ -72,6 +76,8 @@ int main() { stdio_init_all(); + mutex_init(&flashMtx); + multicore_launch_core1(core1Entry); while (true) { From f49c1025f48dedca80f318a6066c7e3792536ae0 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Sat, 5 Nov 2022 10:06:09 +0000 Subject: [PATCH 11/12] ReadData now takes arguments and trims off whitespace --- drivers/readData.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/readData.sh b/drivers/readData.sh index 26b0da7..e102bb3 100755 --- a/drivers/readData.sh +++ b/drivers/readData.sh @@ -1,5 +1,10 @@ #!/bin/bash -echo "r" -> /dev/ttyACM0; -stdbuf -o0 cat /dev/ttyACM0 >> log.csv +# Takes data from the bob and yheets it into a file. +# Usage: readData +echo "r" -> $1; +stdbuf -o0 cat $1 >> $2 + +sed -i '/?/d' $2 +sed -i '/^$/d' $2 From f9cb72ca966706274a0d2725d3fe6d34668396a1 Mon Sep 17 00:00:00 2001 From: ProtonNumber Date: Sat, 5 Nov 2022 10:06:57 +0000 Subject: [PATCH 12/12] Temporarily disabled state machine. Will now log data whenever its not plugged in. --- firmware/src/main.c | 46 ++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/firmware/src/main.c b/firmware/src/main.c index 4994d46..e971cc3 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -64,7 +64,7 @@ void core1Entry(void) { nextPoll = make_timeout_time_ms(10); d = pollSensors(status); dataPush(d); - stateDetect(d); + //stateDetect(d); status = d.status; mutex_exit(&flashMtx); sleep_until(nextPoll); @@ -80,24 +80,32 @@ int main() { multicore_launch_core1(core1Entry); - while (true) { - switch (state) { - case CONNECTED: - if (!stdio_usb_connected()) { - state = GROUNDED; - } else { - pollUsb(); - } - break; - case GROUNDED: - if (stdio_usb_connected()) { - state = CONNECTED; - } - break; - case ASCENDING: - break; - case DESENDING: - break; + while(true) { + if(stdio_usb_connected()) { + pollUsb(); + } else { + writeAll(); } } + + /* while (true) { */ + /* switch (state) { */ + /* case CONNECTED: */ + /* if (!stdio_usb_connected()) { */ + /* state = GROUNDED; */ + /* } else { */ + /* pollUsb(); */ + /* } */ + /* break; */ + /* case GROUNDED: */ + /* if (stdio_usb_connected()) { */ + /* state = CONNECTED; */ + /* } */ + /* break; */ + /* case ASCENDING: */ + /* break; */ + /* case DESENDING: */ + /* break; */ + /* } */ + /* } */ }