Skip to content

Commit

Permalink
Apply astyle config
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jul 2, 2020
1 parent 6fec285 commit 2d59623
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 97 deletions.
28 changes: 14 additions & 14 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ gps_t hgps;
*/
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"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";

int
main() {
Expand Down
28 changes: 14 additions & 14 deletions examples/example_buff.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ uint8_t hgps_buff_data[12];
*/
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"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";
static size_t write_ptr;
static void uart_irqhandler(void);

Expand Down
33 changes: 17 additions & 16 deletions examples/example_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ gps_t hgps;
*/
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"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\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"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";

const gps_statement_t expected[] = {
STAT_RMC,
Expand All @@ -52,12 +52,13 @@ const gps_statement_t expected[] = {

static int err_cnt;

void callback(gps_statement_t res) {
void
callback(gps_statement_t res) {
static int i;

if (res != expected[i]) {
printf("failed i %d, expected res %d but received %d\n",
i, expected[i], res);
i, expected[i], res);
++err_cnt;
}

Expand Down
12 changes: 6 additions & 6 deletions examples/test_code.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ gps_t hgps;
*/
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"
"";
"$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
Expand Down
14 changes: 7 additions & 7 deletions examples/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <stdlib.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__ ); \
exit(1); \
} \
} while (0)
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__ ); \
exit(1); \
} \
} while (0)
#define FLT_IS_EQUAL(x, y) (fabs((double)(x) - (double)(y)) < 0.00001)
#define INT_IS_EQUAL(x, y) ((int)((x) == (y)))

Expand Down
10 changes: 5 additions & 5 deletions examples/test_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ gps_t hgps;
*/
const char
gps_rx_data_A[] = ""
"$PUBX,04*37\r\n"
"$PUBX,04,073731.00,091202,113851.00,1196,15D,1930035,-2660.664,43*71\r\n"
"";
"$PUBX,04*37\r\n"
"$PUBX,04,073731.00,091202,113851.00,1196,15D,1930035,-2660.664,43*71\r\n"
"";
const char
gps_rx_data_B[] = ""
"$PUBX,04,200714.00,230320,158834.00,2098,18,536057,257.043,16*12\r\b"
"";
"$PUBX,04,200714.00,230320,158834.00,2098,18,536057,257.043,16*12\r\b"
"";


/**
Expand Down
98 changes: 63 additions & 35 deletions gps_nmea_parser/src/gps/gps.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

#define CRC_ADD(_gh, ch) (_gh)->p.crc_calc ^= (uint8_t)(ch)
#define TERM_ADD(_gh, ch) do { \
if ((_gh)->p.term_pos < (sizeof((_gh)->p.term_str) - 1)) { \
(_gh)->p.term_str[(_gh)->p.term_pos++] = (ch); \
(_gh)->p.term_str[(_gh)->p.term_pos] = 0; \
} \
} while (0)
if ((_gh)->p.term_pos < (sizeof((_gh)->p.term_str) - 1)) { \
(_gh)->p.term_str[(_gh)->p.term_pos++] = (ch); \
(_gh)->p.term_str[(_gh)->p.term_pos] = 0; \
} \
} while (0)
#define TERM_NEXT(_gh) do { (_gh)->p.term_str[((_gh)->p.term_pos = 0)] = 0; (_gh)->p.term_num++; } while (0)

#define CIN(x) ((x) >= '0' && (x) <= '9')
Expand Down Expand Up @@ -194,7 +194,8 @@ parse_term(gps_t* gh) {
case 11: /* Altitude above ellipsoid */
gh->p.data.gga.geo_sep = parse_float_number(gh, NULL);
break;
default: break;
default:
break;
}
#endif /* GPS_CFG_STATEMENT_GPGGA */
#if GPS_CFG_STATEMENT_GPGSA
Expand Down Expand Up @@ -239,11 +240,20 @@ parse_term(gps_t* gh) {
if (index < sizeof(gh->sats_in_view_desc) / sizeof(gh->sats_in_view_desc[0])) {
value = (uint16_t)parse_number(gh, NULL); /* Parse number as integer */
switch (term_num % 4) {
case 0: gh->sats_in_view_desc[index].num = value; break;
case 1: gh->sats_in_view_desc[index].elevation = value; break;
case 2: gh->sats_in_view_desc[index].azimuth = value; break;
case 3: gh->sats_in_view_desc[index].snr = value; break;
default: break;
case 0:
gh->sats_in_view_desc[index].num = value;
break;
case 1:
gh->sats_in_view_desc[index].elevation = value;
break;
case 2:
gh->sats_in_view_desc[index].azimuth = value;
break;
case 3:
gh->sats_in_view_desc[index].snr = value;
break;
default:
break;
}
}
}
Expand Down Expand Up @@ -276,7 +286,8 @@ parse_term(gps_t* gh) {
gh->p.data.rmc.variation = -gh->p.data.rmc.variation;
}
break;
default: break;
default:
break;
}
#endif /* GPS_CFG_STATEMENT_GPRMC */
#if GPS_CFG_STATEMENT_PUBX
Expand Down Expand Up @@ -309,11 +320,11 @@ parse_term(gps_t* gh) {
*/
if (gh->p.term_str[2] == 'D' || gh->p.term_str[2] == '\0') {
gh->p.data.time.leap_sec = 10 * CTN(gh->p.term_str[0])
+ CTN(gh->p.term_str[1]);
+ CTN(gh->p.term_str[1]);
} else {
gh->p.data.time.leap_sec = 100 * CTN(gh->p.term_str[0])
+ 10 * CTN(gh->p.term_str[1])
+ CTN(gh->p.term_str[2]);
+ 10 * CTN(gh->p.term_str[1])
+ CTN(gh->p.term_str[2]);
}
break;
case 7: /* Process clock bias */
Expand All @@ -325,7 +336,8 @@ parse_term(gps_t* gh) {
case 9: /* Process time pulse granularity */
gh->p.data.time.tp_gran = parse_number(gh, NULL);
break;
default: break;
default:
break;
}
#endif /* GPS_CFG_STATEMENT_PUBX_TIME */
#endif /* GPS_CFG_STATEMENT_PUBX */
Expand Down Expand Up @@ -553,24 +565,40 @@ gps_distance_bearing(gps_float_t las, gps_float_t los, gps_float_t lae, gps_floa
gps_float_t
gps_to_speed(gps_float_t sik, gps_speed_t ts) {
switch (ts) {
case gps_speed_kps: return FLT(sik * FLT(0.000514));
case gps_speed_kph: return FLT(sik * FLT(1.852));
case gps_speed_mps: return FLT(sik * FLT(0.5144));
case gps_speed_mpm: return FLT(sik * FLT(30.87));

case gps_speed_mips: return FLT(sik * FLT(0.0003197));
case gps_speed_mph: return FLT(sik * FLT(1.151));
case gps_speed_fps: return FLT(sik * FLT(1.688));
case gps_speed_fpm: return FLT(sik * FLT(101.3));

case gps_speed_mpk: return FLT(sik * FLT(32.4));
case gps_speed_spk: return FLT(sik * FLT(1944.0));
case gps_speed_sp100m: return FLT(sik * FLT(194.4));
case gps_speed_mipm: return FLT(sik * FLT(52.14));
case gps_speed_spm: return FLT(sik * FLT(3128.0));
case gps_speed_sp100y: return FLT(sik * FLT(177.7));

case gps_speed_smph: return FLT(sik * FLT(1.0));
default: return 0;
case gps_speed_kps:
return FLT(sik * FLT(0.000514));
case gps_speed_kph:
return FLT(sik * FLT(1.852));
case gps_speed_mps:
return FLT(sik * FLT(0.5144));
case gps_speed_mpm:
return FLT(sik * FLT(30.87));

case gps_speed_mips:
return FLT(sik * FLT(0.0003197));
case gps_speed_mph:
return FLT(sik * FLT(1.151));
case gps_speed_fps:
return FLT(sik * FLT(1.688));
case gps_speed_fpm:
return FLT(sik * FLT(101.3));

case gps_speed_mpk:
return FLT(sik * FLT(32.4));
case gps_speed_spk:
return FLT(sik * FLT(1944.0));
case gps_speed_sp100m:
return FLT(sik * FLT(194.4));
case gps_speed_mipm:
return FLT(sik * FLT(52.14));
case gps_speed_spm:
return FLT(sik * FLT(3128.0));
case gps_speed_sp100y:
return FLT(sik * FLT(177.7));

case gps_speed_smph:
return FLT(sik * FLT(1.0));
default:
return 0;
}
}

0 comments on commit 2d59623

Please sign in to comment.