Tips
Google Spreadsheet for Hardware – Software register maps sync
0I usually develop hardware or program some device which has to be accessed by a PC software (at least to test and debug it). Either if it is a board with a micro or an FPGA, a PLC or whatever it is usually it ends having a bunch of registers which are used to check the status of the design or to operate it. So I always end with the problem of having to replicate same information in two separate designs, in this case, a register map.
In this cases, in order to avoid problems I follow some rules:
- Each design has a file of constants where I assign a name to registers address
- It is completely forbidden to use raw integer numbers inside the code to implement or access a register, only constant names. If a name is missing the design will not compile or will generate an exception, but an integer will never generate an error.
- I keep an spreadsheet with: Address, name, description, [ReadOnly/ReadWrite, Units,..]. Only the first three columns are mandatory, the rest are optional. It can have several others columns depending on the design. This is the only file I trust, all constant files on the designs (either HW or SW) are generated from this spreadsheet, either automatically or by hand. The point is that if address constant files from HW and SW doesn’t match, the good values are on the spreadsheet. Doesn’t matter what, good ones are on the spreadsheet.
#!/usr/bin/env bash
OFILE='__init__.py'
IURL='https://docs.google.com/spreadsheet/ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc&output=csv'
IFILE='gdocs.csv'
echo '#!/usr/bin/env python' > $OFILE
echo '' >> $OFILE
echo '## This file is automatically generated by genctns_py ' >> $OFILE
echo '## Do not edit it' >> $OFILE
echo '## To update it execute genctns_py.sh' >> $OFILE
echo '## It downloads contents of a gDocs spreadsheet and generates a py file' >> $OFILE
echo '' >> $OFILE
echo 'Downloading contents from gdocs ('$IURL')'
wget --output-document $IFILE $IURL -o tmp.txt
echo 'Parsing file contents'
awk -F',' '$1~ /^[0-9]+/ {print $2 " = " $1 "\t##" $3};
$1~ /^[a-zA-Z]+/ {print "\n## "$1};' $IFILE >> $OFILE
echo 'Deleting temporary files'
#rm -f $IFILE
rm -f tmp.txt
echo 'Done'
Downloading contents from gdocs (https://docs.google.com/spreadsheet/ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc&output=csv) Parsing file contents Deleting temporary files Done
And generates two files, a csv file called “gdocs.csv” and a py file (__init__.py):
#!/usr/bin/env python ## This file is automatically generated by genctns.sh ## Do not edit it ## To update it execute genctns_py.sh ## It downloads contents of google docs spreadsheet and generates a py constants file ## Address ## Motors power_en = 1 ##Enable/Disable power motor_en = 2 ##Mask to enable/disable motors ## Sensors temp_1 = 1024 ##Temperature sensor 1 value temp_2 = 1025 ##Temperature sensor 2 value temp_3 = 1026 ##Temperature sensor 3 value temp_4 = 1027 ##Temperature sensor 4 value temp_5 = 1028 ##Temperature sensor 5 value
Download Google Docs spreadsheet in a script
1When using Google docs (or as they like to call it now, Google Drive) it is easy to download an spreadsheet as a csv file, just go to “File > Download as > CSV (current sheet) ” on the web interface as seen on the picture:
But what if we want to download it from a script?
In order to be able to do that we must first share the spreadsheet as a public spreadsheet (either public or giving access to anyone with the link). This doesn’t mean that everybody can modify our spreadsheet, as you can set read only permissions, but it can be accessed, at least, by everybody who has the link to the spreadsheet.
Once we have set the share options, we obtain a link like this:
https://docs.google.com/spreadsheet/ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc
If we try to download this link from a script or with “wget”, we will download a rather ugly to read html file. But if we forge the url appending “&output=csv” we will get a csv version of our spreadsheet first sheet. Try loading next link with your browser:
https://docs.google.com/spreadsheet/ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc&output=csv
- Append “&output=xls” to your sharing link to obtain an Excel file
- Append “&output=ods” to your sharing link to obtain an Open Office file
- Append “&output=pdf” to your sharing link to obtain a PDF file
- Append “&output=txt” to your sharing link to obtain a text file (no comma separated, tabulated)
For example to get the csv version of the spreadsheet with wget (use –output-document modifier to avoid having a file name ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc&output=csv):
wget --output-document gdocs.csv "https://docs.google.com/spreadsheet/ccc?key=0AtgWCe1LjubedFZMVHR2QnFxekJIYlFPYmZSQmJ5SHc&output=csv"
Using subversion for android development
0I’ve started to learn the basics of Android Apps development. As always that there is code involved, I like to use a code versioning tool. In my case I use subversion.
The general rule of thumb I use when using subversion is to add everything to subversion except the auto generated files. For Android this means, add everything generated by eclipse ADT plugin except the gen and bin folders.
I tell the steps to follow to create a new project and upload to a subversion repository. In this example I use a folder in my home directory to store the project files. Instead of letting Eclipse create the folder I do it myself and then I check out the option “Use default location”.
- Launch Eclipse and create a new Android Project, setting the location you want to use
- Check out your subversion trunk development at your selected location
svn co http://path/to/your/subversion/trunk ~/libtronicsExample
- Add everything to subversion
cd ~/libtronicsExample svn add * svn add .project svn add .classpath
- Revert bin and gen contents (but keep versioning the root folders, as you need them to build the project)
cd ~/libtronicsExample cd bin svn revert --depth infinity * cd ../gen svn revert --depth infinity *
- Check what are you versioning
cd ~/libtronicsExample svn status
- Submit it
cd ~/libtronicsExample svn ci -m "My first commit of my next awesome Android App"
Enable Marketplace on an Ubuntu Eclipse
5When installing eclipse on an Ubuntu box (don’t know if this happens also in other distributions) it doesn’t have the default eclipse release software site, neither the Marketplace. Next I show how to install the marketplace by enabling the release software site.
For this example I use Eclipse Indigo (default eclipse version in Ubuntu 11.10):
- Go to “Help > Install new software…”
- Press “Add..” Button
- Fill the Dialog and press OK:
- Name: Eclipse Indigo (or whatever you want)
- Location: http://download.eclipse.org/releases/indigo/
- Once the contents of this Software site is loaded, check Marketplace client from “General Purpose Tools” category
This can be used also to install other software packages like “Eclipse XML Editor and Tools”,…
Note: When installing ADT (Android development tools) pluguin I was having an error because it needs some package not installed by default on a basic eclipse install. Once this Software site is added, this error also disappears.
Compiling PyQwt5 in Windows
2At work, we made a python program to display plots of some data. This program is based in python, pyQt, PyQwt5, guiqwt and matplotlib. We are using python 2.7 for all of our developments. We use linux for development, but this application main users are Windows Users, so we had to generate a windows binary of this application. For all libraries there was a binary for windows 32 bits and python 2.7, except for PyQwt, so we had to compile it. Yes, compile!
In order to compile PyQwt-5.2.0 for python 2.7 with pyQt4 we need to install all dependencies. What I installed:
- Visual c++ 2010 express (we need nmake)
- numpy-1.6.1-win32-superpack-python2.7
- PyQt-Py2.7-x86-gpl-4.8.6-1
- qt-win-opensource-4.7.4-vs2008
cd PyQwt-5.2.0 cd configure configqt.bat vcvars32.bat python configure.py -Q ../qwt-5.2 nmake nmake install
- After installing Visual C++ 2010, nmake was not found, I had to add “C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\” to the path
- vcvars32.bat is a batch command to set the paths correctly for Visual c++ 2010, it is located at same place as nmake.
- when running “python configure.py -Q ../qwt-5.2″ an error message box appeared as it was unable to find mspdb100.dll, I searched it on my Program files and copied it to PyQwt-5.2.0/configure
Eclipse setup for pyQt (II)
4As I’m learning python and Qt I change my mind on some of the tips I’ve already posted here. This is the case for my old tip on how to configure Eclipse to work with PyQt4. That old post should be called “How to compile ui files from eclipse”, so I will try to ammend my error in this new post.
Resize VirtualBox disk for WinXP guest
7Resizing a virtualbox virtual disk is not a trivial task. Although it has a direct method to resize the virtual disk, it involves several steps to make Windows XP guest OS realize about this change. I will show all steps needed to increase the size of a Windows XP guest OS.
ssh login without password with nfs shared homes
0On the previous post we saw how to log from one machine to another one without password through ssh. To do the same but in a cluster of computers which have the home of the user shared across them the idea remains the same, but with little changes.
ssh login without password
2At work I have a small cluster for development purposes. To avoid having to input your password to log to a machine you have to generate a pair of public/private keys and copy the public one to the machine where you want to log.





