source: pacpussensors/trunk/NMEA0183/src/LAT.cpp

Last change on this file was 59, checked in by DHERBOMEZ Gérald, 10 years ago

Integration of new modules:

  • GPS NMEA0183 decoder
  • Span CPT Decoder

Update of:

File size: 4.0 KB
Line 
1#include "nmea0183.h"
2#pragma hdrstop
3
4/*
5** Author: Samuel R. Blackburn
6** Internet: sam_blackburn@pobox.com
7**
8** You can use it any way you like as long as you don't try to sell it.
9**
10** Copyright, 1997, Samuel R. Blackburn
11**
12** $Workfile: lat.cpp $
13** $Revision: 6 $
14** $Modtime: 10/13/98 6:56a $
15*/
16/*
17#ifdef _DEBUG
18#undef THIS_FILE
19static char BASED_CODE THIS_FILE[] = __FILE__;
20#define new DEBUG_NEW
21#endif
22*/
23
24#ifdef _MSC_VER
25# pragma warning(disable:4996)
26#endif // _MSC_VER
27
28LATITUDE::LATITUDE()
29{
30 Empty();
31}
32
33LATITUDE::~LATITUDE()
34{
35 Empty();
36}
37
38void LATITUDE::Empty( void )
39{
40 Latitude = 0.0;
41 Northing = NS_Unknown;
42}
43
44BOOL LATITUDE::IsDataValid( void )
45{
46 if ( Northing != North && Northing != South )
47 {
48 return( FALSE );
49 }
50
51 return( TRUE );
52}
53
54void LATITUDE::Parse( int position_field_number, int north_or_south_field_number, const SENTENCE& sentence )
55{
56 // Thanks go to Eric Parsonage (ericpa@mpx.com.au) for finding a nasty
57 // little bug that used to live here.
58
59 double position = 0.0;
60
61 position = sentence.Double( position_field_number );
62
63 QString north_or_south;
64
65 north_or_south = sentence.Field( north_or_south_field_number );
66
67 Set( position, north_or_south.toLatin1() );
68}
69
70void LATITUDE::Set( double position, const char *north_or_south )
71{
72 Latitude = position;
73 Coordinate = position;
74
75 if ( north_or_south[ 0 ] == 'N' )
76 {
77 Northing = North;
78 }
79 else if ( north_or_south[ 0 ] == 'S' )
80 {
81 Northing = South;
82 }
83 else
84 {
85 Northing = NS_Unknown;
86 }
87}
88
89void LATITUDE::Write( SENTENCE& sentence )
90{
91 char temp_string[ 80 ];
92
93 ::sprintf( temp_string, "%07.2f", Latitude );
94 sentence += temp_string;
95
96 if ( Northing == North )
97 {
98 sentence += "N";
99 }
100 else if ( Northing == South )
101 {
102 sentence += "S";
103 }
104 else
105 {
106 /*
107 ** Thanks to Jan-Erik Eriksson (Jan-Erik.Eriksson@st.se) for
108 ** finding and fixing a bug here
109 */
110
111 sentence += "";
112 }
113}
114
115const LATITUDE& LATITUDE::operator = ( const LATITUDE& source )
116{
117 Latitude = source.Latitude;
118 Northing = source.Northing;
119
120 return( *this );
121}
122
123// COORDINATE stuff
124
125// Coordinates are in the format dddmm.ddd
126// For example, 76 degrees 46.887 minutes would be 7646.887
127
128double COORDINATE::GetDecimalDegrees( void ) const
129{
130 double return_value = 0.0;
131
132 int degrees = (int) ::floor( Coordinate );
133 int minutes = degrees % 100;
134
135 double fractional_minutes = 0.0;
136 double throw_away = 0.0;
137
138 fractional_minutes = ::modf( Coordinate, &throw_away );
139
140 degrees -= minutes;
141 degrees /= 100;
142
143 return_value = degrees;
144 return_value += (double) ( (double) minutes / (double) 60.0 );
145 return_value += (double) ( (double) fractional_minutes / (double) 60.0 );
146
147 return( return_value );
148}
149
150double COORDINATE::GetDecimalMinutes( void ) const
151{
152 double return_value = 0.0;
153
154 int degrees = (int) ::floor( Coordinate );
155 int minutes = degrees % 100;
156
157 double fractional_minutes = 0.0;
158 double throw_away = 0.0;
159
160 fractional_minutes = ::modf( Coordinate, &throw_away );
161
162 return_value = (double) ( (double) minutes );
163 return_value += fractional_minutes;
164
165 return( return_value );
166}
167
168double COORDINATE::GetDecimalSeconds( void ) const
169{
170 double return_value = 0.0;
171
172 double minutes = GetDecimalMinutes();
173
174 double fractional_minutes = 0.0;
175 double throw_away = 0.0;
176
177 fractional_minutes = ::modf( minutes, &throw_away );
178
179 return_value = (double) ( (double) fractional_minutes * (double) 60.0 );
180
181 return( return_value );
182}
183
184int COORDINATE::GetWholeDegrees( void ) const
185{
186 return( (int) ::floor( GetDecimalDegrees() ) );
187}
188
189int COORDINATE::GetWholeMinutes( void ) const
190{
191 return( (int) ::floor( GetDecimalMinutes() ) );
192}
193
194int COORDINATE::GetWholeSeconds( void ) const
195{
196 return( (int) ::floor( GetDecimalSeconds() ) );
197}
Note: See TracBrowser for help on using the repository browser.