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 : : 2 : 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 ]: 2 : 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 : : 1 : 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 ]: 1 : 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 : : 3 : 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 ]: 3 : w_assert(data);
39 [ - + ]: [ t F ]: 1 : 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 : : 1 : 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 [ - + ]: [ t F ]: 1 : 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 [ # # ]: [ t f ]: 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 : : 4 : w_status_t get_general_board_status(const can_msg_t *msg, uint32_t *board_error_bitfield) {
80 [ + + ]: [ T F ]: 4 : w_assert(msg);
81 [ + + ]: [ T F ]: 2 : w_assert(board_error_bitfield);
82 : : :
83 : : 1 : *board_error_bitfield =
84 : : 1 : (msg->data[2] << 24) | (msg->data[3] << 16) | (msg->data[4] << 8) | (msg->data[5]);
85 : : :
86 [ - + ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GENERAL_BOARD_STATUS) {
87 : : 0 : return W_INVALID_PARAM;
88 : : : }
89 : : :
90 [ - + ]: [ t F ]: 1 : if (msg->data_len != 6) {
91 : : 0 : return W_DATA_FORMAT_ERROR;
92 : : : }
93 : : :
94 : : 1 : return W_SUCCESS;
95 : : : }
96 : : :
97 : : 4 : w_status_t get_reset_board_id(const can_msg_t *msg, uint8_t *board_type_id,
98 : : : uint8_t *board_inst_id) {
99 [ + + ]: [ T F ]: 4 : w_assert(msg);
100 [ + + ]: [ T F ]: 2 : w_assert(board_type_id);
101 [ - + ]: [ t F ]: 1 : w_assert(board_inst_id);
102 : : :
103 : : 0 : *board_type_id = msg->data[2];
104 : : 0 : *board_inst_id = msg->data[3];
105 : : :
106 [ # # ]: [ t f ]: 0 : if (get_message_type(msg) != MSG_RESET_CMD) {
107 : : 0 : return W_INVALID_PARAM;
108 : : : }
109 : : :
110 [ # # ]: [ t f ]: 0 : if (msg->data_len != 4) {
111 : : 0 : return W_DATA_FORMAT_ERROR;
112 : : : }
113 : : :
114 : : 0 : return W_SUCCESS;
115 : : : }
116 : : :
117 : : 1 : w_status_t check_board_need_reset(const can_msg_t *msg, bool *board_need_reset) {
118 [ - + ]: [ t F ]: 1 : w_assert(msg);
119 [ # # ]: [ t f ]: 0 : w_assert(board_need_reset);
120 : : :
121 : : : uint8_t board_type_id, board_inst_id;
122 : : :
123 : : 0 : *board_need_reset = false;
124 : : :
125 : : 0 : w_status_t status = W_SUCCESS;
126 : : 0 : status = get_reset_board_id(msg, &board_type_id, &board_inst_id);
127 [ # # ]: [ t f ]: 0 : if (status != W_SUCCESS) {
128 : : 0 : return status;
129 : : : }
130 : : :
131 : : : #ifndef CANLIB_DYNAMIC_BOARD_ID
132 : : 0 : const uint8_t board_type_unique_id = BOARD_TYPE_UNIQUE_ID;
133 : : 0 : const uint8_t board_inst_unique_id = BOARD_INST_UNIQUE_ID;
134 : : : #endif
135 : : :
136 [ # # ]: [ t f ]: 0 : if (board_type_id == BOARD_TYPE_ID_ANY) {
137 : : 0 : *board_need_reset = true;
138 [ # # ]: [ t f ]: 0 : } else if (board_type_id == board_type_unique_id) {
139 [ # # ]: [ t f ]: 0 : if (board_inst_id == BOARD_INST_ID_ANY) {
140 : : 0 : *board_need_reset = true;
141 [ # # ]: [ t f ]: 0 : } else if (board_inst_id == board_inst_unique_id) {
142 : : 0 : *board_need_reset = true;
143 : : : }
144 : : : }
145 : : :
146 : : 0 : return W_SUCCESS;
147 : : : }
148 : : :
149 : : 3 : w_status_t get_debug_raw_data(const can_msg_t *msg, uint8_t *data) {
150 [ + + ]: [ T F ]: 3 : w_assert(msg);
151 [ - + ]: [ t F ]: 1 : w_assert(data);
152 : : :
153 : : 0 : memcpy(data, msg->data + 2, 6);
154 : : :
155 [ # # ]: [ t f ]: 0 : if (get_message_type(msg) != MSG_DEBUG_RAW) {
156 : : 0 : return W_INVALID_PARAM;
157 : : : }
158 : : :
159 [ # # ]: [ t f ]: 0 : if (msg->data_len != 8) {
160 : : 0 : return W_DATA_FORMAT_ERROR;
161 : : : }
162 : : :
163 : : 0 : return W_SUCCESS;
164 : : : }
165 : : :
166 : : 4 : w_status_t get_config_set_target_board(const can_msg_t *msg, uint8_t *board_type_id,
167 : : : uint8_t *board_inst_id) {
168 [ + + ]: [ T F ]: 4 : w_assert(msg);
169 [ + + ]: [ T F ]: 2 : w_assert(board_type_id);
170 [ - + ]: [ t F ]: 1 : w_assert(board_inst_id);
171 : : :
172 : : 0 : *board_type_id = msg->data[2];
173 : : 0 : *board_inst_id = msg->data[3];
174 : : :
175 [ # # ]: [ t f ]: 0 : if (get_message_type(msg) != MSG_CONFIG_SET) {
176 : : 0 : return W_INVALID_PARAM;
177 : : : }
178 : : :
179 [ # # ]: [ t f ]: 0 : if (msg->data_len != 8) {
180 : : 0 : return W_DATA_FORMAT_ERROR;
181 : : : }
182 : : :
183 : : 0 : return W_SUCCESS;
184 : : : }
185 : : :
186 : : 4 : w_status_t get_config_id_value(const can_msg_t *msg, uint16_t *config_id, uint16_t *config_value) {
187 [ + + ]: [ T F ]: 4 : w_assert(msg);
188 [ + + ]: [ T F ]: 2 : w_assert(config_id);
189 [ - + ]: [ t F ]: 1 : w_assert(config_value);
190 : : :
191 : : 0 : can_msg_type_t msg_type = get_message_type(msg);
192 [ # # ]: [ t f ]: 0 : if (msg_type == MSG_CONFIG_SET) {
193 : : 0 : *config_id = (msg->data[4] << 8) | (msg->data[5]);
194 : : 0 : *config_value = (msg->data[6] << 8) | (msg->data[7]);
195 : : :
196 [ # # ]: [ t f ]: 0 : if (msg->data_len == 8) {
197 : : 0 : return W_SUCCESS;
198 : : : } else {
199 : : 0 : return W_INVALID_PARAM;
200 : : : }
201 [ # # ]: [ t f ]: 0 : } else if (msg_type == MSG_CONFIG_STATUS) {
202 : : 0 : *config_id = (msg->data[2] << 8) | (msg->data[3]);
203 : : 0 : *config_value = (msg->data[4] << 8) | (msg->data[5]);
204 : : :
205 [ # # ]: [ t f ]: 0 : if (msg->data_len == 6) {
206 : : 0 : return W_SUCCESS;
207 : : : } else {
208 : : 0 : return W_INVALID_PARAM;
209 : : : }
210 : : : }
211 : : :
212 : : 0 : return W_INVALID_PARAM;
213 : : : }
|