예제 #1
0
파일: sensor.c 프로젝트: HEnquist/wview
float sensorAccumGetAverage (WV_ACCUM_ID id)
{
    float               samples, sum;

    sum = sensorAccumGetTotal(id);
    samples = (float)radListGetNumberOfNodes(&id->samples);
    if (samples > 0)
    {
        return (sum/samples);
    }
    else
    {
        return 0;
    }
}
예제 #2
0
파일: ssh.c 프로젝트: StefanPeter/wview
/*  ... the main entry point for the ssh process
*/
int main (int argc, char *argv[])
{
    void            (*alarmHandler)(int);
    STIM            stim;
    int             i;
    int             seconds;
    time_t          ntime;
    struct tm       locTime;
    int             offset, retVal;
    long            msOffset;
    FILE            *pidfile;
    int             runAsDaemon = TRUE;

    if (argc > 1)
    {
        if (!strcmp(argv[1], "-f"))
        {
            runAsDaemon = FALSE;
        }
    }

    memset (&sshWork, 0, sizeof (sshWork));

    /*  ... initialize some system stuff first
    */
    retVal = sshSysInit (&sshWork);
    if (retVal == ERROR)
    {
        radMsgLogInit (PROC_NAME_SSH, FALSE, TRUE);
        radMsgLog (PRI_CATASTROPHIC, "ssh init failed!");
        radMsgLogExit ();
        exit (1);
    }
    else if (retVal == ERROR_ABORT)
    {
        exit (2);
    }


    /*  ... call the global radlib system init function
    */
    if (radSystemInit (WVIEW_SYSTEM_ID) == ERROR)
    {
        radMsgLogInit (PROC_NAME_SSH, TRUE, TRUE);
        radMsgLog (PRI_CATASTROPHIC, "radSystemInit failed!");
        radMsgLogExit ();
        exit (1);
    }


    /*  ... call the radlib process init function
    */
    if (radProcessInit (PROC_NAME_SSH,
                        sshWork.fifoFile,
                        PROC_NUM_TIMERS_SSH,
                        runAsDaemon,                // TRUE for daemon
                        msgHandler,
                        evtHandler,
                        NULL)
        == ERROR)
    {
        printf ("\nradProcessInit failed: %s\n\n", PROC_NAME_SSH);
        radSystemExit (WVIEW_SYSTEM_ID);
        exit (1);
    }

    sshWork.myPid = getpid ();
    pidfile = fopen (sshWork.pidFile, "w");
    if (pidfile == NULL)
    {
        radMsgLog (PRI_CATASTROPHIC, "lock file create failed!");
        radProcessExit ();
        radSystemExit (WVIEW_SYSTEM_ID);
        exit (1);
    }
    fprintf (pidfile, "%d", getpid ());
    fclose (pidfile);


    alarmHandler = radProcessSignalGetHandler (SIGALRM);
    radProcessSignalCatchAll (SSHDefaultSigHandler);
    radProcessSignalCatch (SIGALRM, alarmHandler);
    radProcessSignalRelease(SIGABRT);


    sshWork.timer = radTimerCreate (NULL, timerHandler, NULL);
    if (sshWork.timer == NULL)
    {
        radMsgLog (PRI_HIGH, "radTimerCreate failed - exiting");
        sshSysExit (&sshWork);
        radProcessExit ();
        radSystemExit (WVIEW_SYSTEM_ID);
        exit (1);
    }

    //  ... initialize the ssh utilities
    retVal = sshUtilsInit (&sshWork.sshData);
    if (retVal != OK)
    {
        if (retVal == ERROR)
        {
            radMsgLog (PRI_HIGH, "sshUtilsInit failed - exiting");
        }
        radTimerDelete (sshWork.timer);
        sshSysExit (&sshWork);
        radProcessExit ();
        radSystemExit (WVIEW_SYSTEM_ID);
        exit (1);
    }
    else
    {
        sshWork.sshId = &sshWork.sshData;
    }

    if (statusInit(sshWork.statusFile, sshStatusLabels) == ERROR)
    {
        radMsgLog (PRI_HIGH, "statusInit failed - exiting...");
        sshSysExit (&sshWork);
        radProcessExit ();
        radSystemExit (WVIEW_SYSTEM_ID);
        exit (1);
    }
    statusUpdate(STATUS_BOOTING);
    statusUpdateStat(SSH_STATS_RULES_DEFINED, 
                     radListGetNumberOfNodes(&sshWork.sshData.rules));

    //  ... start THE timer
    ntime = time (NULL);
    localtime_r (&ntime, &locTime);
    seconds = locTime.tm_sec - 15;          // start at 15 secs past

    /*  ... start the ssh timer to go off 1 min past the next archive record
    */
    offset = locTime.tm_min % 5;
    if (offset)
        offset = 6 - offset;
    else
        offset = 1;

    if (seconds < -60)
    {
        offset += 1;
        offset += 60;
    }

    radMsgLog (PRI_HIGH,
               "SSH: starting updates in %d mins %d secs",
               ((seconds > 0) ? ((offset > 0) ? offset-1 : offset) : offset),
                       (seconds > 0) ? 60 - seconds : (-1) * seconds);

    msOffset = radTimeGetMSSinceEpoch () % 1000;
    msOffset -= 250;                        // land on 250 ms mark


    sshWork.msOffset = 0;
    radProcessTimerStart (sshWork.timer,
                          ((((offset * 60) - seconds) * 1000)) - msOffset);

    statusUpdate(STATUS_RUNNING);
    statusUpdateMessage("Normal operation");


    while (!sshWork.exiting)
    {
        /*  ... wait on timers, events, file descriptors, msgs, everything!
        */
        if (radProcessWait (0) == ERROR)
        {
            sshWork.exiting = TRUE;
        }
    }


    statusUpdateMessage("exiting normally");
    radMsgLog (PRI_STATUS, "exiting normally...");
    statusUpdate(STATUS_SHUTDOWN);

    if (sshWork.sshId != NULL)
    {
        sshUtilsExit (sshWork.sshId);
    }
    radTimerDelete (sshWork.timer);
    sshSysExit (&sshWork);
    radProcessExit ();
    radSystemExit (WVIEW_SYSTEM_ID);
    exit (0);
}
예제 #3
0
파일: htmlMgr.c 프로젝트: HEnquist/wview
HTML_MGR_ID htmlmgrInit
(
    char            *installPath,
    int             isMetricUnits,
    char            *imagePath,
    char            *htmlPath,
    int             arcInterval,
    int             isExtendedData,
    char            *name,
    char            *city,
    char            *state,
    int16_t         elevation,
    int16_t         latitude,
    int16_t         longitude,
    char            *mphaseIncrease,
    char            *mphaseDecrease,
    char            *mphaseFull,
    char            *radarURL,
    char            *forecastURL,
    char            *dateFormat,
    int             isDualUnits
)
{
    HTML_MGR_ID     newId;
    int             i, numNodes, numImages, numTemplates;
    char            confFilePath[256];

    newId = &mgrWork;
    memset (newId, 0, sizeof (mgrWork));

    radListReset (&newId->imgList);
    radListReset (&newId->templateList);
    
    newId->isMetricUnits    = isMetricUnits;
    newId->archiveInterval  = arcInterval;
    newId->isExtendedData   = isExtendedData;
    newId->imagePath        = imagePath;
    newId->htmlPath         = htmlPath;
    newId->stationElevation = elevation;
    newId->stationLatitude  = latitude;
    newId->stationLongitude = longitude;
    wvstrncpy (newId->stationName, name, sizeof(newId->stationName));
    wvstrncpy (newId->stationCity, city, sizeof(newId->stationCity));
    wvstrncpy (newId->stationState, state, sizeof(newId->stationState));
    wvstrncpy (newId->mphaseIncrease, mphaseIncrease, sizeof(newId->mphaseIncrease));
    wvstrncpy (newId->mphaseDecrease, mphaseDecrease, sizeof(newId->mphaseDecrease));
    wvstrncpy (newId->mphaseFull, mphaseFull, sizeof(newId->mphaseFull));
    wvstrncpy (newId->radarURL, radarURL, sizeof(newId->radarURL));
    wvstrncpy (newId->forecastURL, forecastURL, sizeof(newId->forecastURL));
    wvstrncpy (newId->dateFormat, dateFormat, sizeof(newId->dateFormat));
    newId->isDualUnits    = isDualUnits;
    
    //  ... initialize the newArchiveMask
    newId->newArchiveMask = NEW_ARCHIVE_ALL;

    
    //  ... first, the built-in generators
    sprintf (confFilePath, "%s/images.conf", installPath);
    if (readImageConfFile (newId, confFilePath, FALSE) != OK)
    {
        return NULL;
    }
    else
    {
        numNodes = radListGetNumberOfNodes (&newId->imgList);
        radMsgLog (PRI_STATUS, "htmlmgrInit: %d built-in image definitions added",
                   numNodes);
        numImages = numNodes;
    }

    //  ... next, the user-defined generators
    sprintf (confFilePath, "%s/images-user.conf", installPath);
    i = readImageConfFile (newId, confFilePath, TRUE);
    if (i == ERROR_ABORT)
    {
        radMsgLog (PRI_STATUS, "htmlmgrInit: no user image definitions found");
    }
    else if (i == ERROR)
    {
        return NULL;
    }
    else
    {
        numImages = radListGetNumberOfNodes (&newId->imgList);
        radMsgLog (PRI_STATUS, "htmlmgrInit: %d user image definitions added",
                   radListGetNumberOfNodes (&newId->imgList) - numNodes);
    }

    //  ... now initialize our html template list
    sprintf (confFilePath, "%s/html-templates.conf", installPath);
    if (readHtmlTemplateFile (newId, confFilePath) != OK)
    {
        return NULL;
    }
    else
    {
        numTemplates = radListGetNumberOfNodes (&newId->templateList);
        radMsgLog (PRI_STATUS, "htmlmgrInit: %d templates added", numTemplates);
    }

    //  ... now initialize our forecast rule text list
    sprintf (confFilePath, "%s/forecast.conf", installPath);
    if (readForecastRuleConfigFile (newId, confFilePath) != OK)
    {
        radMsgLog (PRI_STATUS, "htmlmgrInit: forecast html tags are disabled - %s not found...",
                   confFilePath);
    }

    //  ... initialize the sample label array
    htmlmgrSetSampleLabels(newId);

    //  ... initialize our dial palette to conserve CPU cycles
    if (htmlGenPngDialInit (newId->imagePath) == ERROR)
    {
        radMsgLog (PRI_HIGH, "htmlmgrInit: htmlGenPngDialInit failed!");
        return NULL;
    }

    statusUpdateStat(HTML_STATS_IMAGES_DEFINED, numImages);
    statusUpdateStat(HTML_STATS_TEMPLATES_DEFINED, numTemplates);

    return newId;
}
예제 #4
0
파일: htmlMgr.c 프로젝트: HEnquist/wview
int htmlmgrReReadImageFiles
(
    HTML_MGR_ID     id,
    char            *installPath
)
{
    int             i, numNodes;
    char            confFilePath[256];

    // cleanup the old definitions
    cleanupForecastRules (id);
    emptyWorkLists (id);
    radListReset (&id->imgList);
    radListReset (&id->templateList);
    
    //  re-read the built-in generators
    sprintf (confFilePath, "%s/images.conf", installPath);
    if (readImageConfFile (id, confFilePath, FALSE) != OK)
    {
        return ERROR;
    }
    else
    {
        numNodes = radListGetNumberOfNodes (&id->imgList);
        radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d built-in image definitions added",
                   numNodes);
    }

    //  re-read the user-defined generators
    sprintf (confFilePath, "%s/images-user.conf", installPath);
    i = readImageConfFile (id, confFilePath, TRUE);
    if (i == ERROR_ABORT)
    {
        radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: no user image definitions found");
    }
    else if (i == ERROR)
    {
        return ERROR;
    }
    else
    {
        radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d user image definitions added",
                   radListGetNumberOfNodes (&id->imgList) - numNodes);
    }

    //  reinitialize our html template list
    sprintf (confFilePath, "%s/html-templates.conf", installPath);
    if (readHtmlTemplateFile (id, confFilePath) != OK)
    {
        return ERROR;
    }
    else
    {
        radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: %d templates added",
                   radListGetNumberOfNodes (&id->templateList));
    }

    //  reinitialize our forecast rule text list
    sprintf (confFilePath, "%s/forecast.conf", installPath);
    if (readForecastRuleConfigFile (id, confFilePath) != OK)
    {
        radMsgLog (PRI_STATUS, "htmlmgrReReadImageFiles: forecast html tags are disabled - %s not found...",
                   confFilePath);
    }

    return OK;
}
예제 #5
0
파일: alarms.c 프로젝트: breu/wview
static int readAlarmsConfig (void)
{
    WVIEW_ALARM     *alarm;
    int             i, numAlarms = 0;
    int             iValue;
    char            type[_MAX_PATH];
    int             boolMAX;
    double          thresh;
    int             abate;
    char            exec[_MAX_PATH];
    char            conftype[64];
    const char*     temp;

    if (wvconfigInit(FALSE) == ERROR)
    {
        radMsgLog (PRI_CATASTROPHIC, "wvconfigInit failed!");
        return ERROR;
    }

    // Is the alarms daemon enabled?
    iValue = wvconfigGetBooleanValue(configItem_ENABLE_ALARMS);
    if (iValue == ERROR || iValue == 0)
    {
        wvconfigExit ();
        return ERROR_ABORT;
    }

    // set the wview verbosity setting
    if (wvutilsSetVerbosity (WV_VERBOSE_WVALARMD) == ERROR)
    {
        radMsgLog (PRI_CATASTROPHIC, "wvutilsSetVerbosity failed!");
        wvconfigExit ();
        return ERROR_ABORT;
    }

    // get the metric units flag:
    iValue = wvconfigGetBooleanValue(configItem_ALARMS_STATION_METRIC);
    if (iValue == ERROR)
    {
        alarmsWork.isMetric = 0;
    }
    else
    {
        alarmsWork.isMetric = iValue;
    }

    // get the do test flag:
    iValue = wvconfigGetBooleanValue(configItem_ALARMS_DO_TEST);
    if (iValue <= 0)
    {
        alarmsWork.doTest = FALSE;
    }
    else
    {
        alarmsWork.doTest = TRUE;
        alarmsWork.doTestNumber = wvconfigGetINTValue(configItem_ALARMS_DO_TEST_NUMBER);
    }

    for (i = 1; i <= ALARMS_MAX; i ++)
    {
        sprintf (conftype, "ALARMS_%1.1d_TYPE", i);
        temp = wvconfigGetStringValue(conftype);
        if (temp == NULL)
        {
            // No type defined - continue:
            continue;
        }
        wvstrncpy(type, temp, _MAX_PATH);

        sprintf (conftype, "ALARMS_%1.1d_MAX", i);
        boolMAX = wvconfigGetBooleanValue(conftype);
        if (boolMAX == ERROR)
        {
            continue;
        }

        sprintf (conftype, "ALARMS_%1.1d_THRESHOLD", i);
        thresh = wvconfigGetDOUBLEValue(conftype);

        sprintf (conftype, "ALARMS_%1.1d_ABATEMENT", i);
        abate = wvconfigGetINTValue(conftype);

        sprintf (conftype, "ALARMS_%1.1d_EXECUTE", i);
        temp = wvconfigGetStringValue(conftype);
        if (temp == NULL)
        {
            // No type defined - continue:
            continue;
        }
        wvstrncpy(exec, temp, _MAX_PATH);

        alarm = (WVIEW_ALARM *) malloc (sizeof (*alarm));
        if (alarm == NULL)
        {
            for (alarm = (WVIEW_ALARM *)radListRemoveFirst (&alarmsWork.alarmList);
                 alarm != NULL;
                 alarm = (WVIEW_ALARM *)radListRemoveFirst (&alarmsWork.alarmList))
            {
                free (alarm);
            }

            return ERROR;
        }
        memset (alarm, 0, sizeof (*alarm));


        // get the type
        if (!strcmp (type, "Barometer"))
        {
            alarm->type = Barometer;
        }
        else if (!strcmp (type, "InsideTemp"))
        {
            alarm->type = InsideTemp;
        }
        else if (!strcmp (type, "InsideHumidity"))
        {
            alarm->type = InsideHumidity;
        }
        else if (!strcmp (type, "OutsideTemp"))
        {
            alarm->type = OutsideTemp;
        }
        else if (!strcmp (type, "WindSpeed"))
        {
            alarm->type = WindSpeed;
        }
        else if (!strcmp (type, "TenMinuteAvgWindSpeed"))
        {
            alarm->type = TenMinuteAvgWindSpeed;
        }
        else if (!strcmp (type, "WindDirection"))
        {
            alarm->type = WindDirection;
        }
        else if (!strcmp (type, "OutsideHumidity"))
        {
            alarm->type = OutsideHumidity;
        }
        else if (!strcmp (type, "RainRate"))
        {
            alarm->type = RainRate;
        }
        else if (!strcmp (type, "StormRain"))
        {
            alarm->type = StormRain;
        }
        else if (!strcmp (type, "DayRain"))
        {
            alarm->type = DayRain;
        }
        else if (!strcmp (type, "MonthRain"))
        {
            alarm->type = MonthRain;
        }
        else if (!strcmp (type, "YearRain"))
        {
            alarm->type = YearRain;
        }
        else if (!strcmp (type, "TxBatteryStatus"))
        {
            alarm->type = TxBatteryStatus;
        }
        else if (!strcmp (type, "ConsoleBatteryVoltage"))
        {
            alarm->type = ConsoleBatteryVoltage;
        }
        else if (!strcmp (type, "DewPoint"))
        {
            alarm->type = DewPoint;
        }
        else if (!strcmp (type, "WindChill"))
        {
            alarm->type = WindChill;
        }
        else if (!strcmp (type, "HeatIndex"))
        {
            alarm->type = HeatIndex;
        }
        else if (!strcmp (type, "Radiation"))
        {
            alarm->type = Radiation;
        }
        else if (!strcmp (type, "UV"))
        {
            alarm->type = UV;
        }
        else if (!strcmp (type, "ET"))
        {
            alarm->type = ET;
        }
        else if (!strcmp (type, "ExtraTemp1"))
        {
            alarm->type = ExtraTemp1;
        }
        else if (!strcmp (type, "ExtraTemp2"))
        {
            alarm->type = ExtraTemp2;
        }
        else if (!strcmp (type, "ExtraTemp3"))
        {
            alarm->type = ExtraTemp3;
        }
        else if (!strcmp (type, "SoilTemp1"))
        {
            alarm->type = SoilTemp1;
        }
        else if (!strcmp (type, "SoilTemp2"))
        {
            alarm->type = SoilTemp2;
        }
        else if (!strcmp (type, "SoilTemp3"))
        {
            alarm->type = SoilTemp3;
        }
        else if (!strcmp (type, "SoilTemp4"))
        {
            alarm->type = SoilTemp4;
        }
        else if (!strcmp (type, "LeafTemp1"))
        {
            alarm->type = LeafTemp1;
        }
        else if (!strcmp (type, "LeafTemp2"))
        {
            alarm->type = LeafTemp2;
        }
        else if (!strcmp (type, "ExtraHumid1"))
        {
            alarm->type = ExtraHumid1;
        }
        else if (!strcmp (type, "ExtraHumid2"))
        {
            alarm->type = ExtraHumid2;
        }
        else if (!strcmp (type, "Wxt510Hail"))
        {
            alarm->type = Wxt510Hail;
        }
        else if (!strcmp (type, "Wxt510Hailrate"))
        {
            alarm->type = Wxt510Hailrate;
        }
        else if (!strcmp (type, "Wxt510HeatingTemp"))
        {
            alarm->type = Wxt510HeatingTemp;
        }
        else if (!strcmp (type, "Wxt510HeatingVoltage"))
        {
            alarm->type = Wxt510HeatingVoltage;
        }
        else if (!strcmp (type, "Wxt510SupplyVoltage"))
        {
            alarm->type = Wxt510SupplyVoltage;
        }
        else if (!strcmp (type, "Wxt510ReferenceVoltage"))
        {
            alarm->type = Wxt510ReferenceVoltage;
        }
        else
        {
            free (alarm);
            radMsgLog (PRI_MEDIUM, "invalid alarm type %s - skipping...",
                       type);
            continue;
        }

        //  do the max/min flag
        alarm->isMax = boolMAX;

        //  now the bounding value
        alarm->bound = (float)thresh;

        //  now the abatement seconds
        alarm->abateSecs = abate;

        //  finally, the alarm script
        wvstrncpy (alarm->scriptToRun, exec, WVIEW_ALARM_SCRIPT_LENGTH);

        radListAddToEnd (&alarmsWork.alarmList, (NODE_PTR)alarm);
    }

    wvconfigExit ();
    return (radListGetNumberOfNodes (&alarmsWork.alarmList));
}