mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-27 01:50:34 +08:00
feat(mavlink): add configurable partner IP for ethernet links (#29412)
* feat(mavlink): add configurable partner IP for ethernet links
Ethernet-configured MAVLink instances always learned their partner's
address from the first received UDP packet, with no way to target a
known, fixed peer.
Add a per-instance MAV_${i}_REMOTE_IP parameter, decoded the same way
as the existing UDP port parameters. A value of 0 (the default) keeps
the existing auto-discovery behaviour unchanged; any other value pins
the instance's target address for the lifetime of the mavlink task,
bypassing both discovery and the discovery-based client replacement
on timeout.
Signed-off-by: henrykotze <henry.kotze1996@gmail.com>
Assisted-by: Claude:claude-sonnet-5
* chore(mavlink): verbose partner ip param definition
* fix(mavlink): report partner IP status on ethernet-capable NuttX boards
display_status() gated the "partner IP" line behind __PX4_POSIX, so it
only ever printed in SITL. get_client_source_initialized() and
_src_addr are populated under the broader MAVLINK_UDP guard
(CONFIG_NET || __PX4_POSIX), so real flight controllers with hardware
Ethernet (CONFIG_NET) never showed the configured/discovered partner
address in `mavlink status`, even though the feature works there too.
Move the print under the existing Protocol::UDP case (already scoped
by MAVLINK_UDP) instead of the narrower POSIX-only guard.
Assisted-by: Claude:claude-sonnet-5
Signed-off-by: henrykotze <henry.kotze1996@gmail.com>
* fix(mavlink): accept literal IPs again for -t partner address
Check for the "p:" prefix explicitly: resolve through the parameter
only when it's present, and fall back to inet_aton directly on the
raw argument otherwise, matching the pre-existing behavior.
Assisted-by: Claude:claude-sonnet-5
* chore(mavlink): Improved parameter description
- reduces flash usage
* chore(mavlink): document p:<param_name> form for -t partner IP
The -t option's usage text only showed a literal-IP example
("127.0.0.1"), with no indication it also accepts p:<param_name>
Assisted-by: Claude:claude-sonnet-5
---------
Signed-off-by: henrykotze <henry.kotze1996@gmail.com>
This commit is contained in:
1 parent
443cca4482
commit
7bf5ce950a
2 files changed
+34
-7
No files matched your search
@@ -2482,7 +2482,17 @@ Mavlink::task_main(int argc, char *argv[])
|
||||
case 't':
|
||||
_src_addr.sin_family = AF_INET;
|
||||
|
||||
if (inet_aton(myoptarg, &_src_addr.sin_addr)) {
|
||||
if (strncmp(myoptarg, "p:", 2) == 0) {
|
||||
if (px4_get_parameter_value(myoptarg, temp_int_arg) != 0) {
|
||||
PX4_ERR("invalid partner ip");
|
||||
err_flag = true;
|
||||
|
||||
} else {
|
||||
_src_addr.sin_addr.s_addr = htonl(static_cast<uint32_t>(temp_int_arg));
|
||||
_src_addr_initialized = true;
|
||||
}
|
||||
|
||||
} else if (inet_aton(myoptarg, &_src_addr.sin_addr)) {
|
||||
_src_addr_initialized = true;
|
||||
|
||||
} else {
|
||||
@@ -3643,16 +3653,14 @@ Mavlink::display_status()
|
||||
printf("UDP (%hu, remote port: %hu)\n", _network_port, _remote_port);
|
||||
printf("\tBroadcast enabled: %s\n",
|
||||
broadcast_enabled() ? "YES" : "NO");
|
||||
#if defined(CONFIG_NET_IGMP) && defined(CONFIG_NET_ROUTE)
|
||||
printf("\tMulticast enabled: %s\n",
|
||||
multicast_enabled() ? "YES" : "NO");
|
||||
#endif
|
||||
#ifdef __PX4_POSIX
|
||||
|
||||
if (get_client_source_initialized()) {
|
||||
printf("\tpartner IP: %s\n", inet_ntoa(get_client_source_address().sin_addr));
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_IGMP) && defined(CONFIG_NET_ROUTE)
|
||||
printf("\tMulticast enabled: %s\n",
|
||||
multicast_enabled() ? "YES" : "NO");
|
||||
#endif
|
||||
break;
|
||||
#endif // MAVLINK_UDP
|
||||
@@ -4006,7 +4014,8 @@ $ mavlink stream -u 14556 -s HIGHRES_IMU -r 50
|
||||
PRINT_MODULE_USAGE_PARAM_FLAG('p', "Enable Broadcast", true);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('u', 14556, 0, 65536, "Select UDP Network Port (local)", true);
|
||||
PRINT_MODULE_USAGE_PARAM_INT('o', 14550, 0, 65536, "Select UDP Network Port (remote)", true);
|
||||
PRINT_MODULE_USAGE_PARAM_STRING('t', "127.0.0.1", nullptr, "Partner IP (broadcasting can be enabled via -p flag)", true);
|
||||
PRINT_MODULE_USAGE_PARAM_STRING('t', "127.0.0.1", nullptr,
|
||||
"Partner IP, can also be p:<param_name> (broadcasting can be enabled via -p flag)", true);
|
||||
#endif
|
||||
PRINT_MODULE_USAGE_PARAM_STRING('m', "normal", "custom|camera|onboard|osd|magic|config|iridium|minimal|extvision|extvisionmin|gimbal|onboard_low_bandwidth|uavionix|low_bandwidth|distance_sensor",
|
||||
"Mode: sets default streams and rates", true);
|
||||
|
||||
@@ -7,6 +7,10 @@ serial_config:
|
||||
set MAV_ARGS "-d ${SERIAL_DEV} -b p:${BAUD_PARAM} -m p:MAV_${i}_MODE -r p:MAV_${i}_RATE"
|
||||
else
|
||||
set MAV_ARGS "-u p:MAV_${i}_UDP_PRT -o p:MAV_${i}_REMOTE_PRT -m p:MAV_${i}_MODE -r p:MAV_${i}_RATE"
|
||||
if ! param compare MAV_${i}_REMOTE_IP 0
|
||||
then
|
||||
set MAV_ARGS "${MAV_ARGS} -t p:MAV_${i}_REMOTE_IP"
|
||||
fi
|
||||
if param compare MAV_${i}_BROADCAST 1
|
||||
then
|
||||
set MAV_ARGS "${MAV_ARGS} -p"
|
||||
@@ -160,6 +164,20 @@ parameters:
|
||||
default: [14550, 0, 0]
|
||||
requires_ethernet: true
|
||||
|
||||
MAV_${i}_REMOTE_IP:
|
||||
description:
|
||||
short: MAVLink Partner IP for instance ${i}
|
||||
long: |
|
||||
Messages go to this address at port MAV_${i}_REMOTE_PRT. Encoded as int32
|
||||
with the first octet in the most significant byte, e.g. 192.168.1.2 is -1062731518.
|
||||
Set to 0 to discover the partner from received packets.
|
||||
|
||||
type: int32
|
||||
reboot_required: true
|
||||
num_instances: *max_num_config_instances
|
||||
default: [0, 0, 0]
|
||||
requires_ethernet: true
|
||||
|
||||
MAV_${i}_BROADCAST:
|
||||
description:
|
||||
short: Broadcast heartbeats on local network for MAVLink instance ${i}
|
||||
|
||||
Reference in new issue
Block a user