From ef7ca30b2ea268c01603a1b0dbc9821589377ca4 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sat, 9 Apr 2016 16:51:28 +0200 Subject: added python script Signed-off-by: Olivier Gayot --- reader/reader.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'reader') 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() -- cgit v1.2.3