Skip to content

Commit

Permalink
update opcua modules - remove unnecessary data transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Sep 7, 2023
1 parent 949a7e1 commit 7e3bcea
Show file tree
Hide file tree
Showing 7 changed files with 2,218 additions and 1,521 deletions.
3,650 changes: 2,170 additions & 1,480 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@testdeck/mocha": "^0.1.2",
"@types/chai": "^4.2.18",
"@types/chai-as-promised": "^7.1.4",
"@types/lodash": "^4.14.197",
"@types/mocha": "^9.0.0",
"@types/node": "16.18.35",
"@types/readable-stream": "^2.3.13",
Expand Down
45 changes: 22 additions & 23 deletions packages/binding-opcua/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,28 @@
"@node-wot/td-tools": "0.8.8",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"node-opcua-address-space": "2.77.0",
"node-opcua-basic-types": "2.77.0",
"node-opcua-binary-stream": "2.77.0",
"node-opcua-buffer-utils": "2.77.0",
"node-opcua-client": "2.77.0",
"node-opcua-constants": "2.77.0",
"node-opcua-data-model": "2.77.0",
"node-opcua-data-value": "2.77.0",
"node-opcua-date-time": "2.77.0",
"node-opcua-debug": "2.77.0",
"node-opcua-extension-object": "2.77.0",
"node-opcua-factory": "2.77.0",
"node-opcua-json": "0.19.1",
"node-opcua-nodeid": "2.77.0",
"node-opcua-numeric-range": "2.77.0",
"node-opcua-pseudo-session": "2.77.0",
"node-opcua-pubsub-client": "0.19.1",
"node-opcua-service-browse": "2.77.0",
"node-opcua-service-translate-browse-path": "2.77.0",
"node-opcua-status-code": "2.77.0",
"node-opcua-types": "2.77.0",
"node-opcua-variant": "2.77.0",
"node-opcua": "2.77.0",
"node-opcua-address-space": "2.112.0",
"node-opcua-basic-types": "2.111.0",
"node-opcua-binary-stream": "2.110.0",
"node-opcua-buffer-utils": "2.110.0",
"node-opcua-client": "2.112.0",
"node-opcua-constants": "2.98.1",
"node-opcua-data-model": "2.112.0",
"node-opcua-data-value": "2.112.0",
"node-opcua-date-time": "2.111.0",
"node-opcua-debug": "2.110.0",
"node-opcua-extension-object": "2.112.0",
"node-opcua-factory": "2.112.0",
"node-opcua-json": "0.50.0",
"node-opcua-nodeid": "2.110.0",
"node-opcua-numeric-range": "2.112.0",
"node-opcua-pseudo-session": "2.112.0",
"node-opcua-service-browse": "2.112.0",
"node-opcua-service-translate-browse-path": "2.112.0",
"node-opcua-status-code": "2.110.0",
"node-opcua-types": "2.112.0",
"node-opcua-variant": "2.112.0",
"node-opcua": "2.112.0",
"rxjs": "5.5.11"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-opcua/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class OpcuaBinaryCodec implements ContentCodec {
const binaryStream = new BinaryStream(bytes);
const dataValue = new DataValue();
dataValue.decode(binaryStream);
return JSON.parse(JSON.stringify(opcuaJsonEncodeDataValue(dataValue, true)));
return opcuaJsonEncodeDataValue(dataValue, true);
}

valueToBytes(
Expand Down
4 changes: 2 additions & 2 deletions packages/binding-opcua/src/opcua-protocol-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { schemaDataValue } from "./codec";
import { FormElementProperty } from "wot-thing-description-types";
import { opcuaJsonEncodeVariant } from "node-opcua-json";
import { Argument, BrowseDescription, BrowseResult } from "node-opcua-types";
import { isGoodish, ReferenceTypeIds } from "node-opcua";
import { isGoodish2, ReferenceTypeIds } from "node-opcua";

const { debug } = createLoggers("binding-opcua", "opcua-protocol-client");

Expand Down Expand Up @@ -308,7 +308,7 @@ export class OPCUAProtocolClient implements ProtocolClient {
return statusCode;
});
debug(`writeResource: statusCode ${statusCode}`);
if (statusCode !== StatusCodes.Good && !isGoodish(statusCode)) {
if (statusCode !== StatusCodes.Good && !isGoodish2(statusCode, { treatUncertainAsBad: false })) {
throw new Error("Error in OPCUA Write : " + statusCode.toString());
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/binding-opcua/test/client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ describe("OPCUA Client", function () {
const codecSerDes = ContentSerdes.get();
codecSerDes.addCodec(new OpcuaJSONCodec());
});
after(async () => {
await opcuaServer.shutdown();
});

let client: OPCUAProtocolClient;
before(async function () {
Expand All @@ -51,6 +48,10 @@ describe("OPCUA Client", function () {
after(async () => {
await client.stop();
});
// server shall stop after client
after(async () => {
await opcuaServer.shutdown();
});

[
// 0
Expand Down
30 changes: 18 additions & 12 deletions packages/binding-opcua/test/full-opcua-thing-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ describe("Full OPCUA Thing Test", () => {
opcuaServer = await startServer();
endpoint = opcuaServer.getEndpointUrl();
debug(`endpoint = ${endpoint}`);

// ajdust TD to endpoint
thingDescription.base = endpoint;
(thingDescription.opcua as unknown as { endpoint: string }).endpoint = endpoint;
});
after(async () => {
await opcuaServer.shutdown();
Expand All @@ -327,20 +331,22 @@ describe("Full OPCUA Thing Test", () => {
let temperature = 10;
thing.setPropertyReadHandler("temperature", async () => temperature);

const expThing = thing as ExposedThing;
const readHandler = expThing.__propertyHandlers.get("temperature")?.readHandler;
if (!readHandler) {
expect.fail("must have a readHandler");
}
const temperatureCheck1 = await readHandler();
expect(temperatureCheck1).to.equal(10);

temperature = 100;
try {
const expThing = thing as ExposedThing;
const readHandler = expThing.__propertyHandlers.get("temperature")?.readHandler;
if (!readHandler) {
expect.fail("must have a readHandler");
}
const temperatureCheck1 = await readHandler();
expect(temperatureCheck1).to.equal(10);

const temperatureCheck2 = await readHandler();
expect(temperatureCheck2).to.equal(100);
temperature = 100;

await servient.shutdown();
const temperatureCheck2 = await readHandler();
expect(temperatureCheck2).to.equal(100);
} finally {
await servient.shutdown();
}
});

async function makeThing() {
Expand Down

0 comments on commit 7e3bcea

Please sign in to comment.