[59] | 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, 1996, Samuel R. Blackburn
|
---|
| 11 | **
|
---|
| 12 | ** $Workfile: xdr.cpp $
|
---|
| 13 | ** $Revision: 4 $
|
---|
| 14 | ** $Modtime: 10/10/98 4:20p $
|
---|
| 15 | */
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | XDR::XDR()
|
---|
| 20 | {
|
---|
| 21 | Mnemonic = "XDR";
|
---|
| 22 | Empty();
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | XDR::~XDR()
|
---|
| 26 | {
|
---|
| 27 | //Mnemonic.Empty();
|
---|
| 28 | Empty();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | void XDR::Empty( void )
|
---|
| 32 | {
|
---|
| 33 | delete_all_entries();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | BOOL XDR::Parse( const SENTENCE& sentence )
|
---|
| 37 | {
|
---|
| 38 | /*
|
---|
| 39 | ** XDR - Cross Track Error - Dead Reckoning
|
---|
| 40 | **
|
---|
| 41 | ** 1 2 3 4 n
|
---|
| 42 | ** | | | | |
|
---|
| 43 | ** $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF>
|
---|
| 44 | **
|
---|
| 45 | ** Field Number:
|
---|
| 46 | ** 1) Transducer Type
|
---|
| 47 | ** 2) Measurement Data
|
---|
| 48 | ** 3) Units of measurement
|
---|
| 49 | ** 4) Name of transducer
|
---|
| 50 | ** x) More of the same
|
---|
| 51 | ** n) Checksum
|
---|
| 52 | */
|
---|
| 53 |
|
---|
| 54 | delete_all_entries();
|
---|
| 55 |
|
---|
| 56 | int field_number = 1;
|
---|
| 57 |
|
---|
| 58 | TRANSDUCER_DATA *transducer_data_p = (TRANSDUCER_DATA *) NULL;
|
---|
| 59 |
|
---|
| 60 | while( sentence.Field( field_number + 1 ) != "" )
|
---|
| 61 | {
|
---|
| 62 | transducer_data_p = new TRANSDUCER_DATA;
|
---|
| 63 |
|
---|
| 64 | transducer_data_p->Parse( field_number, sentence );
|
---|
| 65 | //Transducers.Add( transducer_data_p );
|
---|
| 66 | Transducers.resize(Transducers.size()+1);
|
---|
| 67 | Transducers.insert( Transducers.size(),transducer_data_p );
|
---|
| 68 |
|
---|
| 69 | field_number += 4;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | return( TRUE );
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | BOOL XDR::Write( SENTENCE& sentence )
|
---|
| 76 | {
|
---|
| 77 | /*
|
---|
| 78 | ** Let the parent do its thing
|
---|
| 79 | */
|
---|
| 80 |
|
---|
| 81 | RESPONSE::Write( sentence );
|
---|
| 82 |
|
---|
| 83 | int index = 0;
|
---|
| 84 | int number_of_entries = Transducers.size();
|
---|
| 85 |
|
---|
| 86 | while( index < number_of_entries )
|
---|
| 87 | {
|
---|
| 88 | ( (TRANSDUCER_DATA *) Transducers[ index ] )->Write( sentence );
|
---|
| 89 | index++;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | sentence.Finish();
|
---|
| 93 |
|
---|
| 94 | return( TRUE );
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void XDR::delete_all_entries( void )
|
---|
| 98 | {
|
---|
| 99 | int loop_index = 0;
|
---|
| 100 | int number_of_entries = Transducers.size();
|
---|
| 101 |
|
---|
| 102 | TRANSDUCER_DATA * data_p = (TRANSDUCER_DATA *) NULL;
|
---|
| 103 |
|
---|
| 104 | /*while( loop_index < number_of_entries )
|
---|
| 105 | {
|
---|
| 106 | data_p = (TRANSDUCER_DATA *) Transducers[ loop_index ];
|
---|
| 107 | Transducers[ loop_index ] = NULL;
|
---|
| 108 | delete data_p;
|
---|
| 109 | loop_index++;
|
---|
| 110 | }*/
|
---|
| 111 |
|
---|
| 112 | Transducers.clear();
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | TRANSDUCER_DATA::TRANSDUCER_DATA()
|
---|
| 116 | {
|
---|
| 117 | Empty();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | TRANSDUCER_DATA::~TRANSDUCER_DATA()
|
---|
| 121 | {
|
---|
| 122 | Empty();
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | void TRANSDUCER_DATA::Empty( void )
|
---|
| 126 | {
|
---|
| 127 | TransducerType = TransducerUnknown;
|
---|
| 128 | MeasurementData = 0.0;
|
---|
| 129 | //MeasurementUnits.Empty();
|
---|
| 130 | //TransducerName.Empty();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void TRANSDUCER_DATA::Parse( int first_field_number, const SENTENCE& sentence )
|
---|
| 134 | {
|
---|
| 135 | TransducerType = sentence.TransducerType( first_field_number );
|
---|
| 136 | MeasurementData = sentence.Double( first_field_number + 1 );
|
---|
| 137 | MeasurementUnits = sentence.Field( first_field_number + 2 );
|
---|
| 138 | TransducerName = sentence.Field( first_field_number + 3 );
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | void TRANSDUCER_DATA::Write( SENTENCE& sentence )
|
---|
| 142 | {
|
---|
| 143 | sentence += TransducerType;
|
---|
| 144 | sentence += MeasurementData;
|
---|
| 145 | sentence += MeasurementUnits;
|
---|
| 146 | sentence += TransducerName;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | const TRANSDUCER_DATA& TRANSDUCER_DATA::operator = ( const TRANSDUCER_DATA& source )
|
---|
| 150 | {
|
---|
| 151 | TransducerType = source.TransducerType;
|
---|
| 152 | MeasurementData = source.MeasurementData;
|
---|
| 153 | MeasurementUnits = source.MeasurementUnits;
|
---|
| 154 | TransducerName = source.TransducerName;
|
---|
| 155 |
|
---|
| 156 | return( *this );
|
---|
| 157 | }
|
---|