From e494891c8cb7a47279d5ce514850fa855e64ab0c Mon Sep 17 00:00:00 2001 From: Stanley Huang Date: Sun, 17 May 2015 23:29:14 +1000 Subject: No more unologger --- unologger/README.txt | 11 - unologger/config.h | 42 ---- unologger/datalogger.h | 201 ---------------- unologger/unologger.cbp | 598 ------------------------------------------------ unologger/unologger.ino | 455 ------------------------------------ 5 files changed, 1307 deletions(-) delete mode 100644 unologger/README.txt delete mode 100644 unologger/config.h delete mode 100644 unologger/datalogger.h delete mode 100644 unologger/unologger.cbp delete mode 100644 unologger/unologger.ino diff --git a/unologger/README.txt b/unologger/README.txt deleted file mode 100644 index 217971f..0000000 --- a/unologger/README.txt +++ /dev/null @@ -1,11 +0,0 @@ -This is the source code for the Arduino OBD-II data logger, which displays (on a 128x64 OLED display module) and records (to a SD card) a selected set of OBD-II data. For hardware configuration and wiring guide, please refer to: -http://obd.arduinodev.com - -The recorded data is stored in CSV format and the file can be illustrated into a graphic chart by a free service at: -http://freematics.com/chart/ - -To compile the code with Arduino IDE, please copy all library files from the libraries directory to Arduino's libraries directory. - -To open the project file (obdlogger.cbp), please download CodeBlocks Arduino Edition (http://arduinodev.com/codeblocks). - -The source code is distributed under GPL license. diff --git a/unologger/config.h b/unologger/config.h deleted file mode 100644 index 76b4dbe..0000000 --- a/unologger/config.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CONFIG_H_INCLUDED -#define CONFIG_H_INCLUDED - -/************************************** -* Choose model of OBD-II Adapter -**************************************/ -// OBD_MODEL_I2C for I2C version -// OBD_MODEL_UART for UART version -#define OBD_MODEL OBD_MODEL_UART -#define OBD_PROTOCOL PROTO_AUTO - -/************************************** -* Data logging options -**************************************/ -// enable(1)/disable(0) data logging (if SD card is present) -#define ENABLE_DATA_LOG 1 -#define SD_CS_PIN 10 - -/************************************** -* Data streaming options -**************************************/ -// data streaming is not supported on Arduino UNO -#define ENABLE_DATA_OUT 0 - -/************************************** -* Accelerometer & Gyro -**************************************/ -//#define USE_MPU6050 1 -//#define USE_MPU9150 1 - -/************************************** -* Timeout/interval options -**************************************/ -#define OBD_MIN_INTERVAL 20 /* ms */ - -/************************************** -* LCD module (uncomment only one) -**************************************/ -LCD_ILI9341 lcd; /* 2.4" ILI9341 based SPI TFT LCD */ -//LCD_Null lcd; - -#endif diff --git a/unologger/datalogger.h b/unologger/datalogger.h deleted file mode 100644 index 2a58bf3..0000000 --- a/unologger/datalogger.h +++ /dev/null @@ -1,201 +0,0 @@ -/************************************************************************* -* Arduino Data Logger Class -* Distributed under GPL v2.0 -* Copyright (c) 2013-2014 Stanley Huang -* All rights reserved. -* Visit http://freematics.com for more information -*************************************************************************/ - -#define FORMAT_BIN 0 -#define FORMAT_CSV 1 - -typedef struct { - uint32_t time; - uint16_t pid; - uint8_t flags; - uint8_t checksum; - float value[3]; -} LOG_DATA_COMM; - -#define HEADER_LEN 128 /* bytes */ - -#define PID_GPS_LATITUDE 0xA -#define PID_GPS_LONGITUDE 0xB -#define PID_GPS_ALTITUDE 0xC -#define PID_GPS_SPEED 0xD -#define PID_GPS_HEADING 0xE -#define PID_GPS_SAT_COUNT 0xF -#define PID_GPS_TIME 0x10 -#define PID_GPS_DATE 0x11 - -#define PID_ACC 0x20 -#define PID_GYRO 0x21 -#define PID_COMPASS 0x22 -#define PID_MEMS_TEMP 0x23 -#define PID_BATTERY_VOLTAGE 0x24 - -#define FILE_NAME_FORMAT "/DAT%05d.CSV" - -#if ENABLE_DATA_OUT - -#if USE_SOFTSERIAL - -#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__) - SoftwareSerial SerialBLE(A8, A9); /* for BLE Shield on MEGA*/ -#else - SoftwareSerial SerialBLE(A2, A3); /* for BLE Shield on UNO/leonardo*/ -#endif - -#else - -#define SerialBLE Serial3 - -#endif - -#endif - -#if ENABLE_DATA_LOG -static File sdfile; -#endif - -static const char* idstr = "FREEMATICS\r"; - -class CDataLogger { -public: - void initSender() - { -#if ENABLE_DATA_OUT - SerialBLE.begin(STREAM_BAUDRATE); - SerialBLE.print(idstr); -#endif -#if ENABLE_DATA_LOG - m_lastDataTime = 0; -#endif - } - void logTimeElapsed() - { -#if ENABLE_DATA_LOG - dataSize += sdfile.print(dataTime - m_lastDataTime); - sdfile.write(','); - dataSize++; - m_lastDataTime = dataTime; -#endif - } - void logData(char c) - { -#if ENABLE_DATA_OUT && STREAM_FORMAT == FORMAT_CSV - SerialBLE.write(c); -#endif -#if ENABLE_DATA_LOG - if (c >= ' ') { - sdfile.write(c); - dataSize++; - } -#endif - } - void logData(uint16_t pid, int value) - { - char buf[16]; - byte n = sprintf(buf, "%X,%d\r", pid, value); -#if ENABLE_DATA_OUT -#if STREAM_FORMAT == FORMAT_BIN - LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; - ld.checksum = getChecksum((char*)&ld, 12); - SerialBLE.write((uint8_t*)&ld, 12); -#else - SerialBLE.write((uint8_t*)buf, n); -#endif -#endif -#if ENABLE_DATA_LOG - logTimeElapsed(); - dataSize += sdfile.write((uint8_t*)buf, n); -#endif - } - void logData(uint16_t pid, int32_t value) - { - char buf[20]; - byte n = sprintf(buf, "%X,%ld\r", pid, value); -#if ENABLE_DATA_OUT -#if STREAM_FORMAT == FORMAT_BIN - LOG_DATA_COMM ld = {dataTime, pid, 1, 0, value}; - ld.checksum = getChecksum((char*)&ld, 12); - SerialBLE.write((uint8_t*)&ld, 12); -#else - SerialBLE.write((uint8_t*)buf, n); -#endif -#endif -#if ENABLE_DATA_LOG - logTimeElapsed(); - dataSize += sdfile.write((uint8_t*)buf, n); -#endif - } - void logData(uint16_t pid, int value1, int value2, int value3) - { - char buf[24]; - byte n = sprintf(buf, "%X,%d,%d,%d\r", pid, value1, value2, value3); -#if ENABLE_DATA_OUT -#if STREAM_FORMAT == FORMAT_BIN - LOG_DATA_COMM ld = {dataTime, pid, 3, 0, {value1, value2, value3}}; - ld.checksum = getChecksum((char*)&ld, 20); - SerialBLE.write((uint8_t*)&ld, 20); -#else - SerialBLE.write((uint8_t*)buf, n); -#endif -#endif -#if ENABLE_DATA_LOG - logTimeElapsed(); - dataSize += sdfile.write((uint8_t*)buf, n); -#endif - } -#if ENABLE_DATA_LOG - uint16_t openFile(uint16_t logFlags = 0, uint32_t dateTime = 0) - { - uint16_t fileIndex; - char filename[24] = "/FRMATICS"; - - dataSize = 0; - if (SD.exists(filename)) { - for (fileIndex = 1; fileIndex; fileIndex++) { - sprintf(filename + 9, FILE_NAME_FORMAT, fileIndex); - if (!SD.exists(filename)) { - break; - } - } - if (fileIndex == 0) - return 0; - } else { - SD.mkdir(filename); - fileIndex = 1; - sprintf(filename + 9, FILE_NAME_FORMAT, 1); - } - - sdfile = SD.open(filename, FILE_WRITE); - if (!sdfile) { - return 0; - } - return fileIndex; - } - void closeFile() - { - sdfile.close(); - } - void flushFile() - { - sdfile.flush(); - } -#endif - uint32_t dataTime; - uint32_t dataSize; -private: - byte getChecksum(char* buffer, byte len) - { - uint8_t checksum = 0; - for (byte i = 0; i < len; i++) { - checksum ^= buffer[i]; - } - return checksum; - } -#if ENABLE_DATA_LOG - uint32_t m_lastDataTime; -#endif -}; diff --git a/unologger/unologger.cbp b/unologger/unologger.cbp deleted file mode 100644 index ad04efc..0000000 --- a/unologger/unologger.cbp +++ /dev/null @@ -1,598 +0,0 @@ - - - - - - diff --git a/unologger/unologger.ino b/unologger/unologger.ino deleted file mode 100644 index ba7f0a7..0000000 --- a/unologger/unologger.ino +++ /dev/null @@ -1,455 +0,0 @@ -/************************************************************************* -* Arduino OBD-II/G-Force Data Logger -* Distributed under GPL v2.0 -* Copyright (c) 2013 Stanley Huang -* All rights reserved. -*************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include "MultiLCD.h" -#include "config.h" -#include "datalogger.h" - -#define STATE_SD_READY 0x1 -#define STATE_OBD_READY 0x2 -#define STATE_MEMS_READY 0x10 -#define STATE_SLEEPING 0x20 - -#define OBD_MODEL_UART 0 -#define OBD_MODEL_I2C 1 - -static uint32_t lastFileSize = 0; -static int speed = 0; -static uint32_t distance = 0; -static uint16_t fileIndex = 0; -static uint32_t startTime = 0; -static uint16_t elapsed = 0; -static uint8_t lastPid = 0; -static int lastValue = 0; - -#if USE_MPU6050 || USE_MPU9150 -MPU6050 accelgyro; -#endif - -static byte pidTier1[]= {PID_RPM, PID_SPEED, PID_ENGINE_LOAD, PID_THROTTLE, PID_INTAKE_MAP}; -static byte pidTier2[] = {PID_COOLANT_TEMP, PID_INTAKE_TEMP, PID_AMBIENT_TEMP, PID_FUEL_LEVEL, PID_DISTANCE}; - -#define TIER_NUM1 sizeof(pidTier1) -#define TIER_NUM2 sizeof(pidTier2) - -#if OBD_MODEL == OBD_MODEL_UART -class COBDLogger : public COBD, public CDataLogger -#else -class COBDLogger : public COBDI2C, public CDataLogger -#endif -{ -public: - COBDLogger():state(0) {} - void setup() - { - showStates(); - -#if USE_MPU6050 || USE_MPU9150 - Wire.begin(); - accelgyro.initialize(); - if (accelgyro.testConnection()) state |= STATE_MEMS_READY; -#endif - - do { - showStates(); - } while (!init(OBD_PROTOCOL)); - - state |= STATE_OBD_READY; - - showStates(); - - benchmark(); - delay(5000); - -#if ENABLE_DATA_LOG - // open file for logging - if (!(state & STATE_SD_READY)) { - lcd.setFontSize(FONT_SIZE_MEDIUM); - lcd.setCursor(0, 10); - if (checkSD()) { - state |= STATE_SD_READY; - uint16_t index = openFile(); - lcd.setCursor(0, 12); - if (index) { - lcd.print("File ID: "); - lcd.print(index); - } else { - lcd.print("No File"); - } - delay(1000); - } - } -#endif - - initScreen(); - } - void benchmark() - { - lcd.setFontSize(FONT_SIZE_MEDIUM); - - char buf[OBD_RECV_BUF_SIZE]; - uint8_t count = 0; - startTime = millis(); - for (uint8_t n = 0; n < TIER_NUM1; n++) { - sendQuery(pidTier1[n]); - lcd.write('['); - lcd.print(millis()); - lcd.write(']'); - lcd.println(pidTier1[n], HEX); - memset(buf, 0, sizeof(buf)); - if (receive(buf) > 0) { - lcd.println(buf); - count++; - } - } - lcd.setCursor(0, 28); - if (count) { - lcd.print("OBD Time: "); - lcd.printInt((millis() - startTime) / count); - lcd.print("ms"); - } else { - lcd.print("No PID!"); - } - } - void loop() - { - static byte index = 0; - static byte index2 = 0; - static byte index3 = 0; - - logOBDData(pidTier1[index++]); - if (index == TIER_NUM1) { - index = 0; - if (index2 == TIER_NUM2) { - index2 = 0; - } else { - logOBDData(pidTier2[index2++]); - } - } - -#if USE_MPU6050 - if (state & STATE_MEMS_READY) { - processAccelerometer(); - } -#endif - if (errors >= 5) { - reconnect(); - } - } -#if ENABLE_DATA_LOG - bool checkSD() - { - Sd2Card card; - SdVolume volume; - state &= ~STATE_SD_READY; - pinMode(SD_CS_PIN, OUTPUT); - if (card.init(SPI_FULL_SPEED, SD_CS_PIN)) { - const char* type; - - lcd.print("SD"); - switch(card.type()) { - case SD_CARD_TYPE_SD1: - type = "1"; - break; - case SD_CARD_TYPE_SD2: - type = "2"; - break; - case SD_CARD_TYPE_SDHC: - type = "HC"; - break; - default: - type = "x"; - } - - lcd.print(type); - lcd.write(' '); - if (!volume.init(card)) { - lcd.print("No FAT"); - return false; - } - - uint32_t volumesize = volume.blocksPerCluster(); - volumesize >>= 1; // 512 bytes per block - volumesize *= volume.clusterCount(); - volumesize >>= 10; - - lcd.print((int)((volumesize + 511) / 1000)); - lcd.print("GB"); - } else { - lcd.print("SD: No"); - digitalWrite(SD_CS_PIN, HIGH); - return false; - } - - if (!SD.begin(SD_CS_PIN)) { - lcd.print("Bad"); - return false; - } - - state |= STATE_SD_READY; - return true; - } -#endif - void initScreen() - { - initLoggerScreen(); - } -private: - void dataIdleLoop() - { - if (lastPid) { - showData(lastPid, lastValue); - lastPid = 0; - } - uint16_t t = (millis() - startTime) >> 10; - if (t != elapsed) { - lcd.setFontSize(FONT_SIZE_MEDIUM); - lcd.setCursor(260, 8); - lcd.printInt(elapsed / 60, 2); - lcd.write(':'); - lcd.setFlags(FLAG_PAD_ZERO); - lcd.printInt(elapsed % 60, 2); - lcd.setFlags(0); - elapsed = t; - } - -#if ENABLE_DATA_LOG - // flush SD data every 1KB - if (dataSize - lastFileSize >= 1024) { - flushFile(); - lastFileSize = dataSize; - // display logged data size - lcd.setCursor(260, 11); - lcd.printInt(dataSize >> 10, 4); - } -#endif - } -#if USE_MPU6050 - void processAccelerometer() - { -#if USE_MPU6050 || USE_MPU9150 - int16_t ax, ay, az; - int16_t gx, gy, gz; -#if USE_MPU9150 - int16_t mx, my, mz; -#endif - -#if USE_MPU9150 - accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz); -#else - accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); -#endif - - dataTime = millis(); - - // log x/y/z of accelerometer - logData(PID_ACC, ax, ay, az); - // log x/y/z of gyro meter - logData(PID_GYRO, gx, gy, gz); -#if USE_MPU9150 - // log x/y/z of compass - logData(PID_COMPASS, mx, my, mz); -#endif -#endif - } -#endif - void logOBDData(byte pid) - { - int value; - // send a query to OBD adapter for specified OBD-II pid - - // receive and parse the response - if (read(pid, value)) { - dataTime = millis(); - // log data to SD card - logData(0x100 | pid, value); - lastValue = value; - lastPid = pid; - errors = 0; - } else { - errors++; - return; - } - } - void reconnect() - { -#if ENABLE_DATA_LOG - closeFile(); -#endif - lcd.clear(); - lcd.setFontSize(FONT_SIZE_MEDIUM); - lcd.print("Reconnecting"); - startTime = millis(); - state &= ~(STATE_OBD_READY | STATE_MEMS_READY); - state |= STATE_SLEEPING; - //digitalWrite(SD_CS_PIN, LOW); - for (uint16_t i = 0; ; i++) { - if (i == 5) { - lcd.setBackLight(0); - lcd.clear(); - } - if (init()) { - int value; - if (read(PID_RPM, value) && value > 0) - break; - } - } - state &= ~STATE_SLEEPING; - fileIndex++; - lcd.setBackLight(255); - setup(); - } - // screen layout related stuff - void showStates() - { - lcd.setFontSize(FONT_SIZE_MEDIUM); - lcd.setCursor(0, 6); - lcd.print("OBD "); - if (state & STATE_OBD_READY) lcd.print("OK"); -#if USE_MPU6050 || USE_MPU9150 - lcd.setCursor(0, 8); - lcd.print("MEMS "); - if (state & STATE_MEMS_READY) lcd.print("OK"); -#endif - } - void showData(byte pid, int value) - { - switch (pid) { - case PID_RPM: - lcd.setCursor(0, 2); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt((unsigned int)value % 10000, 4); - showChart(value); - break; - case PID_SPEED: - lcd.setCursor(90, 2); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt((unsigned int)value % 1000, 3); - break; - case PID_ENGINE_LOAD: - lcd.setCursor(164, 2); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt(value % 100, 3); - break; - case PID_INTAKE_TEMP: - if ((uint16_t)value < 1000) { - lcd.setCursor(248, 2); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt(value, 3); - } - break; - case PID_INTAKE_MAP: - lcd.setCursor(164, 9); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt((uint16_t)value % 1000, 3); - break; - case PID_COOLANT_TEMP: - lcd.setCursor(8, 9); - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.printInt((uint16_t)value % 1000, 3); - break; - case PID_DISTANCE: - lcd.setFontSize(FONT_SIZE_XLARGE); - lcd.setCursor(90, 9); - lcd.printInt((uint16_t)value % 1000, 3); - break; - } - } - void showChart(int value) - { - static uint16_t pos = 0; - if (value >= 500) { - byte n = (value - 600) / 30; - if (n > 130) n = 130; - lcd.fill(pos, pos, 239 - n, 239, RGB16_CYAN); - } - pos = (pos + 1) % 320; - lcd.fill(pos, pos, 110, 239); - } - void initLoggerScreen() - { - lcd.clear(); - lcd.setBackLight(255); - lcd.setFontSize(FONT_SIZE_SMALL); - lcd.setColor(RGB16_CYAN); - lcd.setCursor(4, 0); - lcd.print("ENGINE RPM"); - lcd.setCursor(104, 0); - lcd.print("SPEED"); - lcd.setCursor(164, 0); - lcd.print("ENGINE LOAD"); - lcd.setCursor(248, 0); - lcd.print("INTAKE TEMP"); - - lcd.setCursor(4, 7); - lcd.print("COOLANT TEMP"); - lcd.setCursor(104, 7); - lcd.print("DISTANCE"); - lcd.setCursor(164, 7); - lcd.print("INTAKE MAP"); - - lcd.setCursor(260, 7); - lcd.print("ELAPSED"); - lcd.setCursor(260, 10); - lcd.print("LOG SIZE"); - - lcd.setColor(RGB16_YELLOW); - lcd.setCursor(24, 5); - lcd.print("rpm"); - lcd.setCursor(110, 5); - lcd.print("km/h"); - lcd.setCursor(216, 4); - lcd.print("%"); - lcd.setCursor(304, 4); - lcd.print("C"); - lcd.setCursor(64, 11); - lcd.print("C"); - lcd.setCursor(110, 12); - lcd.print("km"); - lcd.setCursor(200, 12); - lcd.print("kpa"); - lcd.setCursor(296, 12); - lcd.print("KB"); - - lcd.setColor(RGB16_WHITE); - - - //lcd.setCursor(0, 5); - //lcd.print("THR: %"); - //lcd.setCursor(80, 5); - //lcd.print("AIR: C"); - } - byte state; -}; - -static COBDLogger logger; - -void setup() -{ - lcd.begin(); - lcd.setFontSize(FONT_SIZE_MEDIUM); - lcd.setColor(RGB16_YELLOW); - lcd.println("UNOLOGGER"); - lcd.setColor(RGB16_WHITE); - - logger.begin(); - logger.initSender(); - - logger.setup(); -} - -void loop() -{ - logger.loop(); -} -- cgit v1.2.3