WellDone/MoMo-Firmware — pull request #41 by timburke (2014-02-18 03:41:12+00:00)
Title: Working Cross-Platform MoMo-Commander Replacement: modtool

This pull requests contains all of the changes needed to have a working cross-platform version of momo-commander. It's broken down into 3 parts: FSU changes, pymomo/cmdr module, modtool. Basically, the python module pymomo/cmdr implements all of the functionality required to talk to the momo hardware. modtool is a thin cmdline wrapper on top of a few of these functions. The FSU firmware needed to be updated to work with pymomo/cmdr.

## FSU Changes
- Moved from simple command line rpc parameter passing to passing a base64 encoded buffer that contains the mib buffer, feature, address and command all in one go. This is easier to generate in python and allows for arbitrary values in the mib_buffer rather than dying if a byte was numerically equal to ' '.
- Removed push-firmware and pull-firmware from fsu. This is implemented in pymomo/cmdr. Doing it in software is easier and more robust. The FSU now just serves as a tool for sending rpcs and getting the results. The logical flow is handled on the computer in pymomo/cmdr.

## pymomo/cmdr

A python library wrapping access to momo modules. Each module is given a proxy object that allows for rpc calls to be made on it. Currently only the controller module is implemented with support for enumerating modules and pushing and pulling firmware. The implementation is layered: stream, CmdStream, proxy objects. A stream must be able to send a bytestream. CmdStream adds command frames on top of stream. Proxy objects implement module specific functions on top of the commands sent over the CmdStream. This means that you can swap out, for example, a serial port fsu with a bluetooth fsu and use the same cmdr implementation.

## modtool
A simple demo of the cmdr functionality with support for enumerating modules and reflashing them. To see the supported commands run:
```shell
timburke $ modtool help
Usage:
modtool COMMAND [ARGS...]
modtool help [COMMAND]

Options:
-h, --help show this help message and exit

Commands:
help (?) give detailed help on a specific sub-command
info Describe the mib module given its index
list List all attached MIB modules on the bus
reflash Reflash the mib12 module given either its name or address
```

To enumerate modules use:
```shell
timburke $ modtool list -p /dev/ttyUSB0
Listing attached modules
0: pv_mod at address 11
1: NO APP at address 12
2: NO APP at address 13
```

To reflash a module by name from the list of attached modules by its address use:
```shell
timburke $ modtool reflash -p /dev/ttyUSB0 -a 13
Sending Firmware
Transmission Progress: [########################################]
Firmware stored in bucket 0
Reflashing: [########################################]
```
The command will send the firmware to the controller, find the module and tell it to reflash itself and then wait 10 seconds to make sure the reflashing completed before returning. modtool lives in tools/bin

## Notes
- This requires a new style FSU that does not need D2XX to run (I have extras of these).
- Python dependencies must be installed via easy_install for this to work: tools/README.md has the list of dependencies
- You must pass a serial port to modtool corresponding to the FSU
- This has been tested on Windows 7, OS X Mavericks and Gentoo Linux and works on all of them. It should be very cross-platform since the python libraries that it depends on are themselves cross-platform.