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_actuator.h"
9 : : : #include "msg_common.h"
10 : : :
11 : : 1 : void build_actuator_cmd_msg(can_msg_prio_t prio, uint16_t timestamp, can_actuator_id_t actuator_id,
12 : : : can_actuator_state_t actuator_cmd, can_msg_t *output) {
13 [ + - ]: [ T f ]: 1 : w_assert(output);
14 : : :
15 : : 1 : output->sid = build_sid(prio, MSG_ACTUATOR_CMD, actuator_id);
16 : : 1 : write_timestamp(timestamp, output);
17 : : :
18 : : 1 : output->data[2] = (uint8_t)actuator_cmd;
19 : : 1 : output->data_len = 3;
20 : : 1 : }
21 : : :
22 : : 1 : void build_actuator_status_msg(can_msg_prio_t prio, uint16_t timestamp,
23 : : : can_actuator_id_t actuator_id,
24 : : : can_actuator_state_t actuator_cmd_state,
25 : : : can_actuator_state_t actuator_curr_state, can_msg_t *output) {
26 [ + - ]: [ T f ]: 1 : w_assert(output);
27 : : :
28 : : 1 : output->sid = build_sid(prio, MSG_ACTUATOR_STATUS, actuator_id);
29 : : 1 : write_timestamp(timestamp, output);
30 : : :
31 : : 1 : output->data[2] = (uint8_t)actuator_cmd_state;
32 : : 1 : output->data[3] = (uint8_t)actuator_curr_state;
33 : : 1 : output->data_len = 4;
34 : : 1 : }
35 : : :
36 : : 0 : int get_actuator_id(const can_msg_t *msg) {
37 [ # # ]: [ t f ]: 0 : w_assert(msg);
38 : : :
39 : : 0 : uint16_t msg_type = get_message_type(msg);
40 [ # # ]: [ t f ]: 0 : if (msg_type == MSG_ACTUATOR_STATUS) {
41 : : 0 : return get_message_metadata(msg);
42 : : : }
43 : : :
44 : : : // not a valid field for this message type
45 : : : return -1;
46 : : : }
47 : : :
48 : : 1 : int get_curr_actuator_state(const can_msg_t *msg) {
49 [ + - ]: [ T f ]: 1 : w_assert(msg);
50 : : :
51 : : 1 : uint16_t msg_type = get_message_type(msg);
52 [ + - ]: [ T f ]: 1 : if (msg_type == MSG_ACTUATOR_STATUS) {
53 : : 1 : return msg->data[3];
54 : : : }
55 : : :
56 : : : // not a valid field for this message type
57 : : : return -1;
58 : : : }
59 : : :
60 : : 2 : int get_cmd_actuator_state(const can_msg_t *msg) {
61 [ + - ]: [ T f ]: 2 : w_assert(msg);
62 : : :
63 : : 2 : uint16_t msg_type = get_message_type(msg);
64 : : :
65 [ + - ]: [ T f ]: 2 : if ((msg_type == MSG_ACTUATOR_CMD) || (msg_type == MSG_ACTUATOR_STATUS)) {
66 : : 2 : return msg->data[2];
67 : : : }
68 : : :
69 : : : // not a valid field for this message type
70 : : : return -1;
71 : : : }
|