LCOV - code coverage report
Current view: top level - message/msg_general.c (source / functions) Coverage Total Hit
Test: coverage-filtered.info Lines: 18.4 % 98 18
Test Date: 2026-03-20 08:45:03 Functions: 18.2 % 11 2
Branches: 7.4 % 54 4
MC/DC: 7.4 % 54 4

             Branch data      MC/DC data    Line data    Source code
       1                 :              :             : #include <stdbool.h>
       2                 :              :             : #include <stdint.h>
       3                 :              :             : #include <string.h>
       4                 :              :             : 
       5                 :              :             : #include "common.h"
       6                 :              :             : 
       7                 :              :             : #include "can.h"
       8                 :              :             : #include "message_types.h"
       9                 :              :             : #include "msg_common.h"
      10                 :              :             : #include "msg_general.h"
      11                 :              :             : 
      12                 :              :           1 : void build_general_board_status_msg(can_msg_prio_t prio, uint16_t timestamp,
      13                 :              :             :                                                                         uint32_t board_error_bitfield, can_msg_t *output) {
      14         [ +  - ]:      [ T  f ]:           1 :         w_assert(output);
      15                 :              :             : 
      16                 :              :           1 :         output->sid = build_sid(prio, MSG_GENERAL_BOARD_STATUS, 0);
      17                 :              :           1 :         write_timestamp(timestamp, output);
      18                 :              :           1 :         output->data[2] = (board_error_bitfield >> 24) & 0xff;
      19                 :              :           1 :         output->data[3] = (board_error_bitfield >> 16) & 0xff;
      20                 :              :           1 :         output->data[4] = (board_error_bitfield >> 8) & 0xff;
      21                 :              :           1 :         output->data[5] = board_error_bitfield & 0xff;
      22                 :              :           1 :         output->data_len = 6;
      23                 :              :           1 : }
      24                 :              :             : 
      25                 :              :           0 : void build_reset_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t board_type_id,
      26                 :              :             :                                          uint8_t board_inst_id, can_msg_t *output) {
      27         [ #  # ]:      [ t  f ]:           0 :         w_assert(output);
      28                 :              :             : 
      29                 :              :           0 :         output->sid = build_sid(prio, MSG_RESET_CMD, 0);
      30                 :              :           0 :         write_timestamp(timestamp, output);
      31                 :              :           0 :         output->data[2] = board_type_id;
      32                 :              :           0 :         output->data[3] = board_inst_id;
      33                 :              :           0 :         output->data_len = 4;
      34                 :              :           0 : }
      35                 :              :             : 
      36                 :              :           0 : void build_debug_raw_msg(can_msg_prio_t prio, uint16_t timestamp, const uint8_t *data,
      37                 :              :             :                                                  can_msg_t *output) {
      38         [ #  # ]:      [ t  f ]:           0 :         w_assert(output);
      39                 :              :             : 
      40                 :              :           0 :         output->sid = build_sid(prio, MSG_DEBUG_RAW, 0);
      41                 :              :           0 :         write_timestamp(timestamp, output);
      42                 :              :             : 
      43                 :              :           0 :         memcpy(output->data + 2, data, 6);
      44                 :              :           0 :         output->data_len = 8;
      45                 :              :           0 : }
      46                 :              :             : 
      47                 :              :           0 : void build_config_set_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t board_type_id,
      48                 :              :             :                                                   uint8_t board_inst_id, uint16_t config_id, uint16_t config_value,
      49                 :              :             :                                                   can_msg_t *output) {
      50         [ #  # ]:      [ t  f ]:           0 :         w_assert(output);
      51                 :              :             : 
      52                 :              :           0 :         output->sid = build_sid(prio, MSG_CONFIG_SET, 0);
      53                 :              :           0 :         write_timestamp(timestamp, output);
      54                 :              :             : 
      55                 :              :           0 :         output->data[2] = board_type_id;
      56                 :              :           0 :         output->data[3] = board_inst_id;
      57                 :              :           0 :         output->data[4] = (config_id >> 8) & 0xff;
      58                 :              :           0 :         output->data[5] = config_id & 0xff;
      59                 :              :           0 :         output->data[6] = (config_value >> 8) & 0xff;
      60                 :              :           0 :         output->data[7] = config_value & 0xff;
      61                 :              :           0 :         output->data_len = 8;
      62                 :              :           0 : }
      63                 :              :             : 
      64                 :              :           0 : void build_config_status_msg(can_msg_prio_t prio, uint16_t timestamp, uint16_t config_id,
      65                 :              :             :                                                          uint16_t config_value, can_msg_t *output) {
      66         [ #  # ]:      [ t  f ]:           0 :         w_assert(output);
      67                 :              :             : 
      68                 :              :           0 :         output->sid = build_sid(prio, MSG_CONFIG_STATUS, 0);
      69                 :              :           0 :         write_timestamp(timestamp, output);
      70                 :              :             : 
      71                 :              :           0 :         output->data[2] = (config_id >> 8) & 0xff;
      72                 :              :           0 :         output->data[3] = config_id & 0xff;
      73                 :              :           0 :         output->data[4] = (config_value >> 8) & 0xff;
      74                 :              :           0 :         output->data[5] = config_value & 0xff;
      75                 :              :           0 :         output->data_len = 6;
      76                 :              :           0 : }
      77                 :              :             : 
      78                 :              :           1 : bool get_general_board_status(const can_msg_t *msg, uint32_t *board_error_bitfield) {
      79         [ +  - ]:      [ T  f ]:           1 :         w_assert(msg);
      80         [ +  - ]:      [ T  f ]:           1 :         w_assert(board_error_bitfield);
      81                 :              :             : 
      82                 :              :           1 :         uint16_t msg_type = get_message_type(msg);
      83         [ +  - ]:      [ T  f ]:           1 :         if (msg_type == MSG_GENERAL_BOARD_STATUS) {
      84                 :              :           1 :                 *board_error_bitfield =
      85                 :              :           1 :                         (msg->data[2] << 24) | (msg->data[3] << 16) | (msg->data[4] << 8) | (msg->data[5]);
      86                 :              :           1 :                 return true;
      87                 :              :             :         } else {
      88                 :              :             :                 return false;
      89                 :              :             :         }
      90                 :              :             : }
      91                 :              :             : 
      92                 :              :           0 : bool get_reset_board_id(const can_msg_t *msg, uint8_t *board_type_id, uint8_t *board_inst_id) {
      93         [ #  # ]:      [ t  f ]:           0 :         w_assert(msg);
      94         [ #  # ]:      [ t  f ]:           0 :         w_assert(board_type_id);
      95         [ #  # ]:      [ t  f ]:           0 :         w_assert(board_inst_id);
      96                 :              :             : 
      97                 :              :           0 :         uint16_t msg_type = get_message_type(msg);
      98         [ #  # ]:      [ t  f ]:           0 :         if (msg_type == MSG_RESET_CMD) {
      99                 :              :           0 :                 *board_type_id = msg->data[2];
     100                 :              :           0 :                 *board_inst_id = msg->data[3];
     101                 :              :           0 :                 return true;
     102                 :              :             :         } else {
     103                 :              :             :                 // not a valid field for this message type
     104                 :              :             :                 return false;
     105                 :              :             :         }
     106                 :              :             : }
     107                 :              :             : 
     108                 :              :           0 : bool check_board_need_reset(const can_msg_t *msg) {
     109         [ #  # ]:      [ t  f ]:           0 :         w_assert(msg);
     110                 :              :             : 
     111                 :              :             :         uint8_t board_type_id, board_inst_id;
     112                 :              :             : 
     113         [ #  # ]:      [ t  f ]:           0 :         if (!get_reset_board_id(msg, &board_type_id, &board_inst_id)) {
     114                 :              :             :                 return false;
     115                 :              :             :         }
     116                 :              :             : 
     117                 :              :             : #ifndef CANLIB_DYNAMIC_BOARD_ID
     118                 :              :             :         const uint8_t board_type_unique_id = BOARD_TYPE_UNIQUE_ID;
     119                 :              :             :         const uint8_t board_inst_unique_id = BOARD_INST_UNIQUE_ID;
     120                 :              :             : #endif
     121                 :              :             : 
     122         [ #  # ]:      [ t  f ]:           0 :         if (board_type_id == BOARD_TYPE_ID_ANY) {
     123                 :              :             :                 return true;
     124                 :              :             :         } else if (board_type_id == board_type_unique_id) {
     125                 :              :             :                 if (board_inst_id == BOARD_INST_ID_ANY) {
     126                 :              :             :                         return true;
     127                 :              :             :                 } else if (board_inst_id == board_inst_unique_id) {
     128                 :              :             :                         return true;
     129                 :              :             :                 } else {
     130                 :              :             :                         return false;
     131                 :              :             :                 }
     132                 :              :             :         } else {
     133                 :              :           0 :                 return false;
     134                 :              :             :         }
     135                 :              :             : }
     136                 :              :             : 
     137                 :              :           0 : bool get_debug_raw_data(const can_msg_t *msg, uint8_t *data) {
     138         [ #  # ]:      [ t  f ]:           0 :         w_assert(msg);
     139         [ #  # ]:      [ t  f ]:           0 :         w_assert(data);
     140                 :              :             : 
     141                 :              :           0 :         uint16_t msg_type = get_message_type(msg);
     142         [ #  # ]:      [ t  f ]:           0 :         if (msg_type == MSG_DEBUG_RAW) {
     143                 :              :           0 :                 memcpy(data, msg->data + 2, 6);
     144                 :              :           0 :                 return true;
     145                 :              :             :         } else {
     146                 :              :             :                 return false;
     147                 :              :             :         }
     148                 :              :             : }
     149                 :              :             : 
     150                 :              :           0 : bool get_config_set_target_board(const can_msg_t *msg, uint8_t *board_type_id,
     151                 :              :             :                                                                  uint8_t *board_inst_id) {
     152         [ #  # ]:      [ t  f ]:           0 :         w_assert(msg);
     153         [ #  # ]:      [ t  f ]:           0 :         w_assert(board_type_id);
     154         [ #  # ]:      [ t  f ]:           0 :         w_assert(board_inst_id);
     155                 :              :             : 
     156                 :              :           0 :         uint16_t msg_type = get_message_type(msg);
     157         [ #  # ]:      [ t  f ]:           0 :         if (msg_type == MSG_CONFIG_SET) {
     158                 :              :           0 :                 *board_type_id = msg->data[2];
     159                 :              :           0 :                 *board_inst_id = msg->data[3];
     160                 :              :           0 :                 return true;
     161                 :              :             :         } else {
     162                 :              :             :                 return false;
     163                 :              :             :         }
     164                 :              :             : }
     165                 :              :             : 
     166                 :              :           0 : bool get_config_id_value(const can_msg_t *msg, uint16_t *config_id, uint16_t *config_value) {
     167         [ #  # ]:      [ t  f ]:           0 :         w_assert(msg);
     168         [ #  # ]:      [ t  f ]:           0 :         w_assert(config_id);
     169         [ #  # ]:      [ t  f ]:           0 :         w_assert(config_value);
     170                 :              :             : 
     171                 :              :           0 :         uint16_t msg_type = get_message_type(msg);
     172         [ #  # ]:      [ t  f ]:           0 :         if (msg_type == MSG_CONFIG_SET) {
     173                 :              :           0 :                 *config_id = (msg->data[4] << 8) | (msg->data[5]);
     174                 :              :           0 :                 *config_value = (msg->data[6] << 8) | (msg->data[7]);
     175                 :              :           0 :                 return true;
     176         [ #  # ]:      [ t  f ]:           0 :         } else if (msg_type == MSG_CONFIG_STATUS) {
     177                 :              :           0 :                 *config_id = (msg->data[2] << 8) | (msg->data[3]);
     178                 :              :           0 :                 *config_value = (msg->data[4] << 8) | (msg->data[5]);
     179                 :              :           0 :                 return true;
     180                 :              :             :         } else {
     181                 :              :             :                 return false;
     182                 :              :             :         }
     183                 :              :             : }
        

Generated by: LCOV version 2.0-1