-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpheroResponse.py
49 lines (36 loc) · 1.02 KB
/
SpheroResponse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# coding: utf-8
import struct
class Response(object):
SOP1 = 0
SOP2 = 1
MRSP = 2
SEQ = 3
DLEN = 4
CODE_OK = 0
def __init__(self, header, data):
self.header = header
self.data = data
@property
def fmt(self):
return '%sB' % len(self.data)
def empty(self):
return self.header[self.DLEN] == 1
@property
def success(self):
return self.header[self.MRSP] == self.CODE_OK
def seq(self):
return self.header[self.SEQ]
@property
def body(self):
return struct.unpack(self.fmt, self.data)
class GetRGB(Response):
def __init__(self, header, data):
super(GetRGB, self).__init__(header, data)
self.r = self.body[0]
self.g = self.body[1]
self.b = self.body[2]
class GetBluetoothInfo(Response):
def __init__(self, header, body):
super(GetBluetoothInfo, self).__init__(header, body)
self.name = self.data.split('\x00', 1)[0]
self.bta = self.data[16:].split('\x00', 1)[0]