///////////////////////////////////////////////////////////////////////////
//
//    AutoCap Arduino Firmware
//    Version 1.5
//
//    Data Protocol Description
//
//    License: GNU General Public License Version 3.0.
//    
//    Copyright (C) 2014-2016 by Matthew K. Roberts, KK5JY. All rights reserved.
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//    
//    This program is distributed in the hope that it will be useful, but
//    WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    General Public License for more details.
//    
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see: http://www.gnu.org/licenses/
//
///////////////////////////////////////////////////////////////////////////

Each line received from the host must end with a CR, or CRLF pair.

Each line contains one command byte, of the set:
   I - info:    returns the version string of the device firmware
   P - pulse:   pulses a motor for a specific period of time
   M - move:    starts or stops a motor
   B - brake:   controls the braking circuit
   S - status:  controls status (motor current) reporting
   Z - stop:    sets all ports to safe (stopped) state
   C - count:   returns the number of ports configured in the firmware
If settings peristence is enabled, three additional commands are available:
   A - read:    read persisted settings from EEPROM (automatic at startup)
   W - write:   write settings to EEPROM
   F - factory: erase EEPROM
If stepper support is enabled, these additional commands are available:
   T - step:    moves a stepper motor a specific number of steps
   R - reset:   makes the current stepper position the "zero" position
   X - read:    reads the current stepper position
   G - go-to:   seek to a specific position
   E - enable:  configure enable PWM settings

Some of these commands also take additional argument bytes, describing
the details of the command, as described below.

Pulse takes the form:
   Pdpxxxxyy
   d    = direction, either U or D for up and down.
   p    = motor port number; the first port is 0, the second 1, and so on
   xxxx = duration, in milliseconds, hex-encoded
   yy   = the effort, between 00 (stop) and FF (full speed), hex-encoded

Step takes the form:
   Tdpxxxxyy
   d    = direction, either U or D for up and down.
   p    = motor port number; the first port is 0, the second 1, and so on
   xxxx = distance, measured in steps, hex-encoded
   yy   = the effort, between 00 (stop) and FF (full speed), hex-encoded

Move takes the form:
   Mdpyy
   d    = direction, either U or D for up and down.
   p    = motor port number; the first port is 0, the second 1, and so on
   yy   = the effort, between 00 (stop) and FF (full speed), hex-encoded

Brake takes the form:
   Bps
   p    = motor port number; the first port is 0, the second 1, and so on
   s    = brake status; 0 to disable brake circuit, 1 to enable
If 's' is omitted, the current value is returned.

Status takes the form:
   Ss
   s    = 1 to enable status reports, 0 to disable; enabling
          status reports will periodically send motor current
          readings to the host.

Position read takes the form:
   Xp
   p    = motor port number; the first port is 0, the second 1, and so on

Position reset takes the following form:
   Rp
   p    = motor port number; the first port is 0, the second 1, and so on

Go-to takes the following form:
   Gp[+-]offset
   p    = motor port number; the first port is 0, the second 1, and so on
   [+-] = a single character, either a '+' or '-', indicating the sign of
          the target position
   offset = an integer specifying the target

Enable takes the form:
   EpeIIOO
   p    = motor port number; the first port is 0, the second 1, and so on
   e    = the enable pin for that motor, with the first being 0, ...
   II   = the hex value of the PWM setting for that enable pin when moving
   OO   = the hex value of the PWM setting for that enable pin when stopped
If II and OO are omitted, the current values are returned.

Stop, Info, and Count take no arguments:
   Z
   I
   C

If settings persistence is enabled, the Read, Write, and Factory commands
also take no arguments
   A
   W
   F

The unit will send back responses, prefixed with '#'.  The
standard responses are:
   #info,...  which contains the version string
   #OK,...    which acknowledges a command
   #error,... which indicates some kind of error
   #debug,... which prints extra debugging information
   #stat,...  which provides some key=value pairs, separated by
              commas, which reflect certain runtime parameters,
              currently just motor current readings
   #count,... which returns the number of ports configured; this
              is needed to properly parse #stat, and form commands

Each message will contain some kind of contextual information
about the message, particularly if a failure occurs.  The #OK
message will echo back the command that was accepted.

*** EOF: Protocol.txt
