Skip to content

Commit f81b44d

Browse files
committed
Added more EPath Symbol segment unit tests
1 parent 5f8e937 commit f81b44d

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

TASKS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
- [X] EIP passes down port 44818 to TCP layer
44
- [X] modbus passes down port 502 to TCP layer
55
- [ ] Logix5000
6-
- [ ] fix or ensure boolean decoding is working
7-
- [ ] understand the difference between direct requests, Connection Manager Unconnected Send messages, Connected messages, and how routes to eni/controller
8-
- [ ] use UCMM to get identity and verify device type is programmable logic controller OR fix path routing
6+
- [x] fix or ensure boolean decoding is working
97
- [X] fix reading symbol structures
108
- [X] getTagSymbolInstanceID and _highestListedSymbolInstanceID need to be scoped (global scope vs program scope)
119
- [X] When Program data type is read, read all symbols contained
@@ -18,6 +16,8 @@
1816
- [X] Decide if reading an array should return all values or just the first, if all values then fix
1917
- [ ] Figure out how to read multidimensional arrays (CIP Vol 1, Table C-5.20)
2018
- [ ] CIP
19+
- [ ] understand the difference between direct requests, Connection Manager Unconnected Send messages, Connected messages, and how routes to eni/controller
20+
- [ ] use UCMM to get identity and verify device type is programmable logic controller OR fix path routing
2121
- [ ] Finish Data Segment
2222
- [ ] Encoding for Symbolic Segment
2323
- [X] Cleanup unused EPath code

src/layers/cip/EPath/segments/symbolic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ function validate(value, extendedFormat, extendedSize) {
293293
}
294294
break;
295295
default:
296-
break;
296+
throw new Error(`Invalid extended size`);
297297
}
298298
break;
299299
}
300300
default:
301-
break;
301+
throw new Error('Invalid extended format');
302302
}
303303
}
304304
}

tests/cip.epath.symbolic.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ describe('Symbolic Numeric', () => {
3232
expect(new Symbolic.Numeric(65536).encode()).toEqual(Buffer.from([0x60, 0xC8, 0x00, 0x00, 0x01, 0x00]));
3333
});
3434

35+
test('Encode Invalid', () => {
36+
expect(() => new Symbolic.Numeric(0xFFFFFFFFF)).toThrow();
37+
expect(() => new Symbolic.Numeric(-1)).toThrow();
38+
});
39+
3540
test('Decode 8-bit', () => {
3641
expect(EPath.Decode(Buffer.from([0x60, 0xC6, 0x05]), 0, true, false, segments => {
3742
expect(segments).toEqual([new Symbolic.Numeric(5)]);
@@ -47,4 +52,30 @@ describe('Symbolic Numeric', () => {
4752
expect(segments).toEqual([new Symbolic.Numeric(65536)]);
4853
})).toBe(6);
4954
});
55+
});
56+
57+
58+
describe('Symbolic Double Byte Characters', () => {
59+
test('Encode', () => {
60+
expect(new Symbolic.Double(Buffer.from([0x12, 0x34, 0x23, 0x45])).encode()).toEqual(Buffer.from([0x60, 0x22, 0x12, 0x34, 0x23, 0x45]));
61+
});
62+
63+
test('Decode', () => {
64+
expect(EPath.Decode(Buffer.from([0x60, 0x22, 0x12, 0x34, 0x23, 0x45]), 0, true, false, segments => {
65+
expect(segments).toEqual([new Symbolic.Double(Buffer.from([0x12, 0x34, 0x23, 0x45]))]);
66+
})).toBe(6);
67+
});
68+
});
69+
70+
71+
describe('Symbolic Triple Byte Characters', () => {
72+
test('Encode', () => {
73+
expect(new Symbolic.Triple(Buffer.from([0x12, 0x34, 0x56, 0x23, 0x45, 0x67])).encode()).toEqual(Buffer.from([0x60, 0x42, 0x12, 0x34, 0x56, 0x23, 0x45, 0x67]));
74+
});
75+
76+
test('Decode', () => {
77+
expect(EPath.Decode(Buffer.from([0x60, 0x42, 0x12, 0x34, 0x56, 0x23, 0x45, 0x67]), 0, true, false, segments => {
78+
expect(segments).toEqual([new Symbolic.Triple(Buffer.from([0x12, 0x34, 0x56, 0x23, 0x45, 0x67]))]);
79+
})).toBe(8);
80+
});
5081
});

0 commit comments

Comments
 (0)