11 #include <epicsTypes.h>
12 #include <epicsTime.h>
13 #include <epicsThread.h>
14 #include <epicsString.h>
15 #include <epicsTimer.h>
16 #include <epicsMutex.h>
17 #include <epicsEvent.h>
23 #include <epicsGuard.h>
25 #include <epicsExport.h>
29 static epicsThreadOnceId
onceId = EPICS_THREAD_ONCE_INIT;
63 switch( (stat >> 8) & 0xff )
138 switch( stat & (1 << (beamline - 1)) )
157 #define MAX_ASYN_BL_PARAMS 300
163 : asynPortDriver(portName,
166 asynInt32Mask | asynFloat64Mask | asynOctetMask | asynDrvUserMask,
167 asynInt32Mask | asynFloat64Mask | asynOctetMask,
175 const char *functionName =
"isisbeamDriver";
207 const char* axes =
"NSWE";
210 for(
int i=1; i<=9; ++i)
212 for(
int j=0; j<4; ++j)
214 sprintf(buff,
"SHUT_%c%d", axes[j], i);
215 createParam(buff, asynParamOctet, &
id);
216 setStringParam(
id,
"N/A");
217 m_blparams[buff] = id;
218 sprintf(buff,
"VAT_%c%d", axes[j], i);
219 createParam(buff, asynParamOctet, &
id);
220 setStringParam(
id,
"N/A");
221 m_blparams[buff] = id;
222 sprintf(buff,
"SMODE_%c%d", axes[j], i);
223 createParam(buff, asynParamOctet, &
id);
224 setStringParam(
id,
"N/A");
225 m_blparams[buff] = id;
229 if (epicsThreadCreate(
"isisbeamPoller",
230 epicsThreadPriorityMedium,
231 epicsThreadGetStackSize(epicsThreadStackMedium),
232 (EPICSTHREADFUNC)pollerThreadC,
this) == 0)
234 printf(
"%s:%s: epicsThreadCreate failure\n",
driverName, functionName);
242 return asynPortDriver::readFloat64(pasynUser, value);
252 #define LEN_BUFFER 10024
256 static const char* functionName =
"isisbeamPoller";
263 double beamts1, beamts2, beamepb1, mtempts1, htempts1, beamsynch, freqsynch, totalts1, freqts2, totalts2, demethanets2, methanets2, hydrogents2, dmodrunts2, dmodrunlimts2, beamdmodts2, muonkick, dmodannlowts2;
264 char *onts1, *offts1, *onts2, *offts2, *e1, *e2, *e3, *e4, *e5, *e6, *e7, *e8, *e9, *w1, *w2, *w3, *w4, *w5, *w6, *w7, *w8, *w9, *n1, *n2, *n3, *n4, *n5, *n6, *n7, *n8, *n9, *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8, *s9, *em1, *em2, *em3, *em4, *em5, *em6, *em7, *em8, *em9, *wm1, *wm2, *wm3, *wm4, *wm5, *wm6, *wm7, *wm8, *wm9;
265 static char time_buffer[128];
266 int c1, c2, c3, c4, c5, c6, c7, c8, c9;
290 pstm = localtime(&timer);
292 strftime(time_buffer,
sizeof(time_buffer),
"%Y-%m-%dT%H:%M:%S+0100", pstm);
293 tmp =
xml_parse(buffer,
"DMOD_RUNTIME"); dmodrunts2 = atof(tmp); free(tmp);
294 tmp =
xml_parse(buffer,
"DMOD_RUNTIME_LIM"); dmodrunlimts2 = atof(tmp); free(tmp);
295 tmp =
xml_parse(buffer,
"DMOD_UABEAM"); beamdmodts2 = atof(tmp); free(tmp);
296 tmp =
xml_parse(buffer,
"DMOD_ANNLOW1"); dmodannlowts2 = atof(tmp); free(tmp);
298 sscanf(tmp,
"%lu %lu %lu %lu %lu %lu %lu %lu %lu", &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
310 sscanf(tmp,
"%lu %lu %lu %lu %lu %lu %lu %lu %lu", &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
346 setStringParam(
P_InstTS1,
"ALF,ARGUS,CHRONUS,CRISP,EMMA,EMU,ENGINX,EVS,GEM,HIFI,HRPD,INES,IRIS,LOQ,MAPS,MARI,MERLIN,MUSR,OSIRIS,PEARL,POLARIS,"
347 "PRISMA,ROTAX,SANDALS,SURF,SXD,TOSCA,VESUVIO");
349 setStringParam(
P_InstTS2,
"CHIPIR,IMAT,INTER,LARMOR,LET,NIMROD,OFFSPEC,POLREF,SANS2D,WISH,ZOOM");
351 callParamCallbacks();
363 pstm = localtime(&timer);
365 strftime(time_buffer,
sizeof(time_buffer),
"%Y-%m-%dT%H:%M:%S+0100", pstm);
366 tmp =
xml_parse(buffer,
"BEAMT"); beamts1 = atof(tmp); free(tmp);
367 tmp =
xml_parse(buffer,
"BEAMT2"); beamts2 = atof(tmp); free(tmp);
368 tmp =
xml_parse(buffer,
"BEAME1"); beamepb1 = atof(tmp); free(tmp);
369 tmp =
xml_parse(buffer,
"MTEMP"); mtempts1 = atof(tmp); free(tmp);
370 tmp =
xml_parse(buffer,
"HTEMP"); htempts1 = atof(tmp); free(tmp);
371 tmp =
xml_parse(buffer,
"BEAMS"); beamsynch = atof(tmp); free(tmp);
372 tmp =
xml_parse(buffer,
"REPR"); freqsynch = atof(tmp); free(tmp);
373 tmp =
xml_parse(buffer,
"TS1_TOTAL"); totalts1 = atof(tmp); free(tmp);
374 tmp =
xml_parse(buffer,
"REPR2"); freqts2 = atof(tmp); free(tmp);
375 tmp =
xml_parse(buffer,
"TS2_TOTAL"); totalts2 = atof(tmp); free(tmp);
376 tmp =
xml_parse(buffer,
"T2MTEMP1"); demethanets2 = atof(tmp); free(tmp);
377 tmp =
xml_parse(buffer,
"T2MTEMP2"); methanets2 = atof(tmp); free(tmp);
378 tmp =
xml_parse(buffer,
"T2HTEMP1"); hydrogents2 = atof(tmp); free(tmp);
379 tmp =
xml_parse(buffer,
"MUONKICKER"); muonkick = atof(tmp); free(tmp);
385 sscanf(tmp,
"%lu %lu %lu %lu %lu %lu %lu %lu %lu", &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
406 sscanf(tmp,
"%lu %lu %lu %lu %lu %lu %lu %lu %lu", &c1, &c2, &c3, &c4, &c5, &c6, &c7, &c8, &c9);
427 v = atoi((
const char *)tmp);
439 v = atoi((
const char *)tmp);
466 setStringParam(
P_OnTS1, onts1);
468 setStringParam(
P_OnTS2, onts2);
530 callParamCallbacks();
536 epicsThreadSleep(3.0);
552 catch(
const std::exception& ex)
554 std::cerr <<
"isisbeamDriver failed: " << ex.what() << std::endl;
561 static const iocshArg
initArg0 = {
"portName", iocshArgString};
563 static const iocshArg *
const initArgs[] = { &initArg0 };
565 static const iocshFuncDef
initFuncDef = {
"isisbeamConfigure",
sizeof(
initArgs) /
sizeof(iocshArg*), initArgs};
char * xml_parse(const char *input_string, const char *token)
#define P_MethaneTS1String
static char * ts2_vat_status(int stat)
#define ND_BROADCAST_PORT1
#define P_BeamTS1String
ASYN driver parameter name for TS1 beam current.
int isisbeamConfigure(const char *portName)
EPICS iocsh callable function to call constructor of isisbeamDriver().
#define P_UpdateTimeString
epicsExportRegistrar(isisbeamRegister)
#define P_MethaneTS2String
isisbeamDriver(const char *portName)
Constructor for the isisbeamDriver class.
std::map< std::string, int > m_blparams
ASYN diver parameters for beamline specific information (shutter etc.)
static void pollerThreadC(void *arg)
static char * ts2_shutter_status(int stat)
static epicsThreadOnceId onceId
int receive_data_udp(SOCKET sd, char *dp, int n)
static const iocshFuncDef initFuncDef
#define P_HydrogenTS2String
#define P_BeamSynchString
virtual asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value)
static const char * driverName
int P_BeamTS1
ASYN driver parameter index for TS1 beam current (double)
#define P_BeamDmodTS2String
#define P_DmodRunTS2String
#define P_FreqSynchString
static const iocshArg initArg0
The name of the asyn driver port we will create.
static char * ts2_shutter_mode(int stat)
#define P_DmodAnnLowTS2String
epicsTimeStamp m_timestamp
static void initCOM(void *)
#define P_DeMethaneTS2String
#define P_HydrogenTS1String
Header for ISIS beam driver.
#define P_UpdateTimeTString
static void isisbeamRegister(void)
#define MAX_ASYN_BL_PARAMS
needs to be large enough to cover beamline parameters created dynamically in isisbeamDriver() ...
static const iocshArg *const initArgs[]
static void initCallFunc(const iocshArgBuf *args)
SOCKET setup_udp_socket(unsigned short port, int multicast)
#define P_OsirisCryomagString
static char * ts1_shutter_status(int stat, int beamline)
#define P_DmodRunLimTS2String