Line | Branch | Exec | Source |
---|---|---|---|
1 | // This file is part of INSTINCT, the INS Toolkit for Integrated | ||
2 | // Navigation Concepts and Training by the Institute of Navigation of | ||
3 | // the University of Stuttgart, Germany. | ||
4 | // | ||
5 | // This Source Code Form is subject to the terms of the Mozilla Public | ||
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
7 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
8 | |||
9 | #include "udpSend.hpp" | ||
10 | |||
11 | #include "internal/NodeManager.hpp" | ||
12 | namespace nm = NAV::NodeManager; | ||
13 | #include "internal/FlowManager.hpp" | ||
14 | |||
15 | #include "internal/gui/widgets/imgui_ex.hpp" | ||
16 | #include "internal/gui/widgets/HelpMarker.hpp" | ||
17 | #include "internal/gui/NodeEditorApplication.hpp" | ||
18 | |||
19 | #include "util/Logger.hpp" | ||
20 | |||
21 | 112 | NAV::UdpSend::UdpSend() | |
22 |
6/12✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 112 times.
✗ Branch 9 not taken.
✓ Branch 13 taken 112 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 112 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 112 times.
✗ Branch 20 not taken.
|
112 | : Node(typeStatic()), _socket(_io_context, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), 0)), _resolver(_io_context) |
23 | { | ||
24 | LOG_TRACE("{}: called", name); | ||
25 | |||
26 | 112 | _hasConfig = true; | |
27 | 112 | _guiConfigDefaultWindowSize = { 202, 96 }; | |
28 | |||
29 |
4/8✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 112 times.
✓ Branch 9 taken 112 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
|
336 | nm::CreateInputPin(this, "PosVelAtt", Pin::Type::Flow, { NAV::PosVelAtt::type() }, &UdpSend::receivePosVelAtt); |
30 | 224 | } | |
31 | |||
32 | 224 | NAV::UdpSend::~UdpSend() | |
33 | { | ||
34 | LOG_TRACE("{}: called", nameId()); | ||
35 | 224 | } | |
36 | |||
37 | 224 | std::string NAV::UdpSend::typeStatic() | |
38 | { | ||
39 |
1/2✓ Branch 1 taken 224 times.
✗ Branch 2 not taken.
|
448 | return "UdpSend"; |
40 | } | ||
41 | |||
42 | ✗ | std::string NAV::UdpSend::type() const | |
43 | { | ||
44 | ✗ | return typeStatic(); | |
45 | } | ||
46 | |||
47 | 112 | std::string NAV::UdpSend::category() | |
48 | { | ||
49 |
1/2✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
|
224 | return "Data Link"; |
50 | } | ||
51 | |||
52 | ✗ | void NAV::UdpSend::guiConfig() | |
53 | { | ||
54 | ✗ | ImGui::SetNextItemWidth(150 * gui::NodeEditorApplication::windowFontRatio()); | |
55 | ✗ | if (ImGui::InputInt4L(fmt::format("IPv4##{}", size_t(id)).c_str(), _ip.data(), IP_LIMITS[0], IP_LIMITS[1])) | |
56 | { | ||
57 | ✗ | flow::ApplyChanges(); | |
58 | } | ||
59 | ✗ | ImGui::SetNextItemWidth(150 * gui::NodeEditorApplication::windowFontRatio()); | |
60 | ✗ | if (ImGui::InputIntL(fmt::format("Port##{}", size_t(id)).c_str(), &_port, PORT_LIMITS[0], PORT_LIMITS[1])) | |
61 | { | ||
62 | ✗ | flow::ApplyChanges(); | |
63 | } | ||
64 | ✗ | } | |
65 | |||
66 | ✗ | bool NAV::UdpSend::resetNode() | |
67 | { | ||
68 | ✗ | return true; | |
69 | } | ||
70 | |||
71 | ✗ | json NAV::UdpSend::save() const | |
72 | { | ||
73 | LOG_TRACE("{}: called", nameId()); | ||
74 | |||
75 | ✗ | json j; | |
76 | |||
77 | ✗ | j["ip"] = _ip; | |
78 | ✗ | j["port"] = _port; | |
79 | |||
80 | ✗ | return j; | |
81 | ✗ | } | |
82 | |||
83 | ✗ | void NAV::UdpSend::restore(json const& j) | |
84 | { | ||
85 | LOG_TRACE("{}: called", nameId()); | ||
86 | ✗ | if (j.contains("ip")) | |
87 | { | ||
88 | ✗ | j.at("ip").get_to(_ip); | |
89 | } | ||
90 | ✗ | if (j.contains("port")) | |
91 | { | ||
92 | ✗ | j.at("port").get_to(_port); | |
93 | } | ||
94 | ✗ | } | |
95 | |||
96 | ✗ | bool NAV::UdpSend::initialize() | |
97 | { | ||
98 | LOG_TRACE("{}: called", nameId()); | ||
99 | |||
100 | ✗ | std::string ipString{}; | |
101 | ✗ | for (size_t i = 0; i < 4; i++) | |
102 | { | ||
103 | ✗ | ipString.append(std::to_string(_ip.at(i))); | |
104 | ✗ | i < 3 ? ipString.append(".") : ipString.append(""); | |
105 | } | ||
106 | |||
107 | ✗ | _endpoints = _resolver.resolve(boost::asio::ip::udp::v4(), ipString, std::to_string(_port)); | |
108 | |||
109 | ✗ | return true; | |
110 | ✗ | } | |
111 | |||
112 | ✗ | void NAV::UdpSend::deinitialize() | |
113 | { | ||
114 | ✗ | _io_context.stop(); | |
115 | |||
116 | LOG_TRACE("{}: called", nameId()); | ||
117 | ✗ | } | |
118 | |||
119 | ✗ | void NAV::UdpSend::receivePosVelAtt(NAV::InputPin::NodeDataQueue& queue, size_t /* pinIdx */) | |
120 | { | ||
121 | ✗ | auto posVelAtt = std::make_shared<PosVelAtt>(*std::static_pointer_cast<const PosVelAtt>(queue.extract_front())); | |
122 | |||
123 | ✗ | Eigen::Vector3d posLLA = posVelAtt->lla_position(); | |
124 | ✗ | Eigen::Vector3d vel_n = posVelAtt->n_velocity(); | |
125 | ✗ | Eigen::Vector4d n_Quat_b = { posVelAtt->n_Quat_b().x(), posVelAtt->n_Quat_b().y(), posVelAtt->n_Quat_b().z(), posVelAtt->n_Quat_b().w() }; | |
126 | ✗ | auto timeStamp = posVelAtt->insTime.toGPSweekTow(); | |
127 | ✗ | auto gpsC = timeStamp.gpsCycle; | |
128 | ✗ | auto gpsW = timeStamp.gpsWeek; | |
129 | ✗ | auto gpsT = timeStamp.tow; | |
130 | |||
131 | ✗ | std::vector<double> udp_posVelAtt{ posLLA(0), posLLA(1), posLLA(2), vel_n(0), vel_n(1), vel_n(2), n_Quat_b(0), n_Quat_b(1), n_Quat_b(2), n_Quat_b(3), static_cast<double>(gpsC), static_cast<double>(gpsW), static_cast<double>(gpsT) }; | |
132 | |||
133 | ✗ | _socket.send_to(boost::asio::buffer(udp_posVelAtt), *_endpoints.begin()); | |
134 | ✗ | } | |
135 |