Add serial log levels
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <NimBLEDevice.h>
|
#include <NimBLEDevice.h>
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
static const char* BMS_ADDRESS = "a5:c2:37:2c:05:dc";
|
static const char* BMS_ADDRESS = "a5:c2:37:2c:05:dc";
|
||||||
static const char* BMS_SERVICE_UUID = "ff00";
|
static const char* BMS_SERVICE_UUID = "ff00";
|
||||||
@@ -253,14 +254,16 @@ static bool parseBasicInfo() {
|
|||||||
bmsData.temperatureF = tempF;
|
bmsData.temperatureF = tempF;
|
||||||
bmsData.valid = true;
|
bmsData.valid = true;
|
||||||
|
|
||||||
Serial.print("BMS: SOC ");
|
if (currentLogLevel >= LOG_DEBUG) {
|
||||||
Serial.print(bmsData.soc);
|
Serial.print("BMS: SOC ");
|
||||||
Serial.print("%, V ");
|
Serial.print(bmsData.soc);
|
||||||
Serial.print(bmsData.voltage);
|
Serial.print("%, V ");
|
||||||
Serial.print(", A ");
|
Serial.print(bmsData.voltage);
|
||||||
Serial.print(bmsData.current);
|
Serial.print(", A ");
|
||||||
Serial.print(", Ah ");
|
Serial.print(bmsData.current);
|
||||||
Serial.println(bmsData.remainingAh);
|
Serial.print(", Ah ");
|
||||||
|
Serial.println(bmsData.remainingAh);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -312,15 +315,17 @@ static bool parseCellVoltages() {
|
|||||||
bmsData.cellDeltaMv = (int)((maxV - minV) * 1000.0 + 0.5);
|
bmsData.cellDeltaMv = (int)((maxV - minV) * 1000.0 + 0.5);
|
||||||
bmsData.cellsValid = true;
|
bmsData.cellsValid = true;
|
||||||
|
|
||||||
Serial.print("BMS: Cells ");
|
if (currentLogLevel >= LOG_DEBUG) {
|
||||||
Serial.print(cellsReported);
|
Serial.print("BMS: Cells ");
|
||||||
Serial.print(", min ");
|
Serial.print(cellsReported);
|
||||||
Serial.print(minV, 3);
|
Serial.print(", min ");
|
||||||
Serial.print("V, max ");
|
Serial.print(minV, 3);
|
||||||
Serial.print(maxV, 3);
|
Serial.print("V, max ");
|
||||||
Serial.print("V, delta ");
|
Serial.print(maxV, 3);
|
||||||
Serial.print(bmsData.cellDeltaMv);
|
Serial.print("V, delta ");
|
||||||
Serial.println("mV");
|
Serial.print(bmsData.cellDeltaMv);
|
||||||
|
Serial.println("mV");
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
LogLevel currentLogLevel = LOG_INFO;
|
||||||
|
|
||||||
|
void setLogLevel(LogLevel level) {
|
||||||
|
currentLogLevel = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void logInfo(const String& message) {
|
||||||
|
if (currentLogLevel >= LOG_INFO) {
|
||||||
|
Serial.println(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void logDebug(const String& message) {
|
||||||
|
if (currentLogLevel >= LOG_DEBUG) {
|
||||||
|
Serial.println(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
enum LogLevel {
|
||||||
|
LOG_QUIET = 0,
|
||||||
|
LOG_INFO = 1,
|
||||||
|
LOG_DEBUG = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
extern LogLevel currentLogLevel;
|
||||||
|
|
||||||
|
void setLogLevel(LogLevel level);
|
||||||
|
void logInfo(const String& message);
|
||||||
|
void logDebug(const String& message);
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "alarms.h"
|
#include "alarms.h"
|
||||||
#include "system_status.h"
|
#include "system_status.h"
|
||||||
#include "app_config.h"
|
#include "app_config.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
HardwareSerial DashboardSerial(2);
|
HardwareSerial DashboardSerial(2);
|
||||||
@@ -303,6 +304,24 @@ void handleDebugSerial() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command == "log quiet") {
|
||||||
|
setLogLevel(LOG_QUIET);
|
||||||
|
Serial.println("OK log level quiet");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == "log info") {
|
||||||
|
setLogLevel(LOG_INFO);
|
||||||
|
Serial.println("OK log level info");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (command == "log debug") {
|
||||||
|
setLogLevel(LOG_DEBUG);
|
||||||
|
Serial.println("OK log level debug");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (command == "factory reset") {
|
if (command == "factory reset") {
|
||||||
factoryResetConfig();
|
factoryResetConfig();
|
||||||
Serial.println("OK factory reset complete");
|
Serial.println("OK factory reset complete");
|
||||||
@@ -702,6 +721,6 @@ void loop() {
|
|||||||
if (millis() - lastSensorUpdate > 5000) {
|
if (millis() - lastSensorUpdate > 5000) {
|
||||||
updateSensors();
|
updateSensors();
|
||||||
lastSensorUpdate = millis();
|
lastSensorUpdate = millis();
|
||||||
Serial.println("Sensor Update");
|
logDebug("Sensor Update");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user