def _sendThreadFunc(self): log.debug("Send Thread started.") while not self.exit_requested: # Little bit ugly: need to re-apply changes to the global context to the thread-copy context.log_level = self.log_level # Wait for 'send task' in send queue try: task = self.sendQueue.get(timeout=0.5) except queue2k.Empty: continue # Extract the components of the task h4type, data, queue, filter_function = task # Prepend UART TYPE and length. out = p8(h4type) + p8(len(data)) + data # Send command to the chip using IOBluetoothExtended framework h4type, data, queue, filter_function = task data = bytearray(data) opcode = format(data[1], "02x") + format(data[0], "02x") log.debug("Sending command: 0x" + "".join(format(x, "02x") for x in data) + ", opcode: " + opcode) if not (h4type == 0x01 or h4type == 0x02): log.warn("H4 Type {0} not supported by macOS Core!".format( str(h4type))) if queue is not None: queue.put(None) continue # if the caller expects a response: register a queue to receive the response if queue is not None and filter_function is not None: recvQueue = queue2k.Queue(1) self.registerHciRecvQueue(recvQueue, filter_function) # Sending command self.s_inject.sendto(out, ("127.0.0.1", self.hciport + 1)) # if the caller expects a response: # Wait for the HCI event response by polling the recvQueue if queue is not None and filter_function is not None: try: record = recvQueue.get(timeout=10) hcipkt = record[0] data = hcipkt.data except queue2k.Empty: log.warn("_sendThreadFunc: No response from the firmware.") data = None self.unregisterHciRecvQueue(recvQueue) continue queue.put(data) self.unregisterHciRecvQueue(recvQueue) log.debug("Send Thread terminated.")
def getRaw(self): return (super(HCI_Event, self).getRaw() + p8(self.event_code) + p8(self.length) + self.data)
def getRaw(self): return super(HCI_Diag, self).getRaw() + p8(self.opcode) + self.data
def getRaw(self): raw = bits(p16(self.handle))[4:] raw.extend(bits(p8(self.ps))[6:]) raw.extend(bits(p8(0))[6:]) raw.extend(bits(p8(self.length))) return super(HCI_Sco, self).getRaw() + unbits(raw) + self.data
def getRaw(self): return (super(HCI_Cmd, self).getRaw() + p16(self.opcode) + p8(self.length) + self.data)
def getRaw(self): return p8(self.uart_type)