summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2019-02-01 12:44:35 -0500
committerSolomon Peachy <pizza@shaftnet.org>2019-02-01 13:05:36 -0500
commit6bf3523da5bb1a2e038a12485cbbd965b21c2207 (patch)
tree4ca23c41fbab429f82345c584c6d245cf2a999b5
parent07f09cf51adc786b38c52b7220c1add47da35bd3 (diff)
downloadaldl_pi-6bf3523da5bb1a2e038a12485cbbd965b21c2207.tar.gz
aldl_pi-6bf3523da5bb1a2e038a12485cbbd965b21c2207.tar.bz2
aldl_pi-6bf3523da5bb1a2e038a12485cbbd965b21c2207.zip
Add CSV-based datalogging.
-rw-r--r--TODO3
-rw-r--r--aldl.c36
-rw-r--r--aldl.h3
-rw-r--r--aldl_pi.c7
4 files changed, 46 insertions, 3 deletions
diff --git a/TODO b/TODO
index 0a9a8e0..135ee65 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,5 @@
Non-exclusive TODO:
-
+
* Test it out on an actual vehicle!
* Additional data streams (patches welcome!)
* Better flesh out dashboard
@@ -7,6 +7,5 @@ Non-exclusive TODO:
* better use of color
* Additional data
* GPS support
- * Data logging
* ???
* Profit
diff --git a/aldl.c b/aldl.c
index 9d4deb7..5435de2 100644
--- a/aldl.c
+++ b/aldl.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <time.h>
#include <unistd.h>
#include "aldl.h"
@@ -43,10 +44,43 @@ static uint8_t data[MAX_STREAM_WORDS];
int gotsync = 0;
+static FILE *datalog_handle;
+
struct stream_common decoded = { 0 };
void (*aldl_callback)(uint8_t *data, int datalen) = NULL;
+
+/* Datalogging */
+void datalog_init(char *fname)
+{
+ datalog_handle = fopen(fname, "a");
+ if (!datalog_handle)
+ perror("Can't open datalog file!\n");
+ fprintf(datalog_handle, "# New session\n");
+}
+
+void datalog_close(void)
+{
+ if (datalog_handle)
+ fclose(datalog_handle);
+}
+
+static void aldl_datalog(uint8_t *data, int datalen)
+{
+ int i;
+
+ if (!datalog_handle) return;
+
+ fprintf(datalog_handle, "%ld", time(NULL));
+
+ for (i = 0 ; i < datalen ; i++) {
+ fprintf(datalog_handle, ",%02x", *data++);
+ }
+ fprintf(datalog_handle, "\n");
+}
+
+/* ISR */
void isrfn(void)
{
int val;
@@ -67,6 +101,8 @@ void isrfn(void)
/* New sync word, we've finished a sequence */
if (aldl_callback)
aldl_callback(data, datalen);
+ if (datalog_handle)
+ aldl_datalog(data, datalen);
bits = 0;
datalen = 0;
} else if (++bits == 9) {
diff --git a/aldl.h b/aldl.h
index 89ac2c3..848b4af 100644
--- a/aldl.h
+++ b/aldl.h
@@ -38,6 +38,9 @@ extern void (*aldl_callback)(uint8_t *data, int datalen);
int init_dash(void);
int render_dash(void);
+void datalog_init(char *fname);
+void datalog_close(void);
+
/* Decoded data stream */
struct stream_common {
uint16_t heartbeat;
diff --git a/aldl_pi.c b/aldl_pi.c
index 1069536..c4a5ea7 100644
--- a/aldl_pi.c
+++ b/aldl_pi.c
@@ -38,6 +38,8 @@
/* What pin? */
#define ALDL_PIN_IN 5
+static char *datalog_fname = "DATALOG.csv";
+
int readbit(void)
{
return digitalRead(ALDL_PIN_IN);
@@ -47,6 +49,7 @@ void delayfn(int ms)
delay(1);
}
+/* Main */
int main (int argc, char **argv)
{
/* Set up RPi GPIO */
@@ -57,7 +60,7 @@ int main (int argc, char **argv)
wiringPiISR (ALDL_PIN_IN, INT_EDGE_FALLING, &isrfn);
- aldl_callback = aldl_a179_callback;
+ datalog_init(datalog_fname);
if (init_dash())
return -1;
@@ -67,5 +70,7 @@ int main (int argc, char **argv)
sleep(1);
}
+ datalog_close();
+
return 0;
}