dcn.cpp

来自「提取各种NEMA0183格式数据的类编程。」· C++ 代码 · 共 216 行

CPP
216
字号
/*
** Author: Samuel R. Blackburn
** Internet: wfc@pobox.com
**
** Copyright, 1996-2005, Samuel R. Blackburn
**
** "You can get credit for something or get it done, but not both."
** Dr. Richard Garwin
**
** BSD License follows.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions
** are met:
**
** Redistributions of source code must retain the above copyright notice,
** this list of conditions and the following disclaimer. Redistributions
** in binary form must reproduce the above copyright notice, this list
** of conditions and the following disclaimer in the documentation and/or
** other materials provided with the distribution. Neither the name of
** the WFC nor the names of its contributors may be used to endorse or
** promote products derived from this software without specific prior
** written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** $Workfile: dcn.cpp $
** $Revision: 5 $
** $Modtime: 10/10/98 2:46p $
*/

#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

DCN::DCN()
{
   Mnemonic = TEXT( "DCN" );
   Empty();
}

DCN::~DCN()
{
   Mnemonic.Empty();
   Empty();
}

void DCN::Empty( void )
{
   DeccaChainID                     = 0;
   Red.Empty();
   Green.Empty();
   Purple.Empty();
   RedLineNavigationUse             = NMEA_Unknown;
   GreenLineNavigationUse           = NMEA_Unknown;
   PurpleLineNavigationUse          = NMEA_Unknown;
   PositionUncertaintyNauticalMiles = 0.0;
   Basis                            = BasisUnknown;
}

BOOL DCN::Parse( const SENTENCE& sentence )
{
   /*
   ** DCN - Decca Position
   **                                      11  13      16
   **        1  2  3   4 5  6   7 8  9   10| 12| 14  15| 17
   **        |  |  |   | |  |   | |  |   | | | | |   | | |
   ** $--DCN,xx,cc,x.x,A,cc,x.x,A,cc,x.x,A,A,A,A,x.x,N,x*hh<CR><LF>
   **
   **  1) Decca chain identifier
   **  2) Red Zone Identifier
   **  3) Red Line Of Position
   **  4) Red Master Line Status
   **  5) Green Zone Identifier
   **  6) Green Line Of Position
   **  7) Green Master Line Status
   **  8) Purple Zone Identifier
   **  9) Purple Line Of Position
   ** 10) Purple Master Line Status
   ** 11) Red Line Navigation Use
   ** 12) Green Line Navigation Use
   ** 13) Purple Line Navigation Use
   ** 14) Position Uncertainity
   ** 15) N = Nautical Miles
   ** 16) Fix Data Basis
   **     1 = Normal Pattern
   **     2 = Lane Identification Pattern
   **     3 = Lane Identification Transmissions
   ** 17) Checksum
   */

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

   const NMEA0183_BOOLEAN checksum_is_bad = sentence.IsChecksumBad();

   if ( checksum_is_bad == True )
   {
      InvalidChecksum();
      return( FALSE );
   } 

   DeccaChainID                     = sentence.Integer( 1 );
   Red.Parse( 2, sentence );
   Green.Parse( 5, sentence );
   Purple.Parse( 8, sentence );
   RedLineNavigationUse             = sentence.Boolean( 11 );
   GreenLineNavigationUse           = sentence.Boolean( 12 );
   PurpleLineNavigationUse          = sentence.Boolean( 13 );
   PositionUncertaintyNauticalMiles = sentence.Double( 14 );

   int temp_integer = sentence.Integer( 16 );

   switch( temp_integer )
   {
      case 1:

         Basis = NormalPatternBasis;
         break;

      case 2:

         Basis = LaneIdentificationPatternBasis;
         break;

      case 3:

         Basis = LaneIdentificationTransmissionsBasis;
         break;

      default:

         Basis = BasisUnknown;
         break;
   }

   return( TRUE );
}

BOOL DCN::Write( SENTENCE& sentence )
{
   /*
   ** Let the parent do its thing
   */
   
   RESPONSE::Write( sentence );

   sentence += DeccaChainID;
   Red.Write( sentence );
   Green.Write( sentence );
   Purple.Write( sentence );
   sentence += RedLineNavigationUse;
   sentence += GreenLineNavigationUse;
   sentence += PurpleLineNavigationUse;
   sentence += PositionUncertaintyNauticalMiles;
   sentence += TEXT( "N" );

   switch( Basis )
   {
      case NormalPatternBasis:

         sentence += 1;
         break;

      case LaneIdentificationPatternBasis:

         sentence += 2;
         break;

      case LaneIdentificationTransmissionsBasis:

         sentence += 3;
         break;

      default:

         sentence += "";
         break;
   }

   sentence.Finish();

   return( TRUE );
}

const DCN& DCN::operator = ( const DCN& source )
{
   DeccaChainID                     = source.DeccaChainID;
   Red                              = source.Red;
   Green                            = source.Green;
   Purple                           = source.Purple;
   RedLineNavigationUse             = source.RedLineNavigationUse;
   GreenLineNavigationUse           = source.GreenLineNavigationUse;
   PurpleLineNavigationUse          = source.PurpleLineNavigationUse;
   PositionUncertaintyNauticalMiles = source.PositionUncertaintyNauticalMiles;
   Basis                            = source.Basis;
   
   return( *this );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?