forked from Flairmesh/FlooCast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlooMsgAc.py
More file actions
43 lines (39 loc) · 1.41 KB
/
Copy pathFlooMsgAc.py
File metadata and controls
43 lines (39 loc) · 1.41 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
39
40
41
42
43
from FlooMessage import FlooMessage
class FlooMsgAc(FlooMessage):
"""Audio Codec in Use
AC=xx
xx: 01 Voice CVSD
02 Voice mSBC
03 A2DP SBC
04 A2DP APTX
05 A2DP APTX HD
06 A2DP APTX Adaptive
07 LEA LC3
08 LEA APTX Adaptive
09 LEA APTX Lite
0A A2DP APTX Adaptive Lossless
"""
HEADER = "AC"
def __init__(self, isSend, codec = None, rssi = 0, rate = 0):
self.codec = codec
self.rssi = rssi
self.rate = rate
if codec == 0x0A or codec == 0x06:
adaptiveStr = "%02X" % codec + "," + "%02X" % rssi + "," + "%04X" % rate
super().__init__(isSend, FlooMsgAc.HEADER, bytes(adaptiveStr, 'ascii'))
elif codec != None:
codecStr = "%02X" % codec
super().__init__(isSend, FlooMsgAc.HEADER, bytes(codecStr, 'ascii'))
else:
super().__init__(isSend, FlooMsgAc.HEADER)
@classmethod
def create_valid_msg(cls, payload: bytes):
msgLen = len(payload)
if msgLen == 5:
return cls(False, int(payload[3:5].decode('ascii'), 16))
elif msgLen == 13:
return cls(False, int(payload[3:5].decode('ascii'), 16),
int(payload[6:8].decode('ascii'), 16),
int(payload[9:13].decode('ascii'), 16))
else:
return cls(False, int(payload[3:5].decode('ascii'), 16))