diff options
author | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-12-13 15:38:02 +0600 |
---|---|---|
committer | Dmitry Moiseev <m0sia@m0sia.ru> | 2013-12-13 15:38:02 +0600 |
commit | db29fcb24521c4ab1c2bab3e7ffb512afdb74978 (patch) | |
tree | dea1f55368058fd6bbeabce40c4aed4c12c07793 /ParrotZik.py | |
parent | 29f7644f85980f77315ecbccc8c60842acda9b1c (diff) | |
download | pyParrotZikTCP-db29fcb24521c4ab1c2bab3e7ffb512afdb74978.tar.xz pyParrotZikTCP-db29fcb24521c4ab1c2bab3e7ffb512afdb74978.zip |
Added lightblue support in mac os x
Diffstat (limited to 'ParrotZik.py')
-rw-r--r-- | ParrotZik.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/ParrotZik.py b/ParrotZik.py index 73df83b..4510e27 100644 --- a/ParrotZik.py +++ b/ParrotZik.py @@ -1,6 +1,11 @@ #!/usr/bin/env python -import bluetooth +import sys +if sys.platform == "darwin": + import lightblue +else: + import bluetooth + import ParrotProtocol import struct from BeautifulSoup import BeautifulSoup @@ -9,7 +14,11 @@ class ParrotZik(object): def __init__(self,addr=None): uuid = "0ef0f502-f0ee-46c9-986c-54ed027807fb" - service_matches = bluetooth.find_service( uuid = uuid, address = addr ) + + if sys.platform == "darwin": + service_matches = lightblue.findservices( name = "RFCOMM", addr = addr ) + else: + service_matches = bluetooth.find_service( uuid = uuid, address = addr ) if len(service_matches) == 0: print "Failed to find Parrot Zik RFCOMM service" @@ -23,7 +32,11 @@ class ParrotZik(object): print "Connecting to \"%s\" on %s" % (name, host) - self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) + if sys.platform == "darwin": + self.sock=lightblue.lightblueSocket( lightblue.RFCOMM ) + else: + self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM ) + self.sock.connect((host, port)) self.sock.send('\x00\x03\x00') @@ -115,10 +128,9 @@ class ParrotZik(object): self.sock ="" return data = self.sock.recv(7) - len = struct.unpack('B', data[1])[0] data = self.sock.recv(1024) data=BeautifulSoup(data) return data def Close(self): - self.sock.close() + self.sock.close()
\ No newline at end of file |