forked from SammyB428/NMEA0183
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APB.CPP
173 lines (149 loc) · 5.8 KB
/
APB.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
Author: Samuel R. Blackburn
Internet: [email protected]
"You can get credit for something or get it done, but not both."
Dr. Richard Garwin
The MIT License (MIT)
Copyright (c) 1996-2015 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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "nmea0183.h"
#pragma hdrstop
#if defined( _DEBUG ) && defined( _INC_CRTDBG )
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif // _DEBUG
APB::APB()
{
Mnemonic = "APB";
Empty();
}
APB::~APB()
{
Mnemonic.clear();
Empty();
}
void APB::Empty( void )
{
CrossTrackErrorMagnitude = 0.0;
DirectionToSteer = LR_Unknown;
CrossTrackUnits.clear();
To.clear();
IsArrivalCircleEntered = NMEA_Unknown;
IsPerpendicular = NMEA_Unknown;
}
bool APB::Parse( const SENTENCE& sentence )
{
/*
** APB - Autopilot Sentence "B"
** 13 15
** 1 2 3 4 5 6 7 8 9 10 11 12| 14|
** | | | | | | | | | | | | | | |
** $--APB,A,A,x.x,a,N,A,A,x.x,a,c--c,x.x,a,x.x,a*hh<CR><LF>
**
** 1) Status
** V = LORAN-C Blink or SNR warning
** V = general warning flag or other navigation systems when a reliable
** fix is not available
** 2) Status
** V = Loran-C Cycle Lock warning flag
** A = OK or not used
** 3) Cross Track Error Magnitude
** 4) Direction to steer, L or R
** 5) Cross Track Units, N = Nautical Miles
** 6) Status
** A = Arrival Circle Entered
** 7) Status
** A = Perpendicular passed at waypoint
** 8) Bearing origin to destination
** 9) M = Magnetic, T = True
** 10) Destination Waypoint ID
** 11) Bearing, present position to Destination
** 12) M = Magnetic, T = True
** 13) Heading to steer to destination waypoint
** 14) M = Magnetic, T = True
** 15) Checksum
*/
/*
** First we check the checksum...
*/
if ( sentence.IsChecksumBad( 15 ) == True )
{
SetErrorMessage( "Invalid Checksum" );
return( false );
}
/*
** Line has already been checked for checksum validity
*/
IsLoranBlinkOK = sentence.Boolean( 1 );
IsLoranCCycleLockOK = sentence.Boolean( 2 );
CrossTrackErrorMagnitude = sentence.Double( 3 );
DirectionToSteer = sentence.LeftOrRight( 4 );
CrossTrackUnits = sentence.Field( 5 );
IsArrivalCircleEntered = sentence.Boolean( 6 );
IsPerpendicular = sentence.Boolean( 7 );
BearingOriginToDestination = sentence.Double( 8 );
BearingOriginToDestinationUnits = sentence.Field( 9 );
To = sentence.Field( 10 );
BearingPresentPositionToDestination = sentence.Double( 11 );
BearingPresentPositionToDestinationUnits = sentence.Field( 12 );
HeadingToSteer = sentence.Double( 13 );
HeadingToSteerUnits = sentence.Field( 14 );
return( true );
}
bool APB::Write( SENTENCE& sentence )
{
/*
** Let the parent do its thing
*/
RESPONSE::Write( sentence );
sentence += IsLoranBlinkOK;
sentence += IsLoranCCycleLockOK;
sentence += CrossTrackErrorMagnitude;
sentence += DirectionToSteer;
sentence += CrossTrackUnits;
sentence += IsArrivalCircleEntered;
sentence += IsPerpendicular;
sentence += BearingOriginToDestination;
sentence += BearingOriginToDestinationUnits;
sentence += To;
sentence += BearingPresentPositionToDestination;
sentence += BearingPresentPositionToDestinationUnits;
sentence += HeadingToSteer;
sentence += HeadingToSteerUnits;
sentence.Finish();
return( true );
}
const APB& APB::operator = ( const APB& source )
{
IsLoranBlinkOK = source.IsLoranBlinkOK;
IsLoranCCycleLockOK = source.IsLoranCCycleLockOK;
CrossTrackErrorMagnitude = source.CrossTrackErrorMagnitude;
DirectionToSteer = source.DirectionToSteer;
CrossTrackUnits = source.CrossTrackUnits;
IsArrivalCircleEntered = source.IsArrivalCircleEntered;
IsPerpendicular = source.IsPerpendicular;
BearingOriginToDestination = source.BearingOriginToDestination;
BearingOriginToDestinationUnits = source.BearingOriginToDestinationUnits;
To = source.To;
BearingPresentPositionToDestination = source.BearingPresentPositionToDestination;
BearingPresentPositionToDestinationUnits = source.BearingPresentPositionToDestinationUnits;
HeadingToSteer = source.HeadingToSteer;
HeadingToSteerUnits = source.HeadingToSteerUnits;
return( *this );
}