def dict_to_string(self, d): # Try to trivially translate a dictionary's elements into nice string # formatting. dstr="" for key in d: val=d[key] str_val="" add_string=True if type(val)==type(dbus.Array([])): for elt in val: if type(elt)==type(dbus.Byte(1)): str_val+="%s " % int(elt) elif type(elt)==type(dbus.String("")): str_val+="%s" % elt elif type(val)==type(dbus.Dictionary({})): dstr+=self.dict_to_string(val) add_string=False else: str_val=val if add_string: dstr+="%s: %s\n" % ( key, str_val) return dstr
def __init__(self, bus, index, service): Characteristic.__init__(self, bus, index, self.FITNESS_MACHINE_FEATURE_UUID, ['read'], service) self.notifying = False self.value = [ dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0) ] # ble com module waterrower software revision self.value[0] = 0x26 self.value[1] = 0x56 self.value[2] = 0x00 self.value[3] = 0x00 self.value[4] = 0x00 self.value[5] = 0x00 self.value[6] = 0x00 self.value[7] = 0x00
def __init__(self): self.bus = dbus.SystemBus() self.app = localGATT.Application() self.srv = localGATT.Service(1, CPU_TMP_SRVC, True) self.charc = TemperatureChrc(self.srv) self.charc.service = self.srv.path cpu_format_value = dbus.Array([ dbus.Byte(0x0E), dbus.Byte(0xFE), dbus.Byte(0x2F), dbus.Byte(0x27), dbus.Byte(0x01), dbus.Byte(0x00), dbus.Byte(0x00) ]) self.cpu_format = localGATT.Descriptor(4, CPU_FMT_DSCP, self.charc, cpu_format_value, ['read']) self.app.add_managed_object(self.srv) self.app.add_managed_object(self.charc) self.app.add_managed_object(self.cpu_format) self.srv_mng = GATT.GattManager(adapter.list_adapters()[0]) self.srv_mng.register_application(self.app, {}) self.dongle = adapter.Adapter(adapter.list_adapters()[0]) advert = advertisement.Advertisement(1, 'peripheral') advert.service_UUIDs = [CPU_TMP_SRVC] advert.local_name = 'CPU Temp' advert.appearance = 1344 # eddystone_data = tools.url_to_advert(WEB_BLINKT, 0x10, TX_POWER) # advert.service_data = {EDDYSTONE: eddystone_data} if not self.dongle.powered: self.dongle.powered = True ad_manager = advertisement.AdvertisingManager(self.dongle.address) ad_manager.register_advertisement(advert, {})
def emit(self, record): level = record.levelno message = self.format(record) if message.endswith('\n'): message = message[:-1] if level <= log.INFO: timeout = 10 urgency = 0 elif level <= log.WARNING: timeout = 15 urgency = 1 else: timeout = 0 urgency = 2 self._notify.Notify( APPNAME, 0, APPICON, # app_name, replaces_id, app_icon APPNAME, message, '', # actions {'urgency': dbus.Byte(urgency)}, timeout * 1000)
def ReadValue(self, options): logging.debug('Read Firmware') val = uuids.FIRMWARE_VERSION #supervisorAddress = str(os.environ['BALENA_SUPERVISOR_ADDRESS']) #supervisorKey = str(os.environ['BALENA_SUPERVISOR_API_KEY']) #supervisorAddress = "%s/v2/applications/state?apikey=%s" % \ # (supervisorAddress, supervisorKey) #with urllib.request.urlopen(supervisorAddress) as url: # data = json.loads(url.read().decode()) # if(data[list(data)[0]]['services']['gateway-config']['status'] # != "Running" or # data[list(data)[0]]['services']['helium-miner']['status'] # != "Running"): # val = "2000.01.01.01" value = [] for c in val: value.append(dbus.Byte(c.encode())) return value
def launch_guidance(route): g_mapmatchedposition_interface.SetSimulationMode( dbus.UInt32(g_navigationcore_session_handle), dbus.Boolean(True)) g_guidance_interface.StartGuidance( dbus.UInt32(g_navigationcore_session_handle), dbus.UInt32(route)) g_mapviewercontrol_interface.SetFollowCarMode( dbus.UInt32(g_navigationcore_session_handle), dbus.UInt32(g_mapviewer_maphandle), True) g_mapviewercontrol_interface.SetMapViewScale( dbus.UInt32(g_mapviewer_sessionhandle), dbus.UInt32(g_mapviewer_maphandle), ZOOM_GUIDANCE) g_mapviewercontrol_interface.SetTargetPoint(dbus.UInt32(g_mapviewer_sessionhandle),\ dbus.UInt32(g_mapviewer_maphandle),\ dbus.Struct((\ dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][0]),\ dbus.Double(locations[routes[g_current_route].getElementsByTagName("start")[0].childNodes[0].data][1]),\ dbus.Double(0)\ ))) g_mapmatchedposition_interface.StartSimulation( dbus.UInt32(g_navigationcore_session_handle)) g_mapmatchedposition_interface.SetSimulationSpeed( dbus.UInt32(g_navigationcore_session_handle), dbus.Byte(SPEED_FACTOR_SLOW))
def dict_to_string(d, indent): # Try to trivially translate a dictionary's elements into nice string # formatting. dstr = "" for key in d: val = d[key] str_val = "" add_string = True #There are trhee types: dbus Array, dbus Dictionary and just values if type(val) == type(dbus.Array([])): for elt in val: if type(elt) == type(dbus.Byte(1)): str_val += "%s " % int(elt) elif type(elt) == type(dbus.String("")): str_val += "%s" % elt elif type(val) == type(dbus.Dictionary({})): dstr += dict_to_string(val, indent + " ") add_string = False else: str_val = val if add_string: dstr += "%s%s: %s\n" % (indent, key, str_val) return dstr
def get_buffer(identifier, isGroup): if identifier not in buffers: cb = "buffer_input_group" if isGroup else "buffer_input" name = identifier logger.debug("Creating buffer for identifier %s (%s)", identifier, "group" if isGroup else "contact") nicklist = [] signal = getSignal() try: if isGroup: group = [dbus.Byte(x) for x in base64.b64decode(identifier)] name = signal.getGroupName(group) for number in signal.getGroupMembers(group): contact_name = signal.getContactName(number) if len(contact_name) == 0: contact_name = number nicklist.append(contact_name) else: name = signal.getContactName(identifier) if len(name) == 0: name = identifier logger.debug("%s %s is known as %s", "group" if isGroup else "contact", identifier, name) except dbus.exceptions.DBusException: pass buffers[identifier] = weechat.buffer_new(name, cb, identifier, "", "") weechat.buffer_set(buffers[identifier], "title", name) if len(nicklist) > 0: weechat.buffer_set(buffers[identifier], "nicklist", "1") weechat.buffer_set(buffers[identifier], "nicklist_display_groups", "0") for nick in nicklist: logger.debug("Adding %s to group %s", nick, identifier) weechat.nicklist_add_nick(buffers[identifier], "", nick, "", "", "", 1) return buffers[identifier]
def send_next_chunk(self): # Slice message up into first chunk and remainder tx_chunk = None tx_complete = None self.tx_mutex.acquire() if self.tx_remain and len(self.tx_remain) > 0: tx_chunk = self.tx_remain[:MAX_TX_LEN] self.tx_remain = self.tx_remain[MAX_TX_LEN:] if len(self.tx_remain) == 0: # Setup callback tx_complete = self.tx_complete # Get next message from queue if not self.tx_queue.empty(): self.tx_remain, self.tx_complete = self.tx_queue.get_nowait() else: self.tx_remain = None self.tx_complete = None self.tx_mutex.release() if tx_chunk and len(tx_chunk) > 0: # Convert string to array of DBus Bytes & send val = [dbus.Byte(b) for b in bytearray(tx_chunk)] self.PropertiesChanged(gattsvc.GATT_CHRC_IFACE, { 'Value' : val }, []) if tx_complete: tx_complete()
def get_IRWB(self): value = [] #value = [1] unit = "C" #cpu = CPUTemperature() #cpu = ir_slot06_t(slot_type,slot_active) #cpu = ir_slot06_t() #cpu = 1 #temp = cpu.temperature #value = 1 #irst = 1 irst = n.ir_slot06_t(slot_type, slot_active) print irst #if self.service.is_cartype(): # temp = (temp * 1.8) + 32 # unit = "F" # #strtemp = str(round(temp, 1)) + " " + unit strtemp = str(irst) for c in strtemp: value.append(dbus.Byte(c.encode())) return value
def ReadValue(self): """ meta_record = { "id": "asdf", "description": "", "size": 2, "type":'vadasf', "original_filename": 'asdf.mp', "directory": '..', "filename": "full.mp4", "status": "uploaded", "origin": "Local Upload", "updated": datetime.datetime.now().strftime('%Y-%m-%d %H:%M'), "duration": "" } self.value = array.array('B', json.dumps(meta_record)) self.value = self.value.tolist() print (self.value) return dbus.Array(self.value) """ print('Battery Level read: ' + repr(self.battery_lvl)) return [dbus.Byte(self.battery_lvl)]
def make_key_press(keymask, is_repeat): global start_ticks is_repeat = 1 if is_repeat else 0 t = get_loop_time() if start_ticks is None: start_ticks = t - 1000 t = t - start_ticks value = [] value.append(dbus.Byte(t & 0xff)) value.append(dbus.Byte((t >> 8) & 0xff)) value.append(dbus.Byte((t >> 16) & 0xff)) value.append(dbus.Byte((t >> 24) & 0xff)) value.append(dbus.Byte(keymask)) value.append(dbus.Byte(is_repeat)) return value
def __init__(self, bus, index, service): Characteristic.__init__( self, bus, index, self.SUPPORTED_POWER_RANGE_UUID, ['read'], service) self.value = [dbus.Byte(0), dbus.Byte(0), # Minimum Power dbus.Byte(0), dbus.Byte(0), # Maximum Power dbus.Byte(0), dbus.Byte(0)] # Minimum Increment uint_minimum_power = 25 & 0xFFFF self.value[1] = (np.int16(uint_minimum_power) & 0xFF00) >> 8 self.value[0] = (np.int16(uint_minimum_power) & 0xFF) uint_maximum_power = 800 & 0xFFFF self.value[3] = (np.int16(uint_maximum_power) & 0xFF00) >> 8 self.value[2] = (np.int16(uint_maximum_power) & 0xFF) uint_minimum_increment = 5 & 0xFFFF self.value[5] = (np.uint16(uint_minimum_increment) & 0xFF00) >> 8 self.value[4] = (np.uint16(uint_minimum_increment) & 0xFF)
def ReadValue(self, options): print('Battery Level read: ' + repr(self.battery_lvl)) return [dbus.Byte(self.battery_lvl)]
def notify_battery_level(self): if not self.notifying: return self.PropertiesChanged(GATT_CHRC_IFACE, {'Value': [dbus.Byte(self.battery_lvl)]}, [])
def Waterrower_cb(self): if ble_in_q_value: Waterrower_byte_values = Convert_Waterrower_raw_to_byte() value = [dbus.Byte(0x2C), dbus.Byte(0x0B), dbus.Byte(Waterrower_byte_values[0]), dbus.Byte(Waterrower_byte_values[1]), dbus.Byte(Waterrower_byte_values[2]), dbus.Byte(Waterrower_byte_values[3]), dbus.Byte(Waterrower_byte_values[4]), dbus.Byte(Waterrower_byte_values[5]), dbus.Byte(Waterrower_byte_values[6]), dbus.Byte(Waterrower_byte_values[7]), dbus.Byte(Waterrower_byte_values[8]), dbus.Byte(Waterrower_byte_values[9]), dbus.Byte(Waterrower_byte_values[10]), dbus.Byte(Waterrower_byte_values[11]),dbus.Byte(Waterrower_byte_values[12]),dbus.Byte(Waterrower_byte_values[13]),dbus.Byte(Waterrower_byte_values[14]), dbus.Byte(Waterrower_byte_values[15]), dbus.Byte(Waterrower_byte_values[16]), dbus.Byte(Waterrower_byte_values[17]), ] self.PropertiesChanged(GATT_CHRC_IFACE, { 'Value': value }, []) return self.notifying else: logger.warning("no data from s4 interface") pass
if categoryAndName[0] == ID_HOTEL or categoryAndName[0] == ID_STATION or categoryAndName[0] == ID_RESTAURANT_CAM or categoryAndName[0] == ID_RESTAURANT_CAM: print("Category ID: " + str(int(categoryAndName[0]))) categories.append(categoryAndName[0]) print("Name: " + categoryAndName[1]) attributes_hotel=[] attributes_station=[] attributes_hotel_cam=[] attributes_restaurant_cam=[] attributesDetails=[] ret=g_poiSearch_interface.GetCategoriesDetails(categories) for results in ret: if results[0][0] == ID_HOTEL: for attribute in results[1]: attributes_hotel.append(attribute[0]) attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_HOTEL),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) elif results[0][0] == ID_STATION: for attribute in results[1]: attributes_station.append(attribute[0]) attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_STATION),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) elif results[0][0] == ID_HOTEL_CAM: for attribute in results[1]: attributes_hotel_cam.append(attribute[0]) attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_HOTEL_CAM),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) elif results[0][0] == ID_RESTAURANT_CAM: for attribute in results[1]: attributes_restaurant_cam.append(attribute[0]) attributesDetails.append(dbus.Struct([dbus.UInt32(attribute[0]),dbus.UInt32(ID_RESTAURANT_CAM),dbus.Int32(1280),dbus.Struct([dbus.Byte(2),dbus.String("")]),dbus.Int32(1314),dbus.Boolean(False)])) ret=g_poiSearch_interface.GetRootCategory()
description='Send bluetooth audio to alsa card') argparser.add_argument('--alsa-device', '-d', dest='alsadev', help='Alsa device') argparser.add_argument('--adapter', '-a', dest='adapter', help='Bluetooth adapter', default='hci0') dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) A2DP_SINK_UUID = "0000110b-0000-1000-8000-00805f9B34fb" A2DP_SERVICE_UUID = "0000110d-0000-1000-8000-00805f9b34fb" SBC_CODEC = dbus.Byte(0x00) SBC_CAPABILITIES = dbus.Array( [dbus.Byte(0xff), dbus.Byte(0xff), dbus.Byte(2), dbus.Byte(64)]) SBC_CONFIGURATION = dbus.Array( [dbus.Byte(0x21), dbus.Byte(0x15), dbus.Byte(2), dbus.Byte(32)]) MP3_CODEC = dbus.Byte(0x01) MP3_CAPABILITIES = dbus.Array( [dbus.Byte(0x3f), dbus.Byte(0x07),
def WriteValue(self, value, options): self.value = value self.StartNotify() aktiviteter.getJSON() print("Values received") for item in aktiviteter.aktiviteterArray: date = datetime.strptime(item["date"], "%Y-%m-%d %H:%M") year = date.year year_1 = (year >> 8) & 0xFF year_2 = year & 0xFF month = date.month day = date.day hour = date.hour minute = date.minute text = item["text"] data = [] data.append(dbus.Byte(1)) data.append(dbus.Byte(year_1)) data.append(dbus.Byte(year_2)) data.append(dbus.Byte(month)) data.append(dbus.Byte(day)) data.append(dbus.Byte(hour)) data.append(dbus.Byte(minute)) for c in text[:13]: data.append(dbus.Byte(ord(c))) self.PropertiesChanged(GATT_CHRC_IFACE, {'Value': data}, []) if len(text) > 13: text = text[13:] textA = [text[i:i + 19] for i in range(0, len(text), 19)] i = 1 for e in textA: i += 1 data2 = [] data2.append(dbus.Byte(i)) for c in e: data2.append(dbus.Byte(ord(c))) self.PropertiesChanged(GATT_CHRC_IFACE, {'Value': data2}, []) if i == 253: break # end self.PropertiesChanged(GATT_CHRC_IFACE, {'Value': [dbus.Byte(255)]}, []) self.StopNotify()
def ReadValue(self, options): return [dbus.Byte(int(data.getData("rgb_fade_delay")))]
def ReadValue(self, options): return [dbus.Byte(int(data.getData("rgb_mode")))]
def bytes_to_dbusarray(bytesarray): """Helper function to represent Python bytearray as D-Bus Byte array""" return dbus.Array([dbus.Byte(elem) for elem in bytesarray], 'y')
def bytes_to_ay(self, bytes): """Convert Python bytes to a DBus bytearray""" return dbus.Array([dbus.Byte(b) for b in bytes], signature=dbus.Signature('y'), variant_level=1)
def ReadValue(self, options): return [dbus.Byte('T'), dbus.Byte('e'), dbus.Byte('s'), dbus.Byte('t')]
elif args[0] == 'new': conn = { 'connection': { 'permissions': ['user:joesix:'], 'autoconnect': False, 'type': '802-11-wireless', }, '802-11-wireless': { #'ssid': [ dbus.Byte(ord(c)) for c in "something" ], 'mode': 'infrastructure', 'security': '802-11-wireless-security', }, '802-1x': { 'eap': ['tls'], # peap, ttls 'client-cert': [dbus.Byte(ord(c)) for c in 'file:///home/foo/certs/cert.pem'] + [dbus.Byte(0)], 'private-key': [dbus.Byte(ord(c)) for c in 'file:///home/foo/certs/key.pem'] + [dbus.Byte(0)], 'ca-cert': [ dbus.Byte(ord(c)) for c in 'file:///home/foo/certs/cacert.pem' ] + [dbus.Byte(0)], 'private-key-password': "******", #'ca-cert': 'hash://server/sha256/5336d308fa263f9f07325baae58ac972876f419527a9bf67c5ede3e668d3a925', #'subject-match': '/CN=blah/emailAddress=foo@bar', #'phase2-auth': 'mschapv2', 'identity': 'test1',
def mac_to_dbus(mac): return [dbus.Byte(int(x, 16)) for x in mac.split(':')]
def str_to_dbusarray(word): """Helper function to represent Python string as D-Dbus Byte array""" return dbus.Array([dbus.Byte(ord(letter)) for letter in word], 'y')
def ReadValue(self, options): return [dbus.Byte(int(data.getData("autosleep")))]
def ReadValue(self, options): value = [] desc = uuids.DIAGNOSTICS_VALUE for c in desc: value.append(dbus.Byte(c.encode())) return value
def ReadValue(self, options): databyte = [] for c in data.getData("weather_city"): databyte.append(dbus.Byte(ord(c))) return databyte