Skip to content

Commit

Permalink
netconfig: Change IP addressing to match the new SSRC scheme
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
jlaitine committed Oct 30, 2024
1 parent 27bdeb0 commit b54c360
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/systemcmds/netconfig/netconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit b54c360

Please sign in to comment.