| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "sub_message_parser.h" |
| 2 |
|
|
|
| 3 |
|
✗ |
std::string sub_message_parser::parse_humidity(const std::vector<uint8_t>& payload) { |
| 4 |
|
|
|
| 5 |
|
✗ |
if(payload.size() != 2) { |
| 6 |
|
✗ |
std::cerr << "Warning: Humidity found that isn't 2 bytes long." << std::endl; |
| 7 |
|
✗ |
return ERROR_VALUE; |
| 8 |
|
|
} |
| 9 |
|
|
|
| 10 |
|
✗ |
const uint8_t humidity_whole = payload[0]; |
| 11 |
|
✗ |
const uint8_t humidity_fractional = payload[1]; |
| 12 |
|
|
|
| 13 |
|
✗ |
const float humidity = static_cast<float>(humidity_whole) + static_cast<float>(humidity_fractional)/100; |
| 14 |
|
|
|
| 15 |
|
✗ |
if(humidity_whole >= 100 && humidity_fractional > 0){ |
| 16 |
|
✗ |
std::cerr << "Warning: Humidity can't have fractions when humidity_whole == 100." << std::endl; |
| 17 |
|
✗ |
return ERROR_VALUE; |
| 18 |
|
|
} |
| 19 |
|
|
|
| 20 |
|
✗ |
if(humidity_fractional > 100){ |
| 21 |
|
✗ |
std::cerr << "Warning: Humidity fractional can't be above 100." << std::endl; |
| 22 |
|
✗ |
return ERROR_VALUE; |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
✗ |
if (humidity_whole > 100) { |
| 26 |
|
✗ |
std::cerr << "Warning: Humidity whole found that is larger than 100%." << std::endl; |
| 27 |
|
✗ |
return ERROR_VALUE; |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
// Convert the raw humidity value to a string |
| 31 |
|
✗ |
std::ostringstream oss; |
| 32 |
|
✗ |
oss << humidity; |
| 33 |
|
|
|
| 34 |
|
✗ |
return oss.str(); |
| 35 |
|
|
} |
| 36 |
|
|
|