Skip to content

Commit

Permalink
Updates to RMC
Browse files Browse the repository at this point in the history
Closes #2

Updated to more modern C++ as well as fixing the bugs described in the report.
  • Loading branch information
SammyB428 committed Mar 31, 2021
1 parent 881d602 commit aacd564
Show file tree
Hide file tree
Showing 23 changed files with 116 additions and 43 deletions.
22 changes: 11 additions & 11 deletions ALM.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ bool ALM::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

NumberOfMessages = (uint16_t) sentence.Integer( 1 );
MessageNumber = (uint16_t) sentence.Integer( 2 );
PRNNumber = (uint16_t) sentence.Integer( 3 );
WeekNumber = (uint16_t) sentence.Integer( 4 );
SVHealth = (uint16_t) ::HexValue( sentence.Field( 5 ) );
Eccentricity = (uint16_t) ::HexValue( sentence.Field( 6 ) );
AlmanacReferenceTime = (uint16_t) ::HexValue( sentence.Field( 7 ) );
InclinationAngle = (uint16_t) ::HexValue( sentence.Field( 8 ) );
RateOfRightAscension = (uint16_t) ::HexValue( sentence.Field( 9 ) );
NumberOfMessages = static_cast<uint16_t>(sentence.Integer( 1 ));
MessageNumber = static_cast<uint16_t>(sentence.Integer( 2 ));
PRNNumber = static_cast<uint16_t>(sentence.Integer( 3 ));
WeekNumber = static_cast<uint16_t>(sentence.Integer( 4 ));
SVHealth = static_cast<uint16_t>(::HexValue( sentence.Field( 5 ) ));
Eccentricity = static_cast<uint16_t>(::HexValue( sentence.Field( 6 ) ));
AlmanacReferenceTime = static_cast<uint16_t>(::HexValue( sentence.Field( 7 ) ));
InclinationAngle = static_cast<uint16_t>(::HexValue( sentence.Field( 8 ) ));
RateOfRightAscension = static_cast<uint16_t>(::HexValue( sentence.Field( 9 ) ));
RootOfSemiMajorAxis = ::HexValue( sentence.Field( 10 ) );
ArgumentOfPerigee = ::HexValue( sentence.Field( 11 ) );
LongitudeOfAscensionNode = ::HexValue( sentence.Field( 12 ) );
MeanAnomaly = ::HexValue( sentence.Field( 13 ) );
F0ClockParameter = (uint16_t) ::HexValue( sentence.Field( 14 ) );
F1ClockParameter = (uint16_t) ::HexValue( sentence.Field( 15 ) );
F0ClockParameter = static_cast<uint16_t>(::HexValue( sentence.Field( 14 ) ));
F1ClockParameter = static_cast<uint16_t>(::HexValue( sentence.Field( 15 ) ));

return( true );
}
Expand Down
2 changes: 1 addition & 1 deletion DCN.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ bool DCN::Parse( SENTENCE const& sentence ) noexcept
PurpleLineNavigationUse = sentence.Boolean( 13 );
PositionUncertaintyNauticalMiles = sentence.Double( 14 );

int temp_integer = sentence.Integer( 16 );
auto const temp_integer = sentence.Integer( 16 );

switch( temp_integer )
{
Expand Down
2 changes: 1 addition & 1 deletion FSI.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool FSI::Parse( SENTENCE const& sentence ) noexcept
TransmittingFrequency = sentence.Double( 1 );
ReceivingFrequency = sentence.Double( 2 );
Mode = sentence.CommunicationsMode( 3 );
PowerLevel = (short) sentence.Integer( 4 );
PowerLevel = static_cast<uint16_t>(sentence.Integer( 4 ));

return( true );
}
Expand Down
2 changes: 1 addition & 1 deletion GSA.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ bool GSA::Parse( SENTENCE const& sentence ) noexcept
OperatingMode = GSA::OPERATING_MODE::UnknownOperatingMode;
}

std::size_t index = sentence.Integer( 2 );
auto index = sentence.Integer( 2 );

switch( index )
{
Expand Down
10 changes: 8 additions & 2 deletions GSV.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,21 @@ bool GSV::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

int const message_number = sentence.Integer( 2 );
auto const message_number = sentence.Integer( 2 );

NumberOfSatellites = sentence.Integer( 3 );

int index = 0;

while( index < 4 )
{
SatellitesInView[ ( ( message_number - 1 ) * 4 ) + index ].Parse( ( index * 4 ) + 4, sentence );
auto const array_index = ((message_number - 1) * 4) + index;

if (array_index < std::size(SatellitesInView))
{
SatellitesInView[array_index].Parse((index * 4) + 4, sentence);
}

index++;
}

Expand Down
2 changes: 1 addition & 1 deletion GSV.HPP
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GSV : public RESPONSE
*/

int NumberOfSatellites{ 0 };
SATELLITE_DATA SatellitesInView[ 12 ];
SATELLITE_DATA SatellitesInView[ 36 ];

/*
** Methods
Expand Down
2 changes: 1 addition & 1 deletion GXA.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bool GXA::Parse( SENTENCE const& sentence ) noexcept
Time = sentence.Time( 1 );
Position.Parse( 2, 3, 4, 5, sentence );
WaypointID = sentence.Field( 6 );
SatelliteNumber = (uint16_t) sentence.Integer( 7 );
SatelliteNumber = static_cast<uint16_t>(sentence.Integer( 7 ));

return( true );
}
Expand Down
11 changes: 11 additions & 0 deletions NMEA0183.H
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ enum class TRANSDUCER_TYPE
VolumeTransducer = 'V'
};

enum class FAA_MODE
{
ModeUnknown = 0,
Autonomous = 'A',
Differential = 'D',
Estimated = 'E',
NotValid = 'N',
Simulated = 'S',
Manual = 'M'
};

/*
** Misc Function Prototypes
*/
Expand Down
2 changes: 1 addition & 1 deletion RMA.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool RMA::Parse( SENTENCE const& sentence ) noexcept
** First we check the checksum...
*/

NMEA0183_BOOLEAN const check = sentence.IsChecksumBad( 12 );
auto const check = sentence.IsChecksumBad( 12 );

if ( check == NMEA0183_BOOLEAN::True )
{
Expand Down
2 changes: 1 addition & 1 deletion RMB.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool RMB::Parse( SENTENCE const& sentence ) noexcept
** First we check the checksum...
*/

NMEA0183_BOOLEAN const check = sentence.IsChecksumBad( 14 );
auto const check = sentence.IsChecksumBad( 14 );

if ( check == NMEA0183_BOOLEAN::True )
{
Expand Down
29 changes: 21 additions & 8 deletions RMC.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void RMC::Empty( void ) noexcept
Date.clear();
MagneticVariation = 0.0;
MagneticVariationDirection = EASTWEST::EW_Unknown;
FAAMode = FAA_MODE::ModeUnknown;
}

bool RMC::Parse( SENTENCE const& sentence ) noexcept
Expand All @@ -67,26 +68,38 @@ bool RMC::Parse( SENTENCE const& sentence ) noexcept
** 9) Date, ddmmyy
** 10) Magnetic Variation, degrees
** 11) E or W
** 12) Checksum
** 12) FAA Mode (version 2.3)
** 13) Checksum
*/

/*
** First we check the checksum...
*/

NMEA0183_BOOLEAN const check = sentence.IsChecksumBad( 12 );
int checksum_field = 12;

if ( check == NMEA0183_BOOLEAN::True )
// Version 2.3 of the standard has things different

FAAMode = sentence.FAAMode(12);

if (FAAMode != FAA_MODE::ModeUnknown)
{
checksum_field = 13;
}

auto const check = sentence.IsChecksumBad(checksum_field);

if (check == NMEA0183_BOOLEAN::True)
{
SetErrorMessage(STRING_VIEW("Invalid Checksum"));
return( false );
return(false);
}
if ( check == NMEA0183_BOOLEAN::NMEA_Unknown )

if (check == NMEA0183_BOOLEAN::NMEA_Unknown)
{
SetErrorMessage(STRING_VIEW("Missing Checksum"));
return( false );
}
return(false);
}

UTCTime = sentence.Field( 1 );
Time = sentence.Time( 1 );
Expand Down
1 change: 1 addition & 0 deletions RMC.HPP
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class RMC : public RESPONSE
std::string Date;
double MagneticVariation{ 0.0 };
EASTWEST MagneticVariationDirection{ EASTWEST::EW_Unknown };
FAA_MODE FAAMode{ FAA_MODE::ModeUnknown };

/*
** Methods
Expand Down
2 changes: 1 addition & 1 deletion RSD.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool RSD::Parse( SENTENCE const& sentence ) noexcept
RangeScale = sentence.Double( 11 );
RangeUnits = sentence.Field( 12 );

int temp_integer = sentence.Integer( 13 );
auto const temp_integer = sentence.Integer( 13 );

switch( temp_integer )
{
Expand Down
53 changes: 47 additions & 6 deletions SENTENCE.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Dr. Richard Garwin
The MIT License (MIT)
Copyright (c) 1996-2019 Sam Blackburn
Copyright (c) 1996-2021 Sam Blackburn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -119,7 +119,7 @@ uint8_t SENTENCE::ComputeChecksum( void ) const noexcept
{
uint8_t checksum_value = 0;

std::size_t const string_length = Sentence.length();
auto const string_length = Sentence.length();
std::size_t index = 1; // Skip over the $ at the begining of the sentence

while( index < string_length and
Expand Down Expand Up @@ -183,7 +183,7 @@ std::string_view SENTENCE::Field( int desired_field_number ) const noexcept
std::size_t index = 1; // Skip over the $ at the begining of the sentence
int current_field_number = 0;

std::size_t const string_length = Sentence.length();
auto const string_length = Sentence.length();

while( current_field_number < desired_field_number and index < string_length )
{
Expand Down Expand Up @@ -219,7 +219,7 @@ uint16_t SENTENCE::GetNumberOfDataFields( void ) const noexcept
std::size_t index = 1; // Skip over the $ at the begining of the sentence
int current_field_number = 0;

std::size_t const string_length = Sentence.length();
auto const string_length = Sentence.length();

while( index < string_length )
{
Expand All @@ -241,7 +241,7 @@ uint16_t SENTENCE::GetNumberOfDataFields( void ) const noexcept

void SENTENCE::Finish( void ) noexcept
{
uint8_t const checksum = ComputeChecksum();
auto const checksum = ComputeChecksum();

char temp_string[ 10 ];

Expand Down Expand Up @@ -376,7 +376,7 @@ REFERENCE SENTENCE::Reference( int field_number ) const noexcept

time_t SENTENCE::Time( int field_number ) const noexcept
{
time_t return_value = time(nullptr);
auto return_value = time(nullptr);

auto temp_string = Field( field_number );

Expand Down Expand Up @@ -464,6 +464,47 @@ TRANSDUCER_TYPE SENTENCE::TransducerType( int field_number ) const noexcept
}
}

FAA_MODE SENTENCE::FAAMode(int field_number) const noexcept
{
auto field_data = Field(field_number);

if (field_data.length() == 1)
{
if (field_data[0] == 'A')
{
return(FAA_MODE::Autonomous);
}
else if (field_data[0] == 'D')
{
return(FAA_MODE::Differential);
}
else if (field_data[0] == 'E')
{
return(FAA_MODE::Estimated);
}
else if (field_data[0] == 'N')
{
return(FAA_MODE::NotValid);
}
else if (field_data[0] == 'S')
{
return(FAA_MODE::Simulated);
}
else if (field_data[0] == 'M')
{
return(FAA_MODE::Manual);
}
else
{
return(FAA_MODE::ModeUnknown);
}
}
else
{
return(FAA_MODE::ModeUnknown);
}
}

/*
** Operators
*/
Expand Down
1 change: 1 addition & 0 deletions SENTENCE.HPP
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SENTENCE
virtual REFERENCE Reference( int field_number ) const noexcept;
virtual time_t Time( int field_number ) const noexcept;
virtual TRANSDUCER_TYPE TransducerType( int field_number ) const noexcept;
virtual FAA_MODE FAAMode(int field_number) const noexcept;

/*
** Operators
Expand Down
2 changes: 1 addition & 1 deletion ZFI.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZFI::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZLZ.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool ZLZ::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZPI.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZPI::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZTA.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZTA::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZTE.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZTE::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZTI.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZTI::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZWP.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool ZWP::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down
2 changes: 1 addition & 1 deletion ZZU.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool ZZU::Parse( SENTENCE const& sentence ) noexcept
return( false );
}

time_t temp_time = time(nullptr);
auto temp_time = time(nullptr);

auto tm_p = gmtime(&temp_time);

Expand Down

0 comments on commit aacd564

Please sign in to comment.