-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_connected_msg.py
43 lines (34 loc) · 1019 Bytes
/
app_connected_msg.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
#!/usr/bin/env python
# Send "app connected" message
# Required artoo 0.7.9 or later.
import socket
import struct
import sys
DISCONNECTED = 0
CONNECTED = 1
# Must match flightcode/stm32
APP_CONNECTED_PORT = 5026
def send(app_connected):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
msg = struct.pack("!B", app_connected)
s.sendto(msg, ("127.0.0.1", APP_CONNECTED_PORT))
s.close()
def send_connected():
send(CONNECTED)
def send_disconnected():
send(DISCONNECTED)
def usage():
print "usage: app_connected.py <connected>"
print " where <connected> is one of"
print " c[onnected] tell stm32 app is connected"
print " d[isconnected] tell stm32 app is disconnected"
if __name__ == "__main__":
# one required argument: "c[onnected]" or "d[isconnected]"
if len(sys.argv) != 2:
usage()
elif sys.argv[1][0] == "c":
send_connected()
elif sys.argv[1][0] == "d":
send_disconnected()
else:
usage()