Fixed switch reply string and added test option to ignore updates.

r2921 | ffr | 2010-05-14 12:31:24 +1000 (Fri, 14 May 2010) | 2 lines
This commit is contained in:
Ferdi Franceschini
2010-05-14 12:31:24 +10:00
committed by Douglas Clowes
parent bc3471bb98
commit fbec2505c5

View File

@@ -1,5 +1,5 @@
# $Revision: 1.1.2.1 $
# $Date: 2010-05-10 05:52:24 $
# $Revision: 1.1.2.2 $
# $Date: 2010-05-14 02:31:24 $
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
# Last revision by: $Author: ffr $
@@ -30,6 +30,7 @@ proc readLine {channel} {
global VOLTAGE
global bSWITCHES
global bOPSTATE
set TESTMODE "fail"
set data [read $channel 1]
binary scan $data c sigStart
@@ -69,8 +70,10 @@ proc readLine {channel} {
puts stdout "SENT frequency = $FREQUENCY"
puts -nonewline $channel $VOLTAGE
puts stdout "SENT voltage = $VOLTAGE"
puts -nonewline $channel $bSWITCHES
binary scan $bSWITCHES B8 SW
set SW [string replace $SW 0 0 1]
set bSWITCHES [binary format B8 $SW]
puts -nonewline $channel $bSWITCHES
puts stdout "SENT switches $SW"
puts -nonewline $channel $bOPSTATE
binary scan $bOPSTATE B8 OS
@@ -79,13 +82,18 @@ proc readLine {channel} {
puts stdout "SENT end byte 3"
}
"S" {
set CURRENT [read $channel 2]
set currIn [read $channel 2]
puts stdout "RECEIVED: current = $CURRENT"
set FREQUENCY [read $channel 3]
set freqIn [read $channel 3]
puts stdout "RECEIVED: frequency = $FREQUENCY"
set bSWITCHES [read $channel 1]
binary scan $bSWITCHES B8 SW
set swIn [read $channel 1]
binary scan $swIn B8 SW
puts stdout "RECEIVED: switches = $SW"
if {$TESTMODE == "normal"} {
set CURRENT $currIn
set FREQUENCY $freqIn
set bSWITCHES $swIn
}
set data [read $channel 1]
binary scan $data c sigEnd
if {$sigEnd != 3} {
@@ -106,77 +114,6 @@ proc readLine {channel} {
flush $channel
return
}
# Reads a command from a DMC2280 client and then performs an appropriate
# action depending on whether or not the command produces output or has
# been defined.
set lasttime 0
proc xreadLine {who channel} {
global voltage
global didRead
global B
global currtime
global lasttime
set currtime [clock seconds]
if {[expr $currtime - $lasttime] > 30} {
puts stdout "Time for a NAK"
puts -nonewline $channel [binary format c 0x15]
set lasttime [clock seconds]
flush stdout
flush $channel
return
}
set data [read $channel 1]
puts -nonewline stdout "RECEIVED: <$data"
switch $data {
"v" {
set z [read $channel 1]
if { $z == "z" } {
puts stdout "$z>"
puts stdout "SEND: TESTER 1.0z"
puts -nonewline $channel "TESTER 1.0z"
} else {
puts stdout ">"
}
}
"h" {
set v [read $channel 1]
binary scan $v c volts
set z [read $channel 1]
if { $z == "z" } {
puts stdout [format "%d$z>" $volts]
binary scan $v c voltage
puts stdout "SEND: ACK for $voltage"
puts -nonewline $channel [binary format c 0x06]
} else {
puts stdout [format "%d$z>" $volts]
puts stdout "SEND: NAK for bad h command"
puts -nonewline $channel [binary format c 0x15]
}
}
"H" {
set z [read $channel 1]
if { $z == "z" } {
puts stdout "$z>"
set voltage [expr int(rand()*1000 )]
puts stdout [format "SEND: H%dz" $voltage]
puts -nonewline $channel "H[binary format c $voltage]z"
} else {
puts stdout "$z>"
puts stdout "SEND: NAK for bad H command"
puts -nonewline $channel [binary format c 0x15]
}
}
default {
puts stdout ">"
puts stdout "SEND: NAK for bad <$data> command"
puts -nonewline $channel [binary format c 0x15]
}
}
flush stdout
flush $channel
return;
}
# startserver -port 1034
proc startserver {args} {
@@ -189,4 +126,4 @@ proc startserver {args} {
return;
}
startserver -port 65001
startserver -port 65012