added per actor sensor scripts, improved grabber performance, started saving server configs and cleaned up the repo

This commit is contained in:
Stefan Kögl 2014-04-28 07:20:28 +02:00
parent 12138a9f57
commit 0d2372df12
23 changed files with 3858 additions and 245 deletions

View File

@ -1,3 +0,0 @@
[chaosc]
ipv4_only = True
subscription_file = ~/dev/psychose/config_files/targets.config

View File

@ -1,31 +0,0 @@
[chaosc_ctl]
ipv4_only = True
client_host = lucas
client_port = 11111
chaosc_host = chaosc
[chaosc_dump]
ipv4_only = True
client_host = lucas
client_port = 11112
subscribe = True
chaosc_host = chaosc
[chaosc_emitter]
ipv4_only = True
client_host = lucas
client_port = 11113
chaosc_host = chaosc
[ekgplotter]
ipv4_only = True
client_host = lucas
client_port = 11114
chaosc_host = chaosc
[chaosc_recorder]
ipv4_only = True
client_host = lucas
client_port = 111115
chaosc_host = chaosc

View File

@ -1,11 +0,0 @@
[ekg2osc]
ipv4_only = True
chaosc_host = chaosc
[pulse2osc]
ipv4_only = True
chaosc_host = chaosc
[ehealth2osc]
ipv4_only = True
chaosc_host = chaosc

View File

@ -1,31 +0,0 @@
[chaosc_ctl]
ipv4_only = True
client_host = stefan
client_port = 11111
chaosc_host = chaosc
[chaosc_dump]
ipv4_only = True
client_host = stefan
client_port = 11112
subscribe = True
chaosc_host = chaosc
[chaosc_emitter]
ipv4_only = True
client_host = stefan
client_port = 11113
chaosc_host = chaosc
[ekgplotter]
ipv4_only = True
client_host = stefan
client_port = 11114
chaosc_host = chaosc
[chaosc_recorder]
ipv4_only = True
client_host = stefan
client_port = 111115
chaosc_host = chaosc

View File

@ -1,19 +0,0 @@
Port 8090
BindAddress 0.0.0.0
MaxClients 10
MaxBandwidth 1000000
CustomLog /tmp/ffserver.log
<Feed textcast.ffm>
file /tmp/textcast.ffm
FileMaxSize 10M
ACL allow 127.0.0.1
</Feed>
<Stream textcast.mjpeg>
Feed textcast.ffm
Format mjpeg
VideoFrameRate 25
VideoSize 768x576
Noaudio
</Stream>

View File

@ -0,0 +1,58 @@
[chaosc]
chaosc_host = chaosc
ipv4_only = True
subscription_file = ~/dev/psychose/config_files/test_targets.config
[pulsemerle]
chaosc_host = chaosc
ipv4_only = True
actor = merle
device = /dev/psy_spo2_a
[pulseuwe]
chaosc_host = chaosc
ipv4_only = True
actor = uwe
device = /dev/psy_spo2_b
[pulsebjoern]
chaosc_host = chaosc
ipv4_only = True
actor = bjoern
device = /dev/psy_spo2_c
[ehealthmerle]
chaosc_host = chaosc
ipv4_only = True
actor = merle
device = /dev/psy_ehealth_a
[ehealthuwe]
chaosc_host = chaosc
ipv4_only = True
actor = uwe
device = /dev/psy_ehealth_b
[ehealthbjoern]
chaosc_host = chaosc
ipv4_only = True
actor = bjoern
device = /dev/psy_ehealth_c
[ekgmerle]
chaosc_host = chaosc
ipv4_only = True
actor = merle
device = /dev/psy_ekg_a
[ekguwe]
chaosc_host = chaosc
ipv4_only = True
actor = uwe
device = /dev/psy_ekg_b
[ekgbjoern]
chaosc_host = chaosc
ipv4_only = True
actor = bjoern
device = /dev/psy_ekg_c

View File

@ -2,7 +2,7 @@
depend() {
need net
use dns localmount chaosc
use dns localmount
after bootmisc
provide dump_grabber
}
@ -10,7 +10,7 @@ depend() {
start() {
ebegin "starting dump_grabber"
start-stop-daemon --start --pidfile /var/run/dump_grabber.pid --make-pidfile --user stefan --group stefan --background --exec env DISPLAY=:0 /usr/bin/dump_grabber
start-stop-daemon --start --pidfile /var/run/dump_grabber.pid --make-pidfile --user sarah --group sarah --background --exec env DISPLAY=:0 /usr/bin/dump_grabber
eend $?
}

View File

@ -2,7 +2,7 @@
depend() {
need net
use dns localmount chaosc
use dns localmount
after bootmisc
provide ekgplotter
}
@ -10,7 +10,7 @@ depend() {
start() {
ebegin "starting ekgplotter"
start-stop-daemon --start --pidfile /var/run/ekgplotter.pid --make-pidfile --user stefan --group stefan --background --exec env DISPLAY=:0 /usr/bin/ekgplotter
start-stop-daemon --start --pidfile /var/run/ekgplotter.pid --make-pidfile --user sarah --group sarah --background --exec env DISPLAY=:0 /usr/bin/ekgplotter
eend $?
}

View File

@ -0,0 +1,22 @@
#!/sbin/runscript
depend() {
need net
use dns localmount
after bootmisc
provide psydisplay
}
start() {
ebegin "starting psydisplay"
start-stop-daemon --start --pidfile /var/run/psydisplay.pid --make-pidfile --user sarah --group sarah --background --exec /usr/bin/psydisplay
eend $?
}
stop() {
ebegin "stopping psydisplay"
start-stop-daemon --stop --quiet --pidfile /var/run/psydisplay.pid
eend $?
}

View File

@ -0,0 +1,13 @@
[ekgplotter]
ipv4_only = True
chaosc_host = chaosc
client_host = sensors
client_port = 8000
http_port = 9000
[dump_grabber]
ipv4_only = True
chaosc_host = chaosc
client_host = sensors
client_port = 8001
http_port = 9001

File diff suppressed because it is too large Load Diff

View File

@ -15,49 +15,42 @@ 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 -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'
new-window -n 'socat-ekg-uwe' -t 'csession:4' 'socat -d -d PTY,raw,echo=0,link=/tmp/ekg2osc-uwe-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ekg2osc-uwe-out,b115200,user=stefan'
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-pulse-bjoern' -t 'csession:5' 'socat -d -d PTY,raw,echo=0,link=/tmp/pulse2osc-bjoern-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pulse2osc-bjoern-out,b115200,user=stefan'
new-window -n 'socat-pulse-merle' -t 'csession:6' 'socat -d -d PTY,raw,echo=0,link=/tmp/pulse2osc-merle-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pulse2osc-merle-out,b115200,user=stefan'
new-window -n 'socat-pulse-uwe' -t 'csession:7' 'socat -d -d PTY,raw,echo=0,link=/tmp/pulse2osc-uwe-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pulse2osc-uwe-out,b115200,user=stefan'
new-window -n 'socat-pulse-bjoern' -t 'csession:5' 'socat -d -d PTY,raw,echo=0,link=/tmp/pulse2osc-bjoern-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pulse2osc-bjoern-out,b115200,user=stefan'
new-window -n 'socat-ehealth-bjoern' -t 'csession:8' 'socat -d -d PTY,raw,echo=0,link=/tmp/ehealth2osc-bjoern-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ehealth2osc-bjoern-out,b115200,user=stefan'
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 'socat-ehealth-bjoern' -t 'csession:8' 'socat -d -d PTY,raw,echo=0,link=/tmp/ehealth2osc-bjoern-in,b115200,user=stefan PTY,raw,echo=0,link=/tmp/ehealth2osc-bjoern-out,b115200,user=stefan'
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 'ekg2osc-merle' -t 'csession:11' 'ekgmerle -D /tmp/ekg2osc-merle-out'
new-window -n 'ekg2osc-uwe' -t 'csession:12' 'ekguwe -D /tmp/ekg2osc-uwe-out'
new-window -n 'ekg2osc-bjoern' -t 'csession:13' 'ekgbjoern -D /tmp/ekg2osc-bjoern-out'
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 'pulse2osc-merle' -t 'csession:14' 'pulse2osc -D /tmp/pulse2osc-merle-out -a merle'
new-window -n 'pulse2osc-uwe' -t 'csession:15' 'pulse2osc -D /tmp/pulse2osc-uwe-out -a uwe'
new-window -n 'pulse2osc-bjoern' -t 'csession:16' 'pulse2osc -D /tmp/pulse2osc-bjoern-out -a bjoern'
new-window -n 'ehealth2osc-bjoern' -t 'csession:17' 'sleep 1 && ehealth2osc -4 -D /tmp/ehealth2osc-bjoern-out -a bjoern'
new-window -n 'ehealth2osc-merle' -t 'csession:18' 'sleep 1 && ehealth2osc -4 -D /tmp/ehealth2osc-merle-out -a merle'
new-window -n 'ehealth2osc-uwe' -t 'csession:19' 'sleep 1 && ehealth2osc -4 -D /tmp/ehealth2osc-uwe-out -a uwe'
new-window -n 'ehealth2osc-merle' -t 'csession:17' 'sleep 1 && ehealthmerle -D /tmp/ehealth2osc-merle-out'
new-window -n 'ehealth2osc-uwe' -t 'csession:18' 'sleep 1 && ehealthuwe -D /tmp/ehealth2osc-uwe-out'
new-window -n 'ehealth2osc-bjoern' -t 'csession:19' 'sleep 1 && ehealthbjoern -D /tmp/ehealth2osc-bjoern-out'
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'
new-window -n 'test-ekg-uwe' -t 'csession:22' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ekg_test.py /tmp/ekg2osc-uwe-in'
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-pulse-bjoern' -t 'csession:23' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_pulse_test.py /tmp/pulse2osc-bjoern-in'
new-window -n 'test-pulse-merle' -t 'csession:24' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_pulse_test.py /tmp/pulse2osc-merle-in'
new-window -n 'test-pulse-uwe' -t 'csession:25' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_pulse_test.py /tmp/pulse2osc-uwe-in'
new-window -n 'test-pulse-bjoern' -t 'csession:23' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_pulse_test.py /tmp/pulse2osc-bjoern-in'
new-window -n 'test-ehealth-bjoern' -t 'csession:26' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-bjoern-in'
new-window -n 'test-ehealth-merle' -t 'csession:27' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-merle-in'
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 'test-ehealth-bjoern' -t 'csession:26' 'python /home/stefan/dev/psychose/sensors2osc/sensors2osc/socat_ehealth_test.py /tmp/ehealth2osc-bjoern-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'
select-window -t 'csession:2'
set aggressive-resize on

View File

@ -19,55 +19,34 @@
#
# Copyright (C) 2014 Stefan Kögl
from __future__ import absolute_import
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from chaosc.argparser_groups import *
from chaosc.lib import logger, resolve_host
from collections import deque
from datetime import datetime
from dump_grabber.dump_grabber_ui import Ui_MainWindow
from os import curdir, sep
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QBuffer, QByteArray, QIODevice
from SocketServer import ThreadingMixIn, ForkingMixIn
import logging
import numpy as np
import os
import os.path
import Queue
import random
import re
import select
import socket
import string
import sys
import threading
import time
import traceback
from datetime import datetime
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from chaosc.argparser_groups import *
from chaosc.lib import logger, resolve_host
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import QBuffer, QByteArray, QIODevice
from dump_grabber.dump_grabber_ui import Ui_MainWindow
try:
from chaosc.c_osc_lib import OSCMessage, decode_osc
except ImportError as e:
from chaosc.osc_lib import OSCMessage, decode_osc
#appName = "dump_grabber"
#catalog = "dump_grabber"
#programName = ki18n("dump_grabber")
#version = "0.1"
#aboutData = KAboutData(appName, catalog, programName, version)
#KCmdLineArgs.init(sys.argv, aboutData)
app = QtGui.QApplication([])
fh = logging.FileHandler(os.path.expanduser("~/.chaosc/dump_grabber.log"))
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
class TextStorage(object):
def __init__(self, columns):
super(TextStorage, self).__init__()
@ -114,7 +93,6 @@ class ColumnTextStorage(TextStorage):
text_item.setPos(column * self.column_width, iy * self.line_height)
class ExclusiveTextStorage(TextStorage):
def __init__(self, columns, default_font, column_width, line_height, scene):
super(ExclusiveTextStorage, self).__init__(columns)
@ -280,13 +258,14 @@ class MyHandler(BaseHTTPRequestHandler):
last_frame = time.time() - 1.
frame_rate = 16.0
frame_length = 1. / frame_rate
regrex = re.compile("^/(uwe|merle|bjoern)/(.*?)$")
regex = re.compile("^/(uwe|merle|bjoern)/(.*?)$")
while 1:
event_loop.processEvents()
app.sendPostedEvents(None, 0)
while 1:
try:
osc_address, args = queue.get_nowait()
print osc_address
except Queue.Empty:
break
else:
@ -304,39 +283,24 @@ class MyHandler(BaseHTTPRequestHandler):
now = time.time()
delta = now - last_frame
if delta > frame_length:
print 1 / delta
last_frame = now
img = window.render()
buffer = QBuffer()
buffer.open(QIODevice.WriteOnly)
img.save(buffer, "JPG")
#img.save(os.path.expanduser("~/.chaosc/dump_grabber.jpg"), "JPG")
JpegData = buffer.data()
self.wfile.write("--aaboundary\r\nContent-Type: image/jpeg\r\nContent-length: %d\r\n\r\n%s\r\n\r\n\r\n" % (len(JpegData), JpegData))
JpegData = None
buffer = None
img = None
time.sleep(0.01)
elif self.path.endswith(".jpeg"):
directory = os.path.dirname(os.path.abspath(__file__))
data = open(os.path.join(directory, self.path), "rb").read()
self.send_response(200)
self.send_header('Content-type','image/jpeg')
self.end_headers()
self.wfile.write(data)
return
except (KeyboardInterrupt, SystemError):
#print "queue size", queue.qsize()
if hasattr(self, "thread") and self.thread is not None:
self.thread.running = False
self.thread.join()
self.thread = None
except IOError, e:
#print "ioerror", e, e[0]
#print dir(e)
if e[0] in (32, 104):
if hasattr(self, "thread") and self.thread is not None:
self.thread.running = False
@ -362,11 +326,6 @@ def main():
arg_parser.add_subscriber_group()
args = arg_parser.finalize()
if not args.background:
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
http_host, http_port = resolve_host(args.http_host, args.http_port, args.address_family)
server = JustAHTTPServer((http_host, http_port), MyHandler)

View File

@ -27,31 +27,22 @@ from __future__ import absolute_import
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from chaosc.argparser_groups import *
from chaosc.lib import logger, resolve_host
from collections import deque, defaultdict
from datetime import datetime
from operator import attrgetter
from os import curdir, sep
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QBuffer, QByteArray, QIODevice
from SocketServer import ThreadingMixIn, ForkingMixIn
import cPickle
import logging
import numpy as np
import os.path
import pyqtgraph as pg
import Queue
import random
import re
import select
import socket
import string
import threading
import time
import traceback
fh = logging.FileHandler(os.path.expanduser("~/.chaosc/ekgplotter.log"))
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
try:
@ -75,13 +66,13 @@ class OSCThread(threading.Thread):
self.osc_sock.bind(self.client_address)
self.osc_sock.setblocking(0)
logging.info("%s: starting up osc receiver on '%s:%d'",
logger.info("%s: starting up osc receiver on '%s:%d'",
datetime.now().strftime("%x %X"), self.client_address[0], self.client_address[1])
self.subscribe_me()
def subscribe_me(self):
logging.info("%s: subscribing to '%s:%d' with label %r", datetime.now().strftime("%x %X"), self.chaosc_address[0], self.chaosc_address[1], self.args.subscriber_label)
logger.info("%s: subscribing to '%s:%d' with label %r", datetime.now().strftime("%x %X"), self.chaosc_address[0], self.chaosc_address[1], self.args.subscriber_label)
msg = OSCMessage("/subscribe")
msg.appendTypedArg(self.client_address[0], "s")
msg.appendTypedArg(self.client_address[1], "i")
@ -95,7 +86,7 @@ class OSCThread(threading.Thread):
if self.args.keep_subscribed:
return
logging.info("%s: unsubscribing from '%s:%d'", datetime.now().strftime("%x %X"), self.chaosc_address[0], self.chaosc_address[1])
logger.info("%s: unsubscribing from '%s:%d'", datetime.now().strftime("%x %X"), self.chaosc_address[0], self.chaosc_address[1])
msg = OSCMessage("/unsubscribe")
msg.appendTypedArg(self.client_address[0], "s")
msg.appendTypedArg(self.client_address[1], "i")
@ -117,11 +108,11 @@ class OSCThread(threading.Thread):
osc_address, typetags, messages = decode_osc(osc_input, 0, len(osc_input))
queue.put_nowait((osc_address, messages))
except Exception, e:
logging.info(e)
logger.info(e)
self.unsubscribe_me()
self.osc_sock.close()
logging.info("OSCThread is going down")
logger.info("OSCThread is going down")
queue = Queue.Queue()
@ -329,12 +320,7 @@ class MyHandler(BaseHTTPRequestHandler):
self.thread.join()
self.thread = None
else:
logging.info('-'*40)
logging.info('Exception happened during processing of request from')
logging.exception(e)
logging.info('-'*40)
self.send_error(404,'File Not Found: %s' % self.path)
raise e
pass
class JustAHTTPServer(HTTPServer):
@ -353,24 +339,19 @@ def main():
arg_parser.add_subscriber_group()
args = arg_parser.finalize()
if not args.background:
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logger.addHandler(ch)
http_host, http_port = resolve_host(args.http_host, args.http_port, args.address_family)
server = JustAHTTPServer((http_host, http_port), MyHandler)
server.address_family = args.address_family
server.args = args
logging.info("%s: starting up http server on '%s:%d'",
logger.info("%s: starting up http server on '%s:%d'",
datetime.now().strftime("%x %X"), http_host, http_port)
try:
server.serve_forever()
except KeyboardInterrupt:
logging.info('^C received, shutting down server')
logger.info('^C received, shutting down server')
server.socket.close()
sys.exit(0)

View File

@ -25,6 +25,7 @@ import os.path
import serial
import socket
import time
import sys
from chaosc.argparser_groups import ArgParser
@ -39,6 +40,7 @@ except ImportError as e:
class Platform(object):
def __init__(self, args):
self.args = args
self.remote = (self.args.chaosc_host, self.args.chaosc_port)
self.serial_sock = None
self.osc_sock = socket.socket(args.address_family, 2, 17)
self.osc_sock.connect((self.args.chaosc_host, self.args.chaosc_port))
@ -78,10 +80,10 @@ 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', required=True,
type=str, help='device node under /dev')
arg_parser.add_argument(main_group, "-a", '--actor', required=True,
type=str, help='actor name')
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()
@ -90,8 +92,8 @@ def create_args(name):
return args
def init(name):
args = create_args(name)
def init():
args = create_args(os.path.basename(sys.argv[0]))
platform = Platform(args)
platform.connect()
atexit.register(platform.close)

View File

@ -21,11 +21,11 @@
from __future__ import absolute_import
from sensors2osc.common import *
import time, select
import time, select, sys
def main():
platform = init("ehealth2osc")
platform = init()
actor = platform.args.actor
@ -42,7 +42,7 @@ def main():
print "serial socket error!!!", msg
platform.reconnect()
print "got data", repr(data)
print "data", repr(data)
try:
airFlow, emg, temp = data.split(";")
except ValueError, e:
@ -58,7 +58,7 @@ def main():
try:
osc_message = OSCMessage("/%s/airFlow" % actor)
osc_message.appendTypedArg(airFlow, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
except socket.error, msg:
print "cannot connect to chaosc", msg
continue
@ -73,7 +73,7 @@ def main():
try:
osc_message = OSCMessage("/%s/emg" % actor)
osc_message.appendTypedArg(emg, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
except socket.error, msg:
print "cannot connect to chaosc", msg
continue
@ -88,7 +88,7 @@ def main():
try:
osc_message = OSCMessage("/%s/temperatur" % actor)
osc_message.appendTypedArg(temp, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
except socket.error, msg:
print "cannot connect to chaosc", msg
continue

View File

@ -20,27 +20,30 @@
from __future__ import absolute_import
import time, select
import time, select, sys
from sensors2osc.common import *
from chaosc.lib import logger
def main():
platform = init("ekg2osc")
platform = init()
actor = platform.args.actor
msg_count = 0
while 1:
try:
toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.05)
toread, towrite, toerrors = select.select([platform.serial_sock], [],[], 0.01)
if toread:
t = platform.serial_sock.read(1)
else:
continue
except (socket.error, serial.serialutil.SerialException), msg:
# got disconnected?
print "serial socket error!!!", msg
logger.exception(msg)
logger.info("serial socket error!!! - try to reconnect")
platform.reconnect()
try:
@ -48,17 +51,21 @@ def main():
except TypeError, e:
continue
if msg_count >= 20:
logger.info("value = %d", t)
msg_count = 0
else:
msg_count += 1
try:
print "got value", t
osc_message = OSCMessage("/%s/ekg" % actor)
osc_message.appendTypedArg(t, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
except socket.error, msg:
print "cannot connect to chaosc"
logger.info("ekg2osc error")
logger.exception(msg)
continue
if __name__ == '__main__':
main()

View File

@ -20,7 +20,7 @@
from __future__ import absolute_import
import time, select
import time, select, sys
from datetime import datetime
from sensors2osc.common import *
@ -61,7 +61,7 @@ class RingBuffer(object):
def main():
platform = init("pulse2osc")
platform = init()
actor = platform.args.actor
@ -102,7 +102,7 @@ def main():
osc_message.appendTypedArg(1, "i")
osc_message.appendTypedArg(heart_rate, "i")
osc_message.appendTypedArg(o2, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
print "on heartbeat", datetime.now(), heart_signal, heart_rate, o2, pulse
except socket.error, msg:
print "cannot connect to chaosc"
@ -115,7 +115,7 @@ def main():
osc_message.appendTypedArg(0, "i")
osc_message.appendTypedArg(heart_rate, "i")
osc_message.appendTypedArg(o2, "i")
platform.osc_sock.sendall(osc_message.encode_osc())
platform.osc_sock.sendto(osc_message.encode_osc(), platform.remote)
except socket.error, msg:
print "cannot connect to chaosc"
continue

View File

@ -23,6 +23,14 @@
import serial, sys, time, random, struct
def get_steps(pulse_rate, rate):
beat_length = 60. / pulse_rate
steps_pre = int(beat_length / rate) + 1
used_sleep_time = beat_length / steps_pre
steps = int(beat_length / used_sleep_time)
return steps, used_sleep_time
serial_sock = serial.Serial()
serial_sock.port = sys.argv[1]
serial_sock.baudrate = 115200
@ -31,40 +39,57 @@ serial_sock.open()
data_points = 0
min_steps = 17
max_steps = 43
steps = random.randint(17,43)
sleep_time = 0.04
min_puls = 70
max_pulse = 130
pulse = random.randint(min_puls, max_pulse)
steps, sleep_time = get_steps(pulse, sleep_time)
count = 0
delta = 1
result = list()
print "pulse", pulse
print "sleep_time", sleep_time
print "steps", steps
while 1:
value = random.randint(0, steps)
if count < int(steps / 100. * 20):
value = random.randint(0,20)
elif count < int(steps / 100. * 30):
value = random.randint(20, 30)
elif count < int(steps / 100. * 40):
value = random.randint(30,100)
elif count < int(steps / 2.):
value = random.randint(20,50)
value = random.randint(100,200)
elif count == int(steps / 2.):
value = 255
elif count < int(steps / 100. * 60):
value = random.randint(100, 200)
elif count < int(steps / 100. * 70):
value = random.randint(20,50)
value = random.randint(50, 100)
elif count < int(steps / 100. * 80):
value = random.randint(20, 50)
elif count <= steps:
value = random.randint(0,20)
elif count >= steps:
count = 0
if data_points % (5 * steps) == 0:
print "new steps", steps, delta
steps += delta
#if data_points % (5 * steps) == 0:
#print "new steps", steps, delta
#steps += delta
if steps <= min_steps:
delta = 1
elif steps >= max_steps:
print "change step sign", steps, delta
delta = -1
#if steps <= min_steps:
#delta = 1
#elif steps >= max_steps:
#print "change step sign", steps, delta
#delta = -1
time.sleep(0.02)
time.sleep(sleep_time)
count += 1
data_points += 1
#data_points += 1
serial_sock.write(struct.pack("B", value))

View File

@ -31,11 +31,18 @@ setup(
# predefined extension points, e.g. for plugins
entry_points = """
[console_scripts]
sensors2osc = sensors2osc.main:main
sensorTest = sensors2osc.sensorTest:main
ekg2osc = sensors2osc.ekg2osc:main
ekgmerle = sensors2osc.ekg2osc:main
ekguwe = sensors2osc.ekg2osc:main
ekgbjoern = sensors2osc.ekg2osc:main
pulse2osc = sensors2osc.pulse2osc:main
pulsemerle = sensors2osc.pulse2osc:main
pulseuwe = sensors2osc.pulse2osc:main
pulsebjoern = sensors2osc.pulse2osc:main
ehealth2osc = sensors2osc.ehealth2osc:main
ehealthmerle = sensors2osc.ehealth2osc:main
ehealthuwe = sensors2osc.ehealth2osc:main
ehealthbjoern = sensors2osc.ehealth2osc:main
""",
# pypi metadata
author = "Stefan Kögl",