kopia lustrzana https://github.com/OpenRTX/OpenRTX
Added function to convert minmea coordinate to fixed-point integer representation
rodzic
71b35985ce
commit
36ef3b310c
|
@ -80,6 +80,8 @@ jobs:
|
|||
run: meson test -C build "M17 RRC Test"
|
||||
- name: Codeplug Test
|
||||
run: meson test -C build "Codeplug Test"
|
||||
- name: minmea Conversion Test
|
||||
run: meson test -C build "minmea conversion Test"
|
||||
# The following tests are disabled because they appear to be flakey when run in CI
|
||||
# - name: Sine Test
|
||||
# run: meson test -C build "Sine Test"
|
||||
|
|
|
@ -252,6 +252,12 @@ static inline float minmea_tocoord(struct minmea_float *f)
|
|||
return (float) degrees + (float) minutes / (60 * f->scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a raw coordinate to a fixed point value.
|
||||
* Returns zero for "unknown" values.
|
||||
*/
|
||||
int minmea_tofixedpoint(struct minmea_float *f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -642,4 +642,20 @@ int minmea_gettime(struct timespec *ts, const struct minmea_date *date, const st
|
|||
}
|
||||
}
|
||||
|
||||
int minmea_tofixedpoint(struct minmea_float *f) {
|
||||
|
||||
if (f->scale == 0)
|
||||
return 0;
|
||||
|
||||
int32_t value = f->value;
|
||||
int32_t scale = f->scale;
|
||||
int8_t sign = value < 0 ? -1 : 1;
|
||||
// Ensure value is always positive
|
||||
value = value * sign;
|
||||
int32_t coord_int = value / (scale * 100);
|
||||
int32_t coord_dec = (value % (scale * 100)) * (100000 / scale) / 6;
|
||||
return (coord_int * 1000000 + coord_dec) * sign;
|
||||
}
|
||||
|
||||
|
||||
/* vim: set ts=4 sw=4 et: */
|
||||
|
|
|
@ -880,6 +880,10 @@ vp_test = executable('vp_test',
|
|||
sources : unit_test_src + ['tests/unit/voice_prompts.c'],
|
||||
kwargs : unit_test_opts)
|
||||
|
||||
minmea_conversion_test = executable('minmea_conversion_test',
|
||||
sources : unit_test_src + ['tests/unit/convert_minmea_coord.c'],
|
||||
kwargs : unit_test_opts)
|
||||
|
||||
test('M17 Golay Unit Test', m17_golay_test)
|
||||
test('M17 Viterbi Unit Test', m17_viterbi_test)
|
||||
## test('M17 Demodulator Test', m17_demodulator_test) # Skipped for now as this test no longer works after an M17 refactor
|
||||
|
@ -888,3 +892,4 @@ test('Codeplug Test', cps_test)
|
|||
test('Linux InputStream Test', linux_inputStream_test)
|
||||
test('Sine Test', sine_test)
|
||||
## test('Voice Prompts Test', vp_test) # Skipped for now as this test no longer works
|
||||
test('minmea conversion Test', minmea_conversion_test)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <datetime.h>
|
||||
#include <stdint.h>
|
||||
#include <minmea.h>
|
||||
|
||||
/**
|
||||
* Data structure representing a single satellite as part of a GPS fix.
|
||||
|
@ -63,4 +64,5 @@ gps_t;
|
|||
*/
|
||||
void gps_task();
|
||||
|
||||
|
||||
#endif /* GPS_H */
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <gps.h>
|
||||
|
||||
static void assert_conversion(struct minmea_float *f, int32_t expected)
|
||||
{
|
||||
int32_t result = minmea_tofixedpoint(f);
|
||||
if (result != expected)
|
||||
{
|
||||
printf("FAILED! result value %d - expected %d\n",
|
||||
result, expected);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("minmea coordinate conversion test\n");
|
||||
struct minmea_float test = {5333735, 1000};
|
||||
assert_conversion(&test, 53562250);
|
||||
test.scale = 1;
|
||||
test.value = 0;
|
||||
assert_conversion(&test, 0);
|
||||
test.scale = 1000;
|
||||
test.value = -5333735;
|
||||
assert_conversion(&test, -53562250);
|
||||
test.scale = 1000;
|
||||
test.value = -330;
|
||||
assert_conversion(&test, -5500);
|
||||
test.scale = 1000;
|
||||
test.value = -3296;
|
||||
assert_conversion(&test, -54933);
|
||||
printf("PASS\n");
|
||||
|
||||
return 0;
|
||||
}
|
Ładowanie…
Reference in New Issue