-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSerialParser.py
More file actions
43 lines (30 loc) · 976 Bytes
/
SerialParser.py
File metadata and controls
43 lines (30 loc) · 976 Bytes
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
import struct as st
class Data(object):
def __init__(self,msg,value):
self.msg = msg
self.value = value
def serialParser(msg):
command = list()
for i in range(1,5):
command.append(msg[i])
return(command)
if msg[0] == "&":
return msg[1:]
if msg[0] == "!":
return int(msg[1])
if msg[0] == "*":
pid_params = msg.split(charParamsSeparator)
pid.append(float(pid_params[1])/4096)
pid.append(float(pid_params[2])/4096)
pid.append(float(pid_params[3])/4096)
#print(pid)
return pid
# separate message in parts
variables = msg.split(charDataSeparator)
dataArray = list()
# iterate over all the data and fill a dictionary with ids and measurements
for v in variables:
vAux = v.split(charMessageSeparator)
dataArray.append(Data(vAux[0],vAux[1]))
grahps = dict([ (d.msg, d.value) for d in dataArray ])
return grahps