mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-03 17:59:27 +02:00
Fixing unit tests and formatting
This commit is contained in:
parent
588c78f1d6
commit
5fae1c645d
8 changed files with 48 additions and 18 deletions
|
@ -1,8 +1,8 @@
|
||||||
#include "comm_can.h"
|
#include "comm_can.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "../../lib/pierremolinaro-acan-esp32/ACAN_ESP32.h"
|
|
||||||
#include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
#include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||||
|
#include "../../lib/pierremolinaro-acan-esp32/ACAN_ESP32.h"
|
||||||
#include "../../lib/pierremolinaro-acan2515/ACAN2515.h"
|
#include "../../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||||
#include "CanReceiver.h"
|
#include "CanReceiver.h"
|
||||||
#include "USER_SETTINGS.h"
|
#include "USER_SETTINGS.h"
|
||||||
|
@ -60,7 +60,7 @@ bool native_can_initialized = false;
|
||||||
|
|
||||||
bool init_CAN() {
|
bool init_CAN() {
|
||||||
|
|
||||||
if(user_selected_can_addon_crystal_frequency_mhz > 0){
|
if (user_selected_can_addon_crystal_frequency_mhz > 0) {
|
||||||
QUARTZ_FREQUENCY = user_selected_can_addon_crystal_frequency_mhz * 1000000UL;
|
QUARTZ_FREQUENCY = user_selected_can_addon_crystal_frequency_mhz * 1000000UL;
|
||||||
} else {
|
} else {
|
||||||
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
|
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
|
||||||
|
@ -90,8 +90,7 @@ bool init_CAN() {
|
||||||
settingsespcan->mRxPin = rx_pin;
|
settingsespcan->mRxPin = rx_pin;
|
||||||
|
|
||||||
const uint32_t errorCode = ACAN_ESP32::can.begin(*settingsespcan);
|
const uint32_t errorCode = ACAN_ESP32::can.begin(*settingsespcan);
|
||||||
if (errorCode == 0)
|
if (errorCode == 0) {
|
||||||
{
|
|
||||||
native_can_initialized = true;
|
native_can_initialized = true;
|
||||||
#ifdef DEBUG_LOG
|
#ifdef DEBUG_LOG
|
||||||
logging.println("Native Can ok");
|
logging.println("Native Can ok");
|
||||||
|
@ -101,8 +100,8 @@ bool init_CAN() {
|
||||||
logging.println(settingsespcan->mTimeSegment1);
|
logging.println(settingsespcan->mTimeSegment1);
|
||||||
logging.print("Time Segment 2: ");
|
logging.print("Time Segment 2: ");
|
||||||
logging.println(settingsespcan->mTimeSegment2);
|
logging.println(settingsespcan->mTimeSegment2);
|
||||||
logging.print ("RJW: ") ;
|
logging.print("RJW: ");
|
||||||
logging.println (settingsespcan->mRJW) ;
|
logging.println(settingsespcan->mRJW);
|
||||||
logging.print("Triple Sampling: ");
|
logging.print("Triple Sampling: ");
|
||||||
logging.println(settingsespcan->mTripleSampling ? "yes" : "no");
|
logging.println(settingsespcan->mTripleSampling ? "yes" : "no");
|
||||||
logging.print("Actual bit rate: ");
|
logging.print("Actual bit rate: ");
|
||||||
|
@ -141,7 +140,7 @@ bool init_CAN() {
|
||||||
#endif // DEBUG_LOG
|
#endif // DEBUG_LOG
|
||||||
gBuffer.initWithSize(25);
|
gBuffer.initWithSize(25);
|
||||||
|
|
||||||
if(rst_pin != GPIO_NUM_NC) {
|
if (rst_pin != GPIO_NUM_NC) {
|
||||||
pinMode(rst_pin, OUTPUT);
|
pinMode(rst_pin, OUTPUT);
|
||||||
digitalWrite(rst_pin, HIGH);
|
digitalWrite(rst_pin, HIGH);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
@ -326,7 +325,7 @@ void receive_frame_can_native() { // This section checks if we have a complete
|
||||||
CANMessage frame;
|
CANMessage frame;
|
||||||
|
|
||||||
if (ACAN_ESP32::can.available()) {
|
if (ACAN_ESP32::can.available()) {
|
||||||
if(ACAN_ESP32::can.receive(frame)){
|
if (ACAN_ESP32::can.receive(frame)) {
|
||||||
|
|
||||||
CAN_frame rx_frame;
|
CAN_frame rx_frame;
|
||||||
rx_frame.ID = frame.id;
|
rx_frame.ID = frame.id;
|
||||||
|
@ -500,4 +499,4 @@ CAN_Speed change_can_speed(CAN_Interface interface, CAN_Speed speed) {
|
||||||
ACAN_ESP32::can.begin(*settingsespcan);
|
ACAN_ESP32::can.begin(*settingsespcan);
|
||||||
}
|
}
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _COMM_NVM_H_
|
#define _COMM_NVM_H_
|
||||||
|
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
#include <WString.h>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "../../datalayer/datalayer.h"
|
#include "../../datalayer/datalayer.h"
|
||||||
#include "../../devboard/utils/events.h"
|
#include "../../devboard/utils/events.h"
|
||||||
|
|
|
@ -8,19 +8,19 @@ Esp32Hal* esp32hal = nullptr;
|
||||||
|
|
||||||
void init_hal() {
|
void init_hal() {
|
||||||
#if defined(HW_LILYGO)
|
#if defined(HW_LILYGO)
|
||||||
#include "hw_lilygo.h"
|
#include "hw_lilygo.h"
|
||||||
esp32hal = new LilyGoHal();
|
esp32hal = new LilyGoHal();
|
||||||
#elif defined(HW_LILYGO2CAN)
|
#elif defined(HW_LILYGO2CAN)
|
||||||
#include "hw_lilygo2can.h"
|
#include "hw_lilygo2can.h"
|
||||||
esp32hal = new LilyGo2CANHal();
|
esp32hal = new LilyGo2CANHal();
|
||||||
#elif defined(HW_STARK)
|
#elif defined(HW_STARK)
|
||||||
#include "hw_stark.h"
|
#include "hw_stark.h"
|
||||||
esp32hal = new StarkHal();
|
esp32hal = new StarkHal();
|
||||||
#elif defined(HW_3LB)
|
#elif defined(HW_3LB)
|
||||||
#include "hw_3LB.h"
|
#include "hw_3LB.h"
|
||||||
esp32hal = new ThreeLBHal();
|
esp32hal = new ThreeLBHal();
|
||||||
#elif defined(HW_DEVKIT)
|
#elif defined(HW_DEVKIT)
|
||||||
#include "hw_devkit.h"
|
#include "hw_devkit.h"
|
||||||
esp32hal = new DevKitHal();
|
esp32hal = new DevKitHal();
|
||||||
#else
|
#else
|
||||||
#error "No HW defined."
|
#error "No HW defined."
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
#include <soc/gpio_num.h>
|
#include <soc/gpio_num.h>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include "../../../src/communication/nvm/comm_nvm.h"
|
||||||
#include "../../../src/devboard/utils/events.h"
|
#include "../../../src/devboard/utils/events.h"
|
||||||
#include "../../../src/devboard/utils/logging.h"
|
#include "../../../src/devboard/utils/logging.h"
|
||||||
#include "../../../src/devboard/utils/types.h"
|
#include "../../../src/devboard/utils/types.h"
|
||||||
#include <src/communication/nvm/comm_nvm.h>
|
|
||||||
|
|
||||||
// Hardware Abstraction Layer base class.
|
// Hardware Abstraction Layer base class.
|
||||||
// Derive a class to define board-specific parameters such as GPIO pin numbers
|
// Derive a class to define board-specific parameters such as GPIO pin numbers
|
||||||
|
@ -25,7 +25,7 @@ class Esp32Hal {
|
||||||
virtual int MODBUS_CORE() { return 0; }
|
virtual int MODBUS_CORE() { return 0; }
|
||||||
virtual int WIFICORE() { return 0; }
|
virtual int WIFICORE() { return 0; }
|
||||||
|
|
||||||
virtual void set_default_configuration_values(){}
|
virtual void set_default_configuration_values() {}
|
||||||
|
|
||||||
template <typename... Pins>
|
template <typename... Pins>
|
||||||
bool alloc_pins(const char* name, Pins... pins) {
|
bool alloc_pins(const char* name, Pins... pins) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ class LilyGo2CANHal : public Esp32Hal {
|
||||||
|
|
||||||
virtual void set_default_configuration_values() {
|
virtual void set_default_configuration_values() {
|
||||||
BatteryEmulatorSettingsStore settings;
|
BatteryEmulatorSettingsStore settings;
|
||||||
if(!settings.settingExists("CANFREQ")){
|
if (!settings.settingExists("CANFREQ")) {
|
||||||
settings.saveUInt("CANFREQ", 16);
|
settings.saveUInt("CANFREQ", 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,7 @@ void init_webserver() {
|
||||||
} else if (p->name() == "INVBTYPE") {
|
} else if (p->name() == "INVBTYPE") {
|
||||||
auto type = atoi(p->value().c_str());
|
auto type = atoi(p->value().c_str());
|
||||||
settings.saveUInt("INVBTYPE", (int)type);
|
settings.saveUInt("INVBTYPE", (int)type);
|
||||||
} else if (p->name() == "CANFREQ"){
|
} else if (p->name() == "CANFREQ") {
|
||||||
auto type = atoi(p->value().c_str());
|
auto type = atoi(p->value().c_str());
|
||||||
settings.saveUInt("CANFREQ", type);
|
settings.saveUInt("CANFREQ", type);
|
||||||
}
|
}
|
||||||
|
|
27
test/emul/Preferences.h
Normal file
27
test/emul/Preferences.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef PREFERENCES
|
||||||
|
#define PREFERENCES
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class Preferences {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Preferences() {}
|
||||||
|
|
||||||
|
bool begin(const char *name, bool readOnly = false, const char *partition_label = NULL);
|
||||||
|
void end();
|
||||||
|
bool clear();
|
||||||
|
|
||||||
|
size_t putUInt(const char *key, uint32_t value) { return 0; }
|
||||||
|
size_t putBool(const char *key, bool value) { return 0; }
|
||||||
|
size_t putString(const char *key, const char *value) { return 0; }
|
||||||
|
size_t putString(const char *key, String value) { return 0; }
|
||||||
|
|
||||||
|
bool isKey(const char *key) { return false; }
|
||||||
|
|
||||||
|
uint32_t getUInt(const char *key, uint32_t defaultValue = 0) { return 0; }
|
||||||
|
bool getBool(const char *key, bool defaultValue = false) { return false; }
|
||||||
|
size_t getString(const char *key, char *value, size_t maxLen) { return 0; }
|
||||||
|
String getString(const char *key, String defaultValue = String()) { return String(); }
|
||||||
|
};
|
||||||
|
#endif
|
|
@ -43,6 +43,9 @@ class String {
|
||||||
// Accessor
|
// Accessor
|
||||||
const std::string& str() const { return data; }
|
const std::string& str() const { return data; }
|
||||||
|
|
||||||
|
// Comparison operators
|
||||||
|
bool operator==(const String& rhs) const { return data == rhs.data; }
|
||||||
|
|
||||||
// Concatenation
|
// Concatenation
|
||||||
String operator+(const String& rhs) const { return String(data + rhs.data); }
|
String operator+(const String& rhs) const { return String(data + rhs.data); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue