servod: make multiservo operation easier to configure

This change adds the ability to configure servod using a text file,
and new command line options to support it.

The configuration file has the following format:
 - text starting with # is ignored til the end of line
 - empty lines are ignored
 - one per servo configuration lines consist of up to 4 comma
   separated fields (the last two fields are optional):
       servo-name, serial-number, port-number, board-name


     . servo-name - a user defined symbolic name, just a reference to
                    a certain servo board

     . serial-number - serial number of the servo board this line
                     pertains to

     . port-number - desired port number for servod for this board,
                     can be overridden by the command line switch
                     --port or environment variable setting

     . board-name - board configuration file to use, can be overridden
                    by the command line switch --board

The new command line options are:

   --rcfile (-r) the name of the rc file to use
       (/home/${USER}/.servodrc by default)

   --name (-n) name of the servo configuration to use.

When the servod command is run on a system with multiple servos
connected, it will try to connect to the servo as defined in the
configuration file, looking it up by the serial number.

When a single servo is connected to the host, configuration file could
still be useful, as it would allow to configure the servo to connect
to a particular board and run the daemon on a particular port passing
just one command line option to servod (--name).

This change also adds the ability to specify the configuration name
and port number through environment variables SERVOD_NAME and
SERVOD_PORT respectively. This would help to make sure that
dut-control (not yet being modified) automatically communicates with
the correct servo if used in the same terminal window, where these
environment variables are set and servod was started.

Specifying name and port in the servod command line take precedence
over specifying them in the environment, which in turn takes
precedence over specifying them in the servodrc file.

An example configuration file is being introduced as well.


  The test setup includes two servos as described in the example
  configuration file

 . run the following commands and verify that the expected servo is
   connected on the expected port:

   sudo servod -n pit-4gb -r /tmp/.servodrc
   sudo servod -n pit-2gb -r /tmp/.servodrc
   sudo servod -sn 868534-00014 -r /tmp/.servodrc
   sudo servod -sn 780735-00047 -r /tmp/.servodrc

 . leave just one of the two servos connected, try the same commands,
   observe commands succeed when the command line parameters match the
   connected servo

 . verify that connecting without specifying a config file works as

Change-Id: Icfd3d02a0184618ea42290ccd5408ba58fedb16a
Signed-off-by: Vadim Bendebury <>
2 files changed