Skip to content

Commit 8d7864e

Browse files
authored
Merge pull request DCC-EX#229 from DCC-EX/227-create-apicommand-syntax-pages
227 create apicommand syntax pages
2 parents 3e447f4 + dd750a7 commit 8d7864e

File tree

6 files changed

+158
-25
lines changed

6 files changed

+158
-25
lines changed

docs/developer-reference/api.rst

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
*************************
2+
API syntax documentation
3+
*************************
4+
5+
.. image:: ../_static/images/engineer-level.png
6+
:alt: Engineer Level
7+
:scale: 50%
8+
9+
.. sidebar:: On this page
10+
11+
.. contents::
12+
:depth: 1
13+
:local:
14+
15+
This page documents the API syntax and usage for CommandStation-EX.
16+
17+
The current API has resulted from a mix of new commands and commands inherited from the original DCC++ code base, and therefore there are some noted exceptions to the syntax, however all new commands and responses must conform to the correct syntax.
18+
19+
If you are looking for information on the WiThrottle protocol, you will find that documented on the `JMRI website <https://www.jmri.org/help/en/package/jmri/jmrit/withrottle/Protocol.shtml>`_.
20+
21+
For detailed information on the various commands and responses available with DCC++ EX, refer to the :doc:`/reference/software/command-reference` page.
22+
23+
Serial port and WiFi/Ethernet monitoring
24+
=========================================
25+
26+
The input collectors must monitor the serial ports on a byte by byte basis, look for a beginning "<" with ending ">", and ignore anything outside that before passing commands in for parsing.
27+
28+
The WiFI or ethernet collectors work on a per-transmission basis and the first byte of input determines whether the transmitted block gets sent for parsing as an API or WiThrottle command or response.
29+
30+
**Any input received that a throttle does not understand must be discarded and ignored.**
31+
32+
General API command usage and responses
33+
========================================
34+
35+
API commands are sent using the message format outlined below, with responses conforming to the same format.
36+
37+
Due to the nature of DCC++ EX being able to be operated by multiple throttles concurrently combined with the fact there is no unique throttle identifier, there is no guarantee that a response received directly after a command is sent is related. Care must be taken to take this into account.
38+
39+
To repeat from above, any input received that a throttle does not understand should be discarded and ignored.
40+
41+
Command responses
42+
__________________
43+
44+
Command responses should conform to the syntax standard to ensure they are processed correctly by throttles.
45+
46+
Broadcast responses
47+
____________________
48+
49+
Broadcast information is sent to all throttles along with WiThrottle responses on the understanding that throttles will discard and ignore any responses they do not understand.
50+
51+
It is mandatory that a throttle accepts and ignores a broadcast it doesn't understand.
52+
53+
Diagnostics and other responses
54+
________________________________
55+
56+
If diagnostic commands are enabled, these are sent to the USB serial port.
57+
58+
If you connect a throttle to the USB serial port, you will get these correctly wrapped but do not expect to understand them.
59+
60+
If, however, WiFi debug is enabled, or the <+> command is used, then the wrapping can no longer be guaranteed as the wifi traffic may contain "\*>".
61+
62+
General Message Format
63+
=======================
64+
65+
A DCC++EX API message consists of a leading "<" symbol, a single character OPCODE, zero to n parameters separated by spaces, and a terminating ">" symbol:
66+
67+
``<OPCODE Param1 Param2 … ParamX>``
68+
69+
Messages cannot be nested, and a second "<" inside a message constitutes a syntax error.
70+
71+
Error responses
72+
================
73+
74+
A command sent that is invalid or returns an error has a response of ``<X>``.
75+
76+
Memory limitations of prohibit more detailed error messages.
77+
78+
Parameter parsing sequence
79+
===========================
80+
81+
To obtain the parameters:
82+
83+
Obtain the OPCODE
84+
__________________
85+
86+
The first level of parsing is to obtain the single character, case sensitive OPCODE which is preceeded by a "<" character.
87+
88+
Obtain the parameters
89+
______________________
90+
91+
The second level of parsing takes the next non-blank parameter along with each blank separated parameter and turns them into integers. There are no decimal point or float inputs. A prefix "-" may be used.
92+
93+
Example command and response
94+
_____________________________
95+
96+
A simple example is sending an API command to retrieve the list of defined turnouts.
97+
98+
The command to retrieve the list of defined turnouts is ``<JT>``.
99+
100+
Using our syntax standard, "J" is the OPCODE, and "T" is the parameter.
101+
102+
The response for this command will look something like ``<jT 1 17>``.
103+
104+
Using our parsing sequence, we obtain the OPCODE "j", with the subsequent parameters being "T", "1", and "17".
105+
106+
Parameter values
107+
=================
108+
109+
Parameters containing "a-z", "A-Z", or "_" are hashed to create integers. Thus a command like <D WIFI ON> is internally identical to <D wifi on>.
110+
111+
The translation of parameters from text to integer is base10.
112+
113+
Exceptions
114+
___________
115+
116+
Due to legacy code and backwards compatibility requirements, there are two OPCODES that expect hexadecimal parameter values.
117+
118+
These are the ``<M>`` and ``<P>`` commands documented in the :ref:`reference/software/command-reference:send packet to the track` section of the Command Reference.

docs/developer-reference/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
****************************
2+
Developer and API reference
3+
****************************
4+
5+
This section contains detailed information relevant for those who wish to utilise DCC++ EX's API functions or develop integrated items such as throttles.
6+
7+
.. toctree::
8+
:maxdepth: 1
9+
10+
tech-reference
11+
api

docs/throttles/tech-reference.rst renamed to docs/developer-reference/tech-reference.rst

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
Technical Reference for Throttle Developers
33
********************************************
44

5+
.. image:: ../_static/images/engineer-level.png
6+
:alt: Engineer Level
7+
:scale: 50%
8+
9+
.. sidebar:: On this page
10+
11+
.. contents::
12+
:depth: 2
13+
:local:
14+
515
This page is intended to capture relevant information to assist those who develop throttles compatible with DCC++ EX.
616

717
Additional throttle commands
8-
_____________________________
18+
=============================
919

1020
Release 4.0.2 provides a number of additional throttle information commands that have been implemented to assist throttle authors to obtain information from the Command Station in order to implement turnout, route/automation, and roster features which are already found in the Withrottle implementations.
1121

1222
These commands are new and do not overlap with the existing commands (which are probably due to be obsoleted as they are over complex and unfit for purpose).
1323

14-
Throttle command summary:
15-
~~~~~~~~~~~~~~~~~~~~~~~~~
24+
Throttle command summary
25+
=========================
1626

1727
All throttle specific commands are summarised here, refer below for elaboration on the details with examples.
1828

@@ -46,8 +56,11 @@ All throttle specific commands are summarised here, refer below for elaboration
4656
- ``<l cabid slot speedbyte functionMap>``
4757
- Requests a deliberate update of cab speed/functions in the same format as the cab broadcast.
4858

59+
Detailed command reference
60+
===========================
61+
4962
Turnouts
50-
~~~~~~~~~
63+
_________
5164

5265
The conventional turnout definition commands and the ``<H>`` responses do not contain information about the turnout description which may have been provided in an EX-RAIL script. A turnout description is much more user friendly than the identifier (eg. T123), and having a list helps the throttle UI build a suitable set of buttons.
5366

@@ -72,7 +85,7 @@ Example responses:
7285
- Chris Harlow
7386

7487
Automations/Routes
75-
^^^^^^^^^^^^^^^^^^^
88+
___________________
7689

7790
A throttle needs to know which EX-RAIL Automations and Routes it can show the user.
7891

@@ -91,7 +104,7 @@ Example responses:
91104
* ``<jA 13 X>`` - Indicates ID 13 is not found.
92105

93106
What's the difference?
94-
+++++++++++++++++++++++
107+
^^^^^^^^^^^^^^^^^^^^^^^
95108

96109
A **ROUTE** is just a call to an EX-RAIL ROUTE, traditionally to set some turnouts or signals but can be used to perform any kind of EX-RAIL function, but is not expecting to know the loco ID.
97110

@@ -102,7 +115,7 @@ An **AUTOMATION** is a handoff of the last accessed loco ID to an EX-RAIL AUTOMA
102115
* An automation expects a start command with a cab ID, for example ``</START 13 3>``.
103116

104117
Roster Information
105-
^^^^^^^^^^^^^^^^^^^
118+
___________________
106119

107120
``<JR>`` - Requests a list of cab IDs from the roster.
108121

@@ -118,7 +131,7 @@ Example response:
118131
* ``<jR 200 "Thomas" "whistle/*bell/squeal/panic">`` - Returns the defined description "Thomas" with each defined function's name. Refer to the EX-RAIL ROSTER command for function map format.
119132

120133
Obtaining throttle status
121-
^^^^^^^^^^^^^^^^^^^^^^^^^^
134+
__________________________
122135

123136
``<t cabid>`` - Requests a deliberate update on the cab speed/functions in the same format as the cab broadcast.
124137

@@ -134,7 +147,7 @@ Where:
134147
* functionmap = Binary map of which functions are ON ( 1=F0, 2=F1, 3=F0&F1 etc.)
135148

136149
Commands to avoid
137-
__________________
150+
==================
138151

139152
* ``<f cab func1 func2>`` - Use ``<F cab function 1/0>`` instead.
140153
* ``<t slot cab speed dir>`` - Just drop the slot number .

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ Next see the :doc:`Get Started section <get-started/index>` or click next below.
136136
reference/index
137137
download/index
138138
projects/index
139+
developer-reference/index
139140
contributing/index
140141
roadmap/index
141142
support/index

docs/reference/software/command-reference.rst

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
DCC++ EX Command Reference
33
****************************
44

5+
.. sidebar:: On this page
6+
7+
.. contents::
8+
:depth: 1
9+
:local:
10+
511
This is a detailed reference. For a summary version, please see :doc:`Command Summary <command-summary>`
612

713
`CommandStation-EX <https://github.com/DCC-EX/CommandStation-EX>`_ Provides an Application Programming Interface (API) that other applications use to send simple text commands that can operate your Command Station. Several "front end" controllers are available or you can easily create your own. Here are some examples:
@@ -20,18 +26,6 @@ This reference explains the available command structure, and for commands that p
2026

2127
You can view and edit this code in the `Arduino IDE <https://www.arduino.cc/en/Main/Software>`_ or in `PlatformIO <https://github.com/DCC-EX/CommandStation-EX/blob/master/CONTRIBUTING.md>`_ Software from `GitHub <https://github.com/DCC-EX>`_. If you are new to we suggest you start with the `DCC++ EX Webpage <https://dcc-ex.com>`_.
2228

23-
24-
* :ref:`reference/software/command-reference:Track Power Commands`
25-
* :ref:`reference/software/command-reference:Engine Decoder (CAB) Operation Commands`
26-
* :ref:`reference/software/command-reference:Stationary Accessory Decoder & Turnout Commands`
27-
* :ref:`reference/software/command-reference:Sensors (Input) Commands`
28-
* :ref:`reference/software/command-reference:Outputs (DIO Pin) Commands`
29-
* :ref:`reference/software/command-reference:Storing and Erasing Turnouts, Sensors and Outputs in EEPROM`
30-
* :ref:`reference/software/command-reference:Engine Decoder Programming Commands`
31-
* :ref:`reference/software/command-reference:Diagnostic Commands`
32-
* :ref:`reference/software/command-reference:WiFi "AT" Commands`
33-
* :ref:`reference/software/command-reference:User Commands`
34-
3529
Track Power Commands
3630
=============================
3731

@@ -945,5 +939,3 @@ User Commands
945939
==============
946940

947941
``<U>`` Is reserved for user commands.
948-
949-
This is a detailed reference. For a summary version, please see :doc:`Command Summary <command-summary>`

docs/throttles/index.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ For an overview of throttles and how to choose one, please read the :doc:`Gettin
1717
digitrainspro
1818
srcpclient
1919
streamdeck
20-
tech-reference
21-

0 commit comments

Comments
 (0)