introduce "device confirmed" when device is plugged

This commit is contained in:
l_samenv
2023-09-14 10:58:52 +02:00
parent 298ba9e030
commit 62f4f08d5f
3 changed files with 69 additions and 35 deletions

View File

@ -1040,6 +1040,7 @@ proc samenv args {
set inside_samenv 0
}
set device_name none
device makeitem confirmed ""
restore killerr
save_samenv none
return "samenv = none"
@ -1150,6 +1151,10 @@ proc samenv args {
default load
device name $name
if {$name ne [silent 0 hval /device/confirmed]} {
device makeitem confirmed ""
}
obj_list savefile ""
if { [string length $objects_created] != 0 } {
clientput "create: $objects_created"
@ -1706,6 +1711,7 @@ proc autodeviceCron {} {
}
device action ""
} elseif {$act eq "rebuild"} {
# rebuild SECoP objects after description change
device action ""
set objdict [dict create]
foreach obj [obj_list items] {
@ -1756,24 +1762,33 @@ clientput "CONFIG $device/$stick/$addons"
set unplugged_device [result device name]
if {$unplugged_device ne "none"} {
clientput "unplugged $unplugged_device"
device makeitem confirmed ""
set change_device_to_none [expr $now + 60]
}
} else {
clientput "none $act"
device makeitem confirmed none
samenv -q none
}
} elseif {$act eq "plugged" && $new eq [result device name]} {
clientput "$new plugged, no change"
device makeitem confirmed $new
} else {
clientput "$new $act"
catch {samenv -q $new} msg
clientput $msg
if {[result device name] ne "none" && $act eq "plugged"} {
clientlog "unplugged time too short [result device name] -> $new"
} else {
device makeitem confirmed $new
clientput "LOAD $new $act"
catch {samenv -q $new} msg
clientput $msg
}
}
device action ""
} else {
set c2n [silent 0 set change_device_to_none]
if {$c2n != 0 && $now > $c2n} {
set change_device_to_none 0
device makeitem confirmed none
samenv -q none
}
if {![device exists force_status_save]} {

View File

@ -143,7 +143,7 @@ if {$instrument eq "seaman"} {
restore $statusfile
backup
array_init device name unknown changetime 0 stick_menu {} stick_name {} newdevice {} olddevice {} rack {}
array_init device name unknown changetime 0 stick_menu {} stick_name {} newdevice {} olddevice {} rack {} confirmed {}
array_init device frappy_u_config 0 frappy_u_stick 0 frappy_u_addon 0 frappy_main {} frappy_stick {} frappy_addons {}
connect_sics

View File

@ -177,10 +177,12 @@ proc get_param_values {hp} {
}
proc check_or_do {doit service cfgs} {
# result: 1: no change needed, 0: change needed, 2: failure
set result 1
set config ""
set stick ""
set addons [list]
foreach cfg $cfgs {
if {[regexp {(.*)\.addon} $cfg -> addon]} {
if {![addon_list exists $addon]} {
@ -195,10 +197,20 @@ proc check_or_do {doit service cfgs} {
device makeitem frappy_u_config 1
if {$config ne [hval /device/name]} {
if {$doit} {
if {[hval /device/confirmed] eq [hval /device/name]} {
set msg "do not allow frappy to change from [hval /device/name] to $config"
clientlog $msg
return $msg
}
clientlog 0
clientlog TRANSACTIONFINISHED
samenv -q $config
} else {
device makeitem frappy_u_config 0
}
if {[hval /device/name] == "none"} {
return none
}
set result 0
}
}
@ -206,15 +218,22 @@ proc check_or_do {doit service cfgs} {
device makeitem frappy_u_stick 1
if {$stick ne [hval /device/stick_name]} {
if {$doit} {
clientlog 0
clientlog TRANSACTIONFINISHED
addon stick $stick
} else {
device makeitem frappy_u_stick 0
}
if {[hval /device/name] == "none"} {
return nonestick
}
set result 0
}
}
foreach addon $addons {
if {$doit} {
clientlog 0
clientlog TRANSACTIONFINISHED
addon $addon
} else {
device makeitem frappy_u_addon 0