forked from SupernovaRocketry/SSR
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcliente.py
More file actions
99 lines (83 loc) · 2.63 KB
/
cliente.py
File metadata and controls
99 lines (83 loc) · 2.63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import socket
import json
from time import sleep
from datetime import datetime
import serial
class Cliente():
"""
Classe Cliente - Supervisorio Supernova Rocketry - API Socket
"""
def __init__(self, server_ip, port):
"""
Construtor da classe cliente
:param server_ip: ip do servidor
:param port: porta do servidor
"""
self._serverIP = server_ip
self._port = port
self._tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
def start(self):
"""
Método que inicializa a execução do cliente
"""
endpoint = (self._serverIP, self._port)
try:
self._tcp.connect(endpoint)
print("Conexao realiza com sucesso.")
# self._method()
except Exception as e:
print(f'Erro ao conectar {e.args}')
raise e
def _method(self):
"""
Método que implementa as requisições do cliente e a IHM
"""
try:
msg = 'y'
self._tcp.send(msg.encode())
self._resp = self._tcp.recv(1024)
self._resp = self._resp.decode()
self._resp = eval(self._resp)
self._resp['timestamp'] = datetime.now()
except Exception as e:
print(f'Erro ao realizar a comunicacao com o servidor {e.args}')
raise e
return self._resp
def disconect(self):
self._tcp.close()
print("Desconectar!")
class UART():
_firstData = True
def __init__(self, porta, baudrate):
self._porta = porta
self._baudrate = baudrate
self._minAltValue = 0
def start(self):
try:
self._ser = serial.Serial(self._porta, self._baudrate)
print("Connecting...")
sleep(3)
print(self._ser.name)
except Exception as e:
print(e)
raise e
def recieveData(self):
try:
sleep(0.1)
self._data = self._ser.readline().decode('ascii')
print(self._data)
print(type(self._data))
self._data = json.loads(self._data)
self._data['timestamp'] = datetime.now()
if self._firstData == True:
self._minAltValue = self._data['alt']
self._firstData = False
self._data['alt'] = self._data['alt'] - self._minAltValue
return self._data
except Exception as e:
print(e)
# class WiFi():
# """
# Classe WiFI - Supervisório Supernova Rocketry - Comunicação WiFi
# """
# def __init__(self):