From c3ee26120002d2f3d828310a67c42fcfffb43428 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Wed, 12 Oct 2022 18:01:41 +0200 Subject: [PATCH] write a couple of helper functions, add voltage settings file --- scripts/MDC.pm | 4 +- scripts/MDCPower.pm | 83 +++++++ scripts/README.md | 16 +- scripts/mdc_powerboard.pl | 1 + settings_power/settings_voltage.db | 374 +++++++++++++++++++++++++++++ 5 files changed, 468 insertions(+), 10 deletions(-) create mode 100644 scripts/MDCPower.pm create mode 120000 scripts/mdc_powerboard.pl diff --git a/scripts/MDC.pm b/scripts/MDC.pm index 40d401e..37c2217 100644 --- a/scripts/MDC.pm +++ b/scripts/MDC.pm @@ -49,10 +49,10 @@ sub get_position { } ############################################################################### -#get the correct power channel for board with (address). +#get the correct power output for MBO with (address). #returns (hostname,board,output) ############################################################################### -sub get_power_channel { +sub get_power_output { my $addr = shift @_; my ($p,$s,$b,$e) = get_position($addr); my $id=-1; diff --git a/scripts/MDCPower.pm b/scripts/MDCPower.pm new file mode 100644 index 0000000..f2d761a --- /dev/null +++ b/scripts/MDCPower.pm @@ -0,0 +1,83 @@ +package MDCPower; + +use warnings; +no warnings "portable"; +use FileHandle; +use Data::Dumper; +use lib '.'; +use MDC; + + + + +############################################################################### +#set the voltage for a given board and channel. +#specify if setting should be saved to config file +############################################################################### +sub set_voltage { + my ($addr,$channel,$setting,$save) = @_; + return -1 unless $addr >= 0x8e00 && $addr <= 0x8fff + && $channel >= 0 && $channel <= 1 + && $setting >= 0 && $setting <= 7; + + + my ($host,$board,$outp) = MDC::get_power_output($addr); + return -2 unless defined $host && $board >= 0 && $outp >= 0; + + system("./mdc_powerboard.pl -d $host -b $board -o $outp -c $channel -r adjust -v $setting"); + + store_voltage($addr,$channel,$setting) if $save; + return 1; + } + + +############################################################################### +#saves the voltage for a given board and channel +############################################################################### +sub store_voltage { + my ($addr,$channel,$setting) = @_; + } + +############################################################################### +#get the voltage setting for a given board (from file) +#returns (channel1, channel2) +############################################################################### +sub get_voltage { + my ($addr) = @_; + my $v1 = -1; + my $v2 = -1; + + open FILE, "../settings_power/settings_voltage.db" or die $!."\nsettings_voltage.db not found."; + while (my $a = ) { + if(my @values = $a =~ /^\s*0x(\w\w\w\w)\s+(\d)\s+(\d)/) { + my $board = $values[0]; + if (hex($board) == $addr) { + $v1 = $values[1]; + $v2 = $values[2]; + last; + } + } + } + close FILE; + return ($v1,$v2); + } + +############################################################################### +#switch on/off a specified board +#onoff=2 does a quick power cycle +############################################################################### +sub power_switch { + my ($addr,$onoff) = @_; + + my ($host,$board,$outp) = MDC::get_power_output($addr); + return -1 unless defined $host && $board >= 0 && $outp >= 0; + + + system("./mdc_powerboard.pl -d $host -b $board -o $outp -r switch -v 0") if($onoff == 0 || $onoff == 2); + sleep(1) if($onoff == 2); + system("./mdc_powerboard.pl -d $host -b $board -o $outp -r switch -v 1") if($onoff == 1 || $onoff == 2); + return 1; + } + + +1; diff --git a/scripts/README.md b/scripts/README.md index 3a6b9ee..42d320f 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,20 +1,20 @@ #Scripts# +* `generate_address_list.pl` takes the list of installed MBO serial numbers and generates the address.db file for DAQ +* `generate_address_settings.pl` makes the files needed to automatically set the board addresses from Flash ROM * `generate_pasttrec_settings.pl` prepares data from common baseline database * loads settings to FPGA directly * writes trbcmd files for later writing to Flash ROM * settings are written for boards currently in the system (otherwise serial number / uid can't be matched to addresses) * default PASTTREC registers are currently hardcoded (!) - * `merge_and_flash_settings.pl` generates and loads settings from the 'settings' directory to the FPGAs flashes - -* `generate_address_settings.pl` makes the files needed to automatically set the board addresses from Flash ROM - * `pasttrec_set_threshold.pl` sets an identical threshold to all Pasttrec (temporarily) - * `pasttrec_baseline_finder.pl` basic baseline finder script -* `generate_address_list.pl` takes the list of installed MBO serial numbers and generates the address.db file for DAQ +#Packages# + +* `MDC.pm` Library with common functions, like address lookup +* `MDCPower.pm` Library with common functions related to power setting and switching -##Notes## -All scripts assume that the daqtool repository is available next to this repository. +#Notes# +All scripts assume that the daqtools repository is available next to this repository. diff --git a/scripts/mdc_powerboard.pl b/scripts/mdc_powerboard.pl new file mode 120000 index 0000000..fe12753 --- /dev/null +++ b/scripts/mdc_powerboard.pl @@ -0,0 +1 @@ +../../avr/atmega32u4/dcdc_mdc/mdc_powerboard.pl \ No newline at end of file diff --git a/settings_power/settings_voltage.db b/settings_power/settings_voltage.db index cc7ac08..649d87d 100644 --- a/settings_power/settings_voltage.db +++ b/settings_power/settings_voltage.db @@ -1,6 +1,380 @@ #Board address used here is the TrbNet address of OEP (the same as for ADC readings) #Position in the detector and channel on power board can be calculated from this +#using MDC::get_power_channel() #Voltages are set between 0 and 7 +#This file can be edited, but is changed by scripts as well. # Address # Voltage 1 # Voltage 2 ######################################## + 0x8e00 2 2 + 0x8e01 2 2 + 0x8e02 2 2 + 0x8e03 2 2 + 0x8e04 2 2 + 0x8e05 2 2 + 0x8e06 2 2 + 0x8e07 2 2 + 0x8e08 2 2 + 0x8e09 2 2 + 0x8e0a 2 2 + 0x8e0b 2 2 + 0x8e0c 2 2 + 0x8e0d 2 2 + 0x8e10 2 2 + 0x8e11 2 2 + 0x8e12 2 2 + 0x8e13 2 2 + 0x8e14 2 2 + 0x8e15 2 2 + 0x8e16 2 2 + 0x8e17 2 2 + 0x8e18 2 2 + 0x8e19 2 2 + 0x8e1a 2 2 + 0x8e1b 2 2 + 0x8e1c 2 2 + 0x8e1d 2 2 + 0x8e20 2 2 + 0x8e21 2 2 + 0x8e22 2 2 + 0x8e23 2 2 + 0x8e24 2 2 + 0x8e25 2 2 + 0x8e26 2 2 + 0x8e27 2 2 + 0x8e28 2 2 + 0x8e29 2 2 + 0x8e2a 2 2 + 0x8e2b 2 2 + 0x8e2c 2 2 + 0x8e2d 2 2 + 0x8e30 2 2 + 0x8e31 2 2 + 0x8e32 2 2 + 0x8e33 2 2 + 0x8e34 2 2 + 0x8e35 2 2 + 0x8e36 2 2 + 0x8e37 2 2 + 0x8e38 2 2 + 0x8e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