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_gps.h"
10 : : :
11 : : 1 : bool build_gps_time_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t utc_hours,
12 : : : uint8_t utc_mins, uint8_t utc_secs, uint8_t utc_dsecs, can_msg_t *output) {
13 [ + - ]: [ T f ]: 1 : w_assert(output);
14 : : :
15 : : 1 : output->sid = build_sid(prio, MSG_GPS_TIMESTAMP, 0);
16 : : 1 : write_timestamp(timestamp, output);
17 : : :
18 : : 1 : output->data[2] = utc_hours;
19 : : 1 : output->data[3] = utc_mins;
20 : : 1 : output->data[4] = utc_secs;
21 : : 1 : output->data[5] = utc_dsecs;
22 : : :
23 : : 1 : output->data_len = 6;
24 : : :
25 : : 1 : return true;
26 : : : }
27 : : :
28 : : 1 : bool build_gps_lat_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t degrees, uint8_t minutes,
29 : : : uint16_t dminutes, uint8_t direction, can_msg_t *output) {
30 [ + - ]: [ T f ]: 1 : w_assert(output);
31 : : :
32 : : 1 : output->sid = build_sid(prio, MSG_GPS_LATITUDE, 0);
33 : : 1 : write_timestamp(timestamp, output);
34 : : :
35 : : 1 : output->data[2] = degrees;
36 : : 1 : output->data[3] = minutes;
37 : : 1 : output->data[4] = dminutes >> 8;
38 : : 1 : output->data[5] = dminutes & 0xFF;
39 : : 1 : output->data[6] = direction;
40 : : :
41 : : 1 : output->data_len = 7;
42 : : :
43 : : 1 : return true;
44 : : : }
45 : : :
46 : : 1 : bool build_gps_lon_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t degrees, uint8_t minutes,
47 : : : uint16_t dminutes, uint8_t direction, can_msg_t *output) {
48 [ + - ]: [ T f ]: 1 : w_assert(output);
49 : : :
50 : : 1 : output->sid = build_sid(prio, MSG_GPS_LONGITUDE, 0);
51 : : 1 : write_timestamp(timestamp, output);
52 : : :
53 : : 1 : output->data[2] = degrees;
54 : : 1 : output->data[3] = minutes;
55 : : 1 : output->data[4] = dminutes >> 8;
56 : : 1 : output->data[5] = dminutes & 0xFF;
57 : : 1 : output->data[6] = direction;
58 : : :
59 : : 1 : output->data_len = 7;
60 : : :
61 : : 1 : return true;
62 : : : }
63 : : :
64 : : 1 : bool build_gps_alt_msg(can_msg_prio_t prio, uint16_t timestamp, uint16_t altitude,
65 : : : uint8_t daltitude, uint8_t units, can_msg_t *output) {
66 [ + - ]: [ T f ]: 1 : w_assert(output);
67 : : :
68 : : 1 : output->sid = build_sid(prio, MSG_GPS_ALTITUDE, 0);
69 : : 1 : write_timestamp(timestamp, output);
70 : : :
71 : : 1 : output->data[2] = (altitude >> 8) & 0xff;
72 : : 1 : output->data[3] = (altitude >> 0) & 0xff;
73 : : 1 : output->data[4] = daltitude;
74 : : 1 : output->data[5] = units;
75 : : :
76 : : 1 : output->data_len = 6;
77 : : :
78 : : 1 : return true;
79 : : : }
80 : : :
81 : : 1 : bool build_gps_info_msg(can_msg_prio_t prio, uint16_t timestamp, uint8_t num_sat, uint8_t quality,
82 : : : can_msg_t *output) {
83 [ + - ]: [ T f ]: 1 : w_assert(output);
84 : : :
85 : : 1 : output->sid = build_sid(prio, MSG_GPS_INFO, 0);
86 : : 1 : write_timestamp(timestamp, output);
87 : : :
88 : : 1 : output->data[2] = num_sat;
89 : : 1 : output->data[3] = quality;
90 : : :
91 : : 1 : output->data_len = 4;
92 : : :
93 : : 1 : return true;
94 : : : }
95 : : :
96 : : 1 : bool get_gps_time(const can_msg_t *msg, uint8_t *utc_hours, uint8_t *utc_mins, uint8_t *utc_secs,
97 : : : uint8_t *utc_dsecs) {
98 [ + - ]: [ T f ]: 1 : w_assert(msg);
99 [ + - ]: [ T f ]: 1 : w_assert(utc_hours);
100 [ + - ]: [ T f ]: 1 : w_assert(utc_mins);
101 [ + - ]: [ T f ]: 1 : w_assert(utc_secs);
102 [ + - ]: [ T f ]: 1 : w_assert(utc_dsecs);
103 : : :
104 [ + - ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GPS_TIMESTAMP) {
105 : : : return false;
106 : : : }
107 : : :
108 : : 1 : *utc_hours = msg->data[2];
109 : : 1 : *utc_mins = msg->data[3];
110 : : 1 : *utc_secs = msg->data[4];
111 : : 1 : *utc_dsecs = msg->data[5];
112 : : :
113 : : 1 : return true;
114 : : : }
115 : : :
116 : : 1 : bool get_gps_lat(const can_msg_t *msg, uint8_t *degrees, uint8_t *minutes, uint16_t *dminutes,
117 : : : uint8_t *direction) {
118 [ + - ]: [ T f ]: 1 : w_assert(msg);
119 [ + - ]: [ T f ]: 1 : w_assert(degrees);
120 [ + - ]: [ T f ]: 1 : w_assert(minutes);
121 [ + - ]: [ T f ]: 1 : w_assert(dminutes);
122 [ + - ]: [ T f ]: 1 : w_assert(direction);
123 : : :
124 [ + - ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GPS_LATITUDE) {
125 : : : return false;
126 : : : }
127 : : :
128 : : 1 : *degrees = msg->data[2];
129 : : 1 : *minutes = msg->data[3];
130 : : 1 : *dminutes = ((uint16_t)msg->data[4] << 8) | msg->data[5];
131 : : 1 : *direction = msg->data[6];
132 : : :
133 : : 1 : return true;
134 : : : }
135 : : :
136 : : 1 : bool get_gps_lon(const can_msg_t *msg, uint8_t *degrees, uint8_t *minutes, uint16_t *dminutes,
137 : : : uint8_t *direction) {
138 [ + - ]: [ T f ]: 1 : w_assert(msg);
139 [ + - ]: [ T f ]: 1 : w_assert(degrees);
140 [ + - ]: [ T f ]: 1 : w_assert(minutes);
141 [ + - ]: [ T f ]: 1 : w_assert(dminutes);
142 [ + - ]: [ T f ]: 1 : w_assert(direction);
143 : : :
144 [ + - ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GPS_LONGITUDE) {
145 : : : return false;
146 : : : }
147 : : :
148 : : 1 : *degrees = msg->data[2];
149 : : 1 : *minutes = msg->data[3];
150 : : 1 : *dminutes = ((uint16_t)msg->data[4] << 8) | msg->data[5];
151 : : 1 : *direction = msg->data[6];
152 : : :
153 : : 1 : return true;
154 : : : }
155 : : :
156 : : 1 : bool get_gps_alt(const can_msg_t *msg, uint16_t *altitude, uint8_t *daltitude, uint8_t *units) {
157 [ + - ]: [ T f ]: 1 : w_assert(msg);
158 [ + - ]: [ T f ]: 1 : w_assert(altitude);
159 [ + - ]: [ T f ]: 1 : w_assert(daltitude);
160 [ + - ]: [ T f ]: 1 : w_assert(units);
161 : : :
162 [ + - ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GPS_ALTITUDE) {
163 : : : return false;
164 : : : }
165 : : :
166 : : 1 : *altitude = ((uint16_t)msg->data[2] << 8) | msg->data[3];
167 : : 1 : *daltitude = msg->data[4];
168 : : 1 : *units = msg->data[5];
169 : : :
170 : : 1 : return true;
171 : : : }
172 : : :
173 : : 1 : bool get_gps_info(const can_msg_t *msg, uint8_t *num_sat, uint8_t *quality) {
174 [ + - ]: [ T f ]: 1 : w_assert(msg);
175 [ + - ]: [ T f ]: 1 : w_assert(num_sat);
176 [ + - ]: [ T f ]: 1 : w_assert(quality);
177 : : :
178 [ + - ]: [ t F ]: 1 : if (get_message_type(msg) != MSG_GPS_INFO) {
179 : : : return false;
180 : : : }
181 : : :
182 : : 1 : *num_sat = msg->data[2];
183 : : 1 : *quality = msg->data[3];
184 : : :
185 : : 1 : return true;
186 : : : }
|