/* Add header */ #include #include #include #include #include #include /* for atan2 */ #include /* for DEBUGPRINT */ #include #include #include #include "drvLlrf.h" /* includes llrfMacros.h */ 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 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 /*============================================================================= 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_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 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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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_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 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]; break; #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]; 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, ("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]; 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, ("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]; 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, ("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]; break; #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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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_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 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]; break; #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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("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]; 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, ("llrfGetVoltageScaleFactor: invalid channel: %d for PCAV2\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]; 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, ("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]; 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, ("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]; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfAVCFlag, ("llrfGetVoltageScaleFactor: unrecognized station: %d\n", station)); #endif return (double) ERROR; } } /*============================================================================= 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 L1X AND 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 #ifdef LLRF_L1X_NG case LLRF_L1X: l1x.desired_phase = desired_phase; #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetDesiredPhase: desired phase for L1X: %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 */ /* 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]; /* 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; 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; 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; } } 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= 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 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_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: #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfGetPhaseWeightingFactor: should NOT be called for L1X\n")); #endif return (double) ERROR; 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_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 llrfGetIQWeightingFactor(int station, int channel) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetIQWeightingFactor: IQ weighting factor for station %d: channel: %d %g\n", station, channel, l1x.IQ_weighting_factor[channel])); #endif return l1x.IQ_weighting_factor[channel]; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetIQWeightingFactor: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetTotalIQWeighting(int station) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetTotalIQWeighting: total IQ weighting for station %d: %g\n", station, l1x.total_IQ_weighting)); #endif return l1x.total_IQ_weighting; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetTotalIQWeighting: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetIprim(int station, int channel) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetIprim: total phase weighting for station %d: %g\n", station, l1x.Iprim[channel])); #endif return l1x.Iprim[channel]; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetIprim: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetQprim(int station, int channel) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetQprim: total phase weighting for station %d: %g\n", station, l1x.Qprim[channel])); #endif return l1x.Qprim[channel]; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetQprim: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetI_avg(int station) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetI_avg: total phase weighting for station %d: %g\n", station, l1x.avg_I)); #endif return l1x.avg_I; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetI_avg: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetQ_avg(int station) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetQ_avg: total phase weighting for station %d: %g\n", station, l1x.avg_Q)); #endif return l1x.avg_Q; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetQ_avg: unrecognized station %d\n", station)); #endif return (double) ERROR; } } double llrfGetPhaseprim(int station) { switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfGetPhaseprim: for station %d: %g\n", station, l1x.avg_phaseprim)); #endif return l1x.avg_phaseprim; break; #endif default: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfFlag, ("llrfGetPhaseprim: unrecognized station %d\n", station)); #endif return (double) ERROR; } } int llrfSetIQWeightingFactor(int station, int channel, double IQ_weighting_factor) { #ifdef LLRF_L1X_NG int ii; #endif switch (station) { #ifdef LLRF_L1X_NG case LLRF_L1X: /* L1X HAS FB IN CH 0,1 */ /* Bounds checking on channel, specific to station */ if ((channel < 0) || (channel > 1) ) { #ifdef DEBUG_PRINT DEBUGPRINT(DP_ERROR, drvLlrfL1XFlag, ("llrfSetIQWeightingFactor: IQ weighting factor for station %d channel %d: %g\n", station, channel, l1x.IQ_weighting_factor[channel])); #endif return ERROR; } l1x.IQ_weighting_factor[channel]=IQ_weighting_factor; #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfL1XFlag, ("llrfSetIQWeightingFactor: IQ weighting factor for station %d channel %d: %g\n", station, channel, l1x.IQ_weighting_factor[channel])); #endif /* Update the total */ l1x.total_IQ_weighting=0.; for (ii=0; ii 1)) { return (double) ERROR; } return pc1.linear_phase[channel]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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; } } break; #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; } } break; #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; } } break; #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; } } break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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; } } break; #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]; break; #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]; break; #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]; break; #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; } } break; #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]; break; #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; } } break; #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; } } break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #endif #ifdef LLRF_PCAV3_NG case LLRF_PCAV3: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfTC3Flag, ("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, drvLlrfTC3Flag, ("llrfGetAmpl: ampl for station %d channel %d: %g\n", station, channel, pc4.ampl[channel])); #endif return pc4.ampl[channel]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #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]; break; #endif #ifdef LLRF_PCAV4_NG case LLRF_PCAV4: #ifdef DEBUG_PRINT DEBUGPRINT(DP_INFO, drvLlrfPC3Flag, ("llrfGetPower: power for station %d channel %d: %g\n", station, channel, pc3.power[channel])); #endif return pc4.power[channel]; break; #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 add L1X, etc 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); printf(" zeroing angle (to preserve bucket when src changes. expect 0 if source is 119): %g\n", lsr.phase_zeroing_angle); 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