Add property for manager hostname
This commit is contained in:
parent
ad4bb45951
commit
f8d769ebc6
2 changed files with 28 additions and 1 deletions
|
|
@ -6,7 +6,9 @@
|
||||||
#include "godot_cpp/classes/packet_peer_udp.hpp"
|
#include "godot_cpp/classes/packet_peer_udp.hpp"
|
||||||
#include "godot_cpp/core/math.hpp"
|
#include "godot_cpp/core/math.hpp"
|
||||||
#include "godot_cpp/core/memory.hpp"
|
#include "godot_cpp/core/memory.hpp"
|
||||||
|
#include "godot_cpp/core/object.hpp"
|
||||||
#include "godot_cpp/core/print_string.hpp"
|
#include "godot_cpp/core/print_string.hpp"
|
||||||
|
#include "godot_cpp/core/property_info.hpp"
|
||||||
#include "godot_cpp/variant/basis.hpp"
|
#include "godot_cpp/variant/basis.hpp"
|
||||||
#include "godot_cpp/variant/packed_byte_array.hpp"
|
#include "godot_cpp/variant/packed_byte_array.hpp"
|
||||||
#include "godot_cpp/variant/quaternion.hpp"
|
#include "godot_cpp/variant/quaternion.hpp"
|
||||||
|
|
@ -34,6 +36,13 @@ void MarshConnector::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_manager_connected"),
|
ClassDB::bind_method(D_METHOD("get_manager_connected"),
|
||||||
&MarshConnector::get_manager_connected);
|
&MarshConnector::get_manager_connected);
|
||||||
|
|
||||||
|
// Properties
|
||||||
|
ClassDB::bind_method(D_METHOD("get_hostname"), &MarshConnector::get_hostname);
|
||||||
|
ClassDB::bind_method(D_METHOD("set_hostname", "p_hostname"),
|
||||||
|
&MarshConnector::set_hostname);
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "hostname"), "set_hostname",
|
||||||
|
"get_hostname");
|
||||||
|
|
||||||
// Timer callbacks
|
// Timer callbacks
|
||||||
ClassDB::bind_method(D_METHOD("send_heartbeat"),
|
ClassDB::bind_method(D_METHOD("send_heartbeat"),
|
||||||
&MarshConnector::send_heartbeat);
|
&MarshConnector::send_heartbeat);
|
||||||
|
|
@ -56,6 +65,7 @@ MarshConnector::MarshConnector() {
|
||||||
|
|
||||||
socket = memnew(PacketPeerUDP);
|
socket = memnew(PacketPeerUDP);
|
||||||
|
|
||||||
|
manager_hostname = "127.0.0.1";
|
||||||
manager_connected = false;
|
manager_connected = false;
|
||||||
|
|
||||||
manager_timer = memnew(Timer);
|
manager_timer = memnew(Timer);
|
||||||
|
|
@ -85,7 +95,7 @@ void MarshConnector::_process(double delta) {
|
||||||
time_passed += delta;
|
time_passed += delta;
|
||||||
|
|
||||||
if (!socket->is_socket_connected()) {
|
if (!socket->is_socket_connected()) {
|
||||||
socket->connect_to_host("192.168.1.2", 24400);
|
socket->connect_to_host(manager_hostname, 24400);
|
||||||
} else {
|
} else {
|
||||||
while (socket->get_available_packet_count() > 0) {
|
while (socket->get_available_packet_count() > 0) {
|
||||||
const PackedByteArray data = socket->get_packet();
|
const PackedByteArray data = socket->get_packet();
|
||||||
|
|
@ -94,6 +104,19 @@ void MarshConnector::_process(double delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String MarshConnector::get_hostname() const { return manager_hostname; }
|
||||||
|
|
||||||
|
void MarshConnector::set_hostname(const String hostname) {
|
||||||
|
// Socket's destination address is not available, so discard useless updates
|
||||||
|
// and recreate socket when needed
|
||||||
|
if (hostname == manager_hostname)
|
||||||
|
return;
|
||||||
|
|
||||||
|
manager_hostname = hostname;
|
||||||
|
if (socket->is_socket_connected())
|
||||||
|
socket->close();
|
||||||
|
}
|
||||||
|
|
||||||
Error MarshConnector::send_heartbeat() {
|
Error MarshConnector::send_heartbeat() {
|
||||||
// print_line("Sending HEARTBEAT at ", time_passed, " seconds");
|
// print_line("Sending HEARTBEAT at ", time_passed, " seconds");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ public:
|
||||||
void _ready() override;
|
void _ready() override;
|
||||||
void _process(double delta) override;
|
void _process(double delta) override;
|
||||||
|
|
||||||
|
void set_hostname(const String hostname);
|
||||||
|
String get_hostname() const;
|
||||||
|
|
||||||
// Returns the error from put_packet
|
// Returns the error from put_packet
|
||||||
Error send_heartbeat();
|
Error send_heartbeat();
|
||||||
// Handle MAVLink messages fully contained in data
|
// Handle MAVLink messages fully contained in data
|
||||||
|
|
@ -109,6 +112,7 @@ private:
|
||||||
Timer *heartbeat_timer;
|
Timer *heartbeat_timer;
|
||||||
PacketPeerUDP *socket;
|
PacketPeerUDP *socket;
|
||||||
|
|
||||||
|
String manager_hostname;
|
||||||
bool manager_connected;
|
bool manager_connected;
|
||||||
Timer *manager_timer;
|
Timer *manager_timer;
|
||||||
bool model_connected;
|
bool model_connected;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue