Tests during development

During the development, test check is performed to validate raw NMEA input data vs expected result.

Test code for development
 1/*
 2 * This example uses direct processing function,
 3 * to process dummy NMEA data from GPS receiver
 4 */
 5#include <stdio.h>
 6#include <string.h>
 7#include "lwgps/lwgps.h"
 8#include "test_common.h"
 9
10/* GPS handle */
11lwgps_t hgps;
12
13/**
14 * \brief           Dummy data from GPS receiver
15 */
16const char gps_rx_data[] = ""
17                           "$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
18                           "$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n"
19                           "$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n"
20                           "$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n"
21                           "$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n"
22                           "";
23
24/**
25 * \brief           Run the test of raw input data
26 */
27void
28run_tests() {
29    lwgps_init(&hgps); /* Init GPS */
30
31    /* Process all input data */
32    lwgps_process(&hgps, gps_rx_data, strlen(gps_rx_data));
33
34    /* Run the test */
35    RUN_TEST(!INT_IS_EQUAL(hgps.is_valid, 0));
36    RUN_TEST(INT_IS_EQUAL(hgps.fix, 1));
37    RUN_TEST(INT_IS_EQUAL(hgps.fix_mode, 3));
38    RUN_TEST(FLT_IS_EQUAL(hgps.latitude, 39.1226000000));
39    RUN_TEST(FLT_IS_EQUAL(hgps.longitude, -121.0413666666));
40    RUN_TEST(FLT_IS_EQUAL(hgps.altitude, 646.4000000000));
41    RUN_TEST(FLT_IS_EQUAL(hgps.course, 360.0000000000));
42    RUN_TEST(INT_IS_EQUAL(hgps.dop_p, 1.6000000000));
43    RUN_TEST(INT_IS_EQUAL(hgps.dop_h, 1.6000000000));
44    RUN_TEST(INT_IS_EQUAL(hgps.dop_v, 1.0000000000));
45    RUN_TEST(FLT_IS_EQUAL(hgps.speed, 0.0000000000));
46    RUN_TEST(FLT_IS_EQUAL(hgps.geo_sep, -24.100000000));
47    RUN_TEST(FLT_IS_EQUAL(hgps.variation, 15.500000000));
48    RUN_TEST(INT_IS_EQUAL(hgps.sats_in_view, 8));
49
50    RUN_TEST(INT_IS_EQUAL(hgps.sats_in_use, 5));
51    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[0], 2));
52    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[1], 0));
53    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[2], 0));
54    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[3], 7));
55    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[4], 0));
56    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[5], 9));
57    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[6], 24));
58    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[7], 26));
59    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[8], 0));
60    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[9], 0));
61    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[10], 0));
62    RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[11], 0));
63
64    RUN_TEST(INT_IS_EQUAL(hgps.date, 8));
65    RUN_TEST(INT_IS_EQUAL(hgps.month, 3));
66    RUN_TEST(INT_IS_EQUAL(hgps.year, 1));
67    RUN_TEST(INT_IS_EQUAL(hgps.hours, 18));
68    RUN_TEST(INT_IS_EQUAL(hgps.minutes, 37));
69    RUN_TEST(INT_IS_EQUAL(hgps.seconds, 30));
70}