Adding OSC support for streaming.

Esse commit está contido em:
jfrey
2015-02-20 18:00:15 +01:00
commit 29dabe1368
3 arquivos alterados com 77 adições e 10 exclusões
+15 -2
Ver Arquivo
@@ -140,6 +140,19 @@ the user to hit enter on the user.py script until you get a response.
Connects to the board and fetch data, computing every 10 seconds the average sampling rate.
### openvibelink branch
### Streaming data
Adding streaming capability to user.py with `-s` switch. Default port: `12345` (`--stream-port` option). Default IP: `localhost` (`--stream-ip` option).
### OpenViBE support (raw TCP)
By default the a raw TCP protocol is selected, that could then be acquired with OpenViBE acquisition server, selecting telnet, big endian, float 32 bits, forcing 250 sampling rate (125 if daisy mode is used).
### OSC support
With `--stream-protocol osc` data is sent through OSC (UDP layer). Default stream name: `/openbci` (`--stream-osc-address` option).
Requires pyosc: on linux either `pip install --pre pyosc` as root, or `pip install --pre --user`.
Example: `user.py -p /dev/ttyUSB0 -s --stream-protocol osc` will send data to `localhost/openbci:12345`.
Adding streaming capability to user.py with "-s" switch. Then it could be acquired with OpenViBE acquisition server, selecting telnet, big endian, float 32 bits, forcing 250 sampling rate.
+44
Ver Arquivo
@@ -0,0 +1,44 @@
from streamer import Streamer
# requires pyosc
from OSC import OSCClient, OSCMessage
# Use OSC protocol to broadcast data (UDP layer), using "/openbci" stream. (NB. does not check numbers of channel as TCP server)
class StreamerOSC(Streamer):
"""
Relay OpenBCI values to OSC clients
Args:
port: Port of the server
ip: IP address of the server
address: name of the stream
"""
def __init__(self, ip='localhost', port=12345, address="/openbci"):
# connection infos
self.ip = ip
self.port = port
self.address = address
self.initialize()
# the initialize method reads settings and outputs the first header
def initialize(self):
# init server
self.client = OSCClient()
self.client.connect( (self.ip, self.port) )
# stub for API compability with streamer
def check_connections(self):
return
# close connections, send message to client
def uninitialize(self):
self.client.send( OSCMessage("/quit") )
# send channels values
# as_string: many for debug, send values with a nice "[34.45, 30.4, -38.0]"-like format
def broadcast_values(self, values):
mes = OSCMessage(self.address)
mes.append(values)
self.client.send(mes )
+18 -8
Ver Arquivo
@@ -5,7 +5,7 @@ import os
import time
import csv_collect
import string
import streamer, streamer_tcp_server
import streamer, streamer_tcp_server, streamer_osc
def printData(sample):
#os.system('clear')
@@ -32,13 +32,17 @@ if __name__ == '__main__':
parser.add_argument('-c', '--cvs', action="store_true",
help="write cvs data")
parser.add_argument('-s', '--stream', action="store_true",
help="stream data to TCP")
# options for streaming server
help="stream data to network (see help for options)")
# options for streamer
parser.add_argument('--stream-protocol', default="tcp",
help="Select streaming protocol; 'tcp' for raw TCP, 'osc' for OSC protocol (default: 'tcp')" )
parser.add_argument('--stream-osc-address', default="/openbci",
help="Select target address for OSC streaming protocol (default: '/openbci')" )
parser.add_argument('-si', '--stream-ip', default="localhost",
help="IP address for TCP streaming server " +
help="IP address for streaming" +
"(default: localhost)")
parser.add_argument('-sp', '--stream-port', default=12345, type=int,
help="Port for TCP streaming server " +
help="Port for streaming data, either as client (TCP) or to server (OSC)" +
"(default: 12345)")
args = parser.parse_args()
@@ -58,10 +62,16 @@ if __name__ == '__main__':
fun = csv_collect.csv_collect()
elif args.stream:
print "Selecting streaming. IP: ", args.stream_ip, ", port: ", args.stream_port
# init server
server = streamer_tcp_server.StreamerTCPServer(ip=args.stream_ip, port=args.stream_port, nb_channels=nb_channels)
# init right protocol
server = None
if args.stream_protocol == "tcp":
print "Protocol: TCP"
server = streamer_tcp_server.StreamerTCPServer(ip=args.stream_ip, port=args.stream_port, nb_channels=nb_channels)
else:
print "Protocol: OSC, address: ", args.stream_osc_address
server = streamer_osc.StreamerOSC(ip=args.stream_ip, port=args.stream_port, address=args.stream_osc_address)
# init and daemonize thread to terminate it altogether with the main when time will come monit.daemon = True
monit = streamer.MonitorStreamer(server)
# daemonize theard to terminate it altogether with the main when time will come
monit.daemon = True
fun = monit.send
# launch monitor