From 7de1019e76a10e09d19e35a3b1cd2cab7b649f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Tue, 25 Mar 2014 22:31:42 +0100 Subject: [PATCH] cpu optimized by using select Conflicts: sensors2osc/sensors2osc/ekg2osc.py sensors2osc/sensors2osc/pulse2osc.py sensors2osc/sensors2osc/socat_ehealth_test.py --- config_files/tmux-sensor-testing.conf | 21 ++++++++++--------- sensors2osc/sensors2osc/ehealth2osc.py | 8 +++++-- sensors2osc/sensors2osc/ekg2osc.py | 12 ++++++++--- sensors2osc/sensors2osc/pulse2osc.py | 8 +++++-- sensors2osc/sensors2osc/socat_ehealth_test.py | 2 +- sensors2osc/sensors2osc/socat_pulse_test.py | 2 +- 6 files changed, 34 insertions(+), 19 deletions(-) diff --git a/config_files/tmux-sensor-testing.conf b/config_files/tmux-sensor-testing.conf index d942893..24efb0a 100644 --- a/config_files/tmux-sensor-testing.conf +++ b/config_files/tmux-sensor-testing.conf @@ -15,7 +15,7 @@ set -g terminal-overrides 'xterm*:smcup@:rmcup@' new-session -s 'csession' attach-session -t 'csession' -new-window -n 'chaosc' -t 'csession:1' '/usr/bin/chaosc' +new-window -n 'chaosc' -t 'csession:1' '/usr/bin/chaosc -4' new-window -n 'socat-ekg-bjoern' -t 'csession:2' 'socat -d -d PTY,raw,echo=0,link=/tmp/ekg2osc-bjoern-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ekg2osc-bjoern-out,b115200,user=stefan' new-window -n 'socat-ekg-merle' -t 'csession:3' 'socat -d -d PTY,raw,echo=0,link=/tmp/ekg2osc-merle-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ekg2osc-merle-out,b115200,user=stefan' @@ -29,17 +29,17 @@ new-window -n 'socat-ehealth-bjoern' -t 'csession:8' 'socat -d -d PTY,raw,echo= new-window -n 'socat-ehealth-merle' -t 'csession:9' 'socat -d -d PTY,raw,echo=0,link=/tmp/ehealth2osc-merle-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ehealth2osc-merle-out,b115200,user=stefan' new-window -n 'socat-ehealth-uwe' -t 'csession:10' 'socat -d -d PTY,raw,echo=0,link=/tmp/ehealth2osc-uwe-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ehealth2osc-uwe-out,b115200,user=stefan' -new-window -n 'ekg2osc-bjoern' -t 'csession:11' 'ekg2osc -d /tmp/ekg2osc-bjoern-out -a bjoern' -new-window -n 'ekg2osc-merle' -t 'csession:12' 'ekg2osc -d /tmp/ekg2osc-merle-out -a merle' -new-window -n 'ekg2osc-uwe' -t 'csession:13' 'ekg2osc -d /tmp/ekg2osc-uwe-out -a uwe' +new-window -n 'ekg2osc-bjoern' -t 'csession:11' 'ekg2osc -4 -d /tmp/ekg2osc-bjoern-out -a bjoern' +new-window -n 'ekg2osc-merle' -t 'csession:12' 'ekg2osc -4 -d /tmp/ekg2osc-merle-out -a merle' +new-window -n 'ekg2osc-uwe' -t 'csession:13' 'ekg2osc -4 -d /tmp/ekg2osc-uwe-out -a uwe' -new-window -n 'pulse2osc-bjoern' -t 'csession:14' 'pulse2osc -d /tmp/pulse2osc-bjoern-out -a bjoern' -new-window -n 'pulse2osc-merle' -t 'csession:15' 'pulse2osc -d /tmp/pulse2osc-merle-out -a merle' -new-window -n 'pulse2osc-uwe' -t 'csession:16' 'pulse2osc -d /tmp/pulse2osc-uwe-out -a uwe' +new-window -n 'pulse2osc-bjoern' -t 'csession:14' 'pulse2osc -4 -d /tmp/pulse2osc-bjoern-out -a bjoern' +new-window -n 'pulse2osc-merle' -t 'csession:15' 'pulse2osc -4 -d /tmp/pulse2osc-merle-out -a merle' +new-window -n 'pulse2osc-uwe' -t 'csession:16' 'pulse2osc -4 -d /tmp/pulse2osc-uwe-out -a uwe' -new-window -n 'ehealth2osc-bjoern' -t 'csession:17' 'ehealth2osc -d /tmp/ehealth2osc-bjoern-out -a bjoern' -new-window -n 'ehealth2osc-merle' -t 'csession:18' 'ehealth2osc -d /tmp/ehealth2osc-merle-out -a merle' -new-window -n 'ehealth2osc-uwe' -t 'csession:19' 'ehealth2osc -d /tmp/ehealth2osc-uwe-out -a uwe' +new-window -n 'ehealth2osc-bjoern' -t 'csession:17' 'ehealth2osc -4 -d /tmp/ehealth2osc-bjoern-out -a bjoern' +new-window -n 'ehealth2osc-merle' -t 'csession:18' 'ehealth2osc -4 -d /tmp/ehealth2osc-merle-out -a merle' +new-window -n 'ehealth2osc-uwe' -t 'csession:19' 'ehealth2osc -4 -d /tmp/ehealth2osc-uwe-out -a uwe' new-window -n 'test-ekg-bjoern' -t 'csession:20' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ekg_test.py /tmp/ekg2osc-bjoern-in' new-window -n 'test-ekg-merle' -t 'csession:21' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ekg_test.py /tmp/ekg2osc-merle-in' @@ -54,6 +54,7 @@ new-window -n 'test-ehealth-merle' -t 'csession:27' 'python /home/stefan/dev/ps new-window -n 'test-ehealth-uwe' -t 'csession:28' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-uwe-in' # new-window -n 'ekgplotter' -t 'csession:29' 'sleep 5 && ekgplotter -s' # new-window -n 'vlc' -t 'csession:30' 'sleep 10 && vlc "http://localhost:9000/camera.mjpeg"' +new-window -n 'chaosc_emitter' -t 'csession:31' 'chaosc_emitter' select-window -t 'csession:1' diff --git a/sensors2osc/sensors2osc/ehealth2osc.py b/sensors2osc/sensors2osc/ehealth2osc.py index 3d5fb72..a336aee 100644 --- a/sensors2osc/sensors2osc/ehealth2osc.py +++ b/sensors2osc/sensors2osc/ehealth2osc.py @@ -21,7 +21,7 @@ from __future__ import absolute_import from sensors2osc.common import * -import time +import time, select def main(): @@ -31,7 +31,11 @@ def main(): while 1: try: - data = platform.serial_sock.readline()[:-2] + toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.05) + if toread: + data = platform.serial_sock.readline()[:-2] + else: + continue #print repr(data) except socket.error, msg: # got disconnected? diff --git a/sensors2osc/sensors2osc/ekg2osc.py b/sensors2osc/sensors2osc/ekg2osc.py index 2b57563..bea1cd8 100644 --- a/sensors2osc/sensors2osc/ekg2osc.py +++ b/sensors2osc/sensors2osc/ekg2osc.py @@ -20,7 +20,7 @@ from __future__ import absolute_import -import time +import time, select from sensors2osc.common import * @@ -33,8 +33,12 @@ def main(): while 1: try: - t = platform.serial_sock.read(1) - except socket.error, msg: + toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.05) + if toread: + t = platform.serial_sock.read(1) + else: + continue + except socket.error as msg: # got disconnected? print "serial socket error!!!", msg platform.reconnect() @@ -54,5 +58,7 @@ def main(): continue + + if __name__ == '__main__': main() diff --git a/sensors2osc/sensors2osc/pulse2osc.py b/sensors2osc/sensors2osc/pulse2osc.py index a99a31e..b86ea5b 100644 --- a/sensors2osc/sensors2osc/pulse2osc.py +++ b/sensors2osc/sensors2osc/pulse2osc.py @@ -70,8 +70,12 @@ def main(): while 1: try: - t = platform.serial_sock.read(1) - except socket.error, msg: + toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.05) + if toread: + t = platform.serial_sock.read(1) + else: + continue + except socket.error as msg: # got disconnected? print "serial socket error!!!", msg platform.reconnect() diff --git a/sensors2osc/sensors2osc/socat_ehealth_test.py b/sensors2osc/sensors2osc/socat_ehealth_test.py index 2d75cef..15d5b90 100644 --- a/sensors2osc/sensors2osc/socat_ehealth_test.py +++ b/sensors2osc/sensors2osc/socat_ehealth_test.py @@ -32,4 +32,4 @@ serial_sock.open() while 1: serial_sock.write("%d;%d;%d\r\n" % (random.randint(0,1023), random.randint(0,1023), random.randint(0,1023))) - time.sleep(0.1) + time.sleep(0.05) diff --git a/sensors2osc/sensors2osc/socat_pulse_test.py b/sensors2osc/sensors2osc/socat_pulse_test.py index d424bff..275c0b1 100644 --- a/sensors2osc/sensors2osc/socat_pulse_test.py +++ b/sensors2osc/sensors2osc/socat_pulse_test.py @@ -59,4 +59,4 @@ r = DataGenenerator() while 1: serial_sock.write(struct.pack("B", r.read())) - #time.sleep(0.1) + time.sleep(0.02)