LCOV - code coverage report
Current view: top level - message - msg_sensor.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 32.8 % 58 19
Test Date: 2026-02-15 13:08:52 Functions: 42.9 % 7 3
Branches: 22.7 % 22 5

             Branch data     Line data    Source code
       1                 :             : #include <stdbool.h>
       2                 :             : #include <stdint.h>
       3                 :             : 
       4                 :             : #include "can.h"
       5                 :             : #include "message_types.h"
       6                 :             : #include "msg_common.h"
       7                 :             : #include "msg_sensor.h"
       8                 :             : 
       9                 :           1 : void build_analog_data_16bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      10                 :             :                                                                  can_analog_sensor_id_t sensor_id, uint16_t sensor_data,
      11                 :             :                                                                  can_msg_t *output) {
      12                 :           1 :         w_assert(output);
      13                 :             : 
      14                 :           1 :         output->sid = build_sid(prio, MSG_SENSOR_ANALOG16, sensor_id);
      15                 :           1 :         write_timestamp(timestamp, output);
      16                 :             : 
      17                 :           1 :         output->data[2] = (sensor_data >> 8) & 0xff;
      18                 :           1 :         output->data[3] = (sensor_data >> 0) & 0xff;
      19                 :             : 
      20                 :           1 :         output->data_len = 4;
      21                 :           1 : }
      22                 :             : 
      23                 :           0 : void build_analog_data_32bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      24                 :             :                                                                  can_analog_sensor_id_t sensor_id, uint32_t sensor_data,
      25                 :             :                                                                  can_msg_t *output) {
      26                 :           0 :         w_assert(output);
      27                 :             : 
      28                 :           0 :         output->sid = build_sid(prio, MSG_SENSOR_ANALOG32, sensor_id);
      29                 :           0 :         write_timestamp(timestamp, output);
      30                 :             : 
      31                 :           0 :         output->data[2] = (sensor_data >> 24) & 0xff;
      32                 :           0 :         output->data[3] = (sensor_data >> 16) & 0xff;
      33                 :           0 :         output->data[4] = (sensor_data >> 8) & 0xff;
      34                 :           0 :         output->data[5] = (sensor_data >> 0) & 0xff;
      35                 :             : 
      36                 :           0 :         output->data_len = 6;
      37                 :           0 : }
      38                 :             : 
      39                 :           0 : void build_dem_analog_data_16bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      40                 :             :                                                                          can_dem_sensor_id_t dem_sensor_id, uint16_t sensor_data_x,
      41                 :             :                                                                          uint16_t sensor_data_y, uint16_t sensor_data_z,
      42                 :             :                                                                          can_msg_t *output) {
      43                 :           0 :         w_assert(output);
      44                 :             : 
      45                 :           0 :         output->sid = build_sid(prio, MSG_SENSOR_DEM_ANALOG16, dem_sensor_id);
      46                 :           0 :         write_timestamp(timestamp, output);
      47                 :             : 
      48                 :           0 :         output->data[2] = (sensor_data_x >> 8) & 0xff;
      49                 :           0 :         output->data[3] = (sensor_data_x >> 0) & 0xff;
      50                 :           0 :         output->data[4] = (sensor_data_y >> 8) & 0xff;
      51                 :           0 :         output->data[5] = (sensor_data_y >> 0) & 0xff;
      52                 :           0 :         output->data[6] = (sensor_data_z >> 8) & 0xff;
      53                 :           0 :         output->data[7] = (sensor_data_z >> 0) & 0xff;
      54                 :             : 
      55                 :           0 :         output->data_len = 8;
      56                 :           0 : }
      57                 :             : 
      58                 :           1 : bool msg_is_sensor_data(const can_msg_t *msg) {
      59         [ -  + ]:           1 :         if (!msg) {
      60                 :             :                 return false;
      61                 :             :         }
      62                 :             : 
      63                 :           1 :         uint16_t type = get_message_type(msg);
      64         [ -  + ]:           1 :         if (type == MSG_SENSOR_ANALOG16 || type == MSG_SENSOR_ANALOG32 ||
      65                 :             :                 type == MSG_SENSOR_DEM_ANALOG16) {
      66                 :             :                 return true;
      67                 :             :         } else {
      68                 :             :                 return false;
      69                 :             :         }
      70                 :             : }
      71                 :             : 
      72                 :           1 : bool get_analog_data_16bit(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id,
      73                 :             :                                                    uint16_t *output_data) {
      74         [ -  + ]:           1 :         if (!msg) {
      75                 :             :                 return false;
      76                 :             :         }
      77         [ -  + ]:           1 :         if (!output_data) {
      78                 :             :                 return false;
      79                 :             :         }
      80         [ -  + ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG16) {
      81                 :             :                 return false;
      82                 :             :         }
      83                 :             : 
      84                 :           1 :         *sensor_id = get_message_metadata(msg);
      85                 :           1 :         *output_data = ((uint16_t)msg->data[2] << 8) | msg->data[3];
      86                 :             : 
      87                 :           1 :         return true;
      88                 :             : }
      89                 :             : 
      90                 :           0 : bool get_analog_data_32bit(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id,
      91                 :             :                                                    uint32_t *output_data) {
      92         [ #  # ]:           0 :         if (!msg) {
      93                 :             :                 return false;
      94                 :             :         }
      95         [ #  # ]:           0 :         if (!output_data) {
      96                 :             :                 return false;
      97                 :             :         }
      98         [ #  # ]:           0 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG16) {
      99                 :             :                 return false;
     100                 :             :         }
     101                 :             : 
     102                 :           0 :         *sensor_id = get_message_metadata(msg);
     103                 :           0 :         *output_data = ((uint32_t)msg->data[2] << 24) | ((uint32_t)msg->data[3] << 16) |
     104                 :           0 :                                    ((uint32_t)msg->data[4] << 8) | msg->data[5];
     105                 :             : 
     106                 :           0 :         return true;
     107                 :             : }
     108                 :             : 
     109                 :           0 : bool get_dem_analog_data_16bit(const can_msg_t *msg, can_dem_sensor_id_t *dem_sensor_id,
     110                 :             :                                                            uint16_t *output_data_x, uint16_t *output_data_y,
     111                 :             :                                                            uint16_t *output_data_z) {
     112         [ #  # ]:           0 :         if (!msg) {
     113                 :             :                 return false;
     114                 :             :         }
     115         [ #  # ]:           0 :         if (!output_data_x) {
     116                 :             :                 return false;
     117                 :             :         }
     118         [ #  # ]:           0 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG16) {
     119                 :             :                 return false;
     120                 :             :         }
     121                 :             : 
     122                 :           0 :         *dem_sensor_id = get_message_metadata(msg);
     123                 :           0 :         *output_data_x = ((uint16_t)msg->data[2] << 8) | msg->data[3];
     124                 :           0 :         *output_data_y = ((uint16_t)msg->data[4] << 8) | msg->data[5];
     125                 :           0 :         *output_data_z = ((uint16_t)msg->data[6] << 8) | msg->data[7];
     126                 :             : 
     127                 :           0 :         return true;
     128                 :             : }
        

Generated by: LCOV version 2.0-1