1 /*
2 * Copyright 2023 Google LLC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/gnss.h>
8 #include <zephyr/drivers/gnss/gnss_publish.h>
9 #include <zephyr/device.h>
10
11 DEVICE_DEFINE(gnss_dev, "gnss_dev", NULL, NULL, NULL, NULL,
12 POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, NULL);
13
14 static const struct device *gnss_dev = &DEVICE_NAME_GET(gnss_dev);
15 static struct gnss_data test_data;
16 static struct gnss_satellite test_satellite;
17
test_gnss_data(void)18 static void test_gnss_data(void)
19 {
20 gnss_publish_data(gnss_dev, &test_data);
21
22 /* positive values */
23 test_data.nav_data.latitude = 10000000001;
24 test_data.nav_data.longitude = 20000000002;
25 test_data.nav_data.bearing = 3003;
26 test_data.nav_data.speed = 4004;
27 test_data.nav_data.altitude = 5005;
28
29 test_data.info.satellites_cnt = 6;
30 test_data.info.hdop = 7;
31 test_data.info.fix_status = GNSS_FIX_STATUS_GNSS_FIX;
32 test_data.info.fix_quality = GNSS_FIX_QUALITY_GNSS_PPS;
33
34 test_data.utc.hour = 1;
35 test_data.utc.minute = 2;
36 test_data.utc.millisecond = 3;
37 test_data.utc.month_day = 4;
38 test_data.utc.month = 5;
39 test_data.utc.century_year = 6;
40
41 gnss_publish_data(gnss_dev, &test_data);
42
43 /* small positive values */
44 test_data.nav_data.latitude = 1;
45 test_data.nav_data.longitude = 2;
46 test_data.nav_data.bearing = 3;
47 test_data.nav_data.speed = 4;
48 test_data.nav_data.altitude = 5;
49
50 gnss_publish_data(gnss_dev, &test_data);
51
52 /* negative values */
53 test_data.nav_data.latitude = -10000000001;
54 test_data.nav_data.longitude = -20000000002;
55 test_data.nav_data.altitude = -5005;
56
57 gnss_publish_data(gnss_dev, &test_data);
58
59 /* small negative values */
60 test_data.nav_data.latitude = -1;
61 test_data.nav_data.longitude = -2;
62 test_data.nav_data.altitude = -5;
63
64 gnss_publish_data(gnss_dev, &test_data);
65 }
66
test_satellites_data(void)67 static void test_satellites_data(void)
68 {
69 gnss_publish_satellites(gnss_dev, &test_satellite, 1);
70
71 test_satellite.prn = 1;
72 test_satellite.snr = 2;
73 test_satellite.azimuth = 3;
74 test_satellite.system = GNSS_SYSTEM_GALILEO;
75 test_satellite.is_tracked = 1;
76
77 gnss_publish_satellites(gnss_dev, &test_satellite, 1);
78 }
main(void)79 int main(void)
80 {
81 test_gnss_data();
82 test_satellites_data();
83
84 return 0;
85 }
86