Windows friendly CBC download shell script

1 reply [Last post]
T3hUb3rK1tten
Title: NooBot+
Joined: 03/07/2010
Posts:
BotPoints: 9
User offline. Last seen 12 years 5 weeks ago.

I'm really lazy, so after installing the NHS code and getting WiFi working I tried to figure out the easiest way to push code updates to my CBC. The script in the technical paper didn't play very nicely with CYGWIN, so I messed with it and came up with these scripts below. download.sh, after changing the two locations in it, should be ready to go on Linux and Windows. The batch file is simply a wrapper for CYGWIN. Also, you probably should at least know how to read/write shell scripts before messing with these.

download.sh:

  1. while :
  2. do
  3. CBCIP=`cat "/cygdrive/c/absolute/path/to/cbcip.txt"`
  4. ssh root@$CBCIP "rm -Rf /mnt/user/code/$1/* ; rmdir /mnt/user/code/$1/ ; mkdir /mnt/user/code/$1"
  5. echo
  6. echo Copying files...
  7. echo
  8. scp /cygdrive/c/path/to/project/directory/$1/* "root@$CBCIP:/mnt/user/code/$1"
  9. echo
  10. echo Compiling files...
  11. echo
  12. ssh root@$CBCIP "/mnt/kiss/usercode/compile /mnt/user/code/$1/$1.c"
  13. echo
  14. read -p "Press enter to run..."
  15. echo
  16. echo Running, press Ctrl+C to stop
  17. echo -------------------------------------------------------------------------------
  18. ssh root@$CBCIP "/mnt/user/code/$1/$1.bin"
  19. echo -------------------------------------------------------------------------------
  20. read -p "Press enter to redownload..."
  21. done

Run Project_Name.bat:

@echo off
chdir "C:\Directory with\Project code"
:start
"C:\cygwin\bin\bash.exe" -li "/cygdrive/c/absolute/path/to/Download.sh" "Project_Name"
pause
goto start

Basically, you run "Run Project_Name.bat," and it downloads (technically uploads) the Project_Name folder to your CBC, just like the NHS download script. After pressing enter, it runs the code straight from the command prompt, with all the text output shown right on your computer. You can even press Ctrl+C to stop the program wirelessly, similar to the E-Stop button. Once the code is finished or you stop it, you can press enter to re-download the code and run it again.

This means editing code is ridiculously easy. Just run the script, watch the robot go, make a change, let it reupload, and run it again. It's a bit slower than the original NHS script because it uses separate SSH and SCP sessions rather than the previous convoluted one-liner, but downloading and compiling a moderately complex program still only takes 15 seconds for me. Also, there's an infinite repeat in both the shell script and batch file because not having to reload bash.exe every run saves time. Ctrl+C causes Windows to break out of bash.exe, so it helps with that too.

One interesting thing I noticed is that when you run a compiled .bin file, the "Run blah.c" button's text doesn't change, although pressing it still starts the code you last ran via SSH. Restarting the CBC changes the text to what it should be. While that makes it easy to not have to rummage through the file manager to run code you've been running wirelessly, be careful that you don't run something you aren't expecting when hitting that button!

Jeremy Rand
Jeremy Rand's picture
Title: Botball Youth Advisory Council
Joined: 04/03/2009
Posts:
BotPoints: 1168
User offline. Last seen 7 years 13 weeks ago.

Thanks for the contribution! I'm kind of surprised that the scripts didn't play well with Cygwin for you... the only problem I've encountered is when cbcip somehow gets the wrong kind of line breaks. Yes, the ssh call in our script was very ugly... we found it to be faster, but you are correct, splitting it into ssh and scp is way easier to read. We also noticed the problem with the Run button not changing... I assume a simple cbcui edit would fix this, which we may or may not attempt.

Thanks again for posting this. The more people contributing to the hacks, the better! :-)

-Jeremy Rand
Senior Programmer, Team SNARC (2012-2013), Norman Advanced (2010-2011), Norman HS (2008-2009), Norman North (2005-2007), Whittier MS (2003-2004)
2012-2013 VP of Tech, 2011 President, Botball YAC (2009-2013)
Mentor, Alcott and Whittier MS