-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrendezvous_main.py
97 lines (80 loc) · 2.12 KB
/
rendezvous_main.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
89
90
91
92
93
94
"""
PIG IMPLEMENTATION, the good one is going to be implemented in C or Cython.
^--^ ___
(00){___}@
|| ||
"""
import socket
import sys
import time
import simplejson as json
from paho import mqtt
from utils import eprint
sock_display = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock_sensor = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
print(sock_display)
print(sock_sensor)
server_address_display = '/var/run/rendezvous/terra/display'
server_address_sensor = '/var/run/rendezvous/vaisala/sensor'
eprint("connecting to ", server_address_display)
eprint("connecting to ", server_address_sensor)
try:
sock_display.connect(server_address_display)
sock_sensor.connect(server_address_sensor)
except socket.error, msg:
eprint(msg)
sys.exit()
def get_show_message(ln, message):
print("ln: " + str(ln))
print("message: " + message)
response = json.dumps({"command":"show",
"args":{
"text":message,
"line_num":ln
}})
print("RESPONSE: " + response)
return response
def send_command(sock, message):
sock.sendall(message)
amount_received = 0
amount_expected = len(message)
data = sock.recv(200)
amount_received += len(data)
eprint("received", data)
init_message = get_show_message(0,"NAPIEX")
print init_message
#sock_display.sendall(init_message)
send_command(sock_display, init_message)
init_message = get_show_message(1,"LTDA.")
print init_message
#sock_display.sendall(init_message)
send_command(sock_display, init_message)
time.sleep(3.5)
#sock_display.sendall(json.dumps({"command":"clear"}))
try:
#message = json.dumps(get_show_message(0,"Rendezvous"))
"""message = json.dumps({
"command":"show",
"args":{
"text":"rendezvous",
"line_num":1
}
}
)"""
message = json.dumps({
"command":"read",
"args":{
"device_oid": 1
}
})
send_command(sock_sensor, message)
#sock_sensor.sendall(message)
#amount_received = 0
#amount_expected = len(message)
#while amount_received < amount_expected:
#data = sock_sensor.recv(200)
#amount_received += len(data)
#eprint("received", data)
finally:
eprint("closing socket")
sock.close()