Wiki source code of TCP Communication
Version 4.1 by nbw on 2014/07/05 12:13
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | |||
2 | |||
3 | {{status colour="Red" title="Work in progress - Might by subject to change"/}} | ||
4 | |||
5 | Both the controller and the client GUI send their data as JSON Objects. | ||
6 | In JSON every Object is an unordered set of key/value pairs. The values of these pairs can be a JSON Object, a JSON Array or a primitive value (integer, string, boolean or null). | ||
7 | For more information or a complete grammar see [[http:~~/~~/www.json.org/>>url:http://www.json.org/||shape="rect"]]. | ||
8 | |||
9 | == Messages sent by Controller == | ||
10 | |||
11 | * Every message must provide the keys **msgType** and **data**. | ||
12 | * Valid values for **msgType** are// log//, //error// or// status//. | ||
13 | |||
14 | === Log messages === | ||
15 | |||
16 | For //log// messages the **data** segment consists of a JSON Array, containing zero or more strings. | ||
17 | |||
18 | === Error messages === | ||
19 | |||
20 | For //error// messages the **data** segment consists of one single string, describing the error. | ||
21 | |||
22 | === Status messages === | ||
23 | |||
24 | In //status// messages the **data** segment is a JSON Object which must contain the following key/value pairs. | ||
25 | |||
26 | * **debug** - true if the controller is set to verbose debug output, false otherwise | ||
27 | * **cleanup** - true after cleanup mode has been engaged, false before that point | ||
28 | * **pause** - true while the controller is paused, false otherwise | ||
29 | * **trainCount** - an integer with the number of active trains on the railway | ||
30 | * **trains** - a JSON Array with the data of all trains, each entry is a JSON Object with these values\\ | ||
31 | ** **trainNum** - the individual controller number of the train | ||
32 | ** **spdSlow** - the integer PWM value of this train while driving slow | ||
33 | ** **spdCaution** - the integer PWM value of this train while driving caution | ||
34 | ** **spdNormal** - the integer PWM value of this train while driving normally | ||
35 | ** **currentIndex** -an integer describing the current position in the schedule | ||
36 | ** **schedule** - a JSON Array of integer values, representing the station tracks in the normal encoding (Hoermann API) | ||
37 | * **{{status colour="Yellow" title="Need to change this to enable KH-Reverse tracks"/}}locks** - a JSON Array containing the current value of the track permissions, ordered by the default encoding (Hoermann API) | ||
38 | |||
39 | {{code title="Sample status" language="js" collapse="true"}} | ||
40 | {"msgType":"status", | ||
41 | "data":{ | ||
42 | "debug":false, | ||
43 | "cleanup":false, | ||
44 | "pause":false, | ||
45 | "trainCount":8, | ||
46 | "trains":[ | ||
47 | {"trainNum":0, "spdSlow":40, "spdCaution":60, "spdNormal":100, "currentIndex":2, "schedule":[8, 10, 25, 29, 41, 43]}, | ||
48 | {"trainNum":1, "spdSlow":50, "spdCaution":70, "spdNormal":100, "currentIndex":0, "schedule":[8]}, | ||
49 | ... ], | ||
50 | "locks":[-1, -1, -1, 5, -1, -1, 2, 10, -1, -1, ..., -1]}} | ||
51 | {{/code}} |