-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
55 lines (43 loc) · 1.48 KB
/
main.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
50
51
52
# This is a sample Python script.
import logging
from pprint import pprint
from openthread_cli_interface import OTCommunicator
import json
import jsonpickle
from webui import run
"""@dataclass
class ThreadNode:
ExtAddress: bytes
RLoc16: int
TLVs: dict[TLVTypes, TLV]
LeaderData: LeaderData
@staticmethod
def _parse_record(data: str):
tlv_type = int(data[:2], 16)
record_len = int(data[2:4], 16)
record = data[4:4 + (record_len * 2)]
return TLV(TLVTypes(tlv_type), record_len, record.encode('utf-8')), data[4 + (record_len * 2):]
@staticmethod
def from_net_diag(data: str):
cmd, s = data.split(' ')
tlvs: dict[TLVTypes, TLV] = {}
while True:
tlv, s = ThreadNode._parse_record(s)
tlvs[tlv.type] = tlv
if s == '':
break
return ThreadNode.from_tlvs(tlvs)
@staticmethod
def from_tlvs(tlvs: dict[TLVTypes, TLV]):
ext_addr = tlvs[TLVTypes.ExtAddress].ext_address
rloc16 = tlvs[TLVTypes.RLOC16].rloc16
routers = tlvs[TLVTypes.RouteData].route_data
ld = tlvs[TLVTypes.LeaderData].leader_data
childs = tlvs[TLVTypes.ChildTable].chidl_table
pprint(childs)
return ThreadNode(ext_addr, rloc16, tlvs, ld), routers
"""
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG, format='%(name)s - %(levelname)s - %(message)s')
run()