-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.py
More file actions
78 lines (62 loc) · 2.38 KB
/
Copy pathClient.py
File metadata and controls
78 lines (62 loc) · 2.38 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
from Qpid import QpidConnection
from mxt1xx_pb2 import *
from commands_pb2 import *
from QpidTypes import *
from qpid.messaging import *
#doc http://qpid.apache.org/releases/qpid-0.14/apis/python/html/
#examples https://developers.google.com/protocol-buffers/docs/pythontutorial
qpidCon = QpidConnection('192.168.0.78', '5672', 'fila_dados_ext', 'mxt_command_qpid')
while not(qpidCon.start()):
print('Trying to reconnect')
response_received = True;
def mxt1xx_output_control(activate, pos, qpidCon):
activate = not activate
activate = int(activate == True)
cmd = u_command()
cmd.protocol = pos.firmware.protocol
cmd.serial = pos.firmware.serial
cmd.id = 'Controla Saida ' + str(pos.firmware.serial)
cmd.type = 51
cmd.attempt = 50
cmd.timeout = '2020-12-31 00:00:00'
cmd.handler_type = 2
cmd.transport = 'GPRS'
parameter = cmd.parameter.add()
parameter.id = 'SET_OUTPUT'
parameter.value = '1'
parameter = cmd.parameter.add()
parameter.id = 'SET OUTPUT 1'
parameter.value = str(activate)
parameter = cmd.parameter.add()
parameter.id = 'SET OUTPUT 2'
parameter.value = str(activate)
parameter = cmd.parameter.add()
parameter.id = 'SET OUTPUT 3'
parameter.value = str(activate)
parameter = cmd.parameter.add()
parameter.id = 'SET OUTPUT 4'
parameter.value = str(activate)
message = Message(subject="PB_COMMAND", content=cmd.SerializeToString())
qpidCon.sender.send(message)
return False
while(1):
message = qpidCon.receiver.fetch()
subject = message.subject
print (message.subject + ' received')
if subject == QpidSubjectType.qpid_st_pb_mxt1xx_pos:
pos = mxt1xx_u_position()
pos.ParseFromString(message.content)
print (str(pos.firmware.protocol) + ':' + str(pos.firmware.serial) + ':' + str(pos.firmware.memory_index))
qpidCon.session.acknowledge()
if response_received:
response_received = mxt1xx_output_control(pos.hardware_monitor.outputs.output_1, pos, qpidCon);
if subject == QpidSubjectType.qpid_st_pb_command_response:
res = u_command_response()
res.ParseFromString(message.content)
if res.status == 5:
print('Command response: Success')
response_received = True
else:
print('Command response: ' + str(res.status))
else:
qpidCon.session.acknowledge()