add new protocl controller for ag1010
r3674 | jgn | 2012-07-23 13:42:05 +1000 (Mon, 23 Jul 2012) | 1 line
This commit is contained in:
committed by
Douglas Clowes
parent
1da7a21805
commit
7453eb2458
774
site_ansto/instrument/pelican/config/beamline/sct_power.tcl
Normal file
774
site_ansto/instrument/pelican/config/beamline/sct_power.tcl
Normal file
@@ -0,0 +1,774 @@
|
||||
|
||||
# Define procs in ::scobj::xxx namespace
|
||||
# MakeSICSObj $obj SCT_<class>
|
||||
# The MakeSICSObj cmd adds a /sics/$obj node. NOTE the /sics node is not browsable.
|
||||
|
||||
##
|
||||
# /*--------------------------------------------------------------------------
|
||||
# LF Amplifier/Generator Model AG 1010 Driver
|
||||
#
|
||||
# @file: This file contains the implementation of a driver for the AG 1010
|
||||
# LF Amplifier/Generator
|
||||
#
|
||||
# @author: Jing Chen, ANSTO, 2012-06-26
|
||||
# @brief: SICS driver for LF AG 1010 LF Amplifier/Generator
|
||||
#
|
||||
# ----------------------------------------------------------------------------*/
|
||||
|
||||
# Default AG1010 LF Amplifier/Generator Controller parameters
|
||||
namespace eval ::scobj::ag1010 {
|
||||
|
||||
variable CtrlSetLIMITS [format %02x 2]
|
||||
variable CtrlSetPAGC [format %02x 3]
|
||||
variable CtrlSetPMGC [format %02x 4]
|
||||
variable CtrlSetFREQ [format %02x 5]
|
||||
variable CtrlSetSKEY [format %02x 7]
|
||||
variable CtrlSetBurstPar [format %02x 8]
|
||||
variable CtrlSetSweepPar [format %02x 9]
|
||||
|
||||
variable CtrlGetLIMITS [format %02x 17]
|
||||
variable CtrlGetPAGC [format %02x 19]
|
||||
variable CtrlGetPMGC [format %02x 20]
|
||||
variable CtrlGetFREQ [format %02x 21]
|
||||
variable CtrlGetSKEY [format %02x 23]
|
||||
variable CtrlGetBurstPar [format %02x 24]
|
||||
variable CtrlGetSweepPar [format %02x 25]
|
||||
variable CtrlGetSVER [format %02x 29]
|
||||
variable CtrlGetMEAS [format %02x 30]
|
||||
variable CtrlGetSTA [format %02x 31]
|
||||
|
||||
variable CtrlShowLIMITS [format %02x 2]
|
||||
variable CtrlShowPAGC [format %02x 3]
|
||||
variable CtrlShowPMGC [format %02x 4]
|
||||
variable CtrlShowFREQ [format %02x 5]
|
||||
variable CtrlShowSKEY [format %02x 7]
|
||||
variable CtrlShowBurstPar [format %02x 8]
|
||||
variable CtrlShowSweepPar [format %02x 9]
|
||||
variable CtrlShowSVER [format %02x 13]
|
||||
variable CtrlShowMEAS [format %02x 14]
|
||||
variable CtrlShowSTA [format %02x 15]
|
||||
|
||||
variable CtrlREJ [format %02x 42]
|
||||
}
|
||||
|
||||
|
||||
############# Reading polled nodes #######################################################
|
||||
##
|
||||
# @brief Sends a query command to the device via a read node formalism
|
||||
# @param tc_root The path to the root of the node
|
||||
# @param nextState The next function to call after this one (typically 'rdValue'
|
||||
# to read the response from the device)
|
||||
# @param rdPara data to be sent to the device
|
||||
# @return nextState The next function to call after this one (typically 'rdValue')
|
||||
|
||||
proc ::scobj::ag1010::getValue {tc_root nextState rdPara} {
|
||||
if {[ catch {
|
||||
set HEAD 96
|
||||
set LEN [lindex $rdPara 0]
|
||||
set CTRL [lindex $rdPara 1]
|
||||
set DATA 0
|
||||
set CRC 0
|
||||
|
||||
if {$LEN < 2} {
|
||||
return -code error "Error in getValue: wrong data length provided."
|
||||
} elseif {$LEN > 2} {
|
||||
set cmd [format %02s%02x%02x%02x%02x $HEAD $LEN $CTRL $DATA $CRC]
|
||||
} else {
|
||||
set cmd [format %02s%02x%02x%02x $HEAD $LEN $CTRL $CRC]
|
||||
}
|
||||
sct send "$cmd"
|
||||
} message ]} {
|
||||
return -code error "Error in getValue: $message."
|
||||
}
|
||||
return $nextState
|
||||
}
|
||||
|
||||
################## Writing to nodes ########################################################
|
||||
##
|
||||
# @brief Writes a new value to a node and sends the corresponding command to the device.
|
||||
# @param tc_root string variable holding the path to the object's base node in sics
|
||||
# @param nextState the next function to call after this one
|
||||
# @param wrPara indicates which control loop or which input channel the command belongs to
|
||||
# @return nextState Is typically noResponse as the device does not acknowledge the write request
|
||||
|
||||
proc ::scobj::ag1010::setValue {tc_root nextState rdPara wrPara} {
|
||||
# tc_root and idx are not being used - however, don't remove so we can use the
|
||||
# same calling mask as for setPoint() or other $wrFunc
|
||||
|
||||
#set ns /sics/ag1010
|
||||
set ns [sct]
|
||||
if {[ catch {
|
||||
set HEAD 96
|
||||
set LEN [lindex $rdPara 0]
|
||||
set CTRL [lindex $rdPara 1]
|
||||
set CRC 0
|
||||
|
||||
set newPara [string trim [sct target] " "]
|
||||
switch -exact $wrPara {
|
||||
"FPL" { set RPL [hval $ns/limits/ReversePower]
|
||||
set data [format %04x%04x%04x%04x $newPara $RPL 0 0]
|
||||
}
|
||||
"RPL" { set FPL [hval $ns/limits/ForwardPower]
|
||||
set data [format %04x%04x%04x%04x $FPL $newPara 0 0]
|
||||
}
|
||||
"PAGC" { set data [format %04x $newPara] }
|
||||
"PMGC" { set data [format %04x $newPara] }
|
||||
"FREQ" { set Freq [expr $newPara / 1000]
|
||||
set FreqHz [expr $newPara % 1000]
|
||||
set data [format %04x%04x $Freq $FreqHz]
|
||||
}
|
||||
"SoftOn" { set data 0x00
|
||||
if {$newPara == 1} {
|
||||
set data [expr $data | 0x80]
|
||||
} elseif {$newPara != 0} {
|
||||
return -code error "Error in setValue: only allowed input values for SoftKey are {0,1}."
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key1]} {
|
||||
set data [expr $data | 0x08]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key0]} {
|
||||
set data [expr $data | 0x04]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key2]} {
|
||||
set data [expr $data | 0x02]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key3]} {
|
||||
set data [expr $data | 0x01]
|
||||
}
|
||||
}
|
||||
"Key1" { set data 0x00
|
||||
if {$newPara == 1} {
|
||||
set data [expr $data | 0x08]
|
||||
} elseif {$newPara != 0} {
|
||||
return -code error "Error in setValue: only allowed input values for Key1 are {0,1}."
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/SoftOn]} {
|
||||
set data [expr $data | 0x80]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key0]} {
|
||||
set data [expr $data | 0x04]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key2]} {
|
||||
set data [expr $data | 0x02]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key3]} {
|
||||
set data [expr $data | 0x01]
|
||||
}
|
||||
}
|
||||
"Key0" { set data 0x00
|
||||
if {$newPara == 1} {
|
||||
set data [expr $data | 0x04]
|
||||
} elseif {$newPara != 0} {
|
||||
return -code error "Error in setValue: only allowed input values for Key0 are {0,1}."
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/SoftOn]} {
|
||||
set data [expr $data | 0x80]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key1]} {
|
||||
set data [expr $data | 0x08]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key2]} {
|
||||
set data [expr $data | 0x02]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key3]} {
|
||||
set data [expr $data | 0x01]
|
||||
}
|
||||
}
|
||||
"Key2" { set data 0x00
|
||||
if {$newPara == 1} {
|
||||
set data [expr $data | 0x02]
|
||||
} elseif {$newPara != 0} {
|
||||
return -code error "Error in setValue: only allowed input values for Key2 are {0,1}."
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/SoftOn]} {
|
||||
set data [expr $data | 0x80]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key1]} {
|
||||
set data [expr $data | 0x08]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key0]} {
|
||||
set data [expr $data | 0x04]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key3]} {
|
||||
set data [expr $data | 0x01]
|
||||
}
|
||||
}
|
||||
"Key3" { set data 0x00
|
||||
if {$newPara == 1} {
|
||||
set data [expr $data | 0x01]
|
||||
} elseif {$newPara != 0} {
|
||||
return -code error "Error in setValue: only allowed input values for Key3 are {0,1}."
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/SoftOn]} {
|
||||
set data [expr $data | 0x80]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key1]} {
|
||||
set data [expr $data | 0x08]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key0]} {
|
||||
set data [expr $data | 0x04]
|
||||
}
|
||||
if {[string match -nocase "on" [hval $ns/SKEY/Key2]} {
|
||||
set data [expr $data | 0x02]
|
||||
}
|
||||
}
|
||||
"BurstMode" { if {$newPara<0 || $newPara>3} {
|
||||
return -code error "Error in setValue: only allowed input values for BurstMode are {0,1,2,3}"
|
||||
} else {
|
||||
set BurstMode $newPara
|
||||
}
|
||||
set BRepTime [hval $ns/BurstPar/BRepTime]
|
||||
set TimeOfPower [hval $ns/BurstPar/TimeOfPower]
|
||||
set data [format %02x%04x%04x $BurstMode $BRepTime $TimeOfPower]
|
||||
}
|
||||
"BRepTime" { set BurstMode [hval $ns/BurstPar/BurstMode]
|
||||
if {[string equal $BurstMode "OFF"]} {
|
||||
set BurstMode 0
|
||||
} elseif {[string equal $BurstMode "Internal Mode ON"} {
|
||||
set BurstMode 1
|
||||
} elseif {[string match "Without Changing" $BurstMode]} {
|
||||
set BurstMode 2
|
||||
} elseif {[string match "External Burst" $BurstMode]} {
|
||||
} else {
|
||||
return -code error "Error in setValue: reading invaild BurstMode value."
|
||||
}
|
||||
set TimeOfPower [hval $ns/BurstPar/TimeOfPower]
|
||||
set data [format %02x%04x%04x $BurstMode $newPara $TimeOfPower]
|
||||
}
|
||||
"BTofP" { set BurstMode [hval $ns/BurstPar/BurstMode]
|
||||
if {[string equal $BurstMode "OFF"]} {
|
||||
set BurstMode 0
|
||||
} elseif {[string equal $BurstMode "Internal Mode ON"} {
|
||||
set BurstMode 1
|
||||
} elseif {[string match "Without Changing" $BurstMode]} {
|
||||
set BurstMode 2
|
||||
} elseif {[string match "External Burst" $BurstMode]} {
|
||||
} else {
|
||||
return -code error "Error in setValue: reading invaild BurstMode value."
|
||||
}
|
||||
set BRepTime [hval $ns/BurstPar/BRepTime]
|
||||
set data [format %02x%04x%04x $BurstMode $BRepTime $newPara]
|
||||
}
|
||||
"SweepMode" { if {$newPara<0 || $newPara>2} {
|
||||
return -code error "Error in setValue: only allowed input values for SweepMode are {0,1,2}"
|
||||
} else {
|
||||
set SweepMode $newPara
|
||||
}
|
||||
set SStr [expr [hval $ns/SweepPar/StartFreq] / 1000]
|
||||
set SStrHz [expr [hval $ns/SweepPar/StartFreq] % 1000]
|
||||
set SStp [expr [hval $ns/SweepPar/StepFreq] / 1000]
|
||||
set SStpHz [expr [hval $ns/SweepPar/StepFreq] % 1000]
|
||||
set SCyc [hval $ns/SweepPar/SCyc]
|
||||
set data [format %02x%02x%02x%02x%02x%02x $SweepMode $SStr $SStp $SCyc $SStrHz $SStpHz]
|
||||
}
|
||||
"SStrF" { set SweepMode [hval $ns/SweepPar/SweepMode]
|
||||
if {[string equal $SweepMode "OFF"]} {
|
||||
set SweepMode 0
|
||||
} elseif {[string equal $SweepMode "ON"} {
|
||||
set SweepMode 1
|
||||
} elseif {[string match "Without Changing" $SweepMode]} {
|
||||
set SweepMode 2
|
||||
} else {
|
||||
return -code error "Error in setValue: reading invaild SweepMode value."
|
||||
}
|
||||
set SStr [expr $newPara / 1000]
|
||||
set SStrHz [expr $newPara % 1000]
|
||||
set SStp [expr [hval $ns/SweepPar/StepFreq] / 1000]
|
||||
set SStpHz [expr [hval $ns/SweepPar/StepFreq] % 1000]
|
||||
set SCyc [hval $ns/SweepPar/SCyc]
|
||||
set data [format %02x%02x%02x%02x%02x%02x $SweepMode $SStr $SStp $SCyc $SStrHz $SStpHz]
|
||||
}
|
||||
"SSteF" { set SweepMode [hval $ns/SweepPar/SweepMode]
|
||||
if {[string equal $SweepMode "OFF"]} {
|
||||
set SweepMode 0
|
||||
} elseif {[string equal $SweepMode "ON"} {
|
||||
set SweepMode 1
|
||||
} elseif {[string match "Without Changing" $SweepMode]} {
|
||||
set SweepMode 2
|
||||
} else {
|
||||
return -code error "Error in setValue: reading invaild SweepMode value."
|
||||
}
|
||||
set SStr [expr [hval $ns/SweepPar/StartFreq] / 1000]
|
||||
set SStrHz [expr [hval $ns/SweepPar/StartFreq] % 1000]
|
||||
set SStp [expr $newPara / 1000]
|
||||
set SStpHz [expr $newPara % 1000]
|
||||
set SCyc [hval $ns/SweepPar/SCyc]
|
||||
set data [format %02x%02x%02x%02x%02x%02x $SweepMode $SStr $SStp $SCyc $SStrHz $SStpHz]
|
||||
}
|
||||
"SSCyc" { set SweepMode [hval $ns/SweepPar/SweepMode]
|
||||
if {[string equal $SweepMode "OFF"]} {
|
||||
set SweepMode 0
|
||||
} elseif {[string equal $SweepMode "ON"} {
|
||||
set SweepMode 1
|
||||
} elseif {[string match "Without Changing" $SweepMode]} {
|
||||
set SweepMode 2
|
||||
} else {
|
||||
return -code error "Error in setValue: reading invaild SweepMode value."
|
||||
}
|
||||
set SStr [expr [hval $ns/SweepPar/StartFreq] / 1000]
|
||||
set SStrHz [expr [hval $ns/SweepPar/StartFreq] % 1000]
|
||||
set SStp [expr [hval $ns/SweepPar/StepFreq] / 1000]
|
||||
set SStpHz [expr [hval $ns/SweepPar/StepFreq] % 1000]
|
||||
set SCyc $newPara
|
||||
set data [format %02x%02x%02x%02x%02x%02x $SweepMode $SStr $SStp $SCyc $SStrHz $SStpHz]
|
||||
}
|
||||
default { return -code error "in setValue: Wrong setting field." }
|
||||
}
|
||||
set cmd [format %02s%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC]
|
||||
sct send "$cmd"
|
||||
} message ]} {
|
||||
return -code error "Error in setValue: $message. While sending command"
|
||||
}
|
||||
return $nextState
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# @brief Reads the value of a read-node typically following a query command sent to the device
|
||||
# rdValue is the default nextState for getValue() and setValue()
|
||||
# @param idx indicates which control loop or which input channel the command belongs to
|
||||
# @return idle Always returns system state idle - command sequence completed.
|
||||
|
||||
proc ::scobj::ag1010::rdValue {} {
|
||||
|
||||
variable CtrlShowLIMITS
|
||||
variable CtrlShowPAGC
|
||||
variable CtrlShowPMGC
|
||||
variable CtrlShowFREQ
|
||||
variable CtrlShowSKEY
|
||||
variable CtrlShowBurstPar
|
||||
variable CtrlShowSweepPar
|
||||
variable CtrlShowSVER
|
||||
variable CtrlShowMEAS
|
||||
variable CtrlShowSTA
|
||||
variable CtrlREJ
|
||||
|
||||
#set ns /sics/ag1010
|
||||
set ns [sct]
|
||||
if {[ catch {
|
||||
set data [string trim [sct result] " "]
|
||||
broadcast "Reading data in rdValue: $data"
|
||||
set ctrlCode [string range $data 4 5]
|
||||
|
||||
switch -glob $ctrlCode {
|
||||
|
||||
$CtrlREJ { return -code error "Error in rdValue()"
|
||||
}
|
||||
$CtrlShowLIMITS { set FPLH [string range $data 6 7]
|
||||
set FPLL [string range $data 8 9]
|
||||
set RPLH [string range $data 10 11]
|
||||
set RPLL [string range $data 12 13]
|
||||
|
||||
set $ns/limits/ForwardPower [expr 0x$FPLH$FPLL]
|
||||
set $ns/limits/ReversePower [expr 0x$RPLH$RPLL]
|
||||
}
|
||||
$CtrlShowPAGC { set AGCPoH [string range $data 6 7]
|
||||
set AGCPoL [string range $data 8 9]
|
||||
|
||||
set $ns/PAGC [expr 0x$AGCPoH$AGCPoL]
|
||||
}
|
||||
$CtrlShowPMGC { set MGCPoH [string range $data 6 7]
|
||||
set MGCPoL [string range $data 8 9]
|
||||
|
||||
set $ns/PMGC [expr 0x$MGCPoH$MGCPoL]
|
||||
}
|
||||
$CtrlShowFREQ { set FreqH [string range $data 6 7]
|
||||
set FreqL [string range $data 8 9]
|
||||
set FreqHzH [string range $data 10 11]
|
||||
set FreqHzL [string range $data 12 13]
|
||||
|
||||
set Freq [expr 0x$FreqH$FreqL]
|
||||
set FreqHz [expr 0x$FreqHzH$FreqHzL]
|
||||
set $ns/FREQ [expr $Freq * 1000 + $FreqHz]
|
||||
}
|
||||
$CtrlShowSKEY { set softKey 0x[string range $data 6 7]
|
||||
if {[expr $softKey & 0x80] == 0} {
|
||||
set $ns/SKEY/SoftOn "Off"
|
||||
} else {
|
||||
set $ns/SKEY/SoftOn "On"
|
||||
}
|
||||
if {[expr $softKey & 0x08] == 0} {
|
||||
set $ns/SKEY/Key0 "Off"
|
||||
} else {
|
||||
set $ns/SKEY/Key0 "On"
|
||||
}
|
||||
if {[expr $softKey & 0x04] == 0} {
|
||||
set $ns/SKEY/Key1 "Off"
|
||||
} else {
|
||||
set $ns/SKEY/Key1 "On"
|
||||
}
|
||||
if {[expr $softKey & 0x02] == 0} {
|
||||
set $ns/SKEY/Key2 "Off"
|
||||
} else {
|
||||
set $ns/SKEY/Key2 "On"
|
||||
}
|
||||
if {[expr $softKey & 0x01] == 0} {
|
||||
set $ns/SKEY/Key3 "Off"
|
||||
} else {
|
||||
set $ns/SKEY/Key3 "On"
|
||||
}
|
||||
}
|
||||
$CtrlShowBurstPar { set SCode [expr 0x[string range $data 6 7]]
|
||||
if {SCode == 0} {
|
||||
set $ns/BurstPar/BurstMode "OFF"
|
||||
} elseif {SCode == 1} {
|
||||
set $ns/BurstPar/BurstMode "Internal Mode ON"
|
||||
} elseif {SCode == 2} {
|
||||
set $ns/BurstPar/BurstMode "Change Burst Parameters Without Changing Burst On/Off"
|
||||
} elseif {SCode == 3} {
|
||||
set $ns/BurstPar/BurstMode "External Burst Mode Enable"
|
||||
}
|
||||
|
||||
set BRepTH [string range $data 8 9]
|
||||
set BRepTL [string range $data 10 11]
|
||||
set $ns/BurstPar/BRepTime [expr 0x$BRepTH$BRepTL]
|
||||
|
||||
set BOnTH [string range $data 12 13]
|
||||
set BOnTL [string range $data 14 15]
|
||||
set $ns/BurstPar/TimeOfPower [expr 0x$BOnTH$BOnTL]
|
||||
}
|
||||
$CtrlShowSweepPar { set SCode [expr 0x[string range $data 6 7]]
|
||||
if {SCode == 0} {
|
||||
set $ns/SweepPar/SweepMode "OFF"
|
||||
} elseif {SCode == 1} {
|
||||
set $ns/SweepPar/SweepMode "ON"
|
||||
} elseif {SCode == 2} {
|
||||
set $ns/SweepPar/SweepMode "Change Sweep Parameters Without Changing Sweep On/Off"
|
||||
}
|
||||
|
||||
set SStr [expr [string range $data 8 9]]
|
||||
set SStrHz [expr [string range $data 14 15]]
|
||||
set $ns/SweepPar/StartFreq [expr $SStr * 1000 + $SStrHz]
|
||||
|
||||
set SStp [expr [string range $data 10 11]]
|
||||
set SStpHz [expr [string range $data 16 17]]
|
||||
set $ns/SweepPar/StepFreq [expr $SStp * 1000 + $SStpHz]
|
||||
|
||||
set SCyc [expr [string range $data 12 13]]
|
||||
set $ns/SweepPar/SCyc $SCyc
|
||||
}
|
||||
$CtrlShowSVER { set SNH [string range $data 6 7]
|
||||
set SNL [string range $data 8 9]
|
||||
set $ns/SVER/SN "$SNH$SNL"
|
||||
|
||||
set SVerH [string range $data 10 11]
|
||||
set SVerL [string range $data 12 13]
|
||||
set $ns/SVER/SWVersion "$SVerH$SVerL"
|
||||
|
||||
set DVerH [string range $data 14 15]
|
||||
set DVerL [string range $data 16 17]
|
||||
set $ns/SVER/DeviceVersion "$DVerH$DVerL"
|
||||
}
|
||||
$CtrlShowMEAS { set FPH [string range $data 6 7]
|
||||
set FPL [string range $data 8 9]
|
||||
0t $ns/MEAS/ForwardPower [expr 0x$FPH$FPL]
|
||||
|
||||
set RPH [string range $data 10 11]
|
||||
set RPL [string range $data 12 13]
|
||||
set $ns/MEAS/ReversePower [expr 0x$RPH$RPL]
|
||||
|
||||
set TPH [string range $data 18 19]
|
||||
set TPL [string range $data 20 21]
|
||||
set $ns/MEAS/Temperature [expr 0x$TPH$TPL]
|
||||
}
|
||||
$CtrlShowSTA { set MainState [expr 0x[string range $data 6 7]]
|
||||
switch $MainState {
|
||||
"0" {set $ns/STA/MainState "Initialization"}
|
||||
"1" {set $ns/STA/MainState "Controller is in safe loop"}
|
||||
"2" {set $ns/STA/MainState "Controller is waiting for RFPowerOn Request in LocalMode"}
|
||||
"3" {set $ns/STA/MainState "Controller is waiting for confirm of RFPowerOn in LocalMode"}
|
||||
"4" {set $ns/STA/MainState "Controller is in main loop of the LocalMode"}
|
||||
"5" {set $ns/STA/MainState "Controller is waiting for RFPowerOn Request in RemoteMode"}
|
||||
"6" {set $ns/STA/MainState "Controller is waiting for confirm of RFPowerOn in RemoteMode"}
|
||||
"7" {set $ns/STA/MainState "Controller is in main loop of the RemoteMode"}
|
||||
}
|
||||
|
||||
set state [string range $data 8 9]
|
||||
if {[expr $state & 0x80] != 0} {
|
||||
set $ns/STA/State/FstRemote "RemoteMode"
|
||||
} else {
|
||||
set $ns/STA/State/FstRemote "LocalMode"
|
||||
}
|
||||
if {[expr $state & 0x40] != 0} {
|
||||
set $ns/STA/State/FStExtBurst "External Burst mode ON"
|
||||
} else {
|
||||
set $ns/STA/State/FStExtBurst "External Burst mode OFF"
|
||||
}
|
||||
if {[expr $state & 0x20] != 0} {
|
||||
set $ns/STA/State/FStRFError "RFError Detected"
|
||||
} else {
|
||||
set $ns/STA/State/FStRFError "RFError Not Detected"
|
||||
}
|
||||
if {[expr $state & 0x10] != 0} {
|
||||
set $ns/STA/State/FStSafetyLP "Error of the Safety Loop Detected"
|
||||
} else {
|
||||
set $ns/STA/State/FStSafetyLP "Error of the Safety Loop Not Detected"
|
||||
}
|
||||
if {[expr $state & 0x04] != 0} {
|
||||
set $ns/STA/State/FStExceedRP "Limited of the ReversePower Detected"
|
||||
} else {
|
||||
set $ns/STA/State/FStExceedRP "Limited of the ReversePower Not Detected"
|
||||
}
|
||||
if {[expr $state & 0x02] != 0} {
|
||||
set $ns/STA/State/FStExceedFP "Limited of the ForwardPower Detected"
|
||||
} else {
|
||||
set $ns/STA/State/FStExceedFP "Limited of the ForwardPower Not Detected"
|
||||
}
|
||||
if {[expr $state & 0x01] != 0} {
|
||||
set $ns/STA/State/FStExceedTmp "Temperature Error Detected"
|
||||
} else {
|
||||
set $ns/STA/State/FStExceedTmp "Temperature Error Not Detected"
|
||||
}
|
||||
|
||||
set KeyState [string range $data 10 11]
|
||||
if {[expr $KeyState & 0x80] != 0} {
|
||||
set $ns/STA/keyState/SoftOn "Host takes over the keyboard of controller"
|
||||
} else {
|
||||
set $ns/STA/keyState/SoftOn "Controller takes over the keyboard of controller"
|
||||
}
|
||||
if {[expr $KeyState & 0x08] != 0} {
|
||||
set $ns/STA/keyState/Key1 "On"
|
||||
} else {
|
||||
set $ns/STA/keyState/Key1 "Off"
|
||||
}
|
||||
if {[expr $KeyState & 0x04] != 0} {
|
||||
set $ns/STA/keyState/Key0 "On"
|
||||
} else {
|
||||
set $ns/STA/keyState/Key0 "Off"
|
||||
}
|
||||
if {[expr $KeyState & 0x02] != 0} {
|
||||
set $ns/STA/keyState/Key2 "On"
|
||||
} else {
|
||||
set $ns/STA/keyState/Key2 "Off"
|
||||
}
|
||||
if {[expr $KeyState & 0x01] != 0} {
|
||||
set $ns/STA/keyState/Key3 "On"
|
||||
} else {
|
||||
set $ns/STA/keyState/Key3 "Off"
|
||||
}
|
||||
}
|
||||
default { return -code error "Unexpected returned values from the device in rdValue()" }
|
||||
}
|
||||
} message ]} {
|
||||
return -code error "Error in rdValue: $message."
|
||||
}
|
||||
return idle
|
||||
}
|
||||
|
||||
|
||||
# function names provided
|
||||
# @param scobj_hpath string variable holding the path to the object's base node in sics (/sample/tc1)
|
||||
# @param sct_controller name of the ag1010 scriptcontext object (typically sct_ag1010)
|
||||
# @param cmdGroup subdirectory (below /sample/tc*/) in which the node is to be created
|
||||
# @param varName name of the actual node typically representing one device command
|
||||
# @param readable set to 1 if the node represents a query command, 0 if it is not
|
||||
# @param writable set to 1 if the node represents a request for a change in settings sent to the device
|
||||
# @param pollEnabled set to 1 if the node property pollable is to be enabled (node gets read every 5 secs)
|
||||
# @param dataType data type of the node, must be one of none, int, float, text
|
||||
# @param unit data units, e.g. m, cm, mm, degree, Hz, W, dW and etc
|
||||
# @param permission defines what user group may read/write to this node (is one of spy, user, manager)
|
||||
# @param rdPara actual device query command to be sent to the device
|
||||
# @param rdFunc nextState Function to be called after the getValue function, typically rdValue()
|
||||
# Praparam wrPara actual device write command to be sent to the device
|
||||
# @param wrFunc Function to be called to send the wrPara to the device, typically setValue()
|
||||
# @param allowedValues allowed values for the node data - does not permit other
|
||||
# @return OK
|
||||
proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable pollEnabled displayable \
|
||||
dataType unit permission rdPara rdFunc wrPara allowedValues} {
|
||||
# It is a command that is supported by the device
|
||||
if { [catch {
|
||||
set parentnode "ag1010"
|
||||
set ns ::scobj::$parentnode
|
||||
set basepath $scobj_hpath/$parentnode
|
||||
if {2 < [string length $cmdGroup]} {
|
||||
set nodeName "$basepath/$cmdGroup/$varName"
|
||||
} else {
|
||||
set nodeName "$basepath/$varName"
|
||||
}
|
||||
hfactory $nodeName plain $permission $dataType
|
||||
switch $dataType {
|
||||
"none" {hset $nodeName none}
|
||||
"text" {hset $nodeName UNKNOWN}
|
||||
"int" {hset $nodeName 0}
|
||||
"float" {hset $nodeName 0.0}
|
||||
default {hset $nodeName UNKNOWN}
|
||||
}
|
||||
if {$readable == 1} {
|
||||
hsetprop $nodeName read ${ns}::getValue $scobj_hpath $rdFunc $rdPara
|
||||
hsetprop $nodeName $rdFunc ${ns}::$rdFunc
|
||||
if {$pollEnabled == 1} {
|
||||
#if {[SplitReply [environment_simulation]]=="false"} {
|
||||
$sct_controller poll $nodeName
|
||||
#}
|
||||
}
|
||||
}
|
||||
if {$writable == 1} {
|
||||
hsetprop $nodeName write ${ns}::setValue $scobj_hpath $rdFunc $rdPara $wrPara
|
||||
hsetprop $nodeName $rdFunc ${ns}::$rdFunc
|
||||
if {$pollEnabled == 1} {
|
||||
#if {[SplitReply [environment_simulation]]=="false"} {
|
||||
$sct_controller write $nodeName
|
||||
#}
|
||||
}
|
||||
}
|
||||
if {1 < [string length $unit]} {
|
||||
hsetprop $nodeName units $unit
|
||||
}
|
||||
if {1 < [string length $allowedValues]} {
|
||||
hsetprop $nodeName values $allowedValues
|
||||
}
|
||||
if {$displayable == 1} {
|
||||
if {2 < [string length $cmdGroup]} {
|
||||
::scobj::hinitprops $parentnode $cmdGroup/$varName
|
||||
} else {
|
||||
::scobj::hinitprops $parentnode $varName
|
||||
}
|
||||
}
|
||||
} message ]} {
|
||||
return -code error "Error in createNode $message"
|
||||
}
|
||||
return OK
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# @brief mkAG creates a scriptcontext object for T&C AG1010 Amplifier/generator
|
||||
# #para argList configurable parameters from function call
|
||||
# @return nothing (well, the sct object)
|
||||
|
||||
proc ::scobj::ag1010::mkAG {argList} {
|
||||
if {[catch {
|
||||
|
||||
# Generate parameter array from the argument list
|
||||
foreach {k v} $argList {
|
||||
set KEY [string toupper $k]
|
||||
set pa($KEY) $v
|
||||
}
|
||||
|
||||
MakeSICSObj $pa(NAME) SCT_OBJECT
|
||||
sicslist setatt $pa(NAME) klass instrument
|
||||
sicslist setatt $pa(NAME) long_name $pa(NAME)
|
||||
|
||||
# Create a base node for all the state machines of this sics object
|
||||
#set scobj_hpath /sics/$pa(NAME)
|
||||
set scobj_hpath /sics
|
||||
|
||||
#makesctcontroller sct_ag1010 rfamp $pa(IP):$pa(PORT)
|
||||
makesctcontroller sct_$pa(NAME) lfgen $pa(IP):$pa(PORT)
|
||||
|
||||
# Create state machines for the following device commands
|
||||
# Note that drivable nodes require the index of the control loop in their call to halt()
|
||||
# Nodes appear in gumtree in the order in which they are created here.
|
||||
#
|
||||
# Initialise the model-dependent list of supported device commands
|
||||
# RdWrPlDrIdx
|
||||
# cmdGroup subdirectory in which the node is to be created, "P" means under top-parent node
|
||||
# varName name of the actual node typically representing one device command
|
||||
# readable set to 1 if the node represents a query command, 0 if it is not
|
||||
# writable set to 1 if the node represents a request for a change in settings sent to the device
|
||||
# pollEnabled set to 1 if the node property pollable is to be enabled (node gets read every 5 secs)
|
||||
# displayable set to 1 if the node to be displayed on Gumtree GUI, 0 if it is not
|
||||
# dataType data type of the node, must be one of none, int, float, text
|
||||
# unit data units, e.g. m, cm, mm, degree, Hz, W, dW and etc
|
||||
# permission defines what user group may read/write to this node (is one of spy, user, manager)
|
||||
# rdPara parameters LEN and CTRL to be sent to the device
|
||||
# rdFunc nextState Function to be called after the getValue function, typically rdValue()
|
||||
# wrPara actual device field in write command to be sent to the device
|
||||
# allowedValues allowed values for the node data - does not permit other
|
||||
set deviceCommandToplevel {
|
||||
P limits 1 0 1 1 none {} user {2 18} {rdValue} {} {}
|
||||
limits ForwardPower 0 0 0 1 int {dW} user {} {} {} {}
|
||||
limits ReversePower 0 0 0 1 int {dW} user {} {} {} {}
|
||||
P PAGC 1 0 1 1 int {dW} user {2 19} {rdValue} {} {}
|
||||
P PMGC 1 0 1 1 int {dW} user {2 20} {rdValue} {} {}
|
||||
P FREQ 1 0 1 1 int {Hz} user {2 21} {rdValue} {} {}
|
||||
P SKEY 1 0 1 1 int {} user {3 23} {rdValue} {} {}
|
||||
SKEY SoftOn 0 0 0 1 text {} user {} {} {} {}
|
||||
SKEY Key1 0 0 0 1 int {} user {} {} {} {}
|
||||
SKEY Key0 0 0 0 1 int {} user {} {} {} {}
|
||||
SKEY Key2 0 0 0 1 int {} user {} {} {} {}
|
||||
SKEY Key3 0 0 0 1 int {} user {} {} {} {}
|
||||
P BurstPar 1 0 1 1 none {} user {2 24} {rdValue} {} {}
|
||||
BurstPar BurstMode 0 0 0 1 int {} user {} {} {} {}
|
||||
BurstPar BRepTime 0 0 0 1 int {ms} user {} {} {} {}
|
||||
BurstPar TimeOfPower 0 0 0 1 int {us} user {} {} {} {}
|
||||
P SweepPar 1 0 1 1 none {} user {2 25} {rdValue} {} {}
|
||||
SweepPar SweepMode 0 0 0 1 text {} user {} {} {} {}
|
||||
SweepPar StartFreq 0 0 0 1 int {Hz} user {} {} {} {}
|
||||
SweepPar StepFreq 0 0 0 1 int {Hz} user {} {} {} {}
|
||||
SweepPar SCyc 0 0 0 1 int {} user {} {} {} {}
|
||||
P SVER 1 0 1 1 none {} user {2 29} {rdValue} {} {}
|
||||
SVER SN 0 0 0 1 text {} user {} {} {} {}
|
||||
SVER SWVersion 0 0 0 1 text {} user {} {} {} {}
|
||||
SVER DeviceVersion 0 0 0 1 text {} user {} {} {} {}
|
||||
P MEAS 1 0 1 1 none {} user {2 30} {rdValue} {} {}
|
||||
MEAS ForwardPower 0 0 0 1 int {dW} user {} {} {} {}
|
||||
MEAS ReversePower 0 0 0 1 int {dW} user {} {} {} {}
|
||||
MEAS Temperature 0 0 0 1 int {0C} user {} {} {} {}
|
||||
P STA 1 0 1 1 none {} user {2 31} {rdValue} {} {}
|
||||
STA MainState 0 0 0 1 text {} user {} {} {} {}
|
||||
STA State 0 0 0 1 int {} user {} {} {} {}
|
||||
STA/State FstRemote 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStExtBurst 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStRFError 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStSafetyLP 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStExceedRP 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStExceedFP 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/State FStExceedTmp 0 0 0 1 text {} user {} {} {} {}
|
||||
STA keyState 0 0 0 1 int {} user {} {} {} {}
|
||||
STA/keyState SoftOn 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/keyState Key1 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/keyState Key0 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/keyState Key2 0 0 0 1 text {} user {} {} {} {}
|
||||
STA/keyState Key3 0 0 0 1 text {} user {} {} {} {}
|
||||
|
||||
P responseMsg 0 0 0 1 text {} user {2 42} {} {} {}
|
||||
|
||||
P SetLimitsFPL 0 1 1 1 int {dW} user {10 2} {rdValue} {FPL} {}
|
||||
P SetLimitsRPL 0 1 1 1 int {dW} user {10 2} {rdValue} {RPL} {}
|
||||
P SetPAGC 0 1 1 1 int {dW} user {4 3} {rdValue} {PAGC} {}
|
||||
P SetPMGC 0 1 1 1 int {dW} user {4 4} {rdValue} {PMGC} {}
|
||||
P SetFREQ 0 1 1 1 int {Hz} user {6 5} {rdValue} {FREQ} {}
|
||||
P SetSKEY 0 0 0 1 int {} user {} {} {} {}
|
||||
SetSKEY SoftOn 0 1 1 1 int {} user {3 7} {rdValue} {SoftOn} {1,0}
|
||||
SetSKEY Key1 0 1 1 1 int {} user {3 7} {rdValue} {Key1} {1,0}
|
||||
SetSKEY Key0 0 1 1 1 int {} user {3 7} {rdValue} {Key0} {1,0}
|
||||
SetSKEY Key2 0 1 1 1 int {} user {3 7} {rdValue} {Key2} {1,0}
|
||||
SetSKEY Key3 0 1 1 1 int {} user {3 7} {rdValue} {Key3} {1,0}
|
||||
P SetBurstMode 0 1 1 1 int {} user {7 8} {rdValue} {BurstMode} {0,1,2,3}
|
||||
P SetBRepTime 0 1 1 1 int {ms} user {7 8} {rdValue} {BRepTime} {}
|
||||
P SetBTimeOfPower 0 1 1 1 int {us} user {7 8} {rdValue} {BTofP} {}
|
||||
P SetSweepMode 0 1 1 1 int {} user {13 9} {rdValue} {SweepMode} {0,1,2}
|
||||
P SetSStartFreq 0 1 1 1 int {Hz} user {13 9} {rdValue} {SStrF} {}
|
||||
P SetSStepFreq 0 1 1 1 int {Hz} user {13 9} {rdValue} {SSteF} {}
|
||||
P SetSSCyc 0 1 1 1 int {} user {13 9} {rdValue} {SSCyc} {}
|
||||
}
|
||||
|
||||
foreach {cmdGroup varName readable writable pollEnabled displayable dataType unit permission rdPara rdFunc wrPara allowedValues} \
|
||||
$deviceCommandToplevel {
|
||||
|
||||
createNode $scobj_hpath sct_$pa(NAME) $cmdGroup $varName $readable $writable $pollEnabled $displayable $dataType $unit $permission $rdPara $rdFunc $wrPara $allowedValues
|
||||
}
|
||||
} message ]} {
|
||||
return -code error "Error in ::scobj::ag1010::mkAG $message"
|
||||
}
|
||||
}
|
||||
# end of namespace ::scobj::ag1010::mkAG
|
||||
|
||||
# Main process call
|
||||
# @param name short name for the AG1010 Amplifier/Generator
|
||||
# @param IP IP address of the device (e.g. IP of moxabox that hooks up to the AG1010)
|
||||
# @param port port number on the moxabox (typ. 4001, 4002, 4003, or 4004)
|
||||
# @param turning if the parameter is turnable and can be set from the Gumtree
|
||||
# @internal time internal in polling the nodes
|
||||
|
||||
# IP 137.157.202.215
|
||||
::scobj::ag1010::mkAG {
|
||||
name "ag1010"
|
||||
IP localhost
|
||||
PORT 50001
|
||||
tuning 1
|
||||
interval 5
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user