-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoAP_binary.py
64 lines (50 loc) · 1.17 KB
/
CoAP_binary.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
53
54
55
56
57
58
59
60
61
62
63
64
def get_name(header_name: str, bits: str):
headers = {
'version' : version,
'type' : type,
'req_res_code': req_res_code
}
header = headers.get(header_name)
name = [k for k,v in header.items() if v == bits]
if len(name) > 0:
name = name[0]
else:
name = "Unknown"
return name
def get_bits(header_name: str, name: str):
headers = {
'version' : version,
'type' : type,
'req_res_code': req_res_code
}
header = headers.get(header_name)
bits = header.get(name)
return bits
version = {
'0': '00',
'1': '01',
'2': '10',
'3': '11',
}
type = {
'Confirmable':'00',
'Non-Confirmable':'01',
'Acknowledgement':'10',
'Reset ':'11'
}
req_res_code = {
'EMPTY': '00000000',
'GET': '00000001',
'POST': '00000010',
'PUT': '00000011',
'DELETE': '00000100',
'FETCH': '00000101',
'PATCH': '00000110',
'iPATCH': '00000111',
'Created': '01000001',
'Deleted': '01000010',
'Valid': '01000011',
'Changed': '01000100',
'Content': '01000101',
'Continue': '01011111'
}