netkitty 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/codec/headers/Goose.d.ts +91 -0
- package/dist/lib/codec/headers/Goose.d.ts.map +1 -1
- package/dist/lib/codec/headers/Goose.js +423 -289
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts +7 -0
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts.map +1 -0
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.js +16 -0
- package/dist/lib/helper/NumberToBERBuffer.d.ts +1 -0
- package/dist/lib/helper/NumberToBERBuffer.d.ts.map +1 -1
- package/dist/lib/helper/NumberToBERBuffer.js +3 -1
- package/dist/lib/helper/NumberToBERHex.d.ts +1 -0
- package/dist/lib/helper/NumberToBERHex.d.ts.map +1 -1
- package/dist/lib/helper/NumberToBERHex.js +5 -1
- package/dist/lib/pcap/PcapReader.d.ts +2 -2
- package/dist/lib/pcap/PcapReader.d.ts.map +1 -1
- package/dist/tests/units/Codec.spec.js +11 -5
- package/package.json +1 -1
- package/src/lib/codec/headers/Goose.ts +466 -256
- package/src/lib/codec/lib/GetBERIntegerLengthFromBuffer.ts +12 -0
- package/src/lib/helper/NumberToBERBuffer.ts +2 -0
- package/src/lib/helper/NumberToBERHex.ts +4 -0
- package/src/lib/pcap/PcapReader.ts +2 -2
- package/src/tests/units/Codec.spec.ts +14 -5
|
@@ -13,6 +13,25 @@ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
|
13
13
|
const NumberToBERBuffer_1 = require("../../helper/NumberToBERBuffer");
|
|
14
14
|
const BufferToNumber_1 = require("../../helper/BufferToNumber");
|
|
15
15
|
const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
|
|
16
|
+
const GetBERIntegerLengthFromBuffer_1 = require("../lib/GetBERIntegerLengthFromBuffer");
|
|
17
|
+
var ItemDataType;
|
|
18
|
+
(function (ItemDataType) {
|
|
19
|
+
ItemDataType["Boolean"] = "Boolean";
|
|
20
|
+
ItemDataType["INT8"] = "INT8";
|
|
21
|
+
ItemDataType["INT16"] = "INT16";
|
|
22
|
+
ItemDataType["INT32"] = "INT32";
|
|
23
|
+
ItemDataType["INT64"] = "INT64";
|
|
24
|
+
ItemDataType["INT8U"] = "INT8U";
|
|
25
|
+
ItemDataType["INT16U"] = "INT16U";
|
|
26
|
+
ItemDataType["INT32U"] = "INT32U";
|
|
27
|
+
ItemDataType["FLOAT32"] = "FLOAT32";
|
|
28
|
+
ItemDataType["CODEDENUM"] = "CODED-ENUM";
|
|
29
|
+
ItemDataType["OCTETSTRING"] = "OCTET-STRING";
|
|
30
|
+
ItemDataType["VISIBLESTRING"] = "VISIBLE-STRING";
|
|
31
|
+
ItemDataType["TimeStamp"] = "TimeStamp";
|
|
32
|
+
ItemDataType["Quality"] = "Quality";
|
|
33
|
+
ItemDataType["Structure"] = "Structure";
|
|
34
|
+
})(ItemDataType || (ItemDataType = {}));
|
|
16
35
|
class Goose extends BaseHeader_1.BaseHeader {
|
|
17
36
|
constructor() {
|
|
18
37
|
super(...arguments);
|
|
@@ -109,16 +128,19 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
109
128
|
type: 'object',
|
|
110
129
|
label: 'GOOSE PDU',
|
|
111
130
|
decode: () => {
|
|
112
|
-
let
|
|
131
|
+
let readTLVBufferLength = this.packet.length - this.startPos - 8;
|
|
113
132
|
while (!this.TLVInstance) {
|
|
114
133
|
try {
|
|
115
|
-
const buffer = this.readBytes(8,
|
|
134
|
+
const buffer = this.readBytes(8, readTLVBufferLength, true);
|
|
116
135
|
this.TLVInstance = node_tlv_1.default.parse(buffer);
|
|
117
|
-
|
|
136
|
+
const tagWithLength = buffer.toString('hex').replace(this.TLVInstance.bValue.toString('hex'), '#').split('#');
|
|
137
|
+
const tagWithLengthBytes = Math.max(...tagWithLength.map((value) => Math.ceil(value.length / 2)));
|
|
138
|
+
const TLVBufferLength = this.TLVInstance.bValue.length + tagWithLengthBytes;
|
|
139
|
+
this.TLVInstance = node_tlv_1.default.parse(this.readBytes(8, TLVBufferLength, false));
|
|
118
140
|
}
|
|
119
141
|
catch (e) {
|
|
120
|
-
|
|
121
|
-
if (!
|
|
142
|
+
readTLVBufferLength -= 1;
|
|
143
|
+
if (!readTLVBufferLength)
|
|
122
144
|
break;
|
|
123
145
|
}
|
|
124
146
|
}
|
|
@@ -164,7 +186,7 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
164
186
|
},
|
|
165
187
|
timeAllowedtoLive: {
|
|
166
188
|
type: 'number',
|
|
167
|
-
minimum:
|
|
189
|
+
minimum: 0,
|
|
168
190
|
maximum: 4294967295,
|
|
169
191
|
label: 'TimeAllowedtoLive',
|
|
170
192
|
decode: () => {
|
|
@@ -252,7 +274,7 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
252
274
|
},
|
|
253
275
|
stNum: {
|
|
254
276
|
type: 'integer',
|
|
255
|
-
minimum:
|
|
277
|
+
minimum: 0,
|
|
256
278
|
maximum: 4294967295,
|
|
257
279
|
label: 'StNum',
|
|
258
280
|
decode: () => {
|
|
@@ -267,7 +289,7 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
267
289
|
let stNumValue = this.instance.goosePdu.stNum.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
268
290
|
if (stNumValue < 0)
|
|
269
291
|
return;
|
|
270
|
-
if (stNumValue
|
|
292
|
+
if (stNumValue > 4294967295) {
|
|
271
293
|
stNumValue = 4294967295;
|
|
272
294
|
this.recordError(this.instance.goosePdu.stNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
|
|
273
295
|
}
|
|
@@ -292,7 +314,7 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
292
314
|
let sqNumValue = this.instance.goosePdu.sqNum.getValue(-1, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
293
315
|
if (sqNumValue < 0)
|
|
294
316
|
return;
|
|
295
|
-
if (sqNumValue
|
|
317
|
+
if (sqNumValue > 4294967295) {
|
|
296
318
|
sqNumValue = 4294967295;
|
|
297
319
|
this.recordError(this.instance.goosePdu.sqNum.getPath(), 'This INTEGER value shall have a range of 1 to 4294967295');
|
|
298
320
|
}
|
|
@@ -386,36 +408,116 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
386
408
|
type: 'array',
|
|
387
409
|
label: 'AllData',
|
|
388
410
|
items: {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
'
|
|
401
|
-
'
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
'
|
|
408
|
-
'
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
411
|
+
anyOf: [
|
|
412
|
+
{
|
|
413
|
+
type: 'object',
|
|
414
|
+
properties: {
|
|
415
|
+
dataType: { type: 'string', enum: [ItemDataType.Boolean] },
|
|
416
|
+
value: { type: 'boolean' }
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
type: 'object',
|
|
421
|
+
properties: {
|
|
422
|
+
dataType: { type: 'string', enum: [ItemDataType.INT8] },
|
|
423
|
+
value: { type: 'integer' }
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
type: 'object',
|
|
428
|
+
properties: {
|
|
429
|
+
dataType: { type: 'string', enum: [ItemDataType.INT16] },
|
|
430
|
+
value: { type: 'integer' }
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
type: 'object',
|
|
435
|
+
properties: {
|
|
436
|
+
dataType: { type: 'string', enum: [ItemDataType.INT32] },
|
|
437
|
+
value: { type: 'integer' }
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
type: 'object',
|
|
442
|
+
properties: {
|
|
443
|
+
dataType: { type: 'string', enum: [ItemDataType.INT64] },
|
|
444
|
+
value: { type: 'string', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.BIGINT }
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
type: 'object',
|
|
449
|
+
properties: {
|
|
450
|
+
dataType: { type: 'string', enum: [ItemDataType.INT8U] },
|
|
451
|
+
value: { type: 'integer' }
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
type: 'object',
|
|
456
|
+
properties: {
|
|
457
|
+
dataType: { type: 'string', enum: [ItemDataType.INT16U] },
|
|
458
|
+
value: { type: 'integer' }
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
type: 'object',
|
|
463
|
+
properties: {
|
|
464
|
+
dataType: { type: 'string', enum: [ItemDataType.INT32U] },
|
|
465
|
+
value: { type: 'integer' }
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
{
|
|
469
|
+
type: 'object',
|
|
470
|
+
properties: {
|
|
471
|
+
dataType: { type: 'string', enum: [ItemDataType.FLOAT32] },
|
|
472
|
+
value: { type: 'number' }
|
|
473
|
+
}
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
type: 'object',
|
|
477
|
+
properties: {
|
|
478
|
+
dataType: { type: 'string', enum: [ItemDataType.CODEDENUM] },
|
|
479
|
+
value: { type: 'integer' }
|
|
480
|
+
}
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
type: 'object',
|
|
484
|
+
properties: {
|
|
485
|
+
dataType: { type: 'string', enum: [ItemDataType.OCTETSTRING] },
|
|
486
|
+
value: { type: 'string', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
type: 'object',
|
|
491
|
+
properties: {
|
|
492
|
+
dataType: { type: 'string', enum: [ItemDataType.VISIBLESTRING] },
|
|
493
|
+
value: { type: 'string', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.ASCII }
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: 'object',
|
|
498
|
+
properties: {
|
|
499
|
+
dataType: { type: 'string', enum: [ItemDataType.TimeStamp] },
|
|
500
|
+
value: { type: 'string' }
|
|
501
|
+
}
|
|
412
502
|
},
|
|
413
|
-
|
|
414
|
-
type: '
|
|
415
|
-
|
|
416
|
-
|
|
503
|
+
{
|
|
504
|
+
type: 'object',
|
|
505
|
+
properties: {
|
|
506
|
+
dataType: { type: 'string', enum: [ItemDataType.Quality] },
|
|
507
|
+
value: { type: 'string', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.BINARY }
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
type: 'object',
|
|
512
|
+
properties: {
|
|
513
|
+
dataType: { type: 'string', enum: [ItemDataType.Structure] },
|
|
514
|
+
value: {
|
|
515
|
+
type: 'array',
|
|
516
|
+
$ref: '#/properties/goosePdu/properties/allData'
|
|
517
|
+
}
|
|
518
|
+
}
|
|
417
519
|
}
|
|
418
|
-
|
|
520
|
+
]
|
|
419
521
|
},
|
|
420
522
|
/**
|
|
421
523
|
* +-----------------------------------+-------------------+-------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
@@ -441,264 +543,15 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
441
543
|
decode: () => {
|
|
442
544
|
const allDataTLV = this.TLVChild.find(tlv => tlv.getTag('number') === 0xAB);
|
|
443
545
|
const dataTLVs = allDataTLV ? allDataTLV.getChild() : [];
|
|
444
|
-
const allData =
|
|
445
|
-
dataTLVs.forEach((dataTLV) => {
|
|
446
|
-
const length = dataTLV.getLength('number');
|
|
447
|
-
const value = dataTLV.getValue('buffer');
|
|
448
|
-
const dataItem = {
|
|
449
|
-
dataType: '',
|
|
450
|
-
value: ''
|
|
451
|
-
};
|
|
452
|
-
switch (dataTLV.getTag('number')) {
|
|
453
|
-
case 0x83:
|
|
454
|
-
{
|
|
455
|
-
dataItem.dataType = 'Boolean';
|
|
456
|
-
dataItem.value = String(!!parseInt(value.toString('hex'), 16));
|
|
457
|
-
}
|
|
458
|
-
break;
|
|
459
|
-
case 0x84:
|
|
460
|
-
{
|
|
461
|
-
switch (length) {
|
|
462
|
-
case 2:
|
|
463
|
-
{
|
|
464
|
-
dataItem.dataType = 'CODED-ENUM';
|
|
465
|
-
dataItem.value = parseInt(value.toString('hex'), 16).toString();
|
|
466
|
-
}
|
|
467
|
-
break;
|
|
468
|
-
case 3:
|
|
469
|
-
{
|
|
470
|
-
dataItem.dataType = 'Quality';
|
|
471
|
-
dataItem.value = parseInt(value.toString('hex'), 16).toString(2).padStart(24, '0');
|
|
472
|
-
}
|
|
473
|
-
break;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
break;
|
|
477
|
-
case 0x85:
|
|
478
|
-
{
|
|
479
|
-
if (length === 2) {
|
|
480
|
-
{
|
|
481
|
-
dataItem.dataType = 'INT8';
|
|
482
|
-
dataItem.value = (0, HexToNumber_1.HexToInt8)(value.toString('hex')).toString();
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
else if (length === 3) {
|
|
486
|
-
{
|
|
487
|
-
dataItem.dataType = 'INT16';
|
|
488
|
-
dataItem.value = (0, HexToNumber_1.HexToInt16)(value.toString('hex')).toString();
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
else if (length === 5) {
|
|
492
|
-
{
|
|
493
|
-
dataItem.dataType = 'INT32';
|
|
494
|
-
dataItem.value = (0, HexToNumber_1.HexToInt32)(value.toString('hex')).toString();
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
else if (length === 9) {
|
|
498
|
-
{
|
|
499
|
-
dataItem.dataType = 'INT64';
|
|
500
|
-
dataItem.value = (0, HexToNumber_1.HexToInt64)(value.toString('hex')).toString();
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
break;
|
|
505
|
-
case 0x86:
|
|
506
|
-
{
|
|
507
|
-
switch (length) {
|
|
508
|
-
case 2:
|
|
509
|
-
{
|
|
510
|
-
dataItem.dataType = 'INT8U';
|
|
511
|
-
dataItem.value = (0, HexToNumber_1.HexToUInt8)(value.toString('hex')).toString();
|
|
512
|
-
}
|
|
513
|
-
break;
|
|
514
|
-
case 3:
|
|
515
|
-
{
|
|
516
|
-
dataItem.dataType = 'INT16U';
|
|
517
|
-
dataItem.value = (0, HexToNumber_1.HexToUInt16)(value.toString('hex')).toString();
|
|
518
|
-
}
|
|
519
|
-
break;
|
|
520
|
-
case 5:
|
|
521
|
-
{
|
|
522
|
-
dataItem.dataType = 'INT32U';
|
|
523
|
-
dataItem.value = (0, HexToNumber_1.HexToUInt32)(value.toString('hex')).toString();
|
|
524
|
-
}
|
|
525
|
-
break;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
break;
|
|
529
|
-
case 0x87:
|
|
530
|
-
{
|
|
531
|
-
dataItem.dataType = 'FLOAT32';
|
|
532
|
-
dataItem.value = (0, HexToNumber_1.HexToFloat32)(value.toString('hex')).toString();
|
|
533
|
-
}
|
|
534
|
-
break;
|
|
535
|
-
case 0x89:
|
|
536
|
-
{
|
|
537
|
-
dataItem.dataType = 'OCTET-STRING';
|
|
538
|
-
dataItem.value = value.toString('ascii');
|
|
539
|
-
}
|
|
540
|
-
break;
|
|
541
|
-
case 0x8a:
|
|
542
|
-
{
|
|
543
|
-
dataItem.dataType = 'VISIBLE-STRING';
|
|
544
|
-
dataItem.value = value.toString('ascii');
|
|
545
|
-
}
|
|
546
|
-
break;
|
|
547
|
-
case 0x91:
|
|
548
|
-
{
|
|
549
|
-
dataItem.dataType = 'TimeStamp';
|
|
550
|
-
dataItem.value = parseInt(value.toString('hex'), 16).toString();
|
|
551
|
-
}
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
if (!dataItem.dataType)
|
|
555
|
-
return;
|
|
556
|
-
allData.push(dataItem);
|
|
557
|
-
});
|
|
546
|
+
const allData = this.decodeDataTLVItem(dataTLVs);
|
|
558
547
|
if (allData.length)
|
|
559
548
|
this.instance.goosePdu.allData.setValue(allData);
|
|
560
549
|
},
|
|
561
550
|
encode: () => {
|
|
562
551
|
const allData = this.instance.goosePdu.allData.getValue([], (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
563
|
-
const dataItemTLVs = allData
|
|
564
|
-
.map((dataItem, index) => {
|
|
565
|
-
const errorNodePath = this.instance.goosePdu.allData.getPath(index);
|
|
566
|
-
dataItem.value = dataItem.value.trim();
|
|
567
|
-
switch (dataItem.dataType) {
|
|
568
|
-
case 'Boolean': {
|
|
569
|
-
const availableStringValues = ['FALSE', 'TRUE'];
|
|
570
|
-
const stringValue = dataItem.value.toUpperCase();
|
|
571
|
-
let booleanIntValue = 0;
|
|
572
|
-
if (availableStringValues.includes(stringValue)) {
|
|
573
|
-
booleanIntValue = availableStringValues.indexOf(stringValue);
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
this.recordError(errorNodePath, 'Invalid Boolean value');
|
|
577
|
-
}
|
|
578
|
-
return new node_tlv_1.default(0x83, Buffer.from(booleanIntValue.toString(16).padStart(2, '0'), 'hex'));
|
|
579
|
-
}
|
|
580
|
-
case 'INT8': {
|
|
581
|
-
let intValue = parseInt(dataItem.value);
|
|
582
|
-
if (isNaN(intValue))
|
|
583
|
-
this.recordError(errorNodePath, 'Invalid INT8 value');
|
|
584
|
-
intValue = intValue ? intValue : 0;
|
|
585
|
-
if (intValue < -128 || intValue > 127)
|
|
586
|
-
this.recordError(errorNodePath, 'Invalid INT8 value');
|
|
587
|
-
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int8ToBERHex)(intValue).padStart(2 * 2, '0'), 'hex'));
|
|
588
|
-
}
|
|
589
|
-
case 'INT16': {
|
|
590
|
-
let intValue = parseInt(dataItem.value);
|
|
591
|
-
if (isNaN(intValue))
|
|
592
|
-
this.recordError(errorNodePath, 'Invalid INT16 value');
|
|
593
|
-
intValue = intValue ? intValue : 0;
|
|
594
|
-
if (intValue < -32768 || intValue > 32767)
|
|
595
|
-
this.recordError(errorNodePath, 'Invalid INT16 value');
|
|
596
|
-
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int16ToBERHex)(intValue).padStart(3 * 2, '0'), 'hex'));
|
|
597
|
-
}
|
|
598
|
-
case 'INT32': {
|
|
599
|
-
let intValue = parseInt(dataItem.value);
|
|
600
|
-
if (isNaN(intValue))
|
|
601
|
-
this.recordError(errorNodePath, 'Invalid INT32 value');
|
|
602
|
-
intValue = intValue ? intValue : 0;
|
|
603
|
-
if (intValue < -2147483648 || intValue > 2147483647)
|
|
604
|
-
this.recordError(errorNodePath, 'Invalid INT32 value');
|
|
605
|
-
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int32ToBERHex)(intValue).padStart(5 * 2, '0'), 'hex'));
|
|
606
|
-
}
|
|
607
|
-
case 'INT64': {
|
|
608
|
-
const intValue = BigInt(dataItem.value);
|
|
609
|
-
if (intValue < BigInt('-9223372036854775808') || intValue > BigInt('9223372036854775807'))
|
|
610
|
-
this.recordError(errorNodePath, 'Invalid INT64 value');
|
|
611
|
-
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int64ToBERHex)(intValue).padStart(9 * 2, '0'), 'hex'));
|
|
612
|
-
}
|
|
613
|
-
case 'INT8U': {
|
|
614
|
-
let uintValue = parseInt(dataItem.value);
|
|
615
|
-
if (isNaN(uintValue))
|
|
616
|
-
this.recordError(errorNodePath, 'Invalid INT8U value');
|
|
617
|
-
uintValue = uintValue ? uintValue : 0;
|
|
618
|
-
if (uintValue < 0 || uintValue > 255)
|
|
619
|
-
this.recordError(errorNodePath, 'Invalid INT8U value');
|
|
620
|
-
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt8ToBERHex)(uintValue).padStart(2 * 2, '0'), 'hex'));
|
|
621
|
-
}
|
|
622
|
-
case 'INT16U': {
|
|
623
|
-
let uintValue = parseInt(dataItem.value);
|
|
624
|
-
if (isNaN(uintValue))
|
|
625
|
-
this.recordError(errorNodePath, 'Invalid INT16U value');
|
|
626
|
-
uintValue = uintValue ? uintValue : 0;
|
|
627
|
-
if (uintValue < 0 || uintValue > 65535)
|
|
628
|
-
this.recordError(errorNodePath, 'Invalid INT16U value');
|
|
629
|
-
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(uintValue).padStart(3 * 2, '0'), 'hex'));
|
|
630
|
-
}
|
|
631
|
-
case 'INT32U': {
|
|
632
|
-
let uintValue = parseInt(dataItem.value);
|
|
633
|
-
if (isNaN(uintValue))
|
|
634
|
-
this.recordError(errorNodePath, 'Invalid INT32U value');
|
|
635
|
-
uintValue = uintValue ? uintValue : 0;
|
|
636
|
-
if (uintValue < 0 || uintValue > 4294967295)
|
|
637
|
-
this.recordError(errorNodePath, 'Invalid INT32U value');
|
|
638
|
-
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt32ToBERHex)(uintValue).padStart(5 * 2, '0'), 'hex'));
|
|
639
|
-
}
|
|
640
|
-
case 'FLOAT32': {
|
|
641
|
-
let float32Value = parseFloat(dataItem.value);
|
|
642
|
-
if (isNaN(float32Value))
|
|
643
|
-
this.recordError(errorNodePath, 'Invalid FLOAT32 value');
|
|
644
|
-
float32Value = float32Value ? float32Value : 0;
|
|
645
|
-
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToHex_1.Float32ToHex)(float32Value).padStart(4 * 2, '0'), 'hex'));
|
|
646
|
-
}
|
|
647
|
-
case 'CODED-ENUM': {
|
|
648
|
-
let codedEnumValue = parseInt(dataItem.value);
|
|
649
|
-
if (isNaN(codedEnumValue))
|
|
650
|
-
this.recordError(errorNodePath, 'Invalid CODED-ENUM value');
|
|
651
|
-
codedEnumValue = codedEnumValue ? codedEnumValue : 0;
|
|
652
|
-
return new node_tlv_1.default(0x84, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(codedEnumValue).padStart(2 * 2, '0'), 'hex'));
|
|
653
|
-
}
|
|
654
|
-
case 'OCTET-STRING': {
|
|
655
|
-
const asciiText = dataItem.value;
|
|
656
|
-
if (!asciiText) {
|
|
657
|
-
this.recordError(errorNodePath, 'Empty OCTET-STRING, ignored');
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
|
-
if (asciiText.length > 20)
|
|
661
|
-
this.recordError(errorNodePath, 'OCTET-STRING too long');
|
|
662
|
-
const hex = Buffer.from(asciiText, 'ascii').toString('hex').padStart(20 * 2);
|
|
663
|
-
return new node_tlv_1.default(0x89, Buffer.from(hex, 'hex').subarray(0, 20));
|
|
664
|
-
}
|
|
665
|
-
case 'VISIBLE-STRING': {
|
|
666
|
-
const asciiText = dataItem.value;
|
|
667
|
-
if (!asciiText) {
|
|
668
|
-
this.recordError(errorNodePath, 'Empty VISIBLE-STRING, ignored');
|
|
669
|
-
return null;
|
|
670
|
-
}
|
|
671
|
-
if (asciiText.length > 35)
|
|
672
|
-
this.recordError(errorNodePath, 'VISIBLE-STRING too long');
|
|
673
|
-
const hex = Buffer.from(asciiText, 'ascii').toString('hex').padStart(35 * 2);
|
|
674
|
-
return new node_tlv_1.default(0x8a, Buffer.from(hex, 'hex').subarray(0, 35));
|
|
675
|
-
}
|
|
676
|
-
case 'TimeStamp': {
|
|
677
|
-
let timestamp = parseInt(dataItem.value);
|
|
678
|
-
if (isNaN(timestamp))
|
|
679
|
-
this.recordError(errorNodePath, 'Invalid TimeStamp value');
|
|
680
|
-
timestamp = timestamp ? timestamp : 0;
|
|
681
|
-
return new node_tlv_1.default(0x91, Buffer.from(timestamp.toString(16).padStart(8 * 2, '0'), 'hex'));
|
|
682
|
-
}
|
|
683
|
-
case 'Quality': {
|
|
684
|
-
const bitString = dataItem.value;
|
|
685
|
-
let intValue = parseInt(bitString, 2);
|
|
686
|
-
if (isNaN(intValue))
|
|
687
|
-
this.recordError(errorNodePath, 'Invalid Quality value');
|
|
688
|
-
intValue = intValue ? intValue : 0;
|
|
689
|
-
return new node_tlv_1.default(0x84, Buffer.from(intValue.toString(16).padStart(3 * 2, '0'), 'hex'));
|
|
690
|
-
}
|
|
691
|
-
default: {
|
|
692
|
-
this.recordError(errorNodePath, 'Invalid dataType, ignored');
|
|
693
|
-
return null;
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
})
|
|
697
|
-
.filter((dataItemTLV) => !!dataItemTLV);
|
|
552
|
+
const dataItemTLVs = this.encodeDataTLVItem(allData);
|
|
698
553
|
if (dataItemTLVs.length) {
|
|
699
|
-
|
|
700
|
-
dataItemTLVs.forEach(dataItemTLV => dataItemsHex = `${dataItemsHex}${dataItemTLV.toString()}`);
|
|
701
|
-
const allDataTLV = new node_tlv_1.default(0xAB, dataItemsHex);
|
|
554
|
+
const allDataTLV = new node_tlv_1.default(0xAB, Buffer.concat(dataItemTLVs.map((dataItemTLV) => Buffer.concat([dataItemTLV.bTag, dataItemTLV.bLength, dataItemTLV.bValue]))));
|
|
702
555
|
this.TLVChild.push(allDataTLV);
|
|
703
556
|
}
|
|
704
557
|
}
|
|
@@ -711,6 +564,287 @@ class Goose extends BaseHeader_1.BaseHeader {
|
|
|
711
564
|
this.name = 'IEC61850 GOOSE';
|
|
712
565
|
this.nickname = 'GOOSE';
|
|
713
566
|
}
|
|
567
|
+
/**
|
|
568
|
+
* Decode data TLV items
|
|
569
|
+
* @param dataTLVs
|
|
570
|
+
* @protected
|
|
571
|
+
*/
|
|
572
|
+
decodeDataTLVItem(dataTLVs) {
|
|
573
|
+
const dataItems = [];
|
|
574
|
+
dataTLVs.forEach((dataTLV) => {
|
|
575
|
+
const length = dataTLV.getLength('number');
|
|
576
|
+
const value = dataTLV.getValue('buffer');
|
|
577
|
+
switch (dataTLV.getTag('number')) {
|
|
578
|
+
case 0x83:
|
|
579
|
+
{
|
|
580
|
+
dataItems.push({
|
|
581
|
+
dataType: ItemDataType.Boolean,
|
|
582
|
+
value: !!parseInt(value.toString('hex'), 16)
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
break;
|
|
586
|
+
case 0x84:
|
|
587
|
+
{
|
|
588
|
+
switch (length) {
|
|
589
|
+
case 2:
|
|
590
|
+
{
|
|
591
|
+
dataItems.push({
|
|
592
|
+
dataType: ItemDataType.CODEDENUM,
|
|
593
|
+
value: parseInt(value.toString('hex'), 16)
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
break;
|
|
597
|
+
case 3:
|
|
598
|
+
{
|
|
599
|
+
dataItems.push({
|
|
600
|
+
dataType: ItemDataType.Quality,
|
|
601
|
+
value: parseInt(value.toString('hex'), 16).toString(2).padStart(24, '0')
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
break;
|
|
608
|
+
case 0x85:
|
|
609
|
+
{
|
|
610
|
+
const integerRealLength = (0, GetBERIntegerLengthFromBuffer_1.GetBERIntegerLengthFromBuffer)(value);
|
|
611
|
+
if (integerRealLength === 1) {
|
|
612
|
+
dataItems.push({
|
|
613
|
+
dataType: ItemDataType.INT8,
|
|
614
|
+
value: (0, HexToNumber_1.HexToInt8)(value.toString('hex'))
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
else if (integerRealLength === 2) {
|
|
618
|
+
dataItems.push({
|
|
619
|
+
dataType: ItemDataType.INT16,
|
|
620
|
+
value: (0, HexToNumber_1.HexToInt16)(value.toString('hex'))
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
else if (integerRealLength === 4) {
|
|
624
|
+
dataItems.push({
|
|
625
|
+
dataType: ItemDataType.INT32,
|
|
626
|
+
value: (0, HexToNumber_1.HexToInt32)(value.toString('hex'))
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
else if (integerRealLength === 8) {
|
|
630
|
+
dataItems.push({
|
|
631
|
+
dataType: ItemDataType.INT64,
|
|
632
|
+
value: (0, HexToNumber_1.HexToInt64)(value.toString('hex'))
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
break;
|
|
637
|
+
case 0x86:
|
|
638
|
+
{
|
|
639
|
+
const unsignedIntegerRealLength = (0, GetBERIntegerLengthFromBuffer_1.GetBERIntegerLengthFromBuffer)(value);
|
|
640
|
+
switch (unsignedIntegerRealLength) {
|
|
641
|
+
case 1:
|
|
642
|
+
{
|
|
643
|
+
dataItems.push({
|
|
644
|
+
dataType: ItemDataType.INT8U,
|
|
645
|
+
value: (0, HexToNumber_1.HexToUInt8)(value.toString('hex'))
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
break;
|
|
649
|
+
case 2:
|
|
650
|
+
{
|
|
651
|
+
dataItems.push({
|
|
652
|
+
dataType: ItemDataType.INT16U,
|
|
653
|
+
value: (0, HexToNumber_1.HexToUInt16)(value.toString('hex'))
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
break;
|
|
657
|
+
case 4:
|
|
658
|
+
{
|
|
659
|
+
dataItems.push({
|
|
660
|
+
dataType: ItemDataType.INT32U,
|
|
661
|
+
value: (0, HexToNumber_1.HexToUInt32)(value.toString('hex'))
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
break;
|
|
668
|
+
case 0x87:
|
|
669
|
+
{
|
|
670
|
+
dataItems.push({
|
|
671
|
+
dataType: ItemDataType.FLOAT32,
|
|
672
|
+
value: (0, HexToNumber_1.HexToFloat32)(value.toString('hex'))
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
break;
|
|
676
|
+
case 0x89:
|
|
677
|
+
{
|
|
678
|
+
dataItems.push({
|
|
679
|
+
dataType: ItemDataType.OCTETSTRING,
|
|
680
|
+
value: value.toString('hex')
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
break;
|
|
684
|
+
case 0x8a:
|
|
685
|
+
{
|
|
686
|
+
dataItems.push({
|
|
687
|
+
dataType: ItemDataType.VISIBLESTRING,
|
|
688
|
+
value: value.toString('ascii')
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
break;
|
|
692
|
+
case 0x91:
|
|
693
|
+
{
|
|
694
|
+
dataItems.push({
|
|
695
|
+
dataType: ItemDataType.TimeStamp,
|
|
696
|
+
value: parseInt(value.toString('hex'), 16).toString()
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
break;
|
|
700
|
+
case 0xa2:
|
|
701
|
+
{
|
|
702
|
+
const subDataTLVs = node_tlv_1.default.parseList(value);
|
|
703
|
+
dataItems.push({
|
|
704
|
+
dataType: ItemDataType.Structure,
|
|
705
|
+
value: this.decodeDataTLVItem(subDataTLVs)
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
return dataItems;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Encode data TLV items
|
|
715
|
+
* @param dataItems
|
|
716
|
+
* @protected
|
|
717
|
+
*/
|
|
718
|
+
encodeDataTLVItem(dataItems) {
|
|
719
|
+
return dataItems
|
|
720
|
+
.map((dataItem, index) => {
|
|
721
|
+
const errorNodePath = this.instance.goosePdu.allData.getPath(index);
|
|
722
|
+
switch (dataItem.dataType) {
|
|
723
|
+
case ItemDataType.Boolean: {
|
|
724
|
+
const booleanIntValue = dataItem.value ? 1 : 0;
|
|
725
|
+
return new node_tlv_1.default(0x83, Buffer.from(booleanIntValue.toString(16).padStart(2, '0'), 'hex'));
|
|
726
|
+
}
|
|
727
|
+
case ItemDataType.INT8: {
|
|
728
|
+
let intValue = dataItem.value;
|
|
729
|
+
if (isNaN(intValue))
|
|
730
|
+
this.recordError(errorNodePath, 'Invalid INT8 value');
|
|
731
|
+
intValue = intValue ? intValue : 0;
|
|
732
|
+
if (intValue < -128 || intValue > 127)
|
|
733
|
+
this.recordError(errorNodePath, 'Invalid INT8 value');
|
|
734
|
+
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int8ToBERHex)(intValue), 'hex'));
|
|
735
|
+
}
|
|
736
|
+
case ItemDataType.INT16: {
|
|
737
|
+
let intValue = dataItem.value;
|
|
738
|
+
if (isNaN(intValue))
|
|
739
|
+
this.recordError(errorNodePath, 'Invalid INT16 value');
|
|
740
|
+
intValue = intValue ? intValue : 0;
|
|
741
|
+
if (intValue < -32768 || intValue > 32767)
|
|
742
|
+
this.recordError(errorNodePath, 'Invalid INT16 value');
|
|
743
|
+
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int16ToBERHex)(intValue), 'hex'));
|
|
744
|
+
}
|
|
745
|
+
case ItemDataType.INT32: {
|
|
746
|
+
let intValue = dataItem.value;
|
|
747
|
+
if (isNaN(intValue))
|
|
748
|
+
this.recordError(errorNodePath, 'Invalid INT32 value');
|
|
749
|
+
intValue = intValue ? intValue : 0;
|
|
750
|
+
if (intValue < -2147483648 || intValue > 2147483647)
|
|
751
|
+
this.recordError(errorNodePath, 'Invalid INT32 value');
|
|
752
|
+
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int32ToBERHex)(intValue), 'hex'));
|
|
753
|
+
}
|
|
754
|
+
case ItemDataType.INT64: {
|
|
755
|
+
const intValue = BigInt(dataItem.value);
|
|
756
|
+
if (intValue < BigInt('-9223372036854775808') || intValue > BigInt('9223372036854775807'))
|
|
757
|
+
this.recordError(errorNodePath, 'Invalid INT64 value');
|
|
758
|
+
return new node_tlv_1.default(0x85, Buffer.from((0, NumberToBERHex_1.Int64ToBERHex)(intValue), 'hex'));
|
|
759
|
+
}
|
|
760
|
+
case ItemDataType.INT8U: {
|
|
761
|
+
let uintValue = dataItem.value;
|
|
762
|
+
if (isNaN(uintValue))
|
|
763
|
+
this.recordError(errorNodePath, 'Invalid INT8U value');
|
|
764
|
+
uintValue = uintValue ? uintValue : 0;
|
|
765
|
+
if (uintValue < 0 || uintValue > 255)
|
|
766
|
+
this.recordError(errorNodePath, 'Invalid INT8U value');
|
|
767
|
+
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt8ToBERHex)(uintValue), 'hex'));
|
|
768
|
+
}
|
|
769
|
+
case ItemDataType.INT16U: {
|
|
770
|
+
let uintValue = dataItem.value;
|
|
771
|
+
if (isNaN(uintValue))
|
|
772
|
+
this.recordError(errorNodePath, 'Invalid INT16U value');
|
|
773
|
+
uintValue = uintValue ? uintValue : 0;
|
|
774
|
+
if (uintValue < 0 || uintValue > 65535)
|
|
775
|
+
this.recordError(errorNodePath, 'Invalid INT16U value');
|
|
776
|
+
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(uintValue), 'hex'));
|
|
777
|
+
}
|
|
778
|
+
case ItemDataType.INT32U: {
|
|
779
|
+
let uintValue = dataItem.value;
|
|
780
|
+
if (isNaN(uintValue))
|
|
781
|
+
this.recordError(errorNodePath, 'Invalid INT32U value');
|
|
782
|
+
uintValue = uintValue ? uintValue : 0;
|
|
783
|
+
if (uintValue < 0 || uintValue > 4294967295)
|
|
784
|
+
this.recordError(errorNodePath, 'Invalid INT32U value');
|
|
785
|
+
return new node_tlv_1.default(0x86, Buffer.from((0, NumberToBERHex_1.UInt32ToBERHex)(uintValue), 'hex'));
|
|
786
|
+
}
|
|
787
|
+
case ItemDataType.FLOAT32: {
|
|
788
|
+
let float32Value = dataItem.value;
|
|
789
|
+
if (isNaN(float32Value))
|
|
790
|
+
this.recordError(errorNodePath, 'Invalid FLOAT32 value');
|
|
791
|
+
float32Value = float32Value ? float32Value : 0;
|
|
792
|
+
return new node_tlv_1.default(0x87, Buffer.from((0, NumberToBERHex_1.Float32ToBERHex)(float32Value), 'hex'));
|
|
793
|
+
}
|
|
794
|
+
case ItemDataType.CODEDENUM: {
|
|
795
|
+
let codedEnumValue = dataItem.value;
|
|
796
|
+
if (isNaN(codedEnumValue))
|
|
797
|
+
this.recordError(errorNodePath, 'Invalid CODED-ENUM value');
|
|
798
|
+
codedEnumValue = codedEnumValue ? codedEnumValue : 0;
|
|
799
|
+
return new node_tlv_1.default(0x84, Buffer.from((0, NumberToBERHex_1.UInt16ToBERHex)(codedEnumValue), 'hex'));
|
|
800
|
+
}
|
|
801
|
+
case ItemDataType.OCTETSTRING: {
|
|
802
|
+
const hexText = dataItem.value;
|
|
803
|
+
if (!hexText) {
|
|
804
|
+
this.recordError(errorNodePath, 'Empty OCTET-STRING, ignored');
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
if (hexText.length > 20)
|
|
808
|
+
this.recordError(errorNodePath, 'OCTET-STRING too long');
|
|
809
|
+
return new node_tlv_1.default(0x89, Buffer.from(hexText, 'hex').subarray(0, 20));
|
|
810
|
+
}
|
|
811
|
+
case ItemDataType.VISIBLESTRING: {
|
|
812
|
+
const asciiText = dataItem.value;
|
|
813
|
+
if (!asciiText) {
|
|
814
|
+
this.recordError(errorNodePath, 'Empty VISIBLE-STRING, ignored');
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
if (asciiText.length > 35)
|
|
818
|
+
this.recordError(errorNodePath, 'VISIBLE-STRING too long');
|
|
819
|
+
const hex = Buffer.from(asciiText, 'ascii').toString('hex').padStart(35 * 2);
|
|
820
|
+
return new node_tlv_1.default(0x8a, Buffer.from(hex, 'hex').subarray(0, 35));
|
|
821
|
+
}
|
|
822
|
+
case ItemDataType.TimeStamp: {
|
|
823
|
+
let timestamp = parseInt(dataItem.value);
|
|
824
|
+
if (isNaN(timestamp))
|
|
825
|
+
this.recordError(errorNodePath, 'Invalid TimeStamp value');
|
|
826
|
+
timestamp = timestamp ? timestamp : 0;
|
|
827
|
+
return new node_tlv_1.default(0x91, Buffer.from(timestamp.toString(16), 'hex'));
|
|
828
|
+
}
|
|
829
|
+
case ItemDataType.Quality: {
|
|
830
|
+
const bitString = dataItem.value;
|
|
831
|
+
let intValue = parseInt(bitString, 2);
|
|
832
|
+
if (isNaN(intValue))
|
|
833
|
+
this.recordError(errorNodePath, 'Invalid Quality value');
|
|
834
|
+
intValue = intValue ? intValue : 0;
|
|
835
|
+
return new node_tlv_1.default(0x84, Buffer.from(intValue.toString(16).padStart(3 * 2, '0'), 'hex'));
|
|
836
|
+
}
|
|
837
|
+
case ItemDataType.Structure: {
|
|
838
|
+
return new node_tlv_1.default(0xa2, Buffer.concat(this.encodeDataTLVItem(dataItem.value).map((tlv) => Buffer.concat([tlv.bTag, tlv.bLength, tlv.bValue]))));
|
|
839
|
+
}
|
|
840
|
+
default: {
|
|
841
|
+
this.recordError(errorNodePath, 'Invalid dataType, ignored');
|
|
842
|
+
return null;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
})
|
|
846
|
+
.filter((value) => !!value);
|
|
847
|
+
}
|
|
714
848
|
match() {
|
|
715
849
|
if (!this.prevCodecModule)
|
|
716
850
|
return false;
|