tx-tool/tx-tool2.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:
90:
91: } elseif {[string match "TEL;*" $line]} {
92:
93:
94:
95: } elseif {[string match "CHV;*" $line]} {
96:
97: .c.r.screen12 delete channel
98: for {set N 0} {$N < 8} {set N [expr $N + 1]} {
99: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
100: .c.r.screen12 create rec 18 [expr $N * 5 + 3] [expr 18 + $LEVEL * 35 / 4098] [expr $N * 5 + 8] -fill green -tags channel
101: }
102: .c.r.screen12 create line 18 0 18 45 -fill $FRONT_COLOR2 -tags channel
103:
104: } elseif {[string match "FSV;*" $line]} {
105: # update2 "a.failsave" [split $line ";"] 8 16 2048
106: } elseif {[string match "LQI;*" $line]} {
107: .c.l.screen12 delete lqi
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 + 4] [expr 45 - $LEVEL / 7] [expr $N * 2 + 4] [expr 45 - $LEVEL / 7 + 2] -fill green -tags lqi
111: }
112: } elseif {[string match "RSI;*" $line]} {
113: .c.l.screen12 delete rssi
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 + 3] 45 [expr $N * 2 + 3] [expr 45 - $LEVEL] -fill $FRONT_COLOR2 -tags rssi
117: }
118: } elseif {[string match "SCN;*" $line]} {
119: .c.l.screen12 delete noise
120: for {set N 0} {$N < 16} {set N [expr $N + 1]} {
121: set LEVEL [expr [lindex [split $line ";"] [expr $N + 1]]]
122: .c.l.screen12 create line [expr $N * 2 + 4] 45 [expr $N * 2 + 4] [expr 45 - $LEVEL] -fill red -tags noise
123: }
124:
125:
126:
127: } elseif {[string match "MAG;*" $line]} {
128: set COMPASS [expr [lindex [split $line ";"] 1] / 10.0]
129: set SIZE 80
130: set X 80
131: set Y 80
132:
133: .c.h.screen4 delete tilt
134: .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
135: .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
136: .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
137: .c.h.screen4 create line [expr $X - $SIZE] [expr $Y] [expr $X + $SIZE] [expr $Y] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
138: .c.h.screen4 create line [expr $X] [expr $Y - $SIZE] [expr $X] [expr $Y + $SIZE] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
139: for {set N -30} {$N <= 30} {set N [expr $N + 10]} {
140: .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
141: .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
142: .c.h.screen4 create text [expr $X - $SIZE + 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
143: .c.h.screen4 create text [expr $X + $SIZE - 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
144: }
145: for {set N -30} {$N <= 30} {set N [expr $N + 5]} {
146: .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
147: .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
148: }
149:
150: set COMPASS 0
151:
152: set Y [expr $Y + $COMPASS - 180]
153: .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
154: .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
155: .c.h.screen4 create oval [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -fill green -outline $FRONT_COLOR -tags tilt
156: .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
157:
158: set COMPASS [expr [lindex [split $line ";"] 1] / 10]
159: draw_compas_rec .c.h.screen2 160 40 $COMPASS 230
160:
161:
162:
163:
164: } elseif {[string match "AHR;*" $line]} {
165: set COMPASS [expr [lindex [split $line ";"] 3] / 100.0]
166: set SIZE 80
167: set X 80
168: set Y 80
169:
170: .c.h.screen4 delete tilt
171: .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
172: .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
173: .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
174: .c.h.screen4 create line [expr $X - $SIZE] [expr $Y] [expr $X + $SIZE] [expr $Y] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
175: .c.h.screen4 create line [expr $X] [expr $Y - $SIZE] [expr $X] [expr $Y + $SIZE] -width 1 -fill $FRONT_COLOR2 -dash ".-" -tags tilt
176:
177:
178: for {set N -45} {$N <= 45} {set N [expr $N + 15]} {
179: .c.h.screen4 create line [expr $X - 10] [expr $Y + $N] [expr $X - 7] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
180: .c.h.screen4 create line [expr $X + 10] [expr $Y + $N] [expr $X + 7] [expr $Y + $N] -width 1 -fill $FRONT_COLOR2 -tags tilt
181: if {$N < 0} {
182: .c.h.screen4 create text [expr $X - 30] [expr $Y + $N] -text "[expr $N * -1]" -fill $FRONT_COLOR2 -tags tilt
183: .c.h.screen4 create text [expr $X + 30] [expr $Y + $N] -text "[expr $N * -1]" -fill $FRONT_COLOR2 -tags tilt
184: } else {
185: .c.h.screen4 create text [expr $X - 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
186: .c.h.screen4 create text [expr $X + 30] [expr $Y + $N] -text "$N" -fill $FRONT_COLOR2 -tags tilt
187: }
188: }
189:
190: set N [expr [lindex [split $line ";"] 1] / 100]
191: set Y [expr $Y + [lindex [split $line ";"] 2] / 100]
192:
193: .c.h.screen4 create line [expr $X - $SIZE / 3] [expr $Y] [expr $X - $SIZE / 4 - 2] [expr $Y] -width 1 -fill red -tags tilt
194: .c.h.screen4 create line [expr $X + $SIZE / 3] [expr $Y] [expr $X + $SIZE / 4 + 2] [expr $Y] -width 1 -fill red -tags tilt
195:
196: .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
197: .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
198:
199: .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
200:
201: .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
202:
203:
204:
205:
206: set COMPASS 0
207:
208: set Y [expr $Y + $COMPASS - 180]
209: .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
210: .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
211: .c.h.screen4 create oval [expr $X - 5] [expr $Y - 5] [expr $X + 5] [expr $Y + 5] -fill green -outline $FRONT_COLOR -tags tilt
212: .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
213:
214: set COMPASS [expr [lindex [split $line ";"] 3] / 100]
215: draw_compas_rec .c.h.screen2 160 40 $COMPASS 230
216:
217:
218:
219: } elseif {[string match "ETC;*" $line]} {
220: # set line2 [split $line ";"]
221: # .frame1.last_error configure -text "Last-Error: [lindex $line2 1]"
222: # .frame1.quality_errors configure -text "Quality-Errors: [lindex $line2 2]/[lindex $line2 3] ([lindex $line2 4]%)"
223: # .frame2.txid configure -text "TXID: [lindex $line2 5]"
224: # .frame2.setup_txid configure -text "Setup-TXID: [lindex $line2 6]"
225: # .frame2.seq configure -text "Sequence: [lindex $line2 7]"
226: }
227: set line ""
228: } else {
229: set line "$line$msg"
230: }
231: }
232:
233:
234: wm geometry . 240x320
235: wm title . "RCOPEN24 RX-Tool"
236:
237: frame .c
238: pack .c -side top -fill x
239:
240: frame .c.l
241: pack .c.l -side left -fill x
242:
243: canvas .c.l.screen12 -relief raised -width 35 -height 45
244: pack .c.l.screen12 -side top
245: .c.l.screen12 create rec 1 1 35 45 -fill black
246:
247: canvas .c.l.screen1 -relief raised -width 35 -height 160
248: pack .c.l.screen1 -side top
249: .c.l.screen1 create rec 1 1 35 160 -fill black
250: for {set N 0} {$N < 150} {set N [expr $N + 5]} {
251: .c.l.screen1 create line 30 [expr 150 - $N] 35 [expr 150 - $N] -fill $FRONT_COLOR2
252: }
253: for {set N 0} {$N < 150} {set N [expr $N + 20]} {
254: .c.l.screen1 create line 25 [expr 150 - $N] 35 [expr 150 - $N] -fill $FRONT_COLOR2
255: .c.l.screen1 create text 10 [expr 150 - $N] -text "$N" -tags compass_text -fill $FRONT_COLOR
256: }
257:
258: frame .c.h
259: pack .c.h -side left -fill x
260:
261: canvas .c.h.screen2 -relief raised -width 160 -height 45
262: pack .c.h.screen2 -side top
263:
264: canvas .c.h.screen4 -relief raised -width 160 -height 160
265: pack .c.h.screen4 -side top
266:
267: set SIZE 80
268: set X 80
269: set Y 80
270: .c.h.screen4 create rectangle [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -fill black
271: .c.h.screen4 create oval [expr $X - $SIZE] [expr $Y - $SIZE] [expr $X + $SIZE] [expr $Y + $SIZE] -outline $FRONT_COLOR
272: for {set N 0} {$N <= 360} {set N [expr $N + 5]} {
273: .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
274: }
275: .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
276: for {set N 0} {$N <= 360} {set N [expr $N + 15]} {
277: .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
278: }
279: .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
280:
281:
282: frame .c.r
283: pack .c.r -side left -fill x
284:
285: canvas .c.r.screen12 -relief raised -width 35 -height 45
286: pack .c.r.screen12 -side top
287: .c.r.screen12 create rec 1 1 35 45 -fill black
288:
289: canvas .c.r.screen3 -relief raised -width 35 -height 160
290: pack .c.r.screen3 -side top
291: .c.r.screen3 create rec 1 1 35 160 -fill black
292: for {set N 0} {$N < 150} {set N [expr $N + 5]} {
293: .c.r.screen3 create line 1 [expr 150 - $N] 5 [expr 150 - $N] -fill $FRONT_COLOR2
294: }
295: for {set N 0} {$N < 150} {set N [expr $N + 20]} {
296: .c.r.screen3 create line 1 [expr 150 - $N] 10 [expr 150 - $N] -fill $FRONT_COLOR2
297: .c.r.screen3 create text 25 [expr 150 - $N] -text "$N" -tags compass_text -fill $FRONT_COLOR
298: }
299:
300: frame .b
301: pack .b -side top -fill x
302:
303: canvas .b.screen13 -relief raised -width 234 -height 110
304: pack .b.screen13 -side left
305: .b.screen13 create rec 1 1 234 110 -fill black
306:
307:
308:
309:
310: if {[lindex $argv 0] != ""} {
311: puts "Open Serial-Port: [lindex $argv 0]"
312: if {[lindex $argv 1] != ""} {
313: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
314: } else {
315: set Serial [Serial_Init "[lindex $argv 0]" 38400]
316: }
317: } else {
318: puts "USAGE: rx-tool COMPORT [BAUD]"
319: exit 1
320: }
321:
322: fileevent $Serial readable [list rd_chid $Serial]
323: puts -nonewline $Serial "c"
324:
325:
326:
327:
328: