LCOV - code coverage report
Current view: top level - message/msg_sensor.c (source / functions) Coverage Total Hit
Test: coverage-filtered.info Lines: 91.2 % 102 93
Test Date: 2026-04-29 08:47:32 Functions: 100.0 % 9 9
Branches: 83.8 % 68 57
MC/DC: 79.4 % 68 54

             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                 :              :           2 : 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 ]:           2 :         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                 :              :           2 : 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 ]:           2 :         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                 :              :           2 : 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 ]:           2 :         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                 :              :           2 : 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 ]:           2 :         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                 :              :           5 : bool msg_is_analog_sensor(const can_msg_t *msg) {
      81         [ +  + ]:      [ T  F ]:           5 :         w_assert(msg);
      82                 :              :             : 
      83                 :              :           4 :         uint16_t type = get_message_type(msg);
      84   [ +  +  +  +  :[ T  f  T  f  :           4 :         if (type == MSG_SENSOR_ANALOG16 || type == MSG_SENSOR_ANALOG32 ||
                   +  + ]   T  f  T  f ]
      85         [ +  - ]:              :           1 :                 type == MSG_SENSOR_3D_ANALOG16 || type == MSG_SENSOR_2D_ANALOG24) {
      86                 :              :           4 :                 return true;
      87                 :              :             :         } else {
      88                 :              :           0 :                 return false;
      89                 :              :             :         }
      90                 :              :             : }
      91                 :              :             : 
      92                 :              :           5 : w_status_t 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 ]:           5 :         w_assert(msg);
      95         [ +  + ]:      [ T  F ]:           3 :         w_assert(sensor_id);
      96         [ +  + ]:      [ T  F ]:           2 :         w_assert(output_data);
      97                 :              :             : 
      98                 :              :           1 :         *sensor_id = (can_analog_sensor_id_t)get_message_metadata(msg);
      99                 :              :           1 :         *output_data = ((uint16_t)msg->data[2] << 8) | msg->data[3];
     100                 :              :             : 
     101         [ -  + ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG16) {
     102                 :              :           0 :                 return W_INVALID_PARAM;
     103                 :              :             :         }
     104                 :              :             : 
     105         [ -  + ]:      [ t  F ]:           1 :         if (msg->data_len != 4) {
     106                 :              :           0 :                 return W_DATA_FORMAT_ERROR;
     107                 :              :             :         }
     108                 :              :             : 
     109                 :              :           1 :         return W_SUCCESS;
     110                 :              :             : }
     111                 :              :             : 
     112                 :              :           5 : w_status_t get_analog_sensor_data_32bit(const can_msg_t *msg, can_analog_sensor_id_t *sensor_id,
     113                 :              :             :                                                                                 uint32_t *output_data) {
     114         [ +  + ]:      [ T  F ]:           5 :         w_assert(msg);
     115         [ +  + ]:      [ T  F ]:           3 :         w_assert(sensor_id);
     116         [ +  + ]:      [ T  F ]:           2 :         w_assert(output_data);
     117                 :              :             : 
     118                 :              :           1 :         *sensor_id = (can_analog_sensor_id_t)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         [ -  + ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_ANALOG32) {
     123                 :              :           0 :                 return W_INVALID_PARAM;
     124                 :              :             :         }
     125                 :              :             : 
     126         [ -  + ]:      [ t  F ]:           1 :         if (msg->data_len != 6) {
     127                 :              :           0 :                 return W_DATA_FORMAT_ERROR;
     128                 :              :             :         }
     129                 :              :             : 
     130                 :              :           1 :         return W_SUCCESS;
     131                 :              :             : }
     132                 :              :             : 
     133                 :              :           7 : w_status_t get_3d_analog_sensor_data_16bit(const can_msg_t *msg, can_dem_3d_sensor_id_t *sensor_id,
     134                 :              :             :                                                                                    uint16_t *output_data_x, uint16_t *output_data_y,
     135                 :              :             :                                                                                    uint16_t *output_data_z) {
     136         [ +  + ]:      [ T  F ]:           7 :         w_assert(msg);
     137         [ +  + ]:      [ T  F ]:           5 :         w_assert(sensor_id);
     138         [ +  + ]:      [ T  F ]:           4 :         w_assert(output_data_x);
     139         [ +  + ]:      [ T  F ]:           3 :         w_assert(output_data_y);
     140         [ +  + ]:      [ T  F ]:           2 :         w_assert(output_data_z);
     141                 :              :             : 
     142                 :              :           1 :         *sensor_id = (can_dem_3d_sensor_id_t)get_message_metadata(msg);
     143                 :              :           1 :         *output_data_x = ((uint16_t)msg->data[2] << 8) | msg->data[3];
     144                 :              :           1 :         *output_data_y = ((uint16_t)msg->data[4] << 8) | msg->data[5];
     145                 :              :           1 :         *output_data_z = ((uint16_t)msg->data[6] << 8) | msg->data[7];
     146                 :              :             : 
     147         [ -  + ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_3D_ANALOG16) {
     148                 :              :           0 :                 return W_INVALID_PARAM;
     149                 :              :             :         }
     150                 :              :             : 
     151         [ -  + ]:      [ t  F ]:           1 :         if (msg->data_len != 8) {
     152                 :              :           0 :                 return W_DATA_FORMAT_ERROR;
     153                 :              :             :         }
     154                 :              :             : 
     155                 :              :           1 :         return W_SUCCESS;
     156                 :              :             : }
     157                 :              :             : 
     158                 :              :           6 : w_status_t get_2d_analog_sensor_data_24bit(const can_msg_t *msg, can_dem_2d_sensor_id_t *sensor_id,
     159                 :              :             :                                                                                    uint32_t *sensor_data_x, uint32_t *sensor_data_y) {
     160         [ +  + ]:      [ T  F ]:           6 :         w_assert(msg);
     161         [ +  + ]:      [ T  F ]:           4 :         w_assert(sensor_id);
     162         [ +  + ]:      [ T  F ]:           3 :         w_assert(sensor_data_x);
     163         [ +  + ]:      [ T  F ]:           2 :         w_assert(sensor_data_y);
     164                 :              :             : 
     165                 :              :           1 :         *sensor_id = (can_dem_2d_sensor_id_t)get_message_metadata(msg);
     166                 :              :           1 :         *sensor_data_x = ((uint32_t)msg->data[2] << 16) | ((uint32_t)msg->data[3] << 8) | msg->data[4];
     167                 :              :           1 :         *sensor_data_y = ((uint32_t)msg->data[5] << 16) | ((uint32_t)msg->data[6] << 8) | msg->data[7];
     168                 :              :             : 
     169         [ -  + ]:      [ t  F ]:           1 :         if (get_message_type(msg) != MSG_SENSOR_2D_ANALOG24) {
     170                 :              :           0 :                 return W_INVALID_PARAM;
     171                 :              :             :         }
     172                 :              :             : 
     173         [ -  + ]:      [ t  F ]:           1 :         if (msg->data_len != 8) {
     174                 :              :           0 :                 return W_DATA_FORMAT_ERROR;
     175                 :              :             :         }
     176                 :              :             : 
     177                 :              :           1 :         return W_SUCCESS;
     178                 :              :             : }
        

Generated by: LCOV version 2.0-1