1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  NMEA0183 Support Classes
5  * Author:   Samuel R. Blackburn, David S. Register
6  *
7  ***************************************************************************
8  *   Copyright (C) 2010 by Samuel R. Blackburn, David S Register           *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc.,                                       *
23  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.             *
24  ***************************************************************************
25  *
26  *   S Blackburn's original source license:                                *
27  *         "You can use it any way you like."                              *
28  *   More recent (2010) license statement:                                 *
29  *         "It is BSD license, do with it what you will"                   *
30  */
31 
32 
33 #include "nmea0183.h"
34 
35 /*
36 ** Author: Samuel R. Blackburn
37 ** CI$: 76300,326
38 ** Internet: sammy@sed.csc.com
39 **
40 ** You can use it any way you like.
41 */
42 
43 //IMPLEMENT_DYNAMIC( WPL, RESPONSE )
44 
WPL()45 WPL::WPL()
46 {
47    Mnemonic = _T("WPL");
48    Empty();
49 }
50 
~WPL()51 WPL::~WPL()
52 {
53    Mnemonic.Empty();
54    Empty();
55 }
56 
Empty(void)57 void WPL::Empty( void )
58 {
59 
60    Position.Empty();
61    To.Empty();
62 }
63 
Parse(const SENTENCE & sentence)64 bool WPL::Parse( const SENTENCE& sentence )
65 {
66 
67    /*
68    ** WPL - Waypoint Location
69    **
70    **        +-------------------------------- 1) Latitude
71    **        |       +------------------------ 2) N or S (North or South)
72    **        |       | +---------------------- 3) Longitude
73    **        |       | |        +------------- 4) E or W (East or West)
74    **        |       | |        | +----------- 5) Waypoint name
75    **        |       | |        | |    +-------6) Checksum
76    **        |       | |        | |    |
77    ** $--WPL,llll.ll,a,yyyyy.yy,a,c--c*hh<CR><LF>
78    */
79 
80    /*
81    ** First we check the checksum...
82    */
83 
84    if ( sentence.IsChecksumBad( 6 ) == NTrue )
85    {
86       SetErrorMessage( _T("Invalid Checksum") );
87       return( FALSE );
88    }
89 
90    Position.Parse( 1, 2, 3, 4, sentence );
91    To = sentence.Field( 5 );
92 
93    return( TRUE );
94 }
95 
Write(SENTENCE & sentence)96 bool WPL::Write( SENTENCE& sentence )
97 {
98    /*
99    ** Let the parent do its thing
100    */
101 
102    RESPONSE::Write( sentence );
103 
104    sentence += Position;
105    sentence += To;
106 
107    sentence.Finish();
108 
109    return( TRUE );
110 }
111 
operator =(const WPL & source)112 const WPL& WPL::operator = ( const WPL& source )
113 {
114 
115    Position = source.Position;
116    To       = source.To;
117 
118    return( *this );
119 }
120