© QuantAQ, Inc 2021 – V0.1.0
Get Started ⚡ This guide covers how data flags work and how to decode them.
Each QuantAQ device records a flag value with each data record to let you know the state of the device and to help you understand when data may be corrupt or otherwise invalid. Each device has its own set of flags that are unique to that product model; the exact flags and their values can be found on the device's product page.
Flags are stored as unsigned integers and contain encoded information about each of the on-board sensors. They are generated via bit-masking and can be decoded by reversing the procedure. To determine whether a specific flag is set, you can use the bitwise
and operation (
&) → if the flag's value is returned, then that flag is set. If a zero is returned, it is not set. This can seem a bit complicated, so let's clear it up via examples.
Let's say the flags for a given device are as follows:
|Flag Name||Flag Value||Flag Description|
This flag is set for a period of time after the device has started up → this equates to the 'warm up' period.
This flag is set when something goes wrong with the OPC (nominally a SPI communication error)
This flag is set when the CO data is corrupt for when the CO sensor is warming up.
This flag is set when the NO data is corrupt for when the NO sensor is warming up.
This flag is set when the NO2 data is corrupt for when the NO2 sensor is warming up.
Each data record will have its own flag value, but let's take a single record as an example and extract its value. Let's say the value is 1. If we do the bitwise operation, we get the following:
# bitwise AND - is FLAG_STARTUP set? >>> 1 & 1 1
We see above that FLAG_STARTUP was set → this means the device was recently started up and the electrochemical gas sensor may still be warming up.
How about a slightly more complicated example? Let's say the value for flag is 24:
# bitwise AND - is FLAG_STARTUP set? >>> 24 & 1 0 # bitwise AND - is FLAG_CO set? >>> 24 & 4 0 # bitwise AND - is FLAG_NO set? >>> 24 & 8 8 # bitwise AND - is FLAG_NO2 set? >>> 24 & 16 16
As we can see above, a 24 for this device means that FLAG_NO and FLAG_NO2 are set. Hopefully, this provides an idea for how you can decode flags → if you're looking for an automated way to do this, check out our Command Line Interface tutorial.