mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 07:15:18 +03:00
Update unit tests.
This commit is contained in:
parent
05be7c922c
commit
5b3d86e966
8 changed files with 30 additions and 18 deletions
|
@ -26,9 +26,9 @@
|
||||||
|
|
||||||
|
|
||||||
#define DIGIT_TO_VAL(_x) (_x - '0')
|
#define DIGIT_TO_VAL(_x) (_x - '0')
|
||||||
uint32_t GPS_coord_to_degrees(char* coordinateString)
|
uint32_t GPS_coord_to_degrees(const char* coordinateString)
|
||||||
{
|
{
|
||||||
char *fieldSeparator, *remainingString;
|
const char *fieldSeparator, *remainingString;
|
||||||
uint8_t degress = 0, minutes = 0;
|
uint8_t degress = 0, minutes = 0;
|
||||||
uint16_t fractionalMinutes = 0;
|
uint16_t fractionalMinutes = 0;
|
||||||
uint8_t digitIndex;
|
uint8_t digitIndex;
|
||||||
|
|
|
@ -15,4 +15,4 @@
|
||||||
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint32_t GPS_coord_to_degrees(char* s);
|
uint32_t GPS_coord_to_degrees(const char* coordinateString);
|
||||||
|
|
|
@ -403,7 +403,7 @@ bool gpsNewFrame(uint8_t c)
|
||||||
EOS increased the precision here, even if we think that the gps is not precise enough, with 10e5 precision it has 76cm resolution
|
EOS increased the precision here, even if we think that the gps is not precise enough, with 10e5 precision it has 76cm resolution
|
||||||
with 10e7 it's around 1 cm now. Increasing it further is irrelevant, since even 1cm resolution is unrealistic, however increased
|
with 10e7 it's around 1 cm now. Increasing it further is irrelevant, since even 1cm resolution is unrealistic, however increased
|
||||||
resolution also increased precision of nav calculations
|
resolution also increased precision of nav calculations
|
||||||
static uint32_t GPS_coord_to_degrees(char *s)
|
static uint32_t GPS_coord_to_degrees(char *coordinateString)
|
||||||
{
|
{
|
||||||
char *p = s, *d = s;
|
char *p = s, *d = s;
|
||||||
uint8_t min, deg = 0;
|
uint8_t min, deg = 0;
|
||||||
|
|
|
@ -112,16 +112,16 @@ flight_imu_unittest : $(OBJECT_DIR)/flight/imu.o $(OBJECT_DIR)/flight_imu_unitte
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
|
||||||
$(OBJECT_DIR)/io/gps_conversion.o : $(USER_DIR)/io/gps_conversion.c $(USER_DIR)/io/gps_conversion.h $(GTEST_HEADERS)
|
$(OBJECT_DIR)/flight/gps_conversion.o : $(USER_DIR)/flight/gps_conversion.c $(USER_DIR)/flight/gps_conversion.h $(GTEST_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/io/gps_conversion.c -o $@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/flight/gps_conversion.c -o $@
|
||||||
|
|
||||||
$(OBJECT_DIR)/gps_conversion_unittest.o : $(TEST_DIR)/gps_conversion_unittest.cc \
|
$(OBJECT_DIR)/gps_conversion_unittest.o : $(TEST_DIR)/gps_conversion_unittest.cc \
|
||||||
$(USER_DIR)/io/gps_conversion.h $(GTEST_HEADERS)
|
$(USER_DIR)/flight/gps_conversion.h $(GTEST_HEADERS)
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/gps_conversion_unittest.cc -o $@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/gps_conversion_unittest.cc -o $@
|
||||||
|
|
||||||
gps_conversion_unittest : $(OBJECT_DIR)/io/gps_conversion.o $(OBJECT_DIR)/gps_conversion_unittest.o $(OBJECT_DIR)/gtest_main.a
|
gps_conversion_unittest : $(OBJECT_DIR)/flight/gps_conversion.o $(OBJECT_DIR)/gps_conversion_unittest.o $(OBJECT_DIR)/gtest_main.a
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,5 +135,5 @@ $(OBJECT_DIR)/telemetry_hott_unittest.o : $(TEST_DIR)/telemetry_hott_unittest.cc
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/telemetry_hott_unittest.cc -o $@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/telemetry_hott_unittest.cc -o $@
|
||||||
|
|
||||||
telemetry_hott_unittest :$(OBJECT_DIR)/telemetry/hott.o $(OBJECT_DIR)/telemetry_hott_unittest.o $(OBJECT_DIR)/io/gps_conversion.o $(OBJECT_DIR)/gtest_main.a
|
telemetry_hott_unittest :$(OBJECT_DIR)/telemetry/hott.o $(OBJECT_DIR)/telemetry_hott_unittest.o $(OBJECT_DIR)/flight/gps_conversion.o $(OBJECT_DIR)/gtest_main.a
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
|
@ -84,12 +84,17 @@ TEST(FlightImuTest, IsThrustFacingDownwards)
|
||||||
|
|
||||||
uint16_t acc_1G;
|
uint16_t acc_1G;
|
||||||
int16_t heading;
|
int16_t heading;
|
||||||
flags_t f;
|
|
||||||
gyro_t gyro;
|
gyro_t gyro;
|
||||||
int16_t magADC[XYZ_AXIS_COUNT];
|
int16_t magADC[XYZ_AXIS_COUNT];
|
||||||
int32_t BaroAlt;
|
int32_t BaroAlt;
|
||||||
int16_t debug[4];
|
int16_t debug[4];
|
||||||
|
|
||||||
|
uint8_t stateFlags;
|
||||||
|
uint16_t flightModeFlags;
|
||||||
|
uint8_t armingFlags;
|
||||||
|
|
||||||
|
int32_t sonarAlt;
|
||||||
|
|
||||||
|
|
||||||
void gyroGetADC(void) {};
|
void gyroGetADC(void) {};
|
||||||
bool sensors(uint32_t mask)
|
bool sensors(uint32_t mask)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "io/gps_conversion.h"
|
#include "flight/gps_conversion.h"
|
||||||
|
|
||||||
#include "unittest_macros.h"
|
#include "unittest_macros.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
@ -39,7 +39,7 @@ typedef struct gpsConversionExpectation_s {
|
||||||
|
|
||||||
TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
|
TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
|
||||||
{
|
{
|
||||||
gpsConversionExpectation_t gpsConversionExpectations[] = {
|
const gpsConversionExpectation_t gpsConversionExpectations[] = {
|
||||||
{"0.0", 0},
|
{"0.0", 0},
|
||||||
{"000.0", 0},
|
{"000.0", 0},
|
||||||
{"00000.0000", 0},
|
{"00000.0000", 0},
|
||||||
|
@ -59,7 +59,7 @@ TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
|
||||||
// expect
|
// expect
|
||||||
|
|
||||||
for (uint8_t index = 0; index < testIterationCount; index ++) {
|
for (uint8_t index = 0; index < testIterationCount; index ++) {
|
||||||
gpsConversionExpectation_t *expectation = &gpsConversionExpectations[index];
|
const gpsConversionExpectation_t *expectation = &gpsConversionExpectations[index];
|
||||||
printf("iteration: %d\n", index);
|
printf("iteration: %d\n", index);
|
||||||
|
|
||||||
uint32_t result = GPS_coord_to_degrees(expectation->coord);
|
uint32_t result = GPS_coord_to_degrees(expectation->coord);
|
||||||
|
|
|
@ -18,3 +18,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define BARO
|
#define BARO
|
||||||
|
#define GPS
|
||||||
|
#define TELEMETRY
|
||||||
|
|
||||||
|
#define SERIAL_PORT_COUNT 4
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
#include "telemetry/telemetry.h"
|
#include "telemetry/telemetry.h"
|
||||||
#include "telemetry/hott.h"
|
#include "telemetry/hott.h"
|
||||||
|
|
||||||
#include "io/gps_conversion.h"
|
#include "flight/gps_conversion.h"
|
||||||
|
|
||||||
|
|
||||||
#include "unittest_macros.h"
|
#include "unittest_macros.h"
|
||||||
|
@ -88,8 +88,8 @@ TEST(TelemetryHottTest, UpdateGPSCoordinates2)
|
||||||
|
|
||||||
// Hampstead Heath, London
|
// Hampstead Heath, London
|
||||||
// 51.563886, -0.159960
|
// 51.563886, -0.159960
|
||||||
int32_t longitude = GPS_coord_to_degrees("5156.3886");
|
uint32_t longitude = GPS_coord_to_degrees("5156.3886");
|
||||||
int32_t latitude = -GPS_coord_to_degrees("015.9960");
|
uint32_t latitude = -GPS_coord_to_degrees("015.9960");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
addGPSCoordinates(hottGPSMessage, longitude, latitude);
|
addGPSCoordinates(hottGPSMessage, longitude, latitude);
|
||||||
|
@ -131,7 +131,7 @@ TEST(TelemetryHottTest, PrepareGPSMessage_Altitude1m)
|
||||||
// given
|
// given
|
||||||
HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest();
|
HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest();
|
||||||
|
|
||||||
f.GPS_FIX = 1;
|
stateFlags = GPS_FIX;
|
||||||
uint16_t altitudeInMeters = 1;
|
uint16_t altitudeInMeters = 1;
|
||||||
GPS_altitude = altitudeInMeters * (1 / 0.1f); // 1 = 0.1m
|
GPS_altitude = altitudeInMeters * (1 / 0.1f); // 1 = 0.1m
|
||||||
|
|
||||||
|
@ -147,8 +147,10 @@ TEST(TelemetryHottTest, PrepareGPSMessage_Altitude1m)
|
||||||
|
|
||||||
int16_t debug[4];
|
int16_t debug[4];
|
||||||
|
|
||||||
|
uint8_t stateFlags;
|
||||||
|
|
||||||
|
|
||||||
uint8_t GPS_numSat;
|
uint8_t GPS_numSat;
|
||||||
flags_t f;
|
|
||||||
int32_t GPS_coord[2];
|
int32_t GPS_coord[2];
|
||||||
uint16_t GPS_speed; // speed in 0.1m/s
|
uint16_t GPS_speed; // speed in 0.1m/s
|
||||||
uint16_t GPS_distanceToHome; // distance to home point in meters
|
uint16_t GPS_distanceToHome; // distance to home point in meters
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue