Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netconfig: Change IP addressing to match the new SSRC scheme #742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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