Mhttpd.js: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
(The midas documentation has moved to https://midas.triumf.ca/docs/)
Tag: Replaced
 
(69 intermediate revisions by 3 users not shown)
Line 1: Line 1:
= About =
The midas documentation has moved. The new documentation about the midas JavaScript library is in:
 
* [https://midas.triumf.ca/docs/develop/api/javascript/ Midas JavaScript API] (overview of the libraries)
mhttpd.js contains javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive custom pages for MIDAS experiments.
* [https://midas.triumf.ca/docs/develop/api/javascript/midas/ midas.js] (the mjsonrpc_xxx JSON-RPC functions)
 
* [https://midas.triumf.ca/docs/develop/api/javascript/deprecated/#ajax-interface AJAX interface] on the Deprecated web features page (the old ODBGet(), ODBSet() etc. functions)
AJAX is a set of web development techniques used to construct interactive web applications:
* http://en.wikipedia.org/wiki/Ajax_(programming)
 
mhttpd.js is typically served by mhttpd from $MIDASSYS/resources/mhttpd.js
<pre>
<html>
<head>
...
<script src='mhttpd.js'></script>
...
</head>
...
</html>
</pre>
 
A mostly up to date copy of mhttpd.js is linked here:
* http://ladd00.triumf.ca/~daqweb/doc/midas/resources/mhttpd.js
* https://bitbucket.org/tmidas/midas/src/HEAD/resources/mhttpd.js?at=develop
 
An example for using all mhttpd.js functions is included in the MIDAS distribution under examples/javascript1:
 
* http://ladd00.triumf.ca/~daqweb/doc/midas/examples/javascript1/
* http://ladd00.triumf.ca/~daqweb/doc/midas/examples/javascript1/example.html
 
MIDAS AJAX functions can be accessed directly without using mhttpd.js wrappers (i.e. using the JSON-P script-tag method)
 
* [[AJAX]] - MIDAS AJAX functions
 
= Functions =
 
Helper functions:
 
* function getMouseXY(e)
* function XMLHttpRequestGeneric()
* function ODBExtractRecord(record, key)
* function ODBEdit(path)
* function ODBFinishInlineEdit(...)
* function ODBInlineEditKeydown(...)
* function ODBInlineEdit(...)
 
ODB access functions:
 
* function ODBSet(path, value, pwdname)
* function ODBGet(path, format, defval, len, type)
* function ODBMGet(paths, callback, formats)
* function ODBGetRecord(path)
* function ODBKey(path)
* function ODBCopy(path, format)
* function ODBMCopy(paths, callback, format)
 
MIDAS access functions:
 
* function ODBRpc_rev0(name, rpc, args)
* function ODBRpc_rev1(name, rpc, max_reply_length, args)
* function ODBGetMsg(n)
* function ODBGenerateMsg(m)
* function ODBGetAlarms()
 
= Summary table =
 
{| class="wikitable"
|+ Summary of mhttpd.js functions
| Function || XML || JSON || JSON-P || async || AJAX || URI encoding
|-
| ODBSet(path, value, pwdname) || no || no || no || no || [[AJAX#jset|cmd=jset]]
|-
|ODBGet(path, format, defval, len, type) || no || no || no || no || [[AJAX#jget|cmd=jget]]
|-
| ODBMGet(paths, callback, formats) || no || no || no || yes || [[AJAX#jget|cmd=jget]]
|-
| ODBGetRecord(path) || no || no || no || no || [[AJAX#jget|cmd=jget]] with "name=1"
|-
| ODBKey(path) || no || yes || no || no || [[AJAX#jkey|cmd=jkey]] || by caller
|-
| ODBCopy(path, format) || yes || yes || yes || no || [[AJAX#jcopy|cmd=jcopy]]
|-
| ODBMCopy(paths, callback, format) || yes || yes || yes || yes || [[AJAX#jcopy|cmd=jcopy]]
|-
| ODBRpc_rev0(name, rpc, args) || no || no || no || no || cmd=jrpc_rev0
|-
| ODBRpc_rev1(name, rpc, max_reply_length, args) || no || no || no || no || cmd=jrpc_rev1
|-
| ODBRpc(...) || yes || yes || yes || yes || cmd=jrpc
|-
| ODBGetMsg(n) || no || no || no || no || [[AJAX#jmsg|cmd=jmsg]] || not needed
|-
| ODBGenerateMsg(m) || no || no || no || no || [[AJAX#jgenmsg|cmd=jgenmsg]] || by caller
|-
| ODBGetAlarms() || no || no || no || no || [[AJAX#jalm|cmd=jalm]] || -
|}
 
= ODBSet =
 
http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbset
 
= ODBGet =
 
http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbget
 
* BUG: read the BUG sections in [[AJAX#jget]]
 
= ODBMGet =
 
Valid ODB path targets are: simple variables and arrays (specified as "/eq/foo/var/array[*]").
 
ODBMGet for subdirectories does not work (AJAX jget returns correct data, but incorrectly decoded by ODBMGet() javascript code).
 
ODBMGet for arrays specified without "[*]" is unknown.
 
http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbmget
 
* BUG: read the BUG sections in [[AJAX#jget]]
 
= ODBKey =
 
See: [[AJAX#jkey]]
 
Prototype:
* function ODBKey(path)
 
Arguments:
* path - ODB path, must be URI-encoded
 
Returns: javascript object with data fields corresponding to the data fields of MIDAS KEY (midas.h):
<pre>
{"name":"SLOW","type":"TID_DOUBLE","num_values":"3","item_size":"8","last_written":"1376633931"}
</pre>
 
Usage:
<pre>
var key = new ODBKey(encodeURIComponent("/Equipment/RpcExample/Variables/SLOW"));
document.getElementById('foo').innerHTML = "name: " + key.name + " type: " + key.type;
</pre>
 
= ODBCopy =
 
Usage:
<pre>
var data_json = ODBCopy("/Equipment/RpcExample/Variables", "json");
var obj = JSON.parse(data_json);
document.getElementById('json_data0').innerHTML = obj.SLOW[0];
</pre>
 
Return value:
<pre>
{
  "SLOW/key" : { "type" : 10, "num_values" : 3, "last_written" : 1376634320 },
  "SLOW" : [ 2357, 1376634320, -8.6602540236010100e+01 ]
}
</pre>
 
= ODBMCopy =
 
Usage:
 
<pre>
      var paths = [
      "/Equipment/deapvme01/Settings/EnableControl",
      "/Equipment/deapvme01/Settings/mainSwitch",
      "/Equipment/deapvme01/Readback/sysMainSwitch.0",
      "/Equipment/deapvme01/Variables",
      "/Equipment/deapvme02/Settings/EnableControl",
      "/Equipment/deapvme02/Settings/mainSwitch",
      "/Equipment/deapvme02/Readback/sysMainSwitch.0",
      "/Equipment/deapvme02/Variables",
      "/Equipment/deapvme03/Settings/EnableControl",
      "/Equipment/deapvme03/Settings/mainSwitch",
      "/Equipment/deapvme03/Readback/sysMainSwitch.0",
      "/Equipment/deapvme03/Variables",
      ];
 
      ODBMCopy(paths, load_callback, "json");
...
      function load_callback(data)
      {
      var obj = JSON.parse(data);
      document.getElementById('enableControl1').innerHTML = obj[0].EnableControl;
      document.getElementById('mainSwitch1').innerHTML = obj[1]['mainSwitch'] + " / " + obj[2]['sysMainSwitch.0'];
      document.getElementById('p5v1').innerHTML = obj[3].current[0];
...
</pre>
 
JSON data returned from ODBMCopy():
 
<pre>
[ { "EnableControl/key" : { "type" : 7, "last_written" : 1375145722 }, "EnableControl" : 1 } , { "mainSwitch/key" : { "type" : 7, "last_written" : 1376610870 }, "mainSwitch" : 1 } , { "sysMainSwitch.0/key" : { "type" : 7, "last_written" : 1376681747 }, "sysMainSwitch.0" : 1 } , { "switch/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681747 }, "switch" : [ 1, 1, 1 ], "status/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681747 }, "status" : [ 1, 1, 1 ], "demandVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681747 }, "demandVoltage" : [ 5, 12, 12 ], "senseVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681747 }, "senseVoltage" : [ 5.0500002e+00, 1.1980000e+01, 1.1990000e+01 ], "current/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681747 }, "current" : [ 9.0229996e+01, 4.2700000e+00, 5.9899998e+00 ], "sparkCount/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681747 }, "sparkCount" : [ 0, 0, 0 ], "sensorTemperature/key" : { "type" : 7, "num_values" : 8, "last_written" : 1376681747 }, "sensorTemperature" : [ -128, -128, 25, -128, -128, 25, -128, -128 ], "fanSpeed/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681747 }, "fanSpeed" : [ 3180, 3112, 3236 ] } , { "EnableControl/key" : { "type" : 7, "last_written" : 1375145722 }, "EnableControl" : 1 } , { "mainSwitch/key" : { "type" : 7, "last_written" : 1376603253 }, "mainSwitch" : 1 } , { "sysMainSwitch.0/key" : { "type" : 7, "last_written" : 1376681750 }, "sysMainSwitch.0" : 1 } , { "switch/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681750 }, "switch" : [ 1, 1, 1 ], "status/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681750 }, "status" : [ 1, 1, 1 ], "demandVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681750 }, "demandVoltage" : [ 5, 12, 12 ], "senseVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681750 }, "senseVoltage" : [ 5, 1.1950000e+01, 1.1980000e+01 ], "current/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681750 }, "current" : [ 1.4169999e+01, 1.1000000e+00, 8.0000001e-01 ], "sparkCount/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681750 }, "sparkCount" : [ 0, 0, 0 ], "sensorTemperature/key" : { "type" : 7, "num_values" : 8, "last_written" : 1376681750 }, "sensorTemperature" : [ -128, -128, -128, -128, -128, -128, -128, 22 ], "fanSpeed/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681750 }, "fanSpeed" : [ 3217, 3225, 3213 ] } , { "EnableControl/key" : { "type" : 7, "last_written" : 1375145722 }, "EnableControl" : 1 } , { "mainSwitch/key" : { "type" : 7, "last_written" : 1376596430 }, "mainSwitch" : 1 } , { "sysMainSwitch.0/key" : { "type" : 7, "last_written" : 1376681752 }, "sysMainSwitch.0" : 1 } , { "switch/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681752 }, "switch" : [ 1, 1, 1 ], "status/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681752 }, "status" : [ 1, 1, 1 ], "demandVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681752 }, "demandVoltage" : [ 5, 12, 12 ], "senseVoltage/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681752 }, "senseVoltage" : [ 4.9800000e+00, 1.2009999e+01, 1.1969999e+01 ], "current/key" : { "type" : 9, "num_values" : 3, "last_written" : 1376681752 }, "current" : [ 9.1139999e+01, 4.1999998e+00, 6.0300002e+00 ], "sparkCount/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681752 }, "sparkCount" : [ 0, 0, 0 ], "sensorTemperature/key" : { "type" : 7, "num_values" : 8, "last_written" : 1376681752 }, "sensorTemperature" : [ -128, -128, 24, -128, -128, 27, -128, -128 ], "fanSpeed/key" : { "type" : 7, "num_values" : 3, "last_written" : 1376681752 }, "fanSpeed" : [ 3153, 3067, 3180 ] } ]
</pre>
 
= ODBGetMsg =
 
See: [[AJAX#jmsg]]
 
Prototype:
* function ODBGetMsg(n)
 
Arguments:
* n - number of midas messages to return
 
Returns: array of strings, if n==1, as single string.
 
Usage:
<pre>
var data = ODBGetMsg(10);
document.getElementById("foo").innerHTML = data.join("\n");
</pre>
 
= ODBGenerateMsg =
 
See: [[AJAX#jgenmsg]]
 
Prototype:
* function ODBGenerateMsg(m)
 
Arguments:
* m - text written into midas messages, must be URI-encoded.
 
Usage:
<pre>
ODBGenerateMsg(encodeURIComponent("message text"));
</pre>
 
= ODBGetAlarms =
 
See: [[AJAX#jalm]]
 
Prototype:
* function ODBGetAlarms()
 
Returns: array of strings
 
Usage:
<pre>
var data = ODBGetAlarms();
document.getElementById("foo").innerHTML = data.join("\n");
</pre>

Latest revision as of 22:01, 30 October 2026

The midas documentation has moved. The new documentation about the midas JavaScript library is in: