Main /
ProceduralExampleThis is a part of a larger factory floor monitoring application that monitors temperature sensors as potential indicators of anomalous conditions (e.g.,~temperature > 100 in some area of the factory floor). Upon detection of this event, additional sensors are tasked in the affected area. These sensors then collect additional information to try to determine the precise cause of the anomalous temperature readings. In the code shown here, two kinds of additional sensor readings are collected. Based on these readings, a diagnosis of the cause of the problem is made, and this decision is forwarded to the central node, which notifies a human user. Once the temperature returns to normal, tasking of the extra sensors in the particular area stops and the application resumes passive monitoring of the factory floor. TASK MonitorTempHandler { private dummyCnt; private affectedArea; private temp; } TASKRUN MonitorTempHandler { ! New tuple received, process it temp = getTupleAttr(a_tempsensor_sample) affectedArea = getTupleAttr(a_arealocation) if temp > CRITICAL_TEMP then ! Initiate detailed monitoring newTuple(); setTupleAttr(a_arealocation, affectedArea); setTupleAttr(a_rich_sensor_command, V_RICHSENSOR_SENSE); insertTuple(MonitorTempView); end if } TASK DiagnosticHandler { private dummyCnt; private richSensor1; ! data from rich sensors private richSensor2; private view; private sample; private diagnosis; } TASKRUN DiagnosticHandler { ! New tuple received, process it view = getView(); sample = getTupleAttr(a_rich_sensor_sample); affectedArea = getTupleAttr(a_arealocation); ! What view did we read this from if view = V_RICHSENSOR1 then richSensor1 = sample else richSensor2 = sample end if ! Diagnose the problem if richSensor1 < richSensor2 then diagnosis = ONFIRE end if if richSensor2 > richSensor1 then diagnosis = ONFLOOD else diagnosis = INSUFFICIENT_DATA end if ! Record the diagnosis newTuple(); setTupleAttr(a_arealocation, affectedArea); setTupleAttr(a_subtype_diagnostic_result, V_DIAGNOSTIC_RESULT_INSUFFICIENTDATA); insertTuple(DiagnositcView); } |