Skip to content

Commit febf4b3

Browse files
author
marcusw
committed
Retroactive branching for v1.1.0 from v1.1 branch r99.
1 parent 218f144 commit febf4b3

File tree

3 files changed

+52
-107
lines changed

3 files changed

+52
-107
lines changed

nxt/bluesock.py

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,67 +12,64 @@
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
1414

15-
try:
16-
import bluetooth
17-
except ImportError:
18-
import lightblueglue as bluetooth
15+
import bluetooth
1916
import os
20-
from .brick import Brick
17+
from nxt.brick import Brick
2118

2219
class BlueSock(object):
2320

24-
bsize = 118 # Bluetooth socket block size
25-
PORT = 1 # Standard NXT rfcomm port
21+
bsize = 118 # Bluetooth socket block size
22+
PORT = 1 # Standard NXT rfcomm port
2623

27-
def __init__(self, host):
28-
self.host = host
29-
self.sock = None
30-
self.debug = False
24+
def __init__(self, host):
25+
self.host = host
26+
self.sock = None
27+
self.debug = False
3128

32-
def __str__(self):
33-
return 'Bluetooth (%s)' % self.host
29+
def __str__(self):
30+
return 'Bluetooth (%s)' % self.host
3431

35-
def connect(self):
36-
if self.debug:
37-
print 'Connecting via Bluetooth...'
38-
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
39-
sock.connect((self.host, BlueSock.PORT))
40-
self.sock = sock
41-
if self.debug:
42-
print 'Connected.'
43-
return Brick(self)
32+
def connect(self):
33+
if self.debug:
34+
print 'Connecting via Bluetooth...'
35+
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
36+
sock.connect((self.host, BlueSock.PORT))
37+
self.sock = sock
38+
if self.debug:
39+
print 'Connected.'
40+
return Brick(self)
4441

45-
def close(self):
46-
if self.debug:
47-
print 'Closing Bluetooth connection...'
48-
self.sock.close()
49-
if self.debug:
50-
print 'Bluetooth connection closed.'
42+
def close(self):
43+
if self.debug:
44+
print 'Closing Bluetooth connection...'
45+
self.sock.close()
46+
if self.debug:
47+
print 'Bluetooth connection closed.'
5148

52-
def send(self, data):
53-
if self.debug:
54-
print 'Send:',
55-
print ':'.join('%02x' % ord(c) for c in data)
56-
l0 = len(data) & 0xFF
57-
l1 = (len(data) >> 8) & 0xFF
58-
d = chr(l0) + chr(l1) + data
59-
self.sock.send(d)
49+
def send(self, data):
50+
if self.debug:
51+
print 'Send:',
52+
print ':'.join('%02x' % ord(c) for c in data)
53+
l0 = len(data) & 0xFF
54+
l1 = (len(data) >> 8) & 0xFF
55+
d = chr(l0) + chr(l1) + data
56+
self.sock.send(d)
6057

61-
def recv(self):
62-
data = self.sock.recv(2)
63-
l0 = ord(data[0])
64-
l1 = ord(data[1])
65-
plen = l0 + (l1 << 8)
66-
data = self.sock.recv(plen)
67-
if self.debug:
68-
print 'Recv:',
69-
print ':'.join('%02x' % ord(c) for c in data)
70-
return data
58+
def recv(self):
59+
data = self.sock.recv(2)
60+
l0 = ord(data[0])
61+
l1 = ord(data[1])
62+
plen = l0 + (l1 << 8)
63+
data = self.sock.recv(plen)
64+
if self.debug:
65+
print 'Recv:',
66+
print ':'.join('%02x' % ord(c) for c in data)
67+
return data
7168

7269
def _check_brick(arg, value):
73-
return arg is None or arg == value
70+
return arg is None or arg == value
7471

7572
def find_bricks(host=None, name=None):
76-
for h, n in bluetooth.discover_devices(lookup_names=True):
77-
if _check_brick(host, h) and _check_brick(name, n):
78-
yield BlueSock(h)
73+
for h, n in bluetooth.discover_devices(lookup_names=True):
74+
if _check_brick(host, h) and _check_brick(name, n):
75+
yield BlueSock(h)

nxt/lightblueglue.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

nxt/locator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# GNU General Public License for more details.
1414

1515
class BrickNotFoundError(Exception):
16-
pass
17-
16+
pass
17+
1818
class NoBackendError(Exception):
1919
pass
2020

@@ -33,12 +33,13 @@ def find_bricks(host=None, name=None):
3333
print >>sys.stderr, "USB unavailable, not searching there"
3434

3535
try:
36-
import bluesock
36+
from bluetooth import BluetoothError
3737
try:
38+
import bluesock
3839
socks = bluesock.find_bricks(host, name)
3940
for s in socks:
4041
yield s
41-
except (bluesock.bluetooth.BluetoothError, IOError):
42+
except BluetoothError:
4243
pass
4344
except ImportError:
4445
import sys

0 commit comments

Comments
 (0)