diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 2af65b32..181dc20f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -13,6 +13,7 @@ jobs: - name: Configure and build with CMake run: | + cd test mkdir build cd build cmake .. @@ -20,11 +21,4 @@ jobs: - name: Run unit tests run: | - set -e # Exit immediately on non-zero exit code - cd build/test - dir -s - for test_executable in *; do - if [ -f "$test_executable" ] && [ -x "$test_executable" ]; then - ./"$test_executable" - fi - done + ctest diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 7c9a3578..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required(VERSION 3.10) - -# Set the C++ standard to C++20 -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -project(BatteryEmulator) - -# add_subdirectory(Software/src/devboard/utils) -add_subdirectory(test) diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index fcd70311..5ae9d510 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -1,4 +1,5 @@ #include "BMW-I3-BATTERY.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" diff --git a/Software/src/battery/BMW-I3-BATTERY.h b/Software/src/battery/BMW-I3-BATTERY.h index 1e49a677..455c10ac 100644 --- a/Software/src/battery/BMW-I3-BATTERY.h +++ b/Software/src/battery/BMW-I3-BATTERY.h @@ -2,9 +2,9 @@ #define BMW_I3_BATTERY_H #include "../datalayer/datalayer.h" +#include "../devboard/hal/hal.h" #include "BMW-I3-HTML.h" #include "CanBattery.h" -#include "src/devboard/hal/hal.h" #ifdef BMW_I3_BATTERY #define SELECTED_BATTERY_CLASS BmwI3Battery diff --git a/Software/src/battery/BMW-I3-HTML.h b/Software/src/battery/BMW-I3-HTML.h index a0ba265d..5301cb6b 100644 --- a/Software/src/battery/BMW-I3-HTML.h +++ b/Software/src/battery/BMW-I3-HTML.h @@ -1,9 +1,9 @@ #ifndef _BMW_I3_HTML_H #define _BMW_I3_HTML_H +#include "../../src/devboard/webserver/BatteryHtmlRenderer.h" #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" class BmwI3Battery; diff --git a/Software/src/battery/BMW-IX-HTML.h b/Software/src/battery/BMW-IX-HTML.h index aada8182..44bf99d6 100644 --- a/Software/src/battery/BMW-IX-HTML.h +++ b/Software/src/battery/BMW-IX-HTML.h @@ -2,7 +2,7 @@ #define _BMW_IX_HTML_H #include "../datalayer/datalayer.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class BmwIXBattery; diff --git a/Software/src/battery/BMW-PHEV-BATTERY.cpp b/Software/src/battery/BMW-PHEV-BATTERY.cpp index c59dcc24..ea5d017e 100644 --- a/Software/src/battery/BMW-PHEV-BATTERY.cpp +++ b/Software/src/battery/BMW-PHEV-BATTERY.cpp @@ -1,4 +1,5 @@ #include "BMW-PHEV-BATTERY.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" diff --git a/Software/src/battery/BMW-PHEV-BATTERY.h b/Software/src/battery/BMW-PHEV-BATTERY.h index b6a050a1..b35c9edc 100644 --- a/Software/src/battery/BMW-PHEV-BATTERY.h +++ b/Software/src/battery/BMW-PHEV-BATTERY.h @@ -1,6 +1,5 @@ #ifndef BMW_PHEV_BATTERY_H #define BMW_PHEV_BATTERY_H -#include #include "BMW-PHEV-HTML.h" #include "CanBattery.h" @@ -407,7 +406,7 @@ class BmwPhevBattery : public CanBattery { const unsigned long STALE_PERIOD = STALE_PERIOD_CONFIG; // Time in milliseconds to check for staleness (e.g., 5000 ms = 5 seconds) - byte iX_0C0_counter = 0xF0; // Initialize to 0xF0 + uint8_t iX_0C0_counter = 0xF0; // Initialize to 0xF0 //End iX Intermediate vars diff --git a/Software/src/battery/BMW-PHEV-HTML.h b/Software/src/battery/BMW-PHEV-HTML.h index 3b171d41..52d707a4 100644 --- a/Software/src/battery/BMW-PHEV-HTML.h +++ b/Software/src/battery/BMW-PHEV-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class BmwPhevHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/BMW-SBOX.cpp b/Software/src/battery/BMW-SBOX.cpp index 8b0f2ea9..c4e00add 100644 --- a/Software/src/battery/BMW-SBOX.cpp +++ b/Software/src/battery/BMW-SBOX.cpp @@ -1,4 +1,5 @@ #include "BMW-SBOX.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" diff --git a/Software/src/battery/BOLT-AMPERA-BATTERY.h b/Software/src/battery/BOLT-AMPERA-BATTERY.h index 8582741e..d7d08da4 100644 --- a/Software/src/battery/BOLT-AMPERA-BATTERY.h +++ b/Software/src/battery/BOLT-AMPERA-BATTERY.h @@ -1,7 +1,5 @@ #ifndef BOLT_AMPERA_BATTERY_H #define BOLT_AMPERA_BATTERY_H -#include - #include "BOLT-AMPERA-HTML.h" #include "CanBattery.h" diff --git a/Software/src/battery/BOLT-AMPERA-HTML.h b/Software/src/battery/BOLT-AMPERA-HTML.h index 33487473..61c86b23 100644 --- a/Software/src/battery/BOLT-AMPERA-HTML.h +++ b/Software/src/battery/BOLT-AMPERA-HTML.h @@ -2,7 +2,7 @@ #define _BOLT_AMPERA_HTML_H #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class BoltAmperaHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/BYD-ATTO-3-HTML.h b/Software/src/battery/BYD-ATTO-3-HTML.h index ca021882..d2a43b87 100644 --- a/Software/src/battery/BYD-ATTO-3-HTML.h +++ b/Software/src/battery/BYD-ATTO-3-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class BydAtto3HtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/Battery.h b/Software/src/battery/Battery.h index a9a2c997..fb426725 100644 --- a/Software/src/battery/Battery.h +++ b/Software/src/battery/Battery.h @@ -2,8 +2,8 @@ #define BATTERY_H #include -#include "src/devboard/utils/types.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../../src/devboard/utils/types.h" +#include "../../src/devboard/webserver/BatteryHtmlRenderer.h" enum class BatteryType { None = 0, diff --git a/Software/src/battery/CELLPOWER-BMS.h b/Software/src/battery/CELLPOWER-BMS.h index 0b1c2a23..3a22c732 100644 --- a/Software/src/battery/CELLPOWER-BMS.h +++ b/Software/src/battery/CELLPOWER-BMS.h @@ -1,6 +1,5 @@ #ifndef CELLPOWER_BMS_H #define CELLPOWER_BMS_H -#include #include "CELLPOWER-HTML.h" #include "CanBattery.h" diff --git a/Software/src/battery/CELLPOWER-HTML.h b/Software/src/battery/CELLPOWER-HTML.h index f4f6a7ef..7c628f88 100644 --- a/Software/src/battery/CELLPOWER-HTML.h +++ b/Software/src/battery/CELLPOWER-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class CellpowerHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/CHADEMO-BATTERY-HTML.h b/Software/src/battery/CHADEMO-BATTERY-HTML.h index c9ed2277..d92df2c7 100644 --- a/Software/src/battery/CHADEMO-BATTERY-HTML.h +++ b/Software/src/battery/CHADEMO-BATTERY-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class ChademoBatteryHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/CHADEMO-BATTERY.h b/Software/src/battery/CHADEMO-BATTERY.h index 180d19cf..8e603f4e 100644 --- a/Software/src/battery/CHADEMO-BATTERY.h +++ b/Software/src/battery/CHADEMO-BATTERY.h @@ -3,9 +3,9 @@ #include #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" +#include "../devboard/hal/hal.h" #include "CHADEMO-BATTERY-HTML.h" #include "CanBattery.h" -#include "src/devboard/hal/hal.h" #ifdef CHADEMO_BATTERY #define SELECTED_BATTERY_CLASS ChademoBattery diff --git a/Software/src/battery/CMFA-EV-HTML.h b/Software/src/battery/CMFA-EV-HTML.h index 2d1f445f..22d92471 100644 --- a/Software/src/battery/CMFA-EV-HTML.h +++ b/Software/src/battery/CMFA-EV-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class CmfaEvHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/CanBattery.h b/Software/src/battery/CanBattery.h index db4b0894..4178a4b0 100644 --- a/Software/src/battery/CanBattery.h +++ b/Software/src/battery/CanBattery.h @@ -3,11 +3,11 @@ #include "Battery.h" -#include "USER_SETTINGS.h" -#include "src/communication/Transmitter.h" -#include "src/communication/can/CanReceiver.h" -#include "src/communication/can/comm_can.h" -#include "src/devboard/utils/types.h" +#include "../../USER_SETTINGS.h" +#include "../../src/communication/Transmitter.h" +#include "../../src/communication/can/CanReceiver.h" +#include "../../src/communication/can/comm_can.h" +#include "../../src/devboard/utils/types.h" // Abstract base class for batteries using the CAN bus class CanBattery : public Battery, Transmitter, CanReceiver { diff --git a/Software/src/battery/DALY-BMS.cpp b/Software/src/battery/DALY-BMS.cpp index 3d7666c9..d40a5e8c 100644 --- a/Software/src/battery/DALY-BMS.cpp +++ b/Software/src/battery/DALY-BMS.cpp @@ -1,4 +1,5 @@ #include "DALY-BMS.h" +#include #include #include "../datalayer/datalayer.h" #include "../devboard/hal/hal.h" diff --git a/Software/src/battery/ECMP-BATTERY.h b/Software/src/battery/ECMP-BATTERY.h index 2003d5cd..a7f9e1a8 100644 --- a/Software/src/battery/ECMP-BATTERY.h +++ b/Software/src/battery/ECMP-BATTERY.h @@ -1,7 +1,5 @@ #ifndef STELLANTIS_ECMP_BATTERY_H #define STELLANTIS_ECMP_BATTERY_H -#include - #include "CanBattery.h" #include "ECMP-HTML.h" diff --git a/Software/src/battery/ECMP-HTML.h b/Software/src/battery/ECMP-HTML.h index 7a98a42a..b6ac202b 100644 --- a/Software/src/battery/ECMP-HTML.h +++ b/Software/src/battery/ECMP-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class EcmpHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/FOXESS-BATTERY.h b/Software/src/battery/FOXESS-BATTERY.h index da4b39de..c3471d09 100644 --- a/Software/src/battery/FOXESS-BATTERY.h +++ b/Software/src/battery/FOXESS-BATTERY.h @@ -1,7 +1,5 @@ #ifndef FOXESS_BATTERY_H #define FOXESS_BATTERY_H -#include - #include "CanBattery.h" #ifdef FOXESS_BATTERY diff --git a/Software/src/battery/GEELY-GEOMETRY-C-HTML.h b/Software/src/battery/GEELY-GEOMETRY-C-HTML.h index bb4b5602..ddb49dcc 100644 --- a/Software/src/battery/GEELY-GEOMETRY-C-HTML.h +++ b/Software/src/battery/GEELY-GEOMETRY-C-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class GeelyGeometryCHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index c22e981c..d905aa30 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -1,7 +1,5 @@ #ifndef IMIEV_CZERO_ION_BATTERY_H #define IMIEV_CZERO_ION_BATTERY_H -#include - #include "CanBattery.h" #ifdef IMIEV_CZERO_ION_BATTERY diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index 6952e51a..c5ddf979 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -1,4 +1,5 @@ #include "KIA-E-GMP-BATTERY.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../devboard/utils/events.h" diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.h b/Software/src/battery/KIA-E-GMP-BATTERY.h index b726d33e..06fc025c 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.h +++ b/Software/src/battery/KIA-E-GMP-BATTERY.h @@ -1,6 +1,5 @@ #ifndef KIA_E_GMP_BATTERY_H #define KIA_E_GMP_BATTERY_H -#include #include "CanBattery.h" #define ESTIMATE_SOC_FROM_CELLVOLTAGE diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index 60505cb6..deecab7f 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -1,6 +1,5 @@ #ifndef KIA_HYUNDAI_64_BATTERY_H #define KIA_HYUNDAI_64_BATTERY_H -#include #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" #include "CanBattery.h" diff --git a/Software/src/battery/KIA-HYUNDAI-64-HTML.h b/Software/src/battery/KIA-HYUNDAI-64-HTML.h index 23d5916e..0301c7f6 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-HTML.h +++ b/Software/src/battery/KIA-HYUNDAI-64-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class KiaHyundai64HtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h index 5b667875..95e84e45 100644 --- a/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.h @@ -1,7 +1,5 @@ #ifndef KIA_HYUNDAI_HYBRID_BATTERY_H #define KIA_HYUNDAI_HYBRID_BATTERY_H -#include - #include "CanBattery.h" #ifdef KIA_HYUNDAI_HYBRID_BATTERY diff --git a/Software/src/battery/MEB-BATTERY.cpp b/Software/src/battery/MEB-BATTERY.cpp index 6edc41b0..4e5f16b3 100644 --- a/Software/src/battery/MEB-BATTERY.cpp +++ b/Software/src/battery/MEB-BATTERY.cpp @@ -1,4 +1,5 @@ #include "MEB-BATTERY.h" +#include #include // For std::min and std::max #include "../communication/can/comm_can.h" #include "../communication/can/obd.h" diff --git a/Software/src/battery/MEB-BATTERY.h b/Software/src/battery/MEB-BATTERY.h index 6c2052c0..18068981 100644 --- a/Software/src/battery/MEB-BATTERY.h +++ b/Software/src/battery/MEB-BATTERY.h @@ -1,6 +1,5 @@ #ifndef MEB_BATTERY_H #define MEB_BATTERY_H -#include #include "CanBattery.h" #include "MEB-HTML.h" diff --git a/Software/src/battery/MEB-HTML.h b/Software/src/battery/MEB-HTML.h index e47a5fcc..c6cfaa83 100644 --- a/Software/src/battery/MEB-HTML.h +++ b/Software/src/battery/MEB-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class MebHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/MG-5-BATTERY.h b/Software/src/battery/MG-5-BATTERY.h index 3b4cf99b..21db48ab 100644 --- a/Software/src/battery/MG-5-BATTERY.h +++ b/Software/src/battery/MG-5-BATTERY.h @@ -1,7 +1,5 @@ #ifndef MG_5_BATTERY_H #define MG_5_BATTERY_H -#include - #include "CanBattery.h" #ifdef MG_5_BATTERY diff --git a/Software/src/battery/MG-HS-PHEV-BATTERY.h b/Software/src/battery/MG-HS-PHEV-BATTERY.h index bc51ef57..81ef6dc9 100644 --- a/Software/src/battery/MG-HS-PHEV-BATTERY.h +++ b/Software/src/battery/MG-HS-PHEV-BATTERY.h @@ -1,6 +1,5 @@ #ifndef MG_HS_PHEV_BATTERY_H #define MG_HS_PHEV_BATTERY_H -#include #include "CanBattery.h" diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 398ce59c..8b8e509a 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -747,11 +747,16 @@ void NissanLeafBattery::transmit_can(unsigned long currentMillis) { } } -bool NissanLeafBattery::is_message_corrupt(CAN_frame rx_frame) { +uint8_t NissanLeafBattery::calculate_crc(CAN_frame& rx_frame) { uint8_t crc = 0; for (uint8_t j = 0; j < 7; j++) { crc = crctable[(crc ^ static_cast(rx_frame.data.u8[j])) % 256]; } + return crc; +} + +bool NissanLeafBattery::is_message_corrupt(CAN_frame rx_frame) { + uint8_t crc = calculate_crc(rx_frame); return crc != rx_frame.data.u8[7]; } diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index 46364a74..21c9173c 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -47,6 +47,8 @@ class NissanLeafBattery : public CanBattery { BatteryHtmlRenderer& get_status_renderer() { return renderer; } static constexpr const char* Name = "Nissan LEAF battery"; + uint8_t calculate_crc(CAN_frame& frame); + private: static const int MAX_PACK_VOLTAGE_DV = 4040; //5000 = 500.0V static const int MIN_PACK_VOLTAGE_DV = 2600; diff --git a/Software/src/battery/NISSAN-LEAF-HTML.h b/Software/src/battery/NISSAN-LEAF-HTML.h index 4d21d4dd..6b7e20b1 100644 --- a/Software/src/battery/NISSAN-LEAF-HTML.h +++ b/Software/src/battery/NISSAN-LEAF-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class NissanLeafHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/ORION-BMS.h b/Software/src/battery/ORION-BMS.h index 574dc1b9..20f52481 100644 --- a/Software/src/battery/ORION-BMS.h +++ b/Software/src/battery/ORION-BMS.h @@ -1,6 +1,5 @@ #ifndef ORION_BMS_H #define ORION_BMS_H -#include #include "../system_settings.h" #include "CanBattery.h" diff --git a/Software/src/battery/PYLON-BATTERY.h b/Software/src/battery/PYLON-BATTERY.h index a3dff79a..71963e83 100644 --- a/Software/src/battery/PYLON-BATTERY.h +++ b/Software/src/battery/PYLON-BATTERY.h @@ -1,6 +1,5 @@ #ifndef PYLON_BATTERY_H #define PYLON_BATTERY_H -#include #include "../datalayer/datalayer.h" #include "CanBattery.h" diff --git a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h index 85ec3d04..45a29559 100644 --- a/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h +++ b/Software/src/battery/RANGE-ROVER-PHEV-BATTERY.h @@ -1,6 +1,5 @@ #ifndef RANGE_ROVER_PHEV_BATTERY_H #define RANGE_ROVER_PHEV_BATTERY_H -#include #include "CanBattery.h" diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 12fb991a..e9d01fea 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -1,4 +1,5 @@ #include "RENAULT-KANGOO-BATTERY.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../devboard/utils/events.h" diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index 76dc0e8b..77eb0b3f 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -1,6 +1,5 @@ #ifndef RENAULT_KANGOO_BATTERY_H #define RENAULT_KANGOO_BATTERY_H -#include #include "CanBattery.h" diff --git a/Software/src/battery/RENAULT-ZOE-GEN1-HTML.h b/Software/src/battery/RENAULT-ZOE-GEN1-HTML.h index b03c3107..ebdf17b5 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN1-HTML.h +++ b/Software/src/battery/RENAULT-ZOE-GEN1-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class RenaultZoeGen1HtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp index 19baa4eb..0483898b 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp @@ -1,4 +1,5 @@ #include "RENAULT-ZOE-GEN2-BATTERY.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" //For "More battery info" webpage diff --git a/Software/src/battery/RENAULT-ZOE-GEN2-HTML.h b/Software/src/battery/RENAULT-ZOE-GEN2-HTML.h index 023d14f8..8d4f21f9 100644 --- a/Software/src/battery/RENAULT-ZOE-GEN2-HTML.h +++ b/Software/src/battery/RENAULT-ZOE-GEN2-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class RenaultZoeGen2HtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/RJXZS-BMS.h b/Software/src/battery/RJXZS-BMS.h index 7b2b660f..50fad1e0 100644 --- a/Software/src/battery/RJXZS-BMS.h +++ b/Software/src/battery/RJXZS-BMS.h @@ -1,6 +1,5 @@ #ifndef RJXZS_BMS_H #define RJXZS_BMS_H -#include #include "../system_settings.h" #include "CanBattery.h" diff --git a/Software/src/battery/RS485Battery.h b/Software/src/battery/RS485Battery.h index 3154b9ff..72d13fb2 100644 --- a/Software/src/battery/RS485Battery.h +++ b/Software/src/battery/RS485Battery.h @@ -3,10 +3,9 @@ #include "Battery.h" -#include "src/communication/Transmitter.h" -#include "src/devboard/utils/types.h" - -#include "src/communication/rs485/comm_rs485.h" +#include "../communication/Transmitter.h" +#include "../communication/rs485/comm_rs485.h" +#include "../devboard/utils/types.h" // Abstract base class for batteries using the RS485 interface class RS485Battery : public Battery, Transmitter, Rs485Receiver { diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h index 834483a5..9e9ec2bf 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.h +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.h @@ -1,6 +1,5 @@ #ifndef SANTA_FE_PHEV_BATTERY_H #define SANTA_FE_PHEV_BATTERY_H -#include #include "../datalayer/datalayer.h" #include "CanBattery.h" diff --git a/Software/src/battery/SIMPBMS-BATTERY.h b/Software/src/battery/SIMPBMS-BATTERY.h index 85e19080..365a372f 100644 --- a/Software/src/battery/SIMPBMS-BATTERY.h +++ b/Software/src/battery/SIMPBMS-BATTERY.h @@ -1,6 +1,5 @@ #ifndef SIMPBMS_BATTERY_H #define SIMPBMS_BATTERY_H -#include #include "CanBattery.h" diff --git a/Software/src/battery/SONO-BATTERY.h b/Software/src/battery/SONO-BATTERY.h index 65d7e60b..6721a301 100644 --- a/Software/src/battery/SONO-BATTERY.h +++ b/Software/src/battery/SONO-BATTERY.h @@ -1,6 +1,5 @@ #ifndef SONO_BATTERY_H #define SONO_BATTERY_H -#include #include "CanBattery.h" diff --git a/Software/src/battery/Shunt.h b/Software/src/battery/Shunt.h index fb185041..7128e1e8 100644 --- a/Software/src/battery/Shunt.h +++ b/Software/src/battery/Shunt.h @@ -1,12 +1,14 @@ #ifndef _SHUNT_H #define _SHUNT_H -#include "USER_SETTINGS.h" -#include "src/communication/Transmitter.h" -#include "src/communication/can/CanReceiver.h" -#include "src/communication/can/comm_can.h" -#include "src/devboard/safety/safety.h" -#include "src/devboard/utils/types.h" +#include "../../USER_SETTINGS.h" +#include "../../src/communication/Transmitter.h" +#include "../../src/communication/can/CanReceiver.h" +#include "../../src/communication/can/comm_can.h" +#include "../../src/devboard/safety/safety.h" +#include "../../src/devboard/utils/types.h" + +#include enum class ShuntType { None = 0, BmwSbox = 1, Highest }; diff --git a/Software/src/battery/TESLA-HTML.h b/Software/src/battery/TESLA-HTML.h index c0ff34d8..7826b29c 100644 --- a/Software/src/battery/TESLA-HTML.h +++ b/Software/src/battery/TESLA-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class TeslaHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/TEST-FAKE-BATTERY.cpp b/Software/src/battery/TEST-FAKE-BATTERY.cpp index d2454991..eb3acd54 100644 --- a/Software/src/battery/TEST-FAKE-BATTERY.cpp +++ b/Software/src/battery/TEST-FAKE-BATTERY.cpp @@ -1,4 +1,5 @@ #include "TEST-FAKE-BATTERY.h" +#include #include "../datalayer/datalayer.h" #include "../devboard/utils/logging.h" diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.h b/Software/src/battery/VOLVO-SPA-BATTERY.h index be16549e..8c352755 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.h +++ b/Software/src/battery/VOLVO-SPA-BATTERY.h @@ -1,6 +1,5 @@ #ifndef VOLVO_SPA_BATTERY_H #define VOLVO_SPA_BATTERY_H -#include #include "CanBattery.h" #include "VOLVO-SPA-HTML.h" diff --git a/Software/src/battery/VOLVO-SPA-HTML.h b/Software/src/battery/VOLVO-SPA-HTML.h index f4726532..dd65c9a2 100644 --- a/Software/src/battery/VOLVO-SPA-HTML.h +++ b/Software/src/battery/VOLVO-SPA-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class VolvoSpaHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.h b/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.h index 1aa4c4d0..62339c0a 100644 --- a/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.h +++ b/Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.h @@ -1,7 +1,5 @@ #ifndef VOLVO_SPA_HYBRID_BATTERY_H #define VOLVO_SPA_HYBRID_BATTERY_H -#include - #include "CanBattery.h" #include "VOLVO-SPA-HYBRID-HTML.h" diff --git a/Software/src/battery/VOLVO-SPA-HYBRID-HTML.h b/Software/src/battery/VOLVO-SPA-HYBRID-HTML.h index 3c02d7cc..081b93dd 100644 --- a/Software/src/battery/VOLVO-SPA-HYBRID-HTML.h +++ b/Software/src/battery/VOLVO-SPA-HYBRID-HTML.h @@ -3,7 +3,7 @@ #include "../datalayer/datalayer.h" #include "../datalayer/datalayer_extended.h" -#include "src/devboard/webserver/BatteryHtmlRenderer.h" +#include "../devboard/webserver/BatteryHtmlRenderer.h" class VolvoSpaHybridHtmlRenderer : public BatteryHtmlRenderer { public: diff --git a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp index f00cb245..66a65894 100644 --- a/Software/src/charger/CHEVY-VOLT-CHARGER.cpp +++ b/Software/src/charger/CHEVY-VOLT-CHARGER.cpp @@ -1,4 +1,5 @@ #include "CHEVY-VOLT-CHARGER.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" diff --git a/Software/src/charger/CHEVY-VOLT-CHARGER.h b/Software/src/charger/CHEVY-VOLT-CHARGER.h index aedc40c3..2d17aa88 100644 --- a/Software/src/charger/CHEVY-VOLT-CHARGER.h +++ b/Software/src/charger/CHEVY-VOLT-CHARGER.h @@ -1,6 +1,5 @@ #ifndef CHEVYVOLT_CHARGER_H #define CHEVYVOLT_CHARGER_H -#include #include "../datalayer/datalayer.h" #include "CanCharger.h" diff --git a/Software/src/charger/CanCharger.h b/Software/src/charger/CanCharger.h index 13f94f30..2c8d76cd 100644 --- a/Software/src/charger/CanCharger.h +++ b/Software/src/charger/CanCharger.h @@ -1,13 +1,12 @@ #ifndef CAN_CHARGER_H #define CAN_CHARGER_H -#include "src/devboard/utils/types.h" - +#include "../communication/Transmitter.h" +#include "../communication/can/CanReceiver.h" +#include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" -#include "src/communication/Transmitter.h" -#include "src/communication/can/CanReceiver.h" -#include "src/communication/can/comm_can.h" -#include "src/devboard/safety/safety.h" +#include "../devboard/safety/safety.h" +#include "../devboard/utils/types.h" enum class ChargerType { None, NissanLeaf, ChevyVolt, Highest }; diff --git a/Software/src/charger/NISSAN-LEAF-CHARGER.h b/Software/src/charger/NISSAN-LEAF-CHARGER.h index 0971b333..642b2e54 100644 --- a/Software/src/charger/NISSAN-LEAF-CHARGER.h +++ b/Software/src/charger/NISSAN-LEAF-CHARGER.h @@ -1,7 +1,5 @@ #ifndef NISSANLEAF_CHARGER_H #define NISSANLEAF_CHARGER_H -#include - #include "CanCharger.h" #ifdef NISSANLEAF_CHARGER diff --git a/Software/src/communication/can/CanReceiver.h b/Software/src/communication/can/CanReceiver.h index 9737568c..4d29e59e 100644 --- a/Software/src/communication/can/CanReceiver.h +++ b/Software/src/communication/can/CanReceiver.h @@ -1,7 +1,7 @@ #ifndef _CANRECEIVER_H #define _CANRECEIVER_H -#include "src/devboard/utils/types.h" +#include "../../devboard/utils/types.h" class CanReceiver { public: diff --git a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.cpp b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.cpp index 60a17b54..de03820e 100644 --- a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.cpp +++ b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.cpp @@ -1,6 +1,7 @@ #include "comm_equipmentstopbutton.h" #include "../../devboard/hal/hal.h" #include "../../devboard/safety/safety.h" +#include "../../devboard/utils/debounce_button.h" #include "USER_SETTINGS.h" STOP_BUTTON_BEHAVIOR equipment_stop_behavior = stop_button_default_behavior; diff --git a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h index d7104d2d..42349127 100644 --- a/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h +++ b/Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h @@ -1,8 +1,6 @@ #ifndef _COMM_EQUIPMENTSTOPBUTTON_H_ #define _COMM_EQUIPMENTSTOPBUTTON_H_ -#include "../../devboard/utils/debounce_button.h" - /** * @brief Initialization of equipment stop button * diff --git a/Software/src/communication/precharge_control/precharge_control.cpp b/Software/src/communication/precharge_control/precharge_control.cpp index 52672c92..efdf3ff9 100644 --- a/Software/src/communication/precharge_control/precharge_control.cpp +++ b/Software/src/communication/precharge_control/precharge_control.cpp @@ -1,4 +1,5 @@ #include "precharge_control.h" +#include #include "../../datalayer/datalayer.h" #include "../../datalayer/datalayer_extended.h" #include "../../devboard/hal/hal.h" diff --git a/Software/src/communication/rs485/comm_rs485.cpp b/Software/src/communication/rs485/comm_rs485.cpp index 926f9d5d..0276a5c8 100644 --- a/Software/src/communication/rs485/comm_rs485.cpp +++ b/Software/src/communication/rs485/comm_rs485.cpp @@ -1,7 +1,7 @@ #include "comm_rs485.h" +#include #include "../../devboard/hal/hal.h" -#include #include bool init_rs485() { diff --git a/Software/src/datalayer/datalayer.h b/Software/src/datalayer/datalayer.h index 08352dce..2598999d 100644 --- a/Software/src/datalayer/datalayer.h +++ b/Software/src/datalayer/datalayer.h @@ -5,7 +5,7 @@ #include "../devboard/utils/types.h" #include "../system_settings.h" -typedef struct { +struct DATALAYER_BATTERY_INFO_TYPE { /** uint32_t */ /** Total energy capacity in Watt-hours */ uint32_t total_capacity_Wh = BATTERY_WH_MAX; @@ -30,9 +30,9 @@ typedef struct { /** Other */ /** Chemistry of the pack. NCA, NMC or LFP (so far) */ battery_chemistry_enum chemistry = battery_chemistry_enum::NCA; -} DATALAYER_BATTERY_INFO_TYPE; +}; -typedef struct { +struct DATALAYER_BATTERY_STATUS_TYPE { /** int32_t */ /** Instantaneous battery power in Watts. Calculated based on voltage_dV and current_dA */ /* Positive value = Battery Charging */ @@ -111,10 +111,9 @@ typedef struct { /** LED mode, customizable by user */ led_mode_enum led_mode = LED_MODE; +}; -} DATALAYER_BATTERY_STATUS_TYPE; - -typedef struct { +struct DATALAYER_BATTERY_SETTINGS_TYPE { /** SOC scaling setting. Set to true to use SOC scaling */ bool soc_scaling_active = BATTERY_USE_SCALED_SOC; /** Minimum percentage setting. Set this value to the lowest real SOC @@ -164,8 +163,7 @@ typedef struct { /** Sofar CAN Battery ID (0-15) used to parallel multiple packs */ uint8_t sofar_user_specified_battery_id = 0; - -} DATALAYER_BATTERY_SETTINGS_TYPE; +}; typedef struct { DATALAYER_BATTERY_INFO_TYPE info; @@ -173,7 +171,7 @@ typedef struct { DATALAYER_BATTERY_SETTINGS_TYPE settings; } DATALAYER_BATTERY_TYPE; -typedef struct { +struct DATALAYER_CHARGER_TYPE { /** Charger setpoint voltage */ float charger_setpoint_HV_VDC = 0; /** Charger setpoint current */ @@ -202,9 +200,9 @@ typedef struct { * we report the battery as missing entirely on the CAN bus. */ uint8_t CAN_charger_still_alive = CAN_STILL_ALIVE; -} DATALAYER_CHARGER_TYPE; +}; -typedef struct { +struct DATALAYER_SHUNT_TYPE { /** measured voltage in deciVolts. 4200 = 420.0 V */ uint16_t measured_voltage_dV = 0; /** measured amperage in deciAmperes. 300 = 30.0 A */ @@ -223,9 +221,9 @@ typedef struct { bool contactors_engaged = false; /** True if shunt communication ok **/ bool available = false; -} DATALAYER_SHUNT_TYPE; +}; -typedef struct { +struct DATALAYER_SYSTEM_INFO_TYPE { /** ESP32 main CPU temperature, for displaying on webserver and for safeties */ float CPU_temperature = 0; /** array with type of battery used, for displaying on webserver */ @@ -249,10 +247,9 @@ typedef struct { bool can_2515_send_fail = false; /** uint16_t, MCP2518 CANFD failed to send flag */ bool can_2518_send_fail = false; +}; -} DATALAYER_SYSTEM_INFO_TYPE; - -typedef struct { +struct DATALAYER_SYSTEM_STATUS_TYPE { /** Millis rollover count. Increments every 49.7 days. Used for keeping track on events */ uint8_t millisrolloverCount = 0; #ifdef FUNCTION_TIME_MEASUREMENT @@ -324,18 +321,18 @@ typedef struct { /** State of automatic precharge sequence */ PrechargeState precharge_status = AUTO_PRECHARGE_IDLE; -} DATALAYER_SYSTEM_STATUS_TYPE; +}; -typedef struct { +struct DATALAYER_SYSTEM_SETTINGS_TYPE { bool equipment_stop_active = false; bool start_precharging = false; -} DATALAYER_SYSTEM_SETTINGS_TYPE; +}; -typedef struct { +struct DATALAYER_SYSTEM_TYPE { DATALAYER_SYSTEM_INFO_TYPE info; DATALAYER_SYSTEM_STATUS_TYPE status; DATALAYER_SYSTEM_SETTINGS_TYPE settings; -} DATALAYER_SYSTEM_TYPE; +}; class DataLayer { public: diff --git a/Software/src/datalayer/datalayer_extended.h b/Software/src/datalayer/datalayer_extended.h index d4ad098e..e6f164b9 100644 --- a/Software/src/datalayer/datalayer_extended.h +++ b/Software/src/datalayer/datalayer_extended.h @@ -4,7 +4,7 @@ #include #include "../../USER_SETTINGS.h" -typedef struct { +struct DATALAYER_INFO_BOLTAMPERA { /** uint16_t */ /** PID polling parameters */ uint16_t battery_5V_ref = 0; @@ -38,9 +38,9 @@ typedef struct { uint16_t battery_HVIL = 0; uint16_t battery_HVIL_status = 0; int16_t battery_current_7E4 = 0; -} DATALAYER_INFO_BOLTAMPERA; +}; -typedef struct { +struct DATALAYER_INFO_BMWPHEV { /** uint8_t */ /** Status isolation external, 0 not evaluated, 1 OK, 2 error active, 3 Invalid signal*/ uint8_t ST_iso_ext = 0; @@ -93,10 +93,9 @@ typedef struct { int32_t iso_safety_trg_plausible = 0; int32_t iso_safety_kohm = 0; //STAT_R_ISO_ROH_01_WERT int32_t iso_safety_kohm_quality = 0; //STAT_R_ISO_ROH_QAL_01_INFO Quality of measurement 0-21 (higher better) +}; -} DATALAYER_INFO_BMWPHEV; - -typedef struct { +struct DATALAYER_INFO_BYDATTO3 { /** bool */ /** User requesting crash reset via WebUI*/ bool UserRequestCrashReset = false; @@ -136,9 +135,9 @@ typedef struct { uint8_t unknown11 = 0; uint8_t unknown12 = 0; uint8_t unknown13 = 0; -} DATALAYER_INFO_BYDATTO3; +}; -typedef struct { +struct DATALAYER_INFO_CELLPOWER { /** bool */ /** All values either True or false */ bool system_state_discharge = false; @@ -202,9 +201,9 @@ typedef struct { bool warning_Low_SOC = false; bool warning_Balancing_required_OCV_model = false; bool warning_Charger_not_responding = false; -} DATALAYER_INFO_CELLPOWER; +}; -typedef struct { +struct DATALAYER_INFO_CHADEMO { bool UserRequestRestart = false; bool UserRequestStop = false; bool FaultBatteryVoltageDeviation = false; @@ -214,10 +213,9 @@ typedef struct { bool FaultBatteryOverVoltage = false; uint8_t CHADEMO_Status = 0; uint8_t ControlProtocolNumberEV = 0; +}; -} DATALAYER_INFO_CHADEMO; - -typedef struct { +struct DATALAYER_INFO_CMFAEV { uint16_t soc_z = 0; uint16_t soc_u = 0; uint16_t soh_average = 0; @@ -235,9 +233,9 @@ typedef struct { uint64_t cumulative_energy_when_discharging = 0; uint64_t cumulative_energy_when_charging = 0; uint64_t cumulative_energy_in_regen = 0; -} DATALAYER_INFO_CMFAEV; +}; -typedef struct { +struct DATALAYER_INFO_ECMP { uint8_t MainConnectorState = 0; uint16_t InsulationResistance = 0; uint8_t InsulationDiag = 0; @@ -312,9 +310,9 @@ typedef struct { uint32_t pid_time_spent_over_55c = 0; uint32_t pid_contactor_closing_counter = 0; uint32_t pid_date_of_manufacture = 0; -} DATALAYER_INFO_ECMP; +}; -typedef struct { +struct DATALAYER_INFO_GEELY_GEOMETRY_C { /** uint8_t */ /** Battery software/hardware/serial versions, stores raw HEX values for ASCII chars */ uint8_t BatterySoftwareVersion[16] = {0}; @@ -339,9 +337,9 @@ typedef struct { uint16_t capModMin = 0; uint16_t unknown7 = 0; uint16_t unknown8 = 0; -} DATALAYER_INFO_GEELY_GEOMETRY_C; +}; -typedef struct { +struct DATALAYER_INFO_KIAHYUNDAI64 { uint8_t total_cell_count = 0; int16_t battery_12V = 0; uint8_t waterleakageSensor = 0; @@ -350,9 +348,9 @@ typedef struct { uint8_t batteryManagementMode = 0; uint8_t BMS_ign = 0; uint8_t batteryRelay = 0; -} DATALAYER_INFO_KIAHYUNDAI64; +}; -typedef struct { +struct DATALAYER_INFO_TESLA { /** uint8_t */ /** Contactor status */ //uint8_t status_contactor = 0; @@ -584,9 +582,9 @@ typedef struct { uint8_t HVP_shuntAuxCurrentStatus = 0; uint8_t HVP_shuntBarTempStatus = 0; uint8_t HVP_shuntAsicTempStatus = 0; -} DATALAYER_INFO_TESLA; +}; -typedef struct { +struct DATALAYER_INFO_NISSAN_LEAF { /** uint8_t */ /** Battery info, stores raw HEX values for ASCII chars */ uint8_t BatterySerialNumber[15] = {0}; @@ -652,10 +650,9 @@ typedef struct { /** uint32_t */ /** Solution for crypto challenge, LSBs */ uint32_t SolvedChallengeLSB = 0; +}; -} DATALAYER_INFO_NISSAN_LEAF; - -typedef struct { +struct DATALAYER_INFO_MEB { /** uint8_t */ /** Service disconnect switch status */ bool SDSW = 0; @@ -740,9 +737,9 @@ typedef struct { uint16_t celltemperature_dC[56] = {0}; uint16_t battery_temperature_dC = 0; uint8_t BMS_welded_contactors_status = 0; -} DATALAYER_INFO_MEB; +}; -typedef struct { +struct DATALAYER_INFO_VOLVO_POLESTAR { uint16_t soc_bms = 0; uint16_t soc_calc = 0; uint16_t soc_rescaled = 0; @@ -769,10 +766,9 @@ typedef struct { bool UserRequestDTCreadout = false; /** User requesting BECM reset via WebUI*/ bool UserRequestBECMecuReset = false; +}; -} DATALAYER_INFO_VOLVO_POLESTAR; - -typedef struct { +struct DATALAYER_INFO_VOLVO_HYBRID { uint16_t soc_bms = 0; uint16_t soc_calc = 0; uint16_t soc_rescaled = 0; @@ -799,10 +795,9 @@ typedef struct { bool UserRequestDTCreadout = false; /** User requesting BECM reset via WebUI*/ bool UserRequestBECMecuReset = false; +}; -} DATALAYER_INFO_VOLVO_HYBRID; - -typedef struct { +struct DATALAYER_INFO_ZOE { /** uint8_t */ uint8_t CUV = 0; uint8_t HVBIR = 0; @@ -814,9 +809,9 @@ typedef struct { uint8_t COV = 0; uint16_t mileage_km = 0; uint16_t alltime_kWh = 0; -} DATALAYER_INFO_ZOE; +}; -typedef struct { +struct DATALAYER_INFO_ZOE_PH2 { /** User requesting NVROL reset via WebUI*/ bool UserRequestNVROLReset = false; /** uint16_t */ @@ -861,7 +856,7 @@ typedef struct { uint16_t battery_pack_time = 0; uint16_t battery_soc_min = 0; uint16_t battery_soc_max = 0; -} DATALAYER_INFO_ZOE_PH2; +}; class DataLayerExtended { public: diff --git a/Software/src/devboard/hal/hal.cpp b/Software/src/devboard/hal/hal.cpp index bdceb56b..2d6c38ae 100644 --- a/Software/src/devboard/hal/hal.cpp +++ b/Software/src/devboard/hal/hal.cpp @@ -2,6 +2,7 @@ #include "../../../USER_SETTINGS.h" +#include #include "hw_3LB.h" #include "hw_devkit.h" #include "hw_lilygo.h" @@ -23,8 +24,6 @@ void init_hal() { #endif } -unsigned long millis(); - bool Esp32Hal::system_booted_up() { return milliseconds(millis()) > BOOTUP_TIME(); } diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index 32f99cec..71c9741e 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -1,4 +1,5 @@ #include "events.h" +#include #include "../../../USER_SETTINGS.h" #include "../../datalayer/datalayer.h" #include "../../devboard/hal/hal.h" diff --git a/Software/src/devboard/utils/events.h b/Software/src/devboard/utils/events.h index 2433b6f4..506e244b 100644 --- a/Software/src/devboard/utils/events.h +++ b/Software/src/devboard/utils/events.h @@ -2,8 +2,8 @@ #define __EVENTS_H__ #include -#include #include +#include "types.h" #define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_STRING(STRING) #STRING, diff --git a/Software/src/devboard/utils/logging.h b/Software/src/devboard/utils/logging.h index dcc53340..9ef7e3ca 100644 --- a/Software/src/devboard/utils/logging.h +++ b/Software/src/devboard/utils/logging.h @@ -1,8 +1,8 @@ #ifndef __LOGGING_H__ #define __LOGGING_H__ +#include #include -#include "Print.h" #include "types.h" class Logging : public Print { diff --git a/Software/src/inverter/BYD-MODBUS.cpp b/Software/src/inverter/BYD-MODBUS.cpp index b8c15922..980d4b78 100644 --- a/Software/src/inverter/BYD-MODBUS.cpp +++ b/Software/src/inverter/BYD-MODBUS.cpp @@ -2,6 +2,7 @@ #include "../datalayer/datalayer.h" #include "../devboard/hal/hal.h" #include "../devboard/utils/events.h" +#include "../lib/eModbus-eModbus/RTUutils.h" #include "../lib/eModbus-eModbus/scripts/mbServerFCs.h" // For modbus register definitions, see https://gitlab.com/pelle8/inverter_resources/-/blob/main/byd_registers_modbus_rtu.md @@ -149,8 +150,10 @@ bool BydModbusInverter::setup(void) { // Performs one time setup at startup ove // Init Static data to the RTU Modbus handle_static_data(); +#if HAS_FREERTOS // Init Serial2 connected to the RTU Modbus RTUutils::prepareHardwareSerial(Serial2); +#endif auto rx_pin = esp32hal->RS485_RX_PIN(); auto tx_pin = esp32hal->RS485_TX_PIN(); @@ -160,14 +163,16 @@ bool BydModbusInverter::setup(void) { // Performs one time setup at startup ove } Serial2.begin(9600, SERIAL_8N1, rx_pin, tx_pin); +#if HAS_FREERTOS // Register served function code worker for server - MBserver.registerWorker(MBTCP_ID, READ_HOLD_REGISTER, &FC03); - MBserver.registerWorker(MBTCP_ID, WRITE_HOLD_REGISTER, &FC06); - MBserver.registerWorker(MBTCP_ID, WRITE_MULT_REGISTERS, &FC16); - MBserver.registerWorker(MBTCP_ID, R_W_MULT_REGISTERS, &FC23); + MBserver->registerWorker(MBTCP_ID, READ_HOLD_REGISTER, &FC03); + MBserver->registerWorker(MBTCP_ID, WRITE_HOLD_REGISTER, &FC06); + MBserver->registerWorker(MBTCP_ID, WRITE_MULT_REGISTERS, &FC16); + MBserver->registerWorker(MBTCP_ID, R_W_MULT_REGISTERS, &FC23); // Start ModbusRTU background task - MBserver.begin(Serial2, esp32hal->MODBUS_CORE()); + ((ModbusServerRTU*)MBserver)->begin(Serial2, esp32hal->MODBUS_CORE()); +#endif return true; } diff --git a/Software/src/inverter/CanInverterProtocol.h b/Software/src/inverter/CanInverterProtocol.h index 0a47488f..3c9585d5 100644 --- a/Software/src/inverter/CanInverterProtocol.h +++ b/Software/src/inverter/CanInverterProtocol.h @@ -1,14 +1,14 @@ #ifndef CANINVERTER_PROTOCOL_H #define CANINVERTER_PROTOCOL_H +#include "../../USER_SETTINGS.h" #include "InverterProtocol.h" -#include "USER_SETTINGS.h" -#include "src/communication/Transmitter.h" -#include "src/communication/can/CanReceiver.h" -#include "src/communication/can/comm_can.h" -#include "src/devboard/safety/safety.h" -#include "src/devboard/utils/types.h" +#include "../communication/Transmitter.h" +#include "../communication/can/CanReceiver.h" +#include "../communication/can/comm_can.h" +#include "../devboard/safety/safety.h" +#include "../devboard/utils/types.h" class CanInverterProtocol : public InverterProtocol, Transmitter, CanReceiver { public: diff --git a/Software/src/inverter/KOSTAL-RS485.cpp b/Software/src/inverter/KOSTAL-RS485.cpp index 518ba4cf..233ba517 100644 --- a/Software/src/inverter/KOSTAL-RS485.cpp +++ b/Software/src/inverter/KOSTAL-RS485.cpp @@ -4,7 +4,7 @@ #include "../devboard/hal/hal.h" #include "../devboard/utils/events.h" -void KostalInverterProtocol::float2frame(byte* arr, float value, byte framepointer) { +void KostalInverterProtocol::float2frame(uint8_t* arr, float value, uint8_t framepointer) { f32b g; g.f = value; arr[framepointer] = g.b[0]; @@ -21,7 +21,7 @@ static void dbg_timestamp(void) { #endif } -static void dbg_frame(byte* frame, int len, const char* prefix) { +static void dbg_frame(uint8_t* frame, int len, const char* prefix) { dbg_timestamp(); #ifdef DEBUG_KOSTAL_RS485_DATA logging.print(prefix); @@ -58,22 +58,22 @@ static void dbg_message(const char* msg) { /* https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing#Encoding_examples */ -static void null_stuffer(byte* lfc, int len) { +static void null_stuffer(uint8_t* lfc, int len) { int last_null_byte = 0; for (int i = 0; i < len; i++) { if (lfc[i] == '\0') { - lfc[last_null_byte] = (byte)(i - last_null_byte); + lfc[last_null_byte] = (uint8_t)(i - last_null_byte); last_null_byte = i; } } } -static void send_kostal(byte* frame, int len) { +static void send_kostal(uint8_t* frame, int len) { dbg_frame(frame, len, "TX"); Serial2.write(frame, len); } -static byte calculate_kostal_crc(byte* lfc, int len) { +static uint8_t calculate_kostal_crc(byte* lfc, int len) { unsigned int sum = 0; if (lfc[0] != 0) { logging.printf("WARNING: first byte should be 0, but is 0x%02x\n", lfc[0]); @@ -81,7 +81,7 @@ static byte calculate_kostal_crc(byte* lfc, int len) { for (int i = 1; i < len; i++) { sum += lfc[i]; } - return (byte)(-sum & 0xff); + return (uint8_t)(-sum & 0xff); } bool KostalInverterProtocol::check_kostal_frame_crc(int len) { @@ -189,7 +189,7 @@ void KostalInverterProtocol::update_values() { float2frame(CYCLIC_DATA, (float)datalayer.battery.status.cell_max_voltage_mV / 1000, 46); float2frame(CYCLIC_DATA, (float)datalayer.battery.status.cell_min_voltage_mV / 1000, 50); - CYCLIC_DATA[58] = (byte)(datalayer.battery.status.reported_soc / 100); + CYCLIC_DATA[58] = (uint8_t)(datalayer.battery.status.reported_soc / 100); register_content_ok = true; @@ -260,7 +260,7 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th if (f2_startup_count < 15) { f2_startup_count++; } - byte tmpframe[64]; //copy values to prevent data manipulation during rewrite/crc calculation + uint8_t tmpframe[64]; //copy values to prevent data manipulation during rewrite/crc calculation memcpy(tmpframe, CYCLIC_DATA, 64); tmpframe[62] = calculate_kostal_crc(tmpframe, 62); null_stuffer(tmpframe, 64); @@ -269,7 +269,7 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th } if (code == 0x84a) { //Send battery info - byte tmpframe[40]; //copy values to prevent data manipulation during rewrite/crc calculation + uint8_t tmpframe[40]; //copy values to prevent data manipulation during rewrite/crc calculation memcpy(tmpframe, BATTERY_INFO, 40); tmpframe[38] = calculate_kostal_crc(tmpframe, 38); null_stuffer(tmpframe, 40); @@ -282,7 +282,7 @@ void KostalInverterProtocol::receive() // Runs as fast as possible to handle th } if (code == 0x353) { //Send battery error/status - byte tmpframe[9]; //copy values to prevent data manipulation during rewrite/crc calculation + uint8_t tmpframe[9]; //copy values to prevent data manipulation during rewrite/crc calculation memcpy(tmpframe, STATUS_FRAME, 9); tmpframe[7] = calculate_kostal_crc(tmpframe, 7); null_stuffer(tmpframe, 9); diff --git a/Software/src/inverter/KOSTAL-RS485.h b/Software/src/inverter/KOSTAL-RS485.h index 01a5cf35..a2742a36 100644 --- a/Software/src/inverter/KOSTAL-RS485.h +++ b/Software/src/inverter/KOSTAL-RS485.h @@ -1,7 +1,6 @@ #ifndef BYD_KOSTAL_RS485_H #define BYD_KOSTAL_RS485_H -#include - +#include #include "Rs485InverterProtocol.h" #ifdef BYD_KOSTAL_RS485 @@ -26,7 +25,7 @@ class KostalInverterProtocol : public Rs485InverterProtocol { private: int baud_rate() { return 57600; } - void float2frame(byte* arr, float value, byte framepointer); + void float2frame(uint8_t* arr, float value, uint8_t framepointer); bool check_kostal_frame_crc(int len); // How many value updates we can go without inverter gets reported as missing \ @@ -40,18 +39,18 @@ class KostalInverterProtocol : public Rs485InverterProtocol { uint8_t incoming_message_counter = RS485_HEALTHY; int8_t f2_startup_count = 0; - boolean B1_delay = false; + bool B1_delay = false; unsigned long B1_last_millis = 0; unsigned long currentMillis; unsigned long startupMillis = 0; unsigned long contactorMillis = 0; uint16_t rx_index = 0; - boolean RX_allow = false; + bool RX_allow = false; union f32b { float f; - byte b[4]; + uint8_t b[4]; }; // clang-format off diff --git a/Software/src/inverter/ModbusInverterProtocol.cpp b/Software/src/inverter/ModbusInverterProtocol.cpp index 60dd6259..97c64f38 100644 --- a/Software/src/inverter/ModbusInverterProtocol.cpp +++ b/Software/src/inverter/ModbusInverterProtocol.cpp @@ -1,4 +1,10 @@ #include "ModbusInverterProtocol.h" +#include "../lib/eModbus-eModbus/ModbusServerRTU.h" static const int MB_RTU_NUM_VALUES = 13100; uint16_t mbPV[MB_RTU_NUM_VALUES]; // Process variable memory + +ModbusInverterProtocol::ModbusInverterProtocol() { + mbPV = ::mbPV; + MBserver = new ModbusServerRTU(2000); +} diff --git a/Software/src/inverter/ModbusInverterProtocol.h b/Software/src/inverter/ModbusInverterProtocol.h index c3a32fe2..c77104a4 100644 --- a/Software/src/inverter/ModbusInverterProtocol.h +++ b/Software/src/inverter/ModbusInverterProtocol.h @@ -1,9 +1,9 @@ #ifndef MODBUS_INVERTER_PROTOCOL_H #define MODBUS_INVERTER_PROTOCOL_H +#include #include -#include "../lib/eModbus-eModbus/ModbusServerRTU.h" -#include "HardwareSerial.h" +#include "../lib/eModbus-eModbus/ModbusServer.h" #include "InverterProtocol.h" extern uint16_t mbPV[]; @@ -15,14 +15,14 @@ class ModbusInverterProtocol : public InverterProtocol { protected: // Create a ModbusRTU server instance with 2000ms timeout - ModbusInverterProtocol() : MBserver(2000) { mbPV = ::mbPV; } + ModbusInverterProtocol(); static const int MB_RTU_NUM_VALUES = 13100; // Modbus register file uint16_t* mbPV; - ModbusServerRTU MBserver; + ModbusServer* MBserver; }; #endif diff --git a/Software/src/inverter/Rs485InverterProtocol.h b/Software/src/inverter/Rs485InverterProtocol.h index e0928543..2b8fd196 100644 --- a/Software/src/inverter/Rs485InverterProtocol.h +++ b/Software/src/inverter/Rs485InverterProtocol.h @@ -3,7 +3,7 @@ #include "InverterProtocol.h" -#include "src/communication/rs485/comm_rs485.h" +#include "../communication/rs485/comm_rs485.h" class Rs485InverterProtocol : public InverterProtocol, Rs485Receiver { public: diff --git a/Software/src/inverter/SMA-BYD-H-CAN.h b/Software/src/inverter/SMA-BYD-H-CAN.h index afb91274..1b502201 100644 --- a/Software/src/inverter/SMA-BYD-H-CAN.h +++ b/Software/src/inverter/SMA-BYD-H-CAN.h @@ -1,8 +1,8 @@ #ifndef SMA_BYD_H_CAN_H #define SMA_BYD_H_CAN_H +#include "../devboard/hal/hal.h" #include "SmaInverterBase.h" -#include "src/devboard/hal/hal.h" #ifdef SMA_BYD_H_CAN #define SELECTED_INVERTER_CLASS SmaBydHInverter diff --git a/Software/src/inverter/SMA-BYD-HVS-CAN.h b/Software/src/inverter/SMA-BYD-HVS-CAN.h index c62ac8bf..8b050e9e 100644 --- a/Software/src/inverter/SMA-BYD-HVS-CAN.h +++ b/Software/src/inverter/SMA-BYD-HVS-CAN.h @@ -1,8 +1,8 @@ #ifndef SMA_BYD_HVS_CAN_H #define SMA_BYD_HVS_CAN_H +#include "../devboard/hal/hal.h" #include "SmaInverterBase.h" -#include "src/devboard/hal/hal.h" #ifdef SMA_BYD_HVS_CAN #define SELECTED_INVERTER_CLASS SmaBydHvsInverter diff --git a/Software/src/inverter/SMA-TRIPOWER-CAN.h b/Software/src/inverter/SMA-TRIPOWER-CAN.h index 9611ba53..09397370 100644 --- a/Software/src/inverter/SMA-TRIPOWER-CAN.h +++ b/Software/src/inverter/SMA-TRIPOWER-CAN.h @@ -1,8 +1,8 @@ #ifndef SMA_CAN_TRIPOWER_H #define SMA_CAN_TRIPOWER_H +#include "../devboard/hal/hal.h" #include "SmaInverterBase.h" -#include "src/devboard/hal/hal.h" #ifdef SMA_TRIPOWER_CAN #define SELECTED_INVERTER_CLASS SmaTripowerInverter diff --git a/Software/src/inverter/SOFAR-CAN.cpp b/Software/src/inverter/SOFAR-CAN.cpp index cac1bf65..0354b5ae 100644 --- a/Software/src/inverter/SOFAR-CAN.cpp +++ b/Software/src/inverter/SOFAR-CAN.cpp @@ -1,4 +1,6 @@ #include "SOFAR-CAN.h" +#include +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" diff --git a/Software/src/inverter/SOLAX-CAN.cpp b/Software/src/inverter/SOLAX-CAN.cpp index 386457f5..37516806 100644 --- a/Software/src/inverter/SOLAX-CAN.cpp +++ b/Software/src/inverter/SOLAX-CAN.cpp @@ -1,4 +1,5 @@ #include "SOLAX-CAN.h" +#include #include "../communication/can/comm_can.h" #include "../datalayer/datalayer.h" #include "../devboard/utils/events.h" diff --git a/Software/src/inverter/SmaInverterBase.h b/Software/src/inverter/SmaInverterBase.h index a075cf4d..7e22351c 100644 --- a/Software/src/inverter/SmaInverterBase.h +++ b/Software/src/inverter/SmaInverterBase.h @@ -1,9 +1,10 @@ #ifndef _SMA_INVERTER_BASE_H #define _SMA_INVERTER_BASE_H +#include #include "../datalayer/datalayer.h" +#include "../devboard/hal/hal.h" #include "CanInverterProtocol.h" -#include "src/devboard/hal/hal.h" class SmaInverterBase : public CanInverterProtocol { public: diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 00000000..567609b1 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 76cde93f..a46e0248 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,18 +1,99 @@ -# Include the directory with your source files -include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard ${CMAKE_SOURCE_DIR}/Software/src/devboard/utils . ) +cmake_minimum_required(VERSION 4.0) +enable_testing() -# Create a variable to store the list of test files -file(GLOB TEST_SOURCES utils/*.cpp) +# set the project name +project(UnitTests) -# Loop through each test source file and create an executable -foreach(TEST_SOURCE ${TEST_SOURCES}) - # Extract the test name without extension - get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) +# Enable ExternalProject CMake module +include(ExternalProject) +include(GoogleTest) - # Create an executable for the test - add_executable(${TEST_NAME} ${TEST_SOURCE} test_lib.cpp) +# specify the C++ standard +# At least 17 is required by Gtest +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED True) - # Apply the target_compile_definitions for the test - target_compile_definitions(${TEST_NAME} PRIVATE UNIT_TEST) +# Download and install GoogleTest +ExternalProject_Add( + gtest + URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip + PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest + # Disable install step + INSTALL_COMMAND "" +) -endforeach() +# Get GTest source and binary directories from CMake project +ExternalProject_Get_Property(gtest source_dir binary_dir) + +# Create a libgtest target to be used as a dependency by test programs +add_library(libgtest IMPORTED STATIC GLOBAL) +add_dependencies(libgtest gtest) + +# Set libgtest properties +if(WIN32) + set_target_properties(libgtest PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/lib/Debug/gtest.lib" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}") +else() + set_target_properties(libgtest PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/lib/libgtest.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}") +endif(WIN32) + +# Create a libgmock target to be used as a dependency by test programs +add_library(libgmock IMPORTED STATIC GLOBAL) +add_dependencies(libgmock gtest) + +# Set libgmock properties +if(WIN32) + set_target_properties(libgmock PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/lib/Debug/gmock.lib" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}") +else() + set_target_properties(libgmock PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/lib/libgmock.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}") +endif(WIN32) + +# I couldn't make it work with INTERFACE_INCLUDE_DIRECTORIES +include_directories("${source_dir}/googletest/include" + "${source_dir}/googlemock/include") + +include_directories(emul) + +# For eModBus +add_compile_definitions(__linux__) + +# add the executable +add_executable(tests + tests.cpp + safety_tests.cpp + battery/NissanLeafTest.cpp + ../Software/src/devboard/safety/safety.cpp + ../Software/src/devboard/hal/hal.cpp + ../Software/src/devboard/utils/events.cpp + ../Software/src/datalayer/datalayer.cpp + ../Software/src/datalayer/datalayer_extended.cpp + ../Software/src/lib/eModbus-eModbus/ModbusMessage.cpp + ../Software/src/lib/eModbus-eModbus/ModbusTypeDefs.cpp + ../Software/src/lib/eModbus-eModbus/Logging.cpp +# ../Software/src/lib/eModbus-eModbus/scripts/mbServerFCs.cpp + ../Software/USER_SETTINGS.cpp + ../Software/src/battery/BATTERIES.cpp + ../Software/src/battery/Battery.cpp + ../Software/src/battery/CanBattery.cpp + ../Software/src/battery/NISSAN-LEAF-BATTERY.cpp + ../Software/src/inverter/INVERTERS.cpp + ../Software/src/inverter/BYD-MODBUS.cpp + ../Software/src/charger/CHARGERS.cpp + emul/can.cpp + emul/time.cpp + emul/serial.cpp + ) + +target_link_libraries(tests + libgtest + libgmock +) + +gtest_discover_tests(tests) diff --git a/test/battery/NissanLeafTest.cpp b/test/battery/NissanLeafTest.cpp new file mode 100644 index 00000000..a2db6ce8 --- /dev/null +++ b/test/battery/NissanLeafTest.cpp @@ -0,0 +1,21 @@ +#include + +#include "../../Software/src/battery/NISSAN-LEAF-BATTERY.h" +#include "../../Software/src/datalayer/datalayer.h" + +TEST(NissanLeafTests, ShouldReportVoltage) { + auto battery = new NissanLeafBattery(); + battery->setup(); + + int expected_dV = 440; + + int divided = expected_dV / 5; + + CAN_frame frame = {.ID = 0x1DB, .data = {.u8 = {0, 0, (uint8_t)(divided >> 2), (uint8_t)((divided & 0xC0) << 6)}}}; + + frame.data.u8[7] = battery->calculate_crc(frame); + battery->handle_incoming_can_frame(frame); + battery->update_values(); + + EXPECT_EQ(datalayer.battery.status.voltage_dV, expected_dV); +} diff --git a/test/emul/Arduino.h b/test/emul/Arduino.h new file mode 100644 index 00000000..3196a56a --- /dev/null +++ b/test/emul/Arduino.h @@ -0,0 +1,18 @@ +#ifndef ARDUINO_H +#define ARDUINO_H + +#include + +#include "esp-hal-gpio.h" + +void pinMode(uint8_t pin, uint8_t mode); +void digitalWrite(uint8_t pin, uint8_t val); +int digitalRead(uint8_t pin); + +// Can be previously declared as a macro in stupid eModbus +#undef millis +unsigned long millis(); + +#define max(a, b) std::max(a, b) + +#endif diff --git a/test/emul/HardwareSerial.h b/test/emul/HardwareSerial.h new file mode 100644 index 00000000..3145d322 --- /dev/null +++ b/test/emul/HardwareSerial.h @@ -0,0 +1,44 @@ +#ifndef HARDWARESERIAL_H +#define HARDWARESERIAL_H + +#include +#include "Stream.h" + +enum SerialConfig { + SERIAL_5N1 = 0x8000010, + SERIAL_6N1 = 0x8000014, + SERIAL_7N1 = 0x8000018, + SERIAL_8N1 = 0x800001c, + SERIAL_5N2 = 0x8000030, + SERIAL_6N2 = 0x8000034, + SERIAL_7N2 = 0x8000038, + SERIAL_8N2 = 0x800003c, + SERIAL_5E1 = 0x8000012, + SERIAL_6E1 = 0x8000016, + SERIAL_7E1 = 0x800001a, + SERIAL_8E1 = 0x800001e, + SERIAL_5E2 = 0x8000032, + SERIAL_6E2 = 0x8000036, + SERIAL_7E2 = 0x800003a, + SERIAL_8E2 = 0x800003e, + SERIAL_5O1 = 0x8000013, + SERIAL_6O1 = 0x8000017, + SERIAL_7O1 = 0x800001b, + SERIAL_8O1 = 0x800001f, + SERIAL_5O2 = 0x8000033, + SERIAL_6O2 = 0x8000037, + SERIAL_7O2 = 0x800003b, + SERIAL_8O2 = 0x800003f +}; + +class HardwareSerial : public Stream { + public: + void begin(unsigned long baud, uint32_t config = SERIAL_8N1, int8_t rxPin = -1, int8_t txPin = -1, + bool invert = false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 120) {} +}; + +extern HardwareSerial Serial0; +extern HardwareSerial Serial1; +extern HardwareSerial Serial2; + +#endif diff --git a/test/emul/Print.h b/test/emul/Print.h new file mode 100644 index 00000000..4a4d7edc --- /dev/null +++ b/test/emul/Print.h @@ -0,0 +1,6 @@ +#ifndef PRINT_H +#define PRINT_H + +class Print {}; + +#endif diff --git a/test/emul/Stream.h b/test/emul/Stream.h new file mode 100644 index 00000000..bd9b3b5f --- /dev/null +++ b/test/emul/Stream.h @@ -0,0 +1,6 @@ +#ifndef STREAM_H +#define STREAM_H + +class Stream {}; + +#endif diff --git a/test/emul/WString.h b/test/emul/WString.h new file mode 100644 index 00000000..eb489577 --- /dev/null +++ b/test/emul/WString.h @@ -0,0 +1,91 @@ +#ifndef WSTRING_H +#define WSTRING_H + +/*#include + +class String : public std::string { +public: + String() : std::string() {} + String(uint32_t val) : std::string(std::to_string(val)) {} + String(double value, unsigned int decimalPlaces) : std::string(std::to_string(value)) {} + String(const char* str) : std::string(str) {} +}; +*/ + +#include +#include +#include +#include + +class String { + private: + std::string data; + + public: + // Constructors + String() = default; + String(const char* s) : data(s) {} + String(const std::string& s) : data(s) {} + String(const String& other) = default; + String(String&& other) = default; + + // Numeric constructors (Arduino-style) + String(uint64_t value) { data = std::to_string(value); } + String(int value) { data = std::to_string(value); } + String(unsigned int value) { data = std::to_string(value); } + String(long value) { data = std::to_string(value); } + String(unsigned long value) { data = std::to_string(value); } + String(float value) { data = std::to_string(value); } + String(double value) { data = std::to_string(value); } + + String(float value, unsigned int decimalPlaces) { + std::ostringstream oss; + oss << std::fixed << std::setprecision(decimalPlaces) << value; + data = oss.str(); + } + + // Assignment operators + String& operator=(const String& other) = default; + String& operator=(String&& other) = default; + + // Conversion operator to std::string + operator std::string() const { return data; } + + // Accessor + const std::string& str() const { return data; } + + // Concatenation + String operator+(const String& rhs) const { return String(data + rhs.data); } + + String operator+(const std::string& rhs) const { return String(data + rhs); } + + String operator+(const char* rhs) const { return String(data + std::string(rhs)); } + + // Append + String& operator+=(const String& rhs) { + data += rhs.data; + return *this; + } + + String& operator+=(const std::string& rhs) { + data += rhs; + return *this; + } + + String& operator+=(const char* rhs) { + data += rhs; + return *this; + } + + // Arduino-like methods (example) + int length() const { return static_cast(data.length()); } + const char* c_str() const { return data.c_str(); } + + // Friend functions to allow std::string + String + friend String operator+(const std::string& lhs, const String& rhs) { return String(lhs + rhs.data); } + + friend String operator+(const char* lhs, const String& rhs) { return String(std::string(lhs) + rhs.data); } + + friend std::ostream& operator<<(std::ostream& os, const String& s) { return os << s.data; } +}; +#endif diff --git a/test/emul/can.cpp b/test/emul/can.cpp new file mode 100644 index 00000000..5f87be48 --- /dev/null +++ b/test/emul/can.cpp @@ -0,0 +1,20 @@ +#include "../../Software/src/communication/Transmitter.h" +#include "../../Software/src/communication/can/comm_can.h" + +void transmit_can_frame_to_interface(CAN_frame* tx_frame, int interface) {} + +void register_can_receiver(CanReceiver* receiver, CAN_Interface interface, CAN_Speed speed) {} + +CAN_Speed change_can_speed(CAN_Interface interface, CAN_Speed speed) { + return CAN_Speed::CAN_SPEED_500KBPS; +} + +void stop_can() {} + +void restart_can() {} + +char const* getCANInterfaceName(CAN_Interface) { + return "Foobar"; +} + +void register_transmitter(Transmitter* transmitter) {} diff --git a/test/emul/esp-hal-gpio.h b/test/emul/esp-hal-gpio.h new file mode 100644 index 00000000..1eadd1f1 --- /dev/null +++ b/test/emul/esp-hal-gpio.h @@ -0,0 +1,16 @@ +#ifndef ESP_HAL_GPIO_H +#define ESP_HAL_GPIO_H + +#define LOW 0x0 +#define HIGH 0x1 + +#define INPUT 0x01 +// Changed OUTPUT from 0x02 to behave the same as Arduino pinMode(pin,OUTPUT) +// where you can read the state of pin even when it is set as OUTPUT +#define OUTPUT 0x03 + +void pinMode(uint8_t pin, uint8_t mode); +void digitalWrite(uint8_t pin, uint8_t val); +int digitalRead(uint8_t pin); + +#endif diff --git a/test/emul/serial.cpp b/test/emul/serial.cpp new file mode 100644 index 00000000..254416a4 --- /dev/null +++ b/test/emul/serial.cpp @@ -0,0 +1,5 @@ +#include "HardwareSerial.h" + +HardwareSerial Serial0; +HardwareSerial Serial1; +HardwareSerial Serial2; diff --git a/test/emul/soc/gpio_num.h b/test/emul/soc/gpio_num.h new file mode 100644 index 00000000..45cfd8e0 --- /dev/null +++ b/test/emul/soc/gpio_num.h @@ -0,0 +1,45 @@ +#pragma once + +typedef enum { + GPIO_NUM_NC = -1, /*!< Use to signal not connected to S/W */ + GPIO_NUM_0 = 0, /*!< GPIO0, input and output */ + GPIO_NUM_1 = 1, /*!< GPIO1, input and output */ + GPIO_NUM_2 = 2, /*!< GPIO2, input and output */ + GPIO_NUM_3 = 3, /*!< GPIO3, input and output */ + GPIO_NUM_4 = 4, /*!< GPIO4, input and output */ + GPIO_NUM_5 = 5, /*!< GPIO5, input and output */ + GPIO_NUM_6 = 6, /*!< GPIO6, input and output */ + GPIO_NUM_7 = 7, /*!< GPIO7, input and output */ + GPIO_NUM_8 = 8, /*!< GPIO8, input and output */ + GPIO_NUM_9 = 9, /*!< GPIO9, input and output */ + GPIO_NUM_10 = 10, /*!< GPIO10, input and output */ + GPIO_NUM_11 = 11, /*!< GPIO11, input and output */ + GPIO_NUM_12 = 12, /*!< GPIO12, input and output */ + GPIO_NUM_13 = 13, /*!< GPIO13, input and output */ + GPIO_NUM_14 = 14, /*!< GPIO14, input and output */ + GPIO_NUM_15 = 15, /*!< GPIO15, input and output */ + GPIO_NUM_16 = 16, /*!< GPIO16, input and output */ + GPIO_NUM_17 = 17, /*!< GPIO17, input and output */ + GPIO_NUM_18 = 18, /*!< GPIO18, input and output */ + GPIO_NUM_19 = 19, /*!< GPIO19, input and output */ + GPIO_NUM_20 = 20, /*!< GPIO20, input and output */ + GPIO_NUM_21 = 21, /*!< GPIO21, input and output */ + GPIO_NUM_22 = 22, /*!< GPIO22, input and output */ + GPIO_NUM_23 = 23, /*!< GPIO23, input and output */ + GPIO_NUM_25 = 25, /*!< GPIO25, input and output */ + GPIO_NUM_26 = 26, /*!< GPIO26, input and output */ + GPIO_NUM_27 = 27, /*!< GPIO27, input and output */ + GPIO_NUM_28 = 28, /*!< GPIO28, input and output */ + GPIO_NUM_29 = 29, /*!< GPIO29, input and output */ + GPIO_NUM_30 = 30, /*!< GPIO30, input and output */ + GPIO_NUM_31 = 31, /*!< GPIO31, input and output */ + GPIO_NUM_32 = 32, /*!< GPIO32, input and output */ + GPIO_NUM_33 = 33, /*!< GPIO33, input and output */ + GPIO_NUM_34 = 34, /*!< GPIO34, input mode only */ + GPIO_NUM_35 = 35, /*!< GPIO35, input mode only */ + GPIO_NUM_36 = 36, /*!< GPIO36, input mode only */ + GPIO_NUM_37 = 37, /*!< GPIO37, input mode only */ + GPIO_NUM_38 = 38, /*!< GPIO38, input mode only */ + GPIO_NUM_39 = 39, /*!< GPIO39, input mode only */ + GPIO_NUM_MAX, +} gpio_num_t; diff --git a/test/emul/time.cpp b/test/emul/time.cpp new file mode 100644 index 00000000..7e97f46e --- /dev/null +++ b/test/emul/time.cpp @@ -0,0 +1,9 @@ +#include + +unsigned long millis() { + return 0; +} + +uint64_t get_timestamp(unsigned long millis) { + return 0; +} diff --git a/test/microtest.h b/test/microtest.h deleted file mode 100644 index 6a398bae..00000000 --- a/test/microtest.h +++ /dev/null @@ -1,209 +0,0 @@ -// -// microtest.h -// -// URL: https://github.com/torpedro/microtest.h -// Author: Pedro Flemming (http://torpedro.com/) -// License: MIT License (https://github.com/torpedro/microtest.h/blob/master/LICENSE) -// Copyright (c) 2017 Pedro Flemming -// -// This is a small header-only C++ unit testing framework. -// It allows to define small unit tests with set of assertions available. -// -#ifndef __MICROTEST_H__ -#define __MICROTEST_H__ - -#include -#include -#include -#include - -//////////////// -// Assertions // -//////////////// - -#define ASSERT(cond) ASSERT_TRUE(cond); - -#define ASSERT_TRUE(cond) \ - if (!(cond)) \ - throw mt::AssertFailedException(#cond, __FILE__, __LINE__); - -#define ASSERT_FALSE(cond) \ - if (cond) \ - throw mt::AssertFailedException(#cond, __FILE__, __LINE__); - -#define ASSERT_NULL(value) ASSERT_TRUE(value == NULL); - -#define ASSERT_NOTNULL(value) ASSERT_TRUE(value != NULL); - -#define ASSERT_STREQ(a, b) \ - if (std::string(a).compare(std::string(b)) != 0) { \ - printf("%s{ info} %s", mt::yellow(), mt::def()); \ - std::cout << "Actual values: " << a << " != " << b << std::endl; \ - throw mt::AssertFailedException(#a " == " #b, __FILE__, __LINE__); \ - } - -#define ASSERT_STRNEQ(a, b) \ - if (std::string(a).compare(std::string(b)) != = 0) { \ - printf("%s{ info} %s", mt::yellow(), mt::def()); \ - std::cout << "Actual values: " << a << " == " << b << std::endl; \ - throw mt::AssertFailedException(#a " != " #b, __FILE__, __LINE__); \ - } - -#define ASSERT_EQ(a, b) \ - if (a != b) { \ - printf("%s{ info} %s", mt::yellow(), mt::def()); \ - std::cout << "Actual values: " << a << " != " << b << std::endl; \ - } \ - ASSERT(a == b); - -#define ASSERT_NEQ(a, b) \ - if (a == b) { \ - printf("%s{ info} %s", mt::yellow(), mt::def()); \ - std::cout << "Actual values: " << a << " == " << b << std::endl; \ - } \ - ASSERT(a != b); - -//////////////// -// Unit Tests // -//////////////// - -#define TEST(name) \ - void name(); \ - namespace { \ - bool __##name = mt::TestsManager::AddTest(name, #name); \ - } \ - void name() - -/////////////// -// Framework // -/////////////// - -namespace mt { - -inline const char* red() { - return "\033[1;31m"; -} - -inline const char* green() { - return "\033[0;32m"; -} - -inline const char* yellow() { - return "\033[0;33m"; -} - -inline const char* def() { - return "\033[0m"; -} - -inline void printRunning(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ running}%s %s\n", green(), def(), message); -} - -inline void printOk(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ ok}%s %s\n", green(), def(), message); -} - -inline void printFailed(const char* message, FILE* file = stdout) { - fprintf(file, "%s{ failed} %s%s\n", red(), message, def()); -} - -// Exception that is thrown when an assertion fails. -class AssertFailedException : public std::exception { - public: - AssertFailedException(std::string description, std::string filepath, int line) - : std::exception(), description_(description), filepath_(filepath), line_(line) {}; - - virtual const char* what() const throw() { return description_.c_str(); } - - inline const char* getFilepath() { return filepath_.c_str(); } - - inline int getLine() { return line_; } - - protected: - std::string description_; - std::string filepath_; - int line_; -}; - -class TestsManager { - // Note: static initialization fiasco - // http://www.parashift.com/c++-faq-lite/static-init-order.html - // http://www.parashift.com/c++-faq-lite/static-init-order-on-first-use.html - public: - struct Test { - const char* name; - void (*fn)(void); - }; - - static std::vector& tests() { - static std::vector tests_; - return tests_; - } - - // Adds a new test to the current set of tests. - // Returns false if a test with the same name already exists. - inline static bool AddTest(void (*fn)(void), const char* name) { - tests().push_back({name, fn}); - return true; - } - - // Run all tests that are registered. - // Returns the number of tests that failed. - inline static size_t RunAllTests(FILE* file = stdout) { - size_t num_failed = 0; - - for (const Test& test : tests()) { - // Run the test. - // If an AsserFailedException is thrown, the test has failed. - try { - printRunning(test.name, file); - - (*test.fn)(); - - printOk(test.name, file); - - } catch (AssertFailedException& e) { - printFailed(test.name, file); - fprintf(file, " %sAssertion failed: %s%s\n", red(), e.what(), def()); - fprintf(file, " %s%s:%d%s\n", red(), e.getFilepath(), e.getLine(), def()); - ++num_failed; - } - } - - int return_code = (num_failed > 0) ? 1 : 0; - return return_code; - } -}; - -// Class that will capture the arguments passed to the program. -class Runtime { - public: - static const std::vector& args(int argc = -1, char** argv = NULL) { - static std::vector args_; - if (argc >= 0) { - for (int i = 0; i < argc; ++i) { - args_.push_back(argv[i]); - } - } - return args_; - } -}; -} // namespace mt - -#define TEST_MAIN() \ - int main(int argc, char* argv[]) { \ - mt::Runtime::args(argc, argv); \ - \ - size_t num_failed = mt::TestsManager::RunAllTests(stdout); \ - if (num_failed == 0) { \ - fprintf(stdout, "%s{ summary} All tests succeeded!%s\n", mt::green(), mt::def()); \ - return 0; \ - } else { \ - double percentage = 100.0 * num_failed / mt::TestsManager::tests().size(); \ - fprintf(stderr, "%s{ summary} %zu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def()); \ - return -1; \ - } \ - } - -#endif // __MICROTEST_H__ diff --git a/test/safety_tests.cpp b/test/safety_tests.cpp new file mode 100644 index 00000000..d79d80a7 --- /dev/null +++ b/test/safety_tests.cpp @@ -0,0 +1,24 @@ +#include + +#include "../Software/src/datalayer/datalayer.h" +#include "../Software/src/devboard/safety/safety.h" +#include "../Software/src/devboard/utils/events.h" +#include "../Software/src/inverter/ModbusInverterProtocol.h" + +TEST(SafetyTests, ShouldSetEventWhenTemperatureTooHigh) { + init_events(); + datalayer.system.info.CPU_temperature = 82; + update_machineryprotection(); + + auto event_pointer = get_event_pointer(EVENT_CPU_OVERHEATING); + EXPECT_EQ(event_pointer->occurences, 1); +} + +TEST(SafetyTests, ShouldSetEventWhenTemperatureWayTooHigh) { + init_events(); + datalayer.system.info.CPU_temperature = 200; + update_machineryprotection(); + + auto event_pointer = get_event_pointer(EVENT_CPU_OVERHEATED); + EXPECT_EQ(event_pointer->occurences, 1); +} diff --git a/test/test_lib.cpp b/test/test_lib.cpp deleted file mode 100644 index 2114e2eb..00000000 --- a/test/test_lib.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "test_lib.h" - -#include - -MySerial Serial; - -unsigned long testlib_millis = 0; - -uint8_t bms_status = ACTIVE; - -uint8_t LEDcolor = GREEN; diff --git a/test/test_lib.h b/test/test_lib.h deleted file mode 100644 index 81a8a5e6..00000000 --- a/test/test_lib.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef __TEST_LIB_H__ -#define __TEST_LIB_H__ - -#include -#include -#include -#include - -#include "microtest.h" - -using namespace std; - -class MySerial; - -extern unsigned long testlib_millis; -extern MySerial Serial; -extern uint8_t bms_status; -extern uint8_t LEDcolor; - -/* Mock millis() */ -static inline unsigned long millis(void) { - return testlib_millis; -} - -/* Mock Serial class */ -class MySerial { - public: - size_t println(const char* s) { - return print(s, true); // Call print with newline argument true - } - - size_t print(const char* s) { - return print(s, false); // Call print with newline argument false - } - - private: - size_t print(const char* s, bool newline) { - size_t length = printf("%s", s); // Print the string without newline - if (newline) { - printf("\n"); // Add a newline if specified - length++; // Increment length to account for the added newline character - } - return length; // Return the total length printed - } -}; - -#endif diff --git a/test/tests.cpp b/test/tests.cpp new file mode 100644 index 00000000..c37b1b55 --- /dev/null +++ b/test/tests.cpp @@ -0,0 +1,16 @@ +#include +#include + +#include "../Software/src/datalayer/datalayer.h" +#include "../Software/src/devboard/safety/safety.h" +#include "../Software/src/devboard/utils/events.h" +#include "../Software/src/inverter/ModbusInverterProtocol.h" + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +void store_settings_equipment_stop(void) {} + +ModbusInverterProtocol::ModbusInverterProtocol() {} diff --git a/test/utils/events_test.cpp_ b/test/utils/events_test.cpp_ deleted file mode 100644 index 4a76ccf2..00000000 --- a/test/utils/events_test.cpp_ +++ /dev/null @@ -1,104 +0,0 @@ -// The test library must be included first! -#include "../test_lib.h" - -#include "../../Software/src/devboard/utils/timer.cpp" - - -class EEPROMClass { - public: - void begin(int s) {} - void writeUShort(int a, uint16_t d) {} - void commit(void) {} - uint16_t readUShort(int a) {} - - template - void get(int address, T &t) {} - - template - void put(int address, const T &t) {} -}; - -EEPROMClass EEPROM; - -#include "../../Software/src/devboard/utils/events.cpp" -/* Local test variables */ -bool elapsed = false; - -/* Stubs */ -void run_sequence_on_target(void) {} - -/* Helper functions */ -/* Test functions */ - -TEST(init_events_test) { - init_events(); - - for (uint8_t i = 0; i < EVENT_NOF_EVENTS; i++) { - ASSERT_EQ(events.entries[i].occurences, 0); - ASSERT_EQ(events.entries[i].data, 0); - ASSERT_EQ(events.entries[i].timestamp, 0); - } -} - -TEST(update_event_time_test) { - // Reset - testlib_millis = 0; - events.time_seconds = 0; - init_events(); - - // No delta, so time shouldn't increase - update_event_time(); - ASSERT_EQ(events.time_seconds, 0); - - // Almost time to bump the seconds - testlib_millis = 999; - update_event_time(); - ASSERT_EQ(events.time_seconds, 0); - - // millis == 1000, so we should add a second - testlib_millis = 1000; - update_event_time(); - ASSERT_EQ(events.time_seconds, 1); - - // We shouldn't add more seconds until 2000 now - testlib_millis = 1999; - update_event_time(); - ASSERT_EQ(events.time_seconds, 1); - testlib_millis = 2000; - update_event_time(); - ASSERT_EQ(events.time_seconds, 2); -} - -TEST(set_event_test) { - // Reset - init_events(); - events.time_seconds = 0; - - // Initially, the event should not have any data or occurences - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].data, 0); - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].occurences, 0); - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 0); - // Set current time and overvoltage event for cell 23 (RED color, bms_status == FAULT) - events.time_seconds = 345; - set_event(EVENT_CELL_OVER_VOLTAGE, 123); - // Ensure proper event data - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].data, 123); - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].occurences, 1); - ASSERT_EQ(events.entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345); - ASSERT_EQ(bms_status, FAULT); -} - -TEST(events_message_test) { - set_event(EVENT_DUMMY_ERROR, 0); // Set dummy event with no data - - ASSERT_STREQ("The dummy error event was set!", get_event_message_string(EVENT_DUMMY_ERROR)); -} - -TEST(events_level_test) { - init_events(); - set_event(EVENT_DUMMY_ERROR, 0); // Set dummy event with no data - - ASSERT_STREQ("ERROR", get_event_level_string(EVENT_DUMMY_ERROR)); -} - -TEST_MAIN();