diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-09-11 23:57:39 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-09-11 23:57:39 +0800 |
commit | e24831d6ba903cf3a552ce6bfbc83a6278e176d7 (patch) | |
tree | 69e8fd6f8587902cf366d8b85f4266d35a007d98 /obdlogger | |
parent | 6494578eae63b14a2a34e494455ffad26c758c96 (diff) | |
download | 2021-arduino-obd-e24831d6ba903cf3a552ce6bfbc83a6278e176d7.tar.gz 2021-arduino-obd-e24831d6ba903cf3a552ce6bfbc83a6278e176d7.tar.bz2 2021-arduino-obd-e24831d6ba903cf3a552ce6bfbc83a6278e176d7.zip |
both CSV and binary formats are supported
Diffstat (limited to 'obdlogger')
-rw-r--r-- | obdlogger/datalogger.h | 58 |
1 files changed, 53 insertions, 5 deletions
diff --git a/obdlogger/datalogger.h b/obdlogger/datalogger.h index f02a60d..f8653ca 100644 --- a/obdlogger/datalogger.h +++ b/obdlogger/datalogger.h @@ -1,7 +1,12 @@ // configurations -#define ENABLE_DATA_OUT 0 +#define ENABLE_DATA_OUT 1 #define ENABLE_DATA_LOG 1 +#define FORMAT_BIN 0 +#define FORMAT_CSV 1 + +//this defines the format of log file +#define LOG_FORMAT FORMAT_CSV typedef enum { LOG_TYPE_DEFAULT = 0, LOG_TYPE_0_60, @@ -107,6 +112,9 @@ public: #if ENABLE_DATA_OUT mySerial.begin(9600); #endif +#if ENABLE_DATA_LOG && LOG_FORMAT == FORMAT_CSV + m_lastDataTime = 0; +#endif } #if ENABLE_DATA_OUT void sendFileInfo(File& file) @@ -160,9 +168,19 @@ public: mySerial.write((uint8_t*)&ld, 12); #endif #if ENABLE_DATA_LOG +#if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 12); -#endif dataSize += 12; +#else + dataSize += sdfile.print(dataTime - m_lastDataTime); + dataSize += sdfile.write(','); + dataSize += sdfile.print(pid, HEX); + dataSize += sdfile.write(','); + dataSize += sdfile.print((int)value); + dataSize += sdfile.write('\n'); + m_lastDataTime = dataTime; +#endif +#endif } void logData(uint16_t pid, float value1, float value2) { @@ -172,9 +190,21 @@ public: mySerial.write((uint8_t*)&ld, 16); #endif #if ENABLE_DATA_LOG +#if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 16); -#endif dataSize += 16; +#else + dataSize += sdfile.print(dataTime - m_lastDataTime); + dataSize += sdfile.write(','); + dataSize += sdfile.print(pid, HEX); + dataSize += sdfile.write(','); + dataSize += sdfile.print(value1, 6); + dataSize += sdfile.write(' '); + dataSize += sdfile.print(value2, 6); + dataSize += sdfile.write('\n'); + m_lastDataTime = dataTime; +#endif +#endif } void logData(uint16_t pid, float value1, float value2, float value3) { @@ -184,9 +214,23 @@ public: mySerial.write((uint8_t*)&ld, 20); #endif #if ENABLE_DATA_LOG +#if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 20); -#endif dataSize += 20; +#else + dataSize += sdfile.print(dataTime - m_lastDataTime); + dataSize += sdfile.write(','); + dataSize += sdfile.print(pid, HEX); + dataSize += sdfile.write(','); + dataSize += sdfile.print((int)value1); + dataSize += sdfile.write(' '); + dataSize += sdfile.print((int)value2); + dataSize += sdfile.write(' '); + dataSize += sdfile.print((int)value3); + dataSize += sdfile.write('\n'); + m_lastDataTime = dataTime; +#endif +#endif } #if ENABLE_DATA_LOG uint16_t openFile(LOG_TYPES logType, uint16_t logFlags = 0, uint32_t dateTime = 0) @@ -214,12 +258,13 @@ public: return 0; } +#if LOG_FORMAT == FORMAT_BIN HEADER hdr = {'UDUS', HEADER_LEN, 1, logType, logFlags, dateTime}; sdfile.write((uint8_t*)&hdr, sizeof(hdr)); for (byte i = 0; i < HEADER_LEN - sizeof(hdr); i++) sdfile.write((uint8_t)0); dataSize = HEADER_LEN; - sdfile.flush(); +#endif return fileIndex; } void closeFile() @@ -244,5 +289,8 @@ private: } #if ENABLE_DATA_LOG File sdfile; +#if LOG_FORMAT == FORMAT_CSV + uint32_t m_lastDataTime; +#endif #endif }; |