From e4162538ea3481c1f1642705067aff4ec4fb0108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Thu, 4 Dec 2014 16:38:55 +0100 Subject: [PATCH] last changes before test run --- sensors2osc/sensors2osc/common.py | 21 ++++++++++++--------- sensors2osc/sensors2osc/ekg2osc.py | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/sensors2osc/sensors2osc/common.py b/sensors2osc/sensors2osc/common.py index 6779cab..46d432f 100644 --- a/sensors2osc/sensors2osc/common.py +++ b/sensors2osc/sensors2osc/common.py @@ -80,21 +80,24 @@ class Platform(object): def create_args(name): arg_parser = ArgParser(name) arg_parser.add_global_group() - main_group = arg_parser.add_argument_group("main") - arg_parser.add_argument(main_group, "-D", '--device', - help='device node under /dev') - arg_parser.add_argument(main_group, "-a", '--actor', - help='actor name') - arg_parser.add_argument(main_group, '-b', '--baudrate', type=int, default=115200, choices=sorted(serial.baudrate_constants.keys()), - help='selects the baudrate, default=115200, for valid values execute "import serial;print sorted(serial.baudrate_constants.keys())"') arg_parser.add_chaosc_group() + client_group = arg_parser.add_client_group() + arg_parser.add_argument(client_group, "-D", '--device', + help='device node under /dev') + arg_parser.add_argument(client_group, "-a", '--actor', + help='actor name') + arg_parser.add_argument(client_group, '-b', '--baudrate', type=int, default=115200, choices=sorted(serial.baudrate_constants.keys()), + help='selects the baudrate, default=115200, for valid values execute "import serial;print sorted(serial.baudrate_constants.keys())"') args = arg_parser.finalize() return args -def init(): - args = create_args(os.path.basename(sys.argv[0])) +def init(prog_name, port=None): + args = create_args(prog_name) + if port: + args.chaosc_host = "lucas" + args.chaosc_port = 6002 platform = Platform(args) platform.connect() atexit.register(platform.close) diff --git a/sensors2osc/sensors2osc/ekg2osc.py b/sensors2osc/sensors2osc/ekg2osc.py index fcee877..0d4293a 100644 --- a/sensors2osc/sensors2osc/ekg2osc.py +++ b/sensors2osc/sensors2osc/ekg2osc.py @@ -20,10 +20,9 @@ from __future__ import absolute_import -import time, select, sys +import select from sensors2osc.common import * -from chaosc.lib import logger def main(): @@ -35,7 +34,7 @@ def main(): while 1: try: - toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.01) + toread, towrite, toerrors = select.select([platform.serial_sock], [], [], 0.01) if toread: t = platform.serial_sock.read(1) else: @@ -46,16 +45,18 @@ def main(): logger.info("serial socket error!!! - try to reconnect") platform.reconnect() + t = None try: t = ord(t) - except TypeError, e: + except TypeError: continue - #if msg_count >= 20: - # logger.info("value = %d", t) - # msg_count = 0 - #else: - # msg_count += 1 + if msg_count < 20: + # logger.info("value = %d", t) + msg_count += 1 + continue + else: + msg_count = 0 try: osc_message = OSCMessage("/%s/ekg" % actor)