SENA Parani-MSP1000 User Manual

Page 76

Advertising
background image

76

(23, "information"))

for bitpos, classname in service_classes:

if device_class & (1 << (bitpos-1)) and classname == "object

transfer":

scan_info.append(address)

def inquiry_complete(self):

self.done = True

def sendfile(bdaddr, i):

if len(send_info) > 0:

for item in send_info:

if item['addr'] == bdaddr:

return

services = lightblue.findservices(addr=bdaddr, servicetype=lightblue.OBEX)
address, serviceport, servicename = services[0]
lightblue.obex.sendfile(address, serviceport, file_path)
temp = {'addr': bdaddr, 'time': time()}
send_info.append(temp)

def update_send_info():

cur_time = time()

for item in send_info:

if cur_time - item['time'] > send_interval:

send_info.remove(item)

send_info = []

while True:

scan_info = []
threads = []
nloops = 0

d = MyDiscoverer()
d.find_devices(lookup_names = True)

readfiles = [ d, ]

while True:

rfds = select.select( readfiles, [], [] )[0]

if d in rfds:

d.process_event()

if d.done: break

if len(send_info) > 0:

update_send_info()

for item in scan_info:

t = threading.Thread(target=sendfile, args=(item, 0))
threads.append(t)
nloops += 1

for i in range(0, nloops):

threads[i].start()
sleep(5)

for i in range(0, nloops):

threads[i].join()

del scan_info
del threads
del nloops

Advertising