LCOV - code coverage report
Current view: top level - message/msg_sensor.c (source / functions) Coverage Total Hit
Test: coverage-filtered.info Lines: 98.9 % 89 88
Test Date: 2026-03-20 08:45:03 Functions: 100.0 % 9 9
Branches: 51.8 % 56 29
MC/DC: 50.0 % 56 28

             Branch data      MC/DC data    Line data    Source code
       1                 :              :             : #include <stdbool.h>
       2                 :              :             : #include <stdint.h>
       3                 :              :             : 
       4                 :              :             : #include "common.h"
       5                 :              :             : 
       6                 :              :             : #include "can.h"
       7                 :              :             : #include "message_types.h"
       8                 :              :             : #include "msg_common.h"
       9                 :              :             : #include "msg_sensor.h"
      10                 :              :             : 
      11                 :              :           1 : void build_analog_sensor_16bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      12                 :              :             :                                                                    can_analog_sensor_id_t sensor_id, uint16_t sensor_data,
      13                 :              :             :                                                                    can_msg_t *output) {
      14         [ +  - ]:      [ T  f ]:           1 :         w_assert(output);
      15                 :              :             : 
      16                 :              :           1 :         output->sid = build_sid(prio, MSG_SENSOR_ANALOG16, sensor_id);
      17                 :              :           1 :         write_timestamp(timestamp, output);
      18                 :              :             : 
      19                 :              :           1 :         output->data[2] = (sensor_data >> 8) & 0xff;
      20                 :              :           1 :         output->data[3] = (sensor_data >> 0) & 0xff;
      21                 :              :             : 
      22                 :              :           1 :         output->data_len = 4;
      23                 :              :           1 : }
      24                 :              :             : 
      25                 :              :           1 : void build_analog_sensor_32bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      26                 :              :             :                                                                    can_analog_sensor_id_t sensor_id, uint32_t sensor_data,
      27                 :              :             :                                                                    can_msg_t *output) {
      28         [ +  - ]:      [ T  f ]:           1 :         w_assert(output);
      29                 :              :             : 
      30                 :              :           1 :         output->sid = build_sid(prio, MSG_SENSOR_ANALOG32, sensor_id);
      31                 :              :           1 :         write_timestamp(timestamp, output);
      32                 :              :             : 
      33                 :              :           1 :         output->data[2] = (sensor_data >> 24) & 0xff;
      34                 :              :           1 :         output->data[3] = (sensor_data >> 16) & 0xff;
      35                 :              :           1 :         output->data[4] = (sensor_data >> 8) & 0xff;
      36                 :              :           1 :         output->data[5] = (sensor_data >> 0) & 0xff;
      37                 :              :             : 
      38                 :              :           1 :         output->data_len = 6;
      39                 :              :           1 : }
      40                 :              :             : 
      41                 :              :           1 : void build_3d_analog_sensor_16bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      42                 :              :             :                                                                           can_dem_3d_sensor_id_t sensor_id, uint16_t sensor_data_x,
      43                 :              :             :                                                                           uint16_t sensor_data_y, uint16_t sensor_data_z,
      44                 :              :             :                                                                           can_msg_t *output) {
      45         [ +  - ]:      [ T  f ]:           1 :         w_assert(output);
      46                 :              :             : 
      47                 :              :           1 :         output->sid = build_sid(prio, MSG_SENSOR_3D_ANALOG16, sensor_id);
      48                 :              :           1 :         write_timestamp(timestamp, output);
      49                 :              :             : 
      50                 :              :           1 :         output->data[2] = (sensor_data_x >> 8) & 0xff;
      51                 :              :           1 :         output->data[3] = (sensor_data_x >> 0) & 0xff;
      52                 :              :           1 :         output->data[4] = (sensor_data_y >> 8) & 0xff;
      53                 :              :           1 :         output->data[5] = (sensor_data_y >> 0) & 0xff;
      54                 :              :           1 :         output->data[6] = (sensor_data_z >> 8) & 0xff;
      55                 :              :           1 :         output->data[7] = (sensor_data_z >> 0) & 0xff;
      56                 :              :             : 
      57                 :              :           1 :         output->data_len = 8;
      58                 :              :           1 : }
      59                 :              :             : 
      60                 :              :           1 : void build_2d_analog_sensor_24bit_msg(can_msg_prio_t prio, uint16_t timestamp,
      61                 :              :             :                                                                           can_dem_2d_sensor_id_t sensor_id, uint32_t sensor_data_x,
      62                 :              :             :                                                                           uint32_t sensor_data_y, can_msg_t *output) {
      63         [ +  - ]:      [ T  f ]:           1 :         w_assert(output);
      64         [ +  - ]:      [ T  f ]:           1 :         w_assert((sensor_data_x & 0xff000000) == 0);
      65         [ +  - ]:      [ T  f ]:           1 :         w_assert((sensor_data_y & 0xff000000) == 0);
      66                 :              :             : 
      67                 :              :           1 :         output->sid = build_sid(prio, MSG_SENSOR_2D_ANALOG24, sensor_id);
      68                 :              :           1 :         write_timestamp(timestamp, output);
      69                 :              :             : 
      70                 :              :           1 :         output->data[2] = (sensor_data_x >> 16) & 0xff;
      71                 :              :           1 :         output->data[3] = (sensor_data_x >> 8) & 0xff;
      72                 :              :           1 :         output->data[4] = (sensor_data_x >> 0) & 0xff;
      73                 :              :           1 :         output->data[5] = (sensor_data_y >> 16) & 0xff;
      74                 :              :           1 :         output->data[6] = (sensor_data_y >> 8) & 0xff;
      75                 :              :           1 :         output->data[7] = (sensor_data_y >> 0) & 0xff;
      76                 :              :             : 
      77                 :              :           1 :         output->data_len = 8;
      78                 :              :           1 : }
      79                 :              :             : 
      80                 :              :           4 : bool msg_is_analog_sensor(const can_msg_t *msg) {
      81         [ +  - ]:      [ T  f ]:           4 :         w_assert(msg);
      82                 :              :             : 
      83                 :              :           4 :         uint16_t type = get_message_type(msg);
      84                 :              :           4 :         if (type == MSG_SENSOR_ANALOG16 || type == MSG_SENSOR_ANALOG32 ||
      85   [ +  +  -  + ]:[ T  f  T  f ]:           4 :                 type == MSG_SENSOR_3D_ANALOG16 || type == MSG_SENSOR_2D_ANALOG24) {
      86                 :              :             :                 return true;
      87                 :              :             :         } else {
      88                 :              :           0 :                 return false;
      89                 :              :             :         }
      90                 :              :             : }
      91                 :              :             : 
      92                 :              :           1 : bool get_analog_sensor_data_16bit(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id,
      93                 :              :             :                                                                   uint16_t *output_data) {
      94         [ +  - ]:      [ T  f ]:           1 :         w_assert(msg);
      95         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_id);
      96         [ +  - ]:      [ T  f ]:           1 :         w_assert(output_data);
      97                 :              :             : 
      98         [ +  - ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG16) {
      99                 :              :             :                 return false;
     100                 :              :             :         }
     101                 :              :             : 
     102                 :              :           1 :         *sensor_id = get_message_metadata(msg);
     103                 :              :           1 :         *output_data = ((uint16_t)msg->data[2] << 8) | msg->data[3];
     104                 :              :             : 
     105                 :              :           1 :         return true;
     106                 :              :             : }
     107                 :              :             : 
     108                 :              :           1 : bool get_analog_sensor_data_32bit(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id,
     109                 :              :             :                                                                   uint32_t *output_data) {
     110         [ +  - ]:      [ T  f ]:           1 :         w_assert(msg);
     111         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_id);
     112         [ +  - ]:      [ T  f ]:           1 :         w_assert(output_data);
     113                 :              :             : 
     114         [ +  - ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG32) {
     115                 :              :             :                 return false;
     116                 :              :             :         }
     117                 :              :             : 
     118                 :              :           1 :         *sensor_id = get_message_metadata(msg);
     119                 :              :           1 :         *output_data = ((uint32_t)msg->data[2] << 24) | ((uint32_t)msg->data[3] << 16) |
     120                 :              :           1 :                                    ((uint32_t)msg->data[4] << 8) | msg->data[5];
     121                 :              :             : 
     122                 :              :           1 :         return true;
     123                 :              :             : }
     124                 :              :             : 
     125                 :              :           1 : bool get_3d_analog_sensor_data_16bit(const can_msg_t *msg, can_dem_3d_sensor_id_t *sensor_id,
     126                 :              :             :                                                                          uint16_t *output_data_x, uint16_t *output_data_y,
     127                 :              :             :                                                                          uint16_t *output_data_z) {
     128         [ +  - ]:      [ T  f ]:           1 :         w_assert(msg);
     129         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_id);
     130         [ +  - ]:      [ T  f ]:           1 :         w_assert(output_data_x);
     131         [ +  - ]:      [ T  f ]:           1 :         w_assert(output_data_y);
     132         [ +  - ]:      [ T  f ]:           1 :         w_assert(output_data_z);
     133                 :              :             : 
     134         [ +  - ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_3D_ANALOG16) {
     135                 :              :             :                 return false;
     136                 :              :             :         }
     137                 :              :             : 
     138                 :              :           1 :         *sensor_id = get_message_metadata(msg);
     139                 :              :           1 :         *output_data_x = ((uint16_t)msg->data[2] << 8) | msg->data[3];
     140                 :              :           1 :         *output_data_y = ((uint16_t)msg->data[4] << 8) | msg->data[5];
     141                 :              :           1 :         *output_data_z = ((uint16_t)msg->data[6] << 8) | msg->data[7];
     142                 :              :             : 
     143                 :              :           1 :         return true;
     144                 :              :             : }
     145                 :              :             : 
     146                 :              :           1 : bool get_2d_analog_sensor_data_24bit(const can_msg_t *msg, can_dem_2d_sensor_id_t *sensor_id,
     147                 :              :             :                                                                          uint32_t *sensor_data_x, uint32_t *sensor_data_y) {
     148         [ +  - ]:      [ T  f ]:           1 :         w_assert(msg);
     149         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_id);
     150         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_data_x);
     151         [ +  - ]:      [ T  f ]:           1 :         w_assert(sensor_data_x);
     152                 :              :             : 
     153         [ +  - ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_2D_ANALOG24) {
     154                 :              :             :                 return false;
     155                 :              :             :         }
     156                 :              :             : 
     157                 :              :           1 :         *sensor_id = get_message_metadata(msg);
     158                 :              :           1 :         *sensor_data_x = ((uint32_t)msg->data[2] << 16) | ((uint32_t)msg->data[3] << 8) | msg->data[4];
     159                 :              :           1 :         *sensor_data_y = ((uint32_t)msg->data[5] << 16) | ((uint32_t)msg->data[6] << 8) | msg->data[7];
     160                 :              :             : 
     161                 :              :           1 :         return true;
     162                 :              :             : }
        

Generated by: LCOV version 2.0-1