Added a realist test mode to simulate fluctuating current as in the real RF generator

r2927 | ffr | 2010-05-18 20:16:53 +1000 (Tue, 18 May 2010) | 2 lines
This commit is contained in:
Ferdi Franceschini
2010-05-18 20:16:53 +10:00
committed by Douglas Clowes
parent 9cb2ba5ed8
commit 5811f125a9

View File

@@ -1,5 +1,5 @@
# $Revision: 1.1.2.3 $
# $Date: 2010-05-14 02:36:39 $
# $Revision: 1.1.2.4 $
# $Date: 2010-05-18 10:16:53 $
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
# Last revision by: $Author: ffr $
@@ -23,6 +23,13 @@ set FREQUENCY [format "%03d" 170]
set bSWITCHES [binary format B8 10001111]
set bOPSTATE [binary format B8 10000101]
proc trimzpad {a} {
if {$a == 0} {
return "0"
} else {
return [string trimleft $a 0]
}
}
proc readLine {channel} {
global ADDRESS
global CURRENT
@@ -30,7 +37,7 @@ proc readLine {channel} {
global VOLTAGE
global bSWITCHES
global bOPSTATE
set TESTMODE "normal"
set TESTMODE "realistic"
set data [read $channel 1]
binary scan $data c sigStart
@@ -64,8 +71,24 @@ proc readLine {channel} {
puts stdout "SENT address = $ADDRESS"
puts -nonewline $channel "L"
puts stdout "SENT command type = L"
puts -nonewline $channel $CURRENT
puts stdout "SENT current = $CURRENT"
switch $TESTMODE {
"reliable" {
# Just report what we receive for the current
set currOut $CURRENT
}
"realistic" {
set curr [trimzpad $CURRENT]
set curr [ expr { $curr-1 + round(rand()) } ]
set currOut [format "%02d" $curr]
}
"locurr" {
set curr [trimzpad $CURRENT]
set curr [ expr { $curr-1 } ]
set currOut [format "%02d" $curr]
}
}
puts -nonewline $channel $currOut
puts stdout "SENT current = $currOut"
puts -nonewline $channel $FREQUENCY
puts stdout "SENT frequency = $FREQUENCY"
puts -nonewline $channel $VOLTAGE
@@ -89,11 +112,9 @@ proc readLine {channel} {
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 CURRENT $currIn
set FREQUENCY $freqIn
set bSWITCHES $swIn
set data [read $channel 1]
binary scan $data c sigEnd
if {$sigEnd != 3} {