{Notes to self, programming, technology, linux, windows, git} U {Papers, reviews, games, coffee, tabletennis, ramblings} = {things worth saving}

Friday, May 22, 2009

Flash spine network of shimmer nodes + simple test app

* make shimmer install bsl, /dev/ttyUSB0 (/apps/BaseStation, /contrib/apps/SpineApp - as many sensors as required)

synchronize channel in makefiles:

#radio channel for TX-RX (spine default so change in BS)
PFLAGS += -DCC2420_DEF_CHANNEL=12


* Run tinyos software listener manually:
$ java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:shimmer

(you need to build libgetenv and libtoscomm from your tinyos before you can install and run any SPINE application.
cd $TOSROOT/support/sdk/java && make (if its not already built?)
sudo tos-install-jni ) - what spine doc means is that tos-install-jni will do the above for you, install libtoscomm in your java JRE

sometimes lobtoscomm-32.so and libgetenv.so aren't build.

If you have not installed the tools RPM and are working directly from the TinyOS CVS repository, you can manually install the tos-locate-jre script. Go to tinyos-2.x/tools/tinyos/java. If the directory has a Makefile in it, type make and (again, on Linux, as superuser) make install. If the directory does not have a Makefile, go to tinyos-2.x/tools and type:

$ ./Bootstrap
$ ./configure
$ make
$ make install

notice where the .so files get copied, and notice how they're named, and where the tos-install-jni script expects them to be. (search and edit)

finally do --- tos-install-jni

Now you can start the listeners

http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Cannot_find_JNI_error

)

tells Listen to use the serial port /dev/ttyS0 (on a UNIX machine) at the correct speed for a shimmer mote.

in general:   serial@*PORT*:*SPEED*

PORT depends on your platform and where you have plugged the mote in. For Windows/Cygwin platforms, it is COMN, where N is the port number. For Linux/UNIX machines, it is /dev/ttySN for a built-in serial port, or one of /dev/ttyUSBN or /dev/usb/tts/N for a serial-over-USB port. Additionally as we saw in lesson 1, on Linux you will typically need to make this serial port world writeable. As superuser, execute the following command:

chmod 666 serialport

*

One problem with directly using the serial port is that only one PC program can interact with the mote. Additionally, it requires you to run the application on the PC which is physically connected to the mote. The SerialForwarder tool is a simple way to remove both of these limitations.

Most generally, the SerialForwarder program opens a packet source and lets many applications connect to it over a TCP/IP stream in order to use that source. For example, you can run a SerialForwarder whose packet source is the serial port; instead of connecting to the serial port directly, applications connect to the SerialForwarder, which acts as a proxy to read and write packets. Since applications connect to SerialForwarder over TCP/IP, applications can connect over the Internet.

SerialForwarder is the second kind of packet source. A SerialForwarder source has this syntax:

sf@HOST:PORT

The first step is to run a SerialForwarder; since it takes one packet source and exports it as an sf source, it takes a packet source parameter just like the other tools we've used so far: you can pass a -comm parameter, use MOTECOM, or just rely on the default. Close your MsgReader application so that it no longer uses the serial port, and run a SerialForwarder:

java net.tinyos.sf.SerialForwarder (GUI)
set motecom to serial@/dev/ttyUSB0:shimmer

or

java net.tinyos.sf.SerialForwarder -port 9003 -comm sf@localhost:9002 (this last part is the source)
This command opens a second SerialForwarder, whose source is the first SerialForwarder. You'll see that the client count of the first one has increased to one. It's rare that you'd ever want to do this, but it demonstrates that in the message support libraries you can use a variety of packet sources.


(http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder)
* Spine_serverSide/defaults.properties :
MOTECOM=sf@127.0.0.1:9002 (supply this to tinyos )
LocalNodeAdapter_ClassName=spine.communication.tinyos.SFLocalNodeAdapter

* Run Spine_serverSide/test/SPINETest.java to test!


* VMWARE player - dhcp router? then set Ethernet to NAT and enable network. (eth1)


* Installation tips: http://docs.tinyos.net/index.php/Boomerang_Tmote_Linux_install

Monday, May 11, 2009

Coffee roast May 2009

4 new beans to try.

Rwanda : Horizon Nyamyumba
"Soft and delicious coffee with a good acidity. Lots of fruit - citrus & blackberry aswell as caramel"

Roast #1: A very small bean. Gave the roast 11 minutes at 220. It seemed to go very fast, but it turned out pretty light still. Alot of shells still attached to the beans. Roast#2 will be darker. Interesting to note that no crust formed on the surface. Tastes as advertised, altho the caramel is the most pungent flavor. Maybe a slight darker roast will bring out the rest.

Roast #2: This roast was 15 minutes. There's nothing to be nervous about. The bean can take it. Apparently, this is the reason why there was no crust on roast #1. A light roast is too heavy. Around 14 minutes, the bean started expulsing it's oils and a nice crust has been formed. The coffee is ALOT softer and the flavors are more apparent. A darker roast definately suits this bean. Delicious!

Roast #3+ : ^

Bolivia Primera : Asipai biolatina

"Good sweetness, creamy, pure citrussy with lots of chocolate"

Roast #1:
Roast #2:

Guatemala: Huehuetenango SHB
"Good body with lang, soft aftertaste of flowers and chocolate"

Roasted same day as the Kenya. I took it to the max, got the oils after second crack. Whole thing took about 14 minutes. I thought i'd made it too dark. Day 1 taste was... relatively tasteless, same as Kenya. Maybe dark roasts need to be cultivated longer.


Kenya: Gethubwini AA+

"Large, rich body with classic and wellbalanced acidity. Wonderful sweetness and the classic taste of blackberry anf flowery essence (roses)"

Roast #1: A bit inconsistent. Roasting took longer than expected. Ended up around 15 minutes
Roast #2: Very consistent. Upped the heat some to 230 degrees. First crack at 5-6, second at 10-11.

Taste: After day 1, i wasn't quite sure about this bean. I thought i'd roasted the fuck out of it, but after 3 days, the flavors have come out nicely!

Sunday, May 10, 2009

SHIMMER sensors in SPINE 1.2 on TinyOS

Quicknotes for Cygwin installation:
(TODO: Edit to be something remotely usable in the near future!)

* install cygwin

* install appropriate tinyOS rpm's ($ cd /cygdrive/*drive*/*packageloc* )
* tinyos-tools-1.3.0-1.cygwin.i386.rpm seems to install and compile javatooling for TinyOS including running "tos-install-jni"which installs 32-bit java JNI code into the appropriate JRE.
* The SHIMMER platform requires the TI MSP430 Tool packages. install them with the command 'rpm -ivh --ignoreos '. Without --ignoreos rpm tells you that the package was intended for a cygwin_nt5.1 OS. Warning: installing the gcc package on cygwin, you'll get an error if the current user isn't "TinyOS", and it'll revert to using "root". Unsure of the effect of this sofar.

* Setup permissions and environment
$chown -R /opt/tinyos-2.x
$chmod 666 /dev/ for all necessary devices

* Add to ~/.bashrc:
export TOSROOT=/opt/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=`cygpath -w $TOSROOT/support/sdk/java/tinyos.jar`
#export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:. (linux)
export MAKERULES=$TOSROOT/support/make/Makerules
export PATH=/opt/msp430/bin:$PATH
export CLASSPATH="$CLASSPATH;."

* Check environment setup:
$ tos-check-env *

* Create a /contrib/ folder in $TOSHOME. Copy Spine_nodes from the Spine 1.2 dist into tinyos-2.x-contrib folder
* Compile application through a-d. (SENSORBOARD=*boardtype* make *platform*)

At this time, platforms supported by SPINE1.2 are
a. Telosb motes with spine sensor board
SENSORBOARD=spine make telosb
b. Telosb motes with biosensor sensor board
SENSORBOARD=biosensor make telosb
c. Micaz motes with mts300 board
SENSORBOARD=mts300 make micaz
d. shimmer motes
SENSORBOARD=shimmer make shimmer

Without SENSORBOARD defined, make gives you "error: SENSORBOARD not defined"

* Appropriate compilation units are compiled to "contrib\apps\SPINEApp\build\shimmer"
* app.c
* ident_flags.txt
* main.exe
* main.ihex
* tos_image.xml

* Spine app is defined by the following interface / module:
(detailed information about the tinyos app files http://docs.tinyos.net/index.php/Getting_Started_with_TinyOS)


configuration SPINEApp_AppC {
}

implementation {
components MainC, SPINEApp_C;

components RadioControllerC;
components PacketManagerC;
components SpineStartPktC;
components SpineSetupSensorPktC;
components SpineFunctionReqPktC;
components SpineSetupFunctionPktC;

components new TimerMilliC() as Annce_timer;

components SensorsRegistryC;
components SensorBoardControllerC;

components FunctionManagerC;

SPINEApp_C.Boot -> MainC.Boot;

SPINEApp_C.RadioController -> RadioControllerC;
SPINEApp_C.PacketManager -> PacketManagerC;
SPINEApp_C.SpineStartPkt -> SpineStartPktC;
SPINEApp_C.SpineSetupSensorPkt -> SpineSetupSensorPktC;
SPINEApp_C.SpineFunctionReqPkt -> SpineFunctionReqPktC;
SPINEApp_C.SpineSetupFunctionPkt -> SpineSetupFunctionPktC;

SPINEApp_C.SensorsRegistry -> SensorsRegistryC;
SPINEApp_C.SensorBoardController -> SensorBoardControllerC;

SPINEApp_C.FunctionManager -> FunctionManagerC;

SPINEApp_C.Annce_timer -> Annce_timer;

}



* SERVER SIDE (JAva)

java coordinator applicationss implement the SPINEListener interface. Contains:

void dataReceived(int nodeID, Data data)
void discoveryCompleted(java.util.Vector activeNodes)
void newNodeDiscovered(Node newNode)
void serviceMessageReceived(int nodeID, ServiceMessage msg)


Then, the application can use any APIs exposed by the SPINEManager (see some doc somewhere!)


* Create documentation : SENSORBOARD=shimmer make shimmer docs
* docs will be placed in : contrib\doc\nesdoc\shimmer as html documentation
* docs makes use of Graphviz for generating a componentgraph. If it's not found "sh: dot : command not found". Install package from (http://www.graphviz.org/Download..php). But which one?


Compiling SPINE_ServerApp:
Copy $TOSROOT/support/sdk/java/tinyos.jar to /SPINE_ServerApp/ext-lib/
run "Ant"

If appropriate COMport isn't defined, following error is produced:

run:
[java] serial@COM65:115200 died - exiting (java.io.IOException: Could not open COM65: TOSComm JNI library runtime error: Error 2.
[java] The system cannot find the file specified.
[java] in NativeSerialPort.CreateFile)
[java] Exception in thread "Thread-1" org.apache.tools.ant.ExitException: Permission (java.lang.RuntimePermission exitVM) was not granted.
[java] at org.apache.tools.ant.types.Permissions$MySM.checkExit(Permissions.java:196)
[java] at java.lang.Runtime.exit(Runtime.java:88)
[java] at java.lang.System.exit(System.java:906)
[java] at net.tinyos.packet.PhoenixSource.error(PhoenixSource.java:221)
[java] at net.tinyos.packet.PhoenixSource.run(PhoenixSource.java:174)

* SIMULATION (TOSSIM)

* run "make micaz sim" from tinyos /apps folders (like Blink) (micaz is the only platform supported by TOSSIM currently). Might requires some of the other native compilers. and definately JAVA (1.5). Exports a python interface.

Links:

http://www.physionet.org/physiotools/cygwin/
http://docs.tinyos.net/index.php/Installing_TinyOS_2.1#Manual_installation_on_your_host_OS_with_RPMs (2.1.0)
http://www.tinyos.net/tinyos-2.x/doc/html/install-tinyos.html (2.0.2)
http://ragemaster.livejournal.com/112000.html
http://docs.tinyos.net/index.php/Getting_Started_with_TinyOS
http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2007-February/022355.html
https://www.millennium.berkeley.edu/pipermail/tinyos-help/
http://docs.tinyos.net/index.php/TOSSIM

http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder

Saturday, May 02, 2009

Python: svn pre-commit hook

I put together a python svn pre-commit hook that does 2 things.

* Checks commit message syntax {, orphan} {baseline, tag, integrate}. If syntax does not comply with standards, commit is rejected.
* If syntax contains an activity-id, a ticket repository is checked to locate that specific id. Commit fails if id is not found. If repository connection fails (which shouldn't ever happen), commit is let through regardless.


__doc__ = """
iw_check_commit_messages.py
Utility for doing svn stuff.
"""

import os, string, sys, re, pg
from iw_connect import get_activity_ids #import connect method from iw_connect

SVNLOOK = 'C:\\Program Files\\svn-win32-1.4.5\\bin\\svnlook.exe' #location of SVNlook.exe
authors = {"mk" : "Martin Kjeldsen", "sas" : "Soren Ahm Sorensen", "jo": "Jens Olsen" } #list of fullname authors

syntax_ok = '^(ID|id):(\d+|orphan|baseline|activity|integrate)$' #regexp "tasks"
specifies_activity = '^(ID|id):(\d+)'

def do_lookup(repo,txn, cmd):
cmd = '"%s" %s -t %s %s' % (SVNLOOK, cmd, txn, repo)
result = os.popen(cmd, 'r').readline().rstrip('\n')
return result

def run_reg_exp_task(text, exp, mode):
expression = re.compile(exp)
if mode == "eval":
return expression.search(text) != None
elif mode == "getval":
return expression.search(text)

def parse_commit(repo, txn):
"""
This method parses the log assosiated with transaction txn and takes appropriate action
"""
author = do_lookup(repo,txn, "author") #Determine author
author_fullname = "".join([ v for k,v in authors.items() if k==author]) #if authors fullname isn't in authors dictionary, author is empty.
log_msg = do_lookup(repo,txn, "log") #determine log message

if(run_reg_exp_task(log_msg, syntax_ok, "eval")): #eval TASK: is syntax okay?
if not run_reg_exp_task(log_msg, specifies_activity, "eval"): #eval TASK: does it specify an activity?
sys.exit(0) #exit normally if syntax is okay and we're not dealing with activity id's.
else:
#activity_id = get_activity_id(log_msg) #check database for ID. extract it using a regular exp after it's been approven by the first.
activity_id = run_reg_exp_task(log_msg, specifies_activity, "getval").groups()[1] #get the id from the regexp result
ticket_repository = get_activity_ids() #get ticket repository
if ticket_repository == None: #NONE if connection fails. just commit it. Nothing else we can do. It already passed first test.
sys.exit(0)
elif activity_id in ticket_repository: #is log message activity id present?
sys.exit(0)
else: #reject revision
sys.stderr.write("Dear %s, your revision was rejected. You're trying to commit to an activity that doesn't exist (ID:%s). \n" % (author_fullname, activity_id))
sys.exit(1)
else:
sys.stderr.write("Dear %s, your revision was rejected. Syntax: \nLine 1: {ID|id}:{|orphan|baseline|tag|integrate}\nLine 2+:{Optional: Additional information about activity}" % (author_fullname))
sys.exit(1) #reject revision

if __name__ == "__main__":
print __doc__
if len(sys.argv) <>




__doc__ = """
iw_connect.py
Utility for connecting to a postgresdb using pygresql interface
"""

import os, string, sys, pg

iw_database = 'removed'
iw_host = 'removed'
iw_user = 'removed'
iw_passwd = 'removed'

iw_query = "removed"

def connect():
con = pg.connect(dbname=iw_database, host=iw_host, user=iw_user, passwd=iw_passwd)
return con

def get_activity_ids():
try:
con = connect() #connect to db: details specified in iw_connect.py
query = con.query(iw_query) #Run query to get id's to check in. refactor
ids = [str(v[0]) for v in query.getresult()] #convert result to set of strings
return ids
except pg.InternalError: #if connection fails, just commit it. Nothing else we can do. It already passed first test.
return None

Python: Postgres module import failure

 Traceback (most recent call last):
File "
", line 1, in
import pg
File "C:\Python26\Lib\site-packages\pg.py", line 21, in -toplevel-
from _pg import *
ImportError: DLL load failed: The specified module could not be found.


Solution:
Make sure the PostgreSQL C interface (libpq.dll) is installed or
its directory (\Postgresql\bin) is on PATH.

Followers