watonomous.github.io

  1. Electrical Division
  2. Electrical Division Home
  3. Radar Driver Group

[ Electrical Division : Change Radar Config Script ]

Created by [ Rowan Dempster], last modified by [ Frank Yan] on Apr 17, 2020


Table of Contents

Overview

EthCfgRx.py is a script built using Python 2.7 that is used for sending a packet containing new network configuration properties we want to give the radar. This packet is sent through Ethernet. After sending the packet, the radar takes on a different IP address, MAC address, and/or transmit port. If successful these changes will persist after a power cycle.

APIs and Libraries Used

Sockets API

This API allows you to set up network sockets/endpoints for sending and receiving packets.
Documentation: https://docs.python.org/2/library/socket.html

Struct

This package is used to convert Python integers and primary data types into strings of network-encoded data. To see how to do this, check out the hyperlink below, and also read the "Script Functionality and Packet Structure" section of this document below.
Documentation: https://docs.python.org/2/library/struct.html

Netifaces

This package is used to get the properties of the current machine's network interfaces. This info can also be obtained through typing ifconfig into the terminal.

Check out the tutorial below:
https://pypi.org/project/netifaces/

Example terminal output from ifconfig:

enp3s0    Link encap:Ethernet  HWaddr 11:7b:24:19:fe:0a
                  inet addr:128.91.199.132  Bcast:128.91.199.200  Mask:255.255.255.0
                  inet6 addr: fe80::7429:842:9756:ac56/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:31238625 errors:0 dropped:382444 overruns:0 frame:0
                 TX packets:12926131 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:1000
                 RX bytes:30872758576 (30.8 GB)  TX bytes:3568234637 (3.5 GB)
lo             Link encap:Local Loopback  
                inet addr:127.0.0.1  Mask:255.0.0.0
                inet6 addr: ::1/128 Scope:Host
                UP LOOPBACK RUNNING  MTU:65536  Metric:1
                RX packets:20178972 errors:0 dropped:0 overruns:0 frame:0
                TX packets:20178972 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000 
                RX bytes:35951194492 (35.9 GB)  TX bytes:35951194492 (35.9 GB)

How to Run the Script

The script accepts 3 mandatory command-line arguments (these are the current config properties of the radar that you want to modify):

-n : name of the Ethernet interface connecting to the radar
-ip : Radar's current IP Address. Required format: x.x.x.x {0 <= x <= 255}
-m: Radar's current MAC Address. Required format: x:x:x:x:x:x or x.x.x.x.x.x

There are 4 optional command-line arguments (specify only the properties below that you want to change):

-tx: new Tx port the radar should use to transmit data. Valid range: 31115 - 31122, inclusive 
-ui: Radar's new unicast IP Address. Required format: x.x.x.x {0 <= x <= 255}
-mi: Radar's new multicast IP Address. Required format: x.x.x.x {0 <= x <= 255}
-nm: Radar's new MAC Address. Required format: x:x:x:x:x:x or x.x.x.x.x.x

Example – changing a Radar's Tx Port to 31120:

$ sudo python EthCfgRx.py -n enp3s0 -ip 192.167.0.1 -m 08:09:FF:E4:30:09 -tx 31120

Note that sudo is required, and you will need to type the password for your development computer during the first run.

You technically only need to input the optional arguments for the radar configurations that you want to change. However, note that the default Tx port of the new radar will be set to 31122 and the default multicast IP of the new radar will be set to 225.0.0.1, if those two aforementioned optional arguments are not provided on the command line. Thus, it is possible for the radar Tx port and radar multicast IP to change to their defaults (31122 and 225.0.0.1) after running the script if you did not provide those optional arguments.

Script Functionality and Packet Structure

One packet consists of the following fields:

All aforementioned data is initialized as raw integers or strings in the script. They need to be encoded using the struct API. In EthCfgRx.py, we initialize the Radar MAC address (02.08.02.03.00.00) as a Python list of hex numbers:

RadarMAC = [0x02, 0x08, 0x02, 0x03, 0x00, 0x00]

To encode it, we make the following API call:

struct.pack("!6B", RadarMAC[0], RadarMAC[1], RadarMAC[2], RadarMAC[3], RadarMAC[4], RadarMAC[5])

Specifying "6B" means we need to pass in 6 more arguments into struct.pack() after the very 1st argument, each of which is the same size as an unsigned char ("B" --> 1 Byte). In the above case, every argument is a digit of the Radar MAC address. "!" specifies big-endian ordering. As another example, "2H" requires us to pass in 2 additional arguments after the 1st one, each of which is the same size of an unsigned short ("H" --> 2 Bytes).

API specification: https://docs.python.org/2/library/struct.html

All encoded pieces of data are strings which are concatenated together into a larger string. It is then sent out with help from the Python socket API.

Forums and Support

The link below has inquiries related to the EthCfgRx.py script from the dates beginning 10/18/2018 to 11/09/2018:

https://www.autodrivechallenge.com/cdsweb/rqa/ViewInquiry.aspx?inquirynum=9978&teamid=798f2940-daca-4c70-ad80-cef2b02e3e4b&backto=/cdsweb/rqa/TeamInquiries.aspx%3fteamid=798f2940-daca-4c70-ad80-cef2b02e3e4b

\

Document generated by Confluence on Nov 28, 2021 22:40

Atlassian