-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.py
201 lines (167 loc) · 6.71 KB
/
messages.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from twisted.internet.protocol import ClientFactory, Protocol, DatagramProtocol
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
import struct
import time
class ClientUDPProtocol(DatagramProtocol):
def __init__(self, port, address, on_received):
self.port = port
self.address = address
self.on_received = on_received
def startProtocol(self):
self.transport.connect(self.address, self.port)
def sendDatagram(self, data):
#print "Sending ", data
self.transport.write(data)
def datagramReceived(self, data, host):
self.on_received(data)
def FloatToInt(a):
s = struct.pack('f', a)
return struct.unpack('i', s)[0]
class Sender(object):
def __init__(self):
def rec(x):
print x
self.udpProtocol = ClientUDPProtocol(5556, "192.168.1.1", rec)
self.udpConnection = reactor.listenUDP(0, self.udpProtocol)
self.send0 = self.udpProtocol.sendDatagram
self.seq = 1
self.repeat = None
def send(self, a):
self.send0(a.replace("$", str(self.seq)))
self.seq += 1
def takeoff(self, on):
tosend = "AT*REF=$,%d\r"%((1<<18)+(1<<20)+(1<<22)+(1<<24)+(1<<28)+(1<<9)*on)
self.send(tosend)
self.repeat = None
def emergency(self, on):
tosend = "AT*REF=$,%d\r"%((1<<18)+(1<<20)+(1<<22)+(1<<24)+(1<<28)+(1<<8)*on)
self.send(tosend)
self.repeat = None
def command(self, fb, lr, rot, alt):
tosend = ("AT*PCMD=$,%d,%d,%d,%d,%d\r"%(1, FloatToInt(-lr), FloatToInt(-fb), FloatToInt(alt), FloatToInt(-rot)))
self.repeat = tosend
def watchdog(self):
self.send("AT*COMWDG")
def resettrim(self):
self.send("AT*FTRIM")
def confignavdata(self):
print("NavData")
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:session_id\",\"aaaaaaaa\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:application_id\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:profile_id\",\"bbbbbbbb\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"general:navdata_demo\",\"FALSE\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"general:navdata_options\",\"105971713\"\r")
self.send(tosend)
time.sleep(0.1)
def recordvideo(self, on):
print("Record :" + str(on))
if on == 1:
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:session_id\",\"aaaaaaaa\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:application_id\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"custom:profile_id\",\"bbbbbbbb\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"video:video_channel\",\"0\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"video:video_on_usb\",\"TRUE\"\r")
self.send(tosend)
time.sleep(0.1)
self.repeat = None
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"video:video_codec\",\"130\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"userbox:userbox_command\",\"1\",\"20121221_172834\"\r")
self.send(tosend)
time.sleep(0.1)
else:
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"video:video_on_usb\",\"FALSE\"\r")
self.send(tosend)
time.sleep(0.1)
self.repeat = None
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"video:video_codec\",\"129\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
self.send(tosend)
time.sleep(0.1)
tosend = ("AT*CONFIG=$,\"userbox:userbox_command\",\"0\"\r")
self.send(tosend)
time.sleep(0.1)
#tosend = ("AT*CONFIG_IDS=$,\"aaaaaaaa\",\"bbbbbbbb\",\"cccccccc\"\r")
#self.send(tosend)
#time.sleep(0.1)
#tosend = ("AT*CONFIG=$,\"video:video_on_usb\",\"TRUE\"\r")
#self.send(tosend)
#self.repeat = None
self.repeat = None
def magcalib(self):
self.send("AT*CALIB")
def update(self):
if self.repeat != None:
#print "Repeating", self.repeat
self.send(self.repeat)
self.watchdog()
def start(f, fps):
tick = LoopingCall(f)
try:
tick.start(1.0 / fps)
reactor.run() #not sure it is useful
except KeyboardInterrupt:
reactor.stop()
raise KeyboardInterrupt