Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Testing successful calling of callback when a RMC message has been de…
Browse files Browse the repository at this point in the history
…coded
  • Loading branch information
aentinger committed Nov 16, 2020
1 parent c69c788 commit 2abd672
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
1 change: 1 addition & 0 deletions extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(TEST_TARGET testNmeaParser)

set(TEST_SRCS
src/ArduinoNmeaParser/test_OnGgaUpdateFunc.cpp
src/ArduinoNmeaParser/test_OnRmcUpdateFunc.cpp
src/test_ArduinoNmeaParser.cpp
src/test_checksum.cpp
src/test_GxGGA.cpp
Expand Down
77 changes: 77 additions & 0 deletions extras/test/src/ArduinoNmeaParser/test_OnRmcUpdateFunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020 LXRobotics.
* Author: Alexander Entinger <[email protected]>
* Contributors: https://github.com/107-systems/107-Arduino-NMEA-Parser/graphs/contributors.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include <string.h>

#include <string>
#include <algorithm>

#include <catch.hpp>

#include <ArduinoNmeaParser.h>

/**************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************/

static bool on_rmc_update_called = false;

/**************************************************************************************
* FUNCTION DEFINITION
**************************************************************************************/

static void encode(ArduinoNmeaParser & parser, std::string const & nmea)
{
std::for_each(std::begin(nmea),
std::end(nmea),
[&parser](char const c)
{
parser.encode(c);
});
}

void onRmcUpdate(nmea::RmcData const data)
{
on_rmc_update_called = true;

REQUIRE(data.source == nmea::RmcSource::GPS);

REQUIRE(data.time_utc.hour == 5);
REQUIRE(data.time_utc.minute == 28);
REQUIRE(data.time_utc.second == 56);
REQUIRE(data.time_utc.microsecond == 105);

REQUIRE(data.is_valid == true);

REQUIRE(data.latitude == Approx(52.514567));
REQUIRE(data.longitude == Approx(13.350933));

REQUIRE(data.speed == Approx(44.088f));
REQUIRE(data.course == Approx(206.4f));

REQUIRE(data.date.day == 8);
REQUIRE(data.date.month == 7);
REQUIRE(data.date.year == 2020);

REQUIRE(data.magnetic_variation == Approx(0.0));
}

/**************************************************************************************
* TEST CODE
**************************************************************************************/

TEST_CASE("Testing execution of OnRmcUpdateFunc when a full GxRMC message has been received", "[OnRmcUpdateFunc-01]")
{
ArduinoNmeaParser parser(onRmcUpdate, nullptr);
std::string const GPRMC = ("$GPRMC,052856.105,A,5230.874,N,01321.056,E,085.7,206.4,080720,000.0,W*78\r\n");
encode(parser, GPRMC);
REQUIRE(on_rmc_update_called == true);
}
6 changes: 3 additions & 3 deletions src/nmea/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ enum class RmcSource

typedef struct
{
bool is_valid;
RmcSource source;
Time time_utc;
bool is_valid;
float latitude;
float longitude;
float speed;
float course;
float magnetic_variation;
Time time_utc;
Date date;
} RmcData;

Expand Down Expand Up @@ -99,7 +99,7 @@ typedef struct

Time const INVALID_TIME = {-1, -1, -1, -1};
Date const INVALID_DATE = {-1, -1, -1};
RmcData const INVALID_RMC = {false, RmcSource::Unknown, NAN, NAN, NAN, NAN, NAN, INVALID_TIME, INVALID_DATE};
RmcData const INVALID_RMC = {RmcSource::Unknown, INVALID_TIME, false, NAN, NAN, NAN, NAN, NAN, INVALID_DATE};
GgaData const INVALID_GGA = {GgaSource::Unknown, INVALID_TIME, NAN, NAN, FixQuality::Invalid, -1, NAN, NAN, NAN, -1, {0}};

/**************************************************************************************
Expand Down

0 comments on commit 2abd672

Please sign in to comment.