LCOV - code coverage report
Current view: top level - message - msg_general.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 95 0
Test Date: 2026-02-15 13:08:52 Functions: 0.0 % 11 0
Branches: 0.0 % 30 0

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

Generated by: LCOV version 2.0-1