| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "sub_message_parser.h" |
| 2 |
|
|
|
| 3 |
|
|
|
| 4 |
|
✗ |
std::string sub_message_parser::parse_air_quality_pm1_0(const std::vector<uint8_t> &payload) |
| 5 |
|
|
{ |
| 6 |
|
✗ |
if(payload.size() != 4) { |
| 7 |
|
✗ |
std::cerr << "Warning: Air quality PM1_0 found that isn't 4 bytes long." << std::endl; |
| 8 |
|
✗ |
return ERROR_VALUE; |
| 9 |
|
|
} |
| 10 |
|
|
|
| 11 |
|
|
float pm1_0; |
| 12 |
|
✗ |
std::copy(reinterpret_cast<const char*>(&payload[0]), |
| 13 |
|
✗ |
reinterpret_cast<const char*>(&payload[4]), |
| 14 |
|
|
reinterpret_cast<char*>(&pm1_0)); |
| 15 |
|
|
|
| 16 |
|
✗ |
if(pm1_0 < 0){ |
| 17 |
|
✗ |
std::cerr << "Warning: Air quality PM1_0 found that has negative values." << std::endl; |
| 18 |
|
✗ |
return ERROR_VALUE; |
| 19 |
|
|
} |
| 20 |
|
|
|
| 21 |
|
|
// Convert the raw humidity value to a string |
| 22 |
|
✗ |
std::ostringstream oss; |
| 23 |
|
✗ |
oss << pm1_0; |
| 24 |
|
|
|
| 25 |
|
✗ |
return oss.str(); |
| 26 |
|
|
} |
| 27 |
|
|
|