mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 01:39:30 +02:00
Make tests pass
This commit is contained in:
parent
024ff58965
commit
12cc542a42
44 changed files with 362 additions and 259 deletions
|
@ -85,11 +85,80 @@ add_executable(tests
|
|||
../Software/USER_SETTINGS.cpp
|
||||
../Software/src/battery/BATTERIES.cpp
|
||||
../Software/src/battery/Battery.cpp
|
||||
../Software/src/battery/BMW-I3-BATTERY.cpp
|
||||
../Software/src/battery/BMW-I3-HTML.cpp
|
||||
../Software/src/battery/BMW-IX-BATTERY.cpp
|
||||
../Software/src/battery/BMW-IX-HTML.cpp
|
||||
../Software/src/battery/BMW-PHEV-BATTERY.cpp
|
||||
../Software/src/battery/BMW-SBOX.cpp
|
||||
../Software/src/battery/BOLT-AMPERA-BATTERY.cpp
|
||||
../Software/src/battery/BYD-ATTO-3-BATTERY.cpp
|
||||
../Software/src/battery/CanBattery.cpp
|
||||
../Software/src/battery/CELLPOWER-BMS.cpp
|
||||
../Software/src/battery/CHADEMO-BATTERY.cpp
|
||||
../Software/src/battery/CHADEMO-SHUNTS.cpp
|
||||
../Software/src/battery/CMFA-EV-BATTERY.cpp
|
||||
../Software/src/battery/DALY-BMS.cpp
|
||||
../Software/src/battery/ECMP-BATTERY.cpp
|
||||
../Software/src/battery/FOXESS-BATTERY.cpp
|
||||
../Software/src/battery/GEELY-GEOMETRY-C-BATTERY.cpp
|
||||
../Software/src/battery/HYUNDAI-IONIQ-28-BATTERY-HTML.cpp
|
||||
../Software/src/battery/HYUNDAI-IONIQ-28-BATTERY.cpp
|
||||
../Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
|
||||
../Software/src/battery/JAGUAR-IPACE-BATTERY.cpp
|
||||
../Software/src/battery/KIA-E-GMP-BATTERY.cpp
|
||||
../Software/src/battery/KIA-E-GMP-HTML.cpp
|
||||
../Software/src/battery/KIA-64FD-BATTERY.cpp
|
||||
../Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
|
||||
../Software/src/battery/KIA-HYUNDAI-HYBRID-BATTERY.cpp
|
||||
../Software/src/battery/MEB-BATTERY.cpp
|
||||
../Software/src/battery/MG-5-BATTERY.cpp
|
||||
../Software/src/battery/MG-HS-PHEV-BATTERY.cpp
|
||||
../Software/src/battery/NISSAN-LEAF-BATTERY.cpp
|
||||
../Software/src/inverter/INVERTERS.cpp
|
||||
../Software/src/battery/ORION-BMS.cpp
|
||||
../Software/src/battery/PYLON-BATTERY.cpp
|
||||
../Software/src/battery/RANGE-ROVER-PHEV-BATTERY.cpp
|
||||
../Software/src/battery/RELION-LV-BATTERY.cpp
|
||||
../Software/src/battery/RENAULT-KANGOO-BATTERY.cpp
|
||||
../Software/src/battery/RENAULT-TWIZY.cpp
|
||||
../Software/src/battery/RENAULT-ZOE-GEN1-BATTERY.cpp
|
||||
../Software/src/battery/RENAULT-ZOE-GEN2-BATTERY.cpp
|
||||
../Software/src/battery/RJXZS-BMS.cpp
|
||||
../Software/src/battery/SAMSUNG-SDI-LV-BATTERY.cpp
|
||||
../Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
|
||||
../Software/src/battery/Shunts.cpp
|
||||
../Software/src/battery/SIMPBMS-BATTERY.cpp
|
||||
../Software/src/battery/SONO-BATTERY.cpp
|
||||
../Software/src/battery/TESLA-BATTERY.cpp
|
||||
../Software/src/battery/TEST-FAKE-BATTERY.cpp
|
||||
../Software/src/battery/VOLVO-SPA-BATTERY.cpp
|
||||
../Software/src/battery/VOLVO-SPA-HYBRID-BATTERY.cpp
|
||||
../Software/src/inverter/AFORE-CAN.cpp
|
||||
../Software/src/inverter/BYD-CAN.cpp
|
||||
../Software/src/inverter/BYD-MODBUS.cpp
|
||||
../Software/src/inverter/FERROAMP-CAN.cpp
|
||||
../Software/src/inverter/FOXESS-CAN.cpp
|
||||
../Software/src/inverter/GROWATT-HV-CAN.cpp
|
||||
../Software/src/inverter/GROWATT-LV-CAN.cpp
|
||||
../Software/src/inverter/GROWATT-WIT-CAN.cpp
|
||||
../Software/src/inverter/INVERTERS.cpp
|
||||
../Software/src/inverter/KOSTAL-RS485.cpp
|
||||
../Software/src/inverter/ModbusInverterProtocol.cpp
|
||||
../Software/src/inverter/PYLON-CAN.cpp
|
||||
../Software/src/inverter/PYLON-LV-CAN.cpp
|
||||
../Software/src/inverter/SCHNEIDER-CAN.cpp
|
||||
../Software/src/inverter/SMA-BYD-H-CAN.cpp
|
||||
../Software/src/inverter/SMA-BYD-HVS-CAN.cpp
|
||||
../Software/src/inverter/SMA-LV-CAN.cpp
|
||||
../Software/src/inverter/SMA-TRIPOWER-CAN.cpp
|
||||
../Software/src/inverter/SOFAR-CAN.cpp
|
||||
../Software/src/inverter/SOL-ARK-LV-CAN.cpp
|
||||
../Software/src/inverter/SOLAX-CAN.cpp
|
||||
../Software/src/inverter/SOLXPOW-CAN.cpp
|
||||
../Software/src/inverter/SUNGROW-CAN.cpp
|
||||
../Software/src/charger/CHARGERS.cpp
|
||||
../Software/src/charger/CHEVY-VOLT-CHARGER.cpp
|
||||
../Software/src/charger/NISSAN-LEAF-CHARGER.cpp
|
||||
emul/can.cpp
|
||||
emul/time.cpp
|
||||
emul/serial.cpp
|
||||
|
|
|
@ -15,4 +15,22 @@ int max(int a, int b) {
|
|||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
// Mock implementation for OBD
|
||||
#include "../../Software/src/communication/can/obd.h"
|
||||
void handle_obd_frame(CAN_frame& frame) {
|
||||
(void)frame;
|
||||
}
|
||||
void transmit_obd_can_frame(unsigned int address, int interface, bool canFD) {
|
||||
(void)interface;
|
||||
}
|
||||
|
||||
void start_bms_reset() {}
|
||||
|
||||
#include "../../Software/src/communication/rs485/comm_rs485.h"
|
||||
|
||||
// Mock implementation
|
||||
void register_receiver(Rs485Receiver* receiver) {
|
||||
(void)receiver; // Silence unused parameter warning
|
||||
}
|
||||
|
||||
ESPClass ESP;
|
||||
|
|
|
@ -6,15 +6,97 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "HardwareSerial.h"
|
||||
#include "Logging.h"
|
||||
#include "Print.h"
|
||||
|
||||
#include "esp-hal-gpio.h"
|
||||
|
||||
// Arduino base constants for print formatting
|
||||
constexpr int BIN = 2;
|
||||
constexpr int OCT = 8;
|
||||
constexpr int DEC = 10;
|
||||
constexpr int HEX = 16;
|
||||
// Arduino type aliases
|
||||
using byte = uint8_t;
|
||||
#define boolean bool
|
||||
// Arduino random functions
|
||||
inline long random(long max) {
|
||||
(void)max;
|
||||
return 0; // Return a predictable value for testing
|
||||
}
|
||||
|
||||
inline long random(long min, long max) {
|
||||
(void)min;
|
||||
(void)max;
|
||||
return min; // Return the minimum value for predictability
|
||||
}
|
||||
|
||||
// Also add randomSeed for completeness
|
||||
inline void randomSeed(unsigned long seed) {
|
||||
(void)seed;
|
||||
}
|
||||
|
||||
inline uint16_t word(uint8_t highByte, uint8_t lowByte) {
|
||||
return (static_cast<uint16_t>(highByte) << 8) | lowByte;
|
||||
}
|
||||
|
||||
inline uint16_t word(uint16_t w) {
|
||||
return w;
|
||||
}
|
||||
|
||||
// Bit manipulation functions
|
||||
inline uint8_t bitRead(uint8_t value, uint8_t bit) {
|
||||
return (value >> bit) & 0x01;
|
||||
}
|
||||
|
||||
inline void bitSet(uint8_t& value, uint8_t bit) {
|
||||
value |= (1UL << bit);
|
||||
}
|
||||
|
||||
inline void bitClear(uint8_t& value, uint8_t bit) {
|
||||
value &= ~(1UL << bit);
|
||||
}
|
||||
|
||||
inline void bitWrite(uint8_t& value, uint8_t bit, uint8_t bitvalue) {
|
||||
if (bitvalue) {
|
||||
bitSet(value, bit);
|
||||
} else {
|
||||
bitClear(value, bit);
|
||||
}
|
||||
}
|
||||
|
||||
// Byte extraction functions
|
||||
inline uint8_t lowByte(uint16_t w) {
|
||||
return static_cast<uint8_t>(w & 0xFF);
|
||||
}
|
||||
|
||||
inline uint8_t highByte(uint16_t w) {
|
||||
return static_cast<uint8_t>(w >> 8);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const T& min(const T& a, const T& b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline const T& max(const T& a, const T& b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
void pinMode(uint8_t pin, uint8_t mode);
|
||||
void digitalWrite(uint8_t pin, uint8_t val);
|
||||
int digitalRead(uint8_t pin);
|
||||
inline int analogRead(uint8_t pin) {
|
||||
(void)pin;
|
||||
return 0; // Return 0 for predictable tests
|
||||
}
|
||||
|
||||
unsigned long micros();
|
||||
// Can be previously declared as a macro in stupid eModbus
|
||||
|
|
|
@ -35,17 +35,28 @@ enum SerialConfig {
|
|||
|
||||
class HardwareSerial : public Stream {
|
||||
public:
|
||||
int available() { return 0; }
|
||||
// Implement ALL pure virtual functions from base classes
|
||||
int available() override { return 0; }
|
||||
int read() override { return -1; }
|
||||
int peek() override { return -1; }
|
||||
void flush() override {} // Implement flush from Print
|
||||
size_t write(uint8_t) override { return 0; } // Implement write from Print
|
||||
|
||||
// Your existing methods
|
||||
uint32_t baudRate() { return 9600; }
|
||||
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) {}
|
||||
int read() { return 0; }
|
||||
void setTxBufferSize(uint16_t size) {}
|
||||
void setRxBufferSize(uint16_t size) {}
|
||||
bool setRxFIFOFull(uint8_t fifoBytes) { return false; }
|
||||
size_t write(uint8_t) { return 0; }
|
||||
};
|
||||
|
||||
// Add the buffer write method
|
||||
size_t write(const uint8_t* buffer, size_t size) override {
|
||||
(void)buffer;
|
||||
(void)size;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
extern HardwareSerial Serial;
|
||||
extern HardwareSerial Serial1;
|
||||
extern HardwareSerial Serial2;
|
||||
|
|
|
@ -5,7 +5,7 @@ class Print {
|
|||
public:
|
||||
virtual void flush() {}
|
||||
void printf(const char* format, ...) {}
|
||||
virtual size_t write(uint8_t) = 0;
|
||||
virtual size_t write(uint8_t) { return 0; }
|
||||
virtual size_t write(const char* s) { return 0; }
|
||||
virtual size_t write(const uint8_t* buffer, size_t size) { return 0; }
|
||||
};
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
|
||||
class Stream : public Print {
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int read() = 0;
|
||||
virtual int available() { return 0; }
|
||||
virtual int read() { return -1; }
|
||||
virtual int peek() { return -1; }
|
||||
// flush() is already inherited from Print
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue