Plugins: add streamer_osc
Esse commit está contido em:
+2
-1
@@ -4,7 +4,8 @@
|
||||
Features:
|
||||
- Stream data over TCP (OpenViBE telnet reader format) or OSC
|
||||
- 16 channels support (daisy module)
|
||||
- script: test sampling rate
|
||||
- test sampling rate
|
||||
- plugin system
|
||||
|
||||
Bugfixes:
|
||||
- scale factor
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
To create a new plugin, see print.py and print.yapsy-plugin for a minimal example.
|
||||
|
||||
Note: "__init__" will be automatically called when the main program loads, even if the plugin is not used, put computationally intensive instructions in activate() instead.
|
||||
@@ -0,0 +1,72 @@
|
||||
from streamer import Streamer, MonitorStreamer
|
||||
# requires pyosc
|
||||
from OSC import OSCClient, OSCMessage
|
||||
from yapsy.IPlugin import IPlugin
|
||||
|
||||
# Use OSC protocol to broadcast data (UDP layer), using "/openbci" stream. (NB. does not check numbers of channel as TCP server)
|
||||
# FIXME: no need of a "Streamer" entity anymore with multiple plugins activated
|
||||
|
||||
class StreamerOSC(Streamer, IPlugin):
|
||||
"""
|
||||
|
||||
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
|
||||
|
||||
# From IPlugin
|
||||
def activate(self, args):
|
||||
if len(args) > 0:
|
||||
self.ip = args[0]
|
||||
if len(args) > 1:
|
||||
self.port = args[1]
|
||||
if len(args) > 2:
|
||||
self.address = args[2]
|
||||
# init network
|
||||
print "Selecting OSC streaming. IP: ", self.ip, ", port: ", self.port, ", address: ", self.address
|
||||
self.client = OSCClient()
|
||||
self.client.connect( (self.ip, self.port) )
|
||||
|
||||
# init the daemon that monitors connections
|
||||
|
||||
self.monit = MonitorStreamer(self)
|
||||
self.monit.daemon = True
|
||||
# launch monitor
|
||||
self.monit.start()
|
||||
|
||||
|
||||
return True
|
||||
|
||||
# From IPlugin: close connections, send message to client
|
||||
def deactivate(self):
|
||||
self.client.send(OSCMessage("/quit") )
|
||||
|
||||
# from Streamer: stub for API compability
|
||||
def check_connections(self):
|
||||
return
|
||||
|
||||
# from Streamer: 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)
|
||||
|
||||
# call MonitorStreamer, that will call Streamer, that will call in here
|
||||
def __call__(self, sample):
|
||||
self.monit.send(sample)
|
||||
|
||||
def show_help(self):
|
||||
print """Optional arguments: [ip [port [address]]]
|
||||
\t ip: target IP address (default: 'localhost')
|
||||
\t port: target port (default: 12345)
|
||||
\t address: select target address (default: '/openbci')"""
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
[Core]
|
||||
Name = streamer_osc
|
||||
Module = streamer_osc
|
||||
|
||||
[Documentation]
|
||||
Author = Various
|
||||
Version = 0.1
|
||||
Description = Use OSC protocol to broadcast data (UDP layer). Requires pyosc.
|
||||
@@ -1,44 +0,0 @@
|
||||
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 )
|
||||
Referência em uma Nova Issue
Bloquear um usuário