def _notify(self, handle, data):
     if handle != C.MOVE_HUB_HARDWARE_HANDLE:
         logging.warning("Unsupported notification handle: 0x%s", handle)
         return          
     logging.debug("_notify() Notification on %s: %s", handle, str2hex(data))
     
     msg_type = usbyte(data, 2)
     # Meldungstyp anhand des 2. Bytes identifizieren:
     if msg_type == C.MSG_PORT_INFO:
         self._handle_port_info(data)
     elif msg_type == C.MSG_PORT_STATUS:
         self._handle_port_status(data)
     elif msg_type == C.MSG_SENSOR_DATA:
         self._handle_sensor_data(data)
     elif msg_type == C.MSG_SENSOR_SUBSCRIBE_ACK:
         port = usbyte(data, 3)
         logging.debug("Sensor subscribe ack on port %s", C.PORTS[port])
         self.devices[port].finished()
     elif msg_type == C.MSG_PORT_CMD_ERROR:
         logging.warning("Command error: %s", str2hex(data[3:]))
         port = usbyte(data, 3)
         self.devices[port].finished()
     elif msg_type == C.MSG_DEVICE_SHUTDOWN:
         logging.warning("Device reported shutdown: %s", str2hex(data))
         raise KeyboardInterrupt("Device shutdown")
     elif msg_type == C.MSG_DEVICE_INFO:
         self._handle_device_info(data)
     else:
         logging.warning("Unhandled msg type 0x%x: %s", msg_type, str2hex(data))
 def _handle_device_info(self, data):
     kind = usbyte(data, 3)
     if kind == 2:
         self.button.handle_port_data(data)
     if usbyte(data, 4) == 0x06:
         self.info[kind] = data[5:]
     else:
         logging.warning("Unhandled device info: %s", str2hex(data))
Beispiel #3
0
 def _queue_reader(self):
     while True:
         data = self._incoming_port_data.get()  # Daten aus Queue lesen
         try:
             self.handle_port_data(data)  # Daten interpretieren
         except BaseException:
             logging.warning("%s", traceback.format_exc())
             logging.warning("Failed to handle port data by %s: %s", self,
                             str2hex(data))
Beispiel #4
0
 def handle_port_data(self, data):
     if self._port_subscription_mode == self.COLOR_DISTANCE_FLOAT:
         color = usbyte(data, 4)
         distance = usbyte(data, 5)
         partial = usbyte(data, 7)
         if partial:
             distance += 1.0 / partial
         self._notify_subscribers(color, float(distance))
     elif self._port_subscription_mode == self.COLOR_ONLY:
         color = usbyte(data, 4)
         self._notify_subscribers(color)
     elif self._port_subscription_mode == self.DISTANCE_INCHES:
         distance = usbyte(data, 4)
         self._notify_subscribers(distance)
     elif self._port_subscription_mode == self.DISTANCE_HOW_CLOSE:
         distance = usbyte(data, 4)
         self._notify_subscribers(distance)
     elif self._port_subscription_mode == self.DISTANCE_SUBINCH_HOW_CLOSE:
         distance = usbyte(data, 4)
         self._notify_subscribers(distance)
     elif self._port_subscription_mode == self.OFF1 or self._port_subscription_mode == self.OFF2:
         logging.info("Turned off led on %s", self)
     elif self._port_subscription_mode == self.COUNT_2INCH:
         count = unpack("<L", data[4:8])[0]  # is it all 4 bytes or just 2?
         self._notify_subscribers(count)
     elif self._port_subscription_mode == self.STREAM_3_VALUES:
         # TODO: understand better meaning of these 3 values
         val1 = ushort(data, 4)
         val2 = ushort(data, 6)
         val3 = ushort(data, 8)
         self._notify_subscribers(val1, val2, val3)
     elif self._port_subscription_mode == self.LUMINOSITY:
         luminosity = ushort(data, 4) / 1023.0
         self._notify_subscribers(luminosity)
     else:  # TODO: support whatever we forgot
         logging.debug("Unhandled data in mode %s: %s",
                       self._port_subscription_mode, str2hex(data))
Beispiel #5
0
 def handle_port_data(self, data):
     logging.warning("Unhandled device notification for %s: %s", self,
                     str2hex(data[4:]))
     self._notify_subscribers(data[4:])
 def write(self,handle,data): # Schreiben Charakteristik ueber angegebenes Handle
     logging.debug("BlueGiga: Writing to handle %s: %s", handle, str2hex(data))
     return self.conn_hnd.char_write_handle(handle,data) 
 def write(self,handle,data): # Schreiben an Charakteristic 0x0e
     logging.debug("BlueZ: Writing to handle 0x0e: %s", str2hex(data))
     return self.conn_hnd_char.write_value(data)