r3695 | jgn | 2012-08-07 16:27:59 +1000 (Tue, 07 Aug 2012) | 1 line

This commit is contained in:
Jing Chen
2012-08-07 16:27:59 +10:00
committed by Douglas Clowes
parent 15fdda1deb
commit aaa10b5cf1

View File

@@ -36,6 +36,13 @@ namespace eval ::scobj::ag1010 {
variable CtrlGetSVER [format %02x 29] variable CtrlGetSVER [format %02x 29]
variable CtrlGetMEAS [format %02x 30] variable CtrlGetMEAS [format %02x 30]
variable CtrlGetSTA [format %02x 31] variable CtrlGetSTA [format %02x 31]
variable ForPowerLimit 10040
variable RefPowerLimit 1630
variable FreqUpLimit 2000000
variable FreqDownLimit 0.02
namespace export par
} }
@@ -57,7 +64,7 @@ proc ::scobj::ag1010::getValue {tc_root nextState rdPara} {
set CRC 0 set CRC 0
if {$LEN < 2} { if {$LEN < 2} {
return -code error "Error in getValue: wrong data length provided." return -code error "Error in LF AG1010 Setting: wrong data length provided."
} elseif {$LEN > 2} { } elseif {$LEN > 2} {
set cmd [format %02x%02x%02x%02x%02x $HEAD $LEN $CTRL $DATA $CRC] set cmd [format %02x%02x%02x%02x%02x $HEAD $LEN $CTRL $DATA $CRC]
} else { } else {
@@ -65,7 +72,7 @@ proc ::scobj::ag1010::getValue {tc_root nextState rdPara} {
} }
sct send "$cmd" sct send "$cmd"
} message ]} { } message ]} {
return -code error "Error in getValue: $message." return -code error "Error in LF AG1010 Setting: $message."
} }
return $nextState return $nextState
} }
@@ -82,6 +89,11 @@ 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 # 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 # same calling mask as for setPoint() or other $wrFunc
variable ForPowerLimit
variable RefPowerLimit
variable FreqUpLimit
variable FreqDownLimit
set ns /sics/ag1010 set ns /sics/ag1010
#set ns [sct] #set ns [sct]
if {[ catch { if {[ catch {
@@ -92,18 +104,33 @@ proc ::scobj::ag1010::setValue {tc_root nextState rdPara wrPara} {
set newPara [string trim [sct target] " "] set newPara [string trim [sct target] " "]
switch -exact $wrPara { switch -exact $wrPara {
"FPL" { set RPL [hval $ns/limits/ReversePower] "FPL" { if {$newPara > $ForPowerLimit || $newPara < 0} {
broadcast "Error: The Limit for the Forward Power is 0~$ForPowerLimit dW"
return idle
} else {
set RPL [hval $ns/limits/ReversePower]
set data [format %04x%04x%04x%04x $newPara $RPL 0 0] set data [format %04x%04x%04x%04x $newPara $RPL 0 0]
} }
"RPL" { set FPL [hval $ns/limits/ForwardPower] }
"RPL" { if {$newPara > $RefPowerLimit || $newPara < 0} {
broadcast "Error: The Limit for the Reverse Power is 0~$RefPowerLimit dW"
return idle
} else {
set FPL [hval $ns/limits/ForwardPower]
set data [format %04x%04x%04x%04x $FPL $newPara 0 0] set data [format %04x%04x%04x%04x $FPL $newPara 0 0]
} }
}
"PAGC" { set data [format %04x $newPara] } "PAGC" { set data [format %04x $newPara] }
"PMGC" { set data [format %04x $newPara] } "PMGC" { set data [format %04x $newPara] }
"FREQ" { set Freq [expr $newPara / 1000] "FREQ" { if {$newPara<$FreqDownLimit || $newPara>$FreqUpLimit} {
broadcast "Error: Freqence shall be set between $FreqDownLimit Hz and $FreqUpLimit Hz"
return idle
} else {
set Freq [expr $newPara / 1000]
set FreqHz [expr $newPara % 1000] set FreqHz [expr $newPara % 1000]
set data [format %04x%04x $Freq $FreqHz] set data [format %04x%04x $Freq $FreqHz]
} }
}
"SoftOn" { "SoftOn" {
if {$newPara > 1 || $newPara < 0} { if {$newPara > 1 || $newPara < 0} {
return -code error "Error in setValue: only allowed input values for SoftKey are {0,1}." return -code error "Error in setValue: only allowed input values for SoftKey are {0,1}."
@@ -345,14 +372,20 @@ proc ::scobj::ag1010::rdValue {} {
#set ns [sct] #set ns [sct]
if {[ catch { if {[ catch {
set data [string trim [sct result] " "] set data [string trim [sct result] " "]
broadcast $data
hset $ns/responseMsg "$data"
#broadcast "rdValue : $data"
if {[string first "failed" $data] != -1} { if {[string first "failed" $data] != -1} {
broadcast "Error in rdValue: $data" broadcast "Error in LF AG1010 Response: $data"
return -code error "$data"
} elseif {[string first "read timeout" $data] != -1} {
broadcast "Error in LF AG1010 Response: $data"
return -code error "$data" return -code error "$data"
} elseif {[string length $data] < 1} { } elseif {[string length $data] < 1} {
broadcast "Error in rdValue: no message returned from device" broadcast "Error in LF AG1010 Response: no message returned from device"
return -code error "Error in rdValue: no message returned from device" return -code error "Error in LF AG1010 Response: no message returned from device"
} }
set ctrlCode [format %d 0x[string range $data 4 5]] set ctrlCode [format %d 0x[string range $data 4 5]]
switch -glob $ctrlCode { switch -glob $ctrlCode {
@@ -382,8 +415,7 @@ proc ::scobj::ag1010::rdValue {} {
set FreqHz [format %d [expr 0x$FreqHzH$FreqHzL]] set FreqHz [format %d [expr 0x$FreqHzH$FreqHzL]]
hset $ns/FRE/FREQ [expr $Freq * 1000 + $FreqHz] hset $ns/FRE/FREQ [expr $Freq * 1000 + $FreqHz]
} }
7 { 7 { set softKey 0x[string range $data 6 7]
set softKey 0x[string range $data 6 7]
if {[expr $softKey & 0x80] == 0} { if {[expr $softKey & 0x80] == 0} {
hset $ns/SKEY/SoftOn "Controller takes over the keyboard of controller" hset $ns/SKEY/SoftOn "Controller takes over the keyboard of controller"
} else { } else {
@@ -461,8 +493,7 @@ proc ::scobj::ag1010::rdValue {} {
set DVerL [string range $data 16 17] set DVerL [string range $data 16 17]
hset $ns/SVER/DeviceVersion "$DVerH$DVerL" hset $ns/SVER/DeviceVersion "$DVerH$DVerL"
} }
14 { 14 { set FPH [string range $data 6 7]
set FPH [string range $data 6 7]
set FPL [string range $data 8 9] set FPL [string range $data 8 9]
hset $ns/MEAS/ForwardPower [format %d [expr 0x$FPH$FPL]] hset $ns/MEAS/ForwardPower [format %d [expr 0x$FPH$FPL]]
@@ -600,18 +631,18 @@ proc createNode {scobj_hpath sct_controller cmdGroup varName readable writable p
hsetprop $nodeName read ${ns}::getValue $scobj_hpath $rdFunc $rdPara hsetprop $nodeName read ${ns}::getValue $scobj_hpath $rdFunc $rdPara
hsetprop $nodeName $rdFunc ${ns}::$rdFunc hsetprop $nodeName $rdFunc ${ns}::$rdFunc
if {$pollEnabled == 1} { if {$pollEnabled == 1} {
#if {[SplitReply [environment_simulation]]=="false"} { if {[SplitReply [environment_simulation]]=="false"} {
$sct_controller poll $nodeName $sct_controller poll $nodeName
#} }
} }
} }
if {$writable == 1} { if {$writable == 1} {
hsetprop $nodeName write ${ns}::setValue $scobj_hpath $rdFunc $rdPara $wrPara hsetprop $nodeName write ${ns}::setValue $scobj_hpath $rdFunc $rdPara $wrPara
hsetprop $nodeName $rdFunc ${ns}::$rdFunc hsetprop $nodeName $rdFunc ${ns}::$rdFunc
if {$pollEnabled == 1} { if {$pollEnabled == 1} {
#if {[SplitReply [environment_simulation]]=="false"} { if {[SplitReply [environment_simulation]]=="false"} {
$sct_controller write $nodeName $sct_controller write $nodeName
#} }
} }
} }
if {1 < [string length $unit]} { if {1 < [string length $unit]} {
@@ -657,6 +688,7 @@ proc ::scobj::ag1010::mkAG {argList} {
set scobj_hpath /sics set scobj_hpath /sics
#makesctcontroller sct_ag1010 rfamp $pa(IP):$pa(PORT) #makesctcontroller sct_ag1010 rfamp $pa(IP):$pa(PORT)
#makesctcontroller sct_$pa(NAME) std $pa(IP):$pa(PORT)
makesctcontroller sct_$pa(NAME) lfgen $pa(IP):$pa(PORT) makesctcontroller sct_$pa(NAME) lfgen $pa(IP):$pa(PORT)
######################################################################################################### #########################################################################################################
@@ -733,7 +765,7 @@ proc ::scobj::ag1010::mkAG {argList} {
STA/keyState Key2 0 0 0 1 text {} user {} {} {} {} STA/keyState Key2 0 0 0 1 text {} user {} {} {} {}
STA/keyState Key3 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 responseMsg 0 0 0 1 text {} spy {2 42} {} {} {}
P SetLimitsFPL 0 1 1 1 int {dW} user {10 2} {rdValue} {FPL} {} 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 SetLimitsRPL 0 1 1 1 int {dW} user {10 2} {rdValue} {RPL} {}
@@ -767,6 +799,8 @@ proc ::scobj::ag1010::mkAG {argList} {
# SICS commands # SICS commands
namespace import ::scobj::ag1010::par
proc LFSetLimitsFPL {para} { proc LFSetLimitsFPL {para} {
set HEAD 0x96 set HEAD 0x96
@@ -777,13 +811,17 @@ proc LFSetLimitsFPL {para} {
set ns /sics/ag1010 set ns /sics/ag1010
set newPara [string trim $para " "] set newPara [string trim $para " "]
if {$para > 10040 || $para < 0} {
broadcast "Error: The Limit for the Forward Power is 0~10040 dW"
} else {
set RPL [hval $ns/limits/ReversePower] set RPL [hval $ns/limits/ReversePower]
set data [format %04x%04x%04x%04x $newPara $RPL 0 0] set data [format %04x%04x%04x%04x $newPara $RPL 0 0]
set cmdi [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC]
broadcast "Set Forward Power Limits to $newPara dW" broadcast "Set Forward Power Limits to $newPara dW"
sct_ag1010 send "$cmd" sct_ag1010 send "$cmd"
} }
}
proc LFSetLimitsRPL {para} { proc LFSetLimitsRPL {para} {
@@ -795,6 +833,9 @@ proc LFSetLimitsRPL {para} {
set ns /sics/ag1010 set ns /sics/ag1010
set newPara [string trim $para " "] set newPara [string trim $para " "]
if {$para > 1630 || $para < 0} {
broadcast "Error: The Limit for the Reflected Power is 0~1630 dW"
} else {
set FPL [hval $ns/limits/ForwardPower] set FPL [hval $ns/limits/ForwardPower]
set data [format %04x%04x%04x%04x $FPL $newPara 0 0] set data [format %04x%04x%04x%04x $FPL $newPara 0 0]
set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC] set cmd [format %02x%02x%02x%s%02x $HEAD $LEN $CTRL $data $CRC]
@@ -802,6 +843,7 @@ proc LFSetLimitsRPL {para} {
broadcast "Set Reverse Power Limits to $newPara dW" broadcast "Set Reverse Power Limits to $newPara dW"
sct_ag1010 send "$cmd" sct_ag1010 send "$cmd"
} }
}
proc LFSetPAGC {para} { proc LFSetPAGC {para} {
@@ -847,6 +889,9 @@ proc LFSetFREQ {para} {
set ns /sics/ag1010 set ns /sics/ag1010
set newPara [string trim $para " "] set newPara [string trim $para " "]
if {$para < 0.02 || $para > 2000000} {
broadcast "Error: Freqence shall be set between 0.02 Hz and 2 MHz"
} else {
set Freq [expr $newPara / 1000] set Freq [expr $newPara / 1000]
set FreqHz [expr $newPara % 1000] set FreqHz [expr $newPara % 1000]
set data [format %04x%04x $Freq $FreqHz] set data [format %04x%04x $Freq $FreqHz]
@@ -855,6 +900,7 @@ proc LFSetFREQ {para} {
broadcast "Set Frequency to $newPara Hz" broadcast "Set Frequency to $newPara Hz"
sct_ag1010 send "$cmd" sct_ag1010 send "$cmd"
} }
}
proc LFSetBurstMode {para} { proc LFSetBurstMode {para} {
@@ -1129,8 +1175,8 @@ publish LFGetMEAS user
# IP 137.157.202.219 # IP 137.157.202.219
::scobj::ag1010::mkAG { ::scobj::ag1010::mkAG {
name "ag1010" name "ag1010"
IP localhost IP 137.157.202.219
PORT 50001 PORT 4001
tuning 1 tuning 1
interval 5 interval 5
} }