-
Notifications
You must be signed in to change notification settings - Fork 6
/
DM1702_data_maps.py
111 lines (103 loc) · 4.77 KB
/
DM1702_data_maps.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
DATA_map = {
# 0x00: 'FW_info',
# 0x01: 'Meta',
0x02: 0x02, #Calibration
0x03: 0x16, 0x04: 0x24, 0x05: 0x04, 0x06: 0x45, 0x07: 0x0b, 0x08: 0x11,
0x09: 0x01, 0x0a: 0x0a, 0x0b: 0x13, 0x0c: 0x12, 0x0d: 0x03, 0x0e: 0x06,
0x0f: 0x17, 0x10: 0x18, 0x11: 0x19, 0x12: 0x1a, 0x13: 0x1b, 0x14: 0x1c,
0x15: 0x1d, 0x16: 0x1e, 0x17: 0x1f, 0x18: 0x20, 0x19: 0x21, 0x1a: 0x22,
0x1b: 0x23, 0x1c: 0x25, 0x1d: 0x26, 0x1e: 0x27, 0x1f: 0x28, 0x20: 0x29,
0x21: 0x2a, 0x22: 0x2b, 0x23: 0x2c, 0x24: None, 0x25: 0x3f, 0x26: 0x40,
0x27: 0x41, 0x28: 0x42, 0x29: 0x43, 0x2a: 0x44, 0x2b: 0x46, 0x2c: 0x47,
0x2d: 0x48, 0x2e: 0x49, 0x2f: 0x4a, 0x30: 0x4b, 0x31: 0x4c, 0x32: 0x4d,
0x33: 0x4e, 0x34: 0x4f, 0x35: 0x50, 0x36: 0x51, 0x37: 0x52, 0x38: 0x53,
0x39: 0x54, 0x3a: 0x55, 0x3b: 0x56
}
DATA_chains = {
#'Channel_names': [0x24, 0x4, 0x25, 0x26], #Broken in CPS
'Channel_names': [0x24, 0x25, 0x26],
'Channel_data': range(0x16, 0x23),
'Channel_contact' : [0x27],
'VFO_Channel_data': [0x23],
'Scan_lists' : [0x13],
'RX_lists' : [0x11, 0x12],
'Systems' : [0x11],
'Lone_worker' : [0x11],
'Privacy' : [0x11],
'Contact_meta' : [0xb],
'Contact_data' : range(0x28,0x2d),
'Message_templates' : [0xa], #Done implemening reading
'Message_sent' : [0x9,0x33,0x34,0x35,0x36,0x37,0x38], # Done implementing - still not enough messages?
'Message_received' : [0x8, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32], # Done implementing - still not enough messages?
'Message_drafts' : [0x14], # Done implementing
'Call_missed' : [0xe],
'Call_answered' : [0xf],
'Call_outgoing' : [0x10],
'Buttons' : [0x27],
'Zone_data': range(0x45,0x57),
'Config' : [0x4],
'GPS' : [0x4],
}
DATA_ranges = {
#'Channel_names': [range(0x0, 0x1000), range(0x0, 0x7), range(0x000b, 0xfff), range(0x0, 0xfff)], #Broken data in CPS, maybe not in radio?
'Channel_names': [range(0x0, 0xfff), range(0x0003, 0xfff), range(0x0, 0xfff)], #How it should be in radio?
'Channel_data': [range(0x0, 0xfff)] * 0xd, # Fix: Probably not exactly this range!
'Channel_contact' :[range(0x0, 0x800)], # Contains 0xff from 0x800
'VFO_Channel_data': [range(0xf9f, 0xfff)], # Done
'Scan_lists' : [range(0x0, 0xfff)], # Probably to 0x721
'RX_lists' : [range(0x0, 0x606), range(0x0, 0x73d)], # Probably done, but may be dynamic
'Systems' : [range(0x606, 0x6ac)], #Data from 0x6a0
'Lone_worker' : [range(0x700, 0x800)], #???
'Privacy' : [range(0x800, 0xc00)], # Done
'Contact_meta' : [range(0x0, 0xfff)],
'Contact_data' : [range(0x0, 0xff0)] * 5, # Done, Last record ends at 0xB42?
'Message_templates' : [range(0x0, 0xfff)], # In reality ends at 0xa24?
'Message_sent' : [range(0x0, 0xf00), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0)],
'Message_received' : [range(0x0, 0xf00), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0), range(0x0,0xff0)],
'Message_drafts' : [range(0x0, 0xf00)], # Done with buggy implementation, fix once FW is corrected
'Call_missed' : [range(0x0, 0xfff)],
'Call_answered' : [range(0x0, 0xfff)],
'Call_outgoing' : [range(0x0, 0xfff)],
'Buttons' : [range(0x800, 0x81e)], # Done, contains 0xff from 0x81e
'Zone_data': [range(0x0, 0xf0c), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc),\
range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc), range(0x0, 0xefc)], # Done
'Config' : [range(0x0, 0x500)],# Done
'GPS' : [range(0x500, 0x600)], # Done
}
class DM1702_util(object):
@staticmethod
def get_data_bitmap(data, inverted=False):
odata = []
bit = 0x1 if inverted else 0x0
for c in data:
if isinstance(c,str):
c = ord(c)
for j in range(8):
odata.append(((c >> j) & 0x1 == bit))
return odata
@staticmethod
def pad_data(data, plen):
if len(data) < plen:
if isinstance(data, bytes):
data += b'\xff' * (plen - len(data))
elif isinstance(data[0], int) :
data += [0xff] * (plen - len(data))
return data
@staticmethod
def dtrim(data):
last = len(data) - 1;
while data[last] == 0xff :
last -= 1
if last == 0:
return []
return data[:(last+1)]
@staticmethod
def to_str(data, start, length, trim=False):
sub = data[start:start+length-1]
if trim:
sub = DM1702_util.dtrim(sub)
return "".join([chr(c) for c in sub])
@staticmethod
def csv_esc(in_str):
return '"' + str(in_str).replace('"','""') + '"'