SaltyCrane Blog — Notes on JavaScript and web development

How to determine the version of your Diab compiler in Tornado 2.2 / VxWorks 5.5

Did you ever wonder what version Diab compiler you were using with Tornado 2.2? I have a directory path called "C:\Tornado2.2\host\diab\5.1.2\WIN32\bin", but 5.1.2 was not my version. There was a file called "relnote.htm" which said 5.0.2, but that was slightly incorrect too. The answer is to use the "-VV" option with "dcc.exe", the Diab compiler. (Use "dplus -VV" for C++.) Note the option is two capital "V"s, not a "W". Here is how to do it.

Steps:
1. In the "Workspace" window, click on the "Builds" tab.
2. Double-click on one of the projects using a Diab compiler
2. Right-click on the build (e.g. "PPC860diab") and select "Properties..."
3. Click on the "C/C++ compiler" tab
4. In the text box put "-VV " as the first option
5. Click "OK"
6. Right-click on your project or build and select "Build 'xxx.out'" where xxx is your project name
7. Your "Build Output" window should now contain a line something like "dcc Rel 5.0.3" which is your Diab compiler version.

How to switch from the GNU to the Diab compiler in VxWorks / Tornado 2.2

 I was using the GNU compiler for aVxWorks / Tornado project and wanted to switch to the Diab compiler. Here is how to do it:

1. In the "Workspace" window, click on the "Builds" tab.
2. Right-click on the project that you want to change and select "New Build..."
3. Select the "Default Build Spec for" option and select the Diab toolchain for your hardware.
4. Click "OK". The Diab compiler should now be the "Active Build".
5. To switch back to the GNU compiler, click on the "+" sign to expand the branch, then right-click on the GNU build, and select "Set 'XXXXXXgnu' as Active Build".

How to use Eclipse and CDT to edit C source files

Eclipse is a good integrated development environment rivaling Microsoft Visual Studio 2005. I have Visual Studio 2005 installed on my computer, though for some reason, I don't care to use it. Eclipse originally was used for Java development but now includes plugins for C/C++, Python, Perl, and many others. I use the Pydev plugin for Python development and it is good.

I am using Tornado 2.2 to develop C code for VxWorks. The editor in Tornado isn't the greatest, so I want to edit my code in Eclipse with the CDT plugin. I will still be using Tornado to build the projects, so instead of using a Standard or Managed Make Project, I just created a folder which linked to my source files. Note that you may get messages in Tornado that say "This file has been changed outside the source editor. Do you want to reload it?" Just make sure you don't have any unsaved changes from Tornado and click "Yes". Or just make sure all your source code windows are closed in Tornado. I know this isn't the most elegant solution, but it will have to do unless we upgrade to VxWorks 6 and Workbench.

Update 2/13/07: I've found a better way to use Eclipse with Tornado projects. See my post How to use Tornado GNU tools with Eclipse/CDT for how to use Eclipse to edit *and build* your Tornado project.

Here are the steps:
  1. Start with your .c and .h files in a directory called "c:\sofeng\proj\stuff"
  2. Download and install eclipse-SDK-3.2.1-win32.zip from http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.2.1-200609210945/eclipse-SDK-3.2.1-win32.zip
  3. Download and install org.eclipse.cdt-3.1.1-win32.x86.zip from http://download.eclipse.org/tools/cdt/releases/callisto/dist/3.1.1/
  4. Run "eclipse.exe"
    5. From the menu: "Window" -> "Open Perspective" -> "Other..." -> "C/C++" -> "OK"
  5. From the menu: "File" -> "New" -> "Other..."
  6. Under "General", select "Project"
  7. Click "Next"
  8. In the "Project name:" field, type "dummy". Leave the "Use default location" box checked.
  9. Click "Finish"
  10. From the menu: "File" -> "New" -> "Folder"
  11. In the "Enter or select the parent folder:" enter or select the "dummy" project you just created.
  12. Click the ">> Advanced" button
  13. Click the "Link to folder in the file system" checkbox and enter "c:\sofeng\proj\stuff" or "Browse..." to that location.
  14. Click "Finish"
NOTE: If you do not see the ">> Advanced" button, follow these steps:
  1. From the "Window" menu, select "Preferences..."
  2. Go to "General" > "Workspace" > "Linked Resources" and check "Enable linked resources"
  3. Click "OK"

How to create a downloadable vxworks project in Tornado 2.2

Start with your .c and .h files in a directory called "c:\sofeng\proj\myproj"

TORNADO DOWNLOADABLE PROJECT
1. Install Tornado 2.2
2. Run Tornado ("Start" -> "All Programs" -> "Tornado 2.2" -> "Tornado")
3. If the "Create Project in New/Existing Workspace" dialog is up, click on "New". If not, go to "File" -> "New Project..."
4. Click "Create downloadable application modules for VxWorks", click "OK"
5. In the "Name:" field, enter "myproj"
6. In the "Location:" field, enter "c:\sofeng\proj\myproj"
7. In the "Add to a New or Existing Workspace" field, enter "c:\sofeng\proj\Workspace0.wsp"
8. Click "Next"
9. Choose the "A toolchain" option
10. From the dropdown, choose "SIMNTgnu" if you are using the simulator. Otherwise choose the proper toolchain for your processor.
11. Click "Next" then click "Finish"
12. In the "Workspace:Workspace0" window, make sure the "Files" tab is selected. Make sure the "Workspace0" branch is expanded.
12. Right-click on "myproj Files" and select "Add files..."
13. Navigate to c:\sofeng\proj\myproj
14. Select all the files. (Click the first file, then while holding the "Shift" key, click the last file.)
15. Click "Add"
16. To build your project, right-click on "myproj Files"in the "Workspace:Workspace0" window and select "Build 'myproj.out'"

See also VxWorks/Tornado bootable project tutorial

Standard Make vs. Managed Make in CDT in Eclipse

From this presentation, here are differences between Standard Make and Managed Make in CDT in Eclipse.


Standard Make
  • Re-uses existing makefiles
  • Simple integration with arbitrary build systems
  • Parsing of toolchain output to generate error markers
Managed Make
  • Manages compiles and toolchain directly
  • No makefile editing
  • Fine control over compile, link settings
Also, see "When do I use the standard make feature" from the CDT FAQ.

How to install Easy Install for Python

Update 2009-03-31:
How to install Easy Install on Ubuntu Linux
$ sudo apt-get install python-setuptools python-dev build-essential

How to install Easy Install on Windows
  1. Go to http://peak.telecommunity.com/DevCenter/EasyInstall#installing-easy-install
  2. Right click on "ez_setup.py" and save the file to "c:\temp"
  3. Open a cmd.exe prompt
  4. "cd c:\temp"
  5. "python ez_setup.py"

How to install Easy Install on Cygwin
  1. $ cd /tmp
  2. $ wget http://peak.telecommunity.com/dist/ez_setup.py
  3. $ python ez_setup.py

How to draw a simple line using python and the matplotlib API -

I'm continuing to learn the low level object oriented matplotlib API. My goal is to create very customizable, perfect plots. Here is how to draw a simple line. First create a figure that is 4 inches by 4 inches. Then create some axes with a 10% margin around each edge. Then add the axes to the figure. Then create a line from (0,0) to (1,1). Then add the line to the axes. Then create a canvase. Then create the .png file. Looks like good object oriented python fun to me...


""" line_ex.py                                             
"""
from matplotlib.figure import Figure
from matplotlib.axes import Axes
from matplotlib.lines import Line2D
from matplotlib.backends.backend_agg import FigureCanvasAgg

fig = Figure(figsize=[4,4])
ax = Axes(fig, [.1,.1,.8,.8])
fig.add_axes(ax)
l = Line2D([0,1],[0,1])
ax.add_line(l)

canvas = FigureCanvasAgg(fig)
canvas.print_figure("line_ex.png")

How to use the pylab API vs. the matplotlib API

This article has a good description of the 2 API's in matplotlib: the pylab API and the matplotlib API. I've been using the pylab interface because it is easier, especially coming from a matlab background. But I wanted to get direct access to the matplotlib classes so I needed to use the matplotlib API. Here is a simple example that creates a .png figure using the 2 different API's.

Here is the example using the pylab API:
""" api_pylab.py          
"""
from pylab import *

figure(figsize=[4,4])
axes([.1,.1,.8,.8])
scatter([1,2],[3,4])
savefig('api_pylab.png')

Here is the example using the matplotlib API:
""" api_matplotlib.py                                        
"""
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg

fig = Figure(figsize=[4,4])
ax = fig.add_axes([.1,.1,.8,.8])
ax.scatter([1,2], [3,4])
canvas = FigureCanvasAgg(fig)
canvas.print_figure("api_matplotlib.png")

How to create some derived arrow classes with matplotlib and python

Here is an example of how to create some derived arrow classes with matplotlib and python. The arrow() function inmatplotlib accepts origin and delta x and delta y inputs. I changed this to polor coordinates so Arrow2 accepts the x and y coordinates of the origin, the length, and the angle. Then I created 4 classes derived from Arrow2 called ArrowRight, ArrowLeft, ArrowUp, and ArrowDown. These just set the angle for you to 0, 180, 90, and 270 respectively.Notice too that the **kwargs can be passed down so you can still set all the other parameters.
""" arrow_ex2.py """ 
from pylab import *  

def main(): 
    figure() 
    axes() 
    Arrow2(.5,.5,.2,45) 
    ArrowRight(.5,.5,.2) 
    ArrowLeft(.5,.5,.2) 
    ArrowUp(.5,.5,.2) 
    ArrowDown(.5,.5,.2) 
    show() 

class Arrow2: 
    def __init__(self, x0, y0, length, angle=0.0, color='k', width=0.01, **kwargs):          
        dx = length*cos(angle*pi/180) 
        dy = length*sin(angle*pi/180) 
        arrow (x0, y0, dx, dy, 
               width=width, 
               edgecolor=color,  
               facecolor=color,  
               antialiased=True,  
               head_width=5*width, 
               head_length=7.5*width, 
               **kwargs)

class ArrowRight(Arrow2): 
    def __init__(self, x0, y0, length, **kwargs): 
        Arrow2.__init__(self, x0, y0, length, angle=0.0, **kwargs)

class ArrowLeft(Arrow2): 
    def __init__(self, x0, y0, length, **kwargs): 
        Arrow2.__init__(self, x0, y0, length, angle=180.0, **kwargs)                      

class ArrowUp(Arrow2): 
    def __init__(self, x0, y0, length, **kwargs): 
        Arrow2.__init__(self, x0, y0, length, angle=90.0, **kwargs) 

class ArrowDown(Arrow2): 
    def __init__(self, x0, y0, length, **kwargs): 
        Arrow2.__init__(self, x0, y0, length, angle=270.0, **kwargs) 

if __name__ == "__main__": 
    main()