From b12c6d8810ef19138bbddf5b8ba43ed817540832 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Tue, 6 Aug 2024 14:31:19 +0300 Subject: [PATCH] netconfig: Change IP addressing to match the new SSRC scheme - Change drone's IP last byte to start at mav_id (1 in case of one FC) - Use IP last byte 2 high bits to denote redundant autopilot within same drone Signed-off-by: Jukka Laitinen --- src/systemcmds/netconfig/netconfig.cpp | 41 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/systemcmds/netconfig/netconfig.cpp b/src/systemcmds/netconfig/netconfig.cpp index 617d260d06d4..06782506ee8f 100644 --- a/src/systemcmds/netconfig/netconfig.cpp +++ b/src/systemcmds/netconfig/netconfig.cpp @@ -51,25 +51,42 @@ int netconfig_main(int argc, char *argv[]) { struct in_addr addr; int32_t mav_id; + int32_t mav_comp_id; + int32_t ip; const char ifname[] = CONFIG_NETCONFIG_IFNAME; param_get(param_find("MAV_SYS_ID"), &mav_id); + param_get(param_find("MAV_COMP_ID"), &mav_comp_id); - if (mav_id < 1) { + if (mav_id < 1 || mav_id > 63 || mav_comp_id < 1 || mav_comp_id > 4) { return PX4_ERROR; } - /* IP: CONFIG_NETCONFIG_IPSUBNET + mav_id */ - - addr.s_addr = CONFIG_NETCONFIG_IPSUBNET; - - mav_id += 100; - - if (mav_id > 253) { - return PX4_ERROR; - } - - addr.s_addr |= ((uint32_t)mav_id << 24); + /* IP: CONFIG_NETCONFIG_IPSUBNET 3 bytes + * last byte: + * 2 high bits: mav_comp_id - 1 + * 6 low bits: mav_id + */ + + addr.s_addr = CONFIG_NETCONFIG_IPSUBNET & 0xffffff; + + /* Autopilot IP examples: + MAV_ID 1: + 192.168.202.1 : primary FC1 (comp_id 1) + 192.168.202.65 : redundant FC2 (comp_id 2) + 192.168.202.129 : redundant FC3 (comp_id 3) + 192.168.202.193 : redundant FC4 (comp_id 4) + MAV_ID 2: + 192.168.202.2 : primary FC1 (comp_id 1) + 192.168.202.66 : redundant FC2 (comp_id 2) + 192.168.202.130 : redundant FC3 (comp_id 3) + 192.168.202.194 : redundant FC4 (comp_id 4) + */ + + mav_comp_id--; + ip = ((mav_comp_id & 0x3) << 6) + mav_id; + + addr.s_addr |= ip << 24; netlib_set_ipv4addr(ifname, &addr); /* GW */