-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,18 @@ | ||
/** | ||
* This example uses direct processing function | ||
* to process dummy NMEA data from GPS receiver | ||
*/ | ||
/* | ||
* This example uses direct processing function, | ||
* to process dummy NMEA data from GPS receiver | ||
*/ | ||
#include "gps/gps.h" | ||
#include "gps/gps_buff.h" | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
#define RUN_TEST(x) if ((x)) { printf("Test passed on line %u with condition " # x "\r\n", (unsigned)__LINE__); } else { printf("Test FAILED on line %u with condition " # x "\r\n", (unsigned)__LINE__ ); } | ||
#define FLT_IS_EQUAL(x, y) (fabs((double)(x) - (double)(y)) < 0.00001) | ||
#define INT_IS_EQUAL(x, y) ((int)((x) == (y))) | ||
|
||
/* GPS handle */ | ||
gps_t hgps; | ||
|
||
/** | ||
* \brief Dummy data from GPS receiver | ||
*/ | ||
const char | ||
gps_rx_data[] = "" | ||
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n" | ||
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n" | ||
"$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n" | ||
"$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n" | ||
"$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n" | ||
""; | ||
/* External function */ | ||
extern void run_tests(); | ||
|
||
int | ||
main() { | ||
gps_init(&hgps); /* Init GPS */ | ||
|
||
/* Process all input data */ | ||
gps_process(&hgps, gps_rx_data, strlen(gps_rx_data)); | ||
|
||
/* Run the test */ | ||
RUN_TEST(!INT_IS_EQUAL(hgps.is_valid, 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.fix, 1)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.fix_mode, 3)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.latitude, 39.1226000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.longitude, -121.0413666666)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.altitude, 646.4000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.coarse, 360.0000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_p, 1.6000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_h, 1.6000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_v, 1.0000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.speed, 0.0000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.geo_sep, -24.100000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.variation, 15.500000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_view, 8)); | ||
|
||
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_use, 5)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[0], 2)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[1], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[2], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[3], 7)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[4], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[5], 9)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[6], 24)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[7], 26)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[8], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[9], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[10], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[11], 0)); | ||
|
||
RUN_TEST(INT_IS_EQUAL(hgps.date, 8)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.month, 3)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.year, 1)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.hours, 18)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.minutes, 37)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.seconds, 30)); | ||
run_tests(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* This example uses direct processing function, | ||
* to process dummy NMEA data from GPS receiver | ||
*/ | ||
#include "gps/gps.h" | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <math.h> | ||
|
||
#define RUN_TEST(x) do { \ | ||
if ((x)) { \ | ||
printf("Test passed on line %u with condition " # x "\r\n", (unsigned)__LINE__);\ | ||
} else { \ | ||
printf("Test FAILED on line %u with condition " # x "\r\n", (unsigned)__LINE__ ); \ | ||
} \ | ||
} while (0) | ||
#define FLT_IS_EQUAL(x, y) (fabs((double)(x) - (double)(y)) < 0.00001) | ||
#define INT_IS_EQUAL(x, y) ((int)((x) == (y))) | ||
|
||
/* GPS handle */ | ||
gps_t hgps; | ||
|
||
/** | ||
* \brief Dummy data from GPS receiver | ||
*/ | ||
const char | ||
gps_rx_data[] = "" | ||
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n" | ||
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n" | ||
"$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n" | ||
"$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n" | ||
"$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n" | ||
""; | ||
|
||
/** | ||
* \brief Run the test of raw input data | ||
*/ | ||
void | ||
run_tests() { | ||
gps_init(&hgps); /* Init GPS */ | ||
|
||
/* Process all input data */ | ||
gps_process(&hgps, gps_rx_data, strlen(gps_rx_data)); | ||
|
||
/* Run the test */ | ||
RUN_TEST(!INT_IS_EQUAL(hgps.is_valid, 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.fix, 1)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.fix_mode, 3)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.latitude, 39.1226000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.longitude, -121.0413666666)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.altitude, 646.4000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.coarse, 360.0000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_p, 1.6000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_h, 1.6000000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.dop_v, 1.0000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.speed, 0.0000000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.geo_sep, -24.100000000)); | ||
RUN_TEST(FLT_IS_EQUAL(hgps.variation, 15.500000000)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_view, 8)); | ||
|
||
RUN_TEST(INT_IS_EQUAL(hgps.sats_in_use, 5)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[0], 2)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[1], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[2], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[3], 7)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[4], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[5], 9)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[6], 24)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[7], 26)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[8], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[9], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[10], 0)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.satellites_ids[11], 0)); | ||
|
||
RUN_TEST(INT_IS_EQUAL(hgps.date, 8)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.month, 3)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.year, 1)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.hours, 18)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.minutes, 37)); | ||
RUN_TEST(INT_IS_EQUAL(hgps.seconds, 30)); | ||
} |