-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
executable file
·75 lines (70 loc) · 2.25 KB
/
parser.py
File metadata and controls
executable file
·75 lines (70 loc) · 2.25 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
import time
import sys
import getopt
from protocolo import *
# char<>DLE and char<>ETX
# _______________________________
# | largo = 0 \ \
# ___|__ _|___ ___|__
#/waiting\------->/length\------->/data \
#\______/<-\ \______/ /->\___ _/
# | | | |
# \____/ \___/
# char<>SOF char<>ESC
###################################################################################
myopts, args = getopt.getopt(sys.argv[1:],"vd:i:")
salida = ' '
archivo= ' '
###############################
# o == option
# a == argument passed to the o
###############################
for o, a in myopts:
if o == '-v':
DEBUG=True;
elif o == '-d':
if a != 't' and a !='v' and a !='g' :
print("Usage: %s -d option support only t(ension) , v(oltaje) or g(graphic) argument" % sys.argv[0])
exit()
salida = a
elif o == '-i':
archivo = a
if salida == ' ' or archivo == ' ' :
print("Usage: %s -d [t|v|g] -v -i file" % sys.argv[0])
exit()
fd = open(archivo, "r")
#etiqueta
if salida == 't': #datos de temperatura
print "etiqueta,fecha,hora,temperatura"
if salida == 'v': #datos de tension
print "nodo,tension,fecha,hora"
#leo byte x byte
while byte != EOF and len(byte) != 0:
byte = fd.read(1)
if ESTADO == "waiting":
if byte == SOF :
ESTADO = "length"
elif ESTADO == "length":
largo = ord(byte)
#print largo
if largo == 0:
comandos(KEEP_ALI,'', salida)
# volvemos a leer de a 1 byte ......
ESTADO = "waiting"
else:
ESTADO = "data"
elif ESTADO == "data":
datos = byte + fd.read(largo - 2 )
if datos[0] == DATA_IND : # hasta que arregle el server
datos = escape(datos) # saca los escapes :-)
registro = comandos(datos[0], datos[1:],salida) # mando el comando y los datos restantes
if registro != None :
print registro
if DEBUG == True :
print [hex(ord(x)) for x in datos]
# volvemos a leer de a 1 byte ......
ESTADO = "waiting"
if DEBUG == True:
print "final"
fd.close()