Goby v2
nmea.cpp
1 // Copyright 2009-2018 Toby Schneider (http://gobysoft.org/index.wt/people/toby)
2 // GobySoft, LLC (2013-)
3 // Massachusetts Institute of Technology (2007-2014)
4 //
5 //
6 // This file is part of the Goby Underwater Autonomy Project Binaries
7 // ("The Goby Binaries").
8 //
9 // The Goby Binaries are free software: you can redistribute them and/or modify
10 // them under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // The Goby Binaries are distributed in the hope that they will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Goby. If not, see <http://www.gnu.org/licenses/>.
21 
22 #include "goby/util/binary.h"
23 #include "goby/util/linebasedcomms.h"
24 
25 int main()
26 {
27  {
29  nmea.push_back("$FOOBA");
30  nmea.push_back(1);
31  nmea.push_back(2);
32  nmea.push_back(3);
33  nmea.push_back("");
34  std::cout << nmea.message() << std::endl;
35  assert(nmea.message() == "$FOOBA,1,2,3,*75");
36  }
37 
38  {
40  nmea.push_back("$CCTXD");
41  nmea.push_back(2);
42  nmea.push_back("1,1");
43  nmea.push_back(goby::util::hex_encode(""));
44  std::cout << nmea.message() << std::endl;
45  assert(nmea.message() == "$CCTXD,2,1,1,*7A");
46  }
47 
48  {
49  goby::util::NMEASentence nmea("$CCTXD,2,1,1*56");
50  assert(nmea.as<int>(3) == 1);
51  assert(nmea.at(3) == "1");
52  }
53 
54  {
55  goby::util::NMEASentence nmea("$YXXDR,A,0.3,D,PTCH,A,13.3,D,ROLL*6f ");
56  std::cout << nmea.message() << std::endl;
57  assert(nmea.at(8) == "ROLL");
58  }
59 
60  {
61  goby::util::NMEASentence nmea("!AIVDO,1,1,,,B0000003wk?8mP=18D3Q3wwUkP06,0*7B");
62  std::cout << nmea.message() << std::endl;
63  assert(nmea.as<int>(1) == 1);
64  assert(nmea.as<int>(2) == 1);
65  }
66 
67  std::cout << "all tests passed" << std::endl;
68 
69  return 0;
70 }