#!/bin/bash
#Disable second TRB3 & unused ADC FPGA
-trbcmd w 0xc000 0xc0 0x0ff9
-trbcmd w 0xc000 0xc1 0x0ff9
-trbcmd w 0xc000 0xc3 0x0ff9
-
-
-cd ../../tools/
-./adc.pl 0x5003 init
-cd ../users/frankfurt_test
-
-
-trbcmd w 0xfe4b 0xa010 24 #Buffer depth
-trbcmd w 0xfe4b 0xa011 8 #Samples after trigger
-trbcmd w 0xfe4b 0xa012 2 #Process blocks
-trbcmd w 0xfe4b 0xa013 40 #Trigger offset
-trbcmd w 0xfe4b 0xa014 40 #Readout offset
-trbcmd w 0xfe4b 0xa015 0 #Downsampling
-trbcmd w 0xfe4b 0xa016 8 #Baseline
-trbcmd w 0xfe4b 0xa017 1 #Trigger Enable
-
-trbcmd w 0xfe4b 0xa020 0 #Sum values
-trbcmd w 0xfe4b 0xa021 0 #Sum values
-trbcmd w 0xfe4b 0xa022 0 #Sum values
-trbcmd w 0xfe4b 0xa023 0 #Sum values
-trbcmd w 0xfe4b 0xa024 15 #word count
-trbcmd w 0xfe4b 0xa025 7 #word count
-trbcmd w 0xfe4b 0xa026 0 #word count
-trbcmd w 0xfe4b 0xa027 0 #word count
-
-trbcmd w 0xfe4b 0xa000 0x100 #Reset Baseline
-
-trbcmd setbit 0x8000 0xa14d 0x00040000 #External trigger selector
-trbcmd setbit 0x8000 0xa101 0x00000400 #External trigger on
-
-trbcmd w 0x8000 0xa150 0x05f5e0ff #1 Hz pulser
-trbcmd loadbit 0x8000 0xa158 0x000000f0 0x000000e0 #Pulser 0xe type
-trbcmd setbit 0x8000 0xa101 0x00000002 #Pulser on
+#trbcmd w 0xc000 0xc0 0x0ff9
+#trbcmd w 0xc000 0xc1 0x0ff9
+#trbcmd w 0xc000 0xc3 0x0ff9
+
+
+#cd ../../tools/
+./adc.pl 0xf4cc init
+#cd ../users/frankfurt_test
+
+
+trbcmd w 0xf4cc 0xa010 24 #Buffer depth
+trbcmd w 0xf4cc 0xa011 8 #Samples after trigger
+trbcmd w 0xf4cc 0xa012 2 #Process blocks
+trbcmd w 0xf4cc 0xa013 40 #Trigger offset
+trbcmd w 0xf4cc 0xa014 40 #Readout offset
+trbcmd w 0xf4cc 0xa015 0 #Downsampling
+trbcmd w 0xf4cc 0xa016 8 #Baseline
+trbcmd w 0xf4cc 0xa017 1 #Trigger Enable
+
+trbcmd w 0xf4cc 0xa020 0 #Sum values
+trbcmd w 0xf4cc 0xa021 0 #Sum values
+trbcmd w 0xf4cc 0xa022 0 #Sum values
+trbcmd w 0xf4cc 0xa023 0 #Sum values
+trbcmd w 0xf4cc 0xa024 15 #word count
+trbcmd w 0xf4cc 0xa025 7 #word count
+trbcmd w 0xf4cc 0xa026 0 #word count
+trbcmd w 0xf4cc 0xa027 0 #word count
+
+trbcmd w 0xf4cc 0xa000 0x100 #Reset Baseline
+
+#trbcmd setbit 0x8000 0xa14d 0x00040000 #External trigger selector
+#trbcmd setbit 0x8000 0xa101 0x00000400 #External trigger on
+
+#trbcmd w 0x8000 0xa150 0x05f5e0ff #1 Hz pulser
+#trbcmd loadbit 0x8000 0xa158 0x000000f0 0x000000e0 #Pulser 0xe type
+#trbcmd setbit 0x8000 0xa101 0x00000002 #Pulser on
my $board = hex($ARGV[0]);
+#0 for TRB3sc, 1 for DiRich, 2 for Concentrator, 3 for PowerVoltages, 4 for PowerCurrents
+my $modedesc = ['Trb3sc','DiRich','Concentrator','Power-Voltages','Power-Currents'];
+my $mode = $ARGV[1] || 0;
+my $multiplier= [[2,1,1,2],[2,2,1,0],[2,2,1,25],[2,2,1,1],[10,5,2,1]];
+my $t = [['mV (3.3)','mV (2.5)','mV (1.2)','mV (6)'],
+ ['mV (3.3)','mV (2.5)','mV (1.1)',''],
+ ['mV (3.3)','mV (2.5)','mV (1.2)','mA (@1.2)'],
+ ['mV (3.3)','mV (2.5)','mV (1.2)','mV (1.1)'],
+ ['mA (@1.1)','mA (@1.2)','mA (@2.5)','mA (@3.3)']];
+my $channel = [7,7,7,6,5];
+
+print "\nRunning in mode ".$modedesc->[$mode]."\n\n";
+
+
#2 MHz SPI
system("trbcmd w $board 0xd41a 25");
my $cmd; my $s;
$cmd = 0xc3830000;
-$s = Dmon::PadiwaSendCmd($cmd,$board,7);
+$s = Dmon::PadiwaSendCmd($cmd,$board,$channel->[$mode]);
-usleep(1000);
+usleep(5000);
$cmd = 0xd3830000;
-$s = Dmon::PadiwaSendCmd($cmd,$board,7);
-printf("0x%08x\t%i mV\n",$s->{$board},($s->{$board}>>19&0xfff)*2);
+$s = Dmon::PadiwaSendCmd($cmd,$board,$channel->[$mode]);
+printf("0x%08x\t%i %s\n",$s->{$board},($s->{$board}>>19&0xfff)*$multiplier->[$mode][0],$t->[$mode][0]);
-usleep(1000);
-$cmd = 0xe5830000;
-$s = Dmon::PadiwaSendCmd($cmd,$board,7);
-printf("0x%08x\t%i mV\n",$s->{$board},($s->{$board}>>19)&0xfff);
+usleep(5000);
+$cmd = 0xe3830000;
+$s = Dmon::PadiwaSendCmd($cmd,$board,$channel->[$mode]);
+printf("0x%08x\t%i %s\n",$s->{$board},($s->{$board}>>19&0xfff)*$multiplier->[$mode][1],$t->[$mode][1]);
usleep(1000);
$cmd = 0xf3830000;
-$s = Dmon::PadiwaSendCmd($cmd,$board,7);
-printf("0x%08x\t%i mV\n",$s->{$board},($s->{$board}>>19&0xfff)/2);
-
+$s = Dmon::PadiwaSendCmd($cmd,$board,$channel->[$mode]);
+printf("0x%08x\t%i %s\n",$s->{$board},($s->{$board}>>19&0xfff)*$multiplier->[$mode][2],$t->[$mode][2]);
-usleep(1000);
+usleep(5000);
$cmd = 0xf3930000;
-$s = Dmon::PadiwaSendCmd($cmd,$board,7);
-printf("0x%08x\t%i mV\n",$s->{$board},($s->{$board}>>19&0xfff)*2);
+$s = Dmon::PadiwaSendCmd($cmd,$board,$channel->[$mode]);
+printf("0x%08x\t%i %s\n",$s->{$board},($s->{$board}>>19&0xfff)*$multiplier->[$mode][3],$t->[$mode][3]);
-usleep(1000);
-$s = Dmon::PadiwaSendCmd(0,$board,7);
+usleep(5000);
+$s = Dmon::PadiwaSendCmd(0,$board,$channel->[$mode]);
printf("0x%08x\t%.2f °C\n",$s->{$board},(($s->{$board}>>19)&0xfff)/16.);
#back to normal SPI speed
system("trbcmd w $board 0xd41a 7");
+print "\n";
\ No newline at end of file