int htmlIdleState (int state, void *stimulus, void *data) { STIM *stim = (STIM *)stimulus; HTML_WORK *work = (HTML_WORK *)data; uint16_t year, month, day, hour, minute, second; WVIEW_MSG_REQUEST msg; switch (stim->type) { case STIM_DUMMY: // this one starts this state machine - send the archive request msg.requestType = WVIEW_RQST_TYPE_STATION_INFO; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_REQUEST, &msg, sizeof(msg)) == ERROR) { radMsgLog (PRI_HIGH, "htmlIdleState: radMsgRouterMessageSend failed!"); statusUpdateMessage("radMsgRouterMessageSend failed!"); statusUpdate(STATUS_ERROR); return HTML_STATE_ERROR; } // initialize the DST state change detector here wvutilsDetectDSTInit (); statusUpdate(STATUS_WAITING_FOR_WVIEW); return HTML_STATE_STATION_INFO; } return state; }
static int requestDataPackets (HTML_WORK *work) { WVIEW_MSG_REQUEST msg; msg.requestType = WVIEW_RQST_TYPE_LOOP_DATA; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_REQUEST, &msg, sizeof(msg)) == ERROR) { radMsgLog (PRI_HIGH, "requestDataPackets: radMsgRouterMessageSend failed!"); return ERROR; } msg.requestType = WVIEW_RQST_TYPE_HILOW_DATA; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_REQUEST, &msg, sizeof(msg)) == ERROR) { radMsgLog (PRI_HIGH, "requestDataPackets: radMsgRouterMessageSend failed!"); return ERROR; } return OK; }
void wvutilsSendPMONPollResponse(int mask, PMON_PROCESS_TYPES process) { WVIEW_MSG_POLL_RESPONSE response; if (! PMON_PROCESS_ISSET(mask,process)) { return; } response.pid = getpid(); radMsgRouterMessageSend (WVIEW_MSG_TYPE_POLL_RESPONSE, &response, sizeof(response)); return; }
// send shutdown notification int stationSendShutdown (WVIEWD_WORK *work) { WVIEW_MSG_SHUTDOWN msg; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_SHUTDOWN, &msg, sizeof(msg)) == ERROR) { // can't send! radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed: shutdown"); return ERROR; } return OK; }
int stationProcessInfoResponses (WVIEWD_WORK *work) { WVIEW_MSG_STATION_INFO apath; if (!work->archiveRqstPending) { return OK; } apath.lastArcTime = work->archiveDateTime; apath.archiveInterval = work->archiveInterval; apath.latitude = work->latitude; apath.longitude = work->longitude; apath.elevation = work->elevation; if (! work->showStationIF) { sprintf(apath.stationType, "%s", work->stationType); } else { if (work->medium.type == MEDIUM_TYPE_USBHID) { sprintf(apath.stationType, "%s (USB)", work->stationType); } else if (work->medium.type == MEDIUM_TYPE_NONE) { sprintf(apath.stationType, "%s", work->stationType); } else if (!strcmp(work->stationInterface, "ethernet")) { sprintf(apath.stationType, "%s (%s:%d)", work->stationType, work->stationHost, work->stationPort); } else { sprintf(apath.stationType, "%s (%s)", work->stationType, work->stationDevice); } } if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_STATION_INFO, &apath, sizeof (apath)) == ERROR) { radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed Archive Path"); return ERROR; } work->archiveRqstPending = FALSE; return OK; }
int emailAlertSend (EmailAlertTypes type) { WVIEW_MSG_ALERT alert; if ((time(NULL) - lastAlertTime[type]) < ALERT_NOTIFY_INTERVAL) { // Abate: return OK; } alert.alertType = type; lastAlertTime[type] = time(NULL); radMsgRouterMessageSend (WVIEW_MSG_TYPE_ALERT, &alert, sizeof(alert)); return OK; }
int stationPushArchiveToClients(WVIEWD_WORK *work, ARCHIVE_PKT* pktToSend) { WVIEW_MSG_ARCHIVE_DATA arc; if (!work->runningFlag) { return OK; } memcpy (&arc.archiveData, pktToSend, sizeof (*pktToSend)); if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_ARCHIVE_DATA, &arc, sizeof(arc)) == ERROR) { radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed for archive transmit!"); return ERROR; } return OK; }
int stationPushDataToClients (WVIEWD_WORK *work) { WVIEW_MSG_LOOP_DATA loop; if (!work->runningFlag) { return OK; } memcpy (&loop.loopData, &work->loopPkt, sizeof (loop.loopData)); if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_LOOP_DATA_SVC, &loop, sizeof(loop)) == ERROR) { radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed for loop transmit!"); return ERROR; } radProcessTimerStart (work->pushTimer, work->pushInterval); return OK; }
int stationSendArchiveNotifications (WVIEWD_WORK *work, float sampleRain) { WVIEW_MSG_ARCHIVE_NOTIFY notify; float tempfloat; notify.dateTime = work->archiveDateTime; notify.intemp = (int)floorf(work->loopPkt.inTemp * 10); notify.inhumidity = work->loopPkt.inHumidity; notify.temp = (int)floorf(work->loopPkt.outTemp * 10); notify.humidity = work->loopPkt.outHumidity; notify.barom = (int)floorf(work->loopPkt.barometer * 1000); notify.stationPressure = (int)floorf(work->loopPkt.stationPressure * 1000); notify.altimeter = (int)floorf(work->loopPkt.altimeter * 1000); notify.winddir = work->loopPkt.windDir; notify.wspeed = work->loopPkt.windSpeed; notify.dewpoint = (int)floorf(work->loopPkt.dewpoint * 10); notify.hiwspeed = work->loopPkt.windGust; notify.rxPercent = work->loopPkt.rxCheckPercent; notify.sampleRain = sampleRain; tempfloat = sensorGetCumulative (&work->sensors.sensor[STF_HOUR][SENSOR_RAIN]); tempfloat *= 100; tempfloat += 0.5; notify.rainHour = (int)tempfloat; tempfloat = sensorGetCumulative (&work->sensors.sensor[STF_DAY][SENSOR_RAIN]); tempfloat *= 100; tempfloat += 0.5; notify.rainDay = (int)tempfloat; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_ARCHIVE_NOTIFY, ¬ify, sizeof(notify)) == ERROR) { // can't send! radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed: notify"); return ERROR; } return OK; }
static void pollTimerHandler (void *parm) { int i, mask = 0; WVIEW_MSG_POLL poll; PMON_STIM stim; // Set active process bits: for (i = 0; i < PMON_PROCESS_MAX; i ++) { if (procmonWork.process[i].timeout <= 0 || radStatesGetState (procmonWork.process[i].stateMachine) != PMON_STATE_IDLE) { // Skip this guy continue; } mask = PMON_PROCESS_SET(mask,i); procmonWork.process[i].ticks = procmonWork.process[i].timeout; // Tickle the state machine memset (&stim, 0, sizeof(stim)); stim.index = i; stim.type = PMON_STIM_POLL; radStatesProcess (procmonWork.process[i].stateMachine, &stim); } poll.mask = mask; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_POLL, &poll, sizeof(poll)) == ERROR) { radMsgLog (PRI_HIGH, "pollTimerHandler: radMsgRouterMessageSend failed!"); } radProcessTimerStart (procmonWork.pollTimer, PMON_POLL_INTERVAL); return; }
static int waitForWviewDaemon (void) { WVIEW_MSG_REQUEST msg; char srcQName[QUEUE_NAME_LENGTH+1]; UINT msgType; UINT length; void *recvBfr; int retVal, done = FALSE; // enable message reception from the radlib router for the archive path radMsgRouterMessageRegister (WVIEW_MSG_TYPE_STATION_INFO); msg.requestType = WVIEW_RQST_TYPE_STATION_INFO; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_REQUEST, &msg, sizeof(msg)) == ERROR) { statusUpdateMessage("waitForWviewDaemon: radMsgRouterMessageSend failed!"); radMsgLog (PRI_HIGH, "waitForWviewDaemon: radMsgRouterMessageSend failed!"); radMsgRouterMessageDeregister (WVIEW_MSG_TYPE_STATION_INFO); return ERROR; } statusUpdate(STATUS_WAITING_FOR_WVIEW); // now wait for the response here while (!done) { radUtilsSleep (50); if ((retVal = radQueueRecv (radProcessQueueGetID (), srcQName, &msgType, &recvBfr, &length)) == FALSE) { continue; } else if (retVal == ERROR) { statusUpdateMessage("waitForWviewDaemon: queue is closed!"); radMsgLog (PRI_STATUS, "waitForWviewDaemon: queue is closed!"); radMsgRouterMessageDeregister (WVIEW_MSG_TYPE_STATION_INFO); return ERROR; } // is this what we want? if (msgType == WVIEW_MSG_TYPE_STATION_INFO) { // yes! done = TRUE; cwopWork.reportInterval = ((WVIEW_MSG_STATION_INFO*)recvBfr)->archiveInterval; if (cwopWork.reportInterval < 10) { cwopWork.reportInterval = 10; } } else if (msgType == WVIEW_MSG_TYPE_SHUTDOWN) { statusUpdateMessage("waitForWviewDaemon: received shutdown from wviewd"); radMsgLog (PRI_HIGH, "waitForWviewDaemon: received shutdown from wviewd"); radMsgRouterMessageDeregister (WVIEW_MSG_TYPE_STATION_INFO); return ERROR; } // release the received buffer radBufferRls (recvBfr); } // disable message reception from the radlib router for the archive path radMsgRouterMessageDeregister (WVIEW_MSG_TYPE_STATION_INFO); return OK; }
int stationProcessIPM (WVIEWD_WORK *work, char *srcQueueName, int msgType, void *msg) { WVIEW_MSG_REQUEST *msgRqst; WVIEW_MSG_LOOP_DATA loop; WVIEW_MSG_HILOW_DATA hilow; WVIEW_MSG_ALERT* alert; int retVal, i; switch (msgType) { case WVIEW_MSG_TYPE_REQUEST: msgRqst = (WVIEW_MSG_REQUEST *)msg; switch (msgRqst->requestType) { case WVIEW_RQST_TYPE_STATION_INFO: // flag that a request has been tendered work->archiveRqstPending = TRUE; // are we currently in a serial cycle? if (!work->runningFlag) { // yes, just bail out for now return OK; } else { // no, send it now return (stationProcessInfoResponses (work)); } case WVIEW_RQST_TYPE_LOOP_DATA: loop.loopData = work->loopPkt; if (loop.loopData.sampleET == ARCHIVE_VALUE_NULL) loop.loopData.sampleET = 0; if (loop.loopData.radiation == 0xFFFF) loop.loopData.radiation = 0; if (loop.loopData.UV == 0xFFFF) loop.loopData.UV = 0; if (loop.loopData.rxCheckPercent == 0xFFFF) loop.loopData.rxCheckPercent = 0; if (loop.loopData.wxt510Hail == ARCHIVE_VALUE_NULL) loop.loopData.wxt510Hail = 0; if (loop.loopData.wxt510Hailrate == ARCHIVE_VALUE_NULL) loop.loopData.wxt510Hailrate = 0; if (loop.loopData.wxt510HeatingTemp == ARCHIVE_VALUE_NULL) loop.loopData.wxt510HeatingTemp = 0; if (loop.loopData.wxt510HeatingVoltage == ARCHIVE_VALUE_NULL) loop.loopData.wxt510HeatingVoltage = 0; if (loop.loopData.wxt510SupplyVoltage == ARCHIVE_VALUE_NULL) loop.loopData.wxt510SupplyVoltage = 0; if (loop.loopData.wxt510ReferenceVoltage == ARCHIVE_VALUE_NULL) loop.loopData.wxt510ReferenceVoltage = 0; if (loop.loopData.wxt510RainDuration == ARCHIVE_VALUE_NULL) loop.loopData.wxt510RainDuration = 0; if (loop.loopData.wxt510RainPeakRate == ARCHIVE_VALUE_NULL) loop.loopData.wxt510RainPeakRate = 0; if (loop.loopData.wxt510HailDuration == ARCHIVE_VALUE_NULL) loop.loopData.wxt510HailDuration = 0; if (loop.loopData.wxt510HailPeakRate == ARCHIVE_VALUE_NULL) loop.loopData.wxt510HailPeakRate = 0; if (loop.loopData.wxt510Rain == ARCHIVE_VALUE_NULL) loop.loopData.wxt510Rain = 0; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_LOOP_DATA, &loop, sizeof(loop)) == ERROR) { radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed LOOP"); return ERROR; } return OK; case WVIEW_RQST_TYPE_HILOW_DATA: hilow.hilowData = work->sensors; if (radMsgRouterMessageSend (WVIEW_MSG_TYPE_HILOW_DATA, &hilow, sizeof(hilow)) == ERROR) { radMsgLog (PRI_HIGH, "radMsgRouterMessageSend failed HILOW %d", sizeof(WVIEW_MSG_HILOW_DATA)); return ERROR; } return OK; } break; case WVIEW_MSG_TYPE_ALERT: alert = (WVIEW_MSG_ALERT*)msg; if (processAlertMessage(work, alert->alertType) == ERROR) { radMsgLog (PRI_HIGH, "Email Alert Send failed - are sendmail and sendEmail installed?"); } break; default: // Pass it through to the station-specific function: stationMessageIndicate(work, msgType, msg); break; } return OK; }