LOGGER  Logger
Data Logging using ESP8266
Classes | Macros | Typedefs | Functions | Variables
sensorlibrary.cpp File Reference
#include <arduino.h>
#include "sensorlibrary.h"
#include "dataservices.h"
#include "pincounter.h"
#include "processorsensors.h"
#include "services.h"

Classes

class  Sensor
 

Macros

#define sensorlibraryEdit   1
 version of this module
 

Typedefs

typedef class Sensor Sensor_t
 

Functions

EXTERNDEF void sensorlibraryInit ()
 < version of this module More...
 
EXTERNDEF String sensorlibraryInterfaceGetName (SensorInterfaceID_t interface)
 
EXTERNDEF String sensorlibrarySensorTypeGetName (SensorTypeID_t sensorType)
 
EXTERNDEF void sensorlibraryDumpSensorName (Print *pPrinter, uint8_t sensorID, FormatType_t formatType)
 
EXTERNDEF void sensorlibraryDumpSensorUniqueID (Print *pPrinter, uint8_t sensorID, FormatType_t formatType)
 
EXTERNDEF void sensorlibraryDumpSensorValue (Print *pPrinter, uint8_t indent, uint32_t value, uint8_t sensorID, FormatType_t formatType)
 
EXTERNDEF void sensorlibraryDumpSensors (Print *pPrinter, FormatType_t formatType)
 
EXTERNDEF void sensorlibraryReadSensors (LogElement_t &element)
 
EXTERNDEF void sensorlibraryDumpElement (Print *pPrinter, uint8_t indent, LogElement_t &element, FormatType_t formatType, SensorDatatypeID_t datatype)
 
EXTERNDEF void sensorlibraryDumpElementIDvalue (Print *pPrinter, uint8_t indent, LogElement_t &element, FormatType_t formatType, SensorDatatypeID_t datatype)
 
EXTERNDEF int8_t sensorlibraryCreateSensor (uint8_t *uniqueID, String name, uint8_t bitsOfData, bool isSigned, SensorInterfaceID_t interface, SensorTypeID_t sensorType, SensorDatatypeID_t datatype, uint8_t decimalPlaces, uint8_t sensorSpecific, pSENSOR_READ_CALLBACK pReader)
 
EXTERNDEF void sensorlibraryDisableSensor (uint8_t sensorID)
 
EXTERNDEF uint32_t sensorlibraryExtractPulseCount (uint8_t index, LogElement_t &element, uint32_t defaultCount)
 
EXTERNDEF void sensorlibraryDumpSampleList (Print *pPrinter, LogElement_t &element, SensorDatatypeID_t datatype)
 
EXTERNDEF void sensorlibrarySetPulsesSinceBoot (LogElement_t &element)
 
EXTERNDEF void sensorlibraryDumpAddColumns (Print *pPrinter, GraphType_t graphType, SensorDatatypeID_t datatype)
 
EXTERNDEF String sensorlibraryGetSensorName (uint8_t sensorID)
 
EXTERNDEF void sensorlibraryDumpSensorById (uint8_t sensorID, Print *pPrinter, FormatType_t formatType)
 
EXTERNDEF uint8_t sensorlibraryGetI2Caddress (uint8_t sensorID)
 
EXTERNDEF uint8_t sensorlibraryGetSensorSpecificData (uint8_t sensorID)
 

Variables

EXTERNVAR const char *const datatypeNames []
 

Detailed Description

Manage a library of sensors and the instances of those sensors that are observed.

Typedef Documentation

typedef class Sensor Sensor_t

Description of all sensors that have been found.

The unique ID for onewire sensors is the serial number of the device.

Function Documentation

EXTERNDEF int8_t sensorlibraryCreateSensor ( uint8_t *  uniqueID,
String  name,
uint8_t  bitsOfData,
bool  isSigned,
SensorInterfaceID_t  interface,
SensorTypeID_t  sensorType,
SensorDatatypeID_t  datatype,
uint8_t  decimalPlaces,
uint8_t  sensorSpecific,
pSENSOR_READ_CALLBACK  pReader 
)

Establish a new sensor in the library.

Parameters
uniqueIDunique among sensors of the same type
namestring to emit for people
bitsOfDatabits in one sample
isSigneddata is a signed value
interfacehow the sensor is connected
sensorTypewhat kind of device provides the sensing
datatypetype of information that is stored
decimalPlacesplaces for display as a fixed point number
sensorSpecificinfo about this sensor
pReadercallback to read the sensor
Returns
unique ID for sensor created, -1 if no space
EXTERNDEF void sensorlibraryDisableSensor ( uint8_t  sensorID)

Once a sensor is created it can be turned off. This disables printout of the sensor and is typically used to decomission a sensor that is not available because the hardware is being used for another purpose

EXTERNDEF void sensorlibraryDumpAddColumns ( Print *  pPrinter,
GraphType_t  graphType,
SensorDatatypeID_t  datatype 
)

Dump the addColumn lines for a graph. Lines appropriate to sensors that are intervals can be emitted or lines that are appropriate to sensors that are samples.

??? future enhancements may add other graph types which will need updates to the types of graphs that can be output.

The lines have the form:

data.addColumn('number', 'ADC 0');
Parameters
pPrinterwhere to send the ouput
graphTypewhat kind of graph is being emitted
datatypetype of data elements to put in the list
EXTERNDEF void sensorlibraryDumpElement ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType = FormatForConsole,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print the contents of an element reporting the value logged in the element by the sensorlibraryReadSensors call.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
elementblock of data to work on
formatTypetype of output to do
datatypelimit output to this datatype
EXTERNDEF void sensorlibraryDumpElementIDvalue ( Print *  pPrinter,
uint8_t  indent,
LogElement_t element,
FormatType_t  formatType = FormatForConsole,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print the contents of an element reporting the value logged in the element by the sensorlibraryReadSensors call. Limit the ouptut of each sensor to the ID and value of that sensor.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
elementblock of data to work on
formatTypetype of output to do
datatypelimit output to this datatype
EXTERNDEF void sensorlibraryDumpSampleList ( Print *  pPrinter,
LogElement_t element,
SensorDatatypeID_t  datatype = SDallTypes 
)

Print a comma seperated list of sample values. Skip over the pulse counts and pin arrays

Parameters
pPrinterwhere to send the output
elementelement to dump samples from
datatypetype of data elements to put in the list
EXTERNDEF void sensorlibraryDumpSensorById ( uint8_t  index,
Print *  pPrinter,
FormatType_t  formatType 
)

Dump a sensor given the ID returned by sensorlibraryCreateSensor.

Parameters
indexSensor ID
pPrinterwhere to send the ouput
formatTypehow to format the output
EXTERNDEF void sensorlibraryDumpSensorName ( Print *  pPrinter,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the name of a sensor based on the ID index of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
sensorIDID returned by sensorlibraryCreateSensor
formatTypehow to format the output
EXTERNDEF void sensorlibraryDumpSensors ( Print *  pPrinter = &Serial,
FormatType_t  formatType = FormatForConsole 
)

Dump a list of sensors

Parameters
pPrinterprinter to use for output
formatTypetype of ouput to emit
EXTERNDEF void sensorlibraryDumpSensorUniqueID ( Print *  pPrinter,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the unique ID of a sensor based on the ID index of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
sensorIDID returned by sensorlibraryCreateSensor
formatTypehow to format the output
EXTERNDEF void sensorlibraryDumpSensorValue ( Print *  pPrinter,
uint8_t  indent,
uint32_t  value,
uint8_t  sensorID,
FormatType_t  formatType = FormatForConsole 
)

Dump the value of a sensor based on the unique ID of the sensor determined when the sensor was created with sensorlibraryCreateSensor.

Parameters
pPrinterwhere to sent the output
indentindentation for each new line
valuevalue to dump
sensorIDID returned by sensorlibraryCreateSensor
formatTypeformat of output
EXTERNDEF uint32_t sensorlibraryExtractPulseCount ( uint8_t  index,
LogElement_t element,
uint32_t  defaultCount 
)

Given an element extract the Nth pulse count cell.

Parameters
indexwhich pulse count to extract
elementelement to fetch it from
defaultCountvalue to store in element if value found is invalid
Returns
the value of the Nth pulse count cell from the element
EXTERNDEF uint8_t sensorlibraryGetI2Caddress ( uint8_t  sensorID)

Look up the I2C address for a sensor. The I2C address is stored in the last byte of the uniqueID for TCA9535 device pins.

Parameters
sensorIDindex into 'sensors' table
Returns
I2C address for the device which contains this I/O pin
EXTERNDEF String sensorlibraryGetSensorName ( uint8_t  index)

Fetch a pointer to the name of a sensor given the ID returned by sensorlibraryCreateSensor.

Parameters
indexSensor ID
Returns
: name of the sensor
EXTERNDEF uint8_t sensorlibraryGetSensorSpecificData ( uint8_t  sensorID)

Look up the sensor specific data for a sensor.

Parameters
sensorIDindex into 'sensors' table
Returns
I2C address for the device which contains this I/O pin
EXTERNDEF void sensorlibraryInit ( )

< version of this module

Initialize the onewire services, call once at system startup.

EXTERNDEF String sensorlibraryInterfaceGetName ( SensorInterfaceID_t  interface)

Get the name of a sensor interface

Parameters
interfacethe interface ID
Returns
: name of the interface as a String
EXTERNDEF void sensorlibraryReadSensors ( LogElement_t element)

Read each sensor in the library and place it into the element that gets logged.

Parameters
elementblock of data to write data to
EXTERNDEF String sensorlibrarySensorTypeGetName ( SensorTypeID_t  sensorType)

Get the name of a sensor type

Parameters
sensorTypethe sensor type ID
Returns
: name of the sensor type as a String
EXTERNDEF void sensorlibrarySetPulsesSinceBoot ( LogElement_t element)

For all sensors that are pulse counters read the value from the element and tell the pulse counter module the initial value. This should be called with the latest element from the database at system startup to update the pulse counters with the pulses to date.

Parameters
elementelement to take initial pulses from

Update the pulse counter module

Variable Documentation

EXTERNVAR const char* const datatypeNames[]
Initial value:
= {
"Pin",
"Voltage",
"Degrees C",
"Number",
"Pulse Count",
"Pulse Frequency",
"Pressure",
"All"
}

This array is indexed by a SensorDatatypeID_t to get the ASCIZ name of that type.