treestructure

Building a Client for OPC-UA in Javascript

Martin Baum

OPC-What ?

Machine-2-Machine
connect embedded to enterprise world
abstraction layer
on IP level

Goals

OPC-UA specification

How does it work ?

Adress Space




Messages

Encodings

Requirements

Challanges

Binary Data in JS

Tools for handling Binary Data

var buffer = new ArrayBuffer(length);

var view  = new DataView(buffer);
var num = view.getInt32(31, true);
view.setFloat(127, 42.69, true);
view.setUint8(0,255, true);
view.setInt16(1,255, true);
// problematic
view.setFloat(127,true);
 
        

// typed array used like normal array
var list = new Int32Array(buffer); 
list[0] = 'wrong'; // throws exception
var 32bit = list[15];
// typed arrays offer array like behaviour
list.sort();
list.subarray();
list.map(function(){});
 
        

// receive as binary
var binReq = new XMLHttpRequest();
binReq.open('GET', 'binary/data/url');
binReq.responseType = "arraybuffer";
 
        

// send as binary - impossible in IE9
var sendData = new TypedArray(32);
getMessage(sendData);
binReq.open('POST', 'binary/data/url');
binReq.send(sndBuffer); 
 
        

// receiving in IE
new VBArray(xhrObj.responseBody).toArray();

[76, 67, 120, 27, 177, 0, 255,..........]

        

But now ?

Integer Format

IEEE 754

Numbers in Javascript

Bit Level Operators

Floatingpoints and Dataviews

Strings and Big Integer

Approach for parsing Binary

  1. Take n bytes from the dataview
  2. calculate value for Integer or Float
  3. Usage of Utf.js and BigInt.js for parsing Strings and 64 bit integers
  4. increment a bytecounter
  5. recursively build up cascading object tree based on message type

next challenge

Implement RSA-OAEP encryption for security relevant information
parsing server's public key

Javascript Cryptography

Conclusion

Thanks!

martin.baum@treestructure.net