From cabaa89f83d4e6124728f005c50fb0da8cbd0935 Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Sun, 27 Oct 2013 23:33:11 +1100 Subject: add config.h for placing all configurations --- megalogger/datalogger.h | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'megalogger/datalogger.h') diff --git a/megalogger/datalogger.h b/megalogger/datalogger.h index caffd51..281d50c 100644 --- a/megalogger/datalogger.h +++ b/megalogger/datalogger.h @@ -1,13 +1,3 @@ -// configurations -#define ENABLE_DATA_OUT 0 -#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, @@ -24,6 +14,9 @@ typedef enum { #define FLAG_GPS 0x20 #define FLAG_ACC 0x40 +#define FORMAT_BIN 0 +#define FORMAT_CSV 1 + typedef struct { uint32_t time; uint16_t pid; @@ -100,7 +93,7 @@ typedef struct { #define FILE_NAME_FORMAT "/DAT%05d.CSV" #endif -#if ENABLE_DATA_OUT +#if ENABLE_DATA_OUT && !USE_OBD_BT #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) SoftwareSerial mySerial(A8, A9); /* for BLE Shield on MEGA*/ #elif defined(__AVR_ATmega644P__) @@ -110,13 +103,20 @@ typedef struct { #endif #endif +void btInit(int baudrate); +void btSend(byte* data, byte length); + class CDataLogger { public: void initSender() { #if ENABLE_DATA_OUT +#if USE_OBD_BT + btInit(9600); +#else mySerial.begin(9600); #endif +#endif #if ENABLE_DATA_LOG && LOG_FORMAT == FORMAT_CSV m_lastDataTime = 0; #endif @@ -140,17 +140,26 @@ public: info.logType = hdr.logType; info.logFlags = hdr.flags; info.checksum = getChecksum((char*)&info, sizeof(info)); +#if USE_OBD_BT + btSend((uint8_t*)&info, sizeof(info)); +#else mySerial.write((uint8_t*)&info, sizeof(info)); +#endif } 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)); +#if USE_OBD_BT + btSend((uint8_t*)&msg, sizeof(msg)); +#else mySerial.write((uint8_t*)&msg, sizeof(msg)); +#endif } bool receiveCommand(LOG_DATA_COMMAND& msg) { +#if !USE_OBD_BT if (!mySerial.available()) return false; @@ -162,6 +171,7 @@ public: if (getChecksum((char*)&msg, sizeof(msg)) != msg.checksum) { return false; } +#endif return true; } #endif @@ -170,8 +180,12 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; ld.checksum = getChecksum((char*)&ld, 12); #if ENABLE_DATA_OUT +#if USE_OBD_BT + btSend((uint8_t*)&ld, 12); +#else mySerial.write((uint8_t*)&ld, 12); #endif +#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 12); @@ -192,8 +206,12 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 2, 0, {value1, value2}}; ld.checksum = getChecksum((char*)&ld, 16); #if ENABLE_DATA_OUT +#if USE_OBD_BT + btSend((uint8_t*)&ld, 16); +#else mySerial.write((uint8_t*)&ld, 16); #endif +#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 16); @@ -216,8 +234,12 @@ public: LOG_DATA_COMM ld = {dataTime, pid, 3, 0, {value1, value2, value3}}; ld.checksum = getChecksum((char*)&ld, 20); #if ENABLE_DATA_OUT +#if USE_OBD_BT + btSend((uint8_t*)&ld, 20); +#else mySerial.write((uint8_t*)&ld, 20); #endif +#endif #if ENABLE_DATA_LOG #if LOG_FORMAT == FORMAT_BIN sdfile.write((uint8_t*)&ld, 20); -- cgit v1.2.3