-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTypes.py
More file actions
54 lines (46 loc) · 1.51 KB
/
Types.py
File metadata and controls
54 lines (46 loc) · 1.51 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
44
45
46
47
48
49
50
51
52
53
from xml.etree import ElementTree
class serial_message:
def __init__(self):
with open('imc.xml', 'rt') as f:
self.tree = ElementTree.parse(f)
self.serial = ""
self.form_list = []
def parse_message(self):
for node in self.tree.iter('message'):
self.parse_field(node)
self.get_serial()
self.form_list = []
def parse_field(self, message_node):
for field_node in message_node.iter('field'):
#print "\n"
type = field_node.attrib.get('type')
if type is not None:
print "\ttype: " + type
form = self.format(type)
self.form_list.append(form)
def get_serial(self):
self.serial = self.serial.join(self.form_list)
print self.serial
def format(self, type):
if(type == 'int8_t'):
return 'b'
elif(type == 'uint8_t'):
return 'B'
elif(type == 'int16_t'):
return 'h'
elif(type == 'uint16_t'):
return 'H'
elif(type == 'int32_t'):
return 'i'
elif(type == 'uint32_t'):
return 'I'
elif(type == 'int64_t'):
return 'q'
elif(type == 'fp32_t'):
return 'f'
elif(type == 'fp64_t'):
return 'd'
else:
return "?"
ms = serial_message()
ms.parse_message()