Decoding Flags


This SOP covers the interpretation and decoding of flags - flags appear in all data sources regardless of whether they originate via the QuantAQ Cloud or local storage on the devices.

Every device records a flag value with each data row to let you know what's going on with the state of the system and to help you understand when data may be corrupt or otherwise invalid. Each device has different flags that are unique to that device, so please check the individual device page for the exact flags and their values.

Flags are stored as unsigned integers and contain encoded information about each of the sensors on-board. 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 bit-wise and operation - if the flag's value is returned, then it is set. If a zero is returned, it is not set. This can seem complicated, so let's clear it up with an example.


Let's say our Flag Table looks something like this:

Sample Flag Table

Flag NameFlag ValueDescription
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 communication to the OPC
This flag is set when CO data is corrupt or when the CO sensor is warming up
This flag is set when NO data is corrupt or when the NO sensor is warming up
This flag is set when NO2 data is corrupt or when the NO2 sensor is warming up

Each row of data will have its own flag value, but let's just take one row of data and extract its value. Let's say the value is 1. If we do the bit-wise operation, we see the following:

# bit AND - is FLAG_STARTUP set?
>>> 1 & 1

We see that the STARTUP_FLAG was set, which means the device has recently started up and the electrochemical gas sensors may be warming up. What about a slightly more complicated example? Let's say we encounter a 24:

# bit AND - is FLAG_STARTUP set?
>>> 24 & 1

# bit AND - is FLAG_CO set?
>>> 24 & 4

# bit AND - is FLAG_NO set?
>>> 24 & 8

# bit AND - is FLAG_NO2 set?
>>> 24 & 16

As you can see above, a 24 means the NO and NO2 flags were set.

Hopefully this provides an idea of how you can decode the flags - if you have questions, feel free to file an issue at support@quant-aq.com!