Skip to content

Commit

Permalink
Add timestamps
Browse files Browse the repository at this point in the history
Add newlines after each sample, insert a timestamp once per minute,
and don't forget to flush().

Also fix syntax errors from missing colons and function arguments.
  • Loading branch information
liliakai committed Sep 11, 2012
1 parent 4390981 commit 3ef78e7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python
import os
import time
import serial

def filename(i):
Expand All @@ -24,14 +25,14 @@ def open_file():

return open(logdir + '/' + filename(i), 'w')

def parse_packet(packet)
def parse_packet(packet):
length = len(packet)
result = 0
for i in range(length):
result |= (packet[length - 1 - i] & 0x7F) << 7*i
return result

def read_packet(port)
def read_packet(port):
while True:
data = ord(port.read(1))
if (data & 0x80) != 0:
Expand All @@ -42,8 +43,17 @@ def main():
outfile = open_file()
port = open_serial()

lasttime = time.time()
while True:
outfile.write(read_packet())
outfile.write(str(read_packet(port)))
outfile.write('\n')
if time.time() - lasttime > 60:
lasttime = time.time()
stamp = 'time ' + str(int(time.time()))
outfile.write(stamp)
outfile.write('\n')
print stamp
outfile.flush()

outfile.close()
port.close()
Expand Down

0 comments on commit 3ef78e7

Please sign in to comment.