DCCL v4
Loading...
Searching...
No Matches
test.cpp
1// Copyright 2015-2023:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6// Stephanie Petillo <stephanie@gobysoft.org>
7//
8//
9// This file is part of the Dynamic Compact Control Language Library
10// ("DCCL").
11//
12// DCCL is free software: you can redistribute it and/or modify
13// it under the terms of the GNU Lesser General Public License as published by
14// the Free Software Foundation, either version 2.1 of the License, or
15// (at your option) any later version.
16//
17// DCCL is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU Lesser General Public License for more details.
21//
22// You should have received a copy of the GNU Lesser General Public License
23// along with DCCL. If not, see <http://www.gnu.org/licenses/>.
24#include <iomanip>
25#include <iostream>
26
27#include "auv_status.pb.h"
28#include "test.pb.h"
29#include <boost/units/base_units/metric/bar.hpp>
30#include <boost/units/io.hpp>
31#include <boost/units/physical_dimensions/pressure.hpp>
32#include <boost/units/systems/si.hpp>
33#include <boost/units/systems/si/dimensionless.hpp>
34#include <boost/units/systems/si/prefixes.hpp>
35#include <boost/units/systems/si/velocity.hpp>
36#include <boost/units/systems/temperature/celsius.hpp>
37#include <boost/units/systems/temperature/fahrenheit.hpp>
38
39#include <boost/units/base_units/metric/nautical_mile.hpp>
40
41#include "dccl/units/conductivity.h"
42
43int main()
44{
45 CTDTestMessage test_msg;
46
47 using namespace boost::units;
48 using boost::units::metric::bar_base_unit;
49 using boost::units::si::deci;
50
51 typedef bar_base_unit::unit_type Bar;
52 static const Bar bar;
53
54 quantity<Bar> pressure(150.123456789 * si::deci * bar);
55
56 test_msg.set_pressure_with_units(pressure);
57
58 using Kelvin =
59 boost::units::unit<boost::units::temperature_dimension, boost::units::si::system>;
60 quantity<absolute<Kelvin>> temp(15 * absolute<celsius::temperature>());
61 std::cout << temp << std::endl;
62
63 double temp_d = (temp - quantity<absolute<Kelvin>>(0 * absolute<Kelvin>())) / Kelvin();
64 std::cout << temp_d << std::endl;
65
66 test_msg.set_temperature_with_units(15 * absolute<fahrenheit::temperature>());
67 test_msg.set_micro_temp_with_units(15 * Kelvin());
68 test_msg.set_salinity(35.2);
69 test_msg.set_sound_speed(1500);
70
71 quantity<si::velocity> c(1500 * si::meters_per_second);
72 test_msg.set_sound_speed_with_units(c);
73 test_msg.set_depth_with_units(100 * si::meters);
74 quantity<si::velocity> auv_spd(2.5 * si::meters_per_second);
75 test_msg.set_auv_speed_with_units(auv_spd);
76 std::cout << "auv_spd: " << auv_spd << std::endl;
77
78 test_msg.set_conductivity_with_units(45.0 * dccl::units::siemens_per_m);
79
80 test_msg.set_salinity_with_units(38.9 * si::dimensionless());
81
82 std::cout << test_msg.DebugString() << std::endl; //outputs protobuf debug string
83 std::cout << "Temperature: " << test_msg.temperature_with_units() << std::endl;
84 std::cout << "Micro temperature: " << test_msg.micro_temp_with_units() << std::endl;
85 std::cout << std::setprecision(10) << "Pressure: " << test_msg.pressure_with_units()
86 << std::endl;
87 std::cout << "Pressure (as bars): " << quantity<Bar>(test_msg.pressure_with_units())
88 << std::endl;
89 std::cout << "Sound speed: " << test_msg.sound_speed_with_units() << std::endl;
90 std::cout << "AUV speed: " << test_msg.auv_speed_with_units() << std::endl;
91 std::cout << "Salinity: " << test_msg.salinity_with_units() << std::endl;
92
93 assert(test_msg.conductivity() == 450000); // uS/cm
94
95 AUVStatus status;
96 status.set_x_with_units(1000 * si::meters);
97 status.set_y_with_units(500 * si::meters);
98 status.set_heading_with_units(3.1415926535 / 2 * si::radians);
99
100 using NauticalMile = metric::nautical_mile_base_unit::unit_type;
101 quantity<NauticalMile> x_nm(status.x_with_units());
102 quantity<NauticalMile> y_nm(status.y_with_units());
103
104 std::cout << status.DebugString() << std::endl;
105 std::cout << x_nm << std::endl;
106 std::cout << y_nm << std::endl;
107 std::cout << status.heading_with_units() << std::endl;
108
109 Parent p;
110 p.set_mass_with_units(2 * si::kilograms);
111 p.set_si_mass_with_units(10 * si::kilograms);
112 p.mutable_child()->set_length_with_units(5 * si::meters);
113
114 assert(p.mass() == 2000); // grams
115 assert(p.si_mass() == 10); // kilograms
116 assert(p.child().length() == 500); // centimeters
117
118 std::cout << "all tests passed" << std::endl;
119}