ehealth2osc fixed and added socat_ehealth_test
This commit is contained in:
parent
4c3cc88868
commit
3ba992bcde
|
@ -22,49 +22,72 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
from sensors2osc.common import *
|
from sensors2osc.common import *
|
||||||
|
|
||||||
atexit.register(close)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args, osc_sock = init("ehealth2osc")
|
platform = init("ehealth2osc")
|
||||||
|
|
||||||
actor = args.actor
|
actor = platform.args.actor
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
data = serial_sock.readline()[:-2]
|
data = platform.serial_sock.readline()[:-2]
|
||||||
print "got data", repr(data)
|
print repr(data)
|
||||||
try:
|
|
||||||
airFlow, emg, temp = data.split(";")
|
|
||||||
except ValueError:
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
airFlow = int(airFlow)
|
|
||||||
osc_message = OSCMessage("/%s/airFlow" % actor)
|
|
||||||
osc_message.appendTypedArg(airFlow, "i")
|
|
||||||
osc_sock.sendall(osc_message.encode_osc())
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
emg = int(emg)
|
|
||||||
osc_message = OSCMessage("/%s/emg" % actor)
|
|
||||||
osc_message.appendTypedArg(emg, "i")
|
|
||||||
osc_sock.sendall(osc_message.encode_osc())
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
temp = int(temp)
|
|
||||||
osc_message = OSCMessage("/%s/temperatur" % actor)
|
|
||||||
osc_message.appendTypedArg(temp, "i")
|
|
||||||
osc_sock.sendall(osc_message.encode_osc())
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
except socket.error, msg:
|
except socket.error, msg:
|
||||||
# got disconnected?
|
# got disconnected?
|
||||||
print "lost connection!!!"
|
print "serial socket error!!!", msg
|
||||||
reconnect(args)
|
platform.reconnect()
|
||||||
|
|
||||||
|
print "got data", repr(data)
|
||||||
|
try:
|
||||||
|
airFlow, emg, temp = data.split(";")
|
||||||
|
except ValueError, e:
|
||||||
|
print e
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
airFlow = int(airFlow)
|
||||||
|
except ValueError, e:
|
||||||
|
print e
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
osc_message = OSCMessage("/%s/airFlow" % actor)
|
||||||
|
osc_message.appendTypedArg(airFlow, "i")
|
||||||
|
platform.osc_sock.sendall(osc_message.encode_osc())
|
||||||
|
except socket.error, msg:
|
||||||
|
print "cannot connect to chaosc", msg
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
emg = int(emg)
|
||||||
|
except ValueError, e:
|
||||||
|
print e
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
osc_message = OSCMessage("/%s/emg" % actor)
|
||||||
|
osc_message.appendTypedArg(emg, "i")
|
||||||
|
platform.osc_sock.sendall(osc_message.encode_osc())
|
||||||
|
except socket.error, msg:
|
||||||
|
print "cannot connect to chaosc", msg
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
temp = int(temp)
|
||||||
|
except ValueError, e:
|
||||||
|
print e
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
osc_message = OSCMessage("/%s/temperatur" % actor)
|
||||||
|
osc_message.appendTypedArg(temp, "i")
|
||||||
|
platform.osc_sock.sendall(osc_message.encode_osc())
|
||||||
|
except socket.error, msg:
|
||||||
|
print "cannot connect to chaosc", msg
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# This file is part of chaosc
|
# This file is part of sensors2osc package
|
||||||
#
|
#
|
||||||
# chaosc is free software: you can redistribute it and/or modify
|
# sensors2osc is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# chaosc is distributed in the hope that it will be useful,
|
# sensors2osc is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with chaosc. If not, see <http://www.gnu.org/licenses/>.
|
# along with sensors2osc. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 Stefan Kögl
|
# Copyright (C) 2014 Stefan Kögl
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# This file is part of sensors2osc package
|
||||||
|
#
|
||||||
|
# sensors2osc is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# sensors2osc is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with sensors2osc. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Copyright (C) 2014 Stefan Kögl
|
||||||
|
|
||||||
|
# used this line before opening that script
|
||||||
|
# socat -d -d PTY,raw,echo=0,link=/tmp/pty1,b115200,user=stefan PTY,raw,echo=0,link=/tmp/pty2,b115200,user=stefan
|
||||||
|
|
||||||
|
import serial
|
||||||
|
|
||||||
|
serial_sock = serial.Serial()
|
||||||
|
|
||||||
|
serial_sock = serial.Serial()
|
||||||
|
serial_sock.port = "/tmp/pty2"
|
||||||
|
serial_sock.baudrate = 115200
|
||||||
|
serial_sock.timeout = 0
|
||||||
|
serial_sock.open()
|
||||||
|
import time, random, struct
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
serial_sock.write("%d;%d;%d\r\n" % (random.randint(0,1023), random.randint(0,1023), random.randint(0,1023)))
|
||||||
|
#time.sleep(.5)
|
Loading…
Reference in New Issue