Skip to content

Commit

Permalink
dump-serial should now stop when USB cable is unplugged
Browse files Browse the repository at this point in the history
  • Loading branch information
Randy Sargent committed Feb 6, 2011
1 parent 95f3257 commit e90795b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ hex2binary
junkyard
gnuplot.script
dump-serial
trim-ff
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BINARIES=hex2binary dump-serial
BINARIES=hex2binary dump-serial trim-ff
all: $(BINARIES)

dump-serial: dump-serial.cpp
Expand All @@ -7,6 +7,9 @@ dump-serial: dump-serial.cpp
hex2binary: hex2binary.c
gcc -Wall hex2binary.c -o hex2binary

trim-ff: trim-ff.cpp
g++ -Wall trim-ff.cpp -o trim-ff

clean:
rm -f $(BINARIES)

Expand Down
13 changes: 11 additions & 2 deletions dump-serial.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char **argv)
{
Expand All @@ -11,14 +12,22 @@ int main(int argc, char **argv)
char buf[200];
sprintf(buf, "stty -f %s 38400 -crtscts", filename);
system(buf);
sprintf(buf, "stty -f %s", filename);
system(buf);

fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | ~O_NONBLOCK);

time_t t;
time(&t);
fprintf(stderr, "Capture starting at %s\n", ctime(&t));

while (1) {
int c = getc(in);
if (c == EOF) break; // happens when there's an error reading, e.g. USB cable is unplugged
putchar(c);
fflush(stdout);
}

time(&t);
fprintf(stderr, "Capture ending at %s\n", ctime(&t));

return 0;
}
18 changes: 12 additions & 6 deletions raw2csv/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATE ?= 110205
DATE ?= 110206

ZEOS = $(wildcard *.zeo)
CSVS = $(patsubst %.zeo,%.hypnogram.csv,$(ZEOS))
Expand All @@ -16,18 +16,24 @@ current: anne-$(DATE).hypnogram.csv
sync:
rsync -av john-2.local:/Users/anne/education/bodytrack/zeologger/raw-data/\*.zeo .

connect:
connect.sh anne-$(DATE).zeo
follow:
ssh john-2.local tail -f -c +0 /Users/anne/education/bodytrack/zeologger/raw-data/anne-$(DATE).zeo > data/anne-$(DATE).zeo

follow-ekg:
ssh john-2.local tail -f -c +0 /Users/anne/education/bodytrack/zeologger/raw-data/anne-ekg-$(DATE).zeo > data/anne-ekg-$(DATE).zeo

csv:
-./raw2csv.py -f anne-$(DATE).zeo
-./raw2csv.py -f data/anne-$(DATE).zeo

csv-ekg:
-./raw2csv.py -f data/anne-ekg-$(DATE).zeo

plot-follow:
echo "set datafile separator ','" > gnuplot.script
echo "set xdata time" >> gnuplot.script
echo "set timefmt '%m/%d/%Y %H:%M:%S'" >> gnuplot.script
echo "set format x '%H:%M:%S'" >> gnuplot.script
echo "plot 'anne-$(DATE).hypnogram.csv' every ::2 using 1:6" >> gnuplot.script
echo "plot 'data/anne-$(DATE).hypnogram.csv' every ::2 using 1:6 with impulses" >> gnuplot.script
echo "! sleep 5" >> gnuplot.script
echo "reread" >> gnuplot.script
gnuplot gnuplot.script
Expand All @@ -37,7 +43,7 @@ plot:
echo "set xdata time" >> gnuplot.script
echo "set timefmt '%m/%d/%Y %H:%M:%S'" >> gnuplot.script
echo "set format x '%H:%M:%S'" >> gnuplot.script
echo "plot 'anne-$(DATE).hypnogram.csv' every ::2 using 1:6" >> gnuplot.script
echo "plot 'data/anne-$(DATE).hypnogram.csv' every ::2 using 1:6" >> gnuplot.script
gnuplot -p gnuplot.script


Expand Down
4 changes: 0 additions & 4 deletions raw2csv/connect.sh

This file was deleted.

File renamed without changes.
15 changes: 15 additions & 0 deletions trim-ff.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>

int main(int argc, char **argv)
{
int ff_count = 0;
while (1) {
int c = getchar();
if (c == EOF) break;
if (c == 0xff) ff_count++;
else {
for(; ff_count; ff_count--) { putchar(0xff); }
putchar(c);
}
}
}

0 comments on commit e90795b

Please sign in to comment.