-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlooMsgFn.py
More file actions
38 lines (34 loc) · 1.29 KB
/
FlooMsgFn.py
File metadata and controls
38 lines (34 loc) · 1.29 KB
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
from FlooMessage import FlooMessage
class FlooMsgFn(FlooMessage):
"""
BC:FN
FN=<index>,<name>
"""
HEADER = "FN"
def __init__(self, isSend, index = None, btAddress = None, name = None):
if isSend:
self.index = None
self.name = None
self.btAddress = None
super().__init__(isSend, FlooMsgFn.HEADER)
else:
self.index = index
self.btAddress = btAddress
if btAddress is None:
self.name = None
paramStr = "%02X" % index
else:
self.name = "No Name" if name is None else name
paramStr = "%02X,%s,%s" % (index, btAddress, self.name)
super().__init__(isSend, FlooMsgFn.HEADER, bytes(paramStr, 'utf-8'))
@classmethod
def create_valid_msg(cls, payload: bytes):
msgLen = len(payload)
if msgLen == 5:
return cls(False, int(payload[3:5].decode('ascii')))
elif msgLen == 18:
return cls(False, int(payload[3:5].decode('ascii')), payload[6:].decode('utf-8'))
elif msgLen > 19:
return cls(False, int(payload[3:5].decode('ascii')), payload[6:18].decode('utf-8'), payload[19:].decode('utf-8', errors="ignore"))
else:
return None