Goby v2
two_message.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/acomms/acomms_helpers.h" // for operator<< of google::protobuf::Message
23 #include "goby/acomms/dccl.h"
24 #include "goby/util/binary.h"
25 
26 #include "two_message.pb.h"
27 #include <exception>
28 #include <iostream>
29 
30 using namespace goby;
31 using goby::acomms::operator<<;
32 
33 int main()
34 {
36 
37  // validate the Simple protobuf message type as a valid DCCL message type
38  dccl.validate<GoToCommand>();
39  dccl.validate<VehicleStatus>();
40 
41  // show some useful information about all the loaded messages
42  std::cout << dccl << std::endl;
43 
44  std::cout << "ENCODE / DECODE example:" << std::endl;
45 
46  GoToCommand command;
47  command.set_destination(2);
48  command.set_goto_x(423);
49  command.set_goto_y(523);
50  command.set_lights_on(true);
51  command.set_new_instructions("make_toast");
52  command.set_goto_speed(2.3456);
53 
54  VehicleStatus status;
55  status.set_nav_x(234.5);
56  status.set_nav_y(451.3);
57  status.set_health(VehicleStatus::HEALTH_ABORT);
58 
59  std::cout << "passing values to encoder:\n" << command << "\n" << status << std::endl;
60 
61  std::string bytes2, bytes3;
62  dccl.encode(&bytes2, command);
63  dccl.encode(&bytes3, status);
64 
65  std::cout << "received hexadecimal string for message 2 (GoToCommand): "
66  << goby::util::hex_encode(bytes2) << std::endl;
67 
68  std::cout << "received hexadecimal string for message 3 (VehicleStatus): "
69  << goby::util::hex_encode(bytes3) << std::endl;
70 
71  command.Clear();
72  status.Clear();
73 
74  std::cout << "passed hexadecimal string for message 2 to decoder: "
75  << goby::util::hex_encode(bytes2) << std::endl;
76 
77  std::cout << "passed hexadecimal string for message 3 to decoder: "
78  << goby::util::hex_encode(bytes3) << std::endl;
79 
80  dccl.decode(bytes2, &command);
81  dccl.decode(bytes3, &status);
82 
83  std::cout << "received values:\n" << command << "\n" << status << std::endl;
84 
85  return 0;
86 }
static DCCLCodec * get()
DCCLCodec is a singleton class; use this to get a pointer to the class.
Definition: dccl.h:124
The global namespace for the Goby project.