예제 #1
0
static int countCvtRecords(void)
{
    DBENTRY dbentry;
    extern DBBASE *pdbbase;
    int result = 0;
    long status;

    dbInitEntry(pdbbase, &dbentry);
    status = dbFindRecordType(&dbentry,"cvt");
    if (!status) {
        result = dbGetNRecords(&dbentry);
    }
    dbFinishEntry(&dbentry);
    return result;
}
예제 #2
0
static long ai_init(int pass)
{
    long i;

    if (pass) return 0;

    /* Create timers */
    for (i = 0; i < TOTAL_TYPES; i++) {
        scanIoInit(&scan[i].ioscan);
        scan[i].wd = wdogCreate(scan_time, i);
        scan[i].total = 0;
        scan[i].on = 0;
        scan[i].rate_sec = parmTypes[i].scan_rate;
    }

    /* Init OSD stuff */
    scan_mutex = epicsMutexMustCreate();
    devIocStatsInitCpuUsage();
    devIocStatsInitCpuUtilization(&loadinfo);
    devIocStatsInitFDUsage();
    devIocStatsInitMemUsage();
    devIocStatsInitWorkspaceUsage();
    devIocStatsInitSuspTasks();
    devIocStatsInitIFErrors();
    /* Get initial values of a few things that don't change much */
    devIocStatsGetClusterInfo(SYS_POOL, &clustinfo[SYS_POOL]);
    devIocStatsGetClusterInfo(DATA_POOL, &clustinfo[DATA_POOL]);
    devIocStatsGetClusterUsage(SYS_POOL, &mbufnumber[SYS_POOL]);
    devIocStatsGetClusterUsage(DATA_POOL, &mbufnumber[DATA_POOL]);
    devIocStatsGetCpuUtilization(&loadinfo);
    devIocStatsGetIFErrors(&iferrors);
    devIocStatsGetFDUsage(&fdusage);

    /* Count EPICS records */
    if (pdbbase) {
        DBENTRY dbentry;
        long	  status;
        dbInitEntry(pdbbase,&dbentry);
        status = dbFirstRecordType(&dbentry);
        while (!status) {
            recordnumber += dbGetNRecords(&dbentry);
            status = dbNextRecordType(&dbentry);
        }
        dbFinishEntry(&dbentry);
    }
    return 0;
}
static long ai_init(int pass)
{
    long i;

    if (pass) return 0;

    /* Create timers */
    for (i = 0; i < TOTAL_TYPES; i++) {
        scanIoInit(&scan[i].ioscan);
        scan[i].wd = wdogCreate(scan_time, i);
        scan[i].total = 0;
        scan[i].on = 0;
        scan[i].rate_sec = scan_rate_sec[i];
        scan[i].last_read_sec = 1000000;
    }

    /* Init OSD stuff */
    devIocStatsInitCpuUsage();
    devIocStatsInitCpuUtilization(&loadinfo);
    devIocStatsInitFDUsage();
    devIocStatsInitMemUsage();
    devIocStatsInitWorkspaceUsage();
    devIocStatsInitSuspTasks();
    devIocStatsInitIFErrors();

    /* Count EPICS records */
    if (pdbbase) {
        DBENTRY dbentry;
        long	  status;
        dbInitEntry(pdbbase,&dbentry);
        status = dbFirstRecordType(&dbentry);
        while (!status) {
            recordnumber += dbGetNRecords(&dbentry);
            status = dbNextRecordType(&dbentry);
        }
        dbFinishEntry(&dbentry);
    }
    return 0;
}
예제 #4
0
long epicsShareAPI dbnr(int verbose)
{
    DBENTRY dbentry;
    DBENTRY *pdbentry=&dbentry;
    long status;
    int nrecords;
    int naliases;
    int trecords = 0;
    int taliases = 0;

    if (!pdbbase) {
        printf("No database loaded\n");
        return 0;
    }

    dbInitEntry(pdbbase, pdbentry);
    status = dbFirstRecordType(pdbentry);
    if (status) {
        printf("No record types loaded\n");
        return 0;
    }

    printf("Records  Aliases  Record Type\n");
    while (!status) {
        naliases = dbGetNAliases(pdbentry);
        taliases += naliases;
        nrecords = dbGetNRecords(pdbentry) - naliases;
        trecords += nrecords;
        if (verbose || nrecords)
            printf(" %5d    %5d    %s\n",
                nrecords, naliases, dbGetRecordTypeName(pdbentry));
        status = dbNextRecordType(pdbentry);
    }

    dbFinishEntry(pdbentry);
    printf("Total %d records, %d aliases\n", trecords, taliases);
    return 0;
}
예제 #5
0
int epicsShareAPI logAlarmsInit (
) {
    DBENTRY     dbentry;
    DBENTRY     *pdbentry=&dbentry;
    long        status;
    int		numRecords=0;
    int		tid[MSG_TASK_NUM], btid, ctid, rtid;
    int		normalRangeSize, overRangeSize;
    struct sockaddr_in	*psin;
    int		node;
    char	string[32];
    char	*pstring, *serverList, *ptok, *pheader;
    int		i;

    if (initialized) {
	errlogPrintf ("logAlarmsInit: already initialized\n");
	return ERROR;
    }

    clkRate = sysClkRateGet();

    tickInitWait = (unsigned long)(clkRate * INIT_DELAY_SEC + 0.5);

    tickMaxSilent = (unsigned long)(clkRate * BEACON_IDLE_SEC + 0.5);
    tickBeaconPeriod = (unsigned long)(clkRate * BEACON_PERIOD_SEC + 0.5);
    tickBeaconReplyTmo = (unsigned long)(clkRate * BEACON_REPLY_TMO_SEC + 0.5);
    tickMessageReplyTmo = (unsigned long)(clkRate * MESSAGE_REPLY_TMO_SEC + 0.5);
    /* wait time between retrying to send messages (>= 1 tick) */
    tickMsgRetryWait = (unsigned long)(clkRate * MESSAGE_RETRY_WAIT_SEC + 0.5);
    if (tickMsgRetryWait == 0UL) tickMsgRetryWait = 1UL;

    if(!pdbbase) {
	errlogPrintf ("logAlarmsInit: No database has been loaded\n");
        return ERROR;
    }

    serverList = getenv ("EPICS_ALARM_SERVER_INET");
    if (!serverList) {
	errlogPrintf ("logAlarmsInit: EPICS_ALARM_SERVER_INET env not defined\n");
	return ERROR;
    }

    pstring = getenv ("EPICS_ALARM_MESSAGE_PORT");
    if (!pstring)
	msg_port = DEFAULT_MSG_PORT;
    else {
	msg_port = (unsigned short) atoi (pstring);
	if (msg_port < 1024) {
	    msg_port = DEFAULT_MSG_PORT;
	    errlogPrintf ("Port number EPICS_ALARM_MESSAGE_PORT is wrong\n");
	}
    }

    pstring = getenv ("EPICS_ALARM_COMMAND_PORT");
    if (!pstring)
	cmd_port = DEFAULT_CMD_PORT;
    else {
	cmd_port = (unsigned short) atoi (pstring);
	if (cmd_port < 1024) {
	    cmd_port = DEFAULT_CMD_PORT;
	    errlogPrintf ("Port number EPICS_ALARM_COMMAND_PORT is wrong\n");
	}
    }

    /* if allAcceptOption is set, commands are accepted from all servers */
    pstring = getenv ("EPICS_ALARM_COMMAND_ACCEPT_ALL");
    if (strcmp (pstring, "YES") == 0)
	allAcceptOption = TRUE;

    psin = &msgServerAddr[0];
    node = 0;

    ptok = strtok_r (serverList, " ", &pstring);

    while (ptok && node < SERVERS_MAX && aToIPAddr (ptok, msg_port, psin) == 0) {
        node++;
        psin++;
	ptok = strtok_r (NULL, " ", &pstring);
    }
    numServersConfigured = node;

    if (numServersConfigured == 0) {
	errlogPrintf (
	  "logAlarmsInit: No server correctly defined in EPICS_ALARM_SERVER_INET\n");
    }

    wakeupSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
    if (!wakeupSem) {
	errlogPrintf ("logAlarmsInit: Reader wakeup semaphore could not be created\n");
        return ERROR;
    }

    bucketSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
    if (!bucketSem) {
	errlogPrintf ("logAlarmsInit: Hash facility mutex could not be created\n");
	cleanup (1);
        return ERROR;
    }

    ringSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
    if (!ringSem) {
	errlogPrintf ("logAlarmsInit: Ring r/w mutex could not be created\n");
	cleanup (2);
        return ERROR;
    }

    ringWriteSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
    if (!ringWriteSem) {
	errlogPrintf ("logAlarmsInit: Ring (write) mutex could not be created\n");
	cleanup (3);
        return ERROR;
    }

    msgSockSem = semMCreate (SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE);
    if (!msgSockSem) {
	errlogPrintf ("logAlarmsInit: MsgSocket mutex could not be created\n");
	cleanup (4);
        return ERROR;
    }

    dbInitEntry(pdbbase,pdbentry);

    status = dbFirstRecordType(pdbentry);
    while(!status) {
	int	numRecordsType;

	numRecordsType = dbGetNRecords(pdbentry);
	DEBUG2(4,"There are %d records of type %s\n",
	  numRecordsType, dbGetRecordTypeName(pdbentry))
	numRecords += numRecordsType;
	status = dbNextRecordType(pdbentry);
    }
    dbFinishEntry(pdbentry);

    normalRangeSize = (int)(numRecords * RING_NORMAL_MULTI) + 1;
    overRangeSize = numRecords + numRecords / RING_OVER_DIVI + 1;

    ringSize = normalRangeSize + overRangeSize;

    pRingBottom = (msgBuffer_t *)calloc (ringSize, sizeof(msgBuffer_t));
    if (!pRingBottom) {
	errlogPrintf ("logAlarmsInit: Ring buffer could not be created\n");
	cleanup (5);
	return ERROR;
    }
    pRingTop = pRingBottom + ringSize;
    DEBUG2(2,"pRingBottom:%lu  pRingTop:%lu\n",
      (unsigned long)pRingBottom, (unsigned long)pRingTop)

    ringHighWater = normalRangeSize;
    DEBUG2(2,"Ring buffer size:%d  highwater:%d\n",ringSize,ringHighWater)
    pRingRead = pRingBottom;
    pRingWrite = pRingBottom;
    msgLost = 0;

    pbuck = bucketCreate (numRecords);
    if (!pbuck) {
	errlogPrintf ("logAlarmsInit: Hash table could not be initalized\n");
	cleanup (6);
	return ERROR;
    }

    serverSelected = -1;
    serverSelectedLast = -1;

    queueAllRecords();

    /* spawn alarm beacon task */
    btid = taskSpawn ("Al'Beacon", BEACON_TASK_PRIO, BEACON_TASK_OPTIONS,
      BEACON_TASK_STACK, (FUNCPTR)alarmBeaconTask,0,0,0,0,0,0,0,0,0,0);

    if (!btid) {
	errlogPrintf ("logAlarmsInit: Beacon task could not be spawned\n");
	cleanup (7);
	return ERROR;
    }
    DEBUG1(1,"alarmBeaconTask started. Task-ID = 0x%x\n", btid);

    msg_soc = socket (AF_INET, SOCK_DGRAM, 0);
    if (msg_soc < 0) {
	errlogPrintf ("Message socket create failed\n");
	cleanup (7);
	return ERROR;
    }
    bzero ((char *) &msgReplyInAddr, sockAddrSize);
    msgReplyInAddr.sin_port = htons(msg_port);
    msgReplyInAddr.sin_family = AF_INET;
    msgReplyInAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind (msg_soc, (struct sockaddr*)&msgReplyInAddr, sockAddrSize) < 0 ) {
	errlogPrintf ("Message socket bind failed\n");
	cleanup (8);
	return ERROR;
    }

    cmd_soc = socket (AF_INET, SOCK_DGRAM, 0);
    if (cmd_soc < 0) {
	errlogPrintf ("Command socket create failed\n");
	cleanup (8);
	return ERROR;
    }
    bzero ((char *) &cmdServerAddr, sockAddrSize);
    cmdServerAddr.sin_port = htons(cmd_port);
    cmdServerAddr.sin_family = AF_INET;
    cmdServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind (cmd_soc, (struct sockaddr*)&cmdServerAddr, sockAddrSize) < 0 ) {
	errlogPrintf ("Command socket bind failed\n");
	cleanup (9);
	return ERROR;
    }

    /* spawn alarm message tasks */
    for (i=0; i<MSG_TASK_NUM; i++) {
	sprintf (string, "Al'Msg%d", i+1);
	tid[i] = taskSpawn (string, CLIENT_TASK_PRIO, CLIENT_TASK_OPTIONS,
	 CLIENT_TASK_STACK, (FUNCPTR)alarmMessageTask,i+1,0,0,0,0,0,0,0,0,0);

	if (!tid[i]) {
	    errlogPrintf (
	     "logAlarmsInit: Message task %d could not be spawned\n");
	    cleanup (9);
	    while (i > 0) taskDelete (tid[--i]);
	    taskDelete (btid);
	    return ERROR;
	}
    }

    /* spawn alarm log control (command receiver) server task */
    ctid = taskSpawn ("Al'Command", CONTROL_TASK_PRIO, CONTROL_TASK_OPTIONS,
      CONTROL_TASK_STACK, (FUNCPTR)alarmCommandTask,0,0,0,0,0,0,0,0,0,0);

    if (!ctid) {
	errlogPrintf ("logAlarmsInit: Control task could not be spawned\n");
	cleanup (9);
	taskDelete (btid);
	for (i=0; i<MSG_TASK_NUM; i++) taskDelete (tid[i]);
	return ERROR;
    }

    /* spawn message reply receiver task */
    rtid = taskSpawn ("Al'ReplyRx", REPLY_TASK_PRIO, REPLY_TASK_OPTIONS,
      REPLY_TASK_STACK, (FUNCPTR)replyReceiveTask,0,0,0,0,0,0,0,0,0,0);

    if (!rtid) {
	errlogPrintf ("logAlarmsInit: Reply receiver task could not be spawned\n");
	cleanup (9);
	taskDelete (btid);
	taskDelete (ctid);
	for (i=0; i<MSG_TASK_NUM; i++) taskDelete (tid[i]);
	return ERROR;
    }

    pheader = messageHeader;

    pstring = getenv ("EPICS_IOC_NAME");

    if (pstring)		/* given IOC name */
	pheader = messageHeader +
	  sprintf (messageHeader, "HOST=%s;", pstring);
    pheader +=
      sprintf (pheader, "HOST-PHYS=%s;APPLICATION=logAlarms;",
        gethostname (string, sizeof(string)) ? "TOO_LONG" : string);

    pstring = getenv ("EPICS_FACILITY");

    if (pstring)		/* name of application facility */
	pheader +=
	  sprintf (pheader, "FACILITY=%s;", pstring);

    /* calculate the remaining space in the message string */
    textMsgSize = MAX_MESSAGE_LENGTH - (pheader-messageHeader);

    epicsPrintf("logAlarms started\n");

    recGblAlarmHook = (RECGBL_ALARM_HOOK_ROUTINE)logEvent;
    DEBUG1(3,"recGblAlarmHook = 0x%lx\n",(unsigned long)recGblAlarmHook)

    initialized = TRUE;

    return OK;
}