Mhttpd.js

From MidasWiki
Jump to navigation Jump to search

About

mhttpd.js contains javascript function wrappers for most MIDAS AJAX functions typically used for implementing interactive custom pages for MIDAS experiments.

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

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

  • 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

Summary of mhttpd.js functions
Function XML JSON JSON-P async AJAX URI encoding
ODBSet(path, value, pwdname) no no no no cmd=jset
ODBGet(path, format, defval, len, type) no no no no cmd=jget
ODBMGet(paths, callback, formats) no no no yes cmd=jget
ODBGetRecord(path) no no no no cmd=jget with "name=1"
ODBKey(path) no yes no no cmd=jkey by caller
ODBCopy(path, format) yes yes yes no cmd=jcopy
ODBMCopy(paths, callback, format) yes yes yes yes 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 cmd=jmsg not needed
ODBGenerateMsg(m) no no no no cmd=jgenmsg by caller
ODBGetAlarms() no no no no 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

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

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

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

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 ] } ]

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:

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

ODBGenerateMsg

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");