pass serial object to start()

avoid depending on python's outer to inner scope unless necessary,
doing so limits modularity (e.g. now you could call 'start()' with
an entirly different serial object from another location in the program
pass cursor explicitly to start

same reason as last commit
convert tabs to spaces for ease of editing
refactor db.close() out of inner calls

Whenever managing a resource that requires an open/close,
such as a database, follow the [RAII] idiom. Loosly speaking,
close the resource in the same scope as it was opened.  Here
I use the try/finally pattern to ensure that db.close() is called
even if an exception is thrown during execution of 'start(...)'.

Later I'll refactor the DB connection code out into its own object
so that we can do something like

with open_connect(...) as cursor:
	# use cursor
replace if/elif chain with dictionary lookup

advantages of this are the call and responses are all together
in a dictionary, makes it easier to eyeball for correctness,
and now just one call to log.write(...) (less repeated code)
pass cursor object to *write() functions

same reason as before
replace if/elif chain with dispatch table

see http://dkturner.blogspot.com/2005/04/dispatch-tables-in-python.html
refactor insertion code

collecting the common insertion code into
a single object makes it easier to reuse that
code in the future. It is also only one line
of actual SQL that needs to be debugged
add missing comma
call db.commit after successful insert

note, only one occurace of db.commit() now
fix selfCheck data parsing
remove unused code
replace read functions with dict lookup
replace check functions with dict lookup
consolodate two reset functions
fix bad string substitution syntax

getting confused with ruby syntax!
clean up log message
refactor out data_store

encapsulate database connection
the __enter__ and __exit__ functions
allow this object to be used with the
"with ... as val" pattern