Пример #1
0
int drvRFCTRL_Configure(int start, char *ip, int port)
{
	int i;

	epicsPrintf("*** RF CTRL START ***\n");

	sprintf(lhcd_rfctrl.ip, "%s", ip);
	lhcd_rfctrl.sock = set_up_tcp( ip, RFCTRL_PORT);

	if(lhcd_rfctrl.sock >= 0) lhcd_rfctrl.con_stat = 1;

	epicsPrintf("*** RF CTRL Connection OK ***\n");

	lhcd_rfctrl.mds_status = 0;
	lhcd_rfctrl.t0 = 0.0;

	epicsThreadCreate("RFCTRL", 
			epicsThreadPriorityHigh,
			epicsThreadGetStackSize(epicsThreadStackSmall),
			(EPICSTHREADFUNC)GetRFCTRL_Data_Thread, &lhcd_rfctrl);

	epicsThreadCreate("RFCTRL", 
			epicsThreadPriorityHigh,
			epicsThreadGetStackSize(epicsThreadStackSmall),
			(EPICSTHREADFUNC)PutRFCTRL_MDS_Thread, &lhcd_rfctrl);


	return 0;
}
Пример #2
0
int
Run_mode(acqMaster_t *master)
{
	acqEvent_t *ev;
	acqScan_t *sc;
	char threadName[50];

	master->acqRuns = 1;
	master->globalShutdown = 0;
	master->globalPause = 0;

	for( ev = first_acqEvent(master); ev ; ev = next_acqEvent(ev) )
	{
	 	snprintf(threadName, sizeof threadName, "event_%s", ev->eventName);
		ev->outputCount = 0;
		ev->state = AS_STARTUP;
	 	ev->threadID = epicsThreadCreate(threadName, epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)runEvent, ev);
	}

	for( sc = first_acqScan(master) ; sc ; sc = next_acqScan(sc) )
	{
	 	snprintf(threadName, sizeof threadName, "scan_%s", sc->scanName);
		sc->state = AS_STARTUP;
	 	sc->threadID = epicsThreadCreate(threadName, epicsThreadPriorityMedium, epicsThreadGetStackSize(epicsThreadStackMedium), (EPICSTHREADFUNC)runAcqScan, sc);
	}

	master->putMode(master,  AS_RUNUP);
	master->messageAdd(master, "Run Mode");
	return 0;
}
Пример #3
0
static void errlogInitPvt(void *arg)
{
    struct initArgs *pconfig = (struct initArgs *) arg;
    epicsThreadId tid;

    pvtData.errlogInitFailed = TRUE;
    pvtData.buffersize = pconfig->bufsize;
    pvtData.maxMsgSize = pconfig->maxMsgSize;
    pvtData.msgNeeded = adjustToWorstCaseAlignment(pvtData.maxMsgSize +
        sizeof(msgNode));
    ellInit(&pvtData.listenerList);
    ellInit(&pvtData.msgQueue);
    pvtData.toConsole = TRUE;
    pvtData.console = stderr;
    pvtData.waitForWork = epicsEventMustCreate(epicsEventEmpty);
    pvtData.listenerLock = epicsMutexMustCreate();
    pvtData.msgQueueLock = epicsMutexMustCreate();
    pvtData.waitForFlush = epicsEventMustCreate(epicsEventEmpty);
    pvtData.flush = epicsEventMustCreate(epicsEventEmpty);
    pvtData.flushLock = epicsMutexMustCreate();
    pvtData.waitForExit = epicsEventMustCreate(epicsEventEmpty);
    pvtData.pbuffer = callocMustSucceed(1, pvtData.buffersize,
        "errlogInitPvt");

    errSymBld();    /* Better not to do this lazily... */

    tid = epicsThreadCreate("errlog", epicsThreadPriorityLow,
        epicsThreadGetStackSize(epicsThreadStackSmall),
        (EPICSTHREADFUNC)errlogThread, 0);
    if (tid) {
        pvtData.errlogInitFailed = FALSE;
    }
}
Пример #4
0
long dbtpn(char *pname, char *pvalue)
{
    struct dbChannel *chan;
    tpnInfo *ptpnInfo;
    processNotify *ppn=NULL;

    chan = dbChannelCreate(pname);
    if (!chan) {
        printf("dbtpn: No such channel");
        return -1;
    }
    
    ppn = dbCalloc(1, sizeof(processNotify));
    ppn->requestType = pvalue ? putProcessRequest : processGetRequest;
    ppn->chan = chan;
    ppn->putCallback = putCallback;
    ppn->getCallback = getCallback;
    ppn->doneCallback = doneCallback;

    ptpnInfo = dbCalloc(1, sizeof(tpnInfo));
    ptpnInfo->ppn = ppn;
    ptpnInfo->callbackDone = epicsEventCreate(epicsEventEmpty);
    strncpy(ptpnInfo->buffer, pvalue, 80);
    ptpnInfo->buffer[79] = 0;

    ppn->usrPvt = ptpnInfo;
    epicsThreadCreate("dbtpn", epicsThreadPriorityHigh,
        epicsThreadGetStackSize(epicsThreadStackMedium), tpnThread, ptpnInfo);
    return 0;
}
/// Constructor for the #NetShrVarDriver class.
/// Calls constructor for the asynPortDriver base class and sets up driver parameters.
///
/// @param[in] netvarint  interface pointer created by NetShrVarConfigure()
/// @param[in] poll_ms  @copydoc initArg0
/// @param[in] portName @copydoc initArg3
NetShrVarDriver::NetShrVarDriver(NetShrVarInterface* netvarint, int poll_ms, const char *portName) 
	: asynPortDriver(portName, 
	0, /* maxAddr */ 
	static_cast<int>(netvarint->nParams()),
	asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask | asynDrvUserMask, /* Interface mask */
	asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask,  /* Interrupt mask */
	ASYN_CANBLOCK, /* asynFlags.  This driver can block but it is not multi-device */
	1, /* Autoconnect */
	0, /* Default priority */
	0),	/* Default stack size*/
	m_netvarint(netvarint), m_poll_ms(poll_ms), m_shutting_down(false)
{
	const char *functionName = "NetShrVarDriver";
	
	m_netvarint->createParams(this);
	if (poll_ms == 0)
	{
	    std::cerr << "Warning: driver is not polling for buffered reads, only subscribers will see changes" << std::endl;
	}
    epicsAtExit(epicsExitFunc, this);

	// Create the thread for background tasks (not used at present, could be used for I/O intr scanning) 
	if (epicsThreadCreate("NetShrVarDriverTask",
		epicsThreadPriorityMedium,
		epicsThreadGetStackSize(epicsThreadStackMedium),
		(EPICSTHREADFUNC)NetShrVarTask, this) == 0)
	{
		printf("%s:%s: epicsThreadCreate failure\n", driverName, functionName);
		return;
	}
}
/// Constructor for the isisdaeDriver class.
/// Calls constructor for the asynPortDriver base class.
/// \param[in] dcomint DCOM interface pointer created by lvDCOMConfigure()
/// \param[in] portName @copydoc initArg0
daedataDriver::daedataDriver(const char *portName, const char* host) 
   : asynPortDriver(portName, 
                    0, /* maxAddr */ 
                    NUM_ISISDAE_PARAMS,
                    asynInt32Mask | asynInt32ArrayMask | asynDrvUserMask, /* Interface mask */
                    asynInt32Mask | asynInt32ArrayMask,  /* Interrupt mask */
                    ASYN_CANBLOCK , /* asynFlags.  This driver can block but it is not multi-device */
                    1, /* Autoconnect */
                    0, /* Default priority */
                    0)	/* Default stack size*/					
{
    const char *functionName = "daedataDriver";
//	epicsThreadOnce(&onceId, initCOM, NULL);

	m_udp = new DAEDataUDP(host);

	createParam(P_SVN_VERSIONString, asynParamInt32, &P_SVN_VERSION);
	createParam(P_FIRMWARE_VERSIONString, asynParamInt32, &P_FIRMWARE_VERSION);
	createParam(P_CHANNEL_POSITIONString, asynParamInt32Array, &P_CHANNEL_POSITION);

    // Create the thread for background tasks (not used at present, could be used for I/O intr scanning) 
    if (epicsThreadCreate("isisdaePoller",
                          epicsThreadPriorityMedium,
                          epicsThreadGetStackSize(epicsThreadStackMedium),
                          (EPICSTHREADFUNC)pollerThreadC, this) == 0)
    {
        printf("%s:%s: epicsThreadCreate failure\n", driverName, functionName);
        return;
    }
}
Пример #7
0
/* epicsShareFunc int drvSNMPConnInit(const char *version, const char *hostaddr, const char *username, const char *authpass, const char*privpass) */
epicsShareFunc int drvSNMPConnInit(char *version, char *hostaddr, char *username, char *authpass, char*privpass)
{
  printf("------------------------------------------------\n");
  printf("degug line\n");
  printf("------------------------------------------------\n");
  printf("version: %s, hostaddr: %s, username: %s, authpass: %s, privpass: %s\n", 
	 version, hostaddr, username, authpass, privpass);
  printf("------------------------------------------------\n");

  
  snmpinfo = (SNMP_INFO *)malloc(sizeof(SNMP_INFO));

  strcpy(&snmpinfo->version, version);
  strcpy(&snmpinfo->hostaddr, hostaddr);
  strcpy(&snmpinfo->username, username);
  strcpy(&snmpinfo->authpass, authpass);
  strcpy(&snmpinfo->privpass, privpass);
  strcpy(&snmpinfo->msg,"Test Message");

  gsnmpInfo = snmpinfo;
  memcpy(gsnmpInfo, snmpinfo, sizeof(SNMP_INFO));

  printf("version: %s, hostaddr: %s, username: %s, authpass: %s, privpass: %s\n",
  	 snmpinfo->version, snmpinfo->hostaddr, snmpinfo->username, snmpinfo->authpass, snmpinfo->privpass);

  ellInit(&devSNMPList);
  epicsThreadCreate("drvSNMPConnInit", epicsThreadPriorityHigh, epicsThreadGetStackSize(epicsThreadStackSmall),
		    (EPICSTHREADFUNC)devSNMPScanThread,NULL);

  return 0;
};
/**
 *  @ingroup asub_functions
 *  @param[in] prec Pointer to aSub record
 */
static long iocExit(aSubRecord *prec) 
{
    long stat = *(long*)prec->a;
	epicsThreadCreate("iocExit", epicsThreadPriorityMedium, 
	                  epicsThreadGetStackSize(epicsThreadStackMedium), exitFunc, (void*)stat);
    return 0; /* process output links */
}
Пример #9
0
int epicsShareAPI asInitAsyn(ASDBCALLBACK *pcallback)
{
    if(!pacf) return(0);
    if(asInitTheadId) {
	errMessage(-1,"asInit: asInitTask already active");
	if(pcallback) {
	    pcallback->status = S_asLib_InitFailed;
	    callbackRequest(&pcallback->callback);
	}
	return(-1);
    }
    asInitTheadId = epicsThreadCreate("asInitTask",
        (epicsThreadPriorityCAServerHigh + 1),
        epicsThreadGetStackSize(epicsThreadStackBig),
        (EPICSTHREADFUNC)asInitTask,(void *)pcallback);
    if(asInitTheadId==0) {
	errMessage(0,"asInit: epicsThreadCreate Error");
	if(pcallback) {
	    pcallback->status = S_asLib_InitFailed;
	    callbackRequest(&pcallback->callback);
	}
	asInitTheadId = 0;
    }
    return(0);
}
Пример #10
0
/*
static void print_channelConfig(drvM6802_taskConfig *ptaskConfig, int level)
{
	drvM6802_channelConfig *pchannelConfig;

	pchannelConfig = (drvM6802_channelConfig*) ellFirst(ptaskConfig->pchannelConfig);
	while(pchannelConfig) {
		epicsPrintf("    %s", pchannelConfig->chanName);
		if(level>2) {
			epicsPrintf("\tChannel, status: 0x%x, index: %d, gain: %f", 
				    pchannelConfig->channelStatus,
				    pchannelConfig->chanIndex,
				    pchannelConfig->gain );
			if(level>3) {
				epicsPrintf(", conv.T: %f usec", pchannelConfig->conversionTime_usec);
			}

		}
		epicsPrintf("\n");
  		pchannelConfig = (drvM6802_channelConfig*) ellNext(&pchannelConfig->node);
	}

	return;

}
*/
static drvM6802_controlThreadConfig*  make_controlThreadConfig(drvM6802_taskConfig *ptaskConfig)
{
	drvM6802_controlThreadConfig *pcontrolThreadConfig  = NULL;

	pcontrolThreadConfig  = (drvM6802_controlThreadConfig*)malloc(sizeof(drvM6802_controlThreadConfig));
	if(!pcontrolThreadConfig) return pcontrolThreadConfig; 

	sprintf(pcontrolThreadConfig->threadName, "%s_ctrl", ptaskConfig->taskName);
	
	pcontrolThreadConfig->threadPriority = epicsThreadPriorityLow;
	pcontrolThreadConfig->threadStackSize = epicsThreadGetStackSize(epicsThreadStackSmall);
	pcontrolThreadConfig->threadFunc      = (EPICSTHREADFUNC) controlThreadFunc;
	pcontrolThreadConfig->threadParam     = (void*) ptaskConfig;

	pcontrolThreadConfig->threadQueueId   = epicsMessageQueueCreate(100,sizeof(controlThreadQueueData));

	epicsThreadCreate(pcontrolThreadConfig->threadName,
			  pcontrolThreadConfig->threadPriority,
			  pcontrolThreadConfig->threadStackSize,
			  (EPICSTHREADFUNC) pcontrolThreadConfig->threadFunc,
			  (void*) pcontrolThreadConfig->threadParam);


	return pcontrolThreadConfig;
}
Пример #11
0
static drvM6802_controlThreadConfig*  make_fpdpThreadConfig(drvM6802_taskConfig *ptaskConfig)
{
	drvM6802_controlThreadConfig *pfpdpThreadConfig  = NULL;

	pfpdpThreadConfig  = (drvM6802_controlThreadConfig*)malloc(sizeof(drvM6802_controlThreadConfig));
	if(!pfpdpThreadConfig) return pfpdpThreadConfig; 

	sprintf(pfpdpThreadConfig->threadName, "FPDP_ctrl");	
	pfpdpThreadConfig->threadPriority = epicsThreadPriorityHigh;
	pfpdpThreadConfig->threadStackSize = epicsThreadGetStackSize(epicsThreadStackBig);
	pfpdpThreadConfig->threadFunc      = (EPICSTHREADFUNC) FPDPthreadFunc;
	pfpdpThreadConfig->threadParam     = (void*) ptaskConfig;

	pfpdpThreadConfig->threadQueueId   = epicsMessageQueueCreate(100,sizeof(bufferingThreadQueueData));
	bufferingQueueID = pfpdpThreadConfig->threadQueueId;
/*	pfpdpThreadConfig->threadQueueId   = 0;	*/
/*	if(pfpdpThreadConfig->threadQueueId) ptaskConfig->taskStatus |= TASK_CONTQUEUE; */

	epicsThreadCreate(pfpdpThreadConfig->threadName,
			  pfpdpThreadConfig->threadPriority,
			  pfpdpThreadConfig->threadStackSize,
			  (EPICSTHREADFUNC) pfpdpThreadConfig->threadFunc,
			  (void*) pfpdpThreadConfig->threadParam);


	return pfpdpThreadConfig;
}
Пример #12
0
motorSimController::motorSimController(const char *portName, int numAxes, int priority, int stackSize)
  :  asynMotorController(portName, numAxes, NUM_SIM_CONTROLLER_PARAMS, 
                         asynInt32Mask | asynFloat64Mask, 
                         asynInt32Mask | asynFloat64Mask,
                         ASYN_CANBLOCK | ASYN_MULTIDEVICE, 
                         1, // autoconnect
                         priority, stackSize)
{
  int axis;
  motorSimControllerNode *pNode;
  
  if (!motorSimControllerListInitialized) {
    motorSimControllerListInitialized = 1;
    ellInit(&motorSimControllerList);
  }
  
  // We should make sure this portName is not already in the list */
  pNode = (motorSimControllerNode*) calloc(1, sizeof(motorSimControllerNode));
  pNode->portName = epicsStrDup(portName);
  pNode->pController = this;
  ellAdd(&motorSimControllerList, (ELLNODE *)pNode);

  if (numAxes < 1 ) numAxes = 1;
  numAxes_ = numAxes;
  this->movesDeferred_ = 0;
  for (axis=0; axis<numAxes; axis++) {
    new motorSimAxis(this, axis, DEFAULT_LOW_LIMIT, DEFAULT_HI_LIMIT, DEFAULT_HOME, DEFAULT_START);
    setDoubleParam(axis, this->motorPosition_, DEFAULT_START);
  }

  this->motorThread_ = epicsThreadCreate("motorSimThread", 
                                         epicsThreadPriorityLow,
                                         epicsThreadGetStackSize(epicsThreadStackMedium),
                                         (EPICSTHREADFUNC) motorSimTaskC, (void *) this);
}
Пример #13
0
long epicsShareAPI dbtpn(char	*pname,char *pvalue)
{
    long	status;
    tpnInfo     *ptpnInfo;
    DBADDR	*pdbaddr=NULL;
    putNotify	*ppn=NULL;
    char	*psavevalue;
    int		len;

    len = strlen(pvalue);
    /*allocate space for value immediately following DBADDR*/
    pdbaddr = dbCalloc(1,sizeof(DBADDR) + len+1);
    psavevalue = (char *)(pdbaddr + 1);
    strcpy(psavevalue,pvalue);
    status = dbNameToAddr(pname,pdbaddr);
    if(status) {
	errMessage(status, "dbtpn: dbNameToAddr");
	free((void *)pdbaddr);
	return(-1);
    }
    ppn = dbCalloc(1,sizeof(putNotify));
    ppn->paddr = pdbaddr;
    ppn->pbuffer = psavevalue;
    ppn->nRequest = 1;
    ppn->dbrType = DBR_STRING;
    ppn->userCallback = dbtpnCallback;
    ptpnInfo = dbCalloc(1,sizeof(tpnInfo));
    ptpnInfo->ppn = ppn;
    ptpnInfo->callbackDone = epicsEventCreate(epicsEventEmpty);
    ppn->usrPvt = ptpnInfo;
    epicsThreadCreate("dbtpn",epicsThreadPriorityHigh,
        epicsThreadGetStackSize(epicsThreadStackMedium),
        tpnThread,ptpnInfo);
    return(0);
}
Пример #14
0
static drvM6802_controlThreadConfig*  make_ringThreadConfig(drvM6802_taskConfig *ptaskConfig)
{
	drvM6802_controlThreadConfig *pringThreadConfig  = NULL;

	pringThreadConfig  = (drvM6802_controlThreadConfig*)malloc(sizeof(drvM6802_controlThreadConfig));
	if(!pringThreadConfig) return pringThreadConfig; 

	sprintf(pringThreadConfig->threadName, "RING_ctrl");	
	pringThreadConfig->threadPriority = epicsThreadPriorityLow;
	pringThreadConfig->threadStackSize = epicsThreadGetStackSize(epicsThreadStackBig);
	pringThreadConfig->threadFunc      = (EPICSTHREADFUNC) RingThreadFunc;
	pringThreadConfig->threadParam     = (void*) ptaskConfig;

/*	pringThreadConfig->threadQueueId   = epicsMessageQueueCreate(100,sizeof(controlThreadQueueData)); */
	pringThreadConfig->threadQueueId   = 0; 	/* we don't need this */
/*	if(pringThreadConfig->threadQueueId) ptaskConfig->taskStatus |= TASK_CONTQUEUE; */

	epicsThreadCreate(pringThreadConfig->threadName,
			  pringThreadConfig->threadPriority,
			  pringThreadConfig->threadStackSize,
			  (EPICSTHREADFUNC) pringThreadConfig->threadFunc,
			  (void*) pringThreadConfig->threadParam);


	return pringThreadConfig;
}
Пример #15
0
long mdsPlusPut( genSubRecord *pgsub )
{
    /*char *buf = (char *)calloc(40, sizeof(char));*/
    int i;
    int nextPos = 0;

    /* if notified new pulse set taskPos = 0 and notify next access will not be new */
    if(notifyNewPulse) {
        taskPos = 0;
        notifyNewPulse = 0;
    }
    /* if startMdsPut is active, do nothing */
    if(startMdsPut) {
        return(0);
    }
 
    nextPos = taskPos;
    pmdsPutData[nextPos].plinkout = pgsub->outa;

    /*buf = (char *)pgsub->a;
    sscanf(buf,"%s %s",pmdsPutData[nextPos].serverID, pmdsPutData[nextPos].treeID);
    buf = (char *)pgsub->g;
    sscanf(buf,"%s",pmdsPutData[nextPos].tagName);*/
    sscanf(pgsub->a,"%s %s",pmdsPutData[nextPos].serverID, pmdsPutData[nextPos].treeID);
    sscanf(pgsub->g,"%s",pmdsPutData[nextPos].tagName);
    /* check shot number */
    pmdsPutData[nextPos].shotID = *((unsigned long *)pgsub->b);
    pmdsPutData[nextPos].noRd = *((unsigned long *)pgsub->c);
    /* check dT and offT */
    pmdsPutData[nextPos].dT = *((float *)pgsub->d);
    pmdsPutData[nextPos].offT = *((float *)pgsub->e);
    /* check the node is valid */
    pmdsPutData[nextPos].putFlag = *((unsigned long *)pgsub->h);

    if(genSubDebug > 0)
        printf("genSub: Ready mdsPlusPut() shotID=%lu,treeID=%s,serverID=%s,tagName=%s, noRd=%lu\n",
                     pmdsPutData[nextPos].shotID, pmdsPutData[nextPos].treeID, pmdsPutData[nextPos].serverID, 
                        pmdsPutData[nextPos].tagName, pmdsPutData[nextPos].noRd);
    /* alocate data memory by noRd */
    /*pmdsPutData[nextPos].dataArray = (float *)calloc(pmdsPutData[nextPos].noRd, sizeofTypes[pgsub->ftf]);*/
    pmdsPutData[nextPos].dataArray = (float *)realloc(pmdsPutData[nextPos].dataArray, 
                                                        pmdsPutData[nextPos].noRd * sizeofTypes[pgsub->ftf]);
    /* put data */
    memcpy(pmdsPutData[nextPos].dataArray, pgsub->f, pmdsPutData[nextPos].noRd*sizeof(sizeofTypes[pgsub->ftf]));

    /* if taskPos is equal to the numNode-1, start mdsput and notify new pulse for next access.*/
    if(taskPos == numNode - 1 ) {
        notifyNewPulse = 1;
        startMdsPut = 1;
        epicsThreadCreate("mdsPlusPutTask",
                      epicsThreadPriorityLow,
                      epicsThreadGetStackSize(epicsThreadStackMedium),
                      (EPICSTHREADFUNC) mdsPlusPut_Task,
                      0);
    } else {
        taskPos = (taskPos+1)&0xf;
    }
    /*free(buf);*/
    return(pmdsPutData[nextPos].noRd);
}
Пример #16
0
void ClockTime_Init(int synchronize)
{
    int firstTime = 0;

    epicsThreadOnce(&onceId, ClockTime_InitOnce, &firstTime);

    if (synchronize == CLOCKTIME_SYNC) {
        if (ClockTimePvt.synchronize == CLOCKTIME_NOSYNC) {
            /* Start synchronizing */
            ClockTimePvt.synchronize = synchronize;

            epicsThreadCreate("ClockTimeSync", epicsThreadPriorityHigh,
                epicsThreadGetStackSize(epicsThreadStackSmall),
                ClockTimeSync, NULL);
        }
        else {
            /* No change, sync thread should already be running */
        }
    }
    else {
        if (ClockTimePvt.synchronize == CLOCKTIME_SYNC) {
            /* Turn off synchronization thread */
            ClockTime_Shutdown(NULL);
        }
        else {
            /* No synchronization thread */
            if (firstTime)
                ClockTimeGetCurrent(&ClockTimePvt.startTime);
        }
    }
}
Пример #17
0
//////////////////////////////////////////////////////////////////////////////////////////////////
//																								//
//	void CLeyboldSimPortDriver::octetConnectionCallback(										//
//		void *drvPvt, asynUser *pasynUser, char *portName, size_t len, int eomReason)			//
//																								//
//	Description:																				//
//		static method, callback is invoked when a client connects.								//
//		NB, one thread for each simulated pump connection.										//
//																								//
//////////////////////////////////////////////////////////////////////////////////////////////////
void CLeyboldSimPortDriver::octetConnectionCallback(void *drvPvt, asynUser *pasynUser, char *portName, 
                               size_t len, int eomReason)
{
	CLeyboldSimPortDriver* This = reinterpret_cast<CLeyboldSimPortDriver*>(drvPvt);
    // Create a new thread to communicate with this port
	This->m_Threads.push_back(new epicsThread(*This->m_ThreadRunable, portName, epicsThreadGetStackSize(epicsThreadStackSmall)));
	(*This->m_Threads.rbegin())->start();
}
Пример #18
0
/** Constructor for the testErrors class.
  * Calls constructor for the asynPortDriver base class.
  * \param[in] portName The name of the asyn port driver to be created. */
testErrors::testErrors(const char *portName) 
   : asynPortDriver(portName, 
                    1, /* maxAddr */ 
                    (int)NUM_PARAMS,
                     /* Interface mask */
                    asynInt32Mask       | asynFloat64Mask    | asynUInt32DigitalMask | asynOctetMask | 
                      asynInt8ArrayMask | asynInt16ArrayMask | asynInt32ArrayMask    | asynFloat32ArrayMask | asynFloat64ArrayMask |
                      asynOptionMask    | asynEnumMask      | asynDrvUserMask,
                    /* Interrupt mask */
                    asynInt32Mask       | asynFloat64Mask    | asynUInt32DigitalMask | asynOctetMask | 
                      asynInt8ArrayMask | asynInt16ArrayMask | asynInt32ArrayMask    | asynFloat32ArrayMask | asynFloat64ArrayMask |
                      asynEnumMask,
                    0, /* asynFlags.  This driver does not block and it is not multi-device, so flag is 0 */
                    1, /* Autoconnect */
                    0, /* Default priority */
                    0) /* Default stack size*/    
{
    asynStatus status;
    int i;
    const char *functionName = "testErrors";

    createParam(P_StatusReturnString,       asynParamInt32,         &P_StatusReturn);
    createParam(P_EnumOrderString,          asynParamInt32,         &P_EnumOrder);
    createParam(P_Int32ValueString,         asynParamInt32,         &P_Int32Value);
    createParam(P_Float64ValueString,       asynParamFloat64,       &P_Float64Value);
    createParam(P_UInt32DigitalValueString, asynParamUInt32Digital, &P_UInt32DigitalValue);
    createParam(P_OctetValueString,         asynParamOctet,         &P_OctetValue);
    createParam(P_Int8ArrayValueString,     asynParamInt8Array,     &P_Int8ArrayValue);
    createParam(P_Int16ArrayValueString,    asynParamInt16Array,    &P_Int16ArrayValue);
    createParam(P_Int32ArrayValueString,    asynParamInt32Array,    &P_Int32ArrayValue);
    createParam(P_Float32ArrayValueString,  asynParamFloat32Array,  &P_Float32ArrayValue);
    createParam(P_Float64ArrayValueString,  asynParamFloat64Array,  &P_Float64ArrayValue);
    
    for (i=0; i<MAX_INT32_ENUMS; i++) {
        int32EnumStrings_[i] = (char*)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
    }
    for (i=0; i<MAX_UINT32_ENUMS; i++) {
        uint32EnumStrings_[i] = (char*)calloc(MAX_ENUM_STRING_SIZE, sizeof(char));
    }
    setIntegerParam(P_StatusReturn, asynSuccess);
    setIntegerParam(P_Int32Value, 0);
    setDoubleParam(P_Float64Value, 0.0);
    setIntegerParam(P_EnumOrder, 0);
    setEnums();
    // Need to force callbacks with the interruptMask once 
    setUIntDigitalParam(P_UInt32DigitalValue, (epicsUInt32)0x0, 0xFFFFFFFF, 0xFFFFFFFF);
    
    /* Create the thread that computes the waveforms in the background */
    status = (asynStatus)(epicsThreadCreate("testErrorsTask",
                          epicsThreadPriorityMedium,
                          epicsThreadGetStackSize(epicsThreadStackMedium),
                          (EPICSTHREADFUNC)::callbackTask,
                          this) == NULL);
    if (status) {
        printf("%s:%s: epicsThreadCreate failure\n", driverName, functionName);
        return;
    }
}
Пример #19
0
/* (Re-)connect to IOC,
 * (Re-)start scan tasks, one per PLC.
 * Returns number of tasks spawned.
 */
int drvEtherIP_restart()
{
    PLC    *plc;
    char   taskname[20];
    int    tasks = 0;
    size_t len;

    if (drvEtherIP_private.lock == 0) return 0;
    epicsMutexLock(drvEtherIP_private.lock);

    if (!databaseIsReady) {
        epicsMutexUnlock(drvEtherIP_private.lock);
        for (plc = DLL_first(PLC,&drvEtherIP_private.PLCs);
             plc;  plc = DLL_next(PLC,plc))
        {
            if (plc->name)
            {
                EIP_printf(4, "drvEtherIP: Delaying launch of scan task for PLC '%s' until database ready\n",
                   plc->name);
            }
        }
        return 0;
    }

    for (plc = DLL_first(PLC,&drvEtherIP_private.PLCs);
         plc;  plc = DLL_next(PLC,plc))
    {
        /* block scan task (if running): */
        epicsMutexLock(plc->lock);
        /* restart the connection:
         * disconnect, PLC_scan_task will reconnect */
        disconnect_PLC(plc);
        /* check the scan task */
        if (plc->scan_task_id==0)
        {
            len = strlen(plc->name);
            if (len > 16)
                len = 16;
            taskname[0] = 'E';
            taskname[1] = 'I';
            taskname[2] = 'P';
            memcpy(&taskname[3], plc->name, len);
            taskname[len+3] = '\0';
            plc->scan_task_id = epicsThreadCreate(
              taskname,
              epicsThreadPriorityHigh,
              epicsThreadGetStackSize(epicsThreadStackMedium),
              (EPICSTHREADFUNC)PLC_scan_task,
              (void *)plc);
            EIP_printf(5, "drvEtherIP: launch scan task for PLC '%s'\n",
                       plc->name);
            ++tasks;
        }
        epicsMutexUnlock(plc->lock);
    }
    epicsMutexUnlock(drvEtherIP_private.lock);
    return tasks;
}
Пример #20
0
ipAddrToAsciiEnginePrivate::ipAddrToAsciiEnginePrivate () :
    thread ( *this, "ipToAsciiProxy",
        epicsThreadGetStackSize(epicsThreadStackBig),
        epicsThreadPriorityLow ),
    pCurrent ( 0 ), cancelPendingCount ( 0u ), exitFlag ( false ),  
    callbackInProgress ( false )
{
    this->thread.start (); // start the thread
}
Пример #21
0
static void exitLaterOnceFunc(void *raw)
{
    int *status = raw;
    exitLaterStatus = *status;
    epicsThreadMustCreate("exitLater",
                      epicsThreadPriorityLow,
                      epicsThreadGetStackSize(epicsThreadStackSmall),
                      &exitNow, NULL);
}
timerQueueActive ::
    timerQueueActive ( RefMgr & refMgr, 
        bool okToShareIn, unsigned priority ) :
    _refMgr ( refMgr ), queue ( *this ), thread ( *this, "timerQueue", 
        epicsThreadGetStackSize ( epicsThreadStackMedium ), priority ),
    sleepQuantum ( epicsThreadSleepQuantum() ), okToShare ( okToShareIn ), 
    exitFlag ( false ), terminateFlag ( false )
{
}
Пример #23
0
int createControllerHandler (ST_STD_device *pSTDdev)
{
	epicsThreadCreate ("ctrl_recv",
			epicsThreadPriorityHigh,
			epicsThreadGetStackSize(epicsThreadStackMedium),
			(EPICSTHREADFUNC) ctrl_comm_handler,
			(void*)pSTDdev);

	return WR_OK;
}
Пример #24
0
int createRfmHandler (ST_STD_device *pSTDdev)
{
	epicsThreadCreate ("rfm_recv",
			epicsThreadPriorityHigh,
			epicsThreadGetStackSize(epicsThreadStackMedium),
			(EPICSTHREADFUNC) kstar_rfm_handler,
			(void*)pSTDdev);

	return WR_OK;
}
Пример #25
0
void epicsThreadPoolConfigDefaults(epicsThreadPoolConfig *opts)
{
    memset(opts, 0, sizeof(*opts));
    opts->maxThreads = epicsThreadGetCPUs();
    opts->workerStack = epicsThreadGetStackSize(epicsThreadStackSmall);

    if (epicsThreadLowestPriorityLevelAbove(epicsThreadPriorityCAServerHigh, &opts->workerPriority)
            != epicsThreadBooleanStatusSuccess)
        opts->workerPriority = epicsThreadPriorityMedium;
}
Пример #26
0
static int testInit(const char *port,int addr,
    cmdInfo **ppcmdInfo, threadInfo **ppthreadInfo,int ind,FILE *file)
{
    cmdInfo    *pcmdInfo;
    threadInfo *pthreadInfo;
    asynUser   *pasynUser;
    asynStatus status;
    asynInterface *pasynInterface;
    size_t     size;

    pcmdInfo = (cmdInfo *)pasynManager->memMalloc(sizeof(cmdInfo));
    memset(pcmdInfo,0,sizeof(cmdInfo));
    *ppcmdInfo = pcmdInfo;
    size = sizeof(threadInfo) + (strlen(port)+ 1) + (strlen(thread) + 2);
    pthreadInfo = (threadInfo *)pasynManager->memMalloc(size);
    memset(pthreadInfo,0,sizeof(threadInfo));
    pthreadInfo->size = size;
    *ppthreadInfo = pthreadInfo;
    pthreadInfo->portName = (char *)(pthreadInfo +1);
    strcpy(pthreadInfo->portName,port);
    pthreadInfo->threadName = pthreadInfo->portName
                              + strlen(pthreadInfo->portName) + 1;
    sprintf(pthreadInfo->threadName,"%s%1.1d",thread,ind);
    pcmdInfo->callbackDone = epicsEventMustCreate(epicsEventEmpty);
    pthreadInfo->work = epicsEventMustCreate(epicsEventEmpty);
    pthreadInfo->done = epicsEventMustCreate(epicsEventEmpty);
    pthreadInfo->tid = epicsThreadCreate(pthreadInfo->threadName,
        epicsThreadPriorityHigh,
        epicsThreadGetStackSize(epicsThreadStackMedium),
        (EPICSTHREADFUNC)workThread,pthreadInfo);
    if(!pthreadInfo->tid) {
        fprintf(pcmdInfo->file,"epicsThreadCreate failed\n");
        return -1;
    }
    pcmdInfo->pasynUser = pasynManager->createAsynUser(
        workCallback,timeoutCallback);
    pasynUser = pcmdInfo->pasynUser;
    pasynUser->userPvt = pcmdInfo;
    status = pasynManager->connectDevice(pasynUser,port,addr);
    if(status!=asynSuccess) {
        fprintf(pcmdInfo->file,"connectDevice failed %s\n",pasynUser->errorMessage);
        return -1;
    }
    pasynInterface = pasynManager->findInterface(pasynUser, asynCommonType, 1);
    if(!pasynInterface) {
        fprintf(pcmdInfo->file,"can't find asynCommon\n");
        return -1;
    }
    pcmdInfo->pasynCommon = (asynCommon *) pasynInterface->pinterface;
    pcmdInfo->asynCommonPvt = pasynInterface->drvPvt;
    pcmdInfo->file = file;
    pcmdInfo->pthreadInfo = pthreadInfo;
    pthreadInfo->pcmdInfo = pcmdInfo;
    return 0;
}
Пример #27
0
IRQPoller::IRQPoller(pollerFN fn, void *arg, double period)
    :done(false)
    ,period(0.1)
    ,fn(fn)
    ,arg(arg)
    ,runner(*this, "IRQPoller",
            epicsThreadGetStackSize(epicsThreadStackBig),
            epicsThreadPriorityHigh)
{
    runner.start();
}
Пример #28
0
void RpcServer::startListener()
{
    if (destroyed) {
        throw InvalidState("Invalid state: server has been shutdown and cannot be restarted.");
    }

    // One must call PyEval_InitThreads() in the main thread
    // to initialize thread state, which is needed for proper functioning
    // of PyGILState_Ensure()/PyGILState_Release().
    PyGilManager::evalInitThreads();
    epicsThreadCreate("RpcServerListenerThread", epicsThreadPriorityLow, epicsThreadGetStackSize(epicsThreadStackSmall), (EPICSTHREADFUNC)listenerThread, this);
}
Пример #29
0
void dbCaLinkInit(void)
{
    dbServiceIOInit();
    dbCaLinkInitIsolated();
    startStopEvent = epicsEventMustCreate(epicsEventEmpty);
    dbCaCtl = ctlPause;

    epicsThreadCreate("dbCaLink", epicsThreadPriorityMedium,
        epicsThreadGetStackSize(epicsThreadStackBig),
        dbCaTask, NULL);
    epicsEventMustWait(startStopEvent);
}
Пример #30
0
static void initOnce(void)
{
    if ((onceQ = epicsRingPointerCreate(onceQueueSize)) == NULL) {
        cantProceed("initOnce: Ring buffer create failed\n");
    }
    onceSem = epicsEventMustCreate(epicsEventEmpty);
    onceTaskId = epicsThreadCreate("scanOnce",
        epicsThreadPriorityScanLow + nPeriodic,
        epicsThreadGetStackSize(epicsThreadStackBig), onceTask, 0);

    epicsEventWait(startStopEvent);
}