Serial.print now covered by LogSerial class
This commit is contained in:
132
Board320_240.cpp
132
Board320_240.cpp
@@ -30,7 +30,7 @@ void Board320_240::initBoard() {
|
|||||||
liveData->params.chargingStartTime = liveData->params.currentTime = mktime(&now);
|
liveData->params.chargingStartTime = liveData->params.currentTime = mktime(&now);
|
||||||
|
|
||||||
// Init display
|
// Init display
|
||||||
Serial.println("Init tft display");
|
syslog->println("Init tft display");
|
||||||
tft.begin();
|
tft.begin();
|
||||||
tft.invertDisplay(invertDisplay);
|
tft.invertDisplay(invertDisplay);
|
||||||
tft.setRotation(liveData->settings.displayRotation);
|
tft.setRotation(liveData->settings.displayRotation);
|
||||||
@@ -61,24 +61,24 @@ void Board320_240::afterSetup() {
|
|||||||
// Starting Wifi after BLE prevents reboot loop
|
// Starting Wifi after BLE prevents reboot loop
|
||||||
if (liveData->settings.wifiEnabled == 1) {
|
if (liveData->settings.wifiEnabled == 1) {
|
||||||
|
|
||||||
/*Serial.print("memReport(): MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM bytes free. ");
|
/*syslog->print("memReport(): MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM bytes free. ");
|
||||||
Serial.println(heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM));
|
syslog->println(heap_caps_get_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM));
|
||||||
|
|
||||||
Serial.println("WiFi init...");
|
syslog->println("WiFi init...");
|
||||||
WiFi.enableSTA(true);
|
WiFi.enableSTA(true);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(liveData->settings.wifiSsid, liveData->settings.wifiPassword);
|
WiFi.begin(liveData->settings.wifiSsid, liveData->settings.wifiPassword);
|
||||||
Serial.println("WiFi init completed...");*/
|
syslog->println("WiFi init completed...");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init GPS
|
// Init GPS
|
||||||
if (liveData->settings.gpsHwSerialPort <= 2) {
|
if (liveData->settings.gpsHwSerialPort <= 2) {
|
||||||
Serial.print("GPS initialization on hwUart: ");
|
syslog->print("GPS initialization on hwUart: ");
|
||||||
Serial.println(liveData->settings.gpsHwSerialPort);
|
syslog->println(liveData->settings.gpsHwSerialPort);
|
||||||
if (liveData->settings.gpsHwSerialPort == 0) {
|
if (liveData->settings.gpsHwSerialPort == 0) {
|
||||||
Serial.println("hwUart0 collision with serial console! Disabling serial console");
|
syslog->println("hwUart0 collision with serial console! Disabling serial console");
|
||||||
Serial.flush();
|
syslog->flush();
|
||||||
Serial.end();
|
syslog->end();
|
||||||
}
|
}
|
||||||
gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort);
|
gpsHwUart = new HardwareSerial(liveData->settings.gpsHwSerialPort);
|
||||||
gpsHwUart->begin(9600);
|
gpsHwUart->begin(9600);
|
||||||
@@ -87,7 +87,7 @@ void Board320_240::afterSetup() {
|
|||||||
// SD card
|
// SD card
|
||||||
if (liveData->settings.sdcardEnabled == 1) {
|
if (liveData->settings.sdcardEnabled == 1) {
|
||||||
if (sdcardMount() && liveData->settings.sdcardAutstartLog == 1) {
|
if (sdcardMount() && liveData->settings.sdcardAutstartLog == 1) {
|
||||||
Serial.println("Toggle recording on SD card");
|
syslog->println("Toggle recording on SD card");
|
||||||
sdcardToggleRecording();
|
sdcardToggleRecording();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ void Board320_240::afterSetup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init from parent class
|
// Init from parent class
|
||||||
Serial.println("BoardInterface::afterSetup");
|
syslog->println("BoardInterface::afterSetup");
|
||||||
BoardInterface::afterSetup();
|
BoardInterface::afterSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1006,12 +1006,12 @@ void Board320_240::menuItemClick() {
|
|||||||
// Exit menu, parent level menu, open item
|
// Exit menu, parent level menu, open item
|
||||||
bool showParentMenu = false;
|
bool showParentMenu = false;
|
||||||
if (liveData->menuItemSelected > 0) {
|
if (liveData->menuItemSelected > 0) {
|
||||||
Serial.println(tmpMenuItem->id);
|
syslog->println(tmpMenuItem->id);
|
||||||
// Device list
|
// Device list
|
||||||
if (tmpMenuItem->id > 10000 && tmpMenuItem->id < 10100) {
|
if (tmpMenuItem->id > 10000 && tmpMenuItem->id < 10100) {
|
||||||
strlcpy((char*)liveData->settings.obdMacAddress, (char*)tmpMenuItem->obdMacAddress, 20);
|
strlcpy((char*)liveData->settings.obdMacAddress, (char*)tmpMenuItem->obdMacAddress, 20);
|
||||||
Serial.print("Selected adapter MAC address ");
|
syslog->print("Selected adapter MAC address ");
|
||||||
Serial.println(liveData->settings.obdMacAddress);
|
syslog->println(liveData->settings.obdMacAddress);
|
||||||
saveSettings();
|
saveSettings();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
@@ -1120,7 +1120,7 @@ void Board320_240::menuItemClick() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
liveData->menuCurrent = parentMenu;
|
liveData->menuCurrent = parentMenu;
|
||||||
Serial.println(liveData->menuCurrent);
|
syslog->println(liveData->menuCurrent);
|
||||||
showMenu();
|
showMenu();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -1255,7 +1255,7 @@ void Board320_240::redrawScreen() {
|
|||||||
*/
|
*/
|
||||||
void Board320_240::loadTestData() {
|
void Board320_240::loadTestData() {
|
||||||
|
|
||||||
Serial.println("Loading test data");
|
syslog->println("Loading test data");
|
||||||
|
|
||||||
testDataMode = true; // skip lights off message
|
testDataMode = true; // skip lights off message
|
||||||
carInterface->loadTestData();
|
carInterface->loadTestData();
|
||||||
@@ -1353,18 +1353,18 @@ void Board320_240::mainLoop() {
|
|||||||
if (liveData->params.sdcardInit && liveData->params.sdcardRecording && liveData->params.sdcardCanNotify &&
|
if (liveData->params.sdcardInit && liveData->params.sdcardRecording && liveData->params.sdcardCanNotify &&
|
||||||
(liveData->params.odoKm != -1 && liveData->params.socPerc != -1)) {
|
(liveData->params.odoKm != -1 && liveData->params.socPerc != -1)) {
|
||||||
|
|
||||||
//Serial.println(&now, "%y%m%d%H%M");
|
//syslog->println(&now, "%y%m%d%H%M");
|
||||||
|
|
||||||
// create filename
|
// create filename
|
||||||
if (liveData->params.operationTimeSec > 0 && strlen(liveData->params.sdcardFilename) == 0) {
|
if (liveData->params.operationTimeSec > 0 && strlen(liveData->params.sdcardFilename) == 0) {
|
||||||
sprintf(liveData->params.sdcardFilename, "/%llu.json", uint64_t(liveData->params.operationTimeSec / 60));
|
sprintf(liveData->params.sdcardFilename, "/%llu.json", uint64_t(liveData->params.operationTimeSec / 60));
|
||||||
Serial.print("Log filename by opTimeSec: ");
|
syslog->print("Log filename by opTimeSec: ");
|
||||||
Serial.println(liveData->params.sdcardFilename);
|
syslog->println(liveData->params.sdcardFilename);
|
||||||
}
|
}
|
||||||
if (liveData->params.currTimeSyncWithGps && strlen(liveData->params.sdcardFilename) < 15) {
|
if (liveData->params.currTimeSyncWithGps && strlen(liveData->params.sdcardFilename) < 15) {
|
||||||
strftime(liveData->params.sdcardFilename, sizeof(liveData->params.sdcardFilename), "/%y%m%d%H%M.json", &now);
|
strftime(liveData->params.sdcardFilename, sizeof(liveData->params.sdcardFilename), "/%y%m%d%H%M.json", &now);
|
||||||
Serial.print("Log filename by GPS: ");
|
syslog->print("Log filename by GPS: ");
|
||||||
Serial.println(liveData->params.sdcardFilename);
|
syslog->println(liveData->params.sdcardFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// append buffer, clear buffer & notify state
|
// append buffer, clear buffer & notify state
|
||||||
@@ -1372,14 +1372,14 @@ void Board320_240::mainLoop() {
|
|||||||
liveData->params.sdcardCanNotify = false;
|
liveData->params.sdcardCanNotify = false;
|
||||||
File file = SD.open(liveData->params.sdcardFilename, FILE_APPEND);
|
File file = SD.open(liveData->params.sdcardFilename, FILE_APPEND);
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.println("Failed to open file for appending");
|
syslog->println("Failed to open file for appending");
|
||||||
File file = SD.open(liveData->params.sdcardFilename, FILE_WRITE);
|
File file = SD.open(liveData->params.sdcardFilename, FILE_WRITE);
|
||||||
}
|
}
|
||||||
if (!file) {
|
if (!file) {
|
||||||
Serial.println("Failed to create file");
|
syslog->println("Failed to create file");
|
||||||
}
|
}
|
||||||
if (file) {
|
if (file) {
|
||||||
Serial.println("Save buffer to SD card");
|
syslog->println("Save buffer to SD card");
|
||||||
serializeParamsToJson(file);
|
serializeParamsToJson(file);
|
||||||
file.print(",\n");
|
file.print(",\n");
|
||||||
file.close();
|
file.close();
|
||||||
@@ -1408,7 +1408,7 @@ bool Board320_240::skipAdapterScan() {
|
|||||||
bool Board320_240::sdcardMount() {
|
bool Board320_240::sdcardMount() {
|
||||||
|
|
||||||
if (liveData->params.sdcardInit) {
|
if (liveData->params.sdcardInit) {
|
||||||
Serial.print("SD card already mounted...");
|
syslog->print("SD card already mounted...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1416,47 +1416,47 @@ bool Board320_240::sdcardMount() {
|
|||||||
bool SdState = false;
|
bool SdState = false;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
Serial.print("Initializing SD card...");
|
syslog->print("Initializing SD card...");
|
||||||
|
|
||||||
#ifdef BOARD_TTGO_T4
|
#ifdef BOARD_TTGO_T4
|
||||||
Serial.print(" TTGO-T4 ");
|
syslog->print(" TTGO-T4 ");
|
||||||
SPIClass * hspi = new SPIClass(HSPI);
|
SPIClass * hspi = new SPIClass(HSPI);
|
||||||
spiSD.begin(pinSdcardSclk, pinSdcardMiso, pinSdcardMosi, pinSdcardCs); //SCK,MISO,MOSI,ss
|
spiSD.begin(pinSdcardSclk, pinSdcardMiso, pinSdcardMosi, pinSdcardCs); //SCK,MISO,MOSI,ss
|
||||||
SdState = SD.begin(pinSdcardCs, *hspi, SPI_FREQUENCY);
|
SdState = SD.begin(pinSdcardCs, *hspi, SPI_FREQUENCY);
|
||||||
#endif BOARD_TTGO_T4
|
#endif BOARD_TTGO_T4
|
||||||
|
|
||||||
Serial.print(" M5STACK ");
|
syslog->print(" M5STACK ");
|
||||||
SdState = SD.begin(pinSdcardCs);
|
SdState = SD.begin(pinSdcardCs);
|
||||||
|
|
||||||
if (SdState) {
|
if (SdState) {
|
||||||
|
|
||||||
uint8_t cardType = SD.cardType();
|
uint8_t cardType = SD.cardType();
|
||||||
if (cardType == CARD_NONE) {
|
if (cardType == CARD_NONE) {
|
||||||
Serial.println("No SD card attached");
|
syslog->println("No SD card attached");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("SD card found.");
|
syslog->println("SD card found.");
|
||||||
liveData->params.sdcardInit = true;
|
liveData->params.sdcardInit = true;
|
||||||
|
|
||||||
Serial.print("SD Card Type: ");
|
syslog->print("SD Card Type: ");
|
||||||
if (cardType == CARD_MMC) {
|
if (cardType == CARD_MMC) {
|
||||||
Serial.println("MMC");
|
syslog->println("MMC");
|
||||||
} else if (cardType == CARD_SD) {
|
} else if (cardType == CARD_SD) {
|
||||||
Serial.println("SDSC");
|
syslog->println("SDSC");
|
||||||
} else if (cardType == CARD_SDHC) {
|
} else if (cardType == CARD_SDHC) {
|
||||||
Serial.println("SDHC");
|
syslog->println("SDHC");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("UNKNOWN");
|
syslog->println("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
|
uint64_t cardSize = SD.cardSize() / (1024 * 1024);
|
||||||
Serial.printf("SD Card Size: %lluMB\n", cardSize);
|
syslog->printf("SD Card Size: %lluMB\n", cardSize);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Initialization failed!");
|
syslog->println("Initialization failed!");
|
||||||
countdown--;
|
countdown--;
|
||||||
if (countdown <= 0) {
|
if (countdown <= 0) {
|
||||||
break;
|
break;
|
||||||
@@ -1475,7 +1475,7 @@ void Board320_240::sdcardToggleRecording() {
|
|||||||
if (!liveData->params.sdcardInit)
|
if (!liveData->params.sdcardInit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Serial.println("Toggle SD card recording...");
|
syslog->println("Toggle SD card recording...");
|
||||||
liveData->params.sdcardRecording = !liveData->params.sdcardRecording;
|
liveData->params.sdcardRecording = !liveData->params.sdcardRecording;
|
||||||
if (liveData->params.sdcardRecording) {
|
if (liveData->params.sdcardRecording) {
|
||||||
liveData->params.sdcardCanNotify = true;
|
liveData->params.sdcardCanNotify = true;
|
||||||
@@ -1498,8 +1498,8 @@ void Board320_240::syncGPS() {
|
|||||||
}
|
}
|
||||||
if (gps.satellites.isValid()) {
|
if (gps.satellites.isValid()) {
|
||||||
liveData->params.gpsSat = gps.satellites.value();
|
liveData->params.gpsSat = gps.satellites.value();
|
||||||
//Serial.print("GPS satellites: ");
|
//syslog->print("GPS satellites: ");
|
||||||
//Serial.println(liveData->params.gpsSat);
|
//syslog->println(liveData->params.gpsSat);
|
||||||
}
|
}
|
||||||
if (!liveData->params.currTimeSyncWithGps && gps.date.isValid() && gps.time.isValid()) {
|
if (!liveData->params.currTimeSyncWithGps && gps.date.isValid() && gps.time.isValid()) {
|
||||||
liveData->params.currTimeSyncWithGps = true;
|
liveData->params.currTimeSyncWithGps = true;
|
||||||
@@ -1523,8 +1523,8 @@ void Board320_240::syncGPS() {
|
|||||||
SIM800L
|
SIM800L
|
||||||
*/
|
*/
|
||||||
bool Board320_240::sim800lSetup() {
|
bool Board320_240::sim800lSetup() {
|
||||||
Serial.print("Setting SIM800L module. HW port: ");
|
syslog->print("Setting SIM800L module. HW port: ");
|
||||||
Serial.println(liveData->settings.gprsHwSerialPort);
|
syslog->println(liveData->settings.gprsHwSerialPort);
|
||||||
|
|
||||||
gprsHwUart = new HardwareSerial(liveData->settings.gprsHwSerialPort);
|
gprsHwUart = new HardwareSerial(liveData->settings.gprsHwSerialPort);
|
||||||
gprsHwUart->begin(9600);
|
gprsHwUart->begin(9600);
|
||||||
@@ -1535,31 +1535,31 @@ bool Board320_240::sim800lSetup() {
|
|||||||
|
|
||||||
bool sim800l_ready = sim800l->isReady();
|
bool sim800l_ready = sim800l->isReady();
|
||||||
for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) {
|
for (uint8_t i = 0; i < 5 && !sim800l_ready; i++) {
|
||||||
Serial.println("Problem to initialize SIM800L module, retry in 1 sec");
|
syslog->println("Problem to initialize SIM800L module, retry in 1 sec");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
sim800l_ready = sim800l->isReady();
|
sim800l_ready = sim800l->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sim800l_ready) {
|
if (!sim800l_ready) {
|
||||||
Serial.println("Problem to initialize SIM800L module");
|
syslog->println("Problem to initialize SIM800L module");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("SIM800L module initialized");
|
syslog->println("SIM800L module initialized");
|
||||||
|
|
||||||
Serial.print("Setting GPRS APN to: ");
|
syslog->print("Setting GPRS APN to: ");
|
||||||
Serial.println(liveData->settings.gprsApn);
|
syslog->println(liveData->settings.gprsApn);
|
||||||
|
|
||||||
bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
bool sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
||||||
for (uint8_t i = 0; i < 5 && !sim800l_gprs; i++) {
|
for (uint8_t i = 0; i < 5 && !sim800l_gprs; i++) {
|
||||||
Serial.println("Problem to set GPRS APN, retry in 1 sec");
|
syslog->println("Problem to set GPRS APN, retry in 1 sec");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
sim800l_gprs = sim800l->setupGPRS(liveData->settings.gprsApn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sim800l_gprs) {
|
if (sim800l_gprs) {
|
||||||
liveData->params.sim800l_enabled = true;
|
liveData->params.sim800l_enabled = true;
|
||||||
Serial.println("GPRS APN set OK");
|
syslog->println("GPRS APN set OK");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Problem to set GPRS APN");
|
syslog->println("Problem to set GPRS APN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1567,31 +1567,31 @@ bool Board320_240::sim800lSetup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Board320_240::sendDataViaGPRS() {
|
bool Board320_240::sendDataViaGPRS() {
|
||||||
Serial.println("Sending data via GPRS");
|
syslog->println("Sending data via GPRS");
|
||||||
|
|
||||||
if (liveData->params.socPerc < 0) {
|
if (liveData->params.socPerc < 0) {
|
||||||
Serial.println("No valid data, skipping data send");
|
syslog->println("No valid data, skipping data send");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkRegistration network = sim800l->getRegistrationStatus();
|
NetworkRegistration network = sim800l->getRegistrationStatus();
|
||||||
if (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
|
if (network != REGISTERED_HOME && network != REGISTERED_ROAMING) {
|
||||||
Serial.println("SIM800L module not connected to network, skipping data send");
|
syslog->println("SIM800L module not connected to network, skipping data send");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sim800l->isConnectedGPRS()) {
|
if (!sim800l->isConnectedGPRS()) {
|
||||||
Serial.println("GPRS not connected... Connecting");
|
syslog->println("GPRS not connected... Connecting");
|
||||||
bool connected = sim800l->connectGPRS();
|
bool connected = sim800l->connectGPRS();
|
||||||
for (uint8_t i = 0; i < 5 && !connected; i++) {
|
for (uint8_t i = 0; i < 5 && !connected; i++) {
|
||||||
Serial.println("Problem to connect GPRS, retry in 1 sec");
|
syslog->println("Problem to connect GPRS, retry in 1 sec");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
connected = sim800l->connectGPRS();
|
connected = sim800l->connectGPRS();
|
||||||
}
|
}
|
||||||
if (connected) {
|
if (connected) {
|
||||||
Serial.println("GPRS connected!");
|
syslog->println("GPRS connected!");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("GPRS not connected! Reseting SIM800L module!");
|
syslog->println("GPRS not connected! Reseting SIM800L module!");
|
||||||
sim800l->reset();
|
sim800l->reset();
|
||||||
sim800lSetup();
|
sim800lSetup();
|
||||||
|
|
||||||
@@ -1599,7 +1599,7 @@ bool Board320_240::sendDataViaGPRS() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Start HTTP POST...");
|
syslog->println("Start HTTP POST...");
|
||||||
|
|
||||||
StaticJsonDocument<512> jsonData;
|
StaticJsonDocument<512> jsonData;
|
||||||
|
|
||||||
@@ -1624,19 +1624,19 @@ bool Board320_240::sendDataViaGPRS() {
|
|||||||
char payload[512];
|
char payload[512];
|
||||||
serializeJson(jsonData, payload);
|
serializeJson(jsonData, payload);
|
||||||
|
|
||||||
Serial.print("Sending payload: ");
|
syslog->print("Sending payload: ");
|
||||||
Serial.println(payload);
|
syslog->println(payload);
|
||||||
|
|
||||||
Serial.print("Remote API server: ");
|
syslog->print("Remote API server: ");
|
||||||
Serial.println(liveData->settings.remoteApiUrl);
|
syslog->println(liveData->settings.remoteApiUrl);
|
||||||
|
|
||||||
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000);
|
uint16_t rc = sim800l->doPost(liveData->settings.remoteApiUrl, "application/json", payload, 10000, 10000);
|
||||||
if (rc == 200) {
|
if (rc == 200) {
|
||||||
Serial.println("HTTP POST successful");
|
syslog->println("HTTP POST successful");
|
||||||
} else {
|
} else {
|
||||||
// Failed...
|
// Failed...
|
||||||
Serial.print("HTTP POST error: ");
|
syslog->print("HTTP POST error: ");
|
||||||
Serial.println(rc);
|
syslog->println(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void BoardInterface::attachCar(CarInterface* pCarInterface) {
|
|||||||
*/
|
*/
|
||||||
void BoardInterface::shutdownDevice() {
|
void BoardInterface::shutdownDevice() {
|
||||||
|
|
||||||
Serial.println("Shutdown.");
|
syslog->println("Shutdown.");
|
||||||
|
|
||||||
char msg[20];
|
char msg[20];
|
||||||
for (int i = 3; i >= 1; i--) {
|
for (int i = 3; i >= 1; i--) {
|
||||||
@@ -65,7 +65,7 @@ void BoardInterface::shutdownDevice() {
|
|||||||
void BoardInterface::saveSettings() {
|
void BoardInterface::saveSettings() {
|
||||||
|
|
||||||
// Flash to memory
|
// Flash to memory
|
||||||
Serial.println("Settings saved to eeprom.");
|
syslog->println("Settings saved to eeprom.");
|
||||||
EEPROM.put(0, liveData->settings);
|
EEPROM.put(0, liveData->settings);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ void BoardInterface::saveSettings() {
|
|||||||
void BoardInterface::resetSettings() {
|
void BoardInterface::resetSettings() {
|
||||||
|
|
||||||
// Flash to memory
|
// Flash to memory
|
||||||
Serial.println("Factory reset.");
|
syslog->println("Factory reset.");
|
||||||
liveData->settings.initFlag = 1;
|
liveData->settings.initFlag = 1;
|
||||||
EEPROM.put(0, liveData->settings);
|
EEPROM.put(0, liveData->settings);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
@@ -143,17 +143,17 @@ void BoardInterface::loadSettings() {
|
|||||||
liveData->settings.gprsLogIntervalSec = 60;
|
liveData->settings.gprsLogIntervalSec = 60;
|
||||||
|
|
||||||
// Load settings and replace default values
|
// Load settings and replace default values
|
||||||
Serial.println("Reading settings from eeprom.");
|
syslog->println("Reading settings from eeprom.");
|
||||||
EEPROM.begin(sizeof(SETTINGS_STRUC));
|
EEPROM.begin(sizeof(SETTINGS_STRUC));
|
||||||
EEPROM.get(0, liveData->tmpSettings);
|
EEPROM.get(0, liveData->tmpSettings);
|
||||||
|
|
||||||
// Init flash with default settings
|
// Init flash with default settings
|
||||||
if (liveData->tmpSettings.initFlag != 183) {
|
if (liveData->tmpSettings.initFlag != 183) {
|
||||||
Serial.println("Settings not found. Initialization.");
|
syslog->println("Settings not found. Initialization.");
|
||||||
saveSettings();
|
saveSettings();
|
||||||
} else {
|
} else {
|
||||||
Serial.print("Loaded settings ver.: ");
|
syslog->print("Loaded settings ver.: ");
|
||||||
Serial.println(liveData->tmpSettings.settingsVersion);
|
syslog->println(liveData->tmpSettings.settingsVersion);
|
||||||
|
|
||||||
// Upgrade structure
|
// Upgrade structure
|
||||||
if (liveData->settings.settingsVersion != liveData->tmpSettings.settingsVersion) {
|
if (liveData->settings.settingsVersion != liveData->tmpSettings.settingsVersion) {
|
||||||
@@ -219,8 +219,8 @@ void BoardInterface::loadSettings() {
|
|||||||
void BoardInterface::afterSetup() {
|
void BoardInterface::afterSetup() {
|
||||||
|
|
||||||
// Init Comm iterface
|
// Init Comm iterface
|
||||||
Serial.print("Init communication device: ");
|
syslog->print("Init communication device: ");
|
||||||
Serial.println(liveData->settings.commType);
|
syslog->println(liveData->settings.commType);
|
||||||
|
|
||||||
if (liveData->settings.commType == COMM_TYPE_OBD2BLE4) {
|
if (liveData->settings.commType == COMM_TYPE_OBD2BLE4) {
|
||||||
commInterface = new CommObd2Ble4();
|
commInterface = new CommObd2Ble4();
|
||||||
@@ -228,7 +228,7 @@ void BoardInterface::afterSetup() {
|
|||||||
commInterface = new CommObd2Can();
|
commInterface = new CommObd2Can();
|
||||||
} else if (liveData->settings.commType == COMM_TYPE_OBD2BT3) {
|
} else if (liveData->settings.commType == COMM_TYPE_OBD2BT3) {
|
||||||
//commInterface = new CommObd2Bt3();
|
//commInterface = new CommObd2Bt3();
|
||||||
Serial.println("BT3 not implemented");
|
syslog->println("BT3 not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
commInterface->initComm(liveData, this);
|
commInterface->initComm(liveData, this);
|
||||||
|
|||||||
24
CarBmwI3.cpp
24
CarBmwI3.cpp
@@ -69,15 +69,15 @@ void CarBmwI3::activateCommandQueue() {
|
|||||||
void CarBmwI3::parseRowMerged()
|
void CarBmwI3::parseRowMerged()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Serial.println("--Parsing row merged: ");
|
// syslog->println("--Parsing row merged: ");
|
||||||
// Serial.print("--responseRowMerged: "); Serial.println(liveData->responseRowMerged);
|
// syslog->print("--responseRowMerged: "); syslog->println(liveData->responseRowMerged);
|
||||||
// Serial.print("--currentAtshRequest: "); Serial.println(liveData->currentAtshRequest);
|
// syslog->print("--currentAtshRequest: "); syslog->println(liveData->currentAtshRequest);
|
||||||
// Serial.print("--commandRequest: "); Serial.println(liveData->commandRequest);
|
// syslog->print("--commandRequest: "); syslog->println(liveData->commandRequest);
|
||||||
// Serial.print("--mergedLength: "); Serial.println(liveData->responseRowMerged.length());
|
// syslog->print("--mergedLength: "); syslog->println(liveData->responseRowMerged.length());
|
||||||
Serial.print("--mergedVectorLength: "); Serial.println(liveData->vResponseRowMerged.size());
|
syslog->print("--mergedVectorLength: "); syslog->println(liveData->vResponseRowMerged.size());
|
||||||
|
|
||||||
if (liveData->responseRowMerged.length() <= 6) {
|
if (liveData->responseRowMerged.length() <= 6) {
|
||||||
Serial.println("--too short data, skiping processing");
|
syslog->println("--too short data, skiping processing");
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Header_t
|
struct Header_t
|
||||||
@@ -98,8 +98,8 @@ void CarBmwI3::parseRowMerged()
|
|||||||
std::vector<uint8_t> payloadReversed(pHeader->pData, pHeader->pData + payloadLength);
|
std::vector<uint8_t> payloadReversed(pHeader->pData, pHeader->pData + payloadLength);
|
||||||
std::reverse(payloadReversed.begin(), payloadReversed.end());
|
std::reverse(payloadReversed.begin(), payloadReversed.end());
|
||||||
|
|
||||||
//Serial.print("--extracted PID: "); Serial.println(pHeader->getPid());
|
//syslog->print("--extracted PID: "); syslog->println(pHeader->getPid());
|
||||||
//Serial.print("--payload length: "); Serial.println(payloadLength);
|
//syslog->print("--payload length: "); syslog->println(payloadLength);
|
||||||
|
|
||||||
|
|
||||||
// BMS
|
// BMS
|
||||||
@@ -200,9 +200,9 @@ void CarBmwI3::parseRowMerged()
|
|||||||
liveData->params.batTempC = ptr->tempAvg / 100.0;
|
liveData->params.batTempC = ptr->tempAvg / 100.0;
|
||||||
liveData->params.batMaxC = ptr->tempMax / 100.0;
|
liveData->params.batMaxC = ptr->tempMax / 100.0;
|
||||||
|
|
||||||
Serial.print("----batMinC: "); Serial.println(liveData->params.batMinC);
|
syslog->print("----batMinC: "); syslog->println(liveData->params.batMinC);
|
||||||
Serial.print("----batTemp: "); Serial.println(liveData->params.batTempC);
|
syslog->print("----batTemp: "); syslog->println(liveData->params.batTempC);
|
||||||
Serial.print("----batMaxC: "); Serial.println(liveData->params.batMaxC);
|
syslog->print("----batMaxC: "); syslog->println(liveData->params.batMaxC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ void CommInterface::initComm(LiveData* pLiveData, BoardInterface* pBoard) {
|
|||||||
void CommInterface::mainLoop() {
|
void CommInterface::mainLoop() {
|
||||||
|
|
||||||
// Send command from TTY to OBD2
|
// Send command from TTY to OBD2
|
||||||
if (Serial.available()) {
|
if (syslog->available()) {
|
||||||
ch = Serial.read();
|
ch = syslog->read();
|
||||||
if (ch == '\r' || ch == '\n') {
|
if (ch == '\r' || ch == '\n') {
|
||||||
board->customConsoleCommand(response);
|
board->customConsoleCommand(response);
|
||||||
response = response + ch;
|
response = response + ch;
|
||||||
Serial.println(response);
|
syslog->println(response);
|
||||||
executeCommand(response);
|
executeCommand(response);
|
||||||
response = "";
|
response = "";
|
||||||
} else {
|
} else {
|
||||||
@@ -59,8 +59,8 @@ bool CommInterface::doNextQueueCommand() {
|
|||||||
liveData->currentAtshRequest = liveData->commandRequest;
|
liveData->currentAtshRequest = liveData->commandRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(">>> ");
|
syslog->print(">>> ");
|
||||||
Serial.println(liveData->commandRequest);
|
syslog->println(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
|
||||||
Serial.println(liveData->responseRow);
|
syslog->println(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) == ':') {
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ class MyClientCallback : public BLEClientCallbacks {
|
|||||||
|
|
||||||
// On BLE connect
|
// On BLE connect
|
||||||
void onConnect(BLEClient* pclient) {
|
void onConnect(BLEClient* pclient) {
|
||||||
Serial.println("onConnect");
|
syslog->println("onConnect");
|
||||||
}
|
}
|
||||||
|
|
||||||
// On BLE disconnect
|
// On BLE disconnect
|
||||||
void onDisconnect(BLEClient* pclient) {
|
void onDisconnect(BLEClient* pclient) {
|
||||||
liveDataObj->commConnected = false;
|
liveDataObj->commConnected = false;
|
||||||
Serial.println("onDisconnect");
|
syslog->println("onDisconnect");
|
||||||
|
|
||||||
boardObj->displayMessage("BLE disconnected", "");
|
boardObj->displayMessage("BLE disconnected", "");
|
||||||
}
|
}
|
||||||
@@ -34,9 +34,9 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
|||||||
// Called for each advertising BLE server.
|
// Called for each advertising BLE server.
|
||||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||||
|
|
||||||
Serial.print("BLE advertised device found: ");
|
syslog->print("BLE advertised device found: ");
|
||||||
Serial.println(advertisedDevice.toString().c_str());
|
syslog->println(advertisedDevice.toString().c_str());
|
||||||
Serial.println(advertisedDevice.getAddress().toString().c_str());
|
syslog->println(advertisedDevice.getAddress().toString().c_str());
|
||||||
|
|
||||||
// Add to device list (max. 9 devices allowed yet)
|
// Add to device list (max. 9 devices allowed yet)
|
||||||
String tmpStr;
|
String tmpStr;
|
||||||
@@ -56,17 +56,17 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
// if (advertisedDevice.getServiceDataUUID().toString() != "<NULL>") {
|
||||||
// Serial.print("ServiceDataUUID: ");
|
// syslog->print("ServiceDataUUID: ");
|
||||||
// Serial.println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
// syslog->println(advertisedDevice.getServiceDataUUID().toString().c_str());
|
||||||
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
// if (advertisedDevice.getServiceUUID().toString() != "<NULL>") {
|
||||||
// Serial.print("ServiceUUID: ");
|
// syslog->print("ServiceUUID: ");
|
||||||
// Serial.println(advertisedDevice.getServiceUUID().toString().c_str());
|
// syslog->println(advertisedDevice.getServiceUUID().toString().c_str());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(liveDataObj->settings.serviceUUID)) &&
|
if (advertisedDevice.haveServiceUUID() && advertisedDevice.isAdvertisingService(BLEUUID(liveDataObj->settings.serviceUUID)) &&
|
||||||
(strcmp(advertisedDevice.getAddress().toString().c_str(), liveDataObj->settings.obdMacAddress) == 0)) {
|
(strcmp(advertisedDevice.getAddress().toString().c_str(), liveDataObj->settings.obdMacAddress) == 0)) {
|
||||||
Serial.println("Stop scanning. Found my BLE device.");
|
syslog->println("Stop scanning. Found my BLE device.");
|
||||||
BLEDevice::getScan()->stop();
|
BLEDevice::getScan()->stop();
|
||||||
liveDataObj->foundMyBleDevice = new BLEAdvertisedDevice(advertisedDevice);
|
liveDataObj->foundMyBleDevice = new BLEAdvertisedDevice(advertisedDevice);
|
||||||
}
|
}
|
||||||
@@ -81,29 +81,29 @@ uint32_t PIN = 1234;
|
|||||||
class MySecurity : public BLESecurityCallbacks {
|
class MySecurity : public BLESecurityCallbacks {
|
||||||
|
|
||||||
uint32_t onPassKeyRequest() {
|
uint32_t onPassKeyRequest() {
|
||||||
Serial.printf("Pairing password: %d \r\n", PIN);
|
syslog->printf("Pairing password: %d \r\n", PIN);
|
||||||
return PIN;
|
return PIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onPassKeyNotify(uint32_t pass_key) {
|
void onPassKeyNotify(uint32_t pass_key) {
|
||||||
Serial.printf("onPassKeyNotify\r\n");
|
syslog->printf("onPassKeyNotify\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onConfirmPIN(uint32_t pass_key) {
|
bool onConfirmPIN(uint32_t pass_key) {
|
||||||
Serial.printf("onConfirmPIN\r\n");
|
syslog->printf("onConfirmPIN\r\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool onSecurityRequest() {
|
bool onSecurityRequest() {
|
||||||
Serial.printf("onSecurityRequest\r\n");
|
syslog->printf("onSecurityRequest\r\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAuthenticationComplete(esp_ble_auth_cmpl_t auth_cmpl) {
|
void onAuthenticationComplete(esp_ble_auth_cmpl_t auth_cmpl) {
|
||||||
if (auth_cmpl.success) {
|
if (auth_cmpl.success) {
|
||||||
Serial.printf("onAuthenticationComplete\r\n");
|
syslog->printf("onAuthenticationComplete\r\n");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Auth failure. Incorrect PIN?");
|
syslog->println("Auth failure. Incorrect PIN?");
|
||||||
liveDataObj->bleConnect = false;
|
liveDataObj->bleConnect = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 != "") {
|
||||||
Serial.print("merged:");
|
syslog->print("merged:");
|
||||||
Serial.println(liveDataObj->responseRowMerged);
|
syslog->println(liveDataObj->responseRowMerged);
|
||||||
boardObj->parseRowMerged();
|
boardObj->parseRowMerged();
|
||||||
}
|
}
|
||||||
liveDataObj->responseRowMerged = "";
|
liveDataObj->responseRowMerged = "";
|
||||||
@@ -149,7 +149,7 @@ void CommObd2Ble4::connectDevice() {
|
|||||||
liveDataObj = liveData;
|
liveDataObj = liveData;
|
||||||
boardObj = board;
|
boardObj = board;
|
||||||
|
|
||||||
Serial.println("BLE4 connectDevice");
|
syslog->println("BLE4 connectDevice");
|
||||||
|
|
||||||
// Start BLE connection
|
// Start BLE connection
|
||||||
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
|
||||||
@@ -157,7 +157,7 @@ void CommObd2Ble4::connectDevice() {
|
|||||||
|
|
||||||
// Retrieve a Scanner and set the callback we want to use to be informed when we have detected a new device.
|
// Retrieve a Scanner and set the callback we want to use to be informed when we have detected a new device.
|
||||||
// Specify that we want active scanning and start the scan to run for 10 seconds.
|
// Specify that we want active scanning and start the scan to run for 10 seconds.
|
||||||
Serial.println("Setup BLE scan");
|
syslog->println("Setup BLE scan");
|
||||||
liveData->pBLEScan = BLEDevice::getScan();
|
liveData->pBLEScan = BLEDevice::getScan();
|
||||||
liveData->pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
liveData->pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
||||||
liveData->pBLEScan->setInterval(1349);
|
liveData->pBLEScan->setInterval(1349);
|
||||||
@@ -166,7 +166,7 @@ void CommObd2Ble4::connectDevice() {
|
|||||||
|
|
||||||
// Skip BLE scan if middle button pressed
|
// Skip BLE scan if middle button pressed
|
||||||
if (strcmp(liveData->settings.obdMacAddress, "00:00:00:00:00:00") != 0 && !board->skipAdapterScan()) {
|
if (strcmp(liveData->settings.obdMacAddress, "00:00:00:00:00:00") != 0 && !board->skipAdapterScan()) {
|
||||||
Serial.println(liveData->settings.obdMacAddress);
|
syslog->println(liveData->settings.obdMacAddress);
|
||||||
startBleScan();
|
startBleScan();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ void CommObd2Ble4::connectDevice() {
|
|||||||
*/
|
*/
|
||||||
void CommObd2Ble4::disconnectDevice() {
|
void CommObd2Ble4::disconnectDevice() {
|
||||||
|
|
||||||
Serial.println("COMM disconnectDevice");
|
syslog->println("COMM disconnectDevice");
|
||||||
btStop();
|
btStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ void CommObd2Ble4::disconnectDevice() {
|
|||||||
*/
|
*/
|
||||||
void CommObd2Ble4::scanDevices() {
|
void CommObd2Ble4::scanDevices() {
|
||||||
|
|
||||||
Serial.println("COMM scanDevices");
|
syslog->println("COMM scanDevices");
|
||||||
startBleScan();
|
startBleScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,13 +201,13 @@ void CommObd2Ble4::startBleScan() {
|
|||||||
board->displayMessage(" > Scanning BLE4 devices", "40sec.or hold middle&RST");
|
board->displayMessage(" > Scanning BLE4 devices", "40sec.or hold middle&RST");
|
||||||
|
|
||||||
// Start scanning
|
// Start scanning
|
||||||
Serial.println("Scanning BLE devices...");
|
syslog->println("Scanning BLE devices...");
|
||||||
Serial.print("Looking for ");
|
syslog->print("Looking for ");
|
||||||
Serial.println(liveData->settings.obdMacAddress);
|
syslog->println(liveData->settings.obdMacAddress);
|
||||||
BLEScanResults foundDevices = liveData->pBLEScan->start(40, false);
|
BLEScanResults foundDevices = liveData->pBLEScan->start(40, false);
|
||||||
Serial.print("Devices found: ");
|
syslog->print("Devices found: ");
|
||||||
Serial.println(foundDevices.getCount());
|
syslog->println(foundDevices.getCount());
|
||||||
Serial.println("Scan done!");
|
syslog->println("Scan done!");
|
||||||
liveData->pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
|
liveData->pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
|
||||||
|
|
||||||
char tmpStr1[20];
|
char tmpStr1[20];
|
||||||
@@ -216,7 +216,7 @@ void CommObd2Ble4::startBleScan() {
|
|||||||
|
|
||||||
// Scan devices from menu, show list of devices
|
// Scan devices from menu, show list of devices
|
||||||
if (liveData->menuCurrent == 9999) {
|
if (liveData->menuCurrent == 9999) {
|
||||||
Serial.println("Display menu with devices");
|
syslog->println("Display menu with devices");
|
||||||
liveData->menuVisible = true;
|
liveData->menuVisible = true;
|
||||||
//liveData->menuCurrent = 9999;
|
//liveData->menuCurrent = 9999;
|
||||||
liveData->menuItemSelected = 0;
|
liveData->menuItemSelected = 0;
|
||||||
@@ -238,8 +238,8 @@ bool CommObd2Ble4::connectToServer(BLEAddress pAddress) {
|
|||||||
|
|
||||||
board->displayMessage(" > Connecting device", "");
|
board->displayMessage(" > Connecting device", "");
|
||||||
|
|
||||||
Serial.print("liveData->bleConnect ");
|
syslog->print("liveData->bleConnect ");
|
||||||
Serial.println(pAddress.toString().c_str());
|
syslog->println(pAddress.toString().c_str());
|
||||||
board->displayMessage(" > Connecting device - init", pAddress.toString().c_str());
|
board->displayMessage(" > Connecting device - init", pAddress.toString().c_str());
|
||||||
|
|
||||||
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
|
BLEDevice::setEncryptionLevel(ESP_BLE_SEC_ENCRYPT);
|
||||||
@@ -253,49 +253,49 @@ bool CommObd2Ble4::connectToServer(BLEAddress pAddress) {
|
|||||||
board->displayMessage(" > Connecting device", pAddress.toString().c_str());
|
board->displayMessage(" > Connecting device", pAddress.toString().c_str());
|
||||||
liveData->pClient = BLEDevice::createClient();
|
liveData->pClient = BLEDevice::createClient();
|
||||||
liveData->pClient->setClientCallbacks(new MyClientCallback());
|
liveData->pClient->setClientCallbacks(new MyClientCallback());
|
||||||
if (liveData->pClient->connect(pAddress, BLE_ADDR_TYPE_RANDOM) ) Serial.println("liveData->bleConnected");
|
if (liveData->pClient->connect(pAddress, BLE_ADDR_TYPE_RANDOM) ) syslog->println("liveData->bleConnected");
|
||||||
Serial.println(" - liveData->bleConnected to server");
|
syslog->println(" - liveData->bleConnected to server");
|
||||||
|
|
||||||
// Remote service
|
// Remote service
|
||||||
board->displayMessage(" > Connecting device", "Connecting service...");
|
board->displayMessage(" > Connecting device", "Connecting service...");
|
||||||
BLERemoteService* pRemoteService = liveData->pClient->getService(BLEUUID(liveData->settings.serviceUUID));
|
BLERemoteService* pRemoteService = liveData->pClient->getService(BLEUUID(liveData->settings.serviceUUID));
|
||||||
if (pRemoteService == nullptr)
|
if (pRemoteService == nullptr)
|
||||||
{
|
{
|
||||||
Serial.print("Failed to find our service UUID: ");
|
syslog->print("Failed to find our service UUID: ");
|
||||||
Serial.println(liveData->settings.serviceUUID);
|
syslog->println(liveData->settings.serviceUUID);
|
||||||
board->displayMessage(" > Connecting device", "Unable to find service");
|
board->displayMessage(" > Connecting device", "Unable to find service");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println(" - Found our service");
|
syslog->println(" - Found our service");
|
||||||
|
|
||||||
// Get characteristics
|
// Get characteristics
|
||||||
board->displayMessage(" > Connecting device", "Connecting TxUUID...");
|
board->displayMessage(" > Connecting device", "Connecting TxUUID...");
|
||||||
liveData->pRemoteCharacteristic = pRemoteService->getCharacteristic(BLEUUID(liveData->settings.charTxUUID));
|
liveData->pRemoteCharacteristic = pRemoteService->getCharacteristic(BLEUUID(liveData->settings.charTxUUID));
|
||||||
if (liveData->pRemoteCharacteristic == nullptr) {
|
if (liveData->pRemoteCharacteristic == nullptr) {
|
||||||
Serial.print("Failed to find our characteristic UUID: ");
|
syslog->print("Failed to find our characteristic UUID: ");
|
||||||
Serial.println(liveData->settings.charTxUUID);//.toString().c_str());
|
syslog->println(liveData->settings.charTxUUID);//.toString().c_str());
|
||||||
board->displayMessage(" > Connecting device", "Unable to find TxUUID");
|
board->displayMessage(" > Connecting device", "Unable to find TxUUID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println(" - Found our characteristic");
|
syslog->println(" - Found our characteristic");
|
||||||
|
|
||||||
// Get characteristics
|
// Get characteristics
|
||||||
board->displayMessage(" > Connecting device", "Connecting RxUUID...");
|
board->displayMessage(" > Connecting device", "Connecting RxUUID...");
|
||||||
liveData->pRemoteCharacteristicWrite = pRemoteService->getCharacteristic(BLEUUID(liveData->settings.charRxUUID));
|
liveData->pRemoteCharacteristicWrite = pRemoteService->getCharacteristic(BLEUUID(liveData->settings.charRxUUID));
|
||||||
if (liveData->pRemoteCharacteristicWrite == nullptr) {
|
if (liveData->pRemoteCharacteristicWrite == nullptr) {
|
||||||
Serial.print("Failed to find our characteristic UUID: ");
|
syslog->print("Failed to find our characteristic UUID: ");
|
||||||
Serial.println(liveData->settings.charRxUUID);//.toString().c_str());
|
syslog->println(liveData->settings.charRxUUID);//.toString().c_str());
|
||||||
board->displayMessage(" > Connecting device", "Unable to find RxUUID");
|
board->displayMessage(" > Connecting device", "Unable to find RxUUID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Serial.println(" - Found our characteristic write");
|
syslog->println(" - Found our characteristic write");
|
||||||
|
|
||||||
board->displayMessage(" > Connecting device", "Register callbacks...");
|
board->displayMessage(" > Connecting device", "Register callbacks...");
|
||||||
// Read the value of the characteristic.
|
// Read the value of the characteristic.
|
||||||
if (liveData->pRemoteCharacteristic->canNotify()) {
|
if (liveData->pRemoteCharacteristic->canNotify()) {
|
||||||
Serial.println(" - canNotify");
|
syslog->println(" - canNotify");
|
||||||
if (liveData->pRemoteCharacteristic->canIndicate()) {
|
if (liveData->pRemoteCharacteristic->canIndicate()) {
|
||||||
Serial.println(" - canIndicate");
|
syslog->println(" - canIndicate");
|
||||||
const uint8_t indicationOn[] = {0x2, 0x0};
|
const uint8_t indicationOn[] = {0x2, 0x0};
|
||||||
//const uint8_t indicationOff[] = {0x0,0x0};
|
//const uint8_t indicationOff[] = {0x0,0x0};
|
||||||
liveData->pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)indicationOn, 2, true);
|
liveData->pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)indicationOn, 2, true);
|
||||||
@@ -307,7 +307,7 @@ bool CommObd2Ble4::connectToServer(BLEAddress pAddress) {
|
|||||||
|
|
||||||
board->displayMessage(" > Connecting device", "Done...");
|
board->displayMessage(" > Connecting device", "Done...");
|
||||||
if (liveData->pRemoteCharacteristicWrite->canWrite()) {
|
if (liveData->pRemoteCharacteristicWrite->canWrite()) {
|
||||||
Serial.println(" - canWrite");
|
syslog->println(" - canWrite");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -326,7 +326,7 @@ void CommObd2Ble4::mainLoop() {
|
|||||||
liveData->commConnected = true;
|
liveData->commConnected = true;
|
||||||
liveData->bleConnect = false;
|
liveData->bleConnect = false;
|
||||||
|
|
||||||
Serial.println("We are now connected to the BLE device.");
|
syslog->println("We are now connected to the BLE device.");
|
||||||
|
|
||||||
// Print message
|
// Print message
|
||||||
board->displayMessage(" > Processing init AT cmds", "");
|
board->displayMessage(" > Processing init AT cmds", "");
|
||||||
@@ -335,7 +335,7 @@ void CommObd2Ble4::mainLoop() {
|
|||||||
doNextQueueCommand();
|
doNextQueueCommand();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Serial.println("We have failed to connect to the server; there is nothing more we will do.");
|
syslog->println("We have failed to connect to the server; there is nothing more we will do.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
108
CommObd2Can.cpp
108
CommObd2Can.cpp
@@ -10,22 +10,22 @@
|
|||||||
*/
|
*/
|
||||||
void CommObd2Can::connectDevice() {
|
void CommObd2Can::connectDevice() {
|
||||||
|
|
||||||
Serial.println("CAN connectDevice");
|
syslog->println("CAN connectDevice");
|
||||||
|
|
||||||
//CAN = new MCP_CAN(pinCanCs); // todo: remove if smart pointer is ok
|
//CAN = new MCP_CAN(pinCanCs); // todo: remove if smart pointer is ok
|
||||||
CAN.reset(new MCP_CAN(pinCanCs)); // smart pointer so it's automatically cleaned when out of context and also free to re-init
|
CAN.reset(new MCP_CAN(pinCanCs)); // smart pointer so it's automatically cleaned when out of context and also free to re-init
|
||||||
if (CAN == nullptr) {
|
if (CAN == nullptr) {
|
||||||
Serial.println("Error: Not enough memory to instantiate CAN class");
|
syslog->println("Error: Not enough memory to instantiate CAN class");
|
||||||
Serial.println("init_can() failed");
|
syslog->println("init_can() failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
|
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
|
||||||
if (CAN->begin(MCP_STDEXT, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
|
if (CAN->begin(MCP_STDEXT, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
|
||||||
Serial.println("MCP2515 Initialized Successfully!");
|
syslog->println("MCP2515 Initialized Successfully!");
|
||||||
board->displayMessage(" > CAN init OK", "");
|
board->displayMessage(" > CAN init OK", "");
|
||||||
} else {
|
} else {
|
||||||
Serial.println("Error Initializing MCP2515...");
|
syslog->println("Error Initializing MCP2515...");
|
||||||
board->displayMessage(" > CAN init failed", "");
|
board->displayMessage(" > CAN init failed", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ void CommObd2Can::connectDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MCP2515_OK != CAN->setMode(MCP_NORMAL)) { // Set operation mode to normal so the MCP2515 sends acks to received data.
|
if (MCP2515_OK != CAN->setMode(MCP_NORMAL)) { // Set operation mode to normal so the MCP2515 sends acks to received data.
|
||||||
Serial.println("Error: CAN->setMode(MCP_NORMAL) failed");
|
syslog->println("Error: CAN->setMode(MCP_NORMAL) failed");
|
||||||
board->displayMessage(" > CAN init failed", "");
|
board->displayMessage(" > CAN init failed", "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ void CommObd2Can::connectDevice() {
|
|||||||
liveData->commConnected = true;
|
liveData->commConnected = true;
|
||||||
doNextQueueCommand();
|
doNextQueueCommand();
|
||||||
|
|
||||||
Serial.println("init_can() done");
|
syslog->println("init_can() done");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +60,7 @@ void CommObd2Can::connectDevice() {
|
|||||||
void CommObd2Can::disconnectDevice() {
|
void CommObd2Can::disconnectDevice() {
|
||||||
|
|
||||||
liveData->commConnected = false;
|
liveData->commConnected = false;
|
||||||
Serial.println("COMM disconnectDevice");
|
syslog->println("COMM disconnectDevice");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +68,7 @@ void CommObd2Can::disconnectDevice() {
|
|||||||
*/
|
*/
|
||||||
void CommObd2Can::scanDevices() {
|
void CommObd2Can::scanDevices() {
|
||||||
|
|
||||||
Serial.println("COMM scanDevices");
|
syslog->println("COMM scanDevices");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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) {
|
||||||
Serial.print("CAN execution timeout (multiframe message).\n");
|
syslog->print("CAN execution timeout (multiframe message).\n");
|
||||||
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) {
|
||||||
Serial.print("CAN execution timeout. Continue with next command.\n");
|
syslog->print("CAN execution timeout. Continue with next command.\n");
|
||||||
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) {
|
||||||
|
|
||||||
Serial.print("executeCommand ");
|
syslog->print("executeCommand ");
|
||||||
Serial.println(cmd);
|
syslog->println(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) {
|
||||||
Serial.print("SENT ");
|
syslog->print("SENT ");
|
||||||
lastDataSent = millis();
|
lastDataSent = millis();
|
||||||
} else {
|
} else {
|
||||||
Serial.print("Error sending PID ");
|
syslog->print("Error sending PID ");
|
||||||
}
|
}
|
||||||
Serial.print(pid);
|
syslog->print(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]);
|
||||||
Serial.print(msgString);
|
syslog->print(msgString);
|
||||||
}
|
}
|
||||||
Serial.println("");
|
syslog->println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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) {
|
||||||
Serial.print("Flow control frame sent ");
|
syslog->print("Flow control frame sent ");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("Error sending flow control frame ");
|
syslog->print("Error sending flow control frame ");
|
||||||
}
|
}
|
||||||
Serial.print(lastPid);
|
syslog->print(lastPid);
|
||||||
for (auto txByte : txBuf) {
|
for (auto txByte : txBuf) {
|
||||||
sprintf(msgString, " 0x%.2X", txByte);
|
sprintf(msgString, " 0x%.2X", txByte);
|
||||||
Serial.print(msgString);
|
syslog->print(msgString);
|
||||||
}
|
}
|
||||||
Serial.println("");
|
syslog->println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -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();
|
||||||
Serial.print(" CAN READ ");
|
syslog->print(" 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);
|
||||||
|
|
||||||
Serial.print(msgString);
|
syslog->print(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");
|
||||||
Serial.print(msgString);
|
syslog->print(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]);
|
||||||
Serial.print(msgString);
|
syslog->print(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) {
|
||||||
Serial.println(" [Ignored packet]");
|
syslog->println(" [Ignored packet]");
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,16 +265,16 @@ 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) {
|
||||||
Serial.println(" [Filtered packet]");
|
syslog->println(" [Filtered packet]");
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println();
|
syslog->println();
|
||||||
processFrameBytes();
|
processFrameBytes();
|
||||||
//processFrame();
|
//processFrame();
|
||||||
} else {
|
} else {
|
||||||
//Serial.println(" CAN NOT READ ");
|
//syslog->println(" CAN NOT READ ");
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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]);
|
||||||
Serial.print(str);
|
syslog->print(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bAddNewLine) {
|
if (bAddNewLine) {
|
||||||
Serial.println();
|
syslog->println();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ bool CommObd2Can::processFrameBytes() {
|
|||||||
|
|
||||||
rxRemaining = 0;
|
rxRemaining = 0;
|
||||||
|
|
||||||
//Serial.print("----Processing SingleFrame payload: "); printHexBuffer(pSingleFrame->pData, pSingleFrame->size, true);
|
//syslog->print("----Processing SingleFrame payload: "); printHexBuffer(pSingleFrame->pData, pSingleFrame->size, true);
|
||||||
|
|
||||||
// single frame - process directly
|
// single frame - process directly
|
||||||
buffer2string(liveData->responseRowMerged, mergedData.data(), mergedData.size());
|
buffer2string(liveData->responseRowMerged, mergedData.data(), mergedData.size());
|
||||||
@@ -381,7 +381,7 @@ bool CommObd2Can::processFrameBytes() {
|
|||||||
dataRows[0].assign(pFirstFrame->pData, pFirstFrame->pData + framePayloadSize);
|
dataRows[0].assign(pFirstFrame->pData, pFirstFrame->pData + framePayloadSize);
|
||||||
rxRemaining -= framePayloadSize;
|
rxRemaining -= framePayloadSize;
|
||||||
|
|
||||||
//Serial.print("----Processing FirstFrame payload: "); printHexBuffer(pFirstFrame->pData, framePayloadSize, true);
|
//syslog->print("----Processing FirstFrame payload: "); printHexBuffer(pFirstFrame->pData, framePayloadSize, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -395,19 +395,19 @@ bool CommObd2Can::processFrameBytes() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t structSize = sizeof(ConsecutiveFrame_t);
|
const uint8_t structSize = sizeof(ConsecutiveFrame_t);
|
||||||
//Serial.print("[debug] sizeof(ConsecutiveFrame_t) is expected to be 1 and it's "); Serial.println(structSize);
|
//syslog->print("[debug] sizeof(ConsecutiveFrame_t) is expected to be 1 and it's "); syslog->println(structSize);
|
||||||
|
|
||||||
ConsecutiveFrame_t* pConseqFrame = (ConsecutiveFrame_t*)pDataStart;
|
ConsecutiveFrame_t* pConseqFrame = (ConsecutiveFrame_t*)pDataStart;
|
||||||
const uint8_t framePayloadSize = frameLenght - sizeof(ConsecutiveFrame_t); // remove one byte of header
|
const uint8_t framePayloadSize = frameLenght - sizeof(ConsecutiveFrame_t); // remove one byte of header
|
||||||
dataRows[pConseqFrame->index].assign(pConseqFrame->pData, pConseqFrame->pData + framePayloadSize);
|
dataRows[pConseqFrame->index].assign(pConseqFrame->pData, pConseqFrame->pData + framePayloadSize);
|
||||||
rxRemaining -= framePayloadSize;
|
rxRemaining -= framePayloadSize;
|
||||||
|
|
||||||
//Serial.print("----Processing ConsecFrame payload: "); printHexBuffer(pConseqFrame->pData, framePayloadSize, true);
|
//syslog->print("----Processing ConsecFrame payload: "); printHexBuffer(pConseqFrame->pData, framePayloadSize, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Serial.print("Unknown frame type within CommObd2Can::processFrameBytes(): "); Serial.println((uint8_t)frameType);
|
syslog->print("Unknown frame type within CommObd2Can::processFrameBytes(): "); syslog->println((uint8_t)frameType);
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
} // \switch (frameType)
|
} // \switch (frameType)
|
||||||
@@ -416,10 +416,10 @@ bool CommObd2Can::processFrameBytes() {
|
|||||||
if (rxRemaining <= 0) {
|
if (rxRemaining <= 0) {
|
||||||
// multiple frames and no data remaining - merge everything to single packet
|
// multiple frames and no data remaining - merge everything to single packet
|
||||||
for (int i = 0; i < dataRows.size(); i++) {
|
for (int i = 0; i < dataRows.size(); i++) {
|
||||||
//Serial.print("------merging packet index ");
|
//syslog->print("------merging packet index ");
|
||||||
//Serial.print(i);
|
//syslog->print(i);
|
||||||
//Serial.print(" with length ");
|
//syslog->print(" with length ");
|
||||||
//Serial.println(dataRows[i].size());
|
//syslog->println(dataRows[i].size());
|
||||||
|
|
||||||
mergedData.insert(mergedData.end(), dataRows[i].begin(), dataRows[i].end());
|
mergedData.insert(mergedData.end(), dataRows[i].begin(), dataRows[i].end());
|
||||||
}
|
}
|
||||||
@@ -467,11 +467,11 @@ bool CommObd2Can::processFrame() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print("> frametype:");
|
syslog->print("> frametype:");
|
||||||
Serial.print(frameType);
|
syslog->print(frameType);
|
||||||
Serial.print(", r: ");
|
syslog->print(", r: ");
|
||||||
Serial.print(rxRemaining);
|
syslog->print(rxRemaining);
|
||||||
Serial.print(" ");
|
syslog->print(" ");
|
||||||
|
|
||||||
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 +479,14 @@ bool CommObd2Can::processFrame() {
|
|||||||
rxRemaining--;
|
rxRemaining--;
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.print(", r: ");
|
syslog->print(", r: ");
|
||||||
Serial.print(rxRemaining);
|
syslog->print(rxRemaining);
|
||||||
Serial.println(" ");
|
syslog->println(" ");
|
||||||
|
|
||||||
//parseResponse();
|
//parseResponse();
|
||||||
// We need to sort frames
|
// We need to sort frames
|
||||||
// 1 frame data
|
// 1 frame data
|
||||||
Serial.println(liveData->responseRow);
|
syslog->println(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 +494,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);
|
||||||
Serial.println(liveData->responseRowMerged);
|
syslog->println(liveData->responseRowMerged);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send response to board module
|
// Send response to board module
|
||||||
@@ -510,8 +510,8 @@ bool CommObd2Can::processFrame() {
|
|||||||
processMergedResponse
|
processMergedResponse
|
||||||
*/
|
*/
|
||||||
void CommObd2Can::processMergedResponse() {
|
void CommObd2Can::processMergedResponse() {
|
||||||
Serial.print("merged:");
|
syslog->print("merged:");
|
||||||
Serial.println(liveData->responseRowMerged);
|
syslog->println(liveData->responseRowMerged);
|
||||||
board->parseRowMerged();
|
board->parseRowMerged();
|
||||||
liveData->responseRowMerged = "";
|
liveData->responseRowMerged = "";
|
||||||
liveData->canSendNextAtCommand = true;
|
liveData->canSendNextAtCommand = true;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "LiveData.h"
|
#include "LiveData.h"
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
LogSerial* syslog;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug level
|
* Debug level
|
||||||
*/
|
*/
|
||||||
void debug(String msg, uint8_t debugLevel) {
|
void debug(String msg, uint8_t debugLevel) {
|
||||||
Serial.println(msg);
|
syslog->println(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
12
LiveData.h
12
LiveData.h
@@ -7,6 +7,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <BLEDevice.h>
|
#include <BLEDevice.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "LogSerial.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
// SUPPORTED CARS
|
// SUPPORTED CARS
|
||||||
@@ -34,15 +35,11 @@
|
|||||||
#define SCREEN_CHARGING 5
|
#define SCREEN_CHARGING 5
|
||||||
#define SCREEN_SOC10 6
|
#define SCREEN_SOC10 6
|
||||||
|
|
||||||
// DEBUG LEVEL
|
|
||||||
#define DEBUG_INFO 0
|
|
||||||
#define DEBUG_COMM 1
|
|
||||||
#define DEBUG_GPS 2
|
|
||||||
#define DEBUG_SDCARD 3
|
|
||||||
|
|
||||||
//
|
//
|
||||||
#define MONTH_SEC 2678400
|
#define MONTH_SEC 2678400
|
||||||
|
|
||||||
|
extern LogSerial* syslog;
|
||||||
|
|
||||||
// Structure with realtime values
|
// Structure with realtime values
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// System
|
// System
|
||||||
@@ -215,9 +212,6 @@ typedef struct {
|
|||||||
//
|
//
|
||||||
} SETTINGS_STRUC;
|
} SETTINGS_STRUC;
|
||||||
|
|
||||||
// Debug functions
|
|
||||||
void debug(String msg, uint8_t debugLevel = DEBUG_INFO);
|
|
||||||
|
|
||||||
// LiveData class
|
// LiveData class
|
||||||
class LiveData {
|
class LiveData {
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
8
LogSerial.cpp
Normal file
8
LogSerial.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#include "LogSerial.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
LogSerial::LogSerial() : HardwareSerial(0) {
|
||||||
|
HardwareSerial::begin(115200);
|
||||||
|
}
|
||||||
27
LogSerial.h
Normal file
27
LogSerial.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <HardwareSerial.h>
|
||||||
|
|
||||||
|
// DEBUG LEVEL
|
||||||
|
#define DEBUG_NONE 0
|
||||||
|
#define DEBUG_COMM 1 // filter comm
|
||||||
|
#define DEBUG_GPS 2 // filter gps messages
|
||||||
|
#define DEBUG_SDCARD 3 // filter sdcard
|
||||||
|
|
||||||
|
//
|
||||||
|
class LogSerial: public HardwareSerial {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
LogSerial();
|
||||||
|
/*virtual void infoNolfType(String msg, uint8_t debugLevel = TYPE_NONE);
|
||||||
|
virtual void infoType(String msg, uint8_t debugLevel = TYPE_NONE);
|
||||||
|
/*
|
||||||
|
template <class T, typename... Args> void infoNolf(String msg, uint8_t debugLevel = TYPE_NONE);
|
||||||
|
template <class T, typename... Args> void info(String msg, uint8_t debugLevel = DEBUG_ALL);
|
||||||
|
template <class T, typename... Args> void warnNolf(String msg, uint8_t debugLevel = DEBUG_ALL);
|
||||||
|
template <class T, typename... Args> void warn(String msg, uint8_t debugLevel = DEBUG_ALL);
|
||||||
|
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);*/
|
||||||
|
|
||||||
|
};
|
||||||
18
evDash.ino
18
evDash.ino
@@ -63,19 +63,19 @@ LiveData* liveData;
|
|||||||
*/
|
*/
|
||||||
void setup(void) {
|
void setup(void) {
|
||||||
|
|
||||||
// Serial console, init structures
|
// Serial console
|
||||||
Serial.begin(115200);
|
syslog = new LogSerial();
|
||||||
debug("\nBooting device...");
|
syslog->println("\nBooting device...");
|
||||||
|
|
||||||
// Init settings/params
|
// Init settings/params
|
||||||
liveData = new LiveData();
|
liveData = new LiveData();
|
||||||
liveData->initParams();
|
liveData->initParams();
|
||||||
|
|
||||||
// Turn off serial console
|
// Turn off serial console
|
||||||
if (liveData->settings.serialConsolePort = 255) {
|
if (liveData->settings.serialConsolePort == 255) {
|
||||||
debug("Serial console disabled...");
|
syslog->println("Serial console disabled...");
|
||||||
Serial.flush();
|
syslog->flush();
|
||||||
Serial.end();
|
syslog->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init board
|
// Init board
|
||||||
@@ -124,7 +124,7 @@ void setup(void) {
|
|||||||
board->afterSetup();
|
board->afterSetup();
|
||||||
|
|
||||||
// End
|
// End
|
||||||
Serial.println("Device setup completed");
|
syslog->println("Device setup completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user