From 434e99793e4a3d13dba0d5da947024496ba166cf Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 8 Nov 2024 13:16:54 -0800 Subject: [PATCH 01/61] chore: Adds configuration --- .vscode/c_cpp_properties.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 3da6cb19..7b94c5bc 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -34,6 +34,26 @@ "${workspaceFolder}\\src" ] } + }, + { + "name": "Google Test", + "includePath": [ + "${workspaceFolder}/src" + ], + "cStandard": "c11", + "cppStandard": "c++11", + "configurationProvider": "ms-vscode.cmake-tools", + "mergeConfigurations": true + }, + { + "name": "glibc", + "includePath": [ + "${workspaceFolder}/src" + ], + "cStandard": "c11", + "cppStandard": "c++11", + "configurationProvider": "ms-vscode.cmake-tools", + "mergeConfigurations": true } ], "version": 4 From 1e87b30e3cf851a65994438e33df9bda88dae3ee Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 8 Nov 2024 14:03:03 -0800 Subject: [PATCH 02/61] feat: Adds pc hal --- .vscode/c_cpp_properties.json | 12 +----------- CMakeLists.txt | 5 +++-- pc_hal/CMakeLists.txt | 11 +++++++++++ pc_hal/Particle.h | 10 ++++++++++ pc_hal/main.cpp | 30 ++++++++++++++++++++++++++++++ src/product.hpp | 10 ++++++++-- 6 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 pc_hal/CMakeLists.txt create mode 100644 pc_hal/Particle.h create mode 100644 pc_hal/main.cpp diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 7b94c5bc..b93eaa6b 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -36,17 +36,7 @@ } }, { - "name": "Google Test", - "includePath": [ - "${workspaceFolder}/src" - ], - "cStandard": "c11", - "cppStandard": "c++11", - "configurationProvider": "ms-vscode.cmake-tools", - "mergeConfigurations": true - }, - { - "name": "glibc", + "name": "cmake", "includePath": [ "${workspaceFolder}/src" ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 23141aea..bf773e0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14) -project(SmartfinTests) -set(CMAKE_CXX_STANDARD 14) +project(Smartfin) +set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_subdirectory(external/googletest) @@ -13,3 +13,4 @@ set(GTEST_SOURCE_FILES add_executable(googletests ${GTEST_SOURCE_FILES}) target_link_libraries(googletests gtest gtest_main pthread) +add_subdirectory(pc_hal) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt new file mode 100644 index 00000000..e155f3a5 --- /dev/null +++ b/pc_hal/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.14) +project(smartfin_pc) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include_directories(../src/ .) + +set(SMARTFIN_SOURCE_FILES + main.cpp +) +add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h new file mode 100644 index 00000000..94999ab3 --- /dev/null +++ b/pc_hal/Particle.h @@ -0,0 +1,10 @@ +/** + * @file Particle.h + * @author Nathan Hui (nthui@ucsd.edu) + * @brief GLIBC Particle Shim + * @version 0.1 + * @date 2024-11-08 + * + * @copyright Copyright (c) 2024 + * + */ \ No newline at end of file diff --git a/pc_hal/main.cpp b/pc_hal/main.cpp new file mode 100644 index 00000000..916359dc --- /dev/null +++ b/pc_hal/main.cpp @@ -0,0 +1,30 @@ +/** + * @file main.cpp + * @author Nathan Hui (nthui@ucsd.edu) + * @brief Smartfin CMake Main File + * @version 0.1 + * @date 2024-11-08 + * + * @copyright Copyright (c) 2024 + * + */ + +#include "product.hpp" + +void setup(); +void loop(); + +#include "smartfin-fw3.ino" + +#if SF_PLATFORM == SF_PLATFORM_GLIBC +int main(int argc, char const *argv[]) +{ + setup(); + while (true) + { + loop(); + } + return 0; +} + +#endif \ No newline at end of file diff --git a/src/product.hpp b/src/product.hpp index f35b9f17..75e9eeab 100644 --- a/src/product.hpp +++ b/src/product.hpp @@ -268,7 +268,13 @@ * @brief GCC Platform Selector * */ -#define SF_PLATFORM_GCC 1 +#define SF_PLATFORM_GLIBC 1 + +/** + * @brief GoogleTest Platform Selector + * + */ +#define SF_PLATFORM_GOOGLETEST 2 /** * @brief Smartfin Platform Designator @@ -277,6 +283,6 @@ #ifdef PARTICLE #define SF_PLATFORM SF_PLATFORM_PARTICLE #else -#define SF_PLATFORM SF_PLATFORM_GCC +#define SF_PLATFORM SF_PLATFORM_GLIBC #endif #endif // __PRODUCT_HPP__ \ No newline at end of file From 94e0e77c0326fbac6dc039a14dc640f2f9bf9023 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:37:47 -0800 Subject: [PATCH 03/61] fix: Adds GPS includes --- pc_hal/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index e155f3a5..94b6929b 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -3,7 +3,14 @@ project(smartfin_pc) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -include_directories(../src/ .) +include_directories( + . + ../src/ + ../lib/tracker-edge/src + ../lib/gps-ublox/src + ../lib/gps-nmea-parser/src + ../lib/gps-quectel/src +) set(SMARTFIN_SOURCE_FILES main.cpp From 1cdac32884bbc1c75f98d47311c9f4ff13d409a8 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:37:57 -0800 Subject: [PATCH 04/61] fix: Adds dummy EEPROM --- pc_hal/Particle.h | 24 +++++++++++++++++++++++- pc_hal/Particle_dummy.cpp | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pc_hal/Particle_dummy.cpp diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 94999ab3..6d13e07a 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -7,4 +7,26 @@ * * @copyright Copyright (c) 2024 * - */ \ No newline at end of file + */ +#ifndef __PC_HAL_PARTICLE_H__ +#define __PC_HAL_PARTICLE_H__ +class EEPROMClass +{ + EEPROMClass() + { + } + + template T &get(int idx, T &t) + { + return T(); + } + + template const T &put(int idx, const T &t) + { + return t; + } +}; + +#define EEPROM __fetch_global_EEPROM() +EEPROMClass &__fetch_global_EEPROM(); +#endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp new file mode 100644 index 00000000..b5555112 --- /dev/null +++ b/pc_hal/Particle_dummy.cpp @@ -0,0 +1,18 @@ +/** + * @file Particle_dummy.cpp + * @author Nathan Hui (nthui@ucsd.edu) + * @brief Dummy Particle Implementation + * @version 0.1 + * @date 2024-11-13 + * + * @copyright Copyright (c) 2024 + * + */ + +#include "Particle.h" + +EEPROMClass __global_eeprom; +EEPROMClass &__fetch_global_EEPROM() +{ + return __global_eeprom; +} \ No newline at end of file From eacf51077b6bc4c73ee4fcbf44534a3f3f0cb465 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:53:49 -0800 Subject: [PATCH 05/61] fix: Adds Timer dummy class --- pc_hal/Particle.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 6d13e07a..83b44495 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -29,4 +29,8 @@ class EEPROMClass #define EEPROM __fetch_global_EEPROM() EEPROMClass &__fetch_global_EEPROM(); + +class Timer +{ +}; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From b35a6911b8d7150a222aa83dcbec966be3aec9c2 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:54:16 -0800 Subject: [PATCH 06/61] fix: Adds USARTSerial dummy class --- pc_hal/Particle.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 83b44495..2d878398 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -33,4 +33,8 @@ EEPROMClass &__fetch_global_EEPROM(); class Timer { }; + +class USARTSerial +{ +}; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From c204edf1a2248ea9ca04d93a88d531bb2c0961ae Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:54:33 -0800 Subject: [PATCH 07/61] fix: Adds functional include --- pc_hal/Particle.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 2d878398..f6786f56 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -10,6 +10,9 @@ */ #ifndef __PC_HAL_PARTICLE_H__ #define __PC_HAL_PARTICLE_H__ + +#include + class EEPROMClass { EEPROMClass() From 1de15cc05ecb32330a881c5d5f77b37bc442f091 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:54:51 -0800 Subject: [PATCH 08/61] fix: Adds SPIClass dummy --- pc_hal/Particle.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index f6786f56..84e9759c 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -40,4 +40,8 @@ class Timer class USARTSerial { }; + +class SPIClass +{ +}; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From 340a9317601f3339a7275884b677bcf229c91fe0 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:55:38 -0800 Subject: [PATCH 09/61] fix: Adds String dummy --- pc_hal/Particle.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 84e9759c..95b52504 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -12,7 +12,7 @@ #define __PC_HAL_PARTICLE_H__ #include - +#include class EEPROMClass { EEPROMClass() @@ -44,4 +44,8 @@ class USARTSerial class SPIClass { }; + +class String : public std::string +{ +}; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From a372b9c74ee23e1a2bcbe5559564e76892abc943 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 10:57:00 -0800 Subject: [PATCH 10/61] fix: renames getline to SF_OSAL_getline --- src/cli/cli.cpp | 8 ++++---- src/cli/conio.cpp | 2 +- src/cli/conio.hpp | 2 +- src/cli/menu.cpp | 2 +- src/debug/recorder_debug.cpp | 6 +++--- src/debug/session_debug.cpp | 14 +++++++------- src/fileCLI/fileCLI.cpp | 12 ++++++------ 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index cf3267ed..a1e9a7cb 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -121,10 +121,10 @@ void CLI_hexdump(void) const void* pBuffer; size_t buffer_length; SF_OSAL_printf("Starting address: 0x"); - getline(input_buffer, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(input_buffer, SF_CLI_MAX_CMD_LEN); pBuffer = (const void*)strtol(input_buffer, &pEndTok, 16); SF_OSAL_printf("Length: "); - getline(input_buffer, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(input_buffer, SF_CLI_MAX_CMD_LEN); buffer_length = (size_t) strtol(input_buffer, &pEndTok, 10); hexDump(pBuffer, buffer_length); } @@ -140,7 +140,7 @@ static void CLI_setState(void) SF_OSAL_printf("%3d: %s" __NL__, i, STATES_NAME_TAB[i]); } SF_OSAL_printf("Enter state to change to: "); - getline(input_buffer, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(input_buffer, SF_CLI_MAX_CMD_LEN); nextState = (STATES_e) strtol(input_buffer, &pEndTok, 10); if (nextState == 0) { @@ -169,7 +169,7 @@ static void CLI_sleepSetSleepBehavior(void) char* pEndTok; SleepTask::BOOT_BEHAVIOR_e boot_behavior; SF_OSAL_printf("Boot Behavior Code: "); - getline(input_buffer, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(input_buffer, SF_CLI_MAX_CMD_LEN); boot_behavior = (SleepTask::BOOT_BEHAVIOR_e) strtol(input_buffer, &pEndTok, 10); SleepTask::setBootBehavior(boot_behavior); } diff --git a/src/cli/conio.cpp b/src/cli/conio.cpp index 2c94d2b9..7f74698a 100644 --- a/src/cli/conio.cpp +++ b/src/cli/conio.cpp @@ -45,7 +45,7 @@ extern "C" return ch; } - int getline(char* buffer, int buflen) + int SF_OSAL_getline(char *buffer, int buflen) { int i = 0; char userInput; diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index aae5f026..33792d2c 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -42,7 +42,7 @@ extern "C" * @param buffer buffer to write too * @param buflen length of buffer */ - int getline(char* buffer, int buflen); + int SF_OSAL_getline(char *buffer, int buflen); #ifdef __cplusplus } diff --git a/src/cli/menu.cpp b/src/cli/menu.cpp index 78ab0695..bdefda87 100644 --- a/src/cli/menu.cpp +++ b/src/cli/menu.cpp @@ -44,7 +44,7 @@ void MNU_executeMenu(const Menu_t* pMenu) { SF_OSAL_printf(">"); memset(userInput, 0, SF_CLI_MAX_CMD_LEN); - getline(userInput, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(userInput, SF_CLI_MAX_CMD_LEN); if (strlen(userInput) == 0) { diff --git a/src/debug/recorder_debug.cpp b/src/debug/recorder_debug.cpp index 5d4259e2..8fdf7ba8 100644 --- a/src/debug/recorder_debug.cpp +++ b/src/debug/recorder_debug.cpp @@ -150,7 +150,7 @@ void REC_testPutBytes(void) Recorder* pRecorder = pSystemDesc->pRecorder; SF_OSAL_printf("Hex Input: "); - getline((char*) user_input, REC_MEMORY_BUFFER_SIZE); + SF_OSAL_getline((char *)user_input, REC_MEMORY_BUFFER_SIZE); memset(hex_buffer, 0, 3); input_length = strlen((char*) user_input); @@ -180,7 +180,7 @@ void REC_testCreateBigSession(void) Recorder* pRecorder = pSystemDesc->pRecorder; SF_OSAL_printf("Size of session to create: "); - getline((char*) user_input, REC_MEMORY_BUFFER_SIZE); + SF_OSAL_getline((char *)user_input, REC_MEMORY_BUFFER_SIZE); input_length = atoi(user_input); for (hex_idx = 0; hex_idx < input_length; hex_idx++) @@ -206,7 +206,7 @@ void REC_testSetTime(void) int retval; SF_OSAL_printf("Enter start time: "); - getline(user_input, REC_MEMORY_BUFFER_SIZE); + SF_OSAL_getline(user_input, REC_MEMORY_BUFFER_SIZE); timestamp = atoi(user_input); SF_OSAL_printf("Setting time to %d (0x%04x)" __NL__, timestamp, timestamp); retval = pRecorder->setSessionTime(timestamp); diff --git a/src/debug/session_debug.cpp b/src/debug/session_debug.cpp index 702c6b8d..356e5c7d 100644 --- a/src/debug/session_debug.cpp +++ b/src/debug/session_debug.cpp @@ -55,7 +55,7 @@ void DEPD_testOpenRW(void) int retval; SF_OSAL_printf("Enter path: "); - getline(userInput, REC_SESSION_NAME_MAX_LEN); + SF_OSAL_getline(userInput, REC_SESSION_NAME_MAX_LEN); retval = instance.open(userInput, Deployment::RDWR); SF_OSAL_printf("Returned %d" __NL__, retval); @@ -68,7 +68,7 @@ void DEPD_testOpenRO(void) int retval; SF_OSAL_printf("Enter path: "); - getline(userInput, REC_SESSION_NAME_MAX_LEN); + SF_OSAL_getline(userInput, REC_SESSION_NAME_MAX_LEN); retval = instance.open(userInput, Deployment::READ); SF_OSAL_printf("Returned %d" __NL__, retval); @@ -81,7 +81,7 @@ void DEPD_testOpenWO(void) int retval; SF_OSAL_printf("Enter path: "); - getline(userInput, REC_SESSION_NAME_MAX_LEN); + SF_OSAL_getline(userInput, REC_SESSION_NAME_MAX_LEN); retval = instance.open(userInput, Deployment::WRITE); SF_OSAL_printf("Returned %d" __NL__, retval); @@ -94,7 +94,7 @@ void DEPD_testWrite(void) int retval; SF_OSAL_printf("Enter data: "); - getline(userInput, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(userInput, SF_CLI_MAX_CMD_LEN); retval = instance.write(userInput, strlen(userInput)); SF_OSAL_printf("Returned %d" __NL__, retval); @@ -116,7 +116,7 @@ void DEPD_testRead(void) int retval; SF_OSAL_printf("Enter number of bytes to read: "); - getline(userInput, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(userInput, SF_CLI_MAX_CMD_LEN); n_bytes = atoi(userInput); if (n_bytes < 1) @@ -141,7 +141,7 @@ void DEPD_testSeek(void) int retval; SF_OSAL_printf("Enter location to seek to: "); - getline(userInput, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(userInput, SF_CLI_MAX_CMD_LEN); n_bytes = atoi(userInput); retval = instance.seek(n_bytes); @@ -173,7 +173,7 @@ void DEPD_testTruncate(void) int retval; SF_OSAL_printf("Enter size to truncate to: "); - getline(userInput, SF_CLI_MAX_CMD_LEN); + SF_OSAL_getline(userInput, SF_CLI_MAX_CMD_LEN); n_bytes = atoi(userInput); retval = instance.truncate(n_bytes); diff --git a/src/fileCLI/fileCLI.cpp b/src/fileCLI/fileCLI.cpp index b2312036..b7d7e7d0 100644 --- a/src/fileCLI/fileCLI.cpp +++ b/src/fileCLI/fileCLI.cpp @@ -67,7 +67,7 @@ void FileCLI::execute(void) { SF_OSAL_printf(":>"); memset(input_buffer, 0, FILE_CLI_INPUT_BUFFER_LEN); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); cmd = findCommand(input_buffer); if (!cmd) { @@ -194,7 +194,7 @@ void FileCLI::change_dir(void) rewinddir(cwd); SF_OSAL_printf(__NL__); SF_OSAL_printf("Enter the number of the directory to change to: "); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); cmd_val = atoi(input_buffer); if (cmd_val == same_dir_idx) @@ -266,7 +266,7 @@ void FileCLI::deleteFile(void) memset(this->path_stack[this->current_dir], 0, NAME_MAX); SF_OSAL_printf("Enter the number of the file to remove: "); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); cmd_val = atoi(input_buffer); seekdir(cwd, cmd_val); @@ -361,7 +361,7 @@ void FileCLI::dumpHex(void) memset(this->path_stack[this->current_dir], 0, NAME_MAX); SF_OSAL_printf("Enter the number of the file to hexdump: "); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); cmd_val = atoi(input_buffer); seekdir(cwd, cmd_val); @@ -449,7 +449,7 @@ void FileCLI::dumpBase85(void) memset(this->path_stack[this->current_dir], 0, NAME_MAX); SF_OSAL_printf("Enter the number of the file to dump: "); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); cmd_val = atoi(input_buffer); seekdir(cwd, cmd_val); @@ -487,7 +487,7 @@ void FileCLI::mkdir(void) int result; SF_OSAL_printf("Enter new directory name: "); - getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); + SF_OSAL_getline(input_buffer, FILE_CLI_INPUT_BUFFER_LEN); result = ::mkdir(input_buffer, 0777); SF_OSAL_printf("Returned %d" __NL__, result); From 7b73d0dac9b65ddb4c746a66cf22e34ea2ab5b12 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:24:59 -0800 Subject: [PATCH 11/61] fix: Adds LogLevel dummy --- pc_hal/Particle.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 95b52504..b8b9cccc 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -48,4 +48,9 @@ class SPIClass class String : public std::string { }; + +typedef enum +{ + +} LogLevel; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From 39ae40346b97528349feb747c6665cbd1616997d Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:25:17 -0800 Subject: [PATCH 12/61] fix: Adds logger --- pc_hal/Particle.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index b8b9cccc..eab2046f 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -53,4 +53,8 @@ typedef enum { } LogLevel; + +class Logger +{ +}; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From d47eaecd1641cff93bde2de249a46fbcbe9c6d63 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:25:42 -0800 Subject: [PATCH 13/61] fix: Adds __SPISettings --- pc_hal/Particle.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index eab2046f..7eac79d3 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -57,4 +57,9 @@ typedef enum class Logger { }; + +typedef struct +{ + +} __SPISettings; #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From a5eb618f2be710cc6207cd6acb0b33be595a980b Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:29:14 -0800 Subject: [PATCH 14/61] fix: Adds dummy classes --- pc_hal/Particle.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 7eac79d3..c9dc3a1c 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -62,4 +62,52 @@ typedef struct { } __SPISettings; + +class os_queue_t +{ +}; + +class Thread +{ +}; + +enum +{ + PIN_INVALID +}; +enum +{ + HIGH +}; + +class TwoWire +{ +}; +typedef std::size_t system_tick_t; + +template class Vector +{ +}; + +class RecursiveMutex +{ +}; + +typedef struct +{ + +} LEDSystemTheme; + +class FuelGauge +{ +}; + +typedef struct +{ + +} LEDStatus; + +#define SYSTEM_MODE(a) ; +#define SYSTEM_THREAD(a) ; + #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file From 43b8e25d827f4ca5b87a7ea16a3f7c1cdafed744 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:31:24 -0800 Subject: [PATCH 15/61] fix: Adds System dummy --- pc_hal/Particle.h | 14 ++++++++++++++ pc_hal/Particle_dummy.cpp | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index c9dc3a1c..79d99544 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -110,4 +110,18 @@ typedef struct #define SYSTEM_MODE(a) ; #define SYSTEM_THREAD(a) ; +typedef enum +{ + FEATURE_RESET_INFO +} HAL_Feature; +class SystemClass +{ +public: + int enableFeature(HAL_Feature feature) + { + return 0; + } +}; +#define System __fetch_global_System() +SystemClass &__fetch_global_System(); #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index b5555112..13f1c902 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -15,4 +15,10 @@ EEPROMClass __global_eeprom; EEPROMClass &__fetch_global_EEPROM() { return __global_eeprom; +} + +SystemClass __global_system; +SystemClass &__fetch_global_System() +{ + return __global_system; } \ No newline at end of file From 4dd1d5eaa0392b10b7ae1e129b18dc033c8c7a83 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:33:15 -0800 Subject: [PATCH 16/61] fix: Adds dummy Serial --- pc_hal/Particle.h | 7 +++++++ pc_hal/Particle_dummy.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 79d99544..6064e3c6 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -39,7 +39,13 @@ class Timer class USARTSerial { +public: + void begin(int baud) + { + } }; +#define Serial __get_default_serial() +USARTSerial &__get_default_serial(); class SPIClass { @@ -124,4 +130,5 @@ class SystemClass }; #define System __fetch_global_System() SystemClass &__fetch_global_System(); + #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 13f1c902..df6570c8 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -21,4 +21,10 @@ SystemClass __global_system; SystemClass &__fetch_global_System() { return __global_system; +} + +USARTSerial __default_serial; +USARTSerial &__get_default_serial() +{ + return __default_serial; } \ No newline at end of file From 87355041fb5a91d479b20ede1fa0fa57a0478830 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:37:52 -0800 Subject: [PATCH 17/61] fix: Adds dummy classes --- pc_hal/Particle.h | 21 +++++++++++++++++++++ pc_hal/Particle_dummy.cpp | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 6064e3c6..4f67beae 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -11,6 +11,7 @@ #ifndef __PC_HAL_PARTICLE_H__ #define __PC_HAL_PARTICLE_H__ +#include #include #include class EEPROMClass @@ -120,6 +121,10 @@ typedef enum { FEATURE_RESET_INFO } HAL_Feature; +typedef enum +{ + RESET_REASON_NONE +} __RESET_REASON_t; class SystemClass { public: @@ -127,8 +132,24 @@ class SystemClass { return 0; } + __RESET_REASON_t resetReason() + { + return RESET_REASON_NONE; + } }; #define System __fetch_global_System() SystemClass &__fetch_global_System(); +typedef std::uint32_t time32_t; + +class TimeClass +{ +public: + time32_t now() + { + return 0; + } +}; +#define Time __fetch_global_time() +TimeClass &__fetch_global_time(); #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index df6570c8..b5affbed 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -27,4 +27,10 @@ USARTSerial __default_serial; USARTSerial &__get_default_serial() { return __default_serial; +} + +TimeClass __global_time; +TimeClass &__fetch_global_time() +{ + return __global_time; } \ No newline at end of file From 5eb9880d6a9d669e9ffc8e06cab25310654b054a Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:38:43 -0800 Subject: [PATCH 18/61] Update smartfin-fw3.ino --- src/smartfin-fw3.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/smartfin-fw3.ino b/src/smartfin-fw3.ino index 79e53729..8577d007 100644 --- a/src/smartfin-fw3.ino +++ b/src/smartfin-fw3.ino @@ -56,7 +56,7 @@ static STATES_e currentState; static StateMachine_t* findState(STATES_e state); static void initalizeTaskObjects(void); void mainThread(void* args); -void printState(STATES_e state); +static void printState(STATES_e state); // setup() runs once, when the device is first turned on. void setup() { @@ -163,4 +163,4 @@ static void printState(STATES_e state) } pStateName = STATES_NAME_TAB[state]; SF_OSAL_printf("%s" __NL__, pStateName); -} \ No newline at end of file +} From 0dad497046e55a4f721cd45fa5f555b753d3b42d Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:52:38 -0800 Subject: [PATCH 19/61] fix: Implements EEPROM --- pc_hal/Particle.h | 13 +++++++++---- pc_hal/Particle_dummy.cpp | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 4f67beae..dd58d417 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -12,17 +12,22 @@ #define __PC_HAL_PARTICLE_H__ #include +#include #include #include class EEPROMClass { - EEPROMClass() - { - } +private: + uint8_t *blob; + std::size_t blob_size; + +public: + EEPROMClass(); template T &get(int idx, T &t) { - return T(); + std::memcpy(&t, this->blob + idx, sizeof(T)); + return t; } template const T &put(int idx, const T &t) diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index b5affbed..c9024b33 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -11,6 +11,14 @@ #include "Particle.h" +#include +EEPROMClass::EEPROMClass() +{ + this->blob_size = 2048; + this->blob = new std::uint8_t[this->blob_size]; + std::memset(this->blob, 0xFF, this->blob_size); +} + EEPROMClass __global_eeprom; EEPROMClass &__fetch_global_EEPROM() { From 5584ff9eae36d9002c2ee334d463fbe7330a0171 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:58:29 -0800 Subject: [PATCH 20/61] fix: Adds flog and conio --- pc_hal/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 94b6929b..e768aec3 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -14,5 +14,8 @@ include_directories( set(SMARTFIN_SOURCE_FILES main.cpp + Particle_dummy.cpp + ../src/cli/flog.cpp + ../src/cli/conio.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) From d926f6598031d86294e065085f94fc7c29bb960a Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 11:59:27 -0800 Subject: [PATCH 21/61] fix Adds dummy --- pc_hal/Particle.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index dd58d417..1a3edb82 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -15,6 +15,7 @@ #include #include #include +#define retained class EEPROMClass { private: @@ -49,6 +50,20 @@ class USARTSerial void begin(int baud) { } + + std::size_t available() + { + return 0; + } + + int read() + { + return 0; + } + + void print(char ch) + { + } }; #define Serial __get_default_serial() USARTSerial &__get_default_serial(); @@ -154,6 +169,10 @@ class TimeClass { return 0; } + + void delay(std::uint32_t ms) + { + } }; #define Time __fetch_global_time() TimeClass &__fetch_global_time(); From d70a1875d7d101d15e0637b7324032400a8d7949 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 12:01:07 -0800 Subject: [PATCH 22/61] fix: Adds Particle --- pc_hal/Particle.h | 13 +++++++++++++ pc_hal/Particle_dummy.cpp | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 1a3edb82..2be3b621 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -176,4 +176,17 @@ class TimeClass }; #define Time __fetch_global_time() TimeClass &__fetch_global_time(); + +#define millis Time.now +#define delay Time.delay + +class ParticleClass +{ +public: + void process() + { + } +}; +#define Particle __fetch_global_particle() +ParticleClass &__fetch_global_particle(); #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index c9024b33..21064bc4 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -41,4 +41,10 @@ TimeClass __global_time; TimeClass &__fetch_global_time() { return __global_time; +} + +ParticleClass __global_particle; +ParticleClass &__fetch_global_particle() +{ + return __global_particle; } \ No newline at end of file From 17489a589464b1912edb1d25115f655d144d5b09 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 12:04:56 -0800 Subject: [PATCH 23/61] fix: Adds stdarg --- src/cli/conio.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index 33792d2c..6cd328be 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -1,6 +1,7 @@ #ifndef __CONIO_HPP__ #define __CONIO_HPP__ +#include #include #define SF_OSAL_PRINTF_BUFLEN 1536 From d82b47534176c8d9041af3351b96c33556ebb5ba Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 12:06:30 -0800 Subject: [PATCH 24/61] fix: Adds Serial Write --- pc_hal/Particle.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 2be3b621..59d85251 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -64,6 +64,9 @@ class USARTSerial void print(char ch) { } + void write(const char *str) + { + } }; #define Serial __get_default_serial() USARTSerial &__get_default_serial(); From 66670f1654910395324e2fdaec846242ab88781c Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 16:16:45 -0800 Subject: [PATCH 25/61] fix: Adds system.cpp --- pc_hal/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index e768aec3..146843d7 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -17,5 +17,6 @@ set(SMARTFIN_SOURCE_FILES Particle_dummy.cpp ../src/cli/flog.cpp ../src/cli/conio.cpp + ../src/system.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) From 03600735820341d8c9fdf6b5926fc2a217fbe863 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 16:17:34 -0800 Subject: [PATCH 26/61] fix: Adds SPI for PC HAL --- pc_hal/SPI.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pc_hal/SPI.h diff --git a/pc_hal/SPI.h b/pc_hal/SPI.h new file mode 100644 index 00000000..11198301 --- /dev/null +++ b/pc_hal/SPI.h @@ -0,0 +1,13 @@ +/** + * @file SPI.h + * @author Nathan Hui (nthui@ucsd.edu) + * @brief PC HAL - SPI + * @version 0.1 + * @date 2024-11-13 + * + * @copyright Copyright (c) 2024 + * + */ +#ifndef __PC_HAL_SPI_H__ +#define __PC_HAL_SPI_H__ +#endif // __PC_HAL_SPI_H__ \ No newline at end of file From b71805193620b5cc45ccb8bf6a729bc86d6c5555 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:38:23 -0800 Subject: [PATCH 27/61] fix: Adds dummies --- pc_hal/CMakeLists.txt | 9 ++ pc_hal/Particle.h | 228 ++++++++++++++++++++++++++++++++++++-- pc_hal/Particle_dummy.cpp | 23 +++- src/sleepTask.cpp | 3 +- 4 files changed, 250 insertions(+), 13 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 146843d7..46ee2073 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -18,5 +18,14 @@ set(SMARTFIN_SOURCE_FILES ../src/cli/flog.cpp ../src/cli/conio.cpp ../src/system.cpp + ../src/cellular/sf_cloud.cpp + ../src/sleepTask.cpp + ../src/cli/cli.cpp + ../src/states.cpp + ../src/mfgTest/mfgTest.cpp + ../src/chargeTask.cpp + ../src/cellular/dataUpload.cpp + ../src/sys/NVRAM.cpp + ../src/cellular/recorder.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 59d85251..571442fc 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -42,6 +42,18 @@ EEPROMClass &__fetch_global_EEPROM(); class Timer { + int period; + void (*cb)(void); + bool one_shot; + +public: + Timer(int period, void (*fn)(void), bool one_shot = false); + void start(void) + { + } + void stop(void) + { + } }; class USARTSerial @@ -75,8 +87,16 @@ class SPIClass { }; -class String : public std::string +class String { + std::string val; + +public: + String(const char *val); + const char *c_str() const + { + return val.c_str(); + } }; typedef enum @@ -100,19 +120,22 @@ class os_queue_t class Thread { }; +#define os_thread_yield() ; enum { PIN_INVALID }; -enum -{ - HIGH -}; class TwoWire { +public: + void begin(void) + { + } }; +#define Wire __fetch_global_I2C() +TwoWire &__fetch_global_I2C(); typedef std::size_t system_tick_t; template class Vector @@ -123,19 +146,78 @@ class RecursiveMutex { }; -typedef struct +typedef enum +{ + LED_SIGNAL_NETWORK_OFF, + LED_SIGNAL_NETWORK_ON, + LED_SIGNAL_NETWORK_CONNECTING, + LED_SIGNAL_NETWORK_DHCP, + LED_SIGNAL_NETWORK_CONNECTED, + LED_SIGNAL_CLOUD_CONNECTING, + LED_SIGNAL_CLOUD_CONNECTED, + LED_SIGNAL_CLOUD_HANDSHAKE +} LEDSignal; +typedef enum +{ + LED_PATTERN_SOLID, + LED_PATTERN_BLINK +} LEDPattern; +typedef enum +{ + LED_SPEED_NORMAL +} LEDSpeed; + +enum { + RGB_COLOR_BLUE = 0x000000ff, + RGB_COLOR_RED = 0x00ff0000, + RGB_COLOR_YELLOW = 0x0000ffff, +}; -} LEDSystemTheme; +class LEDSystemTheme +{ +public: + LEDSystemTheme(void); + void setSignal(LEDSignal signal, uint32_t color); + void setSignal(LEDSignal signal, + uint32_t color, + LEDPattern pattern, + LEDSpeed speed = LED_SPEED_NORMAL); + void setSignal(LEDSignal signal, uint32_t color, LEDPattern pattern, uint16_t period); +}; class FuelGauge { +public: + float getVCell(void) + { + return 0; + } }; -typedef struct +typedef enum { - -} LEDStatus; + LED_PRIORITY_IMPORTANT +} LEDPriority; +class LEDStatus +{ +public: + void setColor(uint32_t color) + { + } + void setPattern(LEDPattern pattern) + { + } + void setPeriod(std::uint16_t period) + { + } + void setPriority(LEDPriority priority) + { + } + void setActive(bool active = true) + { + } +}; #define SYSTEM_MODE(a) ; #define SYSTEM_THREAD(a) ; @@ -146,10 +228,41 @@ typedef enum } HAL_Feature; typedef enum { - RESET_REASON_NONE + RESET_REASON_NONE, + RESET_REASON_PIN_RESET, + RESET_REASON_POWER_MANAGEMENT, + RESET_REASON_POWER_DOWN, + RESET_REASON_POWER_BROWNOUT, + RESET_REASON_WATCHDOG, + RESET_REASON_UPDATE, + RESET_REASON_UPDATE_TIMEOUT, + RESET_REASON_FACTORY_RESET, + RESET_REASON_SAFE_MODE, + RESET_REASON_DFU_MODE, + RESET_REASON_PANIC, + RESET_REASON_USER, + RESET_REASON_UNKNOWN } __RESET_REASON_t; + +typedef enum +{ + BATTERY_STATE_UNKNOWN = 0, + BATTERY_STATE_NOT_CHARGING = 1, + BATTERY_STATE_CHARGING = 2, + BATTERY_STATE_CHARGED = 3, + BATTERY_STATE_DISCHARGING = 4, + BATTERY_STATE_FAULT = 5, + BATTERY_STATE_DISCONNECTED = 6 +} battery_state_t; + +enum +{ + SLEEP_MODE_SOFTPOWEROFF +}; class SystemClass { + String device_id = String(""); + public: int enableFeature(HAL_Feature feature) { @@ -159,6 +272,23 @@ class SystemClass { return RESET_REASON_NONE; } + + String &deviceID(void) + { + return device_id; + } + + int batteryState() const + { + return BATTERY_STATE_UNKNOWN; + } + + void sleep(uint32_t mode); + void sleep(uint32_t mode, uint32_t time); + void reset(void) + { + exit(0); + } }; #define System __fetch_global_System() SystemClass &__fetch_global_System(); @@ -189,7 +319,83 @@ class ParticleClass void process() { } + + bool connected() + { + return false; + } + bool disconnected() + { + return !this->connected(); + } + void connect(void) + { + } + void disconnect(void) + { + } + bool publish(const char *name, const char *data) + { + return false; + } }; #define Particle __fetch_global_particle() ParticleClass &__fetch_global_particle(); + +class CellularClass +{ +public: + bool isOn() + { + return false; + } + bool ready() + { + return false; + } +}; +#define Cellular __fetch_global_cellular() +CellularClass &__fetch_global_cellular(); + +/** + * @brief PC HAL Pin Definitions + * + */ +typedef enum +{ + A2, + A3, + A4, + A5, + A6, + A7, + WKP +} __PC_HAL_PIN_DEFs; + +typedef enum +{ + INPUT, + INPUT_PULLDOWN, + OUTPUT +} __PC_HAL_PIN_CONFIG; + +typedef enum +{ + LOW, + HIGH +} __PC_HAL_PIN_STATE; + +void pinMode(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_CONFIG mode); + +void digitalWrite(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_STATE state); + +int digitalRead(__PC_HAL_PIN_DEFs pin); +namespace particle +{ + namespace protocol + { + const std::size_t MAX_EVENT_DATA_LENGTH = 1024; + const std::size_t MAX_EVENT_NAME_LENGTH = 64; + } // namespace protocol +} // namespace particle #endif // __PC_HAL_PARTICLE_H__ \ No newline at end of file diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 21064bc4..cf95571e 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -47,4 +47,25 @@ ParticleClass __global_particle; ParticleClass &__fetch_global_particle() { return __global_particle; -} \ No newline at end of file +} + +Timer::Timer(int period, void (*fn)(void), bool one_shot) + : period(period), cb(fn), one_shot(one_shot) +{ +} + +String::String(const char *val) : val(val) +{ +} + +TwoWire __global_i2c; +TwoWire &__fetch_global_I2C() +{ + return __global_i2c; +} + +CellularClass __global_cellular; +CellularClass &__fetch_global_cellular() +{ + return __global_cellular; +} diff --git a/src/sleepTask.cpp b/src/sleepTask.cpp index 52f70854..7ad75a6d 100644 --- a/src/sleepTask.cpp +++ b/src/sleepTask.cpp @@ -38,7 +38,7 @@ void SleepTask::init(void) // bring down the system safely // SYS_deinitSys(); TODO - +#if SF_PLATFORM == SF_PLATFORM_PARTICLE switch(SleepTask::bootBehavior) { case BOOT_BEHAVIOR_UPLOAD_REATTEMPT: @@ -62,6 +62,7 @@ void SleepTask::init(void) System.sleep(config); break; } +#endif //safety SF_OSAL_printf("System going down!" __NL__); System.reset(); From ef08445f970a98214e7929c8a808fcc2e59911e0 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:45:07 -0800 Subject: [PATCH 28/61] fix: Disables recorder --- pc_hal/Particle.h | 4 ++++ src/cellular/recorder.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 571442fc..325c52c8 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -306,6 +306,10 @@ class TimeClass void delay(std::uint32_t ms) { } + String format(uint32_t timestamp, const char *fmt) + { + return String(""); + } }; #define Time __fetch_global_time() TimeClass &__fetch_global_time(); diff --git a/src/cellular/recorder.cpp b/src/cellular/recorder.cpp index 81848599..b97f7fbd 100644 --- a/src/cellular/recorder.cpp +++ b/src/cellular/recorder.cpp @@ -50,6 +50,7 @@ static inline void REC_build_data_filename(uint32_t session_idx, int Recorder::create_metadata_file(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE struct stat stat_result; int result = stat(METADATA_FILE, &stat_result); int fp; @@ -121,11 +122,13 @@ int Recorder::create_metadata_file(void) return 0; } this->metadata_header_valid = true; +#endif return 1; } int REC_create_data_root(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE struct stat stat_result; int result = stat(DATA_ROOT, &stat_result); @@ -162,6 +165,7 @@ int REC_create_data_root(void) SF_OSAL_printf("REC::create_data_root: Failed to create: %d" __NL__, errno); #endif FLOG_AddError(FLOG_FS_MKDIR_FAIL, errno); +#endif return 0; } @@ -498,6 +502,7 @@ int Recorder::putBytes(const void* pData, size_t nBytes) int Recorder::pop_metadata_entry(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE int fp; off_t final_length; @@ -531,11 +536,13 @@ int Recorder::pop_metadata_entry(void) FLOG_AddError(FLOG_FS_CLOSE_FAIL, errno); return 1; } +#endif return 0; } int Recorder::push_metadata_entry(uint32_t session_idx) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE int fp; timestamp_entry_t entry; @@ -572,11 +579,13 @@ int Recorder::push_metadata_entry(uint32_t session_idx) FLOG_AddError(FLOG_FS_CLOSE_FAIL, errno); return 1; } +#endif return 0; } int Recorder::set_metadata_entry_time(uint32_t session_idx, uint32_t timestamp) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE int fp; timestamp_entry_t entry; int bytes_read; @@ -624,11 +633,13 @@ int Recorder::set_metadata_entry_time(uint32_t session_idx, uint32_t timestamp) FLOG_AddError(FLOG_FS_CLOSE_FAIL, errno); return 5; } +#endif return 0; } int Recorder::peek_last_metadata_entry(timestamp_entry_t& entry) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE int fp; off_t entry_pos; entry_pos = sizeof(metadata_header_t) + @@ -653,5 +664,6 @@ int Recorder::peek_last_metadata_entry(timestamp_entry_t& entry) FLOG_AddError(FLOG_FS_CLOSE_FAIL, errno); return 3; } +#endif return 0; } \ No newline at end of file From 5041831fa2ec5ed7624f06e44a119fecbcdd53d7 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:46:25 -0800 Subject: [PATCH 29/61] fix: Implements pin functions --- pc_hal/Particle_dummy.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index cf95571e..3a0fe93a 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -69,3 +69,16 @@ CellularClass &__fetch_global_cellular() { return __global_cellular; } + +void pinMode(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_CONFIG mode) +{ +} + +void digitalWrite(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_STATE state) +{ +} + +int digitalRead(__PC_HAL_PIN_DEFs pin) +{ + return 0; +} \ No newline at end of file From db7c473c3156ed6b3dab78cf2aad10c44e0ac0ad Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:48:41 -0800 Subject: [PATCH 30/61] fix: Adds LED --- pc_hal/CMakeLists.txt | 1 + pc_hal/Particle.h | 8 +++++--- pc_hal/Particle_dummy.cpp | 16 ++++++++++++---- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 46ee2073..5b5a5047 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -27,5 +27,6 @@ set(SMARTFIN_SOURCE_FILES ../src/cellular/dataUpload.cpp ../src/sys/NVRAM.cpp ../src/cellular/recorder.cpp + ../src/sys/led.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 325c52c8..4792421b 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -389,11 +389,13 @@ typedef enum HIGH } __PC_HAL_PIN_STATE; -void pinMode(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_CONFIG mode); +void pinMode(int pin, __PC_HAL_PIN_CONFIG mode); -void digitalWrite(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_STATE state); +void digitalWrite(int pin, int state); +void digitalWriteFast(int pin, int state); -int digitalRead(__PC_HAL_PIN_DEFs pin); +int digitalRead(int pin); +int pinReadFast(int pin); namespace particle { namespace protocol diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 3a0fe93a..728f7efe 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -70,15 +70,23 @@ CellularClass &__fetch_global_cellular() return __global_cellular; } -void pinMode(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_CONFIG mode) +void pinMode(int pin, __PC_HAL_PIN_CONFIG mode) { } -void digitalWrite(__PC_HAL_PIN_DEFs pin, __PC_HAL_PIN_STATE state) +void digitalWrite(int pin, int state) { } -int digitalRead(__PC_HAL_PIN_DEFs pin) +void digitalWriteFast(int pin, int state) +{ +} + +int digitalRead(int pin) { return 0; -} \ No newline at end of file +} +int pinReadFast(int pin) +{ + return 0; +} From 3ac0640b70bcef3f5d80c0db7b8ff8eb18ff4c5e Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:49:35 -0800 Subject: [PATCH 31/61] fix: Implements LEDSystemTheme --- pc_hal/Particle.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 4792421b..3b4394f4 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -178,12 +178,18 @@ class LEDSystemTheme { public: LEDSystemTheme(void); - void setSignal(LEDSignal signal, uint32_t color); + void setSignal(LEDSignal signal, uint32_t color) + { + } void setSignal(LEDSignal signal, uint32_t color, LEDPattern pattern, - LEDSpeed speed = LED_SPEED_NORMAL); - void setSignal(LEDSignal signal, uint32_t color, LEDPattern pattern, uint16_t period); + LEDSpeed speed = LED_SPEED_NORMAL) + { + } + void setSignal(LEDSignal signal, uint32_t color, LEDPattern pattern, uint16_t period) + { + } }; class FuelGauge From 200d8697a63b037c662ccf746bbc3003f111bcab Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:51:00 -0800 Subject: [PATCH 32/61] fix: Implements waterSensor --- pc_hal/CMakeLists.txt | 1 + pc_hal/Particle.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 5b5a5047..bfbef338 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -28,5 +28,6 @@ set(SMARTFIN_SOURCE_FILES ../src/sys/NVRAM.cpp ../src/cellular/recorder.cpp ../src/sys/led.cpp + ../src/watersensor/waterSensor.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 3b4394f4..e23336d4 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -312,6 +312,9 @@ class TimeClass void delay(std::uint32_t ms) { } + void delayMicroseconds(std::size_t us) + { + } String format(uint32_t timestamp, const char *fmt) { return String(""); @@ -322,6 +325,7 @@ TimeClass &__fetch_global_time(); #define millis Time.now #define delay Time.delay +#define delayMicroseconds Time.delayMicroseconds class ParticleClass { From dcdf943bfc986ae4302cabd981f6caebd5034239 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Wed, 13 Nov 2024 17:56:16 -0800 Subject: [PATCH 33/61] fix: Implemented dummy location service --- pc_hal/Particle.h | 4 +++- pc_hal/Particle_dummy.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index e23336d4..ae1a0cf4 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -177,7 +177,9 @@ enum class LEDSystemTheme { public: - LEDSystemTheme(void); + LEDSystemTheme(void) + { + } void setSignal(LEDSignal signal, uint32_t color) { } diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 728f7efe..059990b9 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -10,6 +10,7 @@ */ #include "Particle.h" +#include "location_service.h" #include EEPROMClass::EEPROMClass() @@ -90,3 +91,18 @@ int pinReadFast(int pin) { return 0; } + +void LocationService::setModuleType(void) +{ +} +int LocationService::begin(const LocationServiceConfiguration &config) +{ + return 1; +} +int LocationService::start(bool restart) +{ + return 1; +} +void LocationService::setFastLock(bool enable) +{ +} \ No newline at end of file From 4f1f1f8a528f4171ea114c8cbe3501d1f1ffbfd7 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 13:38:45 -0800 Subject: [PATCH 34/61] fix: Adds LocationService dummy --- pc_hal/Particle_dummy.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 059990b9..63323af9 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -105,4 +105,9 @@ int LocationService::start(bool restart) } void LocationService::setFastLock(bool enable) { -} \ No newline at end of file +} + +LocationService::LocationService() +{ +} +LocationService *LocationService::_instance = nullptr; From e923893b2da656c710bd8b09fa2a41490a48b921 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 13:42:13 -0800 Subject: [PATCH 35/61] fix: Adds dummy modules --- pc_hal/CMakeLists.txt | 3 +++ pc_hal/Particle.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index bfbef338..94c1d918 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -29,5 +29,8 @@ set(SMARTFIN_SOURCE_FILES ../src/cellular/recorder.cpp ../src/sys/led.cpp ../src/watersensor/waterSensor.cpp + ../src/temperature/max317275_cpp.cpp + ../src/temperature/tmpSensor.cpp + ../src/vers.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index ae1a0cf4..75cf31ec 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -270,6 +270,7 @@ enum class SystemClass { String device_id = String(""); + String version_str = String(""); public: int enableFeature(HAL_Feature feature) @@ -297,6 +298,11 @@ class SystemClass { exit(0); } + + String &version(void) + { + return version_str; + } }; #define System __fetch_global_System() SystemClass &__fetch_global_System(); From 14be8ff6a6a3b1823f2c5fcfffeee74b592ceb8e Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 13:44:33 -0800 Subject: [PATCH 36/61] fix: CRC and SHA256 only on Particle --- src/vers.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vers.cpp b/src/vers.cpp index b1af9ab4..90ea59ca 100644 --- a/src/vers.cpp +++ b/src/vers.cpp @@ -50,6 +50,7 @@ void VERS_printBanner(void) const uint32_t APP_ADDR = 0x000d4000; // Earlier versions including 2.x LTS #endif +#if SF_PLATFORM == SF_PLATFORM_PARTICLE const module_info_t *prefix = (module_info_t *)APP_ADDR; const uint32_t *crcAddr = (const uint32_t *)prefix->module_end_address; @@ -62,7 +63,7 @@ void VERS_printBanner(void) SF_OSAL_printf("%02x", sha[byte_idx]); } SF_OSAL_printf(__NL__); - +#endif } const char* VERS_getBuildDate(void) From e13d7b3640d01daf41df5ef62256d382a4ef8ec5 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 13:49:23 -0800 Subject: [PATCH 37/61] fix: Updates deploy.cpp for PC HAL --- pc_hal/CMakeLists.txt | 3 +++ src/cellular/deploy.cpp | 47 ++++++++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 94c1d918..7fd6a3ac 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -32,5 +32,8 @@ set(SMARTFIN_SOURCE_FILES ../src/temperature/max317275_cpp.cpp ../src/temperature/tmpSensor.cpp ../src/vers.cpp + ../src/cellular/encoding/base64.c + ../src/cli/menu.cpp + ../src/cellular/deploy.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/src/cellular/deploy.cpp b/src/cellular/deploy.cpp index b4dab1fb..2f381e9b 100644 --- a/src/cellular/deploy.cpp +++ b/src/cellular/deploy.cpp @@ -30,6 +30,7 @@ Deployment& Deployment::getInstance(void) int Deployment::open(const char* const name, Deployment::State_e state) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (this->currentFile == 0) { ::close(this->currentFile); @@ -57,25 +58,28 @@ int Deployment::open(const char* const name, Deployment::State_e state) } strncpy(this->filename, name, SF_NAME_MAX); this->currentState = state; +#endif return 1; } int Deployment::write(void* pData, size_t nBytes) { size_t bytesWritten = 0; +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (currentFile == 0 || currentState != Deployment::WRITE) { return 0; } bytesWritten = ::write(currentFile, (uint8_t*)pData, nBytes); ::fsync(currentFile); +#endif return bytesWritten; } int Deployment::read(void* pData, size_t nBytes) { size_t bytesRead = 0; - +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (currentFile == 0) { return 0; @@ -86,11 +90,13 @@ int Deployment::read(void* pData, size_t nBytes) return 0; } bytesRead = ::read(this->currentFile, (char*)pData, nBytes); +#endif return bytesRead; } int Deployment::close(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (currentFile == 0) { return 1; @@ -101,34 +107,38 @@ int Deployment::close(void) } this->currentFile = 0; memset(this->filename, 0, SF_NAME_MAX); +#endif return 1; } int Deployment::seek(size_t loc) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (this->currentFile == 0) { return 0; } lseek(this->currentFile, loc, SEEK_SET); +#endif return 1; } int Deployment::getLength(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (this->currentFile == 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::getLength: invalid file!" __NL__); - #endif +#endif return 0; } struct stat sbuf = {}; if (fstat(currentFile, &sbuf) != 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::getLength: fstat failed!" __NL__); - #endif +#endif } #ifdef DEP_DEBUG @@ -136,51 +146,58 @@ int Deployment::getLength(void) #endif return (int)sbuf.st_size; +#else + return 0; +#endif } int Deployment::remove(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (this->currentFile == 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::remove: invalid file!" __NL__); - #endif +#endif return 0; } if (::close(this->currentFile) != 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::remove: Close failed!" __NL__); - #endif +#endif return 0; } if (unlink(this->filename) != 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::remove: Unlink failed!" __NL__); - #endif +#endif return 0; } memset(this->filename, 0, SF_NAME_MAX); this->currentFile = 0; +#endif return 1; } int Deployment::truncate(size_t nBytes) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE if (this->currentFile == 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::truncate: invalid file!" __NL__); - #endif +#endif return 0; } if (ftruncate(this->currentFile, nBytes) != 0) { - #ifdef DEP_DEBUG +#ifdef DEP_DEBUG SF_OSAL_printf("DEP::truncate: ftruncate failed!" __NL__); - #endif +#endif return 0; } +#endif return 1; } \ No newline at end of file From 871277080bbc1b430b3f9818ebd65afb7ddabda7 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:10:06 -0800 Subject: [PATCH 38/61] fix: Dummy I2C --- pc_hal/CMakeLists.txt | 1 + src/i2c/i2c.cpp | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 7fd6a3ac..f12f33e6 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -35,5 +35,6 @@ set(SMARTFIN_SOURCE_FILES ../src/cellular/encoding/base64.c ../src/cli/menu.cpp ../src/cellular/deploy.cpp + ../src/i2c/i2c.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/src/i2c/i2c.cpp b/src/i2c/i2c.cpp index b3a62bb1..2c440186 100644 --- a/src/i2c/i2c.cpp +++ b/src/i2c/i2c.cpp @@ -1,15 +1,19 @@ -#include "Particle.h" #include "i2c.h" +#include "Particle.h" #include "cli/conio.hpp" +#include "product.hpp" #include +#if SF_PLATFORM == SF_PLATFORM_PARTICLE #include +#endif // Map MBED I2C class to the Particle IO Device OS I2C class. int I2C::read(uint8_t address, char *data, int length, bool repeated) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE // convert from 8-bit to 7-bit address address >>= 1; @@ -18,7 +22,7 @@ int I2C::read(uint8_t address, char *data, int length, bool repeated) Wire.begin(); delay(1000); } - + Wire.beginTransmission(address); uint8_t bytes = Wire.requestFrom((int)address, length); uint8_t idx; @@ -27,12 +31,16 @@ int I2C::read(uint8_t address, char *data, int length, bool repeated) data[idx] = (uint8_t)Wire.read(); } Wire.endTransmission(repeated == false); - + return idx == length ? I2C_NO_ERROR : I2C_ERROR; +#else + return I2C_NO_ERROR; +#endif } int I2C::write(uint8_t address, const char *data, int length, bool repeated) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE // convert from 8-bit to 7-bit address address >>= 1; @@ -41,7 +49,7 @@ int I2C::write(uint8_t address, const char *data, int length, bool repeated) Wire.begin(); delay(1000); } - + Wire.beginTransmission(address); uint8_t idx; for (idx = 0; idx < length; idx++) @@ -49,6 +57,9 @@ int I2C::write(uint8_t address, const char *data, int length, bool repeated) Wire.write(data[idx]); } Wire.endTransmission(repeated == false); - + return idx == length ? I2C_NO_ERROR : I2C_ERROR; +#else + return I2C_NO_ERROR; +#endif } From 9769a349cef42b059726a82cac36fd043765b800 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:10:35 -0800 Subject: [PATCH 39/61] fix: util compile --- pc_hal/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index f12f33e6..b1006b0e 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -36,5 +36,6 @@ set(SMARTFIN_SOURCE_FILES ../src/cli/menu.cpp ../src/cellular/deploy.cpp ../src/i2c/i2c.cpp + ../src/util.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) From 5819e4f9c01ae797af310d17a13ca48eab16a99d Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:11:18 -0800 Subject: [PATCH 40/61] fix: systemCommands compile --- pc_hal/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index b1006b0e..df98a87f 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -37,5 +37,6 @@ set(SMARTFIN_SOURCE_FILES ../src/cellular/deploy.cpp ../src/i2c/i2c.cpp ../src/util.cpp + ../src/cli/menuItems/systemCommands.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) From 9279017136bde9c2314ca96eb0897a02391cb966 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:15:11 -0800 Subject: [PATCH 41/61] fix: Adds debugCommands.cpp --- pc_hal/CMakeLists.txt | 1 + src/fileCLI/fileCLI.hpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index df98a87f..900b4940 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -38,5 +38,6 @@ set(SMARTFIN_SOURCE_FILES ../src/i2c/i2c.cpp ../src/util.cpp ../src/cli/menuItems/systemCommands.cpp + ../src/cli/menuItems/debugCommands.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/src/fileCLI/fileCLI.hpp b/src/fileCLI/fileCLI.hpp index 2603d1be..f4c75f10 100644 --- a/src/fileCLI/fileCLI.hpp +++ b/src/fileCLI/fileCLI.hpp @@ -3,9 +3,9 @@ #include "Particle.h" -#include #include -#include +#include +#include #define FILE_CLI_INPUT_BUFFER_LEN 80 #define FILE_CLI_MAX_DIR_DEPTH 4 From 531fd5c2a7ab388132aadf9e759a4644c8108e77 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:19:12 -0800 Subject: [PATCH 42/61] fix: Adds String methods --- pc_hal/Particle.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pc_hal/Particle.h b/pc_hal/Particle.h index 75cf31ec..4ef398e2 100644 --- a/pc_hal/Particle.h +++ b/pc_hal/Particle.h @@ -11,6 +11,7 @@ #ifndef __PC_HAL_PARTICLE_H__ #define __PC_HAL_PARTICLE_H__ +#include #include #include #include @@ -97,6 +98,19 @@ class String { return val.c_str(); } + static String format(const char *fmt, ...) + { + char buf[2048]; + va_list vargs; + va_start(vargs, fmt); + vsnprintf(buf, 2048, fmt, vargs); + va_end(vargs); + return String(buf); + } + std::size_t length(void) const + { + return val.length(); + } }; typedef enum From 913fa960cd8af21638512247013b8329015c935c Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:20:08 -0800 Subject: [PATCH 43/61] fix: Abstracted particle specific methods --- src/cli/menuItems/debugCommands.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cli/menuItems/debugCommands.cpp b/src/cli/menuItems/debugCommands.cpp index 54717388..f04d0517 100644 --- a/src/cli/menuItems/debugCommands.cpp +++ b/src/cli/menuItems/debugCommands.cpp @@ -61,6 +61,7 @@ void CLI_testGetNumFiles(void) void CLI_createTestFile(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE int fd = open("/testfile.txt", O_RDWR | O_CREAT | O_TRUNC); SF_OSAL_printf("Error: %d" __NL__, errno); SF_OSAL_printf("fd sucsess %d" __NL__, fd); @@ -75,10 +76,12 @@ void CLI_createTestFile(void) } close(fd); } +#endif } void CLI_wipeFileSystem(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE DIR* directory = opendir(""); if (directory == 0) { @@ -89,7 +92,7 @@ void CLI_wipeFileSystem(void) { unlink(readdir(directory)->d_name); } - +#endif } void CLI_checkCharging(void) From 45d06d6b1c4e233d0b671405ef6c488d1335e864 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 14:24:50 -0800 Subject: [PATCH 44/61] fix: IMU dummy --- pc_hal/CMakeLists.txt | 1 + src/imu/imu.cpp | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 900b4940..c9034d8d 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -39,5 +39,6 @@ set(SMARTFIN_SOURCE_FILES ../src/util.cpp ../src/cli/menuItems/systemCommands.cpp ../src/cli/menuItems/debugCommands.cpp + ../src/imu/imu.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/src/imu/imu.cpp b/src/imu/imu.cpp index c36ed225..348f462c 100644 --- a/src/imu/imu.cpp +++ b/src/imu/imu.cpp @@ -11,17 +11,20 @@ * * Modified by Emily Thorpe - Auguest 2023 ***************************************************************/ -#include "ICM_20948.h" + #include "cli/conio.hpp" #include "cli/flog.hpp" +#include "product.hpp" +#if SF_PLATFORM == SF_PLATFORM_PARTICLE +#include "ICM_20948.h" #define SERIAL_PORT Serial #define WIRE_PORT Wire #define AD0_VAL 1 -ICM_20948_I2C myICM; - +ICM_20948_I2C myICM; +#endif float getAccMG( int16_t raw, uint8_t fss ); float getGyrDPS( int16_t raw, uint8_t fss ); @@ -30,6 +33,7 @@ float getTmpC( int16_t raw ); void setupICM(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE WIRE_PORT.begin(); WIRE_PORT.setClock(400000); @@ -42,47 +46,53 @@ void setupICM(void) SF_OSAL_printf("ICM fail"); FLOG_AddError(FLOG_ICM_FAIL, 0); } +#endif } bool getAccelerometer(float *acc_x, float *acc_y, float *acc_z) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE ICM_20948_AGMT_t agmt = myICM.getAGMT(); - + *acc_x = getAccMG(agmt.acc.axes.x, agmt.fss.a); *acc_y = getAccMG(agmt.acc.axes.y, agmt.fss.a); *acc_z = getAccMG(agmt.acc.axes.z, agmt.fss.a); - +#endif return true; } bool getGyroscope(float *gyr_x, float *gyr_y, float *gyr_z) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE ICM_20948_AGMT_t agmt = myICM.getAGMT(); - + *gyr_x = getGyrDPS(agmt.gyr.axes.x, agmt.fss.g); *gyr_y = getGyrDPS(agmt.gyr.axes.y, agmt.fss.g); *gyr_z = getGyrDPS(agmt.gyr.axes.z, agmt.fss.g); - +#endif return true; } bool getMagnetometer(float *mag_x, float *mag_y, float *mag_z) { - ICM_20948_AGMT_t agmt = myICM.getAGMT(); +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + ICM_20948_AGMT_t agmt = myICM.getAGMT(); *mag_x = getMagUT(agmt.mag.axes.x); *mag_y = getMagUT(agmt.mag.axes.y); *mag_z = getMagUT(agmt.mag.axes.z); - +#endif return true; } bool getTemperature(float *temperature) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE ICM_20948_AGMT_t agmt = myICM.getAGMT(); *temperature = getTmpC(agmt.tmp.val); +#endif return true; } From 2d099bc513dc3241f7ac6d839bee71f028393acb Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Thu, 14 Nov 2024 15:34:01 -0800 Subject: [PATCH 45/61] fix: Adds dummy modules --- pc_hal/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index c9034d8d..e1fe6c1a 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -40,5 +40,8 @@ set(SMARTFIN_SOURCE_FILES ../src/cli/menuItems/systemCommands.cpp ../src/cli/menuItems/debugCommands.cpp ../src/imu/imu.cpp + ../src/cli/cliDebug.cpp + ../src/cli/menuItems/gpsCommands.cpp + ../src/debug/recorder_debug.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) From c4126e12f48ec0292bc549dc325178aada7cdd10 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 11:18:46 -0800 Subject: [PATCH 46/61] feat: Adds utils random --- src/debug/recorder_debug.cpp | 2 +- src/util.cpp | 20 ++++++++++++++------ src/util.hpp | 11 +++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/debug/recorder_debug.cpp b/src/debug/recorder_debug.cpp index 5d4259e2..500b7a6b 100644 --- a/src/debug/recorder_debug.cpp +++ b/src/debug/recorder_debug.cpp @@ -185,7 +185,7 @@ void REC_testCreateBigSession(void) input_length = atoi(user_input); for (hex_idx = 0; hex_idx < input_length; hex_idx++) { - rand_byte = random(256); + rand_byte = SF::utils::random(0, 256); switch (pRecorder->putBytes(&rand_byte, 1)) { case 0: diff --git a/src/util.cpp b/src/util.cpp index 54ad37e0..16533b38 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,20 +1,19 @@ /** * @file util.cpp * @author Emily Thorpe (ethorpe@macalster.edu) - * @brief + * @brief * @version 0.1 * @date 2023-07-26 - * + * * @copyright Copyright (c) 2023 - * + * */ - #include "util.hpp" +#include "Particle.h" #include "cli/conio.hpp" #include "consts.hpp" - -#include "Particle.h" +#include "product.hpp" /** * \brief A macro that stores the the size of each line of output as a constant 16 bytes @@ -62,4 +61,13 @@ void hexDump(const void *memoryLocation, size_t buflen) SF_OSAL_printf(" |%s|" __NL__, (const char*)byte_buffer); } SF_OSAL_printf("%08x" __NL__, buffer_idx); +} + +int SF::utils::random(int min, int max) +{ +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + return ::random(min, max); +#elif SF_PLATFORM == SF_PLATFORM_GCC +#error +#endif } \ No newline at end of file diff --git a/src/util.hpp b/src/util.hpp index 36334c9a..2864b238 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -17,4 +17,15 @@ void hexDump(const void *memoryLocation, size_t buflen); #define B_TO_N_ENDIAN_2(x) N_TO_B_ENDIAN_2(x) #define B_TO_N_ENDIAN_4(x) N_TO_B_ENDIAN_4(x) +namespace SF::utils +{ + /** + * @brief Generates a uniform random number in the given range + * + * @param min Minimum value (inclusive) + * @param max Maximum value (exclusive) + * @return int random integer + */ + int random(int min, int max); +}; // namespace SF::utils #endif From 044ef73cd6e3ecbd4d3b22dd83ae36791c82d16f Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 11:44:54 -0800 Subject: [PATCH 47/61] feat: Adds glibc implementation --- src/util.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 16533b38..da2a03ed 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -15,6 +15,8 @@ #include "consts.hpp" #include "product.hpp" +#include + /** * \brief A macro that stores the the size of each line of output as a constant 16 bytes */ @@ -67,7 +69,10 @@ int SF::utils::random(int min, int max) { #if SF_PLATFORM == SF_PLATFORM_PARTICLE return ::random(min, max); -#elif SF_PLATFORM == SF_PLATFORM_GCC -#error +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> distrib(min, max + 1); + return distrib(gen); #endif } \ No newline at end of file From 50f0538b26185c83520393c8bd8de23861817379 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 15:24:05 -0800 Subject: [PATCH 48/61] fix: Adds location service getLocation --- pc_hal/Particle_dummy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pc_hal/Particle_dummy.cpp b/pc_hal/Particle_dummy.cpp index 63323af9..8f775f9b 100644 --- a/pc_hal/Particle_dummy.cpp +++ b/pc_hal/Particle_dummy.cpp @@ -111,3 +111,7 @@ LocationService::LocationService() { } LocationService *LocationService::_instance = nullptr; +int LocationService::getLocation(LocationPoint &point) +{ + return 1; +} \ No newline at end of file From 45a69ef0a7266d2981fe65d9398022ea67436f55 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 15:24:19 -0800 Subject: [PATCH 49/61] fix: Adds fileCLI --- pc_hal/CMakeLists.txt | 2 ++ src/fileCLI/fileCLI.cpp | 70 +++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index e1fe6c1a..2de66880 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -43,5 +43,7 @@ set(SMARTFIN_SOURCE_FILES ../src/cli/cliDebug.cpp ../src/cli/menuItems/gpsCommands.cpp ../src/debug/recorder_debug.cpp + ../src/debug/session_debug.cpp + ../src/fileCLI/fileCLI.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) diff --git a/src/fileCLI/fileCLI.cpp b/src/fileCLI/fileCLI.cpp index b7d7e7d0..c588bac9 100644 --- a/src/fileCLI/fileCLI.cpp +++ b/src/fileCLI/fileCLI.cpp @@ -1,21 +1,20 @@ #include "fileCLI.hpp" +#include "Particle.h" +#include "cellular/encoding/base64.h" +#include "cellular/encoding/base85.h" #include "cli/conio.hpp" #include "cli/flog.hpp" #include "consts.hpp" -#include "cellular/encoding/base64.h" -#include "cellular/encoding/base85.h" #include "product.hpp" #include "system.hpp" -#include "Particle.h" - #include #include #include +#include #include #include -#include static char path_buffer[PATH_MAX]; @@ -57,8 +56,11 @@ void FileCLI::execute(void) this->dir_stack[this->current_dir] = opendir("/"); if (NULL == this->dir_stack[this->current_dir]) { - FLOG_AddError(FLOG_FS_OPENDIR_FAIL, - (uint32_t)this->dir_stack[this->current_dir]); +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + FLOG_AddError(FLOG_FS_OPENDIR_FAIL, (uint32_t)this->dir_stack[this->current_dir]); +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + FLOG_AddError(FLOG_FS_OPENDIR_FAIL, this->current_dir); +#endif SF_OSAL_printf("Failed to open root" __NL__); return; } @@ -234,13 +236,14 @@ void FileCLI::print_dir(void) void FileCLI::deleteFile(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE char input_buffer[FILE_CLI_INPUT_BUFFER_LEN]; - DIR* cwd = this->dir_stack[this->current_dir]; - struct dirent* dirent; + DIR *cwd = this->dir_stack[this->current_dir]; + struct dirent *dirent; char f_type; long idx; int cmd_val; - const char* path; + const char *path; idx = telldir(cwd); while ((dirent = readdir(cwd))) @@ -256,10 +259,7 @@ void FileCLI::deleteFile(void) break; } strncpy(this->path_stack[this->current_dir], dirent->d_name, NAME_MAX); - SF_OSAL_printf("%d: %c %-16s" __NL__, - idx, - f_type, - dirent->d_name); + SF_OSAL_printf("%d: %c %-16s" __NL__, idx, f_type, dirent->d_name); idx = telldir(cwd); } rewinddir(cwd); @@ -281,11 +281,13 @@ void FileCLI::deleteFile(void) } this->current_dir--; memset(this->path_stack[this->current_dir], 0, NAME_MAX); +#endif } void hexdump(int fp, size_t file_len) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE #define BYTES_PER_LINE 16 size_t file_idx = 0; uint8_t byte_buffer[BYTES_PER_LINE + 1]; @@ -329,17 +331,18 @@ void hexdump(int fp, size_t file_len) SF_OSAL_printf(" |%s|" __NL__, (const char*)byte_buffer); } SF_OSAL_printf("%08x" __NL__, file_idx); - +#endif } void FileCLI::dumpHex(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE char input_buffer[FILE_CLI_INPUT_BUFFER_LEN]; - DIR* cwd = this->dir_stack[this->current_dir]; - struct dirent* dirent; + DIR *cwd = this->dir_stack[this->current_dir]; + struct dirent *dirent; long idx; int cmd_val; - const char* path; + const char *path; int fp; struct stat fstats; @@ -352,9 +355,7 @@ void FileCLI::dumpHex(void) continue; } strncpy(this->path_stack[this->current_dir], dirent->d_name, NAME_MAX); - SF_OSAL_printf("%d: %-16s" __NL__, - idx, - dirent->d_name); + SF_OSAL_printf("%d: %-16s" __NL__, idx, dirent->d_name); idx = telldir(cwd); } rewinddir(cwd); @@ -389,10 +390,12 @@ void FileCLI::dumpHex(void) close(fp); this->current_dir--; +#endif } void base85dump(int fp, size_t file_len) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE size_t file_idx = 0, bytes_read; uint8_t byte_buffer[SF_PACKET_SIZE]; char encoded_buffer[SF_RECORD_SIZE]; @@ -402,15 +405,15 @@ void base85dump(int fp, size_t file_len) for (file_idx = 0; file_idx < file_len; file_idx += bytes_read) { bytes_read = read(fp, byte_buffer, SF_PACKET_SIZE); - #if SF_UPLOAD_ENCODING == SF_UPLOAD_BASE85 +#if SF_UPLOAD_ENCODING == SF_UPLOAD_BASE85 encodedLen = bintob85(encoded_buffer, byte_buffer, bytes_read) - encodedBuffer; - #elif SF_UPLOAD_ENCODING == SF_UPLOAD_BASE64 +#elif SF_UPLOAD_ENCODING == SF_UPLOAD_BASE64 encodedLen = SF_RECORD_SIZE; b64_encode(byte_buffer, bytes_read, encoded_buffer, &encodedLen); - #elif SF_UPLOAD_ENCODING == SF_UPLOAD_BASE64URL +#elif SF_UPLOAD_ENCODING == SF_UPLOAD_BASE64URL encodedLen = SF_RECORD_SIZE; urlsafe_b64_encode(byte_buffer, bytes_read, encoded_buffer, &encodedLen); - #endif +#endif totalEncodedLen += encodedLen; SF_OSAL_printf("%s" __NL__, encoded_buffer); n_packets++; @@ -418,16 +421,18 @@ void base85dump(int fp, size_t file_len) SF_OSAL_printf(__NL__ "%d chars of encoded data" __NL__, totalEncodedLen); SF_OSAL_printf("%d packets" __NL__, n_packets); +#endif } void FileCLI::dumpBase85(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE char input_buffer[FILE_CLI_INPUT_BUFFER_LEN]; - DIR* cwd = this->dir_stack[this->current_dir]; - struct dirent* dirent; + DIR *cwd = this->dir_stack[this->current_dir]; + struct dirent *dirent; long idx; int cmd_val; - const char* path; + const char *path; int fp; struct stat fstats; @@ -440,9 +445,7 @@ void FileCLI::dumpBase85(void) continue; } strncpy(this->path_stack[this->current_dir], dirent->d_name, NAME_MAX); - SF_OSAL_printf("%d: %-16s" __NL__, - idx, - dirent->d_name); + SF_OSAL_printf("%d: %-16s" __NL__, idx, dirent->d_name); idx = telldir(cwd); } rewinddir(cwd); @@ -473,12 +476,11 @@ void FileCLI::dumpBase85(void) return; } - SF_OSAL_printf("Publish Header: %s-%s" __NL__, - pSystemDesc->deviceID, - dirent->d_name); + SF_OSAL_printf("Publish Header: %s-%s" __NL__, pSystemDesc->deviceID, dirent->d_name); base85dump(fp, fstats.st_size); close(fp); +#endif } void FileCLI::mkdir(void) From d8397fd46b0b5f25a745f9bc5ca24f0c5e2e16dc Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 16:22:50 -0800 Subject: [PATCH 50/61] fix: Updates platform values --- src/product.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/product.hpp b/src/product.hpp index 75e9eeab..a7df064f 100644 --- a/src/product.hpp +++ b/src/product.hpp @@ -263,18 +263,18 @@ * @brief Particle Platform Selector * */ -#define SF_PLATFORM_PARTICLE 0 +#define SF_PLATFORM_PARTICLE 1 /** * @brief GCC Platform Selector * */ -#define SF_PLATFORM_GLIBC 1 +#define SF_PLATFORM_GLIBC 2 /** * @brief GoogleTest Platform Selector * */ -#define SF_PLATFORM_GOOGLETEST 2 +#define SF_PLATFORM_GOOGLETEST 3 /** * @brief Smartfin Platform Designator From b8b53ce9fd122da6455595b3c67084f5aaf87755 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 13 Dec 2024 16:27:47 -0800 Subject: [PATCH 51/61] feat: Adds printf --- src/cli/conio.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cli/conio.cpp b/src/cli/conio.cpp index 47ec87ac..77040785 100644 --- a/src/cli/conio.cpp +++ b/src/cli/conio.cpp @@ -83,9 +83,13 @@ extern "C" va_list vargs; int nBytes = 0; va_start(vargs, fmt); +#if SF_PLATFORM == SF_PLATFORM_PARTICLE nBytes = vsnprintf(SF_OSAL_printfBuffer, SF_OSAL_PRINTF_BUFLEN, fmt, vargs); - va_end(vargs); Serial.write(SF_OSAL_printfBuffer); +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + nBytes = vprintf(fmt, vargs); +#endif + va_end(vargs); return nBytes; } } \ No newline at end of file From b94b282ac7bfc4980497828b32766d177dc86f15 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 13:45:01 -0800 Subject: [PATCH 52/61] docs: updates install --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97766cd0..8df4df04 100644 --- a/README.md +++ b/README.md @@ -48,4 +48,10 @@ Not charging and less than 10 ms have passed | No Change | Not charging and at least 10 ms have passed | LED ON | ## Wet Dry LED -TODO \ No newline at end of file +TODO + +# Installation for for GCC +Run in a Linux environment + +1. Install build-essentials and cmake +2. Ensure submodules are initialized and updated From 376e21f6ca331f25783b36d699b0a2608bb9ea15 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 13:46:23 -0800 Subject: [PATCH 53/61] fix: Fixes docs --- src/cli/conio.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index df920f22..2aed145e 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -43,7 +43,7 @@ extern "C" int SF_OSAL_printf(const char* fmt, ...); /** - * @brief Gets user input lin + * @brief Gets user input line * @param buffer buffer to write too * @param buflen length of buffer * @return length of the user input line From 2394444a93bd4389619aba9e5384261f08cd6acd Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 14:11:35 -0800 Subject: [PATCH 54/61] docs: Adds gdb --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8df4df04..b8f6f550 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,5 @@ TODO # Installation for for GCC Run in a Linux environment -1. Install build-essentials and cmake +1. Install build-essentials and cmake, gdb 2. Ensure submodules are initialized and updated From cb92f7a6851d10a39f3653f0fa37ab372479040c Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 14:16:36 -0800 Subject: [PATCH 55/61] feat: Switches getch --- src/chargeTask.cpp | 2 +- src/cli/cli.cpp | 2 +- src/cli/conio.cpp | 9 ++++++--- src/cli/conio.hpp | 15 ++++++++------- src/cli/menuItems/debugCommands.cpp | 6 +++--- src/cli/menuItems/gpsCommands.cpp | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/chargeTask.cpp b/src/chargeTask.cpp index 72cf7d04..fac481c8 100644 --- a/src/chargeTask.cpp +++ b/src/chargeTask.cpp @@ -28,7 +28,7 @@ STATES_e ChargeTask::run(void) { if(kbhit()) { - this->inputBuffer[CLI_BUFFER_LEN - 1] = getch(); + this->inputBuffer[CLI_BUFFER_LEN - 1] = SF_OSAL_getch(); byteshiftl(this->inputBuffer, CLI_BUFFER_LEN, 1, 0); if(strcmp(this->inputBuffer, CLI_INTERRUPT_PHRASE) == 0) { diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index a1e9a7cb..68678ad7 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -93,7 +93,7 @@ void CLI::init(void) // While there is an avaliable character typed, get it while (kbhit()) { - getch(); + SF_OSAL_getch(); } } diff --git a/src/cli/conio.cpp b/src/cli/conio.cpp index 77040785..6783e8f5 100644 --- a/src/cli/conio.cpp +++ b/src/cli/conio.cpp @@ -27,14 +27,17 @@ extern "C" return Serial.available(); } - // Get pressed key - int getch(void) + int SF_OSAL_getch(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE while (Serial.available() == 0) { delay(1); } return Serial.read(); +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + return getchar(); +#endif } // Write character @@ -54,7 +57,7 @@ extern "C" Particle.process(); if (kbhit()) { - userInput = getch(); + userInput = SF_OSAL_getch(); switch(userInput) { case '\b': diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index 2aed145e..09853e37 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -14,15 +14,9 @@ extern "C" { #endif - /** - * @brief Gets character from serial - * - * @return int key thats pressed - */ - int getch(void); /** * @brief Checks if key is pressed - * + * * @return int whether key is pressed */ int kbhit(void); @@ -50,6 +44,13 @@ extern "C" */ int SF_OSAL_getline(char *buffer, int buflen); + /** + * @brief Reads the next character from stdin + * + * @return The obtained character on success or EOF on failure. + */ + int SF_OSAL_getch(void); + #ifdef __cplusplus } #endif diff --git a/src/cli/menuItems/debugCommands.cpp b/src/cli/menuItems/debugCommands.cpp index f04d0517..14042fad 100644 --- a/src/cli/menuItems/debugCommands.cpp +++ b/src/cli/menuItems/debugCommands.cpp @@ -149,7 +149,7 @@ void CLI_monitorTempSensor(void) { if(kbhit()) { - ch = getch(); + ch = SF_OSAL_getch(); if('q' == ch) { break; @@ -178,7 +178,7 @@ void CLI_monitorIMU(void) { if(kbhit()) { - ch = getch(); + ch = SF_OSAL_getch(); if('q' == ch) { @@ -216,7 +216,7 @@ void CLI_monitorWetDry(void) { if(kbhit()) { - ch = getch(); + ch = SF_OSAL_getch(); if('q' == ch) { diff --git a/src/cli/menuItems/gpsCommands.cpp b/src/cli/menuItems/gpsCommands.cpp index 8bc753d7..a306b2c8 100644 --- a/src/cli/menuItems/gpsCommands.cpp +++ b/src/cli/menuItems/gpsCommands.cpp @@ -16,7 +16,7 @@ void CLI_GPS() { if(kbhit()) { - ch = getch(); + ch = SF_OSAL_getch(); if('q' == ch) { break; From 278314f975b4d3b0adf7c51859187ec392ab76f9 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 16:19:35 -0800 Subject: [PATCH 56/61] fix: Adds sigint handlers --- pc_hal/main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pc_hal/main.cpp b/pc_hal/main.cpp index 916359dc..6d122cad 100644 --- a/pc_hal/main.cpp +++ b/pc_hal/main.cpp @@ -9,7 +9,9 @@ * */ +#include "cli/conio.hpp" #include "product.hpp" +#include "signal.h" void setup(); void loop(); @@ -17,13 +19,23 @@ void loop(); #include "smartfin-fw3.ino" #if SF_PLATFORM == SF_PLATFORM_GLIBC +#include "ncurses.h" +void sigint_handler(int _) +{ + (void)_; + SF_OSAL_deinit_conio(); + exit(1); +} + int main(int argc, char const *argv[]) { + signal(SIGINT, sigint_handler); setup(); while (true) { loop(); } + SF_OSAL_deinit_conio(); return 0; } From 5775273fdf8ae731517c0118377b9ae04fcc0eb8 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 16:20:15 -0800 Subject: [PATCH 57/61] chore: Encapsulates conio initialization --- src/smartfin-fw3.ino | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/smartfin-fw3.ino b/src/smartfin-fw3.ino index 8577d007..e550d068 100644 --- a/src/smartfin-fw3.ino +++ b/src/smartfin-fw3.ino @@ -61,11 +61,10 @@ static void printState(STATES_e state); // setup() runs once, when the device is first turned on. void setup() { System.enableFeature(FEATURE_RESET_INFO); - Serial.begin(SF_SERIAL_SPEED); + SF_OSAL_init_conio(); currentState = STATE_CLI; - FLOG_Initialize(); time32_t bootTime = Time.now(); FLOG_AddError(FLOG_SYS_START, bootTime); From 6745b45651aa112a6b32535e1bf68b28a5eaf9db Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 16:20:50 -0800 Subject: [PATCH 58/61] fix: Replaces kbhit --- src/chargeTask.cpp | 2 +- src/cli/cli.cpp | 2 +- src/cli/menuItems/debugCommands.cpp | 6 +++--- src/cli/menuItems/gpsCommands.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/chargeTask.cpp b/src/chargeTask.cpp index fac481c8..26695353 100644 --- a/src/chargeTask.cpp +++ b/src/chargeTask.cpp @@ -26,7 +26,7 @@ STATES_e ChargeTask::run(void) { while(1) { - if(kbhit()) + if (SF_OSAL_kbhit()) { this->inputBuffer[CLI_BUFFER_LEN - 1] = SF_OSAL_getch(); byteshiftl(this->inputBuffer, CLI_BUFFER_LEN, 1, 0); diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 68678ad7..3ce4bbf5 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -91,7 +91,7 @@ void CLI::init(void) CLI_ledStatus.setActive(); // While there is an avaliable character typed, get it - while (kbhit()) + while (SF_OSAL_kbhit()) { SF_OSAL_getch(); } diff --git a/src/cli/menuItems/debugCommands.cpp b/src/cli/menuItems/debugCommands.cpp index 14042fad..9695aa8b 100644 --- a/src/cli/menuItems/debugCommands.cpp +++ b/src/cli/menuItems/debugCommands.cpp @@ -147,7 +147,7 @@ void CLI_monitorTempSensor(void) while(1) { - if(kbhit()) + if (SF_OSAL_kbhit()) { ch = SF_OSAL_getch(); if('q' == ch) @@ -176,7 +176,7 @@ void CLI_monitorIMU(void) setupICM(); while(1) { - if(kbhit()) + if (SF_OSAL_kbhit()) { ch = SF_OSAL_getch(); @@ -214,7 +214,7 @@ void CLI_monitorWetDry(void) SF_OSAL_printf("Reading Status" __NL__); while(1) { - if(kbhit()) + if (SF_OSAL_kbhit()) { ch = SF_OSAL_getch(); diff --git a/src/cli/menuItems/gpsCommands.cpp b/src/cli/menuItems/gpsCommands.cpp index a306b2c8..7d591b81 100644 --- a/src/cli/menuItems/gpsCommands.cpp +++ b/src/cli/menuItems/gpsCommands.cpp @@ -14,7 +14,7 @@ void CLI_GPS() int row = 0; for (row = 0; ; row++) { - if(kbhit()) + if (SF_OSAL_kbhit()) { ch = SF_OSAL_getch(); if('q' == ch) From a95d92f2855d13ee7072f18230c7fe4de670774c Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 16:26:08 -0800 Subject: [PATCH 59/61] fix: Replaces newline constant --- src/consts.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/consts.hpp b/src/consts.hpp index 55dc7099..a5727fad 100644 --- a/src/consts.hpp +++ b/src/consts.hpp @@ -1,7 +1,7 @@ #ifndef __CONSTS_HPP__ #define __CONSTS_HPP__ -#define __NL__ "\n" +#define __NL__ "\r\n" #define CLI_SCREEN_HEIGHT 24 #define CLI_SCREEN_WIDTH 80 From 782972c6a16d28d2b96d007217641336aac5b541 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 23:20:19 -0800 Subject: [PATCH 60/61] feat: Adds basic conio --- pc_hal/CMakeLists.txt | 3 + src/cli/conio.cpp | 134 ++++++++++++++++++++++++++++++++++-------- src/cli/conio.hpp | 28 +++++++-- 3 files changed, 135 insertions(+), 30 deletions(-) diff --git a/pc_hal/CMakeLists.txt b/pc_hal/CMakeLists.txt index 2de66880..3a6ac086 100644 --- a/pc_hal/CMakeLists.txt +++ b/pc_hal/CMakeLists.txt @@ -3,6 +3,8 @@ project(smartfin_pc) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +find_package(Threads REQUIRED) + include_directories( . ../src/ @@ -47,3 +49,4 @@ set(SMARTFIN_SOURCE_FILES ../src/fileCLI/fileCLI.cpp ) add_executable(smartfin_pc ${SMARTFIN_SOURCE_FILES}) +target_link_libraries(smartfin_pc Threads::Threads) diff --git a/src/cli/conio.cpp b/src/cli/conio.cpp index 6783e8f5..e361fa20 100644 --- a/src/cli/conio.cpp +++ b/src/cli/conio.cpp @@ -11,20 +11,47 @@ #include "product.hpp" #include -#include - +#if SF_PLATFORM == SF_PLATFORM_GLIBC +#include +#include +#include +#elif SF_PLATFORM == SF_PLATFORM_PARTICLE #include "Particle.h" - +#endif char SF_OSAL_printfBuffer[SF_OSAL_PRINTF_BUFLEN]; +#if SF_PLATFORM == SF_PLATFORM_GLIBC +pthread_t read_thread, write_thread; +#define SF_OSAL_READ_BUFLEN 2048 +char SF_OSAL_inputBuffer[SF_OSAL_READ_BUFLEN]; +std::size_t read_head_idx = 0, read_tail_idx = 0; +void *read_loop(void *_) +{ + while (true) + { + SF_OSAL_inputBuffer[read_head_idx % SF_OSAL_READ_BUFLEN] = getchar(); + read_head_idx++; + } + return nullptr; +} +#endif extern "C" { // Determines if key has been pressed - int kbhit(void) + int SF_OSAL_kbhit(void) { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE return Serial.available(); +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + return read_head_idx != read_tail_idx; +#endif + } + + void SF_OSAL_flush_input(void) + { + read_tail_idx = read_head_idx; } int SF_OSAL_getch(void) @@ -36,15 +63,23 @@ extern "C" } return Serial.read(); #elif SF_PLATFORM == SF_PLATFORM_GLIBC - return getchar(); + char retval = SF_OSAL_inputBuffer[read_tail_idx % SF_OSAL_READ_BUFLEN]; + read_tail_idx++; + return retval; #endif } // Write character - int putch(int ch) + int SF_OSAL_putch(int ch) { - Serial.print((char) ch); +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + Serial.print((char)ch); + return ch; +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + putchar(ch); + fflush(stdout); return ch; +#endif } int SF_OSAL_getline(char *buffer, int buflen) @@ -52,32 +87,60 @@ extern "C" int i = 0; char userInput; +#if SF_PLATFORM == SF_PLATFORM_PARTICLE while (i < buflen) { Particle.process(); - if (kbhit()) + if (SF_OSAL_kbhit()) { userInput = SF_OSAL_getch(); - switch(userInput) + switch (userInput) { - case '\b': - i--; - putch('\b'); - putch(' '); - putch('\b'); - break; - default: - buffer[i++] = userInput; - putch(userInput); - break; - case '\r': - buffer[i++] = 0; - putch('\r'); - putch('\n'); - return i; + case '\b': + i--; + SF_OSAL_putch('\b'); + SF_OSAL_putch(' '); + SF_OSAL_putch('\b'); + break; + default: + buffer[i++] = userInput; + SF_OSAL_putch(userInput); + break; + case '\r': + buffer[i++] = 0; + SF_OSAL_putch('\r'); + SF_OSAL_putch('\n'); + return i; } } } +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + while (i < buflen) + { + if (SF_OSAL_kbhit()) + { + userInput = SF_OSAL_getch(); + switch (userInput) + { + case '\b': + i--; + SF_OSAL_putch('\b'); + SF_OSAL_putch(' '); + SF_OSAL_putch('\b'); + break; + default: + buffer[i++] = userInput; + SF_OSAL_putch(userInput); + break; + case '\r': + buffer[i++] = 0; + SF_OSAL_putch('\r'); + SF_OSAL_putch('\n'); + return i; + } + } + } +#endif return i; } @@ -90,9 +153,30 @@ extern "C" nBytes = vsnprintf(SF_OSAL_printfBuffer, SF_OSAL_PRINTF_BUFLEN, fmt, vargs); Serial.write(SF_OSAL_printfBuffer); #elif SF_PLATFORM == SF_PLATFORM_GLIBC - nBytes = vprintf(fmt, vargs); + vprintf(fmt, vargs); + fflush(stdout); #endif va_end(vargs); return nBytes; } + + void SF_OSAL_init_conio(void) + { +#if SF_PLATFORM == SF_PLATFORM_PARTICLE + Serial.begin(SF_SERIAL_SPEED); +#elif SF_PLATFORM == SF_PLATFORM_GLIBC + pthread_create(&read_thread, NULL, read_loop, NULL); + struct termios term; + tcgetattr(fileno(stdin), &term); + + term.c_lflag &= ~ECHO; + tcsetattr(fileno(stdin), 0, &term); +#endif + } + + void SF_OSAL_deinit_conio(void) + { +#if SF_PLATFORM == SF_PLATFORM_GLIBC +#endif + } } \ No newline at end of file diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index 09853e37..6526badd 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -17,16 +17,16 @@ extern "C" /** * @brief Checks if key is pressed * - * @return int whether key is pressed + * @return 1 if next keypress is available, otherwise 0 */ - int kbhit(void); + int SF_OSAL_kbhit(void); /** * @brief Pushes character to serial - * + * * @param ch character to push - * @return int Sucsess value + * @return Printed char */ - int putch(int ch); + int SF_OSAL_putch(int ch); /** * @brief Printf equivilent * @@ -51,6 +51,24 @@ extern "C" */ int SF_OSAL_getch(void); + /** + * @brief Initializes the conio facility + * + */ + void SF_OSAL_init_conio(void); + + /** + * @brief Safely deinitializes the conio facility + * + */ + void SF_OSAL_deinit_conio(void); + + /** + * @brief Flushes any input buffer + * + */ + void SF_OSAL_flush_input(void); + #ifdef __cplusplus } #endif From 5b40a249b2bb71b5d3ce93374856312bcad14ed3 Mon Sep 17 00:00:00 2001 From: Nathan Hui Date: Fri, 20 Dec 2024 23:28:30 -0800 Subject: [PATCH 61/61] fix: Removes unused function --- src/cli/conio.cpp | 5 ----- src/cli/conio.hpp | 6 ------ 2 files changed, 11 deletions(-) diff --git a/src/cli/conio.cpp b/src/cli/conio.cpp index e361fa20..e4b3ca87 100644 --- a/src/cli/conio.cpp +++ b/src/cli/conio.cpp @@ -49,11 +49,6 @@ extern "C" #endif } - void SF_OSAL_flush_input(void) - { - read_tail_idx = read_head_idx; - } - int SF_OSAL_getch(void) { #if SF_PLATFORM == SF_PLATFORM_PARTICLE diff --git a/src/cli/conio.hpp b/src/cli/conio.hpp index 6526badd..dc1412cd 100644 --- a/src/cli/conio.hpp +++ b/src/cli/conio.hpp @@ -63,12 +63,6 @@ extern "C" */ void SF_OSAL_deinit_conio(void); - /** - * @brief Flushes any input buffer - * - */ - void SF_OSAL_flush_input(void); - #ifdef __cplusplus } #endif