-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (53 loc) · 1.84 KB
/
app.py
File metadata and controls
66 lines (53 loc) · 1.84 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
from daf_virtual_rasp.com.enquadramento import Enquadramento
from daf_virtual_rasp.com.arq import Arq
from daf_virtual_rasp.com.poller import Poller
from daf_virtual_rasp.com.enq_enum import TIPO_t
from daf_virtual_rasp.daf.daf import DAF
import sys, time, os
import serial
import argparse
import logging
# Porta serial padrão
default_port = '/dev/ttyGS0'
# Definindo argumentos de linha de comando
parser = argparse.ArgumentParser(description='DAF-pi')
parser.add_argument('-p', '--port', type=str, default=default_port, help='Porta serial de comunicação (default: /dev/ttyGS0)')
parser.add_argument('-t', '--timeout_arq', type=float, default=2, help='Tempo de timeout da camada de arq (default: 2 segundos)')
args = parser.parse_args()
# Recebendo argumentos de linha de comando
port = args.port
timeout_arq = args.timeout_arq
# Configuração do log
log_level = os.getenv('DAF_PI_LOG', 'INFO').upper()
log_level = getattr(logging, log_level, logging.INFO)
formatter = '%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s'
logging.basicConfig(stream=sys.stdout, level=log_level, format=formatter)
logging.debug('Log de DEBUG habilitado')
# define parametros das camadas ARQ e Enquadramento
max_tentativas_arq = 3
timeout_enq = 0.5
# obtém porta serial
ser = serial.Serial(
port=port,
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout= None
)
ser.flush()
# cria os objetos das camadas ARQ, Enquadramento e DAF
e = Enquadramento(ser, timeout_enq)
a = Arq(max_tentativas_arq, timeout_arq)
daf = DAF()
# define organização das subcamadas
daf.set_inferior(a)
a.set_superior(daf)
a.set_inferior(e)
e.set_superior(a)
# despacha as camadas
pol = Poller()
pol.adiciona(daf)
pol.adiciona(e)
pol.adiciona(a)
pol.despache()