/* ****************************************************************************** * Modification history * Mod: Shantha Condamoor 11-Nov-2013 * Removed LLRF_KLY21_1 as this slot is now used by LLRF_LSRDIAG * for Coherent 2 Laser Diagnostics PAD. PAD is not involved in * local laser feedback controls hence does not need to be included * in drvLlrf functions * Mod: Shantha Condamoor 16-Dec-2013 * Changed l1x functions to be exactly same as TCAV0 functions: * i.e., l1x changed to 'rf_2ch_fdbk_station_t' from 'rf_l1x_station_t' * Removed 'break' statements that are right after 'return' statements. * Added l1s and l1x to the new phase calc algo llrfCalcSimplePhase() **************************************************************************** */ /* Add header */ #include #include #include #include #include /* for atan2 */ #include /* for DEBUGPRINT */ #include #include #include #include "drvLlrf.h" /* includes llrfMacros.h */ int llrfDrvDebug = 0; int llrfReport(int station); int llrfInitialise(void); struct drvet drvLlrf = { 2, (DRVSUPFUN) llrfReport, /* subroutine defined in this file */ (DRVSUPFUN) llrfInitialise /* subroutine defined in this file */ }; epicsExportAddress(drvet, drvLlrf); epicsMutexId laserLock; /* Mutex to lock access to laser struct */ /* 11/21/8 Writing errors (level 2) has become too invasive to the processor w.r.t. processing the incoming data streams. Set all these to 0 */ #ifdef DEBUG_PRINT int drvLlrfFlag = 0; #ifdef LLRF_LSR_NG int drvLlrfAllowLaserOutput = 0; int drvLlrfLSRFlag = 0; int drvLlrfLSRGetFlag = 0; int drvLlrfLSRSetFlag = 0; int drvLlrfLSRGetZeroingFlag = 0; int drvLlrfLSRSetZeroingFlag = 0; int drvLlrfChangeSourceFlag = 0; int drvLlrfLSRFeedbackFlag = 0; #endif #ifdef LLRF_GUN_NG int drvLlrfGUNFlag = 0; #endif #ifdef LLRF_L0A_NG int drvLlrfL0AFlag = 0; #endif #ifdef LLRF_L0B_NG int drvLlrfL0BFlag = 0; #endif #ifdef LLRF_TCAV0_NG int drvLlrfTC0Flag = 0; #endif #ifdef LLRF_TCAV3_NG int drvLlrfTC3Flag = 0; #endif #ifdef LLRF_PCAV1_NG int drvLlrfPC1Flag = 0; #endif #ifdef LLRF_PCAV2_NG int drvLlrfPC2Flag = 0; #endif #ifdef LLRF_PCAV3_NG int drvLlrfPC3Flag = 0; #endif #ifdef LLRF_PCAV4_NG int drvLlrfPC4Flag = 0; #endif #ifdef LLRF_L1S_NG int drvLlrfL1SFlag = 0; #endif #ifdef LLRF_L1X_NG int drvLlrfL1XFlag = 0; #endif #ifdef LLRF_XTCAVA_NG int drvLlrfTCAFlag = 0; #endif int drvLlrfPOCFlag = 0; int drvLlrfAVCFlag = 0; int drvLlrfAPCFlag = 0; int drvLlrfPWTFlag = 0; int drvLlrfAWTFlag = 0; int drvLlrfPhaseFlag = 0; int drvLlrfSumsqFlag = 0; int drvLlrfCalcsFlag = 0; int drvLlrfAmplFlag = 0; int drvLlrfPowerFlag = 0; int drvLlrfDesiredPhaseFlag = 0; /* add to st-prod */ #endif int drv_debug = 0; /*============================================================================= Name: llrfSetPhaseOffsetCorrection Abs: pass in phase offset correction for given station and channel to global structure for the station =============================================================================*/ int llrfSetPhaseOffsetCorrection(int station, int channel, double phase_offset_corr) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRSetFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for LSR\n", channel)); #endif return ERROR; } lsr.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, lsr.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPOCFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for GUN\n", channel)); #endif return ERROR; } gun.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPOCFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, gun.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for L0A\n", channel)); #endif return ERROR; } l0a.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l0a.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for L0B\n", channel)); #endif return ERROR; } l0b.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l0b.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 1)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for PCAV1\n", channel)); #endif return ERROR; } pc1.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc1.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specific to station */ if ((channel <0 ) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for TC0\n", channel)); #endif return ERROR; } tc0.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, tc0.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for L1S\n", channel)); #endif return ERROR; } l1s.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l1s.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for L1X\n", channel)); #endif return ERROR; } l1x.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l1x.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for PCAV2\n", channel)); #endif return ERROR; } pc2.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc2.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for TC3\n", channel)); #endif return ERROR; } tc3.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, tc3.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for TCA\n", channel)); #endif return ERROR; } xtcava.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, xtcava.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY THREE IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for PCAV3\n", channel)); #endif return ERROR; } pc3.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc3.phase_offset_correction[channel])); #endif break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY FOUR IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfSetPhaseOffsetCorrection: invalid channel: %d for PCAV4\n", channel)); #endif return ERROR; } pc4.phase_offset_correction[channel] = phase_offset_corr; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfSetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc4.phase_offset_correction[channel])); #endif break; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: kly21_1.phase_offset_correction[channel] = phase_offset_corr; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPOCFlag, ("llrfSetPhaseOffsetCorrection: unrecognized station: %d\n", station)); #endif return ERROR; } return OK; } /*============================================================================= Name: llrfGetPhaseOffsetCorrection Abs: retrieve phase offset correction for a given station and channel from global structure for station =============================================================================*/ double llrfGetPhaseOffsetCorrection(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRGetFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for LSR\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, lsr.phase_offset_correction[channel])); #endif return lsr.phase_offset_correction[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for GUN\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, gun.phase_offset_correction[channel])); #endif return gun.phase_offset_correction[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for L0A\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l0a.phase_offset_correction[channel])); #endif return l0a.phase_offset_correction[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for L0B\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l0b.phase_offset_correction[channel])); #endif return l0b.phase_offset_correction[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for PCAV1\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc1.phase_offset_correction[channel])); #endif return pc1.phase_offset_correction[channel]; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specific to station */ if ((channel <0 ) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for TC0\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, tc0.phase_offset_correction[channel])); #endif return tc0.phase_offset_correction[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for L1S\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l1s.phase_offset_correction[channel])); #endif return l1s.phase_offset_correction[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for L1X\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, l1x.phase_offset_correction[channel])); #endif return l1x.phase_offset_correction[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for PCAV2\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc2.phase_offset_correction[channel])); #endif return pc2.phase_offset_correction[channel]; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for TCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, tc3.phase_offset_correction[channel])); #endif return tc3.phase_offset_correction[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for XTCAVA\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, xtcava.phase_offset_correction[channel])); #endif return xtcava.phase_offset_correction[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY THREE IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for PCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc3.phase_offset_correction[channel])); #endif return pc3.phase_offset_correction[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY FOUR IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfGetPhaseOffsetCorrection: invalid channel: %d for PCAV4\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetPhaseOffsetCorrection: phase offset correction for station %d channel %d: %g\n", station, channel, pc4.phase_offset_correction[channel])); #endif return pc4.phase_offset_correction[channel]; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: return kly21_1.phase_offset_correction[channel]; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPOCFlag, ("llrfGetPhaseOffsetCorrection: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfSetPowerScaleFactor Abs: =============================================================================*/ int llrfSetPowerScaleFactor(int station, int channel, double power_scal_fac) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRSetFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for LSR\n", channel)); #endif return ERROR; } lsr.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, lsr.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for GUN\n", channel)); #endif return ERROR; } gun.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, gun.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for L0A\n", channel)); #endif return ERROR; } l0a.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l0a.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for L0B\n", channel)); #endif return ERROR; } l0b.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l0b.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for PCAV1\n", channel)); #endif return ERROR; } pc1.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc1.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channels, specfic to station */ if ((channel < 0 ) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for TC0\n", channel)); #endif return ERROR; } tc0.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, tc0.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for L1S\n", channel)); #endif return ERROR; } l1s.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l1s.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for L1X\n", channel)); #endif return ERROR; } l1x.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l1x.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for PCAV2\n", channel)); #endif return ERROR; } pc2.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc2.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for TCAV3\n", channel)); #endif return ERROR; } tc3.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, tc3.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfSetPowerScaleFactor: invalid channel: %d for XTCAVA\n", channel)); #endif return ERROR; } xtcava.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, xtcava.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY THREE IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for PCAV3\n", channel)); #endif return ERROR; } pc3.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc3.power_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY FOUR IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfSetPowerScaleFactor: invalid channel: %d for PCAV4\n", channel)); #endif return ERROR; } pc4.power_scale_factor[channel] = power_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfSetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc4.power_scale_factor[channel])); #endif break; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: kly21_1.power_scale_factor[channel] = power_scal_fac; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfFlag, ("llrfSetPowerScaleFactor: unrecognized station: %d\n", station)); #endif return ERROR; } return OK; } /*============================================================================= Name: llrfGetPowerScaleFactor Abs: =============================================================================*/ double llrfGetPowerScaleFactor(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRGetFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for LSR\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, lsr.power_scale_factor[channel])); #endif return lsr.power_scale_factor[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for GUN\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, gun.power_scale_factor[channel])); #endif return gun.power_scale_factor[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for L0A\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l0a.power_scale_factor[channel])); #endif return l0a.power_scale_factor[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for L0B\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l0b.power_scale_factor[channel])); #endif return l0b.power_scale_factor[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfGetPowerScaleFactor: invalid channel: %d for PCAV1\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc1.power_scale_factor[channel])); #endif return pc1.power_scale_factor[channel]; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specfic to station */ if (channel >= 4) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAPCFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for TC0\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfAPCFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, tc0.power_scale_factor[channel])); #endif return tc0.power_scale_factor[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for L1S\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfAPCFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l1s.power_scale_factor[channel])); #endif return l1s.power_scale_factor[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for L1X\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, l1x.power_scale_factor[channel])); #endif return l1x.power_scale_factor[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfGetPowerScaleFactor: invalid channel: %d for PCAV2\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc2.power_scale_factor[channel])); #endif return pc2.power_scale_factor[channel]; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfGetPowerScaleFactor: invalid channel: %d for TCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, tc3.power_scale_factor[channel])); #endif return tc3.power_scale_factor[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfGetPowerScaleFactor: invalid channel: %d for XTCAVA\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, xtcava.power_scale_factor[channel])); #endif return xtcava.power_scale_factor[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY THREE IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfGetPowerScaleFactor: invalid channel: %d for PCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc3.power_scale_factor[channel])); #endif return pc3.power_scale_factor[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY FOUR IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfGetPowerScaleFactor: invalid channel: %d for PCAV4\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetPowerScaleFactor: power scale factor for station %d channel %d: %g\n", station, channel, pc4.power_scale_factor[channel])); #endif return pc4.power_scale_factor[channel]; #endif /*scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: return kly21_1.power_scale_factor[channel]; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAPCFlag, ("llrfGetPowerScaleFactor: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfSetVoltageScaleFactor Abs: =============================================================================*/ int llrfSetVoltageScaleFactor(int station, int channel, double voltage_scal_fac) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRSetFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for LSR\n", channel)); #endif return ERROR; } lsr.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, lsr.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specfic to station */ if (channel >= PAD_NUM_CHANNELS_GUN_FB) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for GUN\n", channel)); #endif return ERROR; } gun.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, gun.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for L0A\n", channel)); #endif return ERROR; } l0a.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l0a.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for L0B\n", channel)); #endif return ERROR; } l0b.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l0b.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 1)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for PCAV1\n", channel)); #endif return ERROR; } pc1.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc1.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for TC0\n", channel)); #endif return ERROR; } tc0.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, tc0.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specfic to station */ if (channel >= PAD_NUM_CHANNELS_L1S_FB) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for L1S\n", channel)); #endif return ERROR; } l1s.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l1s.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for L1X\n", channel)); #endif return ERROR; } l1x.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l1x.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for PCAV2 \n", channel)); #endif return ERROR; } pc2.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc2.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for TCAV3\n", channel)); #endif return ERROR; } tc3.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, tc3.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfSetVoltageScaleFactor: invalid channel: %d for XTCAVA\n", channel)); #endif return ERROR; } xtcava.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, xtcava.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY 3 IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for PCAV3\n", channel)); #endif return ERROR; } pc3.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc3.voltage_scale_factor[channel])); #endif break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY 4 IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfSetVoltageScaleFactor: invalid channel: %d for PCAV4\n", channel)); #endif return ERROR; } pc4.voltage_scale_factor[channel] = voltage_scal_fac; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfSetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc4.voltage_scale_factor[channel])); #endif break; #endif /*scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: kly21_1.voltage_scale_factor[channel] = voltage_scal_fac; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAVCFlag, ("llrfSetVoltageScaleFactor: unrecognized station: %d\n", station)); #endif return ERROR; } return OK; } /*============================================================================= Name: llrfGetVoltageScaleFactor Abs: =============================================================================*/ double llrfGetVoltageScaleFactor(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRGetFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for LSR\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, lsr.voltage_scale_factor[channel])); #endif return lsr.voltage_scale_factor[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for GUN\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, gun.voltage_scale_factor[channel])); #endif return gun.voltage_scale_factor[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for L0A\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l0a.voltage_scale_factor[channel])); #endif return l0a.voltage_scale_factor[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for L0B\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l0b.voltage_scale_factor[channel])); #endif return l0b.voltage_scale_factor[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for PCAV1\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc1.voltage_scale_factor[channel])); #endif return pc1.voltage_scale_factor[channel]; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specfic to station */ if ((channel < 0 ) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for TC0\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, tc0.voltage_scale_factor[channel])); #endif return tc0.voltage_scale_factor[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for L1S\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l1s.voltage_scale_factor[channel])); #endif return l1s.voltage_scale_factor[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* ANOTHER EXCEPTION: L1X HAS I/Q IN CH 0,1 AND 3, BUT NOT 2 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 3) || (channel == 2)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for L1X\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, l1x.voltage_scale_factor[channel])); #endif return l1x.voltage_scale_factor[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY TWO IN CHANNELS 2 AND 3 */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for PCAV2\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc2.voltage_scale_factor[channel])); #endif return pc2.voltage_scale_factor[channel]; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* ANOTHER EXCEPTION: TCAV3 USING CH0&1 FOR FB, BUT HAS 4 CHANNELS I&Q */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for TCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, tc3.voltage_scale_factor[channel])); #endif return tc3.voltage_scale_factor[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_ON_BOARD)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfGetVoltageScaleFactor: invalid channel: %d for XTCAVA\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, xtcava.voltage_scale_factor[channel])); #endif return xtcava.voltage_scale_factor[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY THREE IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for PCAV3\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc3.voltage_scale_factor[channel])); #endif return pc3.voltage_scale_factor[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specific to station */ /* ANOTHER EXCEPTION: PHASE CAVITY FOUR IN (ONLY) CHANNEL 3 */ if (channel != 3) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfGetVoltageScaleFactor: invalid channel: %d for PCAV4\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetVoltageScaleFactor: voltage scale factor for station %d channel %d: %g\n", station, channel, pc4.voltage_scale_factor[channel])); #endif return pc4.voltage_scale_factor[channel]; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: return kly21_1.voltage_scale_factor[channel]; break; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAVCFlag, ("llrfGetVoltageScaleFactor: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /* scondam: 23-Jul-2013 Using fmod() in the library math.h per Kukhee's recommendation: * double floor(double x); double fmod(double a, double b); */ /* float mod(float a, float N) {return a - N*floor(a/N);} */ /*return in range [0, N) */ /* scondam: 25-Jun-2013: changed to use mod(double, double) per Kukhee's recommendation */ double mod(double a, double N) { return (a-N*floor(a/N));} /*return in range [0, N) */ /* scondam: 30-Sept-2013: TCAV0, TCAV3 reverted back to use llrfCalcPhase() instead of llrfCalcSimplePhase(). Problems arose when using the nw phase calculation algorithm of Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 The function llrfCalcSimplePhase() is still retained in the file such that we can use it once the problems are resolved. Also, fmod() library function was causing phase swings as observed from XTCAV stripcharts. So reverting back to locally defined double mod() instead of the library fmod() */ /*============================================================================= Name: llrfCalcSimplePhase Abs: use atan2 to preserve quadrant, work in degrees, offset and limit =============================================================================*/ double llrfCalcSimplePhase(short I, short Q, double phase_offset_correction) { double phase; phase = atan2((double) Q,(double) I); /* Convert radians to degrees */ phase = phase/PI*180.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPhaseFlag, ("llrfCalcSimplePhase: I,Q=(%hd,%hd) has phase=%g degrees before offset correction\n", I, Q, phase)); #endif phase += phase_offset_correction; #ifdef LLRF_XTCAVA_NG /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 */ /* phase = mod((phase - xtcava.desired_phase + 180.), 360.) + xtcava.desired_phase - 180.; */ /* scondam: 23-Jul-2013: using fmod() in library math.h instead of custom mod() */ /* phase = fmod((phase - xtcava.prev_desired_phase + 180.), 360.) + xtcava.prev_desired_phase - 180.; */ /* scondam: 30-Sept-2013: using mod() instead of library fmod() due to issues noticed with fmod() */ /* phase = mod((phase - xtcava.prev_desired_phase + 180.), 360.) + xtcava.prev_desired_phase - 180.; */ /* scondam: 01-Oct-2013: Added a new PV for reference phase per H.Loos request for XTCAV*/ phase = mod((phase - xtcava.ref_phase + 180.), 360.) + xtcava.ref_phase - 180.; /* scondam: 25-Jun-2013: Desired phase changed? Update prev_desired_phase*/ if (xtcava.prev_desired_phase != xtcava.desired_phase) { xtcava.prev_desired_phase = xtcava.desired_phase; } #elif defined LLRF_TCAV0_NG /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 */ /* scondam: 23-Jul-2013: using fmod() in library math.h instead of custom mod() */ /* phase = fmod((phase - tc0.prev_desired_phase + 180.), 360.) + tc0.prev_desired_phase - 180.; */ /* scondam: 30-Sept-2013: using mod() instead of library fmod() due to issues noticed with fmod() */ phase = mod((phase - tc0.ref_phase + 180.), 360.) + tc0.ref_phase - 180.; /* scondam: 25-Jun-2013: Desired phase changed? Update prev_desired_phase*/ if (tc0.prev_desired_phase != tc0.desired_phase) { tc0.prev_desired_phase = tc0.desired_phase; } #elif defined LLRF_TCAV3_NG /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 */ /* phase = mod((phase - tc3.desired_phase + 180.), 360.) + tc3.desired_phase - 180.;*/ /* scondam: 23-Jul-2013: using fmod() in library math.h instead of custom mod() */ /* phase = fmod((phase - tc3.prev_desired_phase + 180.), 360.) + tc3.prev_desired_phase - 180.; */ /* scondam: 30-Sept-2013: using mod() instead of library fmod() due to issues noticed with fmod() */ phase = mod((phase - tc3.ref_phase + 180.), 360.) + tc3.ref_phase - 180.; /* scondam: 25-Jun-2013: Desired phase changed? Update prev_desired_phase*/ if (tc3.prev_desired_phase != tc3.desired_phase) { tc3.prev_desired_phase = tc3.desired_phase; } #elif defined LLRF_L1X_NG /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 */ phase = mod((phase - l1x.ref_phase + 180.), 360.) + l1x.ref_phase - 180.; /* scondam: 25-Jun-2013: Desired phase changed? Update prev_desired_phase*/ if (l1x.prev_desired_phase != l1x.desired_phase) { l1x.prev_desired_phase = l1x.desired_phase; } #elif defined LLRF_L1S_NG /* Calculated phase = Actual raw phase + phase offset with the modulo applied as below. */ /* Phase = mod(phase - phaseRef+180,360) + phaseRef - 180 */ phase = mod((phase - l1s.ref_phase + 180.), 360.) + l1s.ref_phase - 180.; /* scondam: 25-Jun-2013: Desired phase changed? Update prev_desired_phase*/ if (l1s.prev_desired_phase != l1s.desired_phase) { l1s.prev_desired_phase = l1s.desired_phase; } #endif #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPhaseFlag, ("llrfCalcSimplePhase: after offset correction, phase=%f degrees\n", phase)); #endif return phase; } /*============================================================================= */ /*============================================================================= Name: llrfCalcPhase Abs: use atan2 to preserve quadrant, work in degrees, offset and limit =============================================================================*/ double llrfCalcPhase(short I, short Q, double phase_offset_correction) { double phase; #ifdef LLRF_LSR_NG if (lsr.debug_flag) { drvLlrfPhaseFlag = 4; } #endif phase = atan2((double) Q,(double) I); /* Convert radians to degrees */ phase = phase/PI*180.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPhaseFlag, ("llrfCalcPhase: I,Q=(%hd,%hd) has phase=%g degrees before offset correction\n", I, Q, phase)); #endif phase += phase_offset_correction; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPhaseFlag, ("llrfCalcPhase: after offset correction, phase=%f degrees\n", phase)); #endif /* Ensure phase < 180 degrees */ if (phase > 180.) { phase -= 360.; } /* Ensure phase > -180 degrees */ if (phase < (-180.)) { phase += 360.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPhaseFlag, ("llrfCalcPhase: after range limiting, phase=%f degrees\n", phase)); #endif #ifdef LLRF_LSR_NG drvLlrfPhaseFlag = 0; #endif return phase; } /*============================================================================= Name: llrfCalcSumsq Abs: =============================================================================*/ double llrfCalcSumsq(short I, short Q) { double sumsq; double II = I * I; double QQ = Q * Q; sumsq = II + QQ; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfSumsqFlag, ("llrfCalcSumsq: I,Q=(%hd,%hd) has II=%g, QQ=%g and sumsq=%g\n", I, Q, II, QQ, sumsq)); #endif return sumsq; } /*============================================================================= Name: llrfSetDesiredPhase ONLY FOR LSR. Used in llrfCalculations =============================================================================*/ int llrfSetDesiredPhase(int station, double desired_phase) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_phase = desired_phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRSetFlag, ("llrfSetDesiredPhase: desired phase for LSR: %g\n", desired_phase)); #endif break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfDesiredPhaseFlag, ("llrfSetDesiredPhase: invalid station: %d\n", station)); #endif return ERROR; } return OK; } double llrfGetDesiredPhase(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: return lsr.desired_phase; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfDesiredPhaseFlag, ("llrfGetDesiredPhase: invalid station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfCalculations Abs: Calculates the phases, ampls, powers, avg phase and ampl of a PAD dataset for a station. Station is needed to figure out how many phases and in which channels TBD: So, all the data got across at once, BUT we only want to calculate the phases for BSA stuff, so how should non-BSA related channels be handled. I.e. for PCAV3 riding in klystron diag PAD... =============================================================================*/ int llrfCalculations(int station) { int ii; double deltax; int jj; switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: if (lsr.debug_flag) { drvLlrfLSRFlag = 4; printf("llrfCalculations: start\n\n"); llrfReport(1); printf("\n"); } /* Step 1. Rotate input Is and Qs */ /* rotate ch0's I and Q by desired_phase2856 */ /* TO DO: it MAY be that the desired_phase2856 is not ALWAYS correct. it MAY be that you have to first read which source is active and then rotate by the desired phase for the current source, scaled to 2856!!! check cos, sin return radians 11/23/8: the fix for this would be: replace desired_phase2856 by "desired_phase476*6" in next 2 lines */ lsr.rotatedI[0]=cos(lsr.desired_phase2856*PI/180.)*lsr.I[0]+sin(lsr.desired_phase2856*PI/180.)*lsr.Q[0]; lsr.rotatedQ[0]=cos(lsr.desired_phase2856*PI/180.)*lsr.Q[0]-sin(lsr.desired_phase2856*PI/180.)*lsr.I[0]; /* ch1 does not need to be rotated */ #ifdef LLRF_LSR68_NG /* rotate ch2's I and Q by desired_phase68 */ /* TO DO: it MAY be that the desired_phase68 is not ALWAYS correct. it MAY be that you have to first read which source is active and then rotate by the desired phase for the current source, scaled to 68!!! check cos, sin return radians 11/23/8: the fix for this would be: replace desired_phase68 by "desired_phase476/4" in next 2 lines */ lsr.rotatedI[2]=cos(lsr.desired_phase68*PI/180.)*lsr.I[2]+sin(lsr.desired_phase68*PI/180.)*lsr.Q[2]; lsr.rotatedQ[2]=cos(lsr.desired_phase68*PI/180.)*lsr.Q[2]-sin(lsr.desired_phase68*PI/180.)*lsr.I[2]; #elif LLRF_LSR119_NG /* rotate ch2's I and Q by desired_phase119 */ /* TO DO: it MAY be that the desired_phase119 is not ALWAYS correct. it MAY be that you have to first read which source is active and then rotate by the desired phase for the current source, scaled to 119!!! check cos, sin return radians 11/23/8: the fix for this would be: replace desired_phase119 by "desired_phase476/4" in next 2 lines */ lsr.rotatedI[2]=cos(lsr.desired_phase119*PI/180.)*lsr.I[2]+sin(lsr.desired_phase119*PI/180.)*lsr.Q[2]; lsr.rotatedQ[2]=cos(lsr.desired_phase119*PI/180.)*lsr.Q[2]-sin(lsr.desired_phase119*PI/180.)*lsr.I[2]; #endif /* ch3 does not need to be rotated */ /* Step 2. Calculate phases, both rotated and non-rotated */ /* ch0 has both */ lsr.phase[0]=llrfCalcPhase(lsr.rotatedI[0],lsr.rotatedQ[0],lsr.phase_offset_correction[0]); lsr.nonRotatedPhase[0]=llrfCalcPhase(lsr.I[0],lsr.Q[0],lsr.phase_offset_correction[0]); /* ch1 only has non-rotated, but to stay incoherent, it is called "phase". It is a function of the evolving specs */ lsr.phase[1]=llrfCalcPhase(lsr.I[1],lsr.Q[1],lsr.phase_offset_correction[1]); /* ch2 has both */ lsr.phase[2]=llrfCalcPhase(lsr.rotatedI[2],lsr.rotatedQ[2],lsr.phase_offset_correction[2]); lsr.nonRotatedPhase[2]=llrfCalcPhase(lsr.I[2],lsr.Q[2],lsr.phase_offset_correction[2]); /* ch3 only has non-rotated, but to stay obtuse, it is called "phase". Sigh. It is a function of the evolving specs */ lsr.phase[3]=llrfCalcPhase(lsr.I[3],lsr.Q[3],lsr.phase_offset_correction[3]); /* Step 3. Calculate amplitudes, powers and standard deviations */ /* Note: the rotatedIs and Qs are NOT used for any channel here */ for (ii=0; ii (-1.)*lsr.corrected_phase_lower_limit) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("dbSubLlrfLaserPset: limiting corrected_phase of %f to 0\n", lsr.corrected_phase)); #endif lsr.corrected_phase = 0.; } } else { /* Correction is zero or positive */ if (lsr.corrected_phase < lsr.corrected_phase_lower_limit) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("dbSubLlrfLaserPset: limiting corrected_phase of %f to 0\n", lsr.corrected_phase)); #endif lsr.corrected_phase = 0.; } if (lsr.corrected_phase > lsr.corrected_phase_upper_limit) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("dbSubLlrfLaserPset: limiting corr phase of %f to PCORMAX %f\n", lsr.corrected_phase, lsr.corrected_phase_upper_limit)); #endif lsr.corrected_phase = lsr.corrected_phase_upper_limit; } } /* Is actual ampl above minimum threshold for the source being used? */ if (lsr.actual_ampl > lsr.ampl_minimum_threshold) { lsr.phase_setpt = lsr.previous_phase_setpt - lsr.phase_smoothing_factor * lsr.corrected_phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: phase feedback is on and ampl:%f > thresh: %f.\n", lsr.actual_ampl, lsr.ampl_minimum_threshold)); DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, (" new setpt: %f\n", lsr.phase_setpt)); DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, (" calced from prev: %f - gain %f * correction %f\n", lsr.previous_phase_setpt, lsr.phase_smoothing_factor, lsr.corrected_phase)); #endif /*laser_fdbk_iter++;*/ /* 10/15/8: move guts of dbSubLlrfLaserPacPset here */ switch (lsr.input_source) { case LSR_2856_MHZ_SOURCE: lsr.pac_phase_setpt = lsr.phase_setpt + lsr.phase_zeroing_angle; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: (2856) added zeroing angle and now phase_setpt is %g\n", lsr.pac_phase_setpt)); #endif break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: lsr.pac_phase_setpt = lsr.phase_setpt + lsr.phase_zeroing_angle; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: (68) added zeroing angle and now phase_setpt is %g\n", lsr.pac_phase_setpt)); #endif break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: lsr.pac_phase_setpt = lsr.phase_setpt + lsr.phase_zeroing_angle; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: (119) added zeroing angle and now phase_setpt is %g\n", lsr.pac_phase_setpt)); #endif break; #endif #ifdef LLRF_PCAV1_NG case LSR_2805_MHZ_SOURCE: lsr.pac_phase_setpt = lsr.phase_setpt /* TO DO + lsr.phase_zeroing_angle */; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: (2805) added zeroing angle and now phase_setpt is %g\n", lsr.pac_phase_setpt)); #endif break; #endif } } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFlag, ("llrfCalculations: LOW POWER. ampl < min threshold %f. Reuse phase setpt: %f\n", lsr.ampl_minimum_threshold, lsr.phase_setpt)); #endif return OK; } } /* Keep phase setpoint between -210,210 degrees */ if (lsr.phase_setpt >= 210.) { lsr.phase_setpt -= 360.; } if (lsr.phase_setpt < -210.) { lsr.phase_setpt += 360.; } lsr.i_setpt = lsr.desired_ampl * cos(lsr.pac_phase_setpt*PI/180.) * lsr.i_scale_factor; lsr.q_setpt = lsr.desired_ampl * sin(lsr.pac_phase_setpt*PI/180.) * lsr.q_scale_factor; /* Set up for next iteration */ lsr.previous_phase_setpt = lsr.phase_setpt; if (lsr.debug_flag) { drvLlrfLSRFlag = 0; lsr.debug_flag = 0; llrfReport(1); } /* HERE IS THE END OF LOCKED PART */ epicsMutexUnlock (laserLock); break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: for (ii=0; ii thld First, need average amp */ for (jj=0; jj<2; jj++) { /* for ch 0 and 1 */ /* compute amplitude and power of sample0 only. amplitude and power of sample1 is not calculated */ /* 10/6/09: fix ampl and power caluculation */ pc1.ampl[jj] = sqrt((pc1.I[jj] * pc1.I[jj] + pc1.Q[jj] * pc1.Q[jj])) * pc1.voltage_scale_factor[jj]; pc1.power[jj] = (pc1.I[jj] * pc1.I[jj] + pc1.Q[jj] * pc1.Q[jj]) * pc1.power_scale_factor[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: ch %d samp 0 ampl is: %g\n", jj, pc1.ampl[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: ch %d samp 0 power is: %g\n", jj, pc1.power[jj])); #endif } /* for channels 0 and 1 */ /* 2/10/9: Next, need average ampl */ if (pc1.total_ampl_weighting != 0.) { pc1.avg_ampl = (pc1.ampl[0]*pc1.ampl_weighting_factor[0] + pc1.ampl[1]*pc1.ampl_weighting_factor[1]) /pc1.total_ampl_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfCalculations: total ampl weighting factor for PCAV1 is 0! Set some weightings\n")); #endif return ERROR; } if (pc1.avg_ampl > pc1.ampl_minimum_threshold) { /* 2/10/9: calculate phases only if avg ampl is sufficient */ for (jj=0; jj<2; jj++) { /* for ch 0 and 1 */ /**************************************************************/ /* Convert I and Q to phases */ /* y is Q; x is I */ /* Note: phase offset correction is per channel, so both samples for a channel use the same */ /* calculatiions for ch jj sample 0 */ pc1.phase[jj] = llrfCalcPhase(pc1.Q[jj],pc1.I[jj],pc1.phase_offset_correction[jj]); /* calculatiions for ch jj sample 1 */ pc1.S1_phase[jj] = llrfCalcPhase(pc1.S1_Q[jj],pc1.S1_I[jj],pc1.phase_offset_correction[jj]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: after offset and range limiting ch %d samp 0 phase=%f degrees.\n", jj, pc1.phase[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: after offset and range limiting ch %d samp 1 phase=%f degrees.\n", jj, pc1.S1_phase[jj])); #endif /* Calculate slope */ deltax = pc1.S1_X[jj] - pc1.X[jj]; if ((deltax) < 0.0001 ) { /* line approaches vertical. Return the phase of the first sample instead of computing equation to line. */ pc1.linear_phase[jj] = pc1.phase[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: PCAV1 ch %d line approaching vertical, use phase of first sample %g and skip eqn to line.\n", jj, pc1.linear_phase[jj])); #endif } else { pc1.slope[jj] = (pc1.S1_phase[jj] - pc1.phase[jj])/deltax; /* Calculate y-intercept */ pc1.b[jj] = pc1.phase[jj] - (pc1.slope[jj] * pc1.X[jj]); /* Use equation to line to determine phase at desired X */ pc1.linear_phase[jj] = pc1.slope[jj] * pc1.desired_X[jj] + pc1.b[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfCalculations: ch %d phase %g = %g * %g + %g.\n", jj, pc1.linear_phase[jj], pc1.slope[jj], pc1.desired_X[jj], pc1.b[jj])); #endif } } /* for channels 0 and 1 */ /* Now do weighting of phase and amplitudes of first two channels, 0 and 1 */ if (pc1.total_phase_weighting != 0.) { pc1.avg_phase = (pc1.linear_phase[0]*pc1.phase_weighting_factor[0] + pc1.linear_phase[1]*pc1.phase_weighting_factor[1]) /pc1.total_phase_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfCalculations: total phase weighting factor for PCAV1 is 0! Set some weightings\n")); #endif return ERROR; } } else { /* avg_ampl < amp_threshold; NO updates to phases will be done */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvLlrfPC1Flag, ("llrfCalculations: insufficient amplitude %g < %g\n", pc1.avg_ampl, pc1.ampl_minimum_threshold)); #endif } break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: for (ii=0; ii<4; ii++) { /* scondam: 30-Sept-2013: Reverting back to llrfCalcPhase() until the issues with llrfCalcSimplePhase() are resolved */ /* tc0.phase[ii]=llrfCalcSimplePhase(tc0.I[ii],tc0.Q[ii],tc0.phase_offset_correction[ii]); */ tc0.phase[ii]=llrfCalcPhase(tc0.I[ii],tc0.Q[ii],tc0.phase_offset_correction[ii]); tc0.sumsq[ii]=llrfCalcSumsq(tc0.I[ii],tc0.Q[ii]); tc0.ampl[ii]=sqrt(tc0.sumsq[ii]) * tc0.voltage_scale_factor[ii]; tc0.power[ii]=tc0.sumsq[ii] * tc0.power_scale_factor[ii]; } /* Only first two channels, 0 and 1, used in feedback */ if (tc0.total_phase_weighting != 0.) { tc0.avg_phase = (tc0.phase[0]*tc0.phase_weighting_factor[0] + tc0.phase[1]*tc0.phase_weighting_factor[1]) /tc0.total_phase_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfCalculations: total phase weighting factor for TC0 is 0! Set some weightings\n")); #endif return ERROR; } if (tc0.total_ampl_weighting != 0.) { tc0.avg_ampl = (tc0.ampl[0]*tc0.ampl_weighting_factor[0] + tc0.ampl[1]*tc0.ampl_weighting_factor[1]) /tc0.total_ampl_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfCalculations: total ampl weighting factor for TC0 is 0! Set some weightings\n")); #endif return ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfCalculations: phases are: %g %g %g %g\n", tc0.phase[0], tc0.phase[1], tc0.phase[2], tc0.phase[3])); DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfCalculations: sumsqs are: %g %g %g %g\n", tc0.sumsq[0], tc0.sumsq[1], tc0.sumsq[2], tc0.sumsq[3])); DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfCalculations: ampls are: %g %g %g %g\n", tc0.ampl[0], tc0.ampl[1], tc0.ampl[2], tc0.ampl[3])); DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfCalculations: powers are: %g %g %g %g\n", tc0.power[0], tc0.power[1], tc0.power[2], tc0.power[3])); DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfCalculations: avg phase: %g avg ampl %g\n", tc0.avg_phase, tc0.avg_ampl)); #endif break; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: if (llrfDrvDebug) { for(ii=0; ii<4; ii++) { printf("station L1S -> data[%d]: I: %d Q: %d\n",ii,l1s.I[ii],l1s.Q[ii]); } llrfDrvDebug--; } for (ii=0; ii S: %d\n",l1x.S); } else { printf("station L1X -> data[%d]: I: %d Q: %d\n",ii,l1x.I[ii],l1x.Q[ii]); } } llrfDrvDebug--; } /* EXCEPTION: FEEDBACK IN CHANNELS 0&1; BUT ANOTHER I&Q IN CHANNEL 3 */ for (ii=0; ii thld First, need average amp */ for (jj=2; jj<4; jj++) { /* for ch 2 and 3 */ /* compute amplitude and power of sample0 only. amplitude and power of sample1 is not calculated */ /* 10/6/09 fix ampl and power calculations */ pc2.ampl[jj] = sqrt((pc2.I[jj] * pc2.I[jj] + pc2.Q[jj] * pc2.Q[jj])) * pc2.voltage_scale_factor[jj]; pc2.power[jj] = (pc2.I[jj] * pc2.I[jj] + pc2.Q[jj] * pc2.Q[jj]) * pc2.power_scale_factor[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: ch %d samp 0 ampl is: %g\n", jj, pc2.ampl[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: ch %d samp 0 power is: %g\n", jj, pc2.power[jj])); #endif } /* for channels 2 and 3 */ /* 2/10/9: Next, need average ampl */ if (pc2.total_ampl_weighting != 0.) { pc2.avg_ampl = (pc2.ampl[2]*pc2.ampl_weighting_factor[2] + pc2.ampl[3]*pc2.ampl_weighting_factor[3]) /pc2.total_ampl_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfCalculations: total ampl weighting factor for PCAV2 is 0! Set some weightings\n")); #endif return ERROR; } if (pc2.avg_ampl > pc2.ampl_minimum_threshold) { /* 2/10/9: calculate phases only if avg ampl is sufficient */ for (jj=2; jj<4; jj++) { /* for ch 2 and 3 */ /**************************************************************/ /* Convert I and Q to phases */ /* y is Q; x is I */ /* Note: phase offset correction is per channel, so both samples for a channel use the same */ /* calculatiions for ch jj sample 0 */ pc2.phase[jj] = llrfCalcPhase(pc2.Q[jj],pc2.I[jj],pc2.phase_offset_correction[jj]); /* calculatiions for ch jj sample 1 */ pc2.S1_phase[jj] = llrfCalcPhase(pc2.S1_Q[jj],pc2.S1_I[jj],pc2.phase_offset_correction[jj]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: after offset and range limiting ch %d samp 0 phase=%f degrees.\n", jj, pc2.phase[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: after offset and range limiting ch %d samp 1 phase=%f degrees.\n", jj, pc2.S1_phase[jj])); #endif /* Calculate slope */ deltax = pc2.S1_X[jj] - pc2.X[jj]; if ((deltax) < 0.0001 ) { /* line approaches vertical. Return the phase of the first sample instead of computing equation to line. */ pc2.linear_phase[jj] = pc2.phase[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: PCAV2 ch %d line approaching vertical, use phase of first sample %g and skip eqn to line.\n", jj, pc2.linear_phase[jj])); #endif } else { pc2.slope[jj] = (pc2.S1_phase[jj] - pc2.phase[jj])/deltax; /* Calculate y-intercept */ pc2.b[jj] = pc2.phase[jj] - (pc2.slope[jj] * pc2.X[jj]); /* Use equation to line to determine phase at desired X */ pc2.linear_phase[jj] = pc2.slope[jj] * pc2.desired_X[jj] + pc2.b[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfCalculations: ch %d phase %g = %g * %g + %g.\n", jj, pc2.linear_phase[jj], pc2.slope[jj], pc2.desired_X[jj], pc2.b[jj])); #endif } } /* for channels 2 and 3 */ /* Now do weighting of phase and amplitudes of last two channels, 2 and 3 */ if (pc2.total_phase_weighting != 0.) { pc2.avg_phase = (pc2.linear_phase[2]*pc2.phase_weighting_factor[2] + pc2.linear_phase[3]*pc2.phase_weighting_factor[3]) /pc2.total_phase_weighting; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfCalculations: total phase weighting factor for PCAV2 is 0! Set some weightings\n")); #endif return ERROR; } } else { /* avg_ampl < amp_threshold; NO updates to phases will be done */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvLlrfPC2Flag, ("llrfCalculations: insufficient amplitude %g < %g\n", pc2.avg_ampl, pc2.ampl_minimum_threshold)); #endif } break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* EXCEPTION: 4 CHANNELS OF I&Q, BUT ONLY CHANNEL 0&1 USED IN FEEDBACK */ for (ii=0; ii thld First, need average amp */ for (jj=3; jj<4; jj++) { /* for ch 3 */ /* compute amplitude and power of sample0 only. amplitude and power of sample1 is not calculated */ /* 10/6/09 fix ampl and power calculations */ pc3.ampl[jj] = sqrt((pc3.I[jj] * pc3.I[jj] + pc3.Q[jj] * pc3.Q[jj])) * pc3.voltage_scale_factor[jj]; pc3.power[jj] = (pc3.I[jj] * pc3.I[jj] + pc3.Q[jj] * pc3.Q[jj]) * pc3.power_scale_factor[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: ch %d samp 0 ampl is: %g\n", jj, pc3.ampl[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: ch %d samp 0 power is: %g\n", jj, pc3.power[jj])); #endif } /* for channels 3 */ if (pc3.ampl[3] > pc3.ampl_minimum_threshold) { /* 2/10/9: calculate phases only if avg ampl is sufficient */ for (jj=3; jj<4; jj++) { /* for ch 3 */ /**************************************************************/ /* Convert I and Q to phases */ /* y is Q; x is I */ /* Note: phase offset correction is per channel, so both samples for a channel use the same */ /* calculatiions for ch jj sample 0 */ pc3.phase[jj] = llrfCalcPhase(pc3.Q[jj],pc3.I[jj],pc3.phase_offset_correction[jj]); /* calculatiions for ch jj sample 1 */ pc3.S1_phase[jj] = llrfCalcPhase(pc3.S1_Q[jj],pc3.S1_I[jj],pc3.phase_offset_correction[jj]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: after offset and range limiting ch %d samp 0 phase=%f degrees.\n", jj, pc3.phase[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: after offset and range limiting ch %d samp 1 phase=%f degrees.\n", jj, pc3.S1_phase[jj])); #endif /* Calculate slope */ deltax = pc3.S1_X[jj] - pc3.X[jj]; if ((deltax) < 0.0001 ) { /* line approaches vertical. Return the phase of the first sample instead of computing equation to line. */ pc3.linear_phase[jj] = pc3.phase[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: PCAV3 ch %d line approaching vertical, use phase of first sample %g and skip eqn to line.\n", jj, pc3.linear_phase[jj])); #endif } else { pc3.slope[jj] = (pc3.S1_phase[jj] - pc3.phase[jj])/deltax; /* Calculate y-intercept */ pc3.b[jj] = pc3.phase[jj] - (pc3.slope[jj] * pc3.X[jj]); /* Use equation to line to determine phase at desired X */ pc3.linear_phase[jj] = pc3.slope[jj] * pc3.desired_X[jj] + pc3.b[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfCalculations: ch %d phase %g = %g * %g + %g.\n", jj, pc3.linear_phase[jj], pc3.slope[jj], pc3.desired_X[jj], pc3.b[jj])); #endif } } /* for channel 3 */ } else { /* avg_ampl < amp_threshold; NO updates to phases will be done */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvLlrfPC3Flag, ("llrfCalculations: insufficient amplitude %g < %g\n", pc3.ampl[3], pc3.ampl_minimum_threshold)); #endif } break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* 2/10/9: new: only calc phase if ampl > thld First, need average amp */ for (jj=3; jj<4; jj++) { /* for ch 3 */ /* compute amplitude and power of sample0 only. amplitude and power of sample1 is not calculated */ /* 10/6/09 fix ampl and powe calculations */ pc4.ampl[jj] = sqrt((pc4.I[jj] * pc4.I[jj] + pc4.Q[jj] * pc4.Q[jj])) * pc4.voltage_scale_factor[jj]; pc4.power[jj] = (pc4.I[jj] * pc4.I[jj] + pc4.Q[jj] * pc4.Q[jj]) * pc4.power_scale_factor[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: ch %d samp 0 ampl is: %g\n", jj, pc4.ampl[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: ch %d samp 0 power is: %g\n", jj, pc4.power[jj])); #endif } /* for channels 4 */ if (pc4.ampl[3] > pc4.ampl_minimum_threshold) { /* 2/10/9: calculate phases only if avg ampl is sufficient */ for (jj=3; jj<4; jj++) { /* for ch 4 */ /**************************************************************/ /* Convert I and Q to phases */ /* y is Q; x is I */ /* Note: phase offset correction is per channel, so both samples for a channel use the same */ /* calculatiions for ch jj sample 0 */ pc4.phase[jj] = llrfCalcPhase(pc4.Q[jj],pc4.I[jj],pc4.phase_offset_correction[jj]); /* calculatiions for ch jj sample 1 */ pc4.S1_phase[jj] = llrfCalcPhase(pc4.S1_Q[jj],pc4.S1_I[jj],pc4.phase_offset_correction[jj]); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: after offset and range limiting ch %d samp 0 phase=%f degrees.\n", jj, pc4.phase[jj])); DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: after offset and range limiting ch %d samp 1 phase=%f degrees.\n", jj, pc4.S1_phase[jj])); #endif /* Calculate slope */ deltax = pc4.S1_X[jj] - pc4.X[jj]; if ((deltax) < 0.0001 ) { /* line approaches vertical. Return the phase of the first sample instead of computing equation to line. */ pc4.linear_phase[jj] = pc4.phase[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: PCAV4 ch %d line approaching vertical, use phase of first sample %g and skip eqn to line.\n", jj, pc4.linear_phase[jj])); #endif } else { pc4.slope[jj] = (pc4.S1_phase[jj] - pc4.phase[jj])/deltax; /* Calculate y-intercept */ pc4.b[jj] = pc4.phase[jj] - (pc4.slope[jj] * pc4.X[jj]); /* Use equation to line to determine phase at desired X */ pc4.linear_phase[jj] = pc4.slope[jj] * pc4.desired_X[jj] + pc4.b[jj]; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfCalculations: ch %d samp 0 phase %g = %g * %g + %g.\n", jj, pc4.linear_phase[jj], pc4.slope[jj], pc4.desired_X[jj], pc4.b[jj])); #endif } } /* for channel 3 */ } else { /* avg_ampl < amp_threshold; NO updates to phases will be done */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_DEBUG, drvLlrfPC4Flag, ("llrfCalculations: insufficient amplitude %g < %g\n", pc4.ampl[3], pc4.ampl_minimum_threshold)); #endif } break; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: for (ii=0; ii= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfSetPhaseWeightingFactor: invalid channel for GUN: %d\n", channel)); #endif return ERROR; break; } gun.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, gun.phase_weighting_factor[channel])); #endif /* Update the total */ gun.total_phase_weighting=0.; for (ii=0; ii= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfSetPhaseWeightingFactor: invalid channel for L0A: %d\n", channel)); #endif return ERROR; } l0a.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, l0a.phase_weighting_factor[channel])); #endif /* Update the total */ l0a.total_phase_weighting=0.; for (ii=0; ii 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfSetPhaseWeightingFactor: invalid channel for L0B: %d\n", channel)); #endif return ERROR; } l0b.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, l0b.phase_weighting_factor[channel])); #endif /* Update the total */ l0b.total_phase_weighting=0.; for (ii=2; ii<4; ii++) { l0b.total_phase_weighting += l0b.phase_weighting_factor[ii]; } break; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 1)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfSetPhaseWeightingFactor: invalid channel for PCAV1: %d\n", channel)); #endif return ERROR; break; } pc1.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, pc1.phase_weighting_factor[channel])); #endif /* Update the total */ pc1.total_phase_weighting=0.; for (ii=0; ii<2; ii++) { pc1.total_phase_weighting += pc1.phase_weighting_factor[ii]; } break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_TC0_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfSetPhaseWeightingFactor: invalid channel for TC0: %d\n", channel)); #endif return ERROR; break; } tc0.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, tc0.phase_weighting_factor[channel])); #endif /* Update the total */ tc0.total_phase_weighting=0.; for (ii=0; ii= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfSetPhaseWeightingFactor: invalid channel for L1S: %d\n", channel)); #endif return ERROR; break; } l1s.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, l1s.phase_weighting_factor[channel])); #endif /* Update the total */ l1s.total_phase_weighting=0.; for (ii=0; ii= PAD_NUM_CHANNELS_L1X_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetPhaseWeightingFactor: invalid channel for L1X: %d\n", channel)); #endif return ERROR; break; } l1x.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, l1x.phase_weighting_factor[channel])); #endif /* Update the total */ l1x.total_phase_weighting=0.; for (ii=0; ii 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfSetPhaseWeightingFactor: invalid channel for PC2: %d\n", channel)); #endif return ERROR; } pc2.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, pc2.phase_weighting_factor[channel])); #endif /* Update the total */ pc2.total_phase_weighting=0.; for (ii=2; ii<4; ii++) { pc2.total_phase_weighting += pc2.phase_weighting_factor[ii]; } break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* EXCEPTION: TCAV3 USING CH0&1 FOR FB */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_TC3_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfSetPhaseWeightingFactor: invalid channel for TC3: %d\n", channel)); #endif return ERROR; } tc3.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, tc3.phase_weighting_factor[channel])); #endif /* Update the total */ tc3.total_phase_weighting=0.; for (ii=0; ii= PAD_NUM_CHANNELS_XTCAVA_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfSetPhaseWeightingFactor: invalid channel for XTCAVA: %d\n", channel)); #endif return ERROR; } xtcava.phase_weighting_factor[channel]=phase_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfSetPhaseWeightingFactor: phase weighting factor for station %d channel %d: %g\n", station, channel, xtcava.phase_weighting_factor[channel])); #endif /* Update the total */ xtcava.total_phase_weighting=0.; for (ii=0; ii= PAD_NUM_CHANNELS_GUN_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfGUNFlag, ("llrfGetPhaseWeightingFactor: invalid channel for GUN: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, gun.phase_weighting_factor[channel])); #endif return gun.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L0A_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0AFlag, ("llrfGetPhaseWeightingFactor: invalid channel for L0A: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, l0a.phase_weighting_factor[channel])); #endif return l0a.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: /* THERE IS AN OFFSET OF TWO HERE. L0B IS USING ch 2 and 3 */ /* Bounds checking on channel, specific to station */ if ((channel < 2) || (channel > 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL0BFlag, ("llrfGetPhaseWeightingFactor: invalid channel for L0B: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, l0b.phase_weighting_factor[channel])); #endif return l0b.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 1 )) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfGetPhaseWeightingFactor: invalid channel for PC1: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, pc1.phase_weighting_factor[channel])); #endif return pc1.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_TC0_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC0Flag, ("llrfGetPhaseWeightingFactor: invalid channel for TCAV0: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, tc0.phase_weighting_factor[channel])); #endif return tc0.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1S_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1SFlag, ("llrfGetPhaseWeightingFactor: invalid channel: %d for L1S\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, l1s.phase_weighting_factor[channel])); #endif return l1s.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_L1X_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfGetPhaseWeightingFactor: invalid channel for L1X: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, l1x.phase_weighting_factor[channel])); #endif return l1x.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specific to station */ if ((channel < 3) || (channel > 3 )) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfGetPhaseWeightingFactor: invalid channel for PC2: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, pc2.phase_weighting_factor[channel])); #endif return pc2.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_TC3_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTC3Flag, ("llrfGetPhaseWeightingFactor: invalid channel for TCAV3: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, tc3.phase_weighting_factor[channel])); #endif return tc3.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel >= PAD_NUM_CHANNELS_XTCAVA_FB)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfTCAFlag, ("llrfGetPhaseWeightingFactor: invalid channel for XTCAVA: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetPhaseWeightingFactor: phas weighting factor for station %d channel %d: %g\n", station, channel, xtcava.phase_weighting_factor[channel])); #endif return xtcava.phase_weighting_factor[channel]; break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfGetPhaseWeightingFactor: should NOT be called for PCAV3\n")); #endif return (double) ERROR; break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfGetPhaseWeightingFactor: should NOT be called for PCAV4\n")); #endif return (double) ERROR; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPWTFlag, ("llrfGetPhaseWeightingFactor: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: routines for only L1X =============================================================================*/ double llrfGetS(int station, int channel) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetS: for station %d channel %d: %g\n", station, channel, (double) l1x.S)); #endif return (double) l1x.S; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetS: unrecognized station %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetTotalPhaseWeighting Abs: used by ai record to update edm ai record is flnked by ao records that change phase weight of one ch =============================================================================*/ double llrfGetTotalPhaseWeighting(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetTotalPhaseWeighting: should NOT be called for LSR\n")); #endif return (double) ERROR; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, gun.total_phase_weighting)); #endif return gun.total_phase_weighting; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, l0a.total_phase_weighting)); #endif return l0a.total_phase_weighting; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, l0b.total_phase_weighting)); #endif return l0b.total_phase_weighting; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, tc0.total_phase_weighting)); #endif return tc0.total_phase_weighting; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, l1s.total_phase_weighting)); #endif return l1s.total_phase_weighting; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, l1x.total_phase_weighting)); #endif return l1x.total_phase_weighting; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, tc3.total_phase_weighting)); #endif return tc3.total_phase_weighting; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, xtcava.total_phase_weighting)); #endif return xtcava.total_phase_weighting; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, pc1.total_phase_weighting)); #endif return pc1.total_phase_weighting; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetTotalPhaseWeighting: total phase weighting for station %d: %g\n", station, pc2.total_phase_weighting)); #endif return pc2.total_phase_weighting; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetTotalPhaseWeighting: should NOT be called for PCAV3\n")); #endif return (double) ERROR; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetTotalPhaseWeighting: should NOT be called for PCAV4\n")); #endif return (double) ERROR; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPWTFlag, ("llrfGetTotalPhaseWeighting: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfSetDesiredXOffset Abs: used by ao record to set the value of X at which the phase is to be calculated TODO: bounds check on station-specific channel =============================================================================*/ int llrfSetDesiredXOffset(int station, int channel, double desired_X) { switch (station) { #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: pc1.desired_X[channel] = desired_X; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetDesiredXOffset: \n")); #endif break; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: pc2.desired_X[channel] = desired_X; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetDesiredXOffset: \n")); #endif break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: pc3.desired_X[channel] = desired_X; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfSetDesiredXOffset: \n")); #endif break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: pc4.desired_X[channel] = desired_X; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfSetDesiredXOffset: \n")); #endif break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfFlag, ("llrfSetDesiredXOffset: should not be called for stations %d\n", station)); #endif return ERROR; } return OK; } /*============================================================================= Name: llrfSetAmplWeightingFactor Abs: used by ao record to get edm update into global struct TODO: bounds check on station-specific channel =============================================================================*/ int llrfSetAmplWeightingFactor(int station, int channel, double ampl_weighting_factor) { int ii; switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfLSRFlag, ("llrfSetAmplWeightingFactor: should NOT be called for LSR\n")); #endif return ERROR; break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: gun.ampl_weighting_factor[channel]=ampl_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfSetAmplWeightingFactor: ampl weighting factor for station %d channel %d: %g\n", station, channel, gun.ampl_weighting_factor[channel])); #endif /* Update the total */ gun.total_ampl_weighting=0.; for (ii=0; ii 1)) { return (double) ERROR; } return pc1.linear_phase[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specfic to station */ if ((channel < 2) || (channel > 3)) { return (double) ERROR; } return pc2.linear_phase[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc3.linear_phase[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc4.linear_phase[channel]; #endif default: return (double) ERROR; } } /*============================================================================= Name: llrfGetIntercept Abs: only for phase cavities TODO add error msgs =============================================================================*/ double llrfGetIntercept(int station, int channel) { switch (station) { #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel > 1)) { return (double) ERROR; } return pc1.b[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specfic to station */ if ((channel < 2) || (channel > 3)) { return (double) ERROR; } return pc2.b[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc3.b[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc4.b[channel]; #endif default: return (double) ERROR; } } /*============================================================================= Name: llrfGetSlope Abs: only for phase cavities TODO add error msgs =============================================================================*/ double llrfGetSlope(int station, int channel) { switch (station) { #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel > 1)) { return (double) ERROR; } return pc1.slope[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specfic to station */ if ((channel < 2) || (channel > 3)) { return (double) ERROR; } return pc2.slope[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc3.slope[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } return pc4.slope[channel]; #endif default: return (double) ERROR; } } /*============================================================================= Name: llrfGetMidpoint Abs: only for phase cavities TODO add error msgs =============================================================================*/ double llrfGetMidpoint(int station, int channel, int sample) { switch (station) { #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: /* Bounds checking on channel, specfic to station */ if ((channel < 0) || (channel > 1)) { return (double) ERROR; } if (sample == 0) { return pc1.X[channel]; } else { if (sample == 1) { return pc1.S1_X[channel]; } else { return (double) ERROR; } } #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: /* Bounds checking on channel, specfic to station */ if ((channel < 2) || (channel > 3)) { return (double) ERROR; } if (sample == 0) { return pc2.X[channel]; } else { if (sample == 1) { return pc2.S1_X[channel]; } else { return (double) ERROR; } } #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } if (sample == 0) { return pc3.X[channel]; } else { if (sample == 1) { return pc3.S1_X[channel]; } else { return (double) ERROR; } } #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: /* Bounds checking on channel, specfic to station */ if (channel != 3) { return (double) ERROR; } if (sample == 0) { return pc4.X[channel]; } else { if (sample == 1) { return pc4.S1_X[channel]; } else { return (double) ERROR; } } #endif default: return (double) ERROR; } } /*============================================================================= Name: llrfGetVarQ Abs: return the variance only laser uses this TODO Bounds check on channel =============================================================================*/ double llrfGetVarQ(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetVarQ: varQ for station %d channel %d: %d\n", station, channel, lsr.varQ[channel])); #endif return lsr.varQ[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetVarQ: should not be called for station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetVarI Abs: return the variance only laser uses this TODO Bounds check on channel =============================================================================*/ double llrfGetVarI(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetVarI: varI for station %d channel %d: %d\n", station, channel, lsr.varI[channel])); #endif return lsr.varI[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetSigmaI: should not be called for station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetSigmaQ Abs: only laser uses this TODO Bounds check on channel =============================================================================*/ double llrfGetSigmaQ(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetSigmaQ: sigmaQ for station %d channel %d: %g\n", station, channel, lsr.sigmaQ[channel])); #endif return lsr.sigmaQ[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetSigmaQ: should not be called for station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetSigmaI Abs: only laser uses this TODO Bounds check on channel =============================================================================*/ double llrfGetSigmaI(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetSigmaI: sigmaI for station %d channel %d: %g\n", station, channel, lsr.sigmaI[channel])); #endif return lsr.sigmaI[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetSigmaI: should not be called for station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetNonRotatedPhase Abs: only laser uses this, and only for ch 0 and 2 TODO Bounds check on channel =============================================================================*/ double llrfGetNonRotatedPhase(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: if ((channel == 1) || (channel == 3)) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetNonRotatedPhase: should not be called for laser channel: %d\n", channel)); #endif return (double) ERROR; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetNonRotatedPhase: phase for station %d channel %d: %g\n", station, channel, lsr.phase[channel])); #endif return lsr.nonRotatedPhase[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetNonRotatedPhase: should not be called for station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetPhase Abs: TODO Bounds check on channel debug infos on some check 1ch_pcav_station has only scalar phase (no array) check 2ch_pcav_station really ends up with phase[2] sample is only used for phase cavities =============================================================================*/ double llrfGetPhase(int station, int channel, int sample) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, lsr.phase[channel])); #endif return lsr.phase[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, gun.phase[channel])); #endif return gun.phase[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, l0a.phase[channel])); #endif return l0a.phase[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, l0b.phase[channel])); #endif return l0b.phase[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: if (sample == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPhase: phase for station %d channel %d sample 0: %g\n", station, channel, pc1.phase[channel])); #endif return pc1.phase[channel]; } else { if (sample == 1) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPhase: phase for station %d channel %d sample 1: %g\n", station, channel, pc1.S1_phase[channel])); #endif return pc1.S1_phase[channel]; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC1Flag, ("llrfGetPhase: unrecognized sample %d\n", sample)); #endif return (double) ERROR; } } #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, tc0.phase[channel])); #endif return tc0.phase[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, l1s.phase[channel])); #endif return l1s.phase[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, l1x.phase[channel])); #endif return l1x.phase[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: if (sample == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPhase: phase for station %d channel %d sample 0: %g\n", station, channel, pc2.phase[channel])); #endif return pc2.phase[channel]; } else { if (sample == 1) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPhase: phase for station %d channel %d sample 1: %g\n", station, channel, pc2.S1_phase[channel])); #endif return pc2.S1_phase[channel]; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC2Flag, ("llrfGetPhase: unrecognized sample %d\n", sample)); #endif return (double) ERROR; } } #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, tc3.phase[channel])); #endif return tc3.phase[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetPhase: phase for station %d channel %d: %g\n", station, channel, xtcava.phase[channel])); #endif return xtcava.phase[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: if (sample == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPhase: phase for station %d channel %d sample 0: %g\n", station, channel, pc3.phase[channel])); #endif return pc3.phase[channel]; } else { if (sample == 1) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPhase: phase for station %d channel %d sample 1: %g\n", station, channel, pc3.S1_phase[channel])); #endif return pc3.S1_phase[channel]; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC3Flag, ("llrfGetPhase: unrecognized sample %d\n", sample)); #endif return (double) ERROR; } } #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: if (sample == 0) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetPhase: phase for station %d channel %d sample 0: %g\n", station, channel, pc4.phase[channel])); #endif return pc4.phase[channel]; } else { if (sample == 1) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetPhase: phase for station %d channel %d sample 1: %g\n", station, channel, pc4.S1_phase[channel])); #endif return pc4.S1_phase[channel]; } else { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPC4Flag, ("llrfGetPhase: unrecognized sample %d\n", sample)); #endif return (double) ERROR; } } #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPhaseFlag, ("llrfGetPhase: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetAmpl Abs: TODO Bounds check on channel ampl = scalar on pc3,4 and ampl[2] on pc1,2 =============================================================================*/ double llrfGetAmpl(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, lsr.ampl[channel])); #endif return lsr.ampl[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, gun.ampl[channel])); #endif return gun.ampl[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, l0a.ampl[channel])); #endif return l0a.ampl[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, l0b.ampl[channel])); #endif return l0b.ampl[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, pc1.ampl[channel])); #endif return pc1.ampl[channel]; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, tc0.ampl[channel])); #endif return tc0.ampl[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, l1s.ampl[channel])); #endif return l1s.ampl[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, l1x.ampl[channel])); #endif return l1x.ampl[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, pc2.ampl[channel])); #endif return pc2.ampl[channel]; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, tc3.ampl[channel])); #endif return tc3.ampl[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, xtcava.ampl[channel])); #endif return xtcava.ampl[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, pc3.ampl[channel])); #endif return pc3.ampl[channel]; break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, pc4.ampl[channel])); #endif return pc4.ampl[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAmplFlag, ("llrfGetAmpl: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfGetPower Abs: TODO Bounds check on channel debug info on some check powers in pcav structs =============================================================================*/ double llrfGetPower(int station, int channel) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, lsr.power[channel])); #endif return lsr.power[channel]; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfGUNFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, gun.power[channel])); #endif return gun.power[channel]; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0AFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, l0a.power[channel])); #endif return l0a.power[channel]; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL0BFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, l0b.power[channel])); #endif return l0b.power[channel]; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, pc1.power[channel])); #endif return pc1.power[channel]; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC0Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, tc0.power[channel])); #endif return tc0.power[channel]; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1SFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, l1s.power[channel])); #endif return l1s.power[channel]; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, l1x.power[channel])); #endif return l1x.power[channel]; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, pc2.power[channel])); #endif return pc2.power[channel]; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, tc3.power[channel])); #endif return tc3.power[channel]; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTCAFlag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, xtcava.power[channel])); #endif return xtcava.power[channel]; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, pc3.power[channel])); #endif return pc3.power[channel]; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, pc4.power[channel])); #endif return pc4.power[channel]; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPowerFlag, ("llrfGetPower: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= Name: llrfInitialise Abs: =============================================================================*/ int llrfInitialise() { #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfIntialise: \n")); #endif if ((laserLock = epicsMutexCreate()) == OK) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfPowerFlag, ("llrfInitialise: unable to create mutex to control access to laser setpts\n")); #endif return ERROR; } return OK; } /*============================================================================= Name: llrfReport Abs: TODO order check assumps for PCAVs re: num chans =============================================================================*/ int llrfReport(int station) { int ii; switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: printf("\nLLRF Laser station\n"); printf("------------------\n"); printf("I readouts from PAD\n"); for (ii=0; ii %g to update phase setpoint!!!\n", lsr.actual_ampl, lsr.ampl_minimum_threshold); printf(" !!!calculations in units of deg 476 MHz!!!\n"); printf(" desired phase: %g\n", lsr.desired_phase); printf(" actual phase: %g\n", lsr.actual_phase); #ifdef LLRF_LSR68_NG printf(" zeroing angle (to preserve bucket when src changes. expect 0 if source is 68): %g\n", lsr.phase_zeroing_angle); #elif LLRF_LSR119_NG printf(" zeroing angle (to preserve bucket when src changes. expect 0 if source is 119): %g\n", lsr.phase_zeroing_angle); #endif printf(" previous phase setpoint: %g\n", lsr.previous_phase_setpt); printf(" phase setpoint: %g\n", lsr.phase_setpt); printf(" PAC phase setpoint: %g (zeroing angle added to phase setpoint)\n", lsr.pac_phase_setpt); printf(" corrected phase: %g (the error term; the angle from desired constrained to limits)\n", lsr.corrected_phase); printf(" corrected phase constrained to within: low %g, high %g\n", lsr.corrected_phase_lower_limit, lsr.corrected_phase_upper_limit); printf("I,Q scale factors: %g,%g\n", lsr.i_scale_factor, lsr.q_scale_factor); printf(" new PAC I,Q setpoints: %g,%g\n", lsr.i_setpt, lsr.q_setpt); printf(" PAC's prev I,Q adjust valuels: %g,%g\n", lsr.i_adjust_from_PAC, lsr.q_adjust_from_PAC); break; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: printf("\nGUN\n"); printf("Phase offset corrections\n"); for (ii=0; ii %g to update phase setpoint!!!\n", pc1.avg_ampl, pc1.ampl_minimum_threshold); break; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: printf("\nTC0\n"); printf("Phase offset corrections\n"); for (ii=0; ii %g to update phase setpoint!!!\n", pc2.avg_ampl, pc2.ampl_minimum_threshold); break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: printf("\nTC3\n"); printf("Phase offset corrections\n"); for (ii=0; ii %g to update phase setpoint!!!\n", pc3.ampl[3], pc3.ampl_minimum_threshold); break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: printf("\nPC4\n"); printf("Phase offset corrections\n"); for (ii=3; ii %g to update phase setpoint!!!\n", pc4.ampl[3], pc4.ampl_minimum_threshold); break; #endif default: if (station == 0 ) { printf("Needs station # as argument. See enum list in llrfMacros.h\n"); } #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfFlag, ("llrfReport: unrecognized station: %d\n", station)); #endif return ERROR; } return OK; } void* llrfGetFeedbackStation(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: return (void *) &lsr; #endif #ifdef LLRF_GUN_NG case LLRF_GUN: return (void *) &gun; #endif #ifdef LLRF_L0A_NG case LLRF_L0A: return (void *) &l0a; #endif #ifdef LLRF_L0B_NG case LLRF_L0B: return (void *) &l0b; #endif #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: return (void *) &pc1; #endif #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: return (void *) &tc0; #endif #ifdef LLRF_L1S_NG case LLRF_L1S: return (void *) &l1s; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: return (void *) &l1x; #endif #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: return (void *) &pc2; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: return (void *) &tc3; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: return (void *) &xtcava; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: return (void *) &pc3; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: return (void *) &pc4; #endif /* scondam: 22-Nov-2013: Changed LLRF_KLY21_1 to LLRF_LSRDIAG for slot (20) */ /* #ifdef LLRF_KLY21_1_NG case LLRF_KLY21_1: return (void *) &kly21_1; #endif */ default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfFlag, ("llrfGetFeedbackStation: unrecognized station: %d\n", station)); #endif return NULL; } } int llrfSetInputSource(int station, int source) { /* 11/23/8 TO DO: Possible problem: if feedback is off when the source is changed, the zeroing does not get absorbed/set. should the zeroing be updated regardless of the state of the feedback? */ switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.prev_input_source = lsr.input_source; lsr.input_source = source; #ifdef DEBUG_PRINT #ifdef LLRF_LSR68_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: changing to %d (0=2856, 1=68, 2=2805)\n", source)); #elif LLRF_LSR119_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: changing to %d (0=2856, 1=119, 2=2805)\n", source)); #endif #endif /*if (lsr.feedback_on) { only do zeroing if feedback is on */ switch (lsr.input_source) { case LSR_2856_MHZ_SOURCE: /* When source changes, fix phase setpoint to adjust it by the zeroing factor */ /* Only do this when previous input source was the 119 (or 68) if (lsr.prev_input_source == 1) { */ lsr.phase_zeroing_angle = lsr.phase_setpt; #ifdef DEBUG_PRINT #ifdef LLRF_LSR68_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 68, now 2856): set zeroing to phas setpt: %g\n", lsr.phase_setpt)); #elif LLRF_LSR119_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 119, now 2856): set zeroing to phas setpt: %g\n", lsr.phase_setpt)); #endif DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: zeroing is %g\n", lsr.phase_zeroing_angle)); #endif lsr.previous_phase_setpt -= lsr.phase_zeroing_angle; #ifdef DEBUG_PRINT #ifdef LLRF_LSR68_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 68, now2856): subtract zeroing: %g from prv phas setpt\n", lsr.phase_zeroing_angle)); #elif LLRF_LSR119_NG DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 119, now2856): subtract zeroing: %g from prv phas setpt\n", lsr.phase_zeroing_angle)); #endif DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: prev phase setpt now: %g\n", lsr.previous_phase_setpt)); #endif /*}*/ break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: /* Only do this when previous input source was the 2856 if (lsr.prev_input_source == 0) { */ lsr.previous_phase_setpt += lsr.phase_zeroing_angle; lsr.phase_zeroing_angle = 0.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 2856, now 68): subtract zeroing: %g from prv phas setpt\n", lsr.phase_zeroing_angle)); DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: now set zeroing to 0\n")); DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: prev phas setpt now: %g\n", lsr.previous_phase_setpt)); #endif /*}*/ #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: /* Only do this when previous input source was the 2856 if (lsr.prev_input_source == 0) { */ lsr.previous_phase_setpt += lsr.phase_zeroing_angle; lsr.phase_zeroing_angle = 0.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource (was 2856, now 119): subtract zeroing: %g from prv phas setpt\n", lsr.phase_zeroing_angle)); DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: now set zeroing to 0\n")); DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: prev phas setpt now: %g\n", lsr.previous_phase_setpt)); #endif /*}*/ #endif } /*}*/ /* Regardless of feedback control, set new value of desired phase */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: update the desired phase based on the source\n")); #endif switch (lsr.input_source) { case LSR_2856_MHZ_SOURCE: /* 10/15/8: When the source changes, calculate desired phase from selected source */ lsr.desired_phase = lsr.desired_phase2856/6.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: recalc desired phase: %g deg 2856 MHz/6 = %g deg 476 MHz\n", lsr.desired_phase2856, lsr.desired_phase)); #endif break; #ifdef LLRF_LSR68_NG case LSR_68_MHZ_SOURCE: /* 10/15/8: When the source changes, calculate desired phase from selected source */ lsr.desired_phase = lsr.desired_phase68*7.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: recalc desired phase as: %g deg 68 MHz*7 = %g deg 476 MHz\n", lsr.desired_phase68, lsr.desired_phase)); #endif break; #elif LLRF_LSR119_NG case LSR_119_MHZ_SOURCE: /* 10/15/8: When the source changes, calculate desired phase from selected source */ lsr.desired_phase = lsr.desired_phase119*4.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: recalc desired phase as: %g deg 119 MHz*4 = %g deg 476 MHz\n", lsr.desired_phase119, lsr.desired_phase)); #endif break; #endif case LSR_2805_MHZ_SOURCE: /* 10/15/8: When the source changes, calculate desired phase from selected source */ lsr.desired_phase = lsr.desired_phase2805/2805.*476.; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfChangeSourceFlag, ("llrfSetInputSource: recalc desired phase as: %g/476*2805 = %g deg 476 MHz\n", lsr.desired_phase2805, lsr.desired_phase)); #endif break; } #endif } return OK; } int llrfGetInputSource(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetInputSource: %d\n", lsr.input_source)); #endif return lsr.input_source; break; #endif } return ERROR; } int llrfSetDesiredPhase2856(int station, double phase) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_phase2856 = phase; if (lsr.input_source == LSR_2856_MHZ_SOURCE) { lsr.desired_phase = phase/6.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetDesiredPhase2856: %g\n", lsr.desired_phase2856)); #endif break; #endif } return OK; } #ifdef LLRF_LSR68_NG int llrfSetDesiredPhase68(int station, double phase) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_phase68 = phase; if (lsr.input_source == LSR_68_MHZ_SOURCE) { lsr.desired_phase = phase*7.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetDesiredPhase68: %g\n", lsr.desired_phase68)); #endif break; #endif } return OK; } #elif LLRF_LSR119_NG int llrfSetDesiredPhase119(int station, double phase) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_phase119 = phase; if (lsr.input_source == LSR_119_MHZ_SOURCE) { lsr.desired_phase = phase*4.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetDesiredPhase119: %g\n", lsr.desired_phase119)); #endif break; #endif } return OK; } #endif int llrfSetDesiredPhase2805(int station, double phase) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_phase2805 = phase; if (lsr.input_source == LSR_2805_MHZ_SOURCE) { lsr.desired_phase = phase/476.*2805.; } #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetDesiredPhase2805: %g\n", lsr.desired_phase2805)); #endif break; #endif } return OK; } int llrfSetRefPhase(int station, double phase) { switch (station) { #ifdef LLRF_TCAV0_NG case LLRF_TCAV0: tc0.ref_phase = phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetRefPhase: %g\n", tc0.ref_phase)); #endif break; #endif #ifdef LLRF_TCAV3_NG case LLRF_TCAV3: tc3.ref_phase = phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetRefPhase: %g\n", tc3.ref_phase)); #endif break; #endif #ifdef LLRF_XTCAVA_NG case LLRF_XTCAVA: xtcava.ref_phase = phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetRefPhase: %g\n", xtcava.ref_phase)); #endif break; #endif #ifdef LLRF_L1X_NG case LLRF_L1X: l1x.ref_phase = phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetRefPhase: %g\n", l1x.ref_phase)); #endif break; #endif } return OK; } int llrfSetPhaseCorrectionMax(int station, double correction) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.corrected_phase_upper_limit = correction; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetPhaseCorrectionMax: %g\n", lsr.corrected_phase_upper_limit)); #endif break; #endif } return OK; } int llrfSetPhaseCorrectionMin(int station, double correction) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.corrected_phase_lower_limit = correction; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetPhaseCorrectionMin: %g\n", lsr.corrected_phase_lower_limit)); #endif break; #endif } return OK; } int llrfSetPhaseGain(int station, double gain) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.phase_smoothing_factor = gain; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetPhaseGain: %g\n", lsr.phase_smoothing_factor)); #endif break; #endif } return OK; } int llrfSetDesiredAmpl(int station, double ampl) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.desired_ampl = ampl; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetDesiredAmpl: %g\n", lsr.desired_ampl)); #endif break; #endif } return OK; } int llrfSetQScaleFactor(int station, double scale_factor) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.q_scale_factor = scale_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetQScaleFactor: %g\n", lsr.q_scale_factor)); #endif break; #endif } return OK; } int llrfSetIScaleFactor(int station, double scale_factor) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.i_scale_factor = scale_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetIScaleFactor: %g\n", lsr.i_scale_factor)); #endif break; #endif } return OK; } int llrfSetZeroingFactor(int station, double zeroing_angle) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.phase_zeroing_angle = zeroing_angle; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetZeroingFlag, ("llrfSetZeroingFactor: %g\n", lsr.phase_zeroing_angle)); #endif break; #endif } return OK; } double llrfGetZeroingFactor(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRGetZeroingFlag, ("llrfSetZeroingFactor: %g\n", lsr.phase_zeroing_angle)); #endif return lsr.phase_zeroing_angle; #endif } return (double) ERROR; } /* Absorption of current PAC I and Q adjust done here if feedback control is changing from off to on */ int llrfSetPhaseFeedbackControl(int station, int val) { #ifdef LLRF_LSR_NG double phase; #endif switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: /* turning on from off */ if ((val == 1) && (lsr.feedback_on == 0)) { /* TODO 11/26/8: add way to disable this because, while all the output is written, button response is delayes - this could cause problems if Send to PAC button doesn't respond as expected and thereby causes ops to press it repeatedly */ /* turn this on to write one iter's worth of llrfCalculations, llrfCalculations turns this off at end of one iter. */ if (drvLlrfAllowLaserOutput) { lsr.debug_flag = 1; } /* 11/26/8 this is how the PAC position gets into VME calcs */ /* absorb PAC positions into phase setpoint to start... */ #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFeedbackFlag, ("llrfSetPhaseFeedbackControl: absorb current PAC positions: %g,%g\n", lsr.i_adjust_from_PAC, lsr.q_adjust_from_PAC)); #endif phase = llrfCalcPhase(lsr.i_adjust_from_PAC,lsr.q_adjust_from_PAC,0); #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFeedbackFlag, ("llrfSetPhaseFeedbackControl: corresponding phase is: %g\n", phase)); #endif #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFeedbackFlag, ("llrfSetPhaseFeedbackControl: now subtract zeroing angle: %g\n", lsr.phase_zeroing_angle)); #endif /* HERE IS THE START OF LOCKED PART. new 11/24/8 */ epicsMutexLock (laserLock); lsr.previous_phase_setpt = phase - lsr.phase_zeroing_angle; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRFeedbackFlag, ("llrfSetPhaseFeedbackControl: and prev phas setpoint becomes: %g\n", lsr.previous_phase_setpt)); #endif epicsMutexUnlock (laserLock); /* HERE IS THE END OF LOCKED PART */ } lsr.feedback_on = val; break; #endif } return OK; } int llrfSetPacIPositionMonitor(int station, double position) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetFlag, ("llrfSetPacIPositionMonitor: retrieved I adjust from PAC: %g\n", position)); #endif lsr.i_adjust_from_PAC = position; break; #endif } return OK; } int llrfSetPacQPositionMonitor(int station, double position) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfLSRSetFlag, ("llrfSetPacQPositionMonitor: retrieved Q adjust from PAC: %g\n", position)); #endif lsr.q_adjust_from_PAC = position; break; #endif } return OK; } double llrfGetPreviousPhaseSetpt(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetPreviousPhaseSetpt: retrieved: %g\n", lsr.previous_phase_setpt)); #endif return lsr.previous_phase_setpt; #endif } return (double) ERROR; } double llrfGetPhaseSetpt(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetPhaseSetpt: retrieved: %g\n", lsr.phase_setpt)); #endif return lsr.phase_setpt; #endif } return (double) ERROR; } double llrfGetPACPhaseSetpt(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetPACPhaseSetpt: retrieved: %g\n", lsr.pac_phase_setpt)); #endif return lsr.pac_phase_setpt; #endif } return (double) ERROR; } double llrfGetISetpt(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetISetpt: retrieved: %g\n", lsr.i_setpt)); #endif return lsr.i_setpt; #endif } return (double) ERROR; } double llrfGetQSetpt(int station) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetQSetpt: retrieved: %g\n", lsr.q_setpt)); #endif return lsr.q_setpt; #endif } return (double) ERROR; } int llrfSetDebugLevel(int station, int level) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.debug_flag = level; break; #endif } return OK; } int llrfSetMinPowerThreshold(int station, double threshold) { switch (station) { #ifdef LLRF_LSR_NG case LLRF_LSR: lsr.ampl_minimum_threshold = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfSetMinPowerThreshold: set to: %g\n", lsr.ampl_minimum_threshold)); #endif break; #endif /* 2/10/9 */ #ifdef LLRF_PCAV1_NG case LLRF_PCAV1: pc1.ampl_minimum_threshold = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC1Flag, ("llrfSetMinPowerThreshold: set to %g\n", pc1.ampl_minimum_threshold)); #endif break; #endif /* 2/10/9 */ #ifdef LLRF_PCAV2_NG case LLRF_PCAV2: pc2.ampl_minimum_threshold = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC2Flag, ("llrfSetMinPowerThreshold: set to %g\n", pc2.ampl_minimum_threshold)); #endif break; #endif /* 2/10/9 */ #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: pc3.ampl_minimum_threshold = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfSetMinPowerThreshold: set to %g\n", pc3.ampl_minimum_threshold)); #endif break; #endif /* 2/10/9 */ #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: pc4.ampl_minimum_threshold = threshold; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC4Flag, ("llrfSetMinPowerThreshold: set to %g\n", pc4.ampl_minimum_threshold)); #endif break; #endif } return OK; }