-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSerialReader.py
88 lines (59 loc) · 1.97 KB
/
SerialReader.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
#!/usr/bin/python2.7
import time;
import serial;
import DbContext as db;
from DadosParaPlotarEntity import DadosParaPlotar as Maquina
import datetime
# viagens = 0
ser = serial.Serial('/dev/ttyUSB0', 9600);
db.DbContext.create_all_tables()
moda_coord = 0
moda_router = 0
range_coord = False
range_router = False
id_maquina = raw_input('Digite a identificacao da maquina: ')
maquina = Maquina(periodo = 8, dataEHora = datetime.datetime.now(), viagens = 0,
Id_maquina = id_maquina)
db.DbContext.add(maquina)
def range_ponto_fixo():
global range_coord
global range_router
if moda_coord >= 30 and moda_coord <= 40:
print 'entrou range Coord'
range_coord = True
else:
range_coord = False
if moda_router >= 45 and moda_router <= 55:
print 'entrou range router'
range_router = True
else:
range_router = False
def ponto_de_carga():
# global viagens
print 'range router: ' + str(range_router) + ' range coord: ' + str(range_coord)
if range_router and range_coord:
maquina = db.s.query(Maquina).filter(Maquina.Id_maquina == id_maquina).first()
maquina.viagens += 1
db.s.commit()
print 'viagens = ' + str(maquina.viagens)
while range_router and range_coord:
print 'Esta na posicao'
break
return;
time.sleep(1.8)
while 1==1:
VALUE_SERIAL = ser.readline();
if "RSSI END/COORD (-dBm) = " in VALUE_SERIAL:
moda_coord = float(VALUE_SERIAL[24:].strip())
print "valor de moda_coord = " + str(moda_coord)
if "RSSI ROUTER/COORD (-dBm) = " in VALUE_SERIAL :
moda_router = float(VALUE_SERIAL[27:].strip())
print "valor de moda_router = " + str(moda_router)
if (moda_coord != 0) and (moda_router != 0):
print 'verificando range e ponto de carga'
range_ponto_fixo()
ponto_de_carga()
moda_coord = 0
moda_router = 0
print VALUE_SERIAL
ser.close();