Commit 3ba04ab16116979c026e05c0e2920c2bdf58167b

Authored by Christopher Stone
1 parent 09e0f318
Exists in master

Fixed a few bugs in pollserial, and created an artificial analogue of it for testing

robots/little_john/telemetry/code/monitor/version1/main.py
... ... @@ -8,7 +8,7 @@
8 8 # This code is incomplete, and is missing core features
9 9  
10 10 #import math
11   -#import time
  11 +import time
12 12 #import serial
13 13  
14 14 import pyglet
... ... @@ -57,6 +57,7 @@ class Series:
57 57 self.ylimits = (0, 255)
58 58 self.data = []
59 59 self.points = points
  60 +
60 61 def addpoint(self, point):
61 62 """Add a point to the dataset, and remove the oldest, if necessary"""
62 63 self.data.append(point)
... ... @@ -177,10 +178,19 @@ def pollSerial(elapsed):
177 178 values = datafeed.readline().strip().split(b", ")
178 179 else:
179 180 values = datafeed.readline().strip()
180   - values = str(values).split(", ")
  181 + values = values.split(b', ')
  182 + for n, value in enumerate(values):
  183 + values[n] = float(value)
  184 + logging.info("Recieved data: " + str(values))
  185 + testseries.addpoint(values)
  186 +
  187 +def fakePollSerial(elapsed):
  188 + """This function immitates the behaviour of pollSerial, for testing purposes"""
  189 + values = [time.time(), time.time()%10]
  190 + logging.info("Generated test data: " + str(values))
181 191 testseries.addpoint(values)
182 192  
183 193 # Pyglet looks after the main event loop, but this ensures that data keeps being read in
184   -pyglet.clock.schedule_interval(pollSerial, 0.1)
  194 +pyglet.clock.schedule_interval(fakePollSerial, 0.1)
185 195  
186 196 pyglet.app.run()
... ...