rx-tool/rx-teleview.tcl
1: #!/usr/bin/wish
2: #
3: #
4:
5: global line
6: set line ""
7:
8: set FRONT_COLOR "green"
9: set FRONT_COLOR2 "darkgreen"
10:
11: proc draw_compas_rec {CANVAS CANVAS_W CANVAS_H COMPASS TARGET} {
12: global FRONT_COLOR
13: global FRONT_COLOR2
14:
15: set x [expr $CANVAS_W / 2]
16: $CANVAS delete compass
17: $CANVAS create rec 1 1 $CANVAS_W 45 -fill black -tags compass
18: $CANVAS create line $x 5 $x 25 -fill red -tags compass
19: set y 7
20: set v 5
21: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y - $v}] [expr {$x - $v}] [expr {$y - $v}] -fill green -tags compass
22: set y 25
23: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y + $v}] [expr {$x - $v}] [expr {$y + $v}] -fill green -tags compass
24: for {set N [expr $COMPASS - $CANVAS_W / 2]} {$N <= [expr $COMPASS + $CANVAS_W / 2]} {set N [expr $N + 1]} {
25: set OFFSET [expr $N - $COMPASS + $CANVAS_W / 2]
26: set N2 $N
27: if {$N2 >= 360} {
28: set N2 [expr $N2 - 360]
29: } elseif {$N2 < 0} {
30: set N2 [expr $N2 + 360]
31: }
32: if {[expr $N2 % 90] == 0} {
33: $CANVAS create line $OFFSET 23 $OFFSET 30 -fill $FRONT_COLOR -tags compass
34: if {$N2 == 0 || $N2 == 360} {
35: $CANVAS create text $OFFSET 15 -text "N" -tags compass_text -fill $FRONT_COLOR -tags compass
36: } elseif {$N2 == 90} {
37: $CANVAS create text $OFFSET 15 -text "E" -tags compass_text -fill $FRONT_COLOR -tags compass
38: } elseif {$N2 == 180} {
39: $CANVAS create text $OFFSET 15 -text "S" -tags compass_text -fill $FRONT_COLOR -tags compass
40: } elseif {$N2 == 270} {
41: $CANVAS create text $OFFSET 15 -text "W" -tags compass_text -fill $FRONT_COLOR -tags compass
42: }
43: } elseif {[expr $N2 % 45] == 0} {
44: $CANVAS create line $OFFSET 23 $OFFSET 30 -fill $FRONT_COLOR -tags compass
45: $CANVAS create text $OFFSET 15 -text "$N2" -tags compass_text -fill $FRONT_COLOR -tags compass
46: } elseif {[expr $N2 % 15] == 0} {
47: $CANVAS create line $OFFSET 25 $OFFSET 30 -fill $FRONT_COLOR -tags compass
48: } elseif {[expr $N2 % 5] == 0} {
49: $CANVAS create line $OFFSET 27 $OFFSET 30 -fill $FRONT_COLOR2 -tags compass
50: }
51: }
52: $CANVAS create text $x 39 -text "$COMPASS" -tags compass_text -fill $FRONT_COLOR -tags compass
53: set x [expr $TARGET - $COMPASS + $CANVAS_W / 2]
54: set y 7
55: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y - $v}] [expr {$x - $v}] [expr {$y - $v}] -outline green -tags compass
56: }
57:
58: proc Serial_Init {ComPort ComRate} {
59: set iChannel [open $ComPort w+]
60: set rate $ComRate
61: fconfigure $iChannel -mode $ComRate,n,8,1
62: fconfigure $iChannel -blocking 0
63: fconfigure $iChannel -buffering none
64: fileevent $iChannel readable ""
65: return $iChannel
66: }
67:
68: proc send_channel {CHANNEL VALUE} {
69: global Serial
70: puts $Serial "SCH;$CHANNEL;$VALUE\n"
71: }
72:
73: proc send_cmd {CMD} {
74: global Serial
75: puts -nonewline $Serial "$CMD"
76: }
77:
78:
79: proc rd_chid {chid} {
80: global FRONT_COLOR
81: global FRONT_COLOR2
82: global line
83: set msg [read $chid 1]
84: if {$msg == "\n"} {
85: puts "$line"
86: if {[string match "ADC;*" $line]} {
87: # update2 "a.adc" [split $line ";"] 4 8 0
88: # draw_batt_bar .c.screen3 40 160 [expr [lindex [split $line ";"] 1] * 80 / 1024] 75
89: } elseif {[string match "CHV;*" $line]} {
90:
91: .c.r.screen12 delete channel
92: for {set N 0} {$N < 8} {set N [expr $N + 1]} {
93: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
94: .c.r.screen12 create rec 18 [expr $N * 5 + 3] [expr 18 + $LEVEL * 35 / 4098] [expr $N * 5 + 8] -fill green -tags channel
95: }
96: .c.r.screen12 create line 18 0 18 45 -fill $FRONT_COLOR2 -tags channel
97:
98: } elseif {[string match "FSV;*" $line]} {
99: # update2 "a.failsave" [split $line ";"] 8 16 2048
100: } elseif {[string match "LQI;*" $line]} {
101: .c.l.screen12 delete lqi
102: for {set N 0} {$N < 16} {set N [expr $N + 1]} {
103: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
104: .c.l.screen12 create line [expr $N * 2 + 4] [expr 45 - $LEVEL / 7] [expr $N * 2 + 4] [expr 45 - $LEVEL / 7 + 2] -fill green -tags lqi
105: }
106: } elseif {[string match "RSI;*" $line]} {
107: .c.l.screen12 delete rssi
108: for {set N 0} {$N < 16} {set N [expr $N + 1]} {
109: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
110: .c.l.screen12 create line [expr $N * 2 + 3] 45 [expr $N * 2 + 3] [expr 45 - $LEVEL] -fill $FRONT_COLOR2 -tags rssi
111: }
112: } elseif {[string match "SCN;*" $line]} {
113: .c.l.screen12 delete noise
114: for {set N 0} {$N < 16} {set N [expr $N + 1]} {
115: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
116: .c.l.screen12 create line [expr $N * 2 + 4] 45 [expr $N * 2 + 4] [expr 45 - $LEVEL] -fill red -tags noise
117: }
118: } elseif {[string match "MAG;*" $line]} {
119: set COMPASS [expr [lindex [split $line ";"] 1] / 10.0]
120: set SIZE 80
121: set X 80
122: set Y 80
123:
124: .c.h.screen4 delete tilt
125: .c.h.screen4 create arc [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -start [expr -$COMPASS + 90] -extent 0 -width 3 -outline $FRONT_COLOR -tags tilt
126: .c.h.screen4 create arc [expr $X - $SIZE + 7] [expr $Y - $SIZE + 7] [expr $X + $SIZE - 7] [expr $Y + $SIZE - 7] -start [expr -230 + 90] -extent 0 -width 5 -outline red -tags tilt
127: .c.h.screen4 create oval [expr $X - $SIZE + 13] [expr $Y - $SIZE + 13] [expr $X + $SIZE - 13] [expr $Y + $SIZE - 13] -outline $FRONT_COLOR -fill black -tags tilt
128: .c.h.screen4 create line [expr $X - $SIZE] [expr $Y] [expr $X + $SIZE] [expr $Y] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
129: .c.h.screen4 create line [expr $X] [expr $Y - $SIZE] [expr $X] [expr $Y + $SIZE] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
130: for {set N -30} {$N <= 30} {set N [expr $N + 10]} {
131: .c.h.screen4 create line [expr $X - $SIZE + 45] [expr $Y + $N] [expr $X - 35] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
132: .c.h.screen4 create line [expr $X + 35] [expr $Y + $N] [expr $X + $SIZE - 45] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
133: .c.h.screen4 create text [expr $X - $SIZE + 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
134: .c.h.screen4 create text [expr $X + $SIZE - 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
135: }
136: for {set N -30} {$N <= 30} {set N [expr $N + 5]} {
137: .c.h.screen4 create line [expr $X - $SIZE + 55] [expr $Y + $N] [expr $X - 35] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
138: .c.h.screen4 create line [expr $X + 35] [expr $Y + $N] [expr $X + $SIZE - 55] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
139: }
140:
141: set COMPASS 0
142:
143: set Y [expr $Y + $COMPASS - 180]
144: .c.h.screen4 create arc [expr $X - 15] [expr $Y - 15] [expr $X + 15] [expr $Y + 15] -start [expr $COMPASS] -extent 0 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
145: .c.h.screen4 create arc [expr $X - 15] [expr $Y - 15] [expr $X + 15] [expr $Y + 15] -start [expr $COMPASS + 180.0] -extent 0 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
146: .c.h.screen4 create oval [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -fill green -outline $FRONT_COLOR -tags tilt
147: .c.h.screen4 create arc [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -start [expr $COMPASS + 180.0] -extent 180 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
148:
149: set COMPASS [expr [lindex [split $line ";"] 1] / 10]
150: draw_compas_rec .c.h.screen2 160 40 $COMPASS 230
151:
152:
153:
154:
155: } elseif {[string match "GPS;*" $line]} {
156: # puts [expr [expr [lindex [split $line ";"] 1] * 10000.0 + [lindex [split $line ";"] 2]] / 10000.0]
157: # puts [expr [expr [lindex [split $line ";"] 3] * 10000.0 + [lindex [split $line ";"] 4]] / 10000.0]
158: set SPEED [expr [expr [lindex [split $line ";"] 5] * 100.0 + [lindex [split $line ";"] 6]] / 100.0]
159: set ALT [expr [expr [lindex [split $line ";"] 9] * 100.0 + [lindex [split $line ";"] 10]] / 100.0]
160: .c.r.screen3 delete alti
161: .c.r.screen3 create rec 5 [expr 150 - $ALT / 2] 37 [expr 150 - $ALT / 2 + 2] -fill red -tags alti
162: .c.l.screen1 delete speed
163: .c.l.screen1 create rec 5 [expr 150 - $SPEED] 37 [expr 150 - $SPEED + 2] -fill red -tags speed
164:
165:
166: } elseif {[string match "AHR;*" $line]} {
167: set COMPASS [expr [lindex [split $line ";"] 3] / 100.0]
168: set SIZE 80
169: set X 80
170: set Y 80
171:
172: .c.h.screen4 delete tilt
173: .c.h.screen4 create arc [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -start [expr -$COMPASS + 90] -extent 0 -width 3 -outline $FRONT_COLOR -tags tilt
174: .c.h.screen4 create arc [expr $X - $SIZE + 7] [expr $Y - $SIZE + 7] [expr $X + $SIZE - 7] [expr $Y + $SIZE - 7] -start [expr -230 + 90] -extent 0 -width 5 -outline red -tags tilt
175: .c.h.screen4 create oval [expr $X - $SIZE + 13] [expr $Y - $SIZE + 13] [expr $X + $SIZE - 13] [expr $Y + $SIZE - 13] -outline $FRONT_COLOR -fill black -tags tilt
176: .c.h.screen4 create line [expr $X - $SIZE] [expr $Y] [expr $X + $SIZE] [expr $Y] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
177: .c.h.screen4 create line [expr $X] [expr $Y - $SIZE] [expr $X] [expr $Y + $SIZE] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
178:
179:
180: for {set N -45} {$N <= 45} {set N [expr $N + 15]} {
181: .c.h.screen4 create line [expr $X - 10] [expr $Y + $N] [expr $X - 7] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
182: .c.h.screen4 create line [expr $X + 10] [expr $Y + $N] [expr $X + 7] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
183: if {$N < 0} {
184: .c.h.screen4 create text [expr $X - 30] [expr $Y + $N] -text "[expr $N * -1]" -fill $FRONT_COLOR2 -tags tilt
185: .c.h.screen4 create text [expr $X + 30] [expr $Y + $N] -text "[expr $N * -1]" -fill $FRONT_COLOR2 -tags tilt
186: } else {
187: .c.h.screen4 create text [expr $X - 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
188: .c.h.screen4 create text [expr $X + 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
189: }
190: }
191:
192: set N [expr [lindex [split $line ";"] 1] / 100]
193: set Y [expr $Y + [lindex [split $line ";"] 2] / 100]
194:
195: .c.h.screen4 create line [expr $X - $SIZE / 3] [expr $Y] [expr $X - $SIZE / 4 - 2] [expr $Y] -width 1 -fill red -tags tilt
196: .c.h.screen4 create line [expr $X + $SIZE / 3] [expr $Y] [expr $X + $SIZE / 4 + 2] [expr $Y] -width 1 -fill red -tags tilt
197:
198: .c.h.screen4 create arc [expr $X - $SIZE / 4] [expr $Y - $SIZE / 4] [expr $X + $SIZE / 4] [expr $Y + $SIZE / 4] -start [expr -$N] -extent 0 -width 1 -outline red -tags tilt
199: .c.h.screen4 create arc [expr $X - $SIZE / 4] [expr $Y - $SIZE / 4] [expr $X + $SIZE / 4] [expr $Y + $SIZE / 4] -start [expr -$N - 180] -extent 0 -width 1 -outline red -tags tilt
200:
201: .c.h.screen4 create arc [expr $X - $SIZE / 5] [expr $Y - $SIZE / 5] [expr $X + $SIZE / 5] [expr $Y + $SIZE / 5] -start [expr -$N + 90] -extent 0 -width 1 -outline red -tags tilt
202:
203: .c.h.screen4 create oval [expr $X - $SIZE / 10] [expr $Y - $SIZE / 10] [expr $X + $SIZE / 10] [expr $Y + $SIZE / 10] -outline black -fill black -tags tilt
204:
205:
206:
207:
208: set COMPASS 0
209:
210: set Y [expr $Y + $COMPASS - 180]
211: .c.h.screen4 create arc [expr $X - 15] [expr $Y - 15] [expr $X + 15] [expr $Y + 15] -start [expr $COMPASS] -extent 0 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
212: .c.h.screen4 create arc [expr $X - 15] [expr $Y - 15] [expr $X + 15] [expr $Y + 15] -start [expr $COMPASS + 180.0] -extent 0 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
213: .c.h.screen4 create oval [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -fill green -outline $FRONT_COLOR -tags tilt
214: .c.h.screen4 create arc [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -start [expr $COMPASS + 180.0] -extent 180 -fill yellow -width 1 -outline $FRONT_COLOR -tags tilt
215:
216: set COMPASS [expr [lindex [split $line ";"] 3] / 100]
217: draw_compas_rec .c.h.screen2 160 40 $COMPASS 230
218:
219:
220:
221: } elseif {[string match "ETC;*" $line]} {
222: # set line2 [split $line ";"]
223: # .frame1.last_error configure -text "Last-Error: [lindex $line2 1]"
224: # .frame1.quality_errors configure -text "Quality-Errors: [lindex $line2 2]/[lindex $line2 3] ([lindex $line2 4]%)"
225: # .frame2.txid configure -text "TXID: [lindex $line2 5]"
226: # .frame2.setup_txid configure -text "Setup-TXID: [lindex $line2 6]"
227: # .frame2.seq configure -text "Sequence: [lindex $line2 7]"
228: }
229: set line ""
230: } else {
231: set line "$line$msg"
232: }
233: }
234:
235:
236: wm geometry . 240x320
237: wm title . "RCOPEN24 RX-Tool"
238:
239: frame .c
240: pack .c -side top -fill x
241:
242: frame .c.l
243: pack .c.l -side left -fill x
244:
245: canvas .c.l.screen12 -relief raised -width 35 -height 45
246: pack .c.l.screen12 -side top
247: .c.l.screen12 create rec 1 1 35 45 -fill black
248:
249: canvas .c.l.screen1 -relief raised -width 35 -height 160
250: pack .c.l.screen1 -side top
251: .c.l.screen1 create rec 1 1 35 160 -fill black
252: for {set N 0} {$N < 150} {set N [expr $N + 5]} {
253: .c.l.screen1 create line 30 [expr 150 - $N] 35 [expr 150 - $N] -fill $FRONT_COLOR2
254: }
255: for {set N 0} {$N < 150} {set N [expr $N + 20]} {
256: .c.l.screen1 create line 25 [expr 150 - $N] 35 [expr 150 - $N] -fill $FRONT_COLOR2
257: .c.l.screen1 create text 10 [expr 150 - $N] -text "$N" -tags compass_text -fill $FRONT_COLOR
258: }
259:
260: frame .c.h
261: pack .c.h -side left -fill x
262:
263: canvas .c.h.screen2 -relief raised -width 160 -height 45
264: pack .c.h.screen2 -side top
265:
266: canvas .c.h.screen4 -relief raised -width 160 -height 160
267: pack .c.h.screen4 -side top
268:
269: set SIZE 80
270: set X 80
271: set Y 80
272: .c.h.screen4 create rectangle [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -fill black
273: .c.h.screen4 create oval [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -outline $FRONT_COLOR
274: for {set N 0} {$N <= 360} {set N [expr $N + 5]} {
275: .c.h.screen4 create arc [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -start $N -extent 0 -fill yellow -width 1 -outline $FRONT_COLOR2
276: }
277: .c.h.screen4 create oval [expr $X - $SIZE + 5] [expr $Y - $SIZE + 5] [expr $X + $SIZE - 5] [expr $Y + $SIZE - 5] -outline black -fill black
278: for {set N 0} {$N <= 360} {set N [expr $N + 15]} {
279: .c.h.screen4 create arc [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -start $N -extent 0 -fill red -width 1 -outline $FRONT_COLOR
280: }
281: .c.h.screen4 create oval [expr $X - $SIZE + 7] [expr $Y - $SIZE + 7] [expr $X + $SIZE - 7] [expr $Y + $SIZE - 7] -outline black -fill black
282:
283:
284: frame .c.r
285: pack .c.r -side left -fill x
286:
287: canvas .c.r.screen12 -relief raised -width 35 -height 45
288: pack .c.r.screen12 -side top
289: .c.r.screen12 create rec 1 1 35 45 -fill black
290:
291: canvas .c.r.screen3 -relief raised -width 35 -height 160
292: pack .c.r.screen3 -side top
293: .c.r.screen3 create rec 1 1 35 160 -fill black
294: for {set N 0} {$N < 150} {set N [expr $N + 5]} {
295: .c.r.screen3 create line 1 [expr 150 - $N] 5 [expr 150 - $N] -fill $FRONT_COLOR2
296: }
297: for {set N 0} {$N < 150} {set N [expr $N + 20]} {
298: .c.r.screen3 create line 1 [expr 150 - $N] 10 [expr 150 - $N] -fill $FRONT_COLOR2
299: .c.r.screen3 create text 25 [expr 150 - $N] -text "[expr $N * 2]" -tags compass_text -fill $FRONT_COLOR
300: }
301:
302: frame .b
303: pack .b -side top -fill x
304:
305: canvas .b.screen13 -relief raised -width 234 -height 110
306: pack .b.screen13 -side left
307: .b.screen13 create rec 1 1 234 110 -fill black
308:
309:
310:
311:
312: if {[lindex $argv 0] != ""} {
313: puts "Open Serial-Port: [lindex $argv 0]"
314: if {[lindex $argv 1] != ""} {
315: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
316: } else {
317: set Serial [Serial_Init "[lindex $argv 0]" 38400]
318: }
319: } else {
320: puts "USAGE: rx-tool COMPORT \[BAUD\]"
321: exit 1
322: }
323:
324: fileevent $Serial readable [list rd_chid $Serial]
325: puts -nonewline $Serial "c"
326:
327:
328:
329:
330: