Project:HUGnet Sensor Types

From HUG Wiki

Jump to: navigation, search

The sensor decoding is generally broken down into two steps. The first is to get the value of the sensor in terms of the physical sensor type, then in terms of the logical sensor type. Take a NTC thermistor for instance. Physically it is a resistive sensor. The resistance changes as a negative function of temperature. Therefore, we calculate the resistance first, based on the AtoD reading, then we calculate the temperature from the resistance. The first step gets us into units that can be plugged into formula from the datasheets of the sensors to get the calibrated output values for the sensors.

Contents

Sensor Types

Physical Sensor Types

HUGnet Sensor Types


Code

The code for all of this decoding is in the HUGnetLib in the drivers/sensors directory. The files are named by the sensor types.

Specifying a Sensor

The sensor specifications should go into the 'sensors' class variable for the class that the sensor belongs to. The keys for this array are the sensor types as known by the endpoint. The elements attached to these keys is an array of sensor definitions. The keys for this array are the short names of the sensor. These should contain no spaces or special characters.

Sensor Definition Array

Fields:
longName (Required)
The name of the sensor written out in english. This should be detailed enough to positively identify this sensor
unitType (Required)
This is the generic name for the units. An example would be the generic name for 'degrees F' is "Temperature".
validUnits (Required)
This is an array of unit names that this sensor can use. This should be an exhaustive list.
storageUnit (Required)
This is what units should be used when storing the data to the database.
unitModes (Required)
This is an array defining every mode that a sensor can take for each of the units specified in 'validUnits'. It is an array with the key being the unit and the value being a comma separated list of modes for this unit.
function
This function gets called to change the raw data into something that can be stored in the database. It will output its value in the units defined in 'storageUnit'.
checkFunction
This is the function that gets called to check if a value is correct for this sensor.
extraText
This is either the text to attach to the 'extra' field, or an array of texts. If it is an array an array will be passed in the 'extra' field with the same keys as used in this array.
extraDefault
This must mirror extraText above. If extraText is an array, this needs to be an array with EXACTLY the same keys. This stores the default values for the extra fields.
mult
The raw value will get multiplied by this before it is fed into the function defined by 'function'
doTotal
If this is TRUE then totals will be calculated instead of averages for this sensor.
inputSize
The number of inputs on the enpdoint that this takes. Assumed to be 1 if this is not set.

Example

        var $sensors = array(
            0x70 => array(
                'generic' => array(
                    "longName" => "Generic Pulse Counter",
                    "unitType" => "Pulses",
                    "validUnits" => array('PPM', 'counts'),
                    "storageUnit" =>  'PPM',
                    "unitModes" => array(
                        'PPM' => 'diff',
                        'counts' => 'raw,diff',
                    ),
                    "checkFunction" => "pulseCheck",

                ),
                'genericRevolver' => array(
                    "longName" => "Generic Revolving Thingy",
                    "unitType" => "Revolutional Speed",
                    "validUnits" => array('PPM', 'counts', 'RPM'),
                    "storageUnits" =>  'PPM',
                    "unitModes" => array(
                        'PPM' => 'diff',
                        'RPM' => 'diff',
                        'counts' => 'raw,diff',
                    ),
                    "extraText" => "Counts per Revolution",
                ),
                'maximumAnemometer' => array(
                    "longName" => "Maximum Inc type Hall Effect Anemometer",
                    "unitType" => "Wind Speed",
                    "validUnits" => array('MPH'),
                    "storageUnit" =>  'MPH',
                    "unitModes" => array(
                        'MPH' => 'diff',
                    ),
                    "function" => "maximumAnemometer",
                    "checkFunction" => "diffCheck",
                ),
                'maximumRainGauge' => array(
                    "longName" => "Maximum Inc rain gauge",
                    "unitType" => "Rain Fall",
                    "validUnits" => array('"'),
                    "storageUnit" =>  '"',
                    "unitModes" => array(
                        '"' => 'diff',
                    ),
                    "mult" => 0.01,
                    "checkFunction" => "diffCheck",
                    "doTotal" => TRUE,
                ),
            ),
        );

See Also