rx-tool/serial-menu.tcl
1: #!/usr/bin/wish
2: #
3: #
4:
5: global line
6: global argv
7: set line ""
8: set VERSION ""
9:
10:
11: proc Serial_Init {ComPort ComRate} {
12: set iChannel [open $ComPort w+]
13: set rate $ComRate
14: fconfigure $iChannel -mode $ComRate,n,8,1
15: fconfigure $iChannel -blocking 0
16: fconfigure $iChannel -buffering none
17: fileevent $iChannel readable ""
18: return $iChannel
19: }
20:
21: proc send_channel {CHANNEL VALUE} {
22: global Serial
23: puts $Serial "SCH;$CHANNEL;$VALUE\n"
24: }
25:
26: proc send_cmd {CMD} {
27: global Serial
28: puts -nonewline $Serial "$CMD"
29: }
30:
31: proc get_update {} {
32: global SYSINFO
33: global VERSION
34: global Serial
35: global argv
36:
37: close $Serial
38:
39: set RUNNING_VERSION $VERSION
40: set LAST_VERSION "0"
41: catch {
42: exec xterm -e "wget -O - http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/index.html > rx-tool_wget.TmP"
43: 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] " ->"]
44: }
45: catch {exec rm -rf rx-tool_wget.TmP}
46: if {$LAST_VERSION != "0"} {
47: if {$LAST_VERSION > $RUNNING_VERSION} {
48: puts "## FOUND UPDATES ($LAST_VERSION > $RUNNING_VERSION) ##"
49: set DOWNLOAD_OK 0
50: catch {
51: 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"
52: 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"
53: set DOWNLOAD_OK 1
54: }
55: if {$DOWNLOAD_OK == 1} {
56: puts "start flashing new firmware (meshprog -t [lindex $argv 0] -f rx-tool_wget-srec.TmP)..."
57: catch {
58: exec xterm -e "meshprog -t [lindex $argv 0] -f rx-tool_wget-srec.TmP"
59: after 1000
60: }
61: } else {
62: puts "Error loading last Version from:"
63: 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"
64: }
65: catch {exec rm -rf rx-tool_wget-srec.TmP}
66: } else {
67: puts "You have allready the newest Firmware-Version: $RUNNING_VERSION"
68: }
69: puts "LAST_VERSION=$LAST_VERSION"
70: } else {
71: puts "Error reading last Version from:"
72: puts " http://www.rcopen24.org/targets/[lindex [split $SYSINFO "/"] 0]/[lindex [split $SYSINFO "/"] 1]/index.html"
73: }
74:
75: if {[lindex $argv 0] != ""} {
76: puts "Open Serial-Port: [lindex $argv 0]"
77: if {[lindex $argv 1] != ""} {
78: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
79: } else {
80: set Serial [Serial_Init "[lindex $argv 0]" 38400]
81: }
82: } else {
83: puts "USAGE: rx-tool COMPORT [BAUD]"
84: exit 1
85: }
86: fileevent $Serial readable [list rd_chid $Serial]
87: send_cmd "c"
88: after 100
89: send_cmd "I"
90: }
91:
92: proc rd_chid {chid} {
93: global line
94: global VERSION
95: global SYSINFO
96: set msg [read $chid 1]
97: if {$msg == "\n"} {
98: puts "$line"
99: if {[string match "SYSINFO:*" $line]} {
100: set SYSINFO [lrange [split $line ":"] 1 end]
101: set VERSION [lindex [split $SYSINFO "/"] 3]
102: wm title . "RCOPEN24 RX-Tool ($SYSINFO)"
103:
104: } elseif {[string match "ME:*:*" $line]} {
105: set TEXT [lindex [split [lrange [split $line ":"] 2 end] "="] 0]
106: set VALUE [lrange [split [lrange [split $line ":"] 2 end] "="] 1 end]
107: set ID [lindex [split $line ":"] 1]
108: puts "$ID: $TEXT == $VALUE"
109: catch {
110: eval .frame_list.me$ID.n configure -text \"$TEXT\"
111: eval .frame_list.me$ID.v configure -text \"$VALUE\"
112: eval .frame_list.me$ID.n configure -relief flat
113: eval .frame_list.me$ID.v configure -relief flat
114: eval .frame_list.me[expr $ID + 1].n configure -text \"\"
115: eval .frame_list.me[expr $ID + 1].v configure -text \"\"
116: eval .frame_list.me[expr $ID + 1].n configure -relief flat
117: eval .frame_list.me[expr $ID + 1].v configure -relief flat
118: eval .frame_list.me[expr $ID + 2].n configure -text \"\"
119: eval .frame_list.me[expr $ID + 2].v configure -text \"\"
120: eval .frame_list.me[expr $ID + 2].n configure -relief flat
121: eval .frame_list.me[expr $ID + 2].v configure -relief flat
122: eval .frame_list.me[expr $ID + 3].n configure -text \"\"
123: eval .frame_list.me[expr $ID + 3].v configure -text \"\"
124: eval .frame_list.me[expr $ID + 3].n configure -relief flat
125: eval .frame_list.me[expr $ID + 3].v configure -relief flat
126: eval .frame_list.me[expr $ID + 4].n configure -text \"\"
127: eval .frame_list.me[expr $ID + 4].v configure -text \"\"
128: eval .frame_list.me[expr $ID + 4].n configure -relief flat
129: eval .frame_list.me[expr $ID + 4].v configure -relief flat
130: eval .frame_list.me[expr $ID + 5].n configure -text \"\"
131: eval .frame_list.me[expr $ID + 5].v configure -text \"\"
132: eval .frame_list.me[expr $ID + 5].n configure -relief flat
133: eval .frame_list.me[expr $ID + 5].v configure -relief flat
134: }
135: if {[string match ">*" $TEXT]} {
136: catch {
137: eval .frame_list.me$ID.n configure -relief raised
138: eval .frame_list.me$ID.v configure -relief raised
139: }
140: }
141: }
142: set line ""
143: } else {
144: set line "$line$msg"
145: }
146: }
147:
148:
149: wm geometry . 320x240
150: wm title . "RCOPEN24 RX-Menu"
151:
152:
153: frame .frame_list
154: pack .frame_list -side top -fill x
155:
156: label .frame_list.space -text ""
157: pack .frame_list.space -side top -fill x -expand yes
158:
159: frame .frame_list.me0
160: pack .frame_list.me0 -side top -fill x
161:
162: label .frame_list.me0.n -text ""
163: pack .frame_list.me0.n -side left -fill x -expand yes
164:
165: label .frame_list.me0.v -text ""
166: pack .frame_list.me0.v -side right -fill x -expand yes
167:
168: frame .frame_list.me1
169: pack .frame_list.me1 -side top -fill x
170:
171: label .frame_list.me1.n -text ""
172: pack .frame_list.me1.n -side left -fill x -expand yes
173:
174: label .frame_list.me1.v -text ""
175: pack .frame_list.me1.v -side right -fill x -expand yes
176:
177: frame .frame_list.me2
178: pack .frame_list.me2 -side top -fill x
179:
180: label .frame_list.me2.n -text ""
181: pack .frame_list.me2.n -side left -fill x -expand yes
182:
183: label .frame_list.me2.v -text ""
184: pack .frame_list.me2.v -side right -fill x -expand yes
185:
186: frame .frame_list.me3
187: pack .frame_list.me3 -side top -fill x
188:
189: label .frame_list.me3.n -text ""
190: pack .frame_list.me3.n -side left -fill x -expand yes
191:
192: label .frame_list.me3.v -text ""
193: pack .frame_list.me3.v -side right -fill x -expand yes
194:
195: frame .frame_list.me4
196: pack .frame_list.me4 -side top -fill x
197:
198: label .frame_list.me4.n -text ""
199: pack .frame_list.me4.n -side left -fill x -expand yes
200:
201: label .frame_list.me4.v -text ""
202: pack .frame_list.me4.v -side right -fill x -expand yes
203:
204:
205: frame .frameB
206: pack .frameB -side top -fill x -expand yes
207:
208:
209: button .frameB.m -text "Left" -command {
210: send_cmd "1"
211: }
212: pack .frameB.m -side left -fill both -expand yes
213:
214: frame .frameB.frame3
215: pack .frameB.frame3 -side left -fill x -expand yes
216:
217: button .frameB.frame3.up -text "Up" -command {
218: send_cmd "8"
219: }
220: pack .frameB.frame3.up -side top -fill x -expand yes
221:
222: button .frameB.frame3.down -text "Down" -command {
223: send_cmd "2"
224: }
225: pack .frameB.frame3.down -side bottom -fill x -expand yes
226:
227: button .frameB.frame3.left -text "-" -command {
228: send_cmd "4"
229: }
230: pack .frameB.frame3.left -side left -fill x -expand yes
231:
232: button .frameB.frame3.right -text "+" -command {
233: send_cmd "6"
234: }
235: pack .frameB.frame3.right -side right -fill x -expand yes
236:
237:
238: button .frameB.p -text "Right" -command {
239: send_cmd "3"
240: }
241: pack .frameB.p -side right -fill both -expand yes
242:
243: if {[lindex $argv 0] != ""} {
244: puts "Open Serial-Port: [lindex $argv 0]"
245: if {[lindex $argv 1] != ""} {
246: set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
247: } else {
248: set Serial [Serial_Init "[lindex $argv 0]" 38400]
249: }
250: } else {
251: puts "USAGE: rx-tool COMPORT [BAUD]"
252: exit 1
253: }
254: fileevent $Serial readable [list rd_chid $Serial]
255: send_cmd "s"
256: after 100
257: send_cmd "I"
258: