RCOPEN24

rCOS RCOPEN24 RX12-AVR AVR-Speak BkSave RCDI SSDEMUX CSV2AVI FM-Manager

tx-tool/tx-tool.tcl


  1: #!/usr/bin/wish
  2: #
  3: #
  4: 
  5: global line
  6: set line ""
  7: 
  8: proc draw {TITLE TAG LEN} {
  9:         set Y 2
 10:         set H 2
 11:         set R 4
 12:         frame .$TAG
 13:         pack .$TAG -side left -fill x
 14:         label .$TAG.errors1 -text "$TITLE"
 15:         pack .$TAG.errors1 -side top -fill x -expand yes
 16:         canvas .$TAG.screen -relief raised -width 140 -height [expr $Y + (($LEN) * $R)]
 17:         pack .$TAG.screen -side top -fill x
 18:         set N 1
 19:         while {$N <= $LEN} {
 20:                 eval .$TAG.screen create rectangle 7 [expr $Y + ($N - 1) * $R] [expr 128 + 10] [expr $Y + ($N - 1) * $R + $H] -width 1
 21:                 eval .$TAG.screen create rectangle 7 [expr $Y + ($N - 1) * $R] 64 [expr $Y + ($N - 1) * $R + $H] -width 1 -tags $TAG$N -fill red
 22:                 incr N
 23:         }
 24: }
 25: 
 26: proc text_draw {TITLE TAG LEN} {
 27:         set Y 2
 28:         set H 2
 29:         set R 8
 30:         frame .$TAG
 31:         pack .$TAG -side left -fill x
 32:         label .$TAG.errors1 -text "$TITLE"
 33:         pack .$TAG.errors1 -side top -fill x -expand yes
 34:         canvas .$TAG.screen -relief raised -width 60 -height [expr $Y + (($LEN + 1) * $R)]
 35:         pack .$TAG.screen -side top -fill x
 36:         set N 1
 37:         while {$N <= $LEN} {
 38:                 eval .$TAG.screen create text 7 [expr $Y + ($N) * $R] -text  \"$N = \" -font \{Helvetica 7\} -anchor w
 39:                 eval .$TAG.screen create text 25 [expr $Y + ($N) * $R] -text  \"0\" -font \{Helvetica 7\} -anchor w -tags $TAG$N -fill red
 40:                 incr N
 41:         }
 42: }
 43: 
 44: proc update {TAG VALUES LEN FAC} {
 45:         set Y 2
 46:         set H 2
 47:         set R 4
 48:         set N 1
 49:         while {$N <= $LEN} {
 50:                 set value [expr [lindex $VALUES $N] / $FAC / 2 + 10]
 51:                 if {$value < 0} {
 52:                         set value 0
 53:                 } elseif {$value > 255} {
 54:                         set value 255
 55:                 }
 56:                 eval .$TAG.screen coords $TAG$N 7 [expr $Y + ($N - 1) * $R] $value [expr $Y + ($N - 1) * $R + $H]
 57: #                puts "$TAG -- $TAG$N 7 [expr $Y + ($N - 1) * $R] $value [expr $Y + ($N - 1) * $R + $H]"
 58:                 incr N
 59:         }
 60: }
 61: 
 62: proc update_text {TAG VALUES LEN OFFSET} {
 63:         set N 1
 64:         puts -nonewline "$TAG"
 65:         while {$N <= $LEN} {
 66:                 eval .$TAG.screen itemconfigure $TAG$N -text \"[lindex $VALUES [expr $N + $OFFSET]]\"
 67:                 puts -nonewline ";[lindex $VALUES [expr $N + $OFFSET]]"
 68:                 incr N
 69:         }
 70:         puts ""
 71: }
 72: 
 73: 
 74: proc Serial_Init {ComPort ComRate} {
 75:         set iChannel [open $ComPort w+]
 76:         set rate $ComRate
 77:         fconfigure $iChannel -mode $ComRate,n,8,1
 78:         fconfigure $iChannel -blocking 0
 79:         fconfigure $iChannel -buffering none
 80:         fileevent $iChannel readable ""
 81:         return $iChannel
 82: }
 83: 
 84: proc send_channel {CHANNEL VALUE} {
 85:         global Serial
 86:         puts $Serial "SCH;$CHANNEL;$VALUE\n"
 87: }
 88: 
 89: proc send_cmd {CMD} {
 90:         global Serial
 91:         puts -nonewline $Serial "$CMD"
 92: }
 93: 
 94: 
 95: proc rd_chid {chid} {
 96:         global line
 97:         set msg [read $chid 1]
 98:         if {$msg == "\n"} {
 99:                 if {[string match "TEL;*" $line]} {
100:                         update "a.tel" [split $line ";"] 16 2
101:                         update_text "a.teltext1" [split $line ";"] 16 0
102:                         update_text "a.teltext2" [split $line ";"] 16 15
103:                         update_text "a.teladc" [split $line ";"] 4 5
104:                         update_text "a.telfs" [split $line ";"] 8 9
105: 
106:                         .frame4.rx_rssi configure -text "RX-RSSI: [lindex [split $line ";"] 3]"
107:                         .frame4.rx_lqi configure -text "RX-LQI: [lindex [split $line ";"] 5]"
108:                         .frame4.rx_batt configure -text "RX-BATT: [expr [lindex [split $line ";"] 6] * 1024 / 100] mV"
109: 
110:                 } elseif {[string match "CHV;*" $line]} {
111:                         update "a.channel" [split $line ";"] 8 0.1
112:                 } elseif {[string match "FSV;*" $line]} {
113:                         update "a.failsave" [split $line ";"] 8 0.1
114:                 } elseif {[string match "LQI;*" $line]} {
115:                         update "b.lqi" [split $line ";"] 16 1
116:                 } elseif {[string match "RSI;*" $line]} {
117:                         update "b.rssi" [split $line ";"] 16 1
118:                 } elseif {[string match "SCN;*" $line]} {
119:                         update "b.noise" [split $line ";"] 16 1
120:                 } elseif {[string match "ETC;*" $line]} {
121:                         set line2 [split $line ";"]
122:                         .frame1.tx_rssi configure -text "TX-RSSI: [lindex $line2 2]"
123:                         .frame1.tx_lqi configure -text "TX-LQI: [lindex $line2 3]"
124:                         .frame2.txid configure -text "TX-TXID: [lindex $line2 1]"
125:                         .frame2.tx_channels configure -text "TX-Channels: [lindex $line2 4]"
126:                         .frame2.seq configure -text "Sequence: [lindex $line2 4]"
127:                 }
128:                 set line ""
129:         } else {
130:                 set line "$line$msg"
131:         }
132: }
133: 
134: 
135: #wm geometry . 320x250
136: wm title . "RCOPEN24 TX-Tool"
137: 
138: #frame .frame3
139: #pack .frame3 -side top -fill x -expand yes
140: #
141: #        button .frame3.bind -text "Bind" -command {
142: #                send_cmd "b"
143: #        }
144: #        pack .frame3.bind -side left -fill x -expand yes
145: #
146: #        button .frame3.falisave -text "set Failsave" -command {
147: #                send_cmd "f"
148: #        }
149: #        pack .frame3.falisave -side left -fill x -expand yes
150: #
151: #        button .frame3.update -text "Update" -command {
152: #                send_cmd "c"
153: #        }
154: #        pack .frame3.update -side left -fill x -expand yes
155: #
156: #        button .frame3.reset -text "Reset" -command {
157: #                send_cmd "r"
158: #        }
159: #        pack .frame3.reset -side left -fill x -expand yes
160: 
161: frame .frame1
162: pack .frame1 -side top -fill x
163: 
164:         label .frame1.tx_rssi -text "TX-RSSI: 0"
165:         pack .frame1.tx_rssi -side left -fill none -expand yes
166: 
167:         label .frame1.tx_lqi -text "TX-LQI: 0"
168:         pack .frame1.tx_lqi -side left -fill none -expand yes
169: 
170:         label .frame1.tx_batt -text "TX-BATT: 0 mV"
171:         pack .frame1.tx_batt -side left -fill none -expand yes
172: 
173: frame .frame4
174: pack .frame4 -side top -fill x
175: 
176:         label .frame4.rx_rssi -text "RX-RSSI: 0"
177:         pack .frame4.rx_rssi -side left -fill none -expand yes
178: 
179:         label .frame4.rx_lqi -text "RX-LQI: 0"
180:         pack .frame4.rx_lqi -side left -fill none -expand yes
181: 
182:         label .frame4.rx_batt -text "RX-BATT: 0 mV"
183:         pack .frame4.rx_batt -side left -fill none -expand yes
184: 
185: 
186: frame .frame2
187: pack .frame2 -side top -fill x
188: 
189:         label .frame2.txid -text "TXID: 0"
190:         pack .frame2.txid -side left -fill none -expand yes
191: 
192:         label .frame2.tx_channels -text "Setup-TXID: 0"
193:         pack .frame2.tx_channels -side left -fill none -expand yes
194: 
195:         label .frame2.seq -text "Sequence: 0"
196:         pack .frame2.seq -side left -fill none -expand yes
197: 
198: frame .a
199: pack .a -side top -fill x
200: 
201:         draw "TELEDATA's" "a.tel" 16
202:         draw "Channel's" "a.channel" 8
203:         text_draw "TELE1" "a.teltext1" 16
204:         text_draw "TELE2" "a.teltext2" 16
205:         text_draw "ADC's" "a.teladc" 4
206:         text_draw "Failsave's" "a.telfs" 8
207: 
208: if {[lindex $argv 0] != ""} {
209:         puts "Open Serial-Port: [lindex $argv 0]"
210: 
211:         if {[lindex $argv 1] != ""} {
212:                 set Serial [Serial_Init "[lindex $argv 0]" [lindex $argv 1]]
213:         } else {
214:                 set Serial [Serial_Init "[lindex $argv 0]" 38400]
215:         }
216: } else {
217:         puts "USAGE: tx-tool COMPORT [BAUDRATE]"
218:         exit 1
219: }
220: 
221: fileevent $Serial readable [list rd_chid $Serial]
222: #puts -nonewline $Serial "c"
223: 
224: 
225: 
226: 
227: