GCC Code Coverage Report


Directory: src/
File: src/message_parser/sub_message_parser/sub_message_parser.cpp
Date: 2026-03-27 13:31:42
Exec Total Coverage
Lines: 12 33 36.4%
Branches: 13 48 27.1%

Line Branch Exec Source
1 #include "sub_message_parser.h"
2 #include "encoder_decoder_messages/data_type.h"
3 #include <string>
4
5 /// @brief Parses a TLV item and converts it into an MQTT message.
6 /// @param item the TLV item to parse
7 /// @return The resulting MQTT message
8 3 parse_response sub_message_parser::parse_tlv(const tlv_item &item)
9 {
10
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 std::string mqtt_payload = ERROR_VALUE;
11
12
1/8
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
3 switch(item.type) {
13 3 case EMT_BEACON_ARRAY:
14
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 mqtt_payload = parse_beacons(item.value);
15 3 break;
16 case EMT_TEMPERATURE:
17 mqtt_payload = parse_temperature(item.value);
18 break;
19 case EMT_HUMIDITY:
20 mqtt_payload = parse_humidity(item.value);
21 break;
22 case EMT_AIR_QUALITY_PM1_0:
23 mqtt_payload = parse_air_quality_pm1_0(item.value);
24 break;
25 case EMT_AIR_QUALITY_PM2_5:
26 mqtt_payload = parse_air_quality_pm2_5(item.value);
27 break;
28 case EMT_AIR_QUALITY_PM10:
29 mqtt_payload = parse_air_quality_pm10(item.value);
30 break;
31 case EMT_CO2:
32 mqtt_payload = parse_co2(item.value);
33 break;
34 default:
35 std::cerr << "Warning: Invalid sub_message_type found: " << std::hex << item.type << std::endl;
36 break;
37 }
38
39
1/2
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
6 std::string mqtt_topic = data_type_to_string(static_cast<data_type>(item.type));
40
2/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9 mqtt_message message(mqtt_topic, mqtt_payload);
41
42
5/6
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
3 if(mqtt_payload == ERROR_VALUE || mqtt_topic.empty()){
43
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 return {message, false};
44 }
45
46
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 return {message, true};
47 3 }
48