Add CSV-based datalogging.

This commit is contained in:
Solomon Peachy 2019-02-01 12:44:35 -05:00
parent 07f09cf51a
commit 6bf3523da5
4 changed files with 46 additions and 3 deletions

1
TODO
View File

@ -7,6 +7,5 @@ Non-exclusive TODO:
* better use of color
* Additional data
* GPS support
* Data logging
* ???
* Profit

36
aldl.c
View File

@ -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) {

3
aldl.h
View File

@ -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;

View File

@ -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;
}