diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2016-04-09 16:51:28 +0200 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2016-04-09 16:51:28 +0200 |
commit | ef7ca30b2ea268c01603a1b0dbc9821589377ca4 (patch) | |
tree | b1df80e020dbf5fcce5b11f2b66ffe54ce7cbedf | |
parent | e75fb7c47b640ea329984d95fc9f4b2d7cd3efe4 (diff) |
added python script
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | reader/reader.py | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/reader/reader.py b/reader/reader.py index e5a0d9b..8e4fe2c 100644 --- a/reader/reader.py +++ b/reader/reader.py @@ -1 +1,58 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python2 + +from websocket_server import WebsocketServer + +import thread +import serial +import time +import json + +measures = { + 'pressure_bottom': 0, + 'pressure_top': 0, + 'flexion': 0, + 'angle_x': 0, + 'angle_y': 0, + 'angle_z': 0, + } + +def server_procedure(server): + server.run_forever() + +def main(): + server = WebsocketServer(1234, '0.0.0.0') + + thread.start_new_thread(server_procedure, (server,)) + + #with serial.Serial('/dev/ttyACM0', 9600) as ser: + with open('/tmp/fifo') as ser: + while True: + line = ser.readline() + + if not line: + time.sleep(0.01) + continue + + line = line.strip() + + if line.startswith('PRESSURE_BOTTOM:'): + measures['pressure_bottom'] = line.split('PRESSURE_BOTTOM:')[1] + elif line.startswith('PRESSURE_TOP:'): + measures['pressure_top'] = line.split('PRESSURE_TOP:')[1] + elif line.startswith('FLEXION:'): + measures['flexion'] = line.split('FLEXION:')[1] + elif line.startswith('ANGLE_X:'): + measures['angle_x'] = line.split('ANGLE_X:')[1] + elif line.startswith('ANGLE_Y:'): + measures['angle_y'] = line.split('ANGLE_Y:')[1] + elif line.startswith('ANGLE_Z:'): + measures['angle_z'] = line.split('ANGLE_Z:')[1] + else: + print(line) + + server.send_message_to_all(json.dumps(measures)) + + + +if __name__ == '__main__': + main() |