Add tlmConfirm to tlm_dl ota packet-structure (#2991)
[ExpressLRS.git] / src / python / bootloader.py
blob7120773d1d6c64d8258db1e4ca9540f7f5480d17
2 INIT_SEQ = [0xEC,0x04,0x32,ord('b'),ord('l')]
4 BIND_SEQ = [0xEC,0x04,0x32,ord('b'),ord('d')]
6 MODEL_SEQ = [0xEC,0x04,0x32,ord('m'),ord('m')]
8 def calc_crc8(payload, poly=0xD5):
9 crc = 0
10 for data in payload:
11 crc ^= data
12 for _ in range(8):
13 if crc & 0x80:
14 crc = (crc << 1) ^ poly
15 else:
16 crc = crc << 1
17 return crc & 0xFF
19 def get_telemetry_seq(seq, key=None):
20 payload = list(seq)
21 if payload:
22 if key:
23 if type(key) == str:
24 key = [ord(x) for x in key]
25 payload += key
26 payload[1] += len(key)
27 payload += [calc_crc8(payload[2:])]
28 return bytes(payload)
30 def get_init_seq(key=None):
31 return get_telemetry_seq(INIT_SEQ, key)
33 def get_bind_seq(key=None):
34 return get_telemetry_seq(BIND_SEQ, key)
36 def get_model_seq(model):
37 return get_telemetry_seq(MODEL_SEQ, model)