![]() |
RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
|
PMS5003 particulate-matter (dust) sensor read over serial, reporting PM1.0/PM2.5/PM10 concentrations, particle counts by diameter, rolling averages, and an air-quality evaluation. More...
#include <PMS5003.h>
Public Member Functions | |
| PMS5003 (const std::string &devicePath) | |
| Builds a PMS5003 for the given serial device path, seeding its data map so each reading updates in place. More... | |
| virtual | ~PMS5003 () |
| Destroys the sensor, turning it off first. More... | |
| virtual void | TurnOn () override |
| Opens the serial device at 9600 baud and marks the sensor running, reporting the result through the AlertManager. More... | |
| virtual void | TurnOff () override |
| Closes the serial device (if open) and marks the sensor stopped. More... | |
| virtual int | ReadRawValue () |
| Reads a single raw byte from the serial device. More... | |
| virtual void | ProcessRawValues () override |
| Reads and validates a serial frame (retrying up to RUMPI_MAX_READ_ATTEMPTS), decodes the PM1.0/PM2.5/PM10 concentrations and particle counts from their big-endian byte pairs, and feeds each into its rolling average. More... | |
| virtual bool | IsDataValid (const float *dataToValidate, const size_t bufferSize) const |
| Validates a serial frame by summing all bytes except the trailing two and comparing against the big-endian checksum those two bytes carry. More... | |
| virtual std::string | DetermineAirQuality () const |
| Gets the full air-quality advisory text (quality, at-risk groups, and guidance) for the current average readings. More... | |
| virtual std::string | DetermineAirQuality (const float pmTwoPointFiveReading, const float pmTenReading) const |
| Gets the full air-quality advisory text (quality, at-risk groups, and guidance) for given PM2.5 and PM10 readings. More... | |
| virtual std::string | DetermineAirQualityCategory () const |
| Gets the short air-quality category name for the current average readings. More... | |
| virtual std::string | DetermineAirQualityCategory (const float pmTwoPointFiveReading, const float pmTenReading) const |
| Gets the short form of the air-quality evaluation - just the category name, for compact UI labels such as the Home scene pill. More... | |
| virtual E_AirQualityLevel | CalculateAirQualitySeverity () const |
| Maps the current average PM2.5 and PM10 readings onto a 0 (good) to 5 (hazardous) severity, taking whichever of the two is worse. More... | |
| virtual E_AirQualityLevel | CalculateAirQualitySeverity (const float pmTwoPointFiveReading, const float pmTenReading) const |
| Maps given PM2.5 and PM10 readings onto a 0 (good) to 5 (hazardous) severity, bucketing each against its own thresholds and returning the worse of the two. More... | |
| virtual std::string | ToString () const override |
| Serializes every current reading and rolling average (PM concentrations, particle counts) plus the air-quality evaluation to a string. More... | |
| float | GetPMOneFactory () const |
| Gets the factory-calibrated PM1.0 concentration. More... | |
| float | GetPMOneAverageFactory () const |
| Gets the rolling average of the factory-calibrated PM1.0 concentration. More... | |
| float | GetPMTwoPointFiveFactory () const |
| Gets the factory-calibrated PM2.5 concentration. More... | |
| float | GetPMTwoPointFiveAverageFactory () const |
| Gets the rolling average of the factory-calibrated PM2.5 concentration. More... | |
| float | GetPMTenFactory () const |
| Gets the factory-calibrated PM10 concentration. More... | |
| float | GetPMTenAverageFactory () const |
| Gets the rolling average of the factory-calibrated PM10 concentration. More... | |
| float | GetPMOneAtmospheric () const |
| Gets the atmospheric PM1.0 concentration. More... | |
| float | GetPMOneAverageAtmospheric () const |
| Gets the rolling average of the atmospheric PM1.0 concentration. More... | |
| float | GetPMTwoPointFiveAtmospheric () const |
| Gets the atmospheric PM2.5 concentration. More... | |
| float | GetPMTwoPointFiveAverageAtmospheric () const |
| Gets the rolling average of the atmospheric PM2.5 concentration. More... | |
| float | GetPMTenAtmospheric () const |
| Gets the atmospheric PM10 concentration. More... | |
| float | GetPMTenAverageAtmospheric () const |
| Gets the rolling average of the atmospheric PM10 concentration. More... | |
| float | GetNumberOfParticlesLargerThanZeroPointThreeMicronDiameter () const |
| Gets the number of particles larger than 0.3um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanZeroPointThreeMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 0.3um in diameter. More... | |
| float | GetNumberOfParticlesLargerThanZeroPointFiveMicronDiameter () const |
| Gets the number of particles larger than 0.5um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanZeroPointFiveMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 0.5um in diameter. More... | |
| float | GetNumberOfParticlesLargerThanOneMicronDiameter () const |
| Gets the number of particles larger than 1um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanOneMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 1um in diameter. More... | |
| float | GetNumberOfParticlesLargerThanTwoPointFiveMicronDiameter () const |
| Gets the number of particles larger than 2.5um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanTwoPointFiveMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 2.5um in diameter. More... | |
| float | GetNumberOfParticlesLargerThanFiveMicronDiameter () const |
| Gets the number of particles larger than 5um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanFiveMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 5um in diameter. More... | |
| float | GetNumberOfParticlesLargerThanTenMicronDiameter () const |
| Gets the number of particles larger than 10um in diameter. More... | |
| float | GetAverageNumberOfParticlesLargerThanTenMicronDiameter () const |
| Gets the rolling average of the number of particles larger than 10um in diameter. More... | |
Public Member Functions inherited from RumPi::BaseComponent | |
| BaseComponent () | |
| Builds a base component with an unknown type and an empty name. More... | |
| virtual | ~BaseComponent () |
| Virtual destructor so deleting a component through a BaseComponent* also cleans up the concrete subclass. More... | |
| virtual void | TurnOn ()=0 |
| Turns the component on (e.g. More... | |
| virtual void | TurnOff ()=0 |
| Turns the component off. More... | |
| virtual std::string | ToString () const =0 |
| Serializes the component's current readings to a string (usually JSON). More... | |
| virtual void | ProcessRawValues ()=0 |
| Reads and processes the component's latest raw values (called once per poll). More... | |
| virtual EComponentType | GetComponentType () const |
| Gets the component's type. More... | |
| const std::string & | GetName () const |
| Gets the component's unique per-instance name. More... | |
| void | SetName (const std::string &name) |
| Sets the component's unique per-instance name. More... | |
Protected Attributes | |
| bool | myIsRunning |
| True while the serial device is open and readable. More... | |
| int | mySerialDeviceFileDescriptor |
| The open serial device file descriptor. More... | |
| std::string | myDevicePath |
| The serial device path. More... | |
| RollingAverage | myPMOneAverageFactory |
| Rolling average of the factory-calibrated PM1.0 reading. More... | |
| RollingAverage | myPMTwoPointFiveAverageFactory |
| Rolling average of the factory-calibrated PM2.5 reading. More... | |
| RollingAverage | myPMTenAverageFactory |
| Rolling average of the factory-calibrated PM10 reading. More... | |
| RollingAverage | myPMOneAverageAtmospheric |
| Rolling average of the atmospheric PM1.0 reading. More... | |
| RollingAverage | myPMTwoPointFiveAverageAtmospheric |
| Rolling average of the atmospheric PM2.5 reading. More... | |
| RollingAverage | myPMTenAverageAtmospheric |
| Rolling average of the atmospheric PM10 reading. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanZeroPointThreeMicronDiameter |
| Rolling average of particles > 0.3um. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanZeroPointFiveMicronDiameter |
| Rolling average of particles > 0.5um. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanOneMicronDiameter |
| Rolling average of particles > 1um. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanTwoPointFiveMicronDiameter |
| Rolling average of particles > 2.5um. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanFiveMicronDiameter |
| Rolling average of particles > 5um. More... | |
| RollingAverage | myAverageNumberOfParticlesLargerThanTenMicronDiameter |
| Rolling average of particles > 10um. More... | |
| std::map< std::string, float > | myDustData |
| Most recent raw readings, keyed by measurement name. More... | |
Protected Attributes inherited from RumPi::BaseComponent | |
| EComponentType | myComponentType |
| The kind of component this is (set by each concrete subclass). More... | |
| std::string | myName |
| A unique per-instance name, assigned when the component is added to the manager. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from RumPi::BaseComponent | |
| static std::string | ComponentTypeToString (const EComponentType theComponentTypeToConvert) |
| Maps an EComponentType to its string name. More... | |
| static EComponentType | StringToComponentType (const std::string &theComponentTypeName) |
| Maps a type name back to its EComponentType (the inverse of ComponentTypeToString), so the client can turn the type carried on the wire back into a value it can look an icon up with. More... | |
PMS5003 particulate-matter (dust) sensor read over serial, reporting PM1.0/PM2.5/PM10 concentrations, particle counts by diameter, rolling averages, and an air-quality evaluation.
References: https://www.health.ny.gov/environmental/indoors/air/pmq_a.htm https://www.airveda.com/blog/Understanding-Particulate-Matter-and-Its-Associated-Health-Impact https://ioct.tech/edu/sites/default/files/2019-04/PMS5003-Informational.pdf
| RumPi::PMS5003::PMS5003 | ( | const std::string & | devicePath | ) |
Builds a PMS5003 for the given serial device path, seeding its data map so each reading updates in place.
| [in] | devicePath | The serial device path the sensor is connected to. |
|
virtual |
|
virtual |
Maps the current average PM2.5 and PM10 readings onto a 0 (good) to 5 (hazardous) severity, taking whichever of the two is worse.
Both the short category and the full advisory text derive from this, so the thresholds live in exactly one place.
|
virtual |
Maps given PM2.5 and PM10 readings onto a 0 (good) to 5 (hazardous) severity, bucketing each against its own thresholds and returning the worse of the two.
| [in] | pmTwoPointFiveReading | The PM2.5 reading to evaluate. |
| [in] | pmTenReading | The PM10 reading to evaluate. |
|
virtual |
Gets the full air-quality advisory text (quality, at-risk groups, and guidance) for the current average readings.
|
virtual |
Gets the full air-quality advisory text (quality, at-risk groups, and guidance) for given PM2.5 and PM10 readings.
| [in] | pmTwoPointFiveReading | The PM2.5 reading to evaluate. |
| [in] | pmTenReading | The PM10 reading to evaluate. |
|
virtual |
Gets the short air-quality category name for the current average readings.
|
virtual |
Gets the short form of the air-quality evaluation - just the category name, for compact UI labels such as the Home scene pill.
DetermineAirQuality() returns the full advisory text for a details view.
| [in] | pmTwoPointFiveReading | The PM2.5 reading to evaluate. |
| [in] | pmTenReading | The PM10 reading to evaluate. |
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanFiveMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 5um in diameter.
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanOneMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 1um in diameter.
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanTenMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 10um in diameter.
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanTwoPointFiveMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 2.5um in diameter.
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanZeroPointFiveMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 0.5um in diameter.
| float RumPi::PMS5003::GetAverageNumberOfParticlesLargerThanZeroPointThreeMicronDiameter | ( | ) | const |
Gets the rolling average of the number of particles larger than 0.3um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanFiveMicronDiameter | ( | ) | const |
Gets the number of particles larger than 5um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanOneMicronDiameter | ( | ) | const |
Gets the number of particles larger than 1um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanTenMicronDiameter | ( | ) | const |
Gets the number of particles larger than 10um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanTwoPointFiveMicronDiameter | ( | ) | const |
Gets the number of particles larger than 2.5um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanZeroPointFiveMicronDiameter | ( | ) | const |
Gets the number of particles larger than 0.5um in diameter.
| float RumPi::PMS5003::GetNumberOfParticlesLargerThanZeroPointThreeMicronDiameter | ( | ) | const |
Gets the number of particles larger than 0.3um in diameter.
| float RumPi::PMS5003::GetPMOneAtmospheric | ( | ) | const |
Gets the atmospheric PM1.0 concentration.
| float RumPi::PMS5003::GetPMOneAverageAtmospheric | ( | ) | const |
Gets the rolling average of the atmospheric PM1.0 concentration.
| float RumPi::PMS5003::GetPMOneAverageFactory | ( | ) | const |
Gets the rolling average of the factory-calibrated PM1.0 concentration.
| float RumPi::PMS5003::GetPMOneFactory | ( | ) | const |
Gets the factory-calibrated PM1.0 concentration.
| float RumPi::PMS5003::GetPMTenAtmospheric | ( | ) | const |
Gets the atmospheric PM10 concentration.
| float RumPi::PMS5003::GetPMTenAverageAtmospheric | ( | ) | const |
Gets the rolling average of the atmospheric PM10 concentration.
| float RumPi::PMS5003::GetPMTenAverageFactory | ( | ) | const |
Gets the rolling average of the factory-calibrated PM10 concentration.
| float RumPi::PMS5003::GetPMTenFactory | ( | ) | const |
Gets the factory-calibrated PM10 concentration.
| float RumPi::PMS5003::GetPMTwoPointFiveAtmospheric | ( | ) | const |
Gets the atmospheric PM2.5 concentration.
| float RumPi::PMS5003::GetPMTwoPointFiveAverageAtmospheric | ( | ) | const |
Gets the rolling average of the atmospheric PM2.5 concentration.
| float RumPi::PMS5003::GetPMTwoPointFiveAverageFactory | ( | ) | const |
Gets the rolling average of the factory-calibrated PM2.5 concentration.
| float RumPi::PMS5003::GetPMTwoPointFiveFactory | ( | ) | const |
Gets the factory-calibrated PM2.5 concentration.
|
virtual |
Validates a serial frame by summing all bytes except the trailing two and comparing against the big-endian checksum those two bytes carry.
| [in] | dataToValidate | The frame's bytes (as floats), including the trailing checksum. |
| [in] | bufferSize | The number of bytes in the frame. |
|
overridevirtual |
Reads and validates a serial frame (retrying up to RUMPI_MAX_READ_ATTEMPTS), decodes the PM1.0/PM2.5/PM10 concentrations and particle counts from their big-endian byte pairs, and feeds each into its rolling average.
Implements RumPi::BaseComponent.
|
virtual |
Reads a single raw byte from the serial device.
|
overridevirtual |
Serializes every current reading and rolling average (PM concentrations, particle counts) plus the air-quality evaluation to a string.
Implements RumPi::BaseComponent.
|
overridevirtual |
Closes the serial device (if open) and marks the sensor stopped.
Implements RumPi::BaseComponent.
|
overridevirtual |
Opens the serial device at 9600 baud and marks the sensor running, reporting the result through the AlertManager.
Implements RumPi::BaseComponent.
|
protected |
Rolling average of particles > 5um.
|
protected |
Rolling average of particles > 1um.
|
protected |
Rolling average of particles > 10um.
|
protected |
Rolling average of particles > 2.5um.
|
protected |
Rolling average of particles > 0.5um.
|
protected |
Rolling average of particles > 0.3um.
|
protected |
The serial device path.
|
protected |
Most recent raw readings, keyed by measurement name.
|
protected |
True while the serial device is open and readable.
|
protected |
Rolling average of the atmospheric PM1.0 reading.
|
protected |
Rolling average of the factory-calibrated PM1.0 reading.
|
protected |
Rolling average of the atmospheric PM10 reading.
|
protected |
Rolling average of the factory-calibrated PM10 reading.
|
protected |
Rolling average of the atmospheric PM2.5 reading.
|
protected |
Rolling average of the factory-calibrated PM2.5 reading.
|
protected |
The open serial device file descriptor.