async def send_message(self, node, client_address, *args, **kwargs): when = kwargs.get('when', time.time()) builder = OscMessageBuilder(address=node.osc_address) for arg in args: builder.add_arg(arg) msg = builder.build() await self.server.sendto(msg, client_address, when)
def sendMsg(self, msg): builder = OscMessageBuilder(address=self.address) for v in msg[0]: builder.add_arg(v) out = builder.build() # print("sent osc message to",self.ip,"on port",self.port,"with address",self.address) self.client.send(out)
def send_knob(self, knob_num, knob_val): if self.verbose: print("knob %d: %f" % (knob_num, knob_val)) builder = OscMessageBuilder(address="/repatcher/knob" + str(knob_num)) builder.add_arg(knob_val) msg = builder.build() self.client.send(msg)
def send_colors(r, g, b): msg = OscMessageBuilder(address='/CV07/color/r') msg.add_arg(r, 'i') m = msg.build() client.send(m) print(m.address, m.params) msg = OscMessageBuilder(address='/CV07/color/g') msg.add_arg(g, 'i') m = msg.build() client.send(m) print(m.address, m.params) msg = OscMessageBuilder(address='/CV07/color/b') msg.add_arg(b, 'i') m = msg.build() client.send(m) print(m.address, m.params)
def osc_message(d): """ create OSC message from a dict """ msg = OscMessageBuilder(address="/send") msg.add_arg(json.dumps(d)) return msg.build()
def _build_message( msg_address: str, msg_parameters: Optional[Union[Sequence, Any]] = None) -> OscMessage: """Builds pythonsosc OSC message. Parameters ---------- msg_address : str SuperCollider address. msg_parameters : list, optional List of parameters to add to message. Returns ------- OscMessage Message ready to be sent. """ if msg_parameters is None: msg_parameters = [] elif not isinstance(msg_parameters, Sequence) or isinstance( msg_parameters, (str, bytes)): msg_parameters = [msg_parameters] if not msg_address.startswith("/"): msg_address = "/" + msg_address builder = OscMessageBuilder(address=msg_address) for msg_arg in msg_parameters: if isinstance(msg_arg, np.number): msg_arg = msg_arg.item() builder.add_arg(msg_arg) return builder.build()
def main(): #print("\n" + "get sensor data") sensordata = np.array(sensor.pixels) sensordata = sensordata[:, ::-1] #for row in sensordata: # print (["{0:.1f}".format(temp) for temp in row]) print("\n") print(sensordata.max()) if sensordata.max() > basetemp: #pos =list(zip(*np.where(sensordata > sensordata.max() * 0.95))) pos = list(zip(*np.where(sensordata == sensordata.max()))) print(pos) msg = OscMessageBuilder(address="/pos") for i in pos: msg = OscMessageBuilder(address="/pos") x, y = i msg.add_arg(int(x)) msg.add_arg(int(y)) m = msg.build() print(m.address, m.params) client.send(m) time.sleep(0.05) else: print("nobody is here")
def get_message(self)-> OscMessage: """ returns the OSC message of the Blob with the TUIO spezification """ x, y = self.position X, Y = self.velocity w, h = self.dimension builder = OscMessageBuilder(address=TUIO_BLOB) for val in [ "set", self.session_id, float(x), float(y), float(self.angle), float(w), float(h), float(self.area), float(X), float(Y), float(self.velocity_rotation), float(self.motion_acceleration), float(self.rotation_acceleration) ]: builder.add_arg(val) return builder.build()
def oscReceive(unused_addr, bang): print('Receive Number: ' + bang) msg = OscMessageBuilder(address='/') msg.add_arg('is genius.') m = msg.build() client.send(m)
def osc_message(address, args=()): print(args) builder = OscMessageBuilder(address) if not isinstance(args, Iterable) or isinstance(args, (str, bytes)): args = [args] for arg in args: builder.add_arg(arg) return builder.build()
def send_color(r, g, b): msg = OscMessageBuilder(address='/CV06/pixel') #msg.add_arg(r, 'i') #msg.add_arg(g, 'i') msg.add_arg(b, 'i') m = msg.build() print(m.address, m.params) client.send(m)
def adjust_balloons(): global balloon_osc if not balloon_osc: balloon_osc = UDPClient('0.0.0.0', 5005) msg = OscMessageBuilder("/adjust") balloon_osc.send(msg.build()) logging.info("sent adjustment")
class Orientation3D(object): """Reads out all sensor data from either a local or remote Pozyx""" def __init__(self, pozyx, osc_udp_client, remote_id=None): self.pozyx = pozyx self.remote_id = remote_id self.osc_udp_client = osc_udp_client def setup(self): """There is no specific setup functionality""" self.current_time = time() def loop(self): """Gets new IMU sensor data""" sensor_data = SensorData() calibration_status = SingleRegister() if self.remote_id is not None or self.pozyx.checkForFlag( POZYX_INT_MASK_IMU, 0.01) == POZYX_SUCCESS: status = self.pozyx.getAllSensorData(sensor_data, self.remote_id) status &= self.pozyx.getCalibrationStatus(calibration_status, self.remote_id) if status == POZYX_SUCCESS: self.publishSensorData(sensor_data, calibration_status) return sensor_data return "Error, no data to print for this line" def publishSensorData(self, sensor_data, calibration_status): """Makes the OSC sensor data package and publishes it""" self.msg_builder = OscMessageBuilder("/sensordata") self.msg_builder.add_arg(int(1000 * (time() - self.current_time))) current_time = time() self.addSensorData(sensor_data) self.addCalibrationStatus(calibration_status) self.osc_udp_client.send(self.msg_builder.build()) def addSensorData(self, sensor_data): """Adds the sensor data to the OSC message""" self.msg_builder.add_arg(sensor_data.pressure) self.addComponentsOSC(sensor_data.acceleration) self.addComponentsOSC(sensor_data.magnetic) self.addComponentsOSC(sensor_data.angular_vel) self.addComponentsOSC(sensor_data.euler_angles) self.addComponentsOSC(sensor_data.quaternion) self.addComponentsOSC(sensor_data.linear_acceleration) self.addComponentsOSC(sensor_data.gravity_vector) def addComponentsOSC(self, component): """Adds a sensor data component to the OSC message""" for data in component.data: self.msg_builder.add_arg(float(data)) def addCalibrationStatus(self, calibration_status): """Adds the calibration status data to the OSC message""" self.msg_builder.add_arg(calibration_status[0] & 0x03) self.msg_builder.add_arg((calibration_status[0] & 0x0C) >> 2) self.msg_builder.add_arg((calibration_status[0] & 0x30) >> 4) self.msg_builder.add_arg((calibration_status[0] & 0xC0) >> 6)
def send_patch_bay(self, output_num, values): if self.verbose: print("bay %d: %s" % (output_num, str(values))) builder = OscMessageBuilder(address="/repatcher/output" + str(output_num)) for v in values: builder.add_arg(v) msg = builder.build() self.client.send(msg)
def send(self, pose_id, pose_proba): if not self._is_running: return False msg = OscMessageBuilder(address=self.POSE_LABEL) msg.add_arg(pose_id) msg.add_arg(pose_proba) m = msg.build() self._client.send(m) return True
def send_message(self, address, value): builder = OscMessageBuilder(address=address) if value != '': if not isinstance(value, Iterable) or isinstance( value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() self.send(msg)
def send_message(self, address, *args): msg = OscMessageBuilder(address) for arg in args: msg.add_arg(arg) data = msg.build().dgram if self.osc_spec == 1.0: length = len(data) data = struct.pack('>i', length) + data self._to_write.put_nowait(data) else: data = self._slip_driver.send(data) self._to_write.put_nowait(data)
def send_message(self, address, value): builder = OscMessageBuilder(address=address) if value is None: values = [] elif isinstance(value, list): values = value else: values = [value] for val in values: builder.add_arg(val) msg = builder.build() self.socket.sendto(msg.dgram, self.xr_address)
def main(): ip = '127.0.0.1' port = 6700 client = udp_client.UDPClient(ip, port) args = [0, 228, 123] data = OscMessageBuilder(address='/address') data.add_arg(args) data = data.build() client.send(data)
def _build_alive(address, profile_list): """ builds a OSC which implements a alive message of TUIO returns the message """ builder = OscMessageBuilder(address=address) builder.add_arg("alive") for profile in profile_list: builder.add_arg(profile.session_id) ## add id of cursors alive_msg = builder.build() return alive_msg
def affect_candidate(candidate, osc_msg, amount): global balloon_osc if not balloon_osc: balloon_osc = UDPClient('0.0.0.0', 5005) osc_callback_msg = pickle.dumps(osc_msg) msg = OscMessageBuilder("/instruction") msg.add_arg(candidate) msg.add_arg(amount) msg.add_arg(osc_callback_msg) balloon_osc.send(msg.build()) logging.info("sent instruction %s, %d" % (candidate, amount))
def SendBPM(BPM): if BPM.isdecimal(): BPM=int(BPM) if 0<BPM<=960: msg = OscMessageBuilder(address='/BPM') msg.add_arg(int(BPM)) m = msg.build() print(m.address, m.params) client.send(m) else: print("error: 0<BPM<=960"); else: print ("error:Please enter the correct value")
def build_osc_message(self, address, value): """ composes OSC message in proper format for sending """ builder = OscMessageBuilder(address=address) if not isinstance(value, Iterable) or isinstance(value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() return msg.dgram
def send_pose(client: udp_client, landmark_list: landmark_pb2.NormalizedLandmarkList): if landmark_list is None: client.send_message(OSC_ADDRESS, 0) return # create message and send builder = OscMessageBuilder(address=OSC_ADDRESS) builder.add_arg(1) for landmark in landmark_list.landmark: builder.add_arg(landmark.x) builder.add_arg(landmark.y) builder.add_arg(landmark.z) builder.add_arg(landmark.visibility) msg = builder.build() client.send(msg)
def send_bundle(self): """Build :class:`OscMessage` from arguments and send to server Args: address: OSC address the message shall go to value: One or more arguments to be added to the message """ bundle_builder = OscBundleBuilder(0) # build alive message bundle_builder.add_content( TuioServer._build_alive(TUIO_CURSOR, self.cursors)) bundle_builder.add_content( TuioServer._build_alive(TUIO_BLOB, self.blobs)) bundle_builder.add_content( TuioServer._build_alive(TUIO_OBJECT, self.objects)) # set message of cursor for cursor in self.cursors: cursor_msg = cursor.get_message() bundle_builder.add_content(cursor_msg) # set message of blob for blob in self.blobs: blob_msg = blob.get_message() bundle_builder.add_content(blob_msg) # set message of object for o in self.objects: object_msg = o.get_message() bundle_builder.add_content(object_msg) # message fseq to end the bundle and send (optinal) frame id builder = OscMessageBuilder(address=TUIO_CURSOR) builder.add_arg("fseq") builder.add_arg(-1) fseq = builder.build() bundle_builder.add_content(fseq) # build bundle and send bundle = bundle_builder.build() self.send(bundle)
def send_hands(client: udp_client, detections: [landmark_pb2.NormalizedLandmarkList]): if detections is None: client.send_message(OSC_ADDRESS, 0) return # create message and send builder = OscMessageBuilder(address=OSC_ADDRESS) builder.add_arg(len(detections)) for detection in detections: for landmark in detection.landmark: builder.add_arg(landmark.x) builder.add_arg(landmark.y) builder.add_arg(landmark.z) builder.add_arg(landmark.visibility) msg = builder.build() client.send(msg)
def updateLines(lineName): if not lineName in lines: lines.append(lineName) msg = OscMessageBuilder(address='/tubeLines') msg.add_arg(lineName) #color if lineName in colorIndex: color = colorIndex[lineName] else: color = colorIndex['Others'] msg.add_arg(color) m = msg.build() client.send(m) print('sent a new line: {} ({})'. format(lineName, color))
def __init__(self, scsynth_address=('127.0.0.1', 50000), message_address=('192.168.2.1', 50001), recipient_addresses=( ('192.168.2.2', 50001), ('192.168.2.3', 50001), ), nids_start=10000, nids_end=40000, pan=0, personality_assertiveness=0.10, personality_moodiness=0.02, personality_confidence=0.05, personality_irritability=0.10, **kwargs ): super().__init__(**kwargs) self._client = UDPClient(*scsynth_address) self._message_server = _MessageServer(message_address, self) self._message_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._recipient_addresses = recipient_addresses self._moods = [ Mood(self, SimpleBlipperEngine), Mood(self, SimpleBlipperEngine), Mood(self, SimpleBlipperEngine), Mood(self, SimpleBlipperEngine), Mood(self, FlitterEngine), Mood(self, FlitterEngine), Mood(self, FlitterEngine), Mood(self, BellsEngine), ] self.running = False self.parameter_lock = threading.Lock() self.manager = manager.SynthManager(self._client, nids_start=nids_start, nids_end=nids_end, pan=pan) msg = OscMessageBuilder(address='/d_recv') # send synthdefs to scsynth msg.add_arg(synthdefs.pisynth1) self._client.send(msg.build()) self.personality_assertiveness = personality_assertiveness self.personality_moodiness = personality_moodiness self.personality_confidence = personality_confidence self.personality_irritability = personality_irritability
def get_message(self)-> OscMessage: """ returns the OSC message of the Cursor with the TUIO spezification """ x, y = self.position X, Y = self.velocity builder = OscMessageBuilder(address=TUIO_CURSOR) for val in [ "set", self.session_id, float(x), float(y), float(X), float(Y), float(self.motion_acceleration) ]: builder.add_arg(val) return builder.build()
def send_message(self, address: str, value: Union[int, float, bytes, str, bool, tuple, list]) -> None: """Build :class:`OscMessage` from arguments and send to server Args: address: OSC address the message shall go to value: One or more arguments to be added to the message """ builder = OscMessageBuilder(address=address) if value is None: values = [] elif not isinstance(value, Iterable) or isinstance(value, (str, bytes)): values = [value] else: values = value for val in values: builder.add_arg(val) msg = builder.build() self.send(msg)
def main(): # 受信先のVRChat IP = '127.0.0.1' PORT = 9000 # OSCメッセージ情報の読み込み address = sys.argv[1] arg = sys.argv[2] print('Address: ' + address) print('Arg: ' + arg) # OSCメッセージの構築 client = udp_client.UDPClient(IP, PORT) msg = OscMessageBuilder(address=address) msg.add_arg(arg) m = msg.build() # OSCメッセージの送信 client.send(m)
def get_message(self) -> OscMessage: """ returns the OSC message of the Object with the TUIO spezification """ x, y = self.position X, Y = self.velocity builder = OscMessageBuilder(address=TUIO_OBJECT) for val in [ "set", int(self.session_id), int(self.class_id), float(x), float(y), float(self.angle), float(X), float(Y), float(self.velocity_rotation), float(self.motion_acceleration), float(self.rotation_acceleration) ]: builder.add_arg(val) return builder.build()
def build_osc_message(array): builder = OscMessageBuilder(address='/wek/inputs') for val in array: builder.add_arg(val) return builder.build()
deg_psi = math.degrees(psi) deg_phi = math.degrees(phi) return [deg_theta, deg_psi, deg_phi] #MPU_Init() cnt = 0 Before_a = 1.0 interval = 10 client = udp_client.UDPClient(IP, PORT) while 1: ax, ay, az = getAccel() #print ('x={0:4.3f}, y={1:4.3f}, z={2:4.3f},' .format(ax, ay, az)) a = math.sqrt((ay * ay) + (az * az)) j = a - Before_a if (j >= 0.5 and interval >= 10): print(cnt) interval = 0 msg = OscMessageBuilder(address='/comand') msg.add_arg(cnt) m = msg.build() client.send(m) cnt += 1 Before_a = a interval += 1 sleep(0.01)
class Orientation3D(object): """Reads out all sensor data from either a local or remote Pozyx""" def __init__(self, pozyx, osc_udp_client, remote_id=None): self.pozyx = pozyx self.remote_id = remote_id self.osc_udp_client = osc_udp_client def setup(self): """There is no specific setup functionality""" self.current_time = time() def loop(self, attributeToLog, elapsed, timeDifference, index=None): """Gets new IMU sensor data""" sensor_data = SensorData() calibration_status = SingleRegister() if self.remote_id is not None or self.pozyx.checkForFlag( POZYX_INT_MASK_IMU, 0.01) == POZYX_SUCCESS: status = self.pozyx.getAllSensorData(sensor_data, self.remote_id) status &= self.pozyx.getCalibrationStatus(calibration_status, self.remote_id) if status == POZYX_SUCCESS: self.publishSensorData(sensor_data, calibration_status, attributeToLog, elapsed, timeDifference, index) def publishSensorData(self, sensor_data, calibration_status, attributeToLog, elapsed, timeDifference, index): """Makes the OSC sensor data package and publishes it""" self.msg_builder = OscMessageBuilder("/sensordata") self.msg_builder.add_arg(int(1000 * (time() - self.current_time))) current_time = time() self.addSensorData(sensor_data) self.printSensorData(sensor_data, attributeToLog, elapsed, timeDifference) self.addCalibrationStatus(calibration_status) self.osc_udp_client.send(self.msg_builder.build()) def addSensorData(self, sensor_data): """Adds the sensor data to the OSC message""" self.msg_builder.add_arg(sensor_data.pressure) self.addComponentsOSC(sensor_data.acceleration) self.addComponentsOSC(sensor_data.magnetic) self.addComponentsOSC(sensor_data.angular_vel) self.addComponentsOSC(sensor_data.euler_angles) self.addComponentsOSC(sensor_data.quaternion) self.addComponentsOSC(sensor_data.linear_acceleration) self.addComponentsOSC(sensor_data.gravity_vector) def addComponentsOSC(self, component): """Adds a sensor data component to the OSC message""" for data in component.data: self.msg_builder.add_arg(float(data)) def addCalibrationStatus(self, calibration_status): """Adds the calibration status data to the OSC message""" self.msg_builder.add_arg(calibration_status[0] & 0x03) self.msg_builder.add_arg((calibration_status[0] & 0x0C) >> 2) self.msg_builder.add_arg((calibration_status[0] & 0x30) >> 4) self.msg_builder.add_arg((calibration_status[0] & 0xC0) >> 6) def printSensorData(self, sensor_data, attributeToLog, elapsed, timeDifference): """Prints the Sensor Data to the Console""" try: hertz = 1 / timeDifference except ZeroDivisionError: hertz = 0 try: averageHertz = index / elapsed except ZeroDivisionError: averageHertz = 0 averageHertz = strSetLength(averageHertz, 7) elapsed = strSetLength(elapsed, 10) timeDifference = strSetLength(timeDifference, 10) hertz = strSetLength(hertz, 5) #this is a longer version of the print output including the difference in time between cycles #output = str(index) + " Total: " + elapsed + " Diff: " + timeDifference + " Hz: " + hertz + " " output = str( index ) + " Total: " + elapsed + " Hz: " + hertz + " AveHz: " + averageHertz + " | " if attributeToLog == "pressure": output += "Pressure: " + str(sensor_data.pressure) + " pa" elif attributeToLog == "acceleration": x = strSetLength(sensor_data.acceleration.x, 8) y = strSetLength(sensor_data.acceleration.y, 8) z = strSetLength(sensor_data.acceleration.z, 8) output = "Acceleration: " + " X: " + x + " Y: " + y + " Z: " + z elif attributeToLog == "magnetic": x = strSetLength(sensor_data.magnetic.x, 8) y = strSetLength(sensor_data.magnetic.y, 8) z = strSetLength(sensor_data.magnetic.z, 8) output += "Magnetic Field: " + " X: " + x + " Y: " + y + " Z: " + z elif attributeToLog == "angular velocity": x = strSetLength(sensor_data.angular_vel.x, 8) y = strSetLength(sensor_data.angular_vel.y, 8) z = strSetLength(sensor_data.angular_vel.z, 8) output += "Angular Velocity: " + " X: " + x + " Y: " + y + " Z: " + z elif attributeToLog == "euler angles": heading = strSetLength(sensor_data.euler_angles.heading, 8) roll = strSetLength(sensor_data.euler_angles.roll, 8) pitch = strSetLength(sensor_data.euler_angles.pitch, 8) output += "Euler Angles: " + " Heading: " + heading + " Roll: " + roll + " Pitch: " + pitch elif attributeToLog == "quaternion": x = strSetLength(sensor_data.quaternion.x, 16) y = strSetLength(sensor_data.quaternion.y, 16) z = strSetLength(sensor_data.quaternion.z, 16) w = strSetLength(sensor_data.quaternion.w, 16) output += "Quaternion: " + " X: " + x + " Y: " + y + " Z: " + z + " W: " + w elif attributeToLog == "linear acceleration": x = strSetLength(sensor_data.linear_acceleration.x, 8) y = strSetLength(sensor_data.linear_acceleration.y, 8) z = strSetLength(sensor_data.linear_acceleration.z, 8) output += "Linear Acceleration: " + " X: " + x + " Y: " + y + " Z: " + z elif attributeToLog == "gravity": x = strSetLength(sensor_data.gravity_vector.x, 8) y = strSetLength(sensor_data.gravity_vector.y, 8) z = strSetLength(sensor_data.gravity_vector.z, 8) output += "Gravity Vector: " + " X: " + x + " Y: " + y + " Z: " + z print(output)
def build_osc_message(positioning_values): builder = OscMessageBuilder(address='/wek/inputs') for v in positioning_values: builder.add_arg(v) return builder.build()
def control_wekinator(endpoint, arg=None): builder = OscMessageBuilder('/wekinator/control/{}'.format(endpoint)) if arg is not None: builder.add_arg(arg) msg = builder.build() udp_client.UDPClient('127.0.0.1', 6448).send(msg)