def send_packets_to_android(self, ibus_packets): """ Sends data via Bluetooth socket connection """ if not self.conn_established: return False try: print ("Sending encapsulated IBUSPacket(s)...") packets = [] for ibus_packet in ibus_packets: packets.append(ibus_packet.as_dict()) # encapsulate IBUS packets and send data = {"data": json.dumps(packets)} if globals.debug: print data self.client_sock.send(data) return True except Exception as e: # socket was closed, graceful restart print "Error: " + e.message globals.restart_bluetooth() return False
def send_packets_to_android(self, ibus_packets): """ Sends data via Bluetooth socket connection """ if self.conn_established: try: print ("Sending encapsulated IBUSPacket(s)...") packets = [] for ibus_packet in ibus_packets: packets.append(ibus_packet.as_dict()) # encapsulate IBUS packet in BlueBUSPacket packet = BlueBUSPacket(packet_type=BlueBUSPacket.TYPE_PACKET, data=json.dumps(packets)) # serialize BlueBusPacket and send json_data = json.dumps(packet.as_dict()) if globals.debug: print json_data self.client_sock.send(json_data) # packet sent successfully #print packet return True except Exception as e: # socket was closed, graceful restart print "Error: " + e.message globals.restart_bluetooth() return False
def send_packets_to_android(self, ibus_packets): """ Sends data via Bluetooth socket connection """ if not self.conn_established: return False try: print("Sending encapsulated IBUSPacket(s)...") packets = [] for ibus_packet in ibus_packets: packets.append(ibus_packet.as_dict()) # encapsulate IBUS packets and send data = {"data": json.dumps(packets)} if globals.debug: print data self.client_sock.send(data) return True except Exception as e: # socket was closed, graceful restart print "Error: " + e.message globals.restart_bluetooth() return False
def send_packets_to_android(self, ibus_packets): """ Sends data via Bluetooth socket connection """ if self.conn_established: try: print("Sending encapsulated IBUSPacket(s)...") packets = [] for ibus_packet in ibus_packets: packets.append(ibus_packet.as_dict()) # encapsulate IBUS packet in BlueBUSPacket packet = BlueBUSPacket(packet_type=BlueBUSPacket.TYPE_PACKET, data=json.dumps(packets)) # serialize BlueBusPacket and send json_data = json.dumps(packet.as_dict()) if globals.debug: print json_data self.client_sock.send(json_data) # packet sent successfully #print packet return True except Exception as e: # socket was closed, graceful restart print "Error: " + e.message globals.restart_bluetooth() return False
def start_listening(self): """ Start listening for incoming data """ try: print "Starting to listen for data..." while True: data = self.client_sock.recv(2048) if len(data) > 0: self.process_data_from_android(data) except (IOError, Exception): print ("Android device was disconnected...") globals.restart_bluetooth()
def start_listening(self): """ Start listening for incoming data """ try: print "Starting to listen for data..." while True: data = self.client_sock.recv(2048) if len(data) > 0: self.process_data_from_android(data) except (IOError, Exception): print("Android device was disconnected...") globals.restart_bluetooth()
def send_command_to_android(self, command): """ Sends data via Bluetooth socket connection """ try: print ("Sending message...") # encapsulate command in BlueBUSPacket packet = BlueBUSPacket(packet_type=BlueBUSPacket.TYPE_COMMAND, data=command) # serialize BlueBusPacket and send json_data = json.dumps(packet.__dict__()) self.client_sock.send(json_data) #print packet return True except Exception as e: print "Error: " + e.message globals.restart_bluetooth() return False
def send_command_to_android(self, command): """ Sends data via Bluetooth socket connection """ try: print("Sending message...") # encapsulate command in BlueBUSPacket packet = BlueBUSPacket(packet_type=BlueBUSPacket.TYPE_COMMAND, data=command) # serialize BlueBusPacket and send json_data = json.dumps(packet.__dict__()) self.client_sock.send(json_data) #print packet return True except Exception as e: print "Error: " + e.message globals.restart_bluetooth() return False