Wiki source code of TCP Communication

Version 6.1 by nbw on 2014/07/05 12:40

Show last authors
1
2
3 {{toc/}}
4
5
6
7 {{status colour="Red" title="Work in progress - Might by subject to change"/}}
8
9 Both the controller and the client GUI send their data as JSON Objects.
10 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).
11 For more information or a complete grammar see [[http:~~/~~/www.json.org/>>url:http://www.json.org/||shape="rect"]].
12
13 == Messages sent by Controller ==
14
15 * Every message must provide the keys **msgType** and **data**.
16 * Valid values for **msgType** are// log//, //error// or// status//.
17
18 === Log messages ===
19
20 For //log// messages the **data** segment consists of a JSON Array, containing zero or more strings.
21
22 === Error messages ===
23
24 For //error// messages the **data** segment consists of one single string, describing the error.
25
26 === Status messages ===
27
28 In //status// messages the **data** segment is a JSON Object which must contain the following key/value pairs.
29
30 * **debug** - true if the controller is set to verbose debug output, false otherwise
31 * **cleanup** - true after cleanup mode has been engaged, false before that point
32 * **pause** - true while the controller is paused, false otherwise
33 * **trainCount** - an integer with the number of active trains on the railway
34 * **trains** - a JSON Array with the data of all trains, each entry is a JSON Object with these values\\
35 ** **trainNum** - the individual controller number of the train
36 ** **spdSlow** - the integer PWM value of this train while driving slow
37 ** **spdCaution** - the integer PWM value of this train while driving caution
38 ** **spdNormal** - the integer PWM value of this train while driving normally
39 ** **currentIndex** -an integer describing the current position in the schedule
40 ** **schedule** - a JSON Array of integer values, representing the station tracks in the normal encoding (Hoermann API)
41 * **{{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)
42
43 {{code title="Sample status" language="js" collapse="true"}}
44 {"msgType":"status",
45 "data":{
46 "debug":false,
47 "cleanup":false,
48 "pause":false,
49 "trainCount":8,
50 "trains":[
51 {"trainNum":0, "spdSlow":40, "spdCaution":60, "spdNormal":100, "currentIndex":2, "schedule":[8, 10, 25, 29, 41, 43]},
52 {"trainNum":1, "spdSlow":50, "spdCaution":70, "spdNormal":100, "currentIndex":0, "schedule":[8]},
53 ... ],
54 "locks":[-1, -1, -1, 5, -1, -1, 2, 10, -1, -1, ..., -1]}}
55 {{/code}}
56
57 == Messages received by controller ==
58
59 * Every message must contain the key **command**.
60 * Depending on the command, additional keys might be required.
61
62 === Valid commands ===
63
64 * //SHUTDOWN// - Causing the controller to end the program and close all sockets
65 * //LOGOUT// - Closing the connection, leaving the controller running
66 * //STATUS// - Poll for the current status, should trigger a status reply message
67 * //CLEANUP// - Start the cleanup procedure, sending the trains back to their home tacks
68 * //DEBUG// - enable or disable verbose output, must supply additional payload
69 ** **state** - boolean value, true if verbose output should be activated
70 * //PAUSE// - suspend or resume the controller, must supply additional payload
71 ** **state** - boolean value, true if controller should be suspended
72 * //LIGHT// - activate or deactivate the lights on the railway, must supply additional payload\\
73 ** **state** - boolean value, true if lights should be lit
74 * //WAIT// - Force a train to wait in the next station, must supply additional payload
75 ** **train** - integer train identification
76 * //START// - Force a waiting train to immediately abort the waiting timer, must supply additional payload
77 ** **train** - integer train identification
78 * //SCHEDULE// - Set the new schedule for a train, needs additional payload
79 ** **train** - integer train identification
80 ** **currentIndex** - current integer position in the schedule array
81 ** **tracks** - a JSON Array of integer values, representing the station tracks in the normal encoding (Hoermann API)
82 * //{{status colour="Yellow" title="Need to change this to enable KH-Reverse tracks"/}}SPEED// - Change the speed settings of a train, needs additional payload
83 ** **train** - integer train identification
84 ** **speeds** - JSON Array with three integer values (% class="confluence-link" %)spdSlow, spdCaution, spdNormal
85 * //TIME// - Change the waiting times for a train
86 ** **train** - integer train identification
87 ** **times** -
88
89 {{status colour="Yellow" title="Define a format for this"/}}