mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +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 <algorithm>
|
||||
#include <map>
|
||||
#include "../../lib/pierremolinaro-acan-esp32/ACAN_ESP32.h"
|
||||
#include "../../lib/pierremolinaro-ACAN2517FD/ACAN2517FD.h"
|
||||
#include "../../lib/pierremolinaro-acan-esp32/ACAN_ESP32.h"
|
||||
#include "../../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
#include "CanReceiver.h"
|
||||
#include "USER_SETTINGS.h"
|
||||
|
@ -60,7 +60,7 @@ bool native_can_initialized = false;
|
|||
|
||||
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;
|
||||
} else {
|
||||
QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL;
|
||||
|
@ -90,8 +90,7 @@ bool init_CAN() {
|
|||
settingsespcan->mRxPin = rx_pin;
|
||||
|
||||
const uint32_t errorCode = ACAN_ESP32::can.begin(*settingsespcan);
|
||||
if (errorCode == 0)
|
||||
{
|
||||
if (errorCode == 0) {
|
||||
native_can_initialized = true;
|
||||
#ifdef DEBUG_LOG
|
||||
logging.println("Native Can ok");
|
||||
|
@ -101,8 +100,8 @@ bool init_CAN() {
|
|||
logging.println(settingsespcan->mTimeSegment1);
|
||||
logging.print("Time Segment 2: ");
|
||||
logging.println(settingsespcan->mTimeSegment2);
|
||||
logging.print ("RJW: ") ;
|
||||
logging.println (settingsespcan->mRJW) ;
|
||||
logging.print("RJW: ");
|
||||
logging.println(settingsespcan->mRJW);
|
||||
logging.print("Triple Sampling: ");
|
||||
logging.println(settingsespcan->mTripleSampling ? "yes" : "no");
|
||||
logging.print("Actual bit rate: ");
|
||||
|
@ -141,7 +140,7 @@ bool init_CAN() {
|
|||
#endif // DEBUG_LOG
|
||||
gBuffer.initWithSize(25);
|
||||
|
||||
if(rst_pin != GPIO_NUM_NC) {
|
||||
if (rst_pin != GPIO_NUM_NC) {
|
||||
pinMode(rst_pin, OUTPUT);
|
||||
digitalWrite(rst_pin, HIGH);
|
||||
delay(100);
|
||||
|
@ -326,7 +325,7 @@ void receive_frame_can_native() { // This section checks if we have a complete
|
|||
CANMessage frame;
|
||||
|
||||
if (ACAN_ESP32::can.available()) {
|
||||
if(ACAN_ESP32::can.receive(frame)){
|
||||
if (ACAN_ESP32::can.receive(frame)) {
|
||||
|
||||
CAN_frame rx_frame;
|
||||
rx_frame.ID = frame.id;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _COMM_NVM_H_
|
||||
|
||||
#include <Preferences.h>
|
||||
#include <WString.h>
|
||||
#include <limits>
|
||||
#include "../../datalayer/datalayer.h"
|
||||
#include "../../devboard/utils/events.h"
|
||||
|
|
|
@ -8,19 +8,19 @@ Esp32Hal* esp32hal = nullptr;
|
|||
|
||||
void init_hal() {
|
||||
#if defined(HW_LILYGO)
|
||||
#include "hw_lilygo.h"
|
||||
#include "hw_lilygo.h"
|
||||
esp32hal = new LilyGoHal();
|
||||
#elif defined(HW_LILYGO2CAN)
|
||||
#include "hw_lilygo2can.h"
|
||||
#include "hw_lilygo2can.h"
|
||||
esp32hal = new LilyGo2CANHal();
|
||||
#elif defined(HW_STARK)
|
||||
#include "hw_stark.h"
|
||||
#include "hw_stark.h"
|
||||
esp32hal = new StarkHal();
|
||||
#elif defined(HW_3LB)
|
||||
#include "hw_3LB.h"
|
||||
#include "hw_3LB.h"
|
||||
esp32hal = new ThreeLBHal();
|
||||
#elif defined(HW_DEVKIT)
|
||||
#include "hw_devkit.h"
|
||||
#include "hw_devkit.h"
|
||||
esp32hal = new DevKitHal();
|
||||
#else
|
||||
#error "No HW defined."
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#include <soc/gpio_num.h>
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
#include "../../../src/communication/nvm/comm_nvm.h"
|
||||
#include "../../../src/devboard/utils/events.h"
|
||||
#include "../../../src/devboard/utils/logging.h"
|
||||
#include "../../../src/devboard/utils/types.h"
|
||||
#include <src/communication/nvm/comm_nvm.h>
|
||||
|
||||
// Hardware Abstraction Layer base class.
|
||||
// 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 WIFICORE() { return 0; }
|
||||
|
||||
virtual void set_default_configuration_values(){}
|
||||
virtual void set_default_configuration_values() {}
|
||||
|
||||
template <typename... Pins>
|
||||
bool alloc_pins(const char* name, Pins... pins) {
|
||||
|
|
|
@ -9,7 +9,7 @@ class LilyGo2CANHal : public Esp32Hal {
|
|||
|
||||
virtual void set_default_configuration_values() {
|
||||
BatteryEmulatorSettingsStore settings;
|
||||
if(!settings.settingExists("CANFREQ")){
|
||||
if (!settings.settingExists("CANFREQ")) {
|
||||
settings.saveUInt("CANFREQ", 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -515,7 +515,7 @@ void init_webserver() {
|
|||
} else if (p->name() == "INVBTYPE") {
|
||||
auto type = atoi(p->value().c_str());
|
||||
settings.saveUInt("INVBTYPE", (int)type);
|
||||
} else if (p->name() == "CANFREQ"){
|
||||
} else if (p->name() == "CANFREQ") {
|
||||
auto type = atoi(p->value().c_str());
|
||||
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
|
||||
const std::string& str() const { return data; }
|
||||
|
||||
// Comparison operators
|
||||
bool operator==(const String& rhs) const { return data == rhs.data; }
|
||||
|
||||
// Concatenation
|
||||
String operator+(const String& rhs) const { return String(data + rhs.data); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue