Update HoTT GPS coordinate calculations.

It was broken for South/West values.

Added additional tests for maximum long/lat values.

Requires field testing to make sure values are correct on the telemetry
display.
This commit is contained in:
Dominic Clifton 2014-05-26 02:15:06 +01:00
parent 37051720fd
commit 8f6558156f
2 changed files with 63 additions and 19 deletions

View File

@ -121,11 +121,11 @@ static void initialiseMessages(void)
void addGPSCoordinates(HOTT_GPS_MSG_t *hottGPSMessage, int32_t latitude, int32_t longitude) void addGPSCoordinates(HOTT_GPS_MSG_t *hottGPSMessage, int32_t latitude, int32_t longitude)
{ {
uint8_t deg = latitude / 10000000UL; int16_t deg = latitude / 10000000L;
uint32_t sec = (latitude - (deg * 10000000UL)) * 6; int32_t sec = (latitude - (deg * 10000000L)) * 6;
uint8_t min = sec / 1000000UL; int8_t min = sec / 1000000L;
sec = (sec % 1000000UL) / 100UL; sec = (sec % 1000000L) / 100L;
uint16_t degMin = (deg * 100) + min; uint16_t degMin = (deg * 100L) + min;
hottGPSMessage->pos_NS = (latitude < 0); hottGPSMessage->pos_NS = (latitude < 0);
hottGPSMessage->pos_NS_dm_L = degMin; hottGPSMessage->pos_NS_dm_L = degMin;
@ -133,11 +133,11 @@ void addGPSCoordinates(HOTT_GPS_MSG_t *hottGPSMessage, int32_t latitude, int32_t
hottGPSMessage->pos_NS_sec_L = sec; hottGPSMessage->pos_NS_sec_L = sec;
hottGPSMessage->pos_NS_sec_H = sec >> 8; hottGPSMessage->pos_NS_sec_H = sec >> 8;
deg = longitude / 10000000UL; deg = longitude / 10000000L;
sec = (longitude - (deg * 10000000UL)) * 6; sec = (longitude - (deg * 10000000L)) * 6;
min = sec / 1000000UL; min = sec / 1000000L;
sec = (sec % 1000000UL) / 100UL; sec = (sec % 1000000L) / 100L;
degMin = (deg * 100) + min; degMin = (deg * 100L) + min;
hottGPSMessage->pos_EW = (longitude < 0); hottGPSMessage->pos_EW = (longitude < 0);
hottGPSMessage->pos_EW_dm_L = degMin; hottGPSMessage->pos_EW_dm_L = degMin;

View File

@ -42,27 +42,71 @@ HOTT_GPS_MSG_t *getGPSMessageForTest(void)
return &hottGPSMessage; return &hottGPSMessage;
} }
TEST(TelemetryHottTest, UpdateGPSCoordinates) TEST(TelemetryHottTest, UpdateGPSCoordinates1)
{ {
// given // given
HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest(); HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest();
// Mayrhofen, Austria // Mayrhofen, Austria
uint32_t latitude = GPS_coord_to_degrees("4710.5186"); uint32_t longitude = GPS_coord_to_degrees("4710.5186");
uint32_t longitude = GPS_coord_to_degrees("1151.4252"); uint32_t latitude = GPS_coord_to_degrees("1151.4252");
// when
addGPSCoordinates(hottGPSMessage, latitude, longitude);
// then
EXPECT_EQ(hottGPSMessage->pos_NS, 0);
EXPECT_EQ(hottGPSMessage->pos_NS_dm_H << 8 | hottGPSMessage->pos_NS_dm_L, 1151);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_NS_sec_H << 8 | hottGPSMessage->pos_NS_sec_L), 4251);
EXPECT_EQ(hottGPSMessage->pos_EW, 0);
EXPECT_EQ(hottGPSMessage->pos_EW_dm_H << 8 | hottGPSMessage->pos_EW_dm_L, 4710);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_EW_sec_H << 8 | hottGPSMessage->pos_EW_sec_L), 5186);
}
TEST(TelemetryHottTest, UpdateGPSCoordinates2)
{
// given
HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest();
// Hampstead Heath, London
// 51.563886, -0.159960
int32_t longitude = GPS_coord_to_degrees("5156.3886");
int32_t latitude = -GPS_coord_to_degrees("015.9960");
// when // when
addGPSCoordinates(hottGPSMessage, longitude, latitude); addGPSCoordinates(hottGPSMessage, longitude, latitude);
// then // then
EXPECT_EQ(hottGPSMessage->pos_EW, 0);
EXPECT_EQ(hottGPSMessage->pos_EW_dm_H << 8 | hottGPSMessage->pos_EW_dm_L, 4710);
EXPECT_EQ(hottGPSMessage->pos_EW_sec_H << 8 | hottGPSMessage->pos_EW_sec_L, 5186);
EXPECT_EQ(hottGPSMessage->pos_NS, 0); EXPECT_EQ(hottGPSMessage->pos_NS, 0);
EXPECT_EQ(hottGPSMessage->pos_NS_dm_H << 8 | hottGPSMessage->pos_NS_dm_L, 1151); EXPECT_EQ(hottGPSMessage->pos_NS_dm_H << 8 | hottGPSMessage->pos_NS_dm_L, 5156);
EXPECT_EQ(hottGPSMessage->pos_NS_sec_H << 8 | hottGPSMessage->pos_NS_sec_L, 4251); EXPECT_EQ(hottGPSMessage->pos_NS_sec_H << 8 | hottGPSMessage->pos_NS_sec_L, 3886);
EXPECT_EQ(hottGPSMessage->pos_EW, 1);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_EW_dm_H << 8 | hottGPSMessage->pos_EW_dm_L), -15);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_EW_sec_H << 8 | hottGPSMessage->pos_EW_sec_L), -9960);
}
TEST(TelemetryHottTest, UpdateGPSCoordinates3)
{
// given
HOTT_GPS_MSG_t *hottGPSMessage = getGPSMessageForTest();
int32_t longitude = -GPS_coord_to_degrees("17999.9999");
int32_t latitude = GPS_coord_to_degrees("8999.9999");
// when
addGPSCoordinates(hottGPSMessage, longitude, latitude);
// then
EXPECT_EQ(hottGPSMessage->pos_NS, 1);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_NS_dm_H << 8 | hottGPSMessage->pos_NS_dm_L), -18039);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_NS_sec_H << 8 | hottGPSMessage->pos_NS_sec_L), -9999);
EXPECT_EQ(hottGPSMessage->pos_EW, 0);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_EW_dm_H << 8 | hottGPSMessage->pos_EW_dm_L), 9039);
EXPECT_EQ((int16_t)(hottGPSMessage->pos_EW_sec_H << 8 | hottGPSMessage->pos_EW_sec_L), 9999);
} }