Skip to content

Commit 8dd595b

Browse files
refactor: check for mostSignificantByte/mostSignificantWord (Modbus) globally also
similar to contentType
1 parent 9855e50 commit 8dd595b

3 files changed

Lines changed: 59 additions & 10 deletions

File tree

packages/td-tools/src/util/asset-interface-description.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,32 @@ export class AssetInterfaceDescriptionUtil {
383383
return ""; // TODO what is the right value if information cannot be found
384384
}
385385

386+
private getModbusMostSignificantByteFromEndpointMetadata(
387+
endpointMetadata?: Record<string, unknown>
388+
): string | undefined {
389+
if (endpointMetadata?.value instanceof Array) {
390+
for (const v of endpointMetadata.value) {
391+
if (v.idShort === "modv_mostSignificantByte") {
392+
return v.value;
393+
}
394+
}
395+
}
396+
return undefined;
397+
}
398+
399+
private getModbusMostSignificantWordFromEndpointMetadata(
400+
endpointMetadata?: Record<string, unknown>
401+
): string | undefined {
402+
if (endpointMetadata?.value instanceof Array) {
403+
for (const v of endpointMetadata.value) {
404+
if (v.idShort === "modv_mostSignificantWord") {
405+
return v.value;
406+
}
407+
}
408+
}
409+
return undefined;
410+
}
411+
386412
private updateRootMetadata(thing: Thing, endpointMetadata?: Record<string, unknown>) {
387413
const securityDefinitions: {
388414
[k: string]: SecurityScheme;
@@ -441,6 +467,17 @@ export class AssetInterfaceDescriptionUtil {
441467
contentType: this.getContentTypeFromEndpointMetadata(vi.endpointMetadata),
442468
};
443469

470+
// special treatment for global definitions
471+
// besides contentType there is the AID possibility for mostSignificantByte and mostSignificantWord (Modbus)
472+
const mostSignificantByte = this.getModbusMostSignificantByteFromEndpointMetadata(vi.endpointMetadata);
473+
if (mostSignificantByte != null) {
474+
form["modv:mostSignificantByte"] = mostSignificantByte === "true" || mostSignificantByte === "1";
475+
}
476+
const mostSignificantWord = this.getModbusMostSignificantWordFromEndpointMetadata(vi.endpointMetadata);
477+
if (mostSignificantWord != null) {
478+
form["modv:mostSignificantWord"] = mostSignificantWord === "true" || mostSignificantWord === "1";
479+
}
480+
444481
if (addSecurity) {
445482
// XXX need to add security at form level at all ?
446483
logError("security at form level not added/present");

packages/td-tools/test/AssetInterfaceDescriptionTest.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ class AssetInterfaceDescriptionUtilTest {
238238
.to.eql("modbus+tcp://192.168.178.146:502/1/40020?quantity=16");
239239
expect(tdObj.properties.device_name.forms[0]).to.have.property("modv:function").to.eql("readHoldingRegisters");
240240
expect(tdObj.properties.device_name.forms[0]).to.have.property("modv:type").to.eql("string");
241-
expect(tdObj.properties.device_name.forms[0])
242-
.to.have.property("contentType")
243-
.to.eql("application/octet-stream");
241+
expect(tdObj.properties.device_name.forms[0]).to.have.property("contentType").to.eql("text/plain");
244242
expect(tdObj.properties.device_name.forms[0]).not.to.have.property("security");
245243

246244
// check property soc
@@ -400,6 +398,7 @@ class AssetInterfaceDescriptionUtilTest {
400398
let hasContentType = false;
401399
let hasModbusFunction = false;
402400
let hasModbusType = false;
401+
let hasModbusMostSignificantByte = false;
403402
for (const formEntry of propProperty.value) {
404403
if (formEntry.idShort === "href") {
405404
hasHref = true;
@@ -410,7 +409,9 @@ class AssetInterfaceDescriptionUtilTest {
410409
// expect(formEntry.value).to.equal("readproperty");
411410
} else if (formEntry.idShort === "contentType") {
412411
hasContentType = true;
413-
expect(formEntry.value).to.equal("application/octet-stream");
412+
// Note: It uses the global contentType (locally it was not set in the AID)
413+
expect(formEntry.value).to.equal("text/plain");
414+
// expect(formEntry.value).to.equal("application/octet-stream");
414415
} else if (formEntry.idShort === "modv_function") {
415416
// vs. "modv:function"
416417
hasModbusFunction = true;
@@ -419,13 +420,18 @@ class AssetInterfaceDescriptionUtilTest {
419420
// vs. "modv:type"
420421
hasModbusType = true;
421422
expect(formEntry.value).to.equal("string");
423+
} else if (formEntry.idShort === "modv_mostSignificantByte") {
424+
// vs. "modv:mostSignificantByte"
425+
hasModbusMostSignificantByte = true;
426+
expect(formEntry.value).to.equal("true");
422427
}
423428
}
424429
expect(hasHref).to.equal(true);
425430
expect(hasOp).to.equal(false);
426431
expect(hasContentType).to.equal(true);
427432
expect(hasModbusFunction).to.equal(true);
428433
expect(hasModbusType).to.equal(true);
434+
expect(hasModbusMostSignificantByte).to.equal(true); // global
429435
}
430436
}
431437
expect(hasType).to.equal(true);

packages/td-tools/test/util/inverterModbus.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@
9393
"value": "modbus+tcp://192.168.178.146:502/",
9494
"modelType": "Property"
9595
},
96+
{
97+
"idShort": "contentType",
98+
"valueType": "xs:string",
99+
"value": "text/plain",
100+
"modelType": "Property"
101+
},
102+
{
103+
"idShort": "modv_mostSignificantByte",
104+
"valueType": "xs:boolean",
105+
"value": "true",
106+
"modelType": "Property"
107+
},
96108
{
97109
"idShort": "security",
98110
"typeValueListElement": "ReferenceElement",
@@ -190,12 +202,6 @@
190202
"valueType": "xs:string",
191203
"value": "string",
192204
"modelType": "Property"
193-
},
194-
{
195-
"idShort": "contentType",
196-
"valueType": "xs:string",
197-
"value": "application/octet-stream",
198-
"modelType": "Property"
199205
}
200206
],
201207
"modelType": "SubmodelElementCollection"

0 commit comments

Comments
 (0)