Mhttpd.js: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
No edit summary
 
(76 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Pagelinks}}
= Links =
* [[Mhttpd|mhttpd MIDAS web server]]
* [[Custom Page]]
* [[mjsonrpc|JSON-RPC functions]]
= About =
= About =


mhttpd.js contains javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive custom pages for MIDAS experiments.
{{File|name=mhttpd.js}} is a file containing javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive [[Custom Page]]s for MIDAS experiments.
Since January 2016, it also contains [[#JSON-RPC interface]] functions (see also [[mjsonrpc]]).


AJAX is a set of web development techniques used to construct interactive web applications:
AJAX is a set of web development techniques used to construct interactive web applications:
* http://en.wikipedia.org/wiki/Ajax_(programming)
* http://en.wikipedia.org/wiki/Ajax_(programming)


mhttpd.js is typically served by mhttpd from $MIDASSYS/resources/mhttpd.js
<div id="include js lib"></div>
{{File|name=mhttpd.js}} is typically served by [[mhttpd]] from {{Filepath|path=$MIDASSYS/resources/mhttpd.js}}, and is included into an html file as follows:
<pre>
<pre>
<html>
<html>
<head>
<head>
...
...
<script src='mhttpd.js'></script>
<script src='mhttpd.js'></script>
Line 19: Line 28:


A mostly up to date copy of mhttpd.js is linked here:
A mostly up to date copy of mhttpd.js is linked here:
* http://ladd00.triumf.ca/~daqweb/doc/midas/resources/mhttpd.js
* https://daq.triumf.ca/~daqweb/doc/midas-devel/resources/mhttpd.js
* https://bitbucket.org/tmidas/midas/src/HEAD/resources/mhttpd.js?at=develop
* 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:
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/
* https://daq.triumf.ca/~daqweb/doc/midas-devel/examples/javascript1/
* http://ladd00.triumf.ca/~daqweb/doc/midas/examples/javascript1/example.html
* https://daq.triumf.ca/~daqweb/doc/midas-devel/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)
MIDAS AJAX functions can be accessed directly without using mhttpd.js wrappers (i.e. using the JSON-P script-tag method)


* [[mjsonrpc]] - MIDAS JSON-RPC functions
* [[AJAX]] - MIDAS AJAX functions
* [[AJAX]] - MIDAS AJAX functions
By default, MIDAS AJAX functions assume that the web page was loaded from mhttpd and use relative URLs to access AJAX functions of the same mhttpd. If the web page is loaded from some other source, or needs to talk to a different mhttpd, use the ODBSetURL() function to set the base URL of the target mhttpd. Such cross-site access is normally blocked by web browsers, but recent versions of mhttpd implement the "cross-origin resource sharing" http header to permit such access.
= JSON-RPC interface =
The original AJAX interface to MIDAS is being replaced by a JSON-RPC based interface.
The Javascript functions for use with MIDAS will continue to be documented on this page.
For additional information about the JSON-RPC interface, see [[mjsonrpc]]


= Functions =
= Functions =
This is a partial list of available javascript functions.
For the full list, and for the full documentation, please go to the doxygen-generated documentation at https://daq.triumf.ca/~daqweb/doc/midas-devel/html/mhttpd_8js.html
Functions to access the MIDAS JSON-RPC API:
* function mjsonrpc_set_url (url) - set the URL of the MIDAS JSON-RPC server, if different from web page URL. Cross-site access is fully supported (see CORS).
* function mjsonrpc_call (method, params, id) - call arbitrary RPC method
* function mjsonrpc_start_program (name, id, callback, error_callback)
* function mjsonrpc_stop_program (name, unique, id, callback, error_callback)
* function mjsonrpc_db_get_values (paths, id, callback, error_callback) - read ODB values
* function mjsonrpc_db_paste (paths, values, id, callback, error_callback) - write ODB values
Functions listed below will be replaced by JSON-RPC functions and will become obsolete:


Helper functions:
Helper functions:


* function getMouseXY(e)
* function getMouseXY(e) --- removed Feb 2014
* function XMLHttpRequestGeneric()
* function XMLHttpRequestGeneric()
* function ODBExtractRecord(record, key)
* function ODBExtractRecord(record, key)
Line 42: Line 77:
* function ODBInlineEditKeydown(...)
* function ODBInlineEditKeydown(...)
* function ODBInlineEdit(...)
* function ODBInlineEdit(...)
* function ODBCall(...)


ODB access functions:
ODB access functions:


* function ODBSet(path, value, pwdname)
* function ODBSetURL(url_of_mhttpd) - set the URL of target mhttpd (if web page is loaded from different source)
* function ODBGet(path, format, defval, len, type)
* function ODBSet(path, value, pwdname) - write into ODB
* function ODBMGet(paths, callback, formats)
* function ODBMCopy(paths, callback, format) - read multiple ODB subtrees in ODB, XML or JSON format, asynchronously
* function ODBGetRecord(path)
* function ODBMLs(paths, callback) - return ODB directory listings (same as odbedit ls -l)
* function ODBKey(path)
 
* function ODBCopy(path, format)
Obsolete ODB access functions replaced by ODBMCopy():
* function ODBMCopy(paths, callback, format)
 
* function ODBGet(path, format, defval, len, type) - read from ODB
* function ODBMGet(paths, callback, formats) - read multiple ODB entries
* function ODBGetRecord(path) - read from ODB
* function ODBKey(path) - get the description of an ODB entry --- replaced by ODBMKey()
* function ODBCopy(path, format) - read an ODB subtree in ODB, XML or JSON format
 
ODB entries creation and modification:
 
* function ODBMCreate(paths, types, arraylengths, stringlengths, callback) - create multiple ODB entries using db_create_key(path, type)
* function ODBMResize(paths, arraylengths, stringlengths, callback) - resize multiple ODB arrays, including element size of strings and string arrays
* function ODBMKey(paths, callback) - read multiple ODB KEYs
* function ODBMDelete(paths, callback) - delete multiple ODB entries using db_delete_key(path)
* function ODBMRename(paths, names, callback) - rename multiple ODB entries using db_rename_key(path, name)
* function ODBMLink(paths, links, callback) - create symbolic links using db_create_link(link, path)
* function ODBMReorder(paths, indices, callback) - reorder ODB entries using db_reorder_key(path, index)


MIDAS access functions:
MIDAS access functions:


* function ODBRpc_rev0(name, rpc, args)
* function ODBRpc_rev0(name, rpc, args) --- replaced by ODBRpc()
* function ODBRpc_rev1(name, rpc, max_reply_length, args)
* function ODBRpc_rev1(name, rpc, max_reply_length, args) --- replaced by ODBRpc()
* function ODBGetMsg(n)
* function ODBRpc(name, command, args, callback, max_reply_length)
* function ODBGenerateMsg(m)
* **function ODBGetMsg(facility,start,number) - get midas messages from midas.log
* function ODBGetAlarms()
* function ODBGenerateMsg(m) - write a midas message
* function ODBGetAlarms() - get list of active alarms
 
;Note
: ** marks functions whose parameters have changed recently (August 2015)


= Summary table =
= Summary table =
;Notes
: "*" marks obsoleted functions. Please avoid using them for new designs.
: "**" marks functions whose parameters have changed recently (August 2015)


{| class="wikitable"
{| class="wikitable"
|+ Summary of mhttpd.js functions
|+ Summary of mhttpd.js functions
| Function || XML || JSON || JSON-P || async || AJAX
! Function !! XML !! JSON !! JSON-P !! async !! AJAX !! URI encoding !! replaced by (AJAX) !! replaced by (mjsonrpc)
|-
| *ODBSet(path, value, pwdname) || no || no || no || no || [[AJAX#jset|cmd=jset]] || by caller, except for "value" || ||mjsonrpc_db_paste
|-
| *ODBGet(path, format, defval, len, type) || no || no || no || no || [[AJAX#jget|cmd=jget]] || by caller, except for "format"||ODBMCopy ||mjsonrpc_db_get_values
|-
| *ODBMGet(paths, callback, formats) || no || no || no || yes || [[AJAX#jget|cmd=jget]] || by caller, including "formats"||ODBMCopy ||mjsonrpc_db_get_values
|-
| *ODBGetRecord(path) || no || no || no || no || [[AJAX#jget|cmd=jget]] with "name=1" || by caller||ODBMCopy ||mjsonrpc_db_get_values
|-
| *ODBKey(path) || no || yes || no || no || [[AJAX#jkey|cmd=jkey]] || by caller||ODBMKey|| mjsonrpc_db_ls
|-
| *ODBCopy(path, format) || yes || yes || yes || no || [[AJAX#jcopy|cmd=jcopy]] || by caller, except for "format"||ODBMCopy ||mjsonrpc_db_copy
|-
| ODBMCopy(paths, callback, format) || yes || yes || yes || yes || [[AJAX#jcopy|cmd=jcopy]] || internal || ||mjsonrpc_db_copy
|-
|-
| ODBSet(path, value, pwdname) || no || no || no || no || [[AJAX#jset|cmd=jset]]
| ODBMLs(paths, callback) || no || yes || yes || yes || [[AJAX#jcopy|cmd=jcopy]] || internal || ||mjsonrpc_db_ls
|-
|-
|ODBGet(path, format, defval, len, type) || no || no || no || no || [[AJAX#jget|cmd=jget]]
| ODBMCreate(paths, types, arraylengths, stringlengths, callback) || no || yes || yes || yes || [[AJAX#jcreate|cmd=jcreate]] || internal || ||mjsonrpc_db_create
|-
|-
| ODBMGet(paths, callback, formats) || no || no || no || yes || [[AJAX#jget|cmd=jget]]
| ODBMResize(paths, arraylengths, stringlengths, callback) || no || yes || yes || yes || [[AJAX#jresize|cmd=jresize]] || internal|| ||mjsonrpc_db_resize
|-
|-
| ODBGetRecord(path) || no || no || no || no || [[AJAX#jget|cmd=jget]] with "name=1"
| ODBMRename(paths, names, callback) || no || yes || yes || yes || [[AJAX#jrename|cmd=jrename]] || internal || ||
|-
|-
| ODBKey(path) || no || yes || no || no || [[AJAX#jkey|cmd=jkey]]
| ODBMKey(paths, callback) || no || yes || yes || yes || [[AJAX#jkey|cmd=jkey&encoding=json]] || internal || ||mjsonrpc_db_ls
|-
|-
| ODBCopy(path, format) || yes || yes || yes || no || [[AJAX#jcopy|cmd=jcopy]]
| ODBMDelete(paths, callback) || no || yes || yes || yes || [[AJAX#jdelete|cmd=jdelete]] || internal || ||
|-
|-
| ODBMcopy(paths, callback, format) || yes || yes || yes || yes || [[AJAX#jcopy|cmd=jcopy]]
| ODBMLink(paths, links, callback) || no || yes || yes || yes || [[AJAX#jlink|cmd=jlink]] || internal || ||
|-
|-
| ODBRpc_rev0(name, rpc, args) || no || no || no || no || cmd=jrpc_rev0
| ODBMReorder(paths, indices, callback) || no || yes || yes || yes || [[AJAX#jreorder|cmd=jreorder]] || internal || ||
|-
|-
| ODBRpc_rev1(name, rpc, max_reply_length, args) || no || no || no || no || cmd=jrpc_rev1
| *ODBRpc_rev0(name, rpc, args) || no || no || no || no || cmd=jrpc_rev0 || || ODBRpc ||mjsonrpc_call
|-
|-
| ODBRpc(...) || yes || yes || yes || yes || cmd=jrpc
| *ODBRpc_rev1(name, rpc, max_reply_length, args) || no || no || no || no || cmd=jrpc_rev1|| ODBRpc || ||mjsonrpc_call
|-
|-
| ODBGetMsg(n) || no || no || no || no || [[AJAX#jmsg|cmd=jmsg]]
| ODBRpc(...) || yes || yes || yes || yes || cmd=jrpc || || ||mjsonrpc_call
|-
|-
| ODBGenerateMsg(m) || no || no || no || no || [[AJAX#jgenmsg|cmd=jgenmsg]]
| **ODBGetMsg(n) || no || no || no || no || [[AJAX#jmsg|cmd=jmsg]] || not needed || ||
|-
|-
| ODBGetAlarms() || no || no || no || no || [[AJAX#jalm|cmd=jalm]]
| *ODBGenerateMsg(m) || no || no || no || no || [[AJAX#jgenmsg|cmd=jgenmsg]] || by caller|| ||mjsonrpc_cm_msg
|-
| ODBGetAlarms() || no || no || no || no || [[AJAX#jalm|cmd=jalm]] || -  || ||
|}
|}
= ODBSetURL =
Prototype:
* function ODBSetURL(url)
Arguments:
* url - URL of mhttpd we want to talk to.]
Returns: nothing
Example:
<pre>
ODBSetURL("http://localhost:8080/");
</pre>


= ODBSet =
= ODBSet =


http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbset
See: [[AJAX#jset]]
 
See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbset
 
Prototype:
* function ODBSet(path, value, pwdname)
 
Arguments:
* path - ODB path, must be URI-encoded
* value - value to write, must NOT be URI-encoded (encoding is done inside ODBSet())
* pwdname - see [[AJAX#jset]]
 
Returns: nothing
 
Error handling: issues an alert() if there are errors.
 
BUG: may call alert() and require user interaction.


= ODBGet =
= ODBGet =


http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbget
See: [[AJAX#jset]]
 
See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbget
 
Prototype:
* function ODBGet(path, format, defval, len, type)
 
Arguments:
* path - ODB path to read, must be URI-encoded
* format - sprintf format for the data, must NOT be URI-encoded
* defval - if ODB path does not exist, it is created using [[AJAX#jset]] with this value, must be URI-encoded. Disable this by using "undefined"
* len - data length for jset
* type - data type for jset


* BUG: read the BUG sections in [[AJAX#jget]]
* BUG: read the BUG sections in [[AJAX#jget]]


= ODBMGet =
= ODBMGet =
See: [[AJAX#jget]]
See:  http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbmget
Prototype:
* function ODBMGet(paths, callback, formats)
Arguments:
* paths - array of strings - ODB paths to read, must be URI-encoded
* callback - name of javascript function for asynchronous callback
* formats - array of strings - sprintf() format strings for each ODB path, see BUGS in [[AJAX#jget]], must by URI-encoded


Valid ODB path targets are: simple variables and arrays (specified as "/eq/foo/var/array[*]").
Valid ODB path targets are: simple variables and arrays (specified as "/eq/foo/var/array[*]").
Line 112: Line 242:
ODBMGet for arrays specified without "[*]" is unknown.
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]]
 
= ODBGetRecord =
 
See: [[AJAX#jget]] with parameter "name=1"
 
See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbgetrecord
 
Prototype:
* function ODBGetRecord(path)
 
Arguments:
* path - ODB path to read, must be URI-encoded
 
Returns:
* request.responseText
* use "function ODBExtractRecord(record, key)" to extract ODB values from data retuned by ODBGetRecord().
 
Valid ODB path targets are: simple variables, array elements ("/eq/foo/var/array[0]"), arrays (specified as "/eq/foo/var/array[*]") and subdirectories ("/experiment")
 
Usage:
<pre>
      var rec1 = ODBGetRecord(encodeURIComponent("/Equipment/RpcExample/Variables"));
      document.getElementById('foo').innerHTML = rec1;
      document.getElementById('bar').innerHTML = ODBExtractRecord(rec1, 'SLOW[2]');
</pre>


* BUG: read the BUG sections in [[AJAX#jget]]
* BUG: read the BUG sections in [[AJAX#jget]]
Line 118: Line 273:
= ODBKey =
= ODBKey =


(doc incomplete)
See: [[AJAX#jkey]]


http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbkey
Prototype:
* function ODBKey(path)


Usage:
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>
<pre>
var key = new ODBKey("/Equipment/RpcExample/Variables/SLOW");
{"name":"SLOW","type":"TID_DOUBLE","num_values":"3","item_size":"8","last_written":"1376633931"}
</pre>
</pre>


Returns a javascript object with data fields corresponding to the data fields of MIDAS KEY (midas.h):
Usage:
<pre>
<pre>
{"name":"SLOW","type":"TID_DOUBLE","num_values":"3","item_size":"8","last_written":"1376633931"}
var key = new ODBKey(encodeURIComponent("/Equipment/RpcExample/Variables/SLOW"));
document.getElementById('foo').innerHTML = "name: " + key.name + " type: " + key.type;
</pre>
</pre>


= ODBCopy =
= ODBCopy =
See: [[AJAX#jcopy]]
Prototype:
* function ODBCopy(path, format)
Arguments:
* path - ODB path, must be URI-encoded
* format - data format (same as "encoding"), must NOT be URI-encoded
Returns: request.responseText, use JSON.parse() to decode JSON data.


Usage:
Usage:
Line 150: Line 321:


= ODBMCopy =
= ODBMCopy =
See: [[AJAX#jcopy]]
Prototype:
* function ODBMCopy(paths, callback, encoding)
Arguments:
* paths - array of strings - odb paths to read
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
* encoding - requested data encoding - ODB, XML or JSON, see [[AJAX#jcopy]]
Returns:
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data


Usage:
Usage:
<pre>
<pre>
       var paths = [
       var paths = [
Line 185: Line 369:
[ { "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 ] } ]
[ { "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>
</pre>
= ODBMLs =
Description: return ODB directory listing with full ODB KEY information (same as odbedit ls -l). It uses the jcopy AJAX method with the JSON "norecurse" option. Same as with odbedit "ls -l", symlinks are followed and the linked-to values are reported, with the symlink path reported as "link" entry in the ODB KEY ("xxx/key") section.
See: [[AJAX#jcopy]]
Prototype:
* function ODBMLs(paths, callback)
Arguments:
* paths - array of strings - odb paths to report
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of JSON encoded ODB entries
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/", "/Test/noexistant", "/Experiment" ];
var data = ODBMLs(paths);
var obj = JSON.Parse(data);
</pre>
= ODBMCreate =
See: [[AJAX#jcreate]]
Prototype:
* function ODBMCreate(paths, types, arraylengths, stringlengths, callback)
Arguments:
* paths - array of strings - odb paths to create
* types - array of integers - midas data types of created keys (TID_INT, etc)
* arraylengths - array of integers - "undefined" - or array size to create
* stringlengths - array of integers - "undefined" - or array of lengths of strings to create
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of integers: status of db_create_key() for each element of "paths"
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ];
var types = [ TID_INT, 0, TID_STRING ];
ODBMCreate(paths, types);
</pre>
= ODBMResize =
See: [[AJAX#jresize]]
Prototype:
* function ODBMResize(paths, arraylengths, stringlengths, callback)
Arguments:
* paths - array of strings - odb paths to resize
* arraylengths - array of integers - new array size, use "0" for "no change"
* stringlengths - array of integers - new string length or new element length for string arrays, use "0" for "no change"
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of integers: status of db_set_num_values() for each element of "paths"
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ];
var arraylengths = [ 10, 0, 15 ];
var stringarrays = [ 0, 0, 16 ];
ODBMResize(paths, arraylengths, stringlengths);
</pre>
= ODBMKey =
See: [[AJAX#jkey]]
Prototype:
* function ODBMKey(paths, callback)
Arguments:
* paths - array of strings - odb paths to read ODB KEYs
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of ODB KEYs
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ];
var data = JSON.parse(ODBMKey(paths));
</pre>
Example:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar", "/Test/foofoo", "/Test/barlink", "/Test/foo10", "/Test/bar15" ];
var data = ODBMKey(paths);
xprint data;
[ { "name":"foo","type":7,"type_name":"TID_INT","num_values":1,"item_size":4,"last_written":0 }, { "/error":312 }, { "name":"bar","type":12,"type_name":"TID_STRING","num_values":1,"item_size":0,"last_written":0 }, { "/error":312 }, { "name":"bar","type":12,"type_name":"TID_STRING","num_values":1,"item_size":0,"last_written":0 }, { "name":"foo10","type":7,"type_name":"TID_INT","num_values":5,"item_size":4,"last_written":1380134916 }, { "name":"bar15","type":12,"type_name":"TID_STRING","num_values":7,"item_size":12,"last_written":1380134916 } ]
</pre>
= ODBMDelete =
See: [[AJAX#jdelete]]
Prototype:
* function ODBMDelete(paths, callback)
Arguments:
* paths - array of strings - odb paths to delete
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of integer: status of db_delete_key() for each element of "paths"
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ];
ODBMDelete(paths);
</pre>
= ODBMRename =
See: [[AJAX#jrename]]
Prototype:
* function ODBMRename(paths, names, callback)
Arguments:
* paths - array of strings - odb paths to rename
* names - array of strings - new names (subject to ODB limitation on key names)
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of integer: status of db_rename_key() for each element of "paths"
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ];
var names = [ "fooxxx", "zzz", "barxxx" ];
ODBMRename(paths, names);
</pre>
= ODBMLink =
See: [[AJAX#jlink]]
Prototype:
* function ODBMLink(paths, links, callback)
Arguments:
* paths - array of strings - odb paths create as symlinks
* links - array of strings - odb paths of existing odb entries that we link to
* callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
Returns:
* array of integer: status of db_create_link() for each element of "paths"
* synchronous: returns request.responseText, use JSON.parse() to decode JSON data
* asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data
Usage:
<pre>
var paths = [ "/Test/foolink", "/Test/barlink" ];
var links = [ "/Test/foo", "/Test/bar" ];
ODBMLink(paths, links);
</pre>


= ODBGetMsg =
= ODBGetMsg =
Gets message(s) from the MIDAS [[Message System]] or from the [[Chat Page|chat]].
The parameters of this command have been changed August 2015. See [[#odbgetmsg_old|below]] for older version.
Prototype:
* function ODBGetMsg(facility, start, number)
Arguments:
* facility - message facility in which messages are written
:  facility can be "midas" for normal messages or "chat" to load the chat messages
* start - start time (0=latest message)
:  the absolute time from when to retrieve messages. Time is defined in unix standard time, i.e. seconds since 1.1.1970. A value of zero has a special meaning of now.
* number - number of midas messages to return
Returns: array of strings, if number==1, a single string.
Usage:
Retrieve the last 100 messages:
var data = ODBGetMsg("midas",0,100);
document.getElementById("foo").innerHTML = data.join("\n");
Each message returned in a separate line in this code contains its UNIX time in the first position, e.g.
1449015258 01:14:18.006 2015/12/02 [SC Frontend,TALK] General alarm: COBRA SC quenched
Now the UNIX time stamp can be saved in the JavaScript code on the page, e.g.
last_tstamp = 1449015258
and in another call we can retrieve the additional 100 message which occurred BEFORE the previous block, i.e.
ODBGetMsg(midas, last_tstamp-1, 100)
The time stamping ensures that no message is lost between the two calls, even if the second call is made many seconds later than the first call. So start
means start searching for messages at the given UNIX timestamp, and go backwards for n messages.


See: [[AJAX::jmsg]]
The function ODBGetMsg returns an array of strings, with one entry per message. This way they can be easily parsed in JavaScript:
var msg = ODBGetMsg(midas, 0, 100);
for (i=0 ; i<msg.length ; i++)
    alert(msg[i]);
 
To see how individual messages are parsed and extracted see function ''msg_append(msg)'' in [[Mhttpd.js|MIDAS Javascript Library]].
 
 
<div style="font-size:90%; background-color:whitesmoke">
<div id="odbgetmsg_old"></div>
; ODBGetMsg (pre August 2015)
See: [[AJAX#jgenmsg]]
Prototype:
* function ODBGetMsg(n)
 
Arguments:
* n - number of midas messages to return


Returns: array of strings, if n==1, as single string.
Returns: array of strings, if n==1, as single string.


Usage:
Usage:
<pre>
var data = ODBGetMsg(10);
var data = ODBGetMsg(10);
document.getElementById("foo").innerHTML = data.join("\n");
document.getElementById("foo").innerHTML = data.join("\n");
 
</pre>
</div>
 
 
= ODBGenMsg =
Send a message to the MIDAS [[Message System]] or the [[Chat Page|Chat]].
 
The parameters of this command have been changed August 2015. See [[#odbgenmsg_old|below]] for older version.
 
Prototype:
 
* function ODBGenMsg(type, facility, user, msg)
 
Arguments:
* type -  midas message type, numerical value of one of MT_ERROR, MT_INFO, MT_DEBUG, MT_USER, as defined in midas.h.
: i.e. 1 for MT_ERROR, 2 for MT_INFO etc.
* facility - facility can be "midas" for the MIDAS message system, or "chat" for the chat message system
* user -  name of the user who generated the message
: The user name ends up in the message file inside the [] section to tag each message with an associated user name.
* message - text written into midas messages
 
Usage:
ODBGenerateMsg(2, midas, fred, "message text");
 


= ODBGenerateMsg =
<div style="font-size:90%; background-color:whitesmoke">
<div id="odbgenmsg_old"></div>
; ODBGenerateMsg (pre August 2015)


See: [[AJAX#jgenmsg]]
See: [[AJAX#jgenmsg]]
Prototype:
* function ODBGenerateMsg(m)
Arguments:
* m - text written into midas messages, must be URI-encoded.


Usage:
Usage:
Line 206: Line 646:
ODBGenerateMsg(encodeURIComponent("message text"));
ODBGenerateMsg(encodeURIComponent("message text"));
</pre>
</pre>
</div>


= ODBGetAlarms =
= ODBGetAlarms =


See: [[AJAX#jalm]]
See: [[AJAX#jalm]]
Prototype:
* function ODBGetAlarms()


Returns: array of strings
Returns: array of strings
Line 218: Line 662:
document.getElementById("foo").innerHTML = data.join("\n");
document.getElementById("foo").innerHTML = data.join("\n");
</pre>
</pre>
[[Category:Custom]] [[Category:Javascript library]] [[Category:Ajax]]

Latest revision as of 14:05, 26 January 2016


Links

About

mhttpd.js is a file containing javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive Custom Pages for MIDAS experiments. Since January 2016, it also contains #JSON-RPC interface functions (see also mjsonrpc).

AJAX is a set of web development techniques used to construct interactive web applications:

mhttpd.js is typically served by mhttpd from $MIDASSYS/resources/mhttpd.js, and is included into an html file as follows:

<html>
<head>

...
<script src='mhttpd.js'></script>
...
</head>
...
</html>

A mostly up to date copy of mhttpd.js is linked here:

An example for using all mhttpd.js functions is included in the MIDAS distribution under examples/javascript1:

MIDAS AJAX functions can be accessed directly without using mhttpd.js wrappers (i.e. using the JSON-P script-tag method)

  • mjsonrpc - MIDAS JSON-RPC functions
  • AJAX - MIDAS AJAX functions

By default, MIDAS AJAX functions assume that the web page was loaded from mhttpd and use relative URLs to access AJAX functions of the same mhttpd. If the web page is loaded from some other source, or needs to talk to a different mhttpd, use the ODBSetURL() function to set the base URL of the target mhttpd. Such cross-site access is normally blocked by web browsers, but recent versions of mhttpd implement the "cross-origin resource sharing" http header to permit such access.

JSON-RPC interface

The original AJAX interface to MIDAS is being replaced by a JSON-RPC based interface.

The Javascript functions for use with MIDAS will continue to be documented on this page.

For additional information about the JSON-RPC interface, see mjsonrpc

Functions

This is a partial list of available javascript functions.

For the full list, and for the full documentation, please go to the doxygen-generated documentation at https://daq.triumf.ca/~daqweb/doc/midas-devel/html/mhttpd_8js.html

Functions to access the MIDAS JSON-RPC API:

  • function mjsonrpc_set_url (url) - set the URL of the MIDAS JSON-RPC server, if different from web page URL. Cross-site access is fully supported (see CORS).
  • function mjsonrpc_call (method, params, id) - call arbitrary RPC method
  • function mjsonrpc_start_program (name, id, callback, error_callback)
  • function mjsonrpc_stop_program (name, unique, id, callback, error_callback)
  • function mjsonrpc_db_get_values (paths, id, callback, error_callback) - read ODB values
  • function mjsonrpc_db_paste (paths, values, id, callback, error_callback) - write ODB values

Functions listed below will be replaced by JSON-RPC functions and will become obsolete:

Helper functions:

  • function getMouseXY(e) --- removed Feb 2014
  • function XMLHttpRequestGeneric()
  • function ODBExtractRecord(record, key)
  • function ODBEdit(path)
  • function ODBFinishInlineEdit(...)
  • function ODBInlineEditKeydown(...)
  • function ODBInlineEdit(...)
  • function ODBCall(...)

ODB access functions:

  • function ODBSetURL(url_of_mhttpd) - set the URL of target mhttpd (if web page is loaded from different source)
  • function ODBSet(path, value, pwdname) - write into ODB
  • function ODBMCopy(paths, callback, format) - read multiple ODB subtrees in ODB, XML or JSON format, asynchronously
  • function ODBMLs(paths, callback) - return ODB directory listings (same as odbedit ls -l)

Obsolete ODB access functions replaced by ODBMCopy():

  • function ODBGet(path, format, defval, len, type) - read from ODB
  • function ODBMGet(paths, callback, formats) - read multiple ODB entries
  • function ODBGetRecord(path) - read from ODB
  • function ODBKey(path) - get the description of an ODB entry --- replaced by ODBMKey()
  • function ODBCopy(path, format) - read an ODB subtree in ODB, XML or JSON format

ODB entries creation and modification:

  • function ODBMCreate(paths, types, arraylengths, stringlengths, callback) - create multiple ODB entries using db_create_key(path, type)
  • function ODBMResize(paths, arraylengths, stringlengths, callback) - resize multiple ODB arrays, including element size of strings and string arrays
  • function ODBMKey(paths, callback) - read multiple ODB KEYs
  • function ODBMDelete(paths, callback) - delete multiple ODB entries using db_delete_key(path)
  • function ODBMRename(paths, names, callback) - rename multiple ODB entries using db_rename_key(path, name)
  • function ODBMLink(paths, links, callback) - create symbolic links using db_create_link(link, path)
  • function ODBMReorder(paths, indices, callback) - reorder ODB entries using db_reorder_key(path, index)

MIDAS access functions:

  • function ODBRpc_rev0(name, rpc, args) --- replaced by ODBRpc()
  • function ODBRpc_rev1(name, rpc, max_reply_length, args) --- replaced by ODBRpc()
  • function ODBRpc(name, command, args, callback, max_reply_length)
  • **function ODBGetMsg(facility,start,number) - get midas messages from midas.log
  • function ODBGenerateMsg(m) - write a midas message
  • function ODBGetAlarms() - get list of active alarms
Note
** marks functions whose parameters have changed recently (August 2015)

Summary table

Notes
"*" marks obsoleted functions. Please avoid using them for new designs.
"**" marks functions whose parameters have changed recently (August 2015)
Summary of mhttpd.js functions
Function XML JSON JSON-P async AJAX URI encoding replaced by (AJAX) replaced by (mjsonrpc)
*ODBSet(path, value, pwdname) no no no no cmd=jset by caller, except for "value" mjsonrpc_db_paste
*ODBGet(path, format, defval, len, type) no no no no cmd=jget by caller, except for "format" ODBMCopy mjsonrpc_db_get_values
*ODBMGet(paths, callback, formats) no no no yes cmd=jget by caller, including "formats" ODBMCopy mjsonrpc_db_get_values
*ODBGetRecord(path) no no no no cmd=jget with "name=1" by caller ODBMCopy mjsonrpc_db_get_values
*ODBKey(path) no yes no no cmd=jkey by caller ODBMKey mjsonrpc_db_ls
*ODBCopy(path, format) yes yes yes no cmd=jcopy by caller, except for "format" ODBMCopy mjsonrpc_db_copy
ODBMCopy(paths, callback, format) yes yes yes yes cmd=jcopy internal mjsonrpc_db_copy
ODBMLs(paths, callback) no yes yes yes cmd=jcopy internal mjsonrpc_db_ls
ODBMCreate(paths, types, arraylengths, stringlengths, callback) no yes yes yes cmd=jcreate internal mjsonrpc_db_create
ODBMResize(paths, arraylengths, stringlengths, callback) no yes yes yes cmd=jresize internal mjsonrpc_db_resize
ODBMRename(paths, names, callback) no yes yes yes cmd=jrename internal
ODBMKey(paths, callback) no yes yes yes cmd=jkey&encoding=json internal mjsonrpc_db_ls
ODBMDelete(paths, callback) no yes yes yes cmd=jdelete internal
ODBMLink(paths, links, callback) no yes yes yes cmd=jlink internal
ODBMReorder(paths, indices, callback) no yes yes yes cmd=jreorder internal
*ODBRpc_rev0(name, rpc, args) no no no no cmd=jrpc_rev0 ODBRpc mjsonrpc_call
*ODBRpc_rev1(name, rpc, max_reply_length, args) no no no no cmd=jrpc_rev1 ODBRpc mjsonrpc_call
ODBRpc(...) yes yes yes yes cmd=jrpc mjsonrpc_call
**ODBGetMsg(n) no no no no cmd=jmsg not needed
*ODBGenerateMsg(m) no no no no cmd=jgenmsg by caller mjsonrpc_cm_msg
ODBGetAlarms() no no no no cmd=jalm -

ODBSetURL

Prototype:

  • function ODBSetURL(url)

Arguments:

  • url - URL of mhttpd we want to talk to.]

Returns: nothing

Example:

ODBSetURL("http://localhost:8080/");

ODBSet

See: AJAX#jset

See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbset

Prototype:

  • function ODBSet(path, value, pwdname)

Arguments:

  • path - ODB path, must be URI-encoded
  • value - value to write, must NOT be URI-encoded (encoding is done inside ODBSet())
  • pwdname - see AJAX#jset

Returns: nothing

Error handling: issues an alert() if there are errors.

BUG: may call alert() and require user interaction.

ODBGet

See: AJAX#jset

See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbget

Prototype:

  • function ODBGet(path, format, defval, len, type)

Arguments:

  • path - ODB path to read, must be URI-encoded
  • format - sprintf format for the data, must NOT be URI-encoded
  • defval - if ODB path does not exist, it is created using AJAX#jset with this value, must be URI-encoded. Disable this by using "undefined"
  • len - data length for jset
  • type - data type for jset

ODBMGet

See: AJAX#jget

See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbmget

Prototype:

  • function ODBMGet(paths, callback, formats)

Arguments:

  • paths - array of strings - ODB paths to read, must be URI-encoded
  • callback - name of javascript function for asynchronous callback
  • formats - array of strings - sprintf() format strings for each ODB path, see BUGS in AJAX#jget, must by URI-encoded

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.

ODBGetRecord

See: AJAX#jget with parameter "name=1"

See: http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/RC_mhttpd_custom_ODB_access.html#RC_mhttpd_custom_odbgetrecord

Prototype:

  • function ODBGetRecord(path)

Arguments:

  • path - ODB path to read, must be URI-encoded

Returns:

  • request.responseText
  • use "function ODBExtractRecord(record, key)" to extract ODB values from data retuned by ODBGetRecord().

Valid ODB path targets are: simple variables, array elements ("/eq/foo/var/array[0]"), arrays (specified as "/eq/foo/var/array[*]") and subdirectories ("/experiment")

Usage:

      var rec1 = ODBGetRecord(encodeURIComponent("/Equipment/RpcExample/Variables"));
      document.getElementById('foo').innerHTML = rec1;
      document.getElementById('bar').innerHTML = ODBExtractRecord(rec1, 'SLOW[2]');

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):

{"name":"SLOW","type":"TID_DOUBLE","num_values":"3","item_size":"8","last_written":"1376633931"}

Usage:

var key = new ODBKey(encodeURIComponent("/Equipment/RpcExample/Variables/SLOW"));
document.getElementById('foo').innerHTML = "name: " + key.name + " type: " + key.type;

ODBCopy

See: AJAX#jcopy

Prototype:

  • function ODBCopy(path, format)

Arguments:

  • path - ODB path, must be URI-encoded
  • format - data format (same as "encoding"), must NOT be URI-encoded

Returns: request.responseText, use JSON.parse() to decode JSON data.

Usage:

var data_json = ODBCopy("/Equipment/RpcExample/Variables", "json");
var obj = JSON.parse(data_json);
document.getElementById('json_data0').innerHTML = obj.SLOW[0];

Return value:

{
  "SLOW/key" : { "type" : 10, "num_values" : 3, "last_written" : 1376634320 },
  "SLOW" : [ 2357, 1376634320, -8.6602540236010100e+01 ]
}

ODBMCopy

See: AJAX#jcopy

Prototype:

  • function ODBMCopy(paths, callback, encoding)

Arguments:

  • paths - array of strings - odb paths to read
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return
  • encoding - requested data encoding - ODB, XML or JSON, see AJAX#jcopy

Returns:

  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

      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];
...

JSON data returned from ODBMCopy():

[ { "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 ] } ]

ODBMLs

Description: return ODB directory listing with full ODB KEY information (same as odbedit ls -l). It uses the jcopy AJAX method with the JSON "norecurse" option. Same as with odbedit "ls -l", symlinks are followed and the linked-to values are reported, with the symlink path reported as "link" entry in the ODB KEY ("xxx/key") section.

See: AJAX#jcopy

Prototype:

  • function ODBMLs(paths, callback)

Arguments:

  • paths - array of strings - odb paths to report
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of JSON encoded ODB entries
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/", "/Test/noexistant", "/Experiment" ]; 
var data = ODBMLs(paths);
var obj = JSON.Parse(data);

ODBMCreate

See: AJAX#jcreate

Prototype:

  • function ODBMCreate(paths, types, arraylengths, stringlengths, callback)

Arguments:

  • paths - array of strings - odb paths to create
  • types - array of integers - midas data types of created keys (TID_INT, etc)
  • arraylengths - array of integers - "undefined" - or array size to create
  • stringlengths - array of integers - "undefined" - or array of lengths of strings to create
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of integers: status of db_create_key() for each element of "paths"
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ]; 
var types = [ TID_INT, 0, TID_STRING ]; 
ODBMCreate(paths, types);

ODBMResize

See: AJAX#jresize

Prototype:

  • function ODBMResize(paths, arraylengths, stringlengths, callback)

Arguments:

  • paths - array of strings - odb paths to resize
  • arraylengths - array of integers - new array size, use "0" for "no change"
  • stringlengths - array of integers - new string length or new element length for string arrays, use "0" for "no change"
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of integers: status of db_set_num_values() for each element of "paths"
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ]; 
var arraylengths = [ 10, 0, 15 ]; 
var stringarrays = [ 0, 0, 16 ];
ODBMResize(paths, arraylengths, stringlengths);

ODBMKey

See: AJAX#jkey

Prototype:

  • function ODBMKey(paths, callback)

Arguments:

  • paths - array of strings - odb paths to read ODB KEYs
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of ODB KEYs
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ]; 
var data = JSON.parse(ODBMKey(paths));

Example:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar", "/Test/foofoo", "/Test/barlink", "/Test/foo10", "/Test/bar15" ];
var data = ODBMKey(paths);
xprint data;
[ { "name":"foo","type":7,"type_name":"TID_INT","num_values":1,"item_size":4,"last_written":0 }, { "/error":312 }, { "name":"bar","type":12,"type_name":"TID_STRING","num_values":1,"item_size":0,"last_written":0 }, { "/error":312 }, { "name":"bar","type":12,"type_name":"TID_STRING","num_values":1,"item_size":0,"last_written":0 }, { "name":"foo10","type":7,"type_name":"TID_INT","num_values":5,"item_size":4,"last_written":1380134916 }, { "name":"bar15","type":12,"type_name":"TID_STRING","num_values":7,"item_size":12,"last_written":1380134916 } ]

ODBMDelete

See: AJAX#jdelete

Prototype:

  • function ODBMDelete(paths, callback)

Arguments:

  • paths - array of strings - odb paths to delete
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of integer: status of db_delete_key() for each element of "paths"
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ]; 
ODBMDelete(paths);

ODBMRename

See: AJAX#jrename

Prototype:

  • function ODBMRename(paths, names, callback)

Arguments:

  • paths - array of strings - odb paths to rename
  • names - array of strings - new names (subject to ODB limitation on key names)
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of integer: status of db_rename_key() for each element of "paths"
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foo", "/Test/noexistant", "/Test/bar" ]; 
var names = [ "fooxxx", "zzz", "barxxx" ];
ODBMRename(paths, names);

ODBMLink

See: AJAX#jlink

Prototype:

  • function ODBMLink(paths, links, callback)

Arguments:

  • paths - array of strings - odb paths create as symlinks
  • links - array of strings - odb paths of existing odb entries that we link to
  • callback - name of javascript function for asynchronous callback, or "undefined" for synchronous return

Returns:

  • array of integer: status of db_create_link() for each element of "paths"
  • synchronous: returns request.responseText, use JSON.parse() to decode JSON data
  • asynchronous: calls the callback function with a single argument set to request.responseText, use JSON.parse() to decode JSON data

Usage:

var paths = [ "/Test/foolink", "/Test/barlink" ]; 
var links = [ "/Test/foo", "/Test/bar" ];
ODBMLink(paths, links);


ODBGetMsg

Gets message(s) from the MIDAS Message System or from the chat.

The parameters of this command have been changed August 2015. See below for older version.

Prototype:

  • function ODBGetMsg(facility, start, number)

Arguments:

  • facility - message facility in which messages are written
facility can be "midas" for normal messages or "chat" to load the chat messages
  • start - start time (0=latest message)
the absolute time from when to retrieve messages. Time is defined in unix standard time, i.e. seconds since 1.1.1970. A value of zero has a special meaning of now.
  • number - number of midas messages to return

Returns: array of strings, if number==1, a single string.

Usage:

Retrieve the last 100 messages:

var data = ODBGetMsg("midas",0,100);
document.getElementById("foo").innerHTML = data.join("\n");

Each message returned in a separate line in this code contains its UNIX time in the first position, e.g.

1449015258 01:14:18.006 2015/12/02 [SC Frontend,TALK] General alarm: COBRA SC quenched

Now the UNIX time stamp can be saved in the JavaScript code on the page, e.g.

last_tstamp = 1449015258

and in another call we can retrieve the additional 100 message which occurred BEFORE the previous block, i.e.

ODBGetMsg(midas, last_tstamp-1, 100)

The time stamping ensures that no message is lost between the two calls, even if the second call is made many seconds later than the first call. So start means start searching for messages at the given UNIX timestamp, and go backwards for n messages.

The function ODBGetMsg returns an array of strings, with one entry per message. This way they can be easily parsed in JavaScript:

var msg = ODBGetMsg(midas, 0, 100);
for (i=0 ; i<msg.length ; i++)
   alert(msg[i]);

To see how individual messages are parsed and extracted see function msg_append(msg) in MIDAS Javascript Library.


ODBGetMsg (pre August 2015)

See: AJAX#jgenmsg Prototype:

  • function ODBGetMsg(n)

Arguments:

  • n - number of midas messages to return

Returns: array of strings, if n==1, as single string.

Usage:

var data = ODBGetMsg(10);
document.getElementById("foo").innerHTML = data.join("\n");


ODBGenMsg

Send a message to the MIDAS Message System or the Chat.

The parameters of this command have been changed August 2015. See below for older version.

Prototype:

  • function ODBGenMsg(type, facility, user, msg)

Arguments:

  • type - midas message type, numerical value of one of MT_ERROR, MT_INFO, MT_DEBUG, MT_USER, as defined in midas.h.
i.e. 1 for MT_ERROR, 2 for MT_INFO etc.
  • facility - facility can be "midas" for the MIDAS message system, or "chat" for the chat message system
  • user - name of the user who generated the message
The user name ends up in the message file inside the [] section to tag each message with an associated user name.
  • message - text written into midas messages

Usage:

ODBGenerateMsg(2, midas, fred, "message text");


ODBGenerateMsg (pre August 2015)

See: AJAX#jgenmsg

Prototype:

  • function ODBGenerateMsg(m)

Arguments:

  • m - text written into midas messages, must be URI-encoded.

Usage:

ODBGenerateMsg(encodeURIComponent("message text"));

ODBGetAlarms

See: AJAX#jalm

Prototype:

  • function ODBGetAlarms()

Returns: array of strings

Usage:

var data = ODBGetAlarms();
document.getElementById("foo").innerHTML = data.join("\n");