Obsolete /
GDPJSThe GDP is no longer supported by the Accessors Framework. This page exists as a historical reference. This page is about using the GDP with JavaScript How to use the GDP Accessors with Node. InstallationTo use the shared libraries in the GDP JavaScript interface, you must have certain packages installed. If you are working from the Accessor svn repository, then run: accessors/web/gdp/adm/gdp-setup.sh If you installed the node_modules/@terraswarm/gdp/adm/gdp-setup.sh What worksAs of 8/22/16
See What is missing
TestingThe Node GDP accessor tests are based on CapeCode GDP Accessor tests, see CapeCode and the GDP The CapeCode Code Generator is run on the CapeCode .xml tests to generate tests in To run the tests,
See the individual files in Cape Code ExampleA Cape Code Model that reads from a log. When it is run, it uses the Java/GDP interface and produces the following on stdout: TestDisplay: foo (Thread[GDPLogRead,1,main]) Double clicking on the Blue AccessorCodeGenerator icon and then clicking on the generator button generates the following CompositeAccessor: exports.setup = function() { // This composite accessor was created by Cape Code. // To regenerate this composite accessor, run: // java -classpath $PTII ptolemy.cg.kernel.generic.accessor.AccessorCodeGenerator -language accessor $PTII/ptolemy/actor/lib/jjs/modules/gdp/test/GDPLogRead.xml // to edit the model, run: // $PTII/bin/vergil -capecode $PTII/ptolemy/actor/lib/jjs/modules/gdp/test/GDPLogRead.xml // Ports: GDPLogRead: ptolemy/cg/adapter/generic/accessor/adapters/ptolemy/actor/TypedCompositeActor.java // Start: GDPLogRead: ptolemy/cg/adapter/generic/accessor/adapters/org/terraswarm/accessor/JSAccessor.java var GDPLogRead = this.instantiate('GDPLogRead', 'gdp/GDPLogRead.js'); GDPLogRead.setParameter('logname', "GDPLogRead1"); // Start: TestSpontaneous: ptolemy/cg/adapter/generic/accessor/adapters/org/terraswarm/accessor/JSAccessor.java var TestSpontaneous = this.instantiate('TestSpontaneous', 'test/TestSpontaneous.js'); TestSpontaneous.setParameter('interval', 1000.0); // Start: TestDisplay: ptolemy/cg/adapter/generic/accessor/adapters/org/terraswarm/accessor/JSAccessor.java var TestDisplay = this.instantiate('TestDisplay', 'test/TestDisplay.js'); // Start: JavaScriptRamp: ptolemy/cg/adapter/generic/accessor/adapters/ptolemy/actor/lib/jjs/JavaScript.java // FIXME: See instantiate() in accessors/web/{$HOSTS_COMMON}/commonHost.js // We probably need to do something with the bindings. var JavaScriptRamp = new Accessor('JavaScriptRamp', '/** Output a sequence with a given step in values.\n *\n * @accessor test/TestRamp\n * @param init The value produced on its first iteration. The\n * initial default is 0.\n * @input trigger The trigger\n * @output output The output\n * @param step The amount by which the output is incremented. The\n * default is 1.\n * @author Christopher Brooks\n * @version $$Id: GDPLogRead.xml 74960 2016-07-20 15:05:03Z cxh $$\n */\nexports.setup = function() {\n // FIXME: this only supports numbers, unlike the Cape Code Ramp\n // actor, which supports many types.\n this.parameter(\'init\', {\'type\':\'number\', \'value\':0});\n this.input(\'trigger\');\n this.output(\'output\', {\'type\':\'number\'});\n this.parameter(\'step\', {\'type\':\'number\', \'value\':1});\n};\n\nvar _lastValue = 0;\n\nexports.initialize = function() {\n _lastValue = this.getParameter(\'init\');\n}\nexports.fire = function() {\n _lastValue += this.getParameter(\'step\');\n this.send(\'output\', _lastValue);\n};', null, null, null, null); JavaScriptRamp.container = this; this.containedAccessors.push(JavaScriptRamp); JavaScriptRamp.setParameter('init', 0); JavaScriptRamp.setParameter('step', 1); // Connections: GDPLogRead: ptolemy/cg/adapter/generic/accessor/adapters/ptolemy/actor/TypedCompositeActor.java this.connect(TestSpontaneous, 'output', GDPLogRead, 'trigger'); this.connect(JavaScriptRamp, 'output', GDPLogRead, 'recno'); this.connect(GDPLogRead, 'data', TestDisplay, 'input'); this.connect(TestSpontaneous, 'output', JavaScriptRamp, 'trigger'); } After clicking on generate, the dialog box contains: // Starting ptolemy.cg.kernel.generic.accessor.AccessorCodeGenerator {.GDPLogRead.AccessorCodeGenerator} code generation. Writing GDPLogRead.js in file:/Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/test/auto/ (3153 characters) In "/Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/test/auto", about to execute: node ../../../{$HOSTS_NODE}/nodeHostInvoke.js -timeout 6000 gdp/test/auto/GDPLogRead Reading accessor at: /Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/test/auto/GDPLogRead.js Reading accessor at: /Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/GDPLogRead.js Reading accessor at: /Users/cxh/ptII/org/terraswarm/accessor/accessors/web/test/TestSpontaneous.js Reading accessor at: /Users/cxh/ptII/org/terraswarm/accessor/accessors/web/test/TestDisplay.js Instantiated accessor GDPLogRead with class gdp/test/auto/GDPLogRead GDPLogRead.initialize() gdp.js: GDP() gdpjs/index.js: gdp_gcl_open(GDPLogRead1, 1) gdpjs/index.js: gdp_gcl_open(GDPLogRead1, 1): calling gdp_init_js() gdpjs/index.js: gdp_gcl_open(GDPLogRead1, 1): calling gdp_gcl_open() gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f gdpjs.js: gdpGclOpen gcliname: 32 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f GDPLogRead.initialize() done // Code generation complete. node_modules/gdp/gdp.js:read(1) gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 >>> recno 1, len 3, ts 2016-07-20T14:17:37.588347000Z 00000000 66 6f 6f f o o exiting with status OK [67896525 = 0x40c04cd] foo node_modules/gdp/gdp.js:read(2) gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 gdpjs.js: read_gcl_records(): do_multiread() or do_simpleread() is not ok WARNING: end of file [EPLIB:generic:3] node_modules/gdp/gdp.js:read(3) gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 gdpjs.js: read_gcl_records(): do_multiread() or do_simpleread() is not ok WARNING: end of file [EPLIB:generic:3] node_modules/gdp/gdp.js:read(4) gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 gdpjs.js: read_gcl_records(): do_multiread() or do_simpleread() is not ok WARNING: end of file [EPLIB:generic:3] node_modules/gdp/gdp.js:read(5) gdpjs.js: gdp_parse_name_js(): GDPLogRead1, gdpjs.js: gdp_parse_name_js(): GDPLogRead1, 854d1f3f2888dbbee867792720fbf3589d328443712231bb958cde82ff6ca4f Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 gdpjs.js: read_gcl_records(): do_multiread() or do_simpleread() is not ok WARNING: end of file [EPLIB:generic:3] nodeHostInvoke.js: Timeout of 6000 ms. has occurred. About to invoke wrapup(). All Done. The key thing is that the line foo appears Cape Code GDP Model to NodeBelow are the steps necessary to create a Composite Accessor that reads a GDP record Install Cape Code and the GDP
Start the GDP Daemons and initialize the log
As an alternative, if you are running linux (tested on ubuntu), you can also use a docker setup (requires bridge-utils and docker) to have your own log-server and router. The advantage of this is that you can have multiple instances of log-servers/routers, and everything is contained in the docker images. For details, see:
Build the GDP/JavaScript interface
Install the GDP/JavaScript interfaceThe JavaScript interface to the GDP is located in Modules may be installed either globally, which requires access to the root account, or locally. We install the module locally. To refer to our module, the JavaScript file contains: require('@terraswarm/gdp') When To install the interface, we use the
Note that a number of packages will be installed. The above will create bash-3.2$ ls -l $PTII/node_modules/@terraswarm/gdp total 40 -rw-r--r-- 1 cxh staff 2218 Jul 7 16:51 README.txt drwxr-xr-x 12 cxh staff 408 Jul 19 08:47 apps drwxr-xr-x 10 cxh staff 340 Jul 19 08:47 gdpjs -rw-r--r-- 1 cxh staff 6801 Jul 17 19:40 index.js drwxr-xr-x 6 cxh staff 204 Jul 19 08:47 libs -rw-r--r-- 1 cxh staff 4205 Jul 19 08:47 package.json bash-3.2$ You may ignore messages like: npm WARN enoent ENOENT: no such file or directory, open '/Users/cxh/ptII/package.json' If you want to get rid of those messages, create { "name": "mytest", "version": "6.6.6" } CapeCode
Invoking a Composite Accessor using just nodeWhen the Generate button was depressed, something similar to the following output should have appeared: Writing GDPLogRead.js in file:/Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/test/auto/ (3156 characters) In "/Users/cxh/ptII/org/terraswarm/accessor/accessors/web/gdp/test/auto", about to execute: node ../../../{$HOSTS_NODE}/nodeHostInvoke.js -timeout 6000 gdp/test/auto/GDPLogRead
Troubleshootinggdplogd and gdp_routerUse ps to check that the gdplogd and gdp_router daemons are working: bash-3.2$ ps auxgww | grep gdp cxh 20812 0.0 0.0 2453272 836 s003 S+ 7:52AM 0:00.00 grep gdp cxh 20799 0.0 0.0 2459344 2104 s003 S 7:51AM 0:00.01 /Users/cxh/ptII/vendors/gdp/gdp/gdplogd/gdplogd -F -N ealmac23.local cxh 20795 0.0 0.1 2496032 22608 s003 S 7:51AM 0:00.15 /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python ./src/gdp_router.py -l routerLog.txt bash-3.2$ If they are not running, then rerun the gdp-readerUse the gdp-reader binary to read from the log, see above. If you cannot open the GCL: bash-3.2$ ./apps/gdp-reader GDPLogRead1 Reading GCL hU0fPyiI277oZ3knIPvzBYnTKEQ3EiMbuVjN6C_2yk8 [ERROR] gdp-reader: Cannot open GCL: ERROR: 600 no route available [Berkeley:Swarm-GDP:600] exiting after 0 records with status ERROR: 600 no route available [Berkeley:Swarm-GDP:600] bash-3.2$ then perhaps the GCL was not yet created, see the How the Node/JavaScript/GDP interface worksWhen node is run on a Composite Accessor: (cd $PTII/org/terraswarm/accessor/accessors/web/gdp/test/auto/; node ../../../{$HOSTS_NODE}/nodeHostInvoke.js -timeout 6000 gdp/test/auto/GDPLogRead) The following occurs
How to make a GDP function available in JavaScriptFor testing purposes, it is easiest to edit the files in the
To access a C-based GDP API function from JavaScript, look for the method signature in For example, if we want to access the GDP var libep = ffi.Library(GDP_DIR + '/libs/libep.3.0', { ... 'ep_dbg_set': ['void', ['string']], }) .. exports.ep_dbg_set = libep.ep_dbg_set; The next step is to add the function to var gdpjsSupport = require(LIBGDP_H_DIR + 'gdpjs.js'); exports.ep_dbg_init = gdpjsSupport.ep_dbg_init; exports.ep_dbg_set = gdpjsSupport.ep_dbg_set; Then, we update the gdp module to include the call. For the node host, the gdp module is defined in var gdpjs = require('@terraswarm/gdp'); ... exports.GDP.prototype.setDebugLevel = function (debugLevel) { gdpjs.ep_dbg_set(debugLevel) } TroubleShootingCannot Read PropertyProblem: Error: TypeError: Cannot read property 'setDebugLevel' of undefined Solution: Make sure to instantiate the GDP object log = new GDP.GDP(logname, 2); Not log = GDP.GDP(logname, 2); See Also
|