rx-tool/rx-tool.tcl
1: #!/usr/bin/wish
2: #
3: #
4:
5: global line
6: global argv
7: set line ""
8: set VERSION ""
9:
10: proc draw_compas_rec {CANVAS CANVAS_W CANVAS_H COMPASS TARGET} {
11: set x [expr $CANVAS_W / 2]
12: $CANVAS delete compass
13: $CANVAS create rec 1 1 $CANVAS_W 45 -fill black -tags compass
14: $CANVAS create line $x 5 $x 25 -fill red -tags compass
15: set y 7
16: set v 5
17: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y - $v}] [expr {$x - $v}] [expr {$y - $v}] -fill green -tags compass
18: set y 25
19: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y + $v}] [expr {$x - $v}] [expr {$y + $v}] -fill green -tags compass
20: for {set N [expr $COMPASS - $CANVAS_W / 2]} {$N <= [expr $COMPASS + $CANVAS_W / 2]} {set N [expr $N + 1]} {
21: set OFFSET [expr $N - $COMPASS + $CANVAS_W / 2]
22: set N2 $N
23: if {$N2 >= 360} {
24: set N2 [expr $N2 - 360]
25: } elseif {$N2 < 0} {
26: set N2 [expr $N2 + 360]
27: }
28: if {[expr $N2 % 90] == 0} {
29: $CANVAS create line $OFFSET 23 $OFFSET 30 -fill white -tags compass
30: if {$N2 == 0 || $N2 == 360} {
31: $CANVAS create text $OFFSET 15 -text "N" -tags compass_text -fill white -tags compass
32: } elseif {$N2 == 90} {
33: $CANVAS create text $OFFSET 15 -text "E" -tags compass_text -fill white -tags compass
34: } elseif {$N2 == 180} {
35: $CANVAS create text $OFFSET 15 -text "S" -tags compass_text -fill white -tags compass
36: } elseif {$N2 == 270} {
37: $CANVAS create text $OFFSET 15 -text "W" -tags compass_text -fill white -tags compass
38: }
39: } elseif {[expr $N2 % 45] == 0} {
40: $CANVAS create line $OFFSET 23 $OFFSET 30 -fill white -tags compass
41: $CANVAS create text $OFFSET 15 -text "$N2" -tags compass_text -fill white -tags compass
42: } elseif {[expr $N2 % 15] == 0} {
43: $CANVAS create line $OFFSET 25 $OFFSET 30 -fill white -tags compass
44: } elseif {[expr $N2 % 5] == 0} {
45: $CANVAS create line $OFFSET 27 $OFFSET 30 -fill gray -tags compass
46: }
47: }
48: $CANVAS create text $x 39 -text "$COMPASS" -tags compass_text -fill white -tags compass
49: set x [expr $TARGET - $COMPASS + $CANVAS_W / 2]
50: set y 7
51: $CANVAS create polygon $x $y [expr {$x + $v}] [expr {$y - $v}] [expr {$x - $v}] [expr {$y - $v}] -outline green -tags compass
52: }
53:
54: proc draw_batt_bar {CANVAS CANVAS_W CANVAS_H VALUE ALARM} {
55: $CANVAS delete batt
56: # $CANVAS create rec 1 1 $CANVAS_W $CANVAS_H -fill black -tags batt
57: # $CANVAS create rec 3 3 [expr $CANVAS_W - 2] [expr $CANVAS_H - 2] -fill red -tags batt
58: # $CANVAS create rec 3 [expr $CANVAS_H - ($CANVAS_H * $VALUE / 100) + 2] [expr $CANVAS_W - 2] [expr $CANVAS_H - 2] -fill green -tags batt
59: $CANVAS create line 1 [expr $CANVAS_H - ($CANVAS_H * $VALUE / 100) + 2] $CANVAS_W [expr $CANVAS_H - ($CANVAS_H * $VALUE / 100) + 2] -fill blue -tags batt
60: $CANVAS create line 1 [expr $CANVAS_H - ($CANVAS_H * $ALARM / 100) + 2] $CANVAS_W [expr $CANVAS_H - ($CANVAS_H * $ALARM / 100) + 2] -fill black -tags batt
61: $CANVAS create text [expr $CANVAS_W / 2] [expr $CANVAS_H - 17] -text "$VALUE%" -tags compass_text -fill black -tags batt
62: }
63:
64: proc draw {TITLE TAG LEN} {
65: set Y 2
66: set H 2
67: set R 4
68: frame .$TAG
69: pack .$TAG -side left -fill x
70: label .$TAG.errors1 -text "$TITLE"
71: pack .$TAG.errors1 -side top -fill x -expand yes
72: canvas .$TAG.screen -relief raised -width 140 -height [expr $Y + (($LEN) * $R)]
73: pack .$TAG.screen -side top -fill x
74: set N 1
75: while {$N <= $LEN} {
76: eval .$TAG.screen create rectangle 0 [expr $Y + ($N - 1) * $R] [expr 128] [expr $Y + ($N - 1) * $R + $H] -width 1
77: eval .$TAG.screen create rectangle 0 [expr $Y + ($N - 1) * $R] 64 [expr $Y + ($N - 1) * $R + $H] -width 1 -tags $TAG$N -fill red
78: incr N
79: }
80: }
81:
82: proc update2 {TAG VALUES LEN FAC OFFSET} {
83: set Y 2
84: set H 2
85: set R 4
86: set N 1
87: while {$N <= $LEN} {
88: set value [expr [expr [lindex $VALUES $N] + $OFFSET] / $FAC / 2]
89: if {$value < 0} {
90: set value 0
91: } elseif {$value > 255} {
92: set value 255
93: }
94: eval .$TAG.screen coords $TAG$N 0 [expr $Y + ($N - 1) * $R] $value [expr $Y + ($N - 1) * $R + $H]
95: incr N
96: }
97: }
98:
99: proc Serial_Init {ComPort ComRate} {
100: set iChannel [open $ComPort w+]
101: set rate $ComRate
102: fconfigure $iChannel -mode $ComRate,n,8,1
103: fconfigure $iChannel -blocking 0
104: fconfigure $iChannel -buffering none
105: fileevent $iChannel readable ""
106: return $iChannel
107: }
108:
109: proc send_channel {CHANNEL VALUE} {
110: global Serial
111: puts $Serial "SCH;$CHANNEL;$VALUE\n"
112: }
113:
114: proc send_cmd {CMD} {
115: global Serial
116: puts -nonewline $Serial "$CMD"
117: }
118:
119: proc get_update {} {
120: global SYSINFO
121: global VERSION
122: global Serial
123: global argv
124:
125: close $Serial
126:
127: set RUNNING_VERSION $VERSION
128: set LAST_VERSION "0"
129: catch {
130: exec xterm -e "wget -O - http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/index.html > rx-tool_wget.TmP"
131: set LAST_VERSION [string trimright [lindex [split [exec cat rx-tool_wget.TmP | grep "[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/[lindex [split $SYSINFO "/"] 0]_[lindex [split $SYSINFO "/"] 1]-[lindex [split $SYSINFO "/"] 2].srec:VERSION="] "="] 1] " ->"]
132: }
133: catch {exec rm -rf rx-tool_wget.TmP}
134: if {$LAST_VERSION != "0"} {
135: if {$LAST_VERSION > $RUNNING_VERSION} {
136: puts "## FOUND UPDATES ($LAST_VERSION > $RUNNING_VERSION) ##"
137: set DOWNLOAD_OK 0
138: catch {
139: puts "wget http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/[lindex [split $SYSINFO "/"] 0]_[lindex [split $SYSINFO "/"] 1]-[lindex [split $SYSINFO "/"] 2].srec > rx-tool_wget-srec.TmP"
140: exec xterm -e "wget -O - http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/[lindex [split $SYSINFO "/"] 0]_[lindex [split $SYSINFO "/"] 1]-[lindex [split $SYSINFO "/"] 2].srec > rx-tool_wget-srec.TmP"
141: set DOWNLOAD_OK 1
142: }
143: if {$DOWNLOAD_OK == 1} {
144: puts "start flashing new firmware (meshprog -t [lindex $argv 0] -f rx-tool_wget-srec.TmP)..."
145: catch {
146: exec xterm -e "meshprog -t [lindex $argv 0] -f rx-tool_wget-srec.TmP"
147: after 1000
148: }
149: } else {
150: puts "Error loading last Version from:"
151: puts " http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/[lindex [split $SYSINFO "/"] 0]_[lindex [split $SYSINFO "/"] 1]-[lindex [split $SYSINFO "/"] 2].srec"
152: }
153: catch {exec rm -rf rx-tool_wget-srec.TmP}
154: } else {
155: puts "You have allready the newest Firmware-Version: $RUNNING_VERSION"
156: }
157: puts "LAST_VERSION=$LAST_VERSION"
158: } else {
159: puts "Error reading last Version from:"
160: puts " http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/index.html"
161: }
162:
163: if {[lindex $argv 0] != ""} {
164: puts "Open Serial-Port: [lindex $argv 0]"
165: if {[lindex $argv 1] != ""} {
166: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
167: } else {
168: set Serial [Serial_Init "[lindex $argv 0]" 38400]
169: }
170: } else {
171: puts "USAGE: rx-tool COMPORT \[BAUD\]"
172: exit 1
173: }
174: fileevent $Serial readable [list rd_chid $Serial]
175: send_cmd "c"
176: after 100
177: send_cmd "I"
178: }
179:
180: proc rd_chid {chid} {
181: global line
182: global VERSION
183: global SYSINFO
184: set msg [read $chid 1]
185: if {$msg == "\n"} {
186: # puts "$line"
187: if {[string match "SYSINFO:*" $line]} {
188: set SYSINFO [lrange [split $line ":"] 1 end]
189: set VERSION [lindex [split $SYSINFO "/"] 3]
190: wm title . "RCOPEN24 RX-Tool ($SYSINFO)"
191: } elseif {[string match "MT:*" $line]} {
192: set TEXT [lrange [split $line ":"] 2 end]
193: catch {
194: wm title .menu "RCOPEN24 Menu: $TEXT"
195: }
196: } elseif {[string match "ME:*:*" $line]} {
197: set TEXT [lindex [split [lrange [split $line ":"] 2 end] "="] 0]
198: set VALUE [lrange [split [lrange [split $line ":"] 2 end] "="] 1 end]
199: set ID [lindex [split $line ":"] 1]
200: # puts "$ID: $TEXT == $VALUE"
201: catch {
202: eval .menu.topm.frame_list.me$ID.n configure -text \"$TEXT\"
203: eval .menu.topm.frame_list.me$ID.v configure -text \"$VALUE\"
204: eval .menu.topm.frame_list.me$ID.n configure -relief flat
205: eval .menu.topm.frame_list.me$ID.v configure -relief flat
206: eval .menu.topm.frame_list.me[expr $ID + 1].n configure -text \"\"
207: eval .menu.topm.frame_list.me[expr $ID + 1].v configure -text \"\"
208: eval .menu.topm.frame_list.me[expr $ID + 1].n configure -relief flat
209: eval .menu.topm.frame_list.me[expr $ID + 1].v configure -relief flat
210: eval .menu.topm.frame_list.me[expr $ID + 2].n configure -text \"\"
211: eval .menu.topm.frame_list.me[expr $ID + 2].v configure -text \"\"
212: eval .menu.topm.frame_list.me[expr $ID + 2].n configure -relief flat
213: eval .menu.topm.frame_list.me[expr $ID + 2].v configure -relief flat
214: eval .menu.topm.frame_list.me[expr $ID + 3].n configure -text \"\"
215: eval .menu.topm.frame_list.me[expr $ID + 3].v configure -text \"\"
216: eval .menu.topm.frame_list.me[expr $ID + 3].n configure -relief flat
217: eval .menu.topm.frame_list.me[expr $ID + 3].v configure -relief flat
218: eval .menu.topm.frame_list.me[expr $ID + 4].n configure -text \"\"
219: eval .menu.topm.frame_list.me[expr $ID + 4].v configure -text \"\"
220: eval .menu.topm.frame_list.me[expr $ID + 4].n configure -relief flat
221: eval .menu.topm.frame_list.me[expr $ID + 4].v configure -relief flat
222: eval .menu.topm.frame_list.me[expr $ID + 5].n configure -text \"\"
223: eval .menu.topm.frame_list.me[expr $ID + 5].v configure -text \"\"
224: eval .menu.topm.frame_list.me[expr $ID + 5].n configure -relief flat
225: eval .menu.topm.frame_list.me[expr $ID + 5].v configure -relief flat
226: }
227: if {[string match ">*" $TEXT]} {
228: catch {
229: eval .menu.topm.frame_list.me$ID.n configure -relief sunken
230: eval .menu.topm.frame_list.me$ID.v configure -relief sunken
231: }
232: }
233:
234:
235:
236:
237: } elseif {[string match "ADC;*" $line]} {
238: update2 "a.adc" [split $line ";"] 4 8 0
239: draw_batt_bar .c.screen3 40 240 [expr [lindex [split $line ";"] 1] * 100 / 1024] 75
240: } elseif {[string match "CHV;*" $line]} {
241: update2 "a.channel" [split $line ";"] 8 16 2048
242: } elseif {[string match "FSV;*" $line]} {
243: update2 "a.failsave" [split $line ";"] 8 16 2048
244: } elseif {[string match "LQI;*" $line]} {
245: update2 "b.lqi" [split $line ";"] 16 1 0
246: } elseif {[string match "RSI;*" $line]} {
247: update2 "b.rssi" [split $line ";"] 16 .11 0
248: } elseif {[string match "SCN;*" $line]} {
249: update2 "b.noise" [split $line ";"] 16 0.12 0
250:
251: } elseif {[string match "MAG;*" $line]} {
252:
253: set COMPASS [expr [lindex [split $line ";"] 1] / 10.0]
254: .c.screen delete compass
255: .c.screen create arc 11 11 60 60 -start [expr -$COMPASS + 90.0] -extent 0 -fill blue -width 2 -tags compass
256: .c.screen delete compass_text
257: .c.screen create text 37 44 -text $COMPASS -tags compass_text
258:
259: set COMPASS [expr [lindex [split $line ";"] 1] / 10]
260: draw_compas_rec .c.screen2 240 40 $COMPASS 230
261:
262:
263: } elseif {[string match "AHR;*" $line]} {
264:
265: set COMPASS [expr [lindex [split $line ";"] 3] / 100.0]
266: .c.screen delete compass
267: .c.screen create arc 11 11 60 60 -start [expr -$COMPASS + 90.0] -extent 0 -fill blue -width 2 -tags compass
268: .c.screen delete compass_text
269: .c.screen create text 37 44 -text $COMPASS -tags compass_text
270:
271: set COMPASS [expr [lindex [split $line ";"] 3] / 100]
272: draw_compas_rec .c.screen2 240 40 $COMPASS 230
273:
274: } elseif {[string match "ETC;*" $line]} {
275: set line2 [split $line ";"]
276: .frame1.last_error configure -text "Last-Error: [lindex $line2 1]"
277: .frame1.quality_errors configure -text "Quality-Errors: [lindex $line2 2]/[lindex $line2 3] ([lindex $line2 4]%)"
278: .frame2.txid configure -text "TXID: [lindex $line2 5]"
279: .frame2.setup_txid configure -text "Setup-TXID: [lindex $line2 6]"
280: .frame2.seq configure -text "Sequence: [lindex $line2 7]"
281: }
282: set line ""
283: } else {
284: set line "$line$msg"
285: }
286: }
287:
288:
289: #wm geometry . 320x250
290: wm title . "RCOPEN24 RX-Tool"
291:
292: frame .frame3
293: pack .frame3 -side top -fill x -expand yes
294:
295: button .frame3.bind -text "Bind" -command {
296: send_cmd "b"
297: }
298: pack .frame3.bind -side left -fill x -expand yes
299:
300: button .frame3.falisave -text "set Failsave" -command {
301: send_cmd "f"
302: }
303: pack .frame3.falisave -side left -fill x -expand yes
304:
305: button .frame3.update -text "Update" -command {
306: send_cmd "c"
307: after 100
308: send_cmd "I"
309: }
310: pack .frame3.update -side left -fill x -expand yes
311:
312: button .frame3.reset -text "Reset" -command {
313: send_cmd "r"
314: after 3000
315: send_cmd "c"
316: after 100
317: send_cmd "I"
318: }
319: pack .frame3.reset -side left -fill x -expand yes
320:
321: button .frame3.flash -text "Flash" -command {
322: get_update
323: }
324: pack .frame3.flash -side left -fill x -expand yes
325:
326: button .frame3.menu -text "Menu" -command {
327: global argv
328:
329:
330: toplevel .menu
331: # wm geometry .menu 320x240
332:
333:
334: frame .menu.topm
335: pack .menu.topm -side top -fill both -expand yes
336:
337:
338: button .menu.topm.left -text "<<" -command {
339: send_cmd "1"
340: after 100
341: send_cmd "c"
342: }
343: pack .menu.topm.left -side left -fill y -expand no
344:
345: frame .menu.topm.frame_list -border 2 -relief raised
346: pack .menu.topm.frame_list -side left -fill both -expand yes
347:
348: frame .menu.topm.frame_list.me0
349: pack .menu.topm.frame_list.me0 -side top -fill both -expand yes
350:
351: label .menu.topm.frame_list.me0.n -text "sss"
352: pack .menu.topm.frame_list.me0.n -side left -fill x -expand yes
353:
354: label .menu.topm.frame_list.me0.v -text ""
355: pack .menu.topm.frame_list.me0.v -side right -fill x -expand yes
356:
357: frame .menu.topm.frame_list.me1
358: pack .menu.topm.frame_list.me1 -side top -fill both -expand yes
359:
360: label .menu.topm.frame_list.me1.n -text ""
361: pack .menu.topm.frame_list.me1.n -side left -fill x -expand yes
362:
363: label .menu.topm.frame_list.me1.v -text ""
364: pack .menu.topm.frame_list.me1.v -side right -fill x -expand yes
365:
366: frame .menu.topm.frame_list.me2
367: pack .menu.topm.frame_list.me2 -side top -fill both -expand yes
368:
369: label .menu.topm.frame_list.me2.n -text ""
370: pack .menu.topm.frame_list.me2.n -side left -fill x -expand yes
371:
372: label .menu.topm.frame_list.me2.v -text ""
373: pack .menu.topm.frame_list.me2.v -side right -fill x -expand yes
374:
375: frame .menu.topm.frame_list.me3
376: pack .menu.topm.frame_list.me3 -side top -fill both -expand yes
377:
378: label .menu.topm.frame_list.me3.n -text ""
379: pack .menu.topm.frame_list.me3.n -side left -fill x -expand yes
380:
381: label .menu.topm.frame_list.me3.v -text ""
382: pack .menu.topm.frame_list.me3.v -side right -fill x -expand yes
383:
384: frame .menu.topm.frame_list.me4
385: pack .menu.topm.frame_list.me4 -side top -fill both -expand yes
386:
387: label .menu.topm.frame_list.me4.n -text ""
388: pack .menu.topm.frame_list.me4.n -side left -fill x -expand yes
389:
390: label .menu.topm.frame_list.me4.v -text ""
391: pack .menu.topm.frame_list.me4.v -side right -fill x -expand yes
392:
393:
394: button .menu.topm.right -text ">>" -command {
395: send_cmd "3"
396: after 100
397: send_cmd "c"
398: }
399: pack .menu.topm.right -side right -fill y -expand no
400:
401:
402:
403:
404: frame .menu.cursor
405: pack .menu.cursor -side left -fill x -expand yes
406:
407: button .menu.cursor.up -text "Up" -command {
408: send_cmd "8"
409: after 100
410: send_cmd "c"
411: }
412: pack .menu.cursor.up -side top -fill x -expand yes
413:
414: button .menu.cursor.down -text "Down" -command {
415: send_cmd "2"
416: after 100
417: send_cmd "c"
418: }
419: pack .menu.cursor.down -side bottom -fill x -expand yes
420:
421: button .menu.cursor.left -text "-" -command {
422: send_cmd "4"
423: after 100
424: send_cmd "c"
425: }
426: pack .menu.cursor.left -side left -fill x -expand yes
427:
428: button .menu.cursor.right -text "+" -command {
429: send_cmd "6"
430: after 100
431: send_cmd "c"
432: }
433: pack .menu.cursor.right -side right -fill x -expand yes
434:
435:
436: send_cmd "s"
437: after 100
438: send_cmd "c"
439:
440:
441:
442: }
443: pack .frame3.menu -side left -fill x -expand yes
444:
445:
446:
447: frame .frame1
448: pack .frame1 -side top -fill x
449:
450: label .frame1.last_error -text "Last-Error: 0"
451: pack .frame1.last_error -side left -fill none -expand yes
452:
453: label .frame1.quality_errors -text "Quality: 0"
454: pack .frame1.quality_errors -side left -fill none -expand yes
455:
456: frame .frame2
457: pack .frame2 -side top -fill x
458:
459: label .frame2.txid -text "TXID: 0"
460: pack .frame2.txid -side left -fill none -expand yes
461:
462: label .frame2.setup_txid -text "Setup-TXID: 0"
463: pack .frame2.setup_txid -side left -fill none -expand yes
464:
465: label .frame2.seq -text "Sequence: 0"
466: pack .frame2.seq -side left -fill none -expand yes
467:
468: frame .a
469: pack .a -side top -fill x
470:
471: draw "ADC's" "a.adc" 4
472: draw "Channel's" "a.channel" 8
473: draw "Failsave's" "a.failsave" 8
474:
475: frame .b
476: pack .b -side top -fill x
477:
478: draw "LQI" "b.lqi" 16
479: draw "RSSI" "b.rssi" 16
480: draw "Noise" "b.noise" 16
481:
482: frame .c
483: #pack .c -side top -fill x
484:
485: canvas .c.screen -relief raised -width 140 -height 140
486: pack .c.screen -side top -fill x
487:
488: .c.screen create oval 1 1 70 70 -fill green
489: for {set N 0} {$N < 360} {set N [expr $N + 10]} {
490: .c.screen create arc 1 1 70 70 -start $N -extent 0 -fill blue
491: }
492: .c.screen create oval 11 11 60 60 -fill gray
493: .c.screen create arc 1 1 70 70 -start 90 -extent 0 -fill blue -tags compass
494: .c.screen create text 37 44 -text "11" -tags compass_text
495:
496: canvas .c.screen2 -relief raised -width 240 -height 45
497: pack .c.screen2 -side top
498: draw_compas_rec .c.screen2 240 40 190 230
499:
500: canvas .c.screen3 -relief raised -width 40 -height 240
501: pack .c.screen3 -side top
502: draw_batt_bar .c.screen3 40 240 86 75
503:
504: .c.screen3 create rec 1 1 40 240 -fill black
505: for {set N 0} {$N <= 240} {set N [expr $N + 4]} {
506: set COLOR "[format "#%0.2x%0.2x%0.2x" [expr 255 - $N] $N 10]"
507: .c.screen3 create rectangle 2 $N 40 [expr $N + 4] -fill $COLOR -outline $COLOR
508: }
509:
510:
511: if {[lindex $argv 0] != ""} {
512: puts "Open Serial-Port: [lindex $argv 0]"
513: if {[lindex $argv 1] != ""} {
514: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
515: } else {
516: set Serial [Serial_Init "[lindex $argv 0]" 38400]
517: }
518: } else {
519: puts "USAGE: rx-tool COMPORT \[BAUD\]"
520: exit 1
521: }
522: fileevent $Serial readable [list rd_chid $Serial]
523: send_cmd "c"
524: after 100
525: send_cmd "I"
526: