This commit is contained in:
Lubos Petrovic
2020-12-27 16:32:36 +01:00
parent fbdfd1f1e3
commit fe79609660
9 changed files with 107 additions and 66 deletions

View File

@@ -878,7 +878,7 @@ String Board320_240::menuItemCaption(int16_t menuItemId, String title) {
case MENU_SDCARD: sprintf(tmpStr1, "[%d] %lluMB", SD.cardType(), SD.cardSize() / (1024 * 1024)); suffix = tmpStr1; break; case MENU_SDCARD: sprintf(tmpStr1, "[%d] %lluMB", SD.cardType(), SD.cardSize() / (1024 * 1024)); suffix = tmpStr1; break;
case MENU_SERIAL_CONSOLE: suffix = (liveData->settings.serialConsolePort == 255) ? "[off]" : "[on]"; break; case MENU_SERIAL_CONSOLE: suffix = (liveData->settings.serialConsolePort == 255) ? "[off]" : "[on]"; break;
case MENU_DEBUG_LEVEL: switch (liveData->settings.debugLevel) { case MENU_DEBUG_LEVEL: switch (liveData->settings.debugLevel) {
case 0: suffix = "[none]" ; break; case 0: suffix = "[all]" ; break;
case 1: suffix = "[comm]" ; break; case 1: suffix = "[comm]" ; break;
case 2: suffix = "[gsm]" ; break; case 2: suffix = "[gsm]" ; break;
case 3: suffix = "[sdcard]" ; break; case 3: suffix = "[sdcard]" ; break;
@@ -1049,7 +1049,7 @@ void Board320_240::menuItemClick() {
case MENU_GPRS: liveData->settings.gprsHwSerialPort = (liveData->settings.gprsHwSerialPort == 2) ? 255 : liveData->settings.gprsHwSerialPort + 1; showMenu(); return; break; case MENU_GPRS: liveData->settings.gprsHwSerialPort = (liveData->settings.gprsHwSerialPort == 2) ? 255 : liveData->settings.gprsHwSerialPort + 1; showMenu(); return; break;
case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break; case MENU_GPS: liveData->settings.gpsHwSerialPort = (liveData->settings.gpsHwSerialPort == 2) ? 255 : liveData->settings.gpsHwSerialPort + 1; showMenu(); return; break;
case MENU_SERIAL_CONSOLE: liveData->settings.serialConsolePort = (liveData->settings.serialConsolePort == 0) ? 255 : liveData->settings.serialConsolePort + 1; showMenu(); return; break; case MENU_SERIAL_CONSOLE: liveData->settings.serialConsolePort = (liveData->settings.serialConsolePort == 0) ? 255 : liveData->settings.serialConsolePort + 1; showMenu(); return; break;
case MENU_DEBUG_LEVEL: liveData->settings.debugLevel = (liveData->settings.debugLevel == 3) ? 0 : liveData->settings.debugLevel + 1; showMenu(); return; break; case MENU_DEBUG_LEVEL: liveData->settings.debugLevel = (liveData->settings.debugLevel == 3) ? 0 : liveData->settings.debugLevel + 1; syslog->setDebugLevel(liveData->settings.debugLevel); showMenu(); return; break;
// Wifi menu // Wifi menu
case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break; case MENU_WIFI_ENABLED: liveData->settings.wifiEnabled = (liveData->settings.wifiEnabled == 1) ? 0 : 1; showMenu(); return; break;
case MENU_WIFI_SSID: return; break; case MENU_WIFI_SSID: return; break;

View File

@@ -211,6 +211,8 @@ void BoardInterface::loadSettings() {
// Apply settings from flash if needed // Apply settings from flash if needed
liveData->settings = liveData->tmpSettings; liveData->settings = liveData->tmpSettings;
} }
syslog->setDebugLevel(liveData->settings.debugLevel);
} }
/** /**

View File

@@ -24,7 +24,7 @@ void CommInterface::mainLoop() {
if (ch == '\r' || ch == '\n') { if (ch == '\r' || ch == '\n') {
board->customConsoleCommand(response); board->customConsoleCommand(response);
response = response + ch; response = response + ch;
syslog->println(response); syslog->info(DEBUG_COMM, response);
executeCommand(response); executeCommand(response);
response = ""; response = "";
} else { } else {
@@ -59,8 +59,8 @@ bool CommInterface::doNextQueueCommand() {
liveData->currentAtshRequest = liveData->commandRequest; liveData->currentAtshRequest = liveData->commandRequest;
} }
syslog->print(">>> "); syslog->infoNolf(DEBUG_COMM, ">>> ");
syslog->println(liveData->commandRequest); syslog->info(DEBUG_COMM, liveData->commandRequest);
liveData->responseRowMerged = ""; liveData->responseRowMerged = "";
executeCommand(liveData->commandRequest); executeCommand(liveData->commandRequest);
liveData->commandQueueIndex++; liveData->commandQueueIndex++;
@@ -72,7 +72,7 @@ bool CommInterface::doNextQueueCommand() {
bool CommInterface::parseResponse() { bool CommInterface::parseResponse() {
// 1 frame data // 1 frame data
syslog->println(liveData->responseRow); syslog->info(DEBUG_COMM, liveData->responseRow);
// Merge frames 0:xxxx 1:yyyy 2:zzzz to single response xxxxyyyyzzzz string // Merge frames 0:xxxx 1:yyyy 2:zzzz to single response xxxxyyyyzzzz string
if (liveData->responseRow.length() >= 2 && liveData->responseRow.charAt(1) == ':') { if (liveData->responseRow.length() >= 2 && liveData->responseRow.charAt(1) == ':') {

View File

@@ -129,8 +129,8 @@ static void notifyCallback (BLERemoteCharacteristic * pBLERemoteCharacteristic,
liveDataObj->responseRow += ch; liveDataObj->responseRow += ch;
if (liveDataObj->responseRow == ">") { if (liveDataObj->responseRow == ">") {
if (liveDataObj->responseRowMerged != "") { if (liveDataObj->responseRowMerged != "") {
syslog->print("merged:"); syslog->infoNolf(DEBUG_COMM, "merged:");
syslog->println(liveDataObj->responseRowMerged); syslog->info(DEBUG_COMM, liveDataObj->responseRowMerged);
boardObj->parseRowMerged(); boardObj->parseRowMerged();
} }
liveDataObj->responseRowMerged = ""; liveDataObj->responseRowMerged = "";

View File

@@ -90,7 +90,7 @@ void CommObd2Can::mainLoop() {
delay(1); delay(1);
// apply timeout for next frames loop too // apply timeout for next frames loop too
if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) { if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) {
syslog->print("CAN execution timeout (multiframe message).\n"); syslog->info(DEBUG_COMM, "CAN execution timeout (multiframe message).");
break; break;
} }
} }
@@ -101,7 +101,7 @@ void CommObd2Can::mainLoop() {
} }
} }
if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) { if (lastDataSent != 0 && (unsigned long)(millis() - lastDataSent) > 100) {
syslog->print("CAN execution timeout. Continue with next command.\n"); syslog->info(DEBUG_COMM, "CAN execution timeout. Continue with next command.");
liveData->canSendNextAtCommand = true; liveData->canSendNextAtCommand = true;
return; return;
} }
@@ -112,8 +112,8 @@ void CommObd2Can::mainLoop() {
*/ */
void CommObd2Can::executeCommand(String cmd) { void CommObd2Can::executeCommand(String cmd) {
syslog->print("executeCommand "); syslog->infoNolf(DEBUG_COMM, "executeCommand ");
syslog->println(cmd); syslog->info(DEBUG_COMM, cmd);
if (cmd.equals("") || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection if (cmd.equals("") || cmd.startsWith("AT")) { // skip AT commands as not used by direct CAN connection
lastDataSent = 0; lastDataSent = 0;
@@ -184,17 +184,17 @@ void CommObd2Can::sendPID(const uint16_t pid, const String& cmd) {
const uint8_t sndStat = CAN->sendMsgBuf(pid, 0, 8, txBuf); // 11 bit const uint8_t sndStat = CAN->sendMsgBuf(pid, 0, 8, txBuf); // 11 bit
// uint8_t sndStat = CAN->sendMsgBuf(0x7e4, 1, 8, tmp); // 29 bit extended frame // uint8_t sndStat = CAN->sendMsgBuf(0x7e4, 1, 8, tmp); // 29 bit extended frame
if (sndStat == CAN_OK) { if (sndStat == CAN_OK) {
syslog->print("SENT "); syslog->infoNolf(DEBUG_COMM, "SENT ");
lastDataSent = millis(); lastDataSent = millis();
} else { } else {
syslog->print("Error sending PID "); syslog->infoNolf(DEBUG_COMM, "Error sending PID ");
} }
syslog->print(pid); syslog->infoNolf(DEBUG_COMM, pid);
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
sprintf(msgString, " 0x%.2X", txBuf[i]); sprintf(msgString, " 0x%.2X", txBuf[i]);
syslog->print(msgString); syslog->infoNolf(DEBUG_COMM, msgString);
} }
syslog->println(""); syslog->info(DEBUG_COMM, "");
} }
/** /**
@@ -212,16 +212,16 @@ void CommObd2Can::sendFlowControlFrame() {
const uint8_t sndStat = CAN->sendMsgBuf(lastPid, 0, 8, txBuf); // 11 bit const uint8_t sndStat = CAN->sendMsgBuf(lastPid, 0, 8, txBuf); // 11 bit
if (sndStat == CAN_OK) { if (sndStat == CAN_OK) {
syslog->print("Flow control frame sent "); syslog->infoNolf(DEBUG_COMM, "Flow control frame sent ");
} else { } else {
syslog->print("Error sending flow control frame "); syslog->infoNolf(DEBUG_COMM, "Error sending flow control frame ");
} }
syslog->print(lastPid); syslog->infoNolf(DEBUG_COMM, lastPid);
for (auto txByte : txBuf) { for (auto txByte : txBuf) {
sprintf(msgString, " 0x%.2X", txByte); sprintf(msgString, " 0x%.2X", txByte);
syslog->print(msgString); syslog->infoNolf(DEBUG_COMM, msgString);
} }
syslog->println(""); syslog->info(DEBUG_COMM, "");
} }
/** /**
@@ -232,7 +232,7 @@ uint8_t CommObd2Can::receivePID() {
if (!digitalRead(pinCanInt)) // If CAN0_INT pin is low, read receive buffer if (!digitalRead(pinCanInt)) // If CAN0_INT pin is low, read receive buffer
{ {
lastDataSent = millis(); lastDataSent = millis();
syslog->print(" CAN READ "); syslog->infoNolf(DEBUG_COMM, " CAN READ ");
CAN->readMsgBuf(&rxId, &rxLen, rxBuf); // Read data: len = data length, buf = data byte(s) CAN->readMsgBuf(&rxId, &rxLen, rxBuf); // Read data: len = data length, buf = data byte(s)
// mockupReceiveCanBuf(&rxId, &rxLen, rxBuf); // mockupReceiveCanBuf(&rxId, &rxLen, rxBuf);
@@ -241,22 +241,22 @@ uint8_t CommObd2Can::receivePID() {
else else
sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, rxLen); sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, rxLen);
syslog->print(msgString); syslog->infoNolf(DEBUG_COMM, msgString);
if ((rxId & 0x40000000) == 0x40000000) { // Determine if message is a remote request frame. if ((rxId & 0x40000000) == 0x40000000) { // Determine if message is a remote request frame.
sprintf(msgString, " REMOTE REQUEST FRAME"); sprintf(msgString, " REMOTE REQUEST FRAME");
syslog->print(msgString); syslog->infoNolf(DEBUG_COMM, msgString);
} else { } else {
for (uint8_t i = 0; i < rxLen; i++) { for (uint8_t i = 0; i < rxLen; i++) {
sprintf(msgString, " 0x%.2X", rxBuf[i]); sprintf(msgString, " 0x%.2X", rxBuf[i]);
syslog->print(msgString); syslog->infoNolf(DEBUG_COMM, msgString);
} }
} }
// Check if this packet shall be discarded due to its length. // Check if this packet shall be discarded due to its length.
// If liveData->expectedPacketLength is set to 0, accept any length. // If liveData->expectedPacketLength is set to 0, accept any length.
if(liveData->expectedMinimalPacketLength != 0 && rxLen < liveData->expectedMinimalPacketLength) { if(liveData->expectedMinimalPacketLength != 0 && rxLen < liveData->expectedMinimalPacketLength) {
syslog->println(" [Ignored packet]"); syslog->info(DEBUG_COMM, " [Ignored packet]");
return 0xff; return 0xff;
} }
@@ -265,12 +265,12 @@ uint8_t CommObd2Can::receivePID() {
long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8; long unsigned int atsh_response = liveData->hexToDec(liveData->currentAtshRequest.substring(4), 2, false) + 8;
if(rxId != atsh_response) { if(rxId != atsh_response) {
syslog->println(" [Filtered packet]"); syslog->info(DEBUG_COMM, " [Filtered packet]");
return 0xff; return 0xff;
} }
} }
syslog->println(); syslog->info(DEBUG_COMM, "");
processFrameBytes(); processFrameBytes();
//processFrame(); //processFrame();
} else { } else {
@@ -287,11 +287,11 @@ static void printHexBuffer(uint8_t* pData, const uint16_t length, const bool bAd
for (uint8_t i = 0; i < length; i++) { for (uint8_t i = 0; i < length; i++) {
sprintf(str, " 0x%.2X", pData[i]); sprintf(str, " 0x%.2X", pData[i]);
syslog->print(str); syslog->infoNolf(DEBUG_COMM, str);
} }
if (bAddNewLine) { if (bAddNewLine) {
syslog->println(); syslog->info(DEBUG_COMM, "");
} }
} }
@@ -407,7 +407,8 @@ bool CommObd2Can::processFrameBytes() {
break; break;
default: default:
syslog->print("Unknown frame type within CommObd2Can::processFrameBytes(): "); syslog->println((uint8_t)frameType); syslog->infoNolf(DEBUG_COMM, "Unknown frame type within CommObd2Can::processFrameBytes(): ");
syslog->info(DEBUG_COMM, (uint8_t)frameType);
return false; return false;
break; break;
} // \switch (frameType) } // \switch (frameType)
@@ -467,11 +468,11 @@ bool CommObd2Can::processFrame() {
break; break;
} }
syslog->print("> frametype:"); syslog->infoNolf(DEBUG_COMM, "> frametype:");
syslog->print(frameType); syslog->infoNolf(DEBUG_COMM, frameType);
syslog->print(", r: "); syslog->infoNolf(DEBUG_COMM, ", r: ");
syslog->print(rxRemaining); syslog->infoNolf(DEBUG_COMM, rxRemaining);
syslog->print(" "); syslog->infoNolf(DEBUG_COMM, " ");
for (uint8_t i = start; i < rxLen; i++) { for (uint8_t i = start; i < rxLen; i++) {
sprintf(msgString, "%.2X", rxBuf[i]); sprintf(msgString, "%.2X", rxBuf[i]);
@@ -479,14 +480,14 @@ bool CommObd2Can::processFrame() {
rxRemaining--; rxRemaining--;
} }
syslog->print(", r: "); syslog->infoNolf(DEBUG_COMM, ", r: ");
syslog->print(rxRemaining); syslog->infoNolf(DEBUG_COMM, rxRemaining);
syslog->println(" "); syslog->info(DEBUG_COMM, " ");
//parseResponse(); //parseResponse();
// We need to sort frames // We need to sort frames
// 1 frame data // 1 frame data
syslog->println(liveData->responseRow); syslog->info(DEBUG_COMM, liveData->responseRow);
// Merge frames 0:xxxx 1:yyyy 2:zzzz to single response xxxxyyyyzzzz string // Merge frames 0:xxxx 1:yyyy 2:zzzz to single response xxxxyyyyzzzz string
if (liveData->responseRow.length() >= 2 && liveData->responseRow.charAt(1) == ':') { if (liveData->responseRow.length() >= 2 && liveData->responseRow.charAt(1) == ':') {
//liveData->responseRowMerged += liveData->responseRow.substring(2); //liveData->responseRowMerged += liveData->responseRow.substring(2);
@@ -494,7 +495,7 @@ bool CommObd2Can::processFrame() {
uint16_t startPos = (rowNo * 14) - ((rowNo > 0) ? 2 : 0); uint16_t startPos = (rowNo * 14) - ((rowNo > 0) ? 2 : 0);
uint16_t endPos = ((rowNo + 1) * 14) - ((rowNo > 0) ? 2 : 0); uint16_t endPos = ((rowNo + 1) * 14) - ((rowNo > 0) ? 2 : 0);
liveData->responseRowMerged = liveData->responseRowMerged.substring(0, startPos) + liveData->responseRow.substring(2) + liveData->responseRowMerged.substring(endPos); liveData->responseRowMerged = liveData->responseRowMerged.substring(0, startPos) + liveData->responseRow.substring(2) + liveData->responseRowMerged.substring(endPos);
syslog->println(liveData->responseRowMerged); syslog->info(DEBUG_COMM, liveData->responseRowMerged);
} }
// Send response to board module // Send response to board module
@@ -510,8 +511,8 @@ bool CommObd2Can::processFrame() {
processMergedResponse processMergedResponse
*/ */
void CommObd2Can::processMergedResponse() { void CommObd2Can::processMergedResponse() {
syslog->print("merged:"); syslog->infoNolf(DEBUG_COMM, "merged:");
syslog->println(liveData->responseRowMerged); syslog->info(DEBUG_COMM, liveData->responseRowMerged);
board->parseRowMerged(); board->parseRowMerged();
liveData->responseRowMerged = ""; liveData->responseRowMerged = "";
liveData->canSendNextAtCommand = true; liveData->canSendNextAtCommand = true;

View File

@@ -206,7 +206,7 @@ typedef struct {
// === settings version 6 // === settings version 6
// ================================= // =================================
byte serialConsolePort; // 255-off, 0 - hw serial (std) byte serialConsolePort; // 255-off, 0 - hw serial (std)
byte debugLevel; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard uint8_t debugLevel; // 0 - info only, 1 - debug communication (BLE/CAN), 2 - debug GSM, 3 - debug SDcard
uint16_t sdcardLogIntervalSec; // every x seconds uint16_t sdcardLogIntervalSec; // every x seconds
uint16_t gprsLogIntervalSec; // every x seconds uint16_t gprsLogIntervalSec; // every x seconds
// //

View File

@@ -6,3 +6,10 @@
LogSerial::LogSerial() : HardwareSerial(0) { LogSerial::LogSerial() : HardwareSerial(0) {
HardwareSerial::begin(115200); HardwareSerial::begin(115200);
} }
/**
* Set debug level
*/
void LogSerial::setDebugLevel(uint8_t aDebugLevel) {
debugLevel = aDebugLevel;
}

View File

@@ -5,23 +5,54 @@
// DEBUG LEVEL // DEBUG LEVEL
#define DEBUG_NONE 0 #define DEBUG_NONE 0
#define DEBUG_COMM 1 // filter comm #define DEBUG_COMM 1 // filter comm
#define DEBUG_GPS 2 // filter gps messages #define DEBUG_GSM 2 // filter gsm messages
#define DEBUG_SDCARD 3 // filter sdcard #define DEBUG_SDCARD 3 // filter sdcard
// //
class LogSerial: public HardwareSerial { class LogSerial: public HardwareSerial {
protected: protected:
uint8_t debugLevel;
public: public:
LogSerial(); LogSerial();
/*virtual void infoNolfType(String msg, uint8_t debugLevel = TYPE_NONE); //
virtual void infoType(String msg, uint8_t debugLevel = TYPE_NONE); void setDebugLevel(uint8_t aDebugLevel);
/* // info
template <class T, typename... Args> void infoNolf(String msg, uint8_t debugLevel = TYPE_NONE); template <class T, typename... Args> void info(uint8_t aDebugLevel, T msg) {
template <class T, typename... Args> void info(String msg, uint8_t debugLevel = DEBUG_ALL); if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
template <class T, typename... Args> void warnNolf(String msg, uint8_t debugLevel = DEBUG_ALL); return;
template <class T, typename... Args> void warn(String msg, uint8_t debugLevel = DEBUG_ALL); println(msg);
template <class T, typename... Args> void errNolf(String msg, uint8_t debugLevel = DEBUG_ALL); }
template <class T, typename... Args> void err(String msg, uint8_t debugLevel = DEBUG_ALL);*/ template <class T, typename... Args> void infoNolf(uint8_t aDebugLevel, T msg) {
if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
return;
print(msg);
}
// warning
template <class T, typename... Args> void warn(uint8_t aDebugLevel, T msg) {
if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
return;
print("WARN ");
println(msg);
}
template <class T, typename... Args> void warnNolf(uint8_t aDebugLevel, T msg) {
if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
return;
print("WARN ");
print(msg);
}
// error
template <class T, typename... Args> void err(uint8_t aDebugLevel, T msg) {
if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
return;
print("ERR ");
println(msg);
}
template <class T, typename... Args> void errNolf(uint8_t aDebugLevel, T msg) {
if (debugLevel != DEBUG_NONE && aDebugLevel != DEBUG_NONE && aDebugLevel != debugLevel)
return;
print("ERR ");
print(msg);
}
}; };

View File

@@ -1,16 +1,16 @@
/* /*
Project renamed from eNiroDashboard to evDash Project renamed from eNiroDashboard to evDash
Serial console commands Serial console commands
serviceUUID=xxx serviceUUID=xxx
charTxUUID=xxx charTxUUID=xxx
charRxUUID=xxx charRxUUID=xxx
wifiSsid=xxx wifiSsid=xxx
wifiPassword=xxx wifiPassword=xxx
gprsApn=xxx gprsApn=xxx
remoteApiUrl=xxx remoteApiUrl=xxx
remoteApiKey=xxx remoteApiKey=xxx
Required libraries Required libraries
- esp32 board support - esp32 board support
@@ -66,7 +66,7 @@ void setup(void) {
// Serial console // Serial console
syslog = new LogSerial(); syslog = new LogSerial();
syslog->println("\nBooting device..."); syslog->println("\nBooting device...");
// Init settings/params // Init settings/params
liveData = new LiveData(); liveData = new LiveData();
liveData->initParams(); liveData->initParams();