tridge/SiK — pull request #18 by mikeclement (2014-05-16 21:41:46+00:00)
Title: atcommander: initial commit

Added a new script, atcommander.py, which wraps the AT command set on the radio. It consists of two parts: the ATCommandSet class that manages the serial connection and provides a reasonable API to the functionality of the AT commands, and a basic CLI that uses the class to display and change parameters. In its current form, this script is nearly orthogonal to every other script in the tools directory; however, with some extensions it could subsume some of the other one-off scripts into a single class and CLI. With a minor rewrite to allow passing in an open serial connection, it could potentially be incorporated into other software that uses the radios, such as MAVProxy.

The class can currently enter and leave command mode, produce basic device information (version, etc), get and set parameters, write parameters to the EEPROM, and reboot the radio. Its internal functions are designed to make implementing other AT commands easy (see __send_at() and __query() and its variants). The class allows switching in and out of "remote mode," in which it uses "RT" commands to manipulate a remotely linked radio just as it normally manipulates the locally attached radio.

The CLI allows displaying and changing parameters on both the local and remote radio. Any changes trigger a subsequent EEPROM write and reboot for the affected radio(s). The full set of options can be seen with the '-h' flag; here are a few examples for some /dev/ttyUSB0:

List basic information and parameters for the local radio:
```bash
./atcommander.py /dev/ttyUSB0 --list-local
```

List for both local and remote radios (will time out gracefully in the absence of a remote radio):
```bash
./atcommander.py /dev/ttyUSB0 --list-local --list-remote
```

Change the TX Power on the remote radio:
```bash
./atcommander.py /dev/ttyUSB0 --set-remote txpower 10
```

Change the Net ID on both local and remote radios (it will attempt on the remote first, and not proceed on the local if the remote fails):
```bash
./atcommander.py /dev/ttyUSB0 --set-both netid 41
```

There are a few caveats: it doesn't support both --list-* and --set-* in the same command; the user can specify multiple --set-* even with the same parameter (precedence of last-specified may not be guaranteed, but --set-both overrides --set-local and --set-remote); occasionally commands are lost along the way, causing (usually safe) failures or leaving a radio in command mode (--force can send an ATO before trying to re-enter command mode). Otherwise, the CLI does its best to keep the user safe.