From b8305124c8a95aea78073cb69e01db35c4d2dd9a Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Fri, 4 Apr 2014 11:24:48 +0800 Subject: Update UNO Logger --- unologger/datalogger.h | 155 ++++++++++++++++++++++++++++++--------------- unologger/unologger.depend | 73 --------------------- unologger/unologger.ino | 7 +- 3 files changed, 107 insertions(+), 128 deletions(-) delete mode 100644 unologger/unologger.depend diff --git a/unologger/datalogger.h b/unologger/datalogger.h index 4fdf805..1fbcc20 100644 --- a/unologger/datalogger.h +++ b/unologger/datalogger.h @@ -1,19 +1,3 @@ -typedef enum { - LOG_TYPE_DEFAULT = 0, - LOG_TYPE_0_60, - LOG_TYPE_0_100, - LOG_TYPE_100_200, - LOG_TYPE_400M, - LOG_TYPE_LAPS, - LOG_TYPE_ROUTE, -} LOG_TYPES; - -#define FLAG_CAR 0x1 -#define FLAG_CYCLING 0x2 -#define FLAG_OBD 0x10 -#define FLAG_GPS 0x20 -#define FLAG_ACC 0x40 - #define FORMAT_BIN 0 #define FORMAT_CSV 1 @@ -94,13 +78,26 @@ typedef struct { #endif #if ENABLE_DATA_OUT + +#if USE_SOFTSERIAL + #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) - SoftwareSerial mySerial(A8, A9); /* for BLE Shield on MEGA*/ + SoftwareSerial SerialBLE(A8, A9); /* for BLE Shield on MEGA*/ #elif defined(__AVR_ATmega644P__) - SoftwareSerial mySerial(9, 10); /* for Microduino */ + SoftwareSerial SerialBLE(9, 10); /* for Microduino */ +#else + SoftwareSerial SerialBLE(A2, A3); /* for BLE Shield on UNO/leonardo*/ +#endif + +#define OUTPUT_BAUDRATE 9600 + #else - SoftwareSerial mySerial(A2, A3); /* for BLE Shield on UNO*/ + +#define SerialBLE Serial +#define OUTPUT_BAUDRATE 115200 + #endif + #endif void btInit(int baudrate); @@ -111,7 +108,7 @@ public: void initSender() { #if ENABLE_DATA_OUT - mySerial.begin(9600); + SerialBLE.begin(OUTPUT_BAUDRATE); #endif #if ENABLE_DATA_LOG && LOG_FORMAT == FORMAT_CSV m_lastDataTime = 0; @@ -136,21 +133,21 @@ public: info.logType = hdr.logType; info.logFlags = hdr.flags; info.checksum = getChecksum((char*)&info, sizeof(info)); - mySerial.write((uint8_t*)&info, sizeof(info)); + SerialBLE.write((uint8_t*)&info, sizeof(info)); } void sendCommand(byte message, void* data = 0, byte bytes = 0) { LOG_DATA_COMMAND msg = {0, PID_MESSAGE, message}; if (data) memcpy(msg.data, data, bytes); msg.checksum = getChecksum((char*)&msg, sizeof(msg)); - mySerial.write((uint8_t*)&msg, sizeof(msg)); + SerialBLE.write((uint8_t*)&msg, sizeof(msg)); } bool receiveCommand(LOG_DATA_COMMAND& msg) { - if (!mySerial.available()) + if (!SerialBLE.available()) return false; - if (mySerial.readBytes((char*)&msg, sizeof(msg)) != sizeof(msg)) + if (SerialBLE.readBytes((char*)&msg, sizeof(msg)) != sizeof(msg)) return false; uint8_t checksum = msg.checksum; @@ -163,10 +160,19 @@ public: #endif void logData(uint16_t pid, int value) { +#if LOG_FORMAT == FORMAT_BIN || STREAM_FORMAT == FORMAT_BIN LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; ld.checksum = getChecksum((char*)&ld, 12); +#endif #if ENABLE_DATA_OUT - mySerial.write((uint8_t*)&ld, 12); +#if LOG_FORMAT == FORMAT_BIN + SerialBLE.write((uint8_t*)&ld, 12); +#else + SerialBLE.print(pid, HEX); + SerialBLE.write(','); + SerialBLE.print(value); + SerialBLE.write('\n'); +#endif #endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN @@ -174,21 +180,31 @@ public: dataSize += 12; #else dataSize += sdfile.print(dataTime - m_lastDataTime); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(pid, HEX); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value); - dataSize += sdfile.write('\n'); + sdfile.write('\n'); + dataSize += 3; m_lastDataTime = dataTime; #endif #endif } void logData(uint16_t pid, float value) { +#if LOG_FORMAT == FORMAT_BIN || STREAM_FORMAT == FORMAT_BIN LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; ld.checksum = getChecksum((char*)&ld, 12); +#endif #if ENABLE_DATA_OUT - mySerial.write((uint8_t*)&ld, 12); +#if LOG_FORMAT == FORMAT_BIN + SerialBLE.write((uint8_t*)&ld, 12); +#else + SerialBLE.print(pid, HEX); + SerialBLE.write(','); + SerialBLE.print(value); + SerialBLE.write('\n'); +#endif #endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN @@ -196,21 +212,33 @@ public: dataSize += 12; #else dataSize += sdfile.print(dataTime - m_lastDataTime); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(pid, HEX); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value); - dataSize += sdfile.write('\n'); + sdfile.write('\n'); + dataSize += 3; m_lastDataTime = dataTime; #endif #endif } void logData(uint16_t pid, float value1, float value2) { +#if LOG_FORMAT == FORMAT_BIN || STREAM_FORMAT == FORMAT_BIN LOG_DATA_COMM ld = {dataTime, pid, 2, 0, {value1, value2}}; ld.checksum = getChecksum((char*)&ld, 16); +#endif #if ENABLE_DATA_OUT - mySerial.write((uint8_t*)&ld, 16); +#if LOG_FORMAT == FORMAT_BIN + SerialBLE.write((uint8_t*)&ld, 16); +#else + SerialBLE.print(pid, HEX); + SerialBLE.write(','); + SerialBLE.print(value1, 6); + SerialBLE.write(','); + SerialBLE.print(value2, 6); + SerialBLE.write('\n'); +#endif #endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN @@ -218,23 +246,35 @@ public: dataSize += 16; #else dataSize += sdfile.print(dataTime - m_lastDataTime); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(pid, HEX); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value1, 6); - dataSize += sdfile.write(' '); + sdfile.write(','); dataSize += sdfile.print(value2, 6); - dataSize += sdfile.write('\n'); + sdfile.write('\n'); + dataSize += 4; m_lastDataTime = dataTime; #endif #endif } void logData(uint16_t pid, uint32_t value1, uint32_t value2) { +#if LOG_FORMAT == FORMAT_BIN || STREAM_FORMAT == FORMAT_BIN LOG_DATA_COMM ld = {dataTime, pid, 2, 0, {value1, value2}}; ld.checksum = getChecksum((char*)&ld, 16); +#endif #if ENABLE_DATA_OUT - mySerial.write((uint8_t*)&ld, 16); +#if LOG_FORMAT == FORMAT_BIN + SerialBLE.write((uint8_t*)&ld, 16); +#else + SerialBLE.print(pid, HEX); + SerialBLE.write(','); + SerialBLE.print(value1); + SerialBLE.write(','); + SerialBLE.print(value2); + SerialBLE.write('\n'); +#endif #endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN @@ -242,23 +282,37 @@ public: dataSize += 16; #else dataSize += sdfile.print(dataTime - m_lastDataTime); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(pid, HEX); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value1); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value2); - dataSize += sdfile.write('\n'); + sdfile.write('\n'); + dataSize += 4; m_lastDataTime = dataTime; #endif #endif } void logData(uint16_t pid, int value1, int value2, int value3) { +#if LOG_FORMAT == FORMAT_BIN || STREAM_FORMAT == FORMAT_BIN LOG_DATA_COMM ld = {dataTime, pid, 3, 0, {value1, value2, value3}}; ld.checksum = getChecksum((char*)&ld, 20); +#endif #if ENABLE_DATA_OUT - mySerial.write((uint8_t*)&ld, 20); +#if LOG_FORMAT == FORMAT_BIN + SerialBLE.write((uint8_t*)&ld, 20); +#else + SerialBLE.print(pid, HEX); + SerialBLE.write(','); + SerialBLE.print(value1); + SerialBLE.write(','); + SerialBLE.print(value2); + SerialBLE.write(','); + SerialBLE.print(value3); + SerialBLE.write('\n'); +#endif #endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN @@ -266,21 +320,22 @@ public: dataSize += 20; #else dataSize += sdfile.print(dataTime - m_lastDataTime); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(pid, HEX); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value1); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value2); - dataSize += sdfile.write(','); + sdfile.write(','); dataSize += sdfile.print(value3); - dataSize += sdfile.write('\n'); + sdfile.write('\n'); + dataSize += 5; m_lastDataTime = dataTime; #endif #endif } #if ENABLE_DATA_LOG - uint16_t openFile(LOG_TYPES logType, uint16_t logFlags = 0, uint32_t dateTime = 0) + uint16_t openFile(uint16_t logFlags = 0, uint32_t dateTime = 0) { uint16_t fileIndex; char filename[24] = "/FRMATICS"; @@ -306,7 +361,7 @@ public: } #if LOG_FORMAT == FORMAT_BIN - HEADER hdr = {'UDUS', HEADER_LEN, 1, logType, logFlags, dateTime}; + HEADER hdr = {'UDUS', HEADER_LEN, 1, 0, logFlags, dateTime}; sdfile.write((uint8_t*)&hdr, sizeof(hdr)); for (byte i = 0; i < HEADER_LEN - sizeof(hdr); i++) sdfile.write((uint8_t)0); diff --git a/unologger/unologger.depend b/unologger/unologger.depend deleted file mode 100644 index 54000de..0000000 --- a/unologger/unologger.depend +++ /dev/null @@ -1,73 +0,0 @@ -# depslib dependency file v1.0 -1394947618 source:e:\arduino\arduinoobd\unologger\unologger.ino - - - - - - - "MultiLCD.h" - "images.h" - "config.h" - - "datalogger.h" - -1371033101 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\arduino.h - - - - - - - "binary.h" - "WCharacter.h" - "WString.h" - "HardwareSerial.h" - "pins_arduino.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\binary.h - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\wcharacter.h - - -1371033133 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\wstring.h - - - - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\hardwareserial.h - - "Stream.h" - "USBAPI.h" - -1371032829 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\stream.h - - "Print.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\print.h - - - "WString.h" - "Printable.h" - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\printable.h - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\new.h - - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\cores\arduino\usbapi.h - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\variants\standard\pins_arduino.h - - -1391012219 e:\arduino\arduinoobd\unologger\images.h - -1394948886 e:\arduino\arduinoobd\unologger\config.h - -1391012219 e:\arduino\arduinoobd\unologger\datalogger.h - -1362986950 d:\apps\codeblocks\arduino\hardware\arduino\variants\mega\pins_arduino.h - - diff --git a/unologger/unologger.ino b/unologger/unologger.ino index 61ed24f..49245a6 100644 --- a/unologger/unologger.ino +++ b/unologger/unologger.ino @@ -79,9 +79,6 @@ public: delay(1000); */ - uint16_t flags = FLAG_CAR | FLAG_OBD; - if (state & STATE_GPS_FOUND) flags |= FLAG_GPS; - if (state & STATE_ACC_READY) flags |= FLAG_ACC; #if ENABLE_DATA_LOG uint16_t index = openFile(LOG_TYPE_DEFAULT, flags); lcd.setFont(FONT_SIZE_SMALL); @@ -108,9 +105,10 @@ public: } #endif +#if 0 showECUCap(); delay(3000); - +#endif initScreen(); } void benchmark() @@ -333,7 +331,6 @@ private: } state &= ~STATE_SLEEPING; fileIndex++; - write('\r'); lcd.backlight(true); setup(); } -- cgit v1.2.3