| 1 | /**
|
|---|
| 2 | * @fileOverview
|
|---|
| 3 | * Documentation of dim namespace.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * @namespace
|
|---|
| 8 | *
|
|---|
| 9 | * Namespace for extension functions dealing with the DIM network.
|
|---|
| 10 | *
|
|---|
| 11 | * @author <a href="mailto:thomas.bretz@epfl.ch">Thomas Bretz</a>
|
|---|
| 12 | */
|
|---|
| 13 | var dim = { };
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * Sleep for a while. This can be used to just wait or give time
|
|---|
| 17 | * back to the operating system to produce less CPU load if the
|
|---|
| 18 | * main purpose of a loop is, e.g., to wait for something to happen.
|
|---|
| 19 | *
|
|---|
| 20 | * @param {Integer} [milliseconds=0]
|
|---|
| 21 | * Number of millliseconds to sleep. Note that even 0 will always
|
|---|
| 22 | * sleep at least one millisecond.
|
|---|
| 23 | *
|
|---|
| 24 | */
|
|---|
| 25 | dim.sleep = function() { /* [native code] */ }
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | *
|
|---|
| 29 | * Post a message into the dim log stream.
|
|---|
| 30 | *
|
|---|
| 31 | * It will be logged by the datalogger, displayed on the console
|
|---|
| 32 | * and in the smartfact web-gui.
|
|---|
| 33 | *
|
|---|
| 34 | * @param argument
|
|---|
| 35 | * Any kind of argument can be given. If it is not a String, it
|
|---|
| 36 | * is converted using the toString() member function.
|
|---|
| 37 | *
|
|---|
| 38 | * @param [. . .]
|
|---|
| 39 | * Any number of additional arguments. Each argument will appear in
|
|---|
| 40 | * a new line.
|
|---|
| 41 | *
|
|---|
| 42 | * @example
|
|---|
| 43 | * dim.print("Five="+5, "--- new line ---");
|
|---|
| 44 | *
|
|---|
| 45 | */
|
|---|
| 46 | dim.print = function() { /* [native code] */ }
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | *
|
|---|
| 50 | * Posts a message to the dim network with alarm severity.
|
|---|
| 51 | *
|
|---|
| 52 | * Similar to dim.print, but the message is posted to the network
|
|---|
| 53 | * with alarm severity. This means that it is displayed in red
|
|---|
| 54 | * and the smartfact web-gui will play an alarm sound.
|
|---|
| 55 | * The alarm state will stay valid (displayed in the web-gui) until it
|
|---|
| 56 | * is reset.
|
|---|
| 57 | *
|
|---|
| 58 | * @param argument
|
|---|
| 59 | * Any kind of argument can be given. If it is not a String, it
|
|---|
| 60 | * is converted using the toString() member function.
|
|---|
| 61 | *
|
|---|
| 62 | * @param [. . .]
|
|---|
| 63 | * Any number of additional arguments. Each argument will appear as
|
|---|
| 64 | * individual alarm.
|
|---|
| 65 | *
|
|---|
| 66 | * @example
|
|---|
| 67 | * dim.alarm("Alarm for 30 seconds!");
|
|---|
| 68 | * dim.sleep(30000);
|
|---|
| 69 | * dim.alarm();
|
|---|
| 70 | */
|
|---|
| 71 | dim.alarm = function() { /* [native code] */ }
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | *
|
|---|
| 75 | * Displays a message on the local console (only).
|
|---|
| 76 | *
|
|---|
| 77 | * @param argument
|
|---|
| 78 | * Any kind of argument can be given. If it is not a String, it
|
|---|
| 79 | * is converted using the toString() member function.
|
|---|
| 80 | *
|
|---|
| 81 | * @param [. . .]
|
|---|
| 82 | * Any number of additional arguments. Each argument will appear in
|
|---|
| 83 | * a new line.
|
|---|
| 84 | *
|
|---|
| 85 | * @example
|
|---|
| 86 | * dim.out("Five="+5, "--- new line ---");
|
|---|
| 87 | *
|
|---|
| 88 | */
|
|---|
| 89 | dim.out = function() { /* [native code] */ }
|
|---|
| 90 |
|
|---|
| 91 | /**
|
|---|
| 92 | *
|
|---|
| 93 | * Send a dim command to a dim client.
|
|---|
| 94 | *
|
|---|
| 95 | * @param {String} commandId
|
|---|
| 96 | * The command id is a string and usually compiles like
|
|---|
| 97 | * 'SERVER/COMMAND'
|
|---|
| 98 | *
|
|---|
| 99 | * @param argument
|
|---|
| 100 | * Any kind of argument can be given. Arguments are internally
|
|---|
| 101 | * converted into strings using toString() and processed as
|
|---|
| 102 | * if they were typed on th console.
|
|---|
| 103 | *
|
|---|
| 104 | * @param [. . .]
|
|---|
| 105 | * Any number of additional arguments.
|
|---|
| 106 | *
|
|---|
| 107 | * @example
|
|---|
| 108 | * dim.send('DRIVE_CONTROL/TRACK_SOURCE 0.5 180 "Mrk 421"');
|
|---|
| 109 | * dim.send('DRIVE_CONTROL/TRACK_SOURCE', 0.5, 180, 'Mrk 421');
|
|---|
| 110 | *
|
|---|
| 111 | * @returns
|
|---|
| 112 | * A boolean value is returned whether the command was succesfully
|
|---|
| 113 | * posted into the network or not. Note that true does by no means
|
|---|
| 114 | * mean that the command was sucessfully received or even processed.
|
|---|
| 115 | */
|
|---|
| 116 | dim.send = function() { /* [native code] */ }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Returns the state of the given server.
|
|---|
| 120 | *
|
|---|
| 121 | * @param {String} name
|
|---|
| 122 | * The name of the server of which you want to get the state.
|
|---|
| 123 | *
|
|---|
| 124 | * @throws
|
|---|
| 125 | * If number or type of arguments is wrong
|
|---|
| 126 | *
|
|---|
| 127 | * @returns {Object}
|
|---|
| 128 | * An object with the properties 'index' {Integer} and 'name' {String}
|
|---|
| 129 | * is returned if a connection to the server is established and
|
|---|
| 130 | * state information have been received, 'undefined' otherwise. If
|
|---|
| 131 | * the time of the last state change is available it is stored
|
|---|
| 132 | * in the 'property'. If a server disconnected, a valid object will
|
|---|
| 133 | * be returned, but without any properties.
|
|---|
| 134 | */
|
|---|
| 135 | dim.state = function(server, timeout) { /* [native code] */ }
|
|---|
| 136 |
|
|---|
| 137 | /**
|
|---|
| 138 | * Wait for the given state of a server.
|
|---|
| 139 | *
|
|---|
| 140 | * @param {String} name
|
|---|
| 141 | * The name of the server of which you want to wait for a state.
|
|---|
| 142 | * The name must not contain quotation marks.
|
|---|
| 143 | *
|
|---|
| 144 | * @param {String,Integer} state
|
|---|
| 145 | * The state you want to wait for. It can either be given as an Integer
|
|---|
| 146 | * or as the corresponding short name. If given as String it must
|
|---|
| 147 | * not contain quotation marks.
|
|---|
| 148 | *
|
|---|
| 149 | * @param {Integer} [timeout]
|
|---|
| 150 | * An optional timeout. If no timeout is given, waiting will not stop
|
|---|
| 151 | * until the condition is fulfilled. A timeout of 0 is allowed and
|
|---|
| 152 | * will essentially just check if the server is in this state or not.
|
|---|
| 153 | *
|
|---|
| 154 | * @throws
|
|---|
| 155 | * <li> If number or type of arguments is wrong
|
|---|
| 156 | * <li> If no connection to the server is established or no state
|
|---|
| 157 | * has been received yet. This is identical to dim.state()
|
|---|
| 158 | * returning 'undefined'.
|
|---|
| 159 | *
|
|---|
| 160 | * @returns {Boolean}
|
|---|
| 161 | * true if the state was achived within the timeout, false otherwise.
|
|---|
| 162 | */
|
|---|
| 163 | dim.wait = function() { /* [native code] */ }
|
|---|
| 164 |
|
|---|
| 165 | /**
|
|---|
| 166 | *
|
|---|
| 167 | * Callback in case of state changes.
|
|---|
| 168 | *
|
|---|
| 169 | * To install a callback in case the state of a server changes. set
|
|---|
| 170 | * the corresponding property of this array to a function. The argument
|
|---|
| 171 | * provided to the function is identical with the object returned
|
|---|
| 172 | * by dim.state(). In addition the name of the server is added
|
|---|
| 173 | * as the 'name' property and the comment sent with the state change
|
|---|
| 174 | * as 'comment' property. For the code executed, the same rules apply
|
|---|
| 175 | * than for a thread created with Thread.<P>
|
|---|
| 176 | *
|
|---|
| 177 | * If a state change is defined for a server for which no callback
|
|---|
| 178 | * has been set, the special entry '*' is checked.
|
|---|
| 179 | *
|
|---|
| 180 | *
|
|---|
| 181 | * @type Array[Function]
|
|---|
| 182 | *
|
|---|
| 183 | * @example
|
|---|
| 184 | * dim.onchange['*'] = function(state) { dim.out("State change from "+state.name+" received"); }
|
|---|
| 185 | * dim.onchange['DIM_CONTROL'] = function(state) { dim.out(JSON.stringify(state); }
|
|---|
| 186 | * ...
|
|---|
| 187 | * delete dim.onchange['DIM_CONTROL']; // to remove the callback
|
|---|
| 188 | *
|
|---|
| 189 | */
|
|---|
| 190 | dim.onchange = [];
|
|---|