Created
July 1, 2016 13:05
-
-
Save JakubVanek/4408783cd4d5d3a22a08e2302b7c6b33 to your computer and use it in GitHub Desktop.
Connect EV3 to hotplugged ethernet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a small program for restarting DHCP on first interface for the EV3 programmable brick. This can be useful when you need to make the brick connect through a *supported* USB-to-Ethernet adapter to a wired network and you don't want to wait for a restart. | |
How to build: | |
- Get a copy of EV3 assembler (lmsasm) - my modified version can be found on https://github.com/JakubVanek/ev3sources-asm | |
- Download connect.lms to the directory with file assembler.jar from the step above. | |
- Compile this program. That is done by running "java -jar assembler.jar connect" in the assembler directory. | |
- Upload the connect.rbf file to the brick. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define OK_FREQ 1000 | |
define OK_LEN 100 | |
define ERR_FREQ 400 | |
define ERR_LEN 250 | |
define VOL 50 | |
define YSPACE1 0 | |
define DELAY 1000 | |
vmthread MAIN | |
{ | |
DATA32 Status | |
DATAS Command 60 | |
DATAS Interface 10 | |
DATAS Info 10 | |
DATA16 Handle | |
DATA8 Empty | |
STRINGS(DUPLICATE,'udhcpc -R -b -p /var/run/udhcpc.',Command) | |
UI_DRAW(FILLWINDOW, BG_COLOR, 0, 0) | |
UI_DRAW(UPDATE) | |
SYSTEM('killall udhcpc', Status) | |
SYSTEM('ifconfig -a | sed "s/[ \\t].*//;/^\\(lo\\|\\)$/d" >/mnt/ramdisk/interfaces 2>/dev/null', Status) | |
FILE(OPEN_READ, '/mnt/ramdisk/interfaces', Handle, Status) | |
FILE(READ_TEXT, Handle, DEL_LINEFEED, 40, Interface) | |
FILE(CLOSE, Handle) | |
FILE(REMOVE, '/mnt/ramdisk/interfaces') | |
STRINGS(STRIP, Interface, Interface) | |
STRINGS(COMPARE, Interface, '', Empty) | |
JR_FALSE(Empty, run) | |
UI_DRAW(TEXT, FG_COLOR, 0, YSPACE1, 'No interface!') | |
UI_DRAW(UPDATE) | |
JR(err) | |
run: | |
STRINGS(ADD, Command, Interface, Command) | |
STRINGS(ADD, Command, '.pid -i ', Command) | |
STRINGS(ADD, Command, Interface, Command) | |
SYSTEM(Command, Status) | |
DIV32(Status, 256, Status) | |
STRINGS(NUMBER_FORMATTED, Status, '%d', 10, Info) | |
UI_DRAW(TEXT, FG_COLOR, 0, YSPACE1, 'dhcp:') | |
UI_DRAW(TEXT, FG_COLOR, 50, YSPACE1, Info) | |
UI_DRAW(UPDATE) | |
JR_NEQ32(Status, 0, err) | |
SOUND(TONE, VOL, OK_FREQ, OK_LEN) | |
TIMER_WAIT(DELAY, Status) | |
TIMER_READY(Status) | |
JR(end) | |
err: | |
SOUND(TONE, VOL, ERR_FREQ, ERR_LEN) | |
UI_BUTTON(WAIT_FOR_PRESS) | |
end: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Meh, the following code works as well and is much more hassle-free:
One only has to stop the services before the brick is powered off: