@zaes/sidc 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseNumericSidc = parseNumericSidc;
4
+ exports.formatNumericSidc = formatNumericSidc;
5
+ /**
6
+ * The numeric SIDC of MIL-STD-2525D and 2525E (Appendix A, A.5): 20 positions in 2525D, 30 in
7
+ * 2525E. A 20-position code read as 2525E has an all-zero Set C.
8
+ *
9
+ * Set A 1–2 version · 3 context · 4 standard identity · 5–6 symbol set · 7 status ·
10
+ * 8 headquarters/task force/dummy · 9–10 amplifying descriptor
11
+ * Set B 11–16 entity, entity type, entity subtype · 17–18 sector 1 modifier · 19–20 sector 2 modifier
12
+ * Set C 21 sector 1 modifier identifier · 22 sector 2 modifier identifier · 23 frame shape ·
13
+ * 24–27 reserved · 28–30 country (GENC numeric)
14
+ */
15
+ const tables_js_1 = require("./tables.js");
16
+ const NUMERIC = /^[0-9A-F]+$/;
17
+ /**
18
+ * Reads a numeric SIDC. A code of the wrong length or with characters outside [0-9A-F] fails; a
19
+ * well-formed code with values the tables don't define parses, with each one listed in `problems`,
20
+ * so a caller can decide whether to draw it.
21
+ */
22
+ function parseNumericSidc(input) {
23
+ const code = input.trim().toUpperCase();
24
+ if (code.length !== 20 && code.length !== 30) {
25
+ return { ok: false, problems: [{ position: 1, message: `a numeric SIDC has 20 or 30 positions, not ${code.length}` }] };
26
+ }
27
+ if (!NUMERIC.test(code))
28
+ return { ok: false, problems: [{ position: firstBad(code) + 1, message: 'a numeric SIDC holds only 0-9 and A-F' }] };
29
+ const at = (from, to = from) => code.slice(from - 1, to);
30
+ const problems = [];
31
+ const check = (position, value, known, what) => {
32
+ if (!known)
33
+ problems.push({ position, message: `${what} ${value} is not defined` });
34
+ };
35
+ const version = at(1, 2);
36
+ const versionEntry = (0, tables_js_1.lookup)(tables_js_1.VERSIONS, version);
37
+ check(1, version, !!versionEntry, 'version');
38
+ const standard = versionEntry === null || versionEntry === void 0 ? void 0 : versionEntry.standard;
39
+ const context = at(3);
40
+ check(3, context, !!(0, tables_js_1.lookup)(tables_js_1.CONTEXTS, context), 'context');
41
+ const standardIdentity = at(4);
42
+ const identity = (0, tables_js_1.lookup)(tables_js_1.STANDARD_IDENTITIES, standardIdentity);
43
+ check(4, standardIdentity, !!identity, 'standard identity');
44
+ const symbolSet = at(5, 6);
45
+ const sets = standard === '2525D' || standard === 'APP-6D' ? [...tables_js_1.SYMBOL_SETS.filter((s) => s.value !== '50'), ...tables_js_1.SYMBOL_SETS_2525D_ONLY] : tables_js_1.SYMBOL_SETS;
46
+ check(5, symbolSet, !!(0, tables_js_1.lookup)(sets, symbolSet), 'symbol set');
47
+ const status = at(7);
48
+ check(7, status, !!(0, tables_js_1.lookup)(tables_js_1.STATUSES, status), 'status');
49
+ const hqTfDummy = at(8);
50
+ check(8, hqTfDummy, !!(0, tables_js_1.lookup)(tables_js_1.HQ_TF_DUMMY, hqTfDummy), 'headquarters/task force/dummy');
51
+ const flags = Number.parseInt(hqTfDummy, 16);
52
+ const amplifyingDescriptor = at(9, 10);
53
+ check(9, amplifyingDescriptor, !!(0, tables_js_1.lookup)(tables_js_1.AMPLIFYING_DESCRIPTORS, amplifyingDescriptor), 'amplifying descriptor');
54
+ const long = code.length === 30;
55
+ if (!long && (standard === '2525E' || standard === 'APP-6E')) {
56
+ problems.push({ position: 21, message: 'a 2525E code has 30 positions; read with an all-zero Set C' });
57
+ }
58
+ const frameShape = long ? at(23) : '0';
59
+ check(23, frameShape, !!(0, tables_js_1.lookup)(tables_js_1.FRAME_SHAPES, frameShape), 'frame shape');
60
+ if (long && at(24, 27) !== '0000')
61
+ problems.push({ position: 24, message: 'positions 24–27 are reserved and should be 0' });
62
+ return {
63
+ ok: true,
64
+ problems,
65
+ sidc: {
66
+ kind: 'numeric',
67
+ code,
68
+ standard,
69
+ version,
70
+ context,
71
+ standardIdentity,
72
+ standardIdentityGroup: identity === null || identity === void 0 ? void 0 : identity.group,
73
+ symbolSet,
74
+ status,
75
+ hqTfDummy,
76
+ feintDummy: (flags & 1) !== 0,
77
+ headquarters: (flags & 2) !== 0,
78
+ taskForce: (flags & 4) !== 0,
79
+ amplifyingDescriptor,
80
+ entityCode: at(11, 16),
81
+ sector1: at(17, 18),
82
+ sector2: at(19, 20),
83
+ sector1Identifier: long ? at(21) : '0',
84
+ sector2Identifier: long ? at(22) : '0',
85
+ frameShape,
86
+ country: long ? at(28, 30) : '000',
87
+ },
88
+ };
89
+ }
90
+ /** Writes a 30-position 2525E SIDC (version 15 unless given). Each field is padded to its width. */
91
+ function formatNumericSidc(fields) {
92
+ var _a;
93
+ const f = (value, width) => (value !== null && value !== void 0 ? value : '').padStart(width, '0').slice(-width);
94
+ return [
95
+ f((_a = fields.version) !== null && _a !== void 0 ? _a : '15', 2),
96
+ f(fields.context, 1),
97
+ f(fields.standardIdentity, 1),
98
+ f(fields.symbolSet, 2),
99
+ f(fields.status, 1),
100
+ f(fields.hqTfDummy, 1),
101
+ f(fields.amplifyingDescriptor, 2),
102
+ f(fields.entityCode, 6),
103
+ f(fields.sector1, 2),
104
+ f(fields.sector2, 2),
105
+ f(fields.sector1Identifier, 1),
106
+ f(fields.sector2Identifier, 1),
107
+ f(fields.frameShape, 1),
108
+ '0000',
109
+ f(fields.country, 3),
110
+ ].join('');
111
+ }
112
+ function firstBad(code) {
113
+ for (let i = 0; i < code.length; i++)
114
+ if (!NUMERIC.test(code[i]))
115
+ return i;
116
+ return 0;
117
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ /**
3
+ * The fixed code tables of the numeric SIDC, transcribed from MIL-STD-2525E Change 1, Appendix A.
4
+ * Each table names its source so a reviewer can check it against the standard line by line.
5
+ * The entity and modifier tables (A-XI onward) are generated, not typed here.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.FRAME_SHAPES = exports.AMPLIFYING_DESCRIPTORS = exports.HQ_TF_DUMMY = exports.STATUSES = exports.SYMBOL_SETS_2525D_ONLY = exports.SYMBOL_SETS = exports.STANDARD_IDENTITIES = exports.CONTEXTS = exports.VERSIONS = void 0;
9
+ exports.lookup = lookup;
10
+ /**
11
+ * Table A-I, Version. Value 10 is shared by 2525D and APP-6(D)(1), which the standard says carry
12
+ * the same versioning; `standard` gives the US one. 12, APP-6(D)(2), was withdrawn but codes
13
+ * carrying it may still exist. 17–3F are reserved.
14
+ */
15
+ exports.VERSIONS = [
16
+ { value: '10', name: 'MIL-STD-2525D / APP-06(D)(1)', standard: '2525D', released: 'June 2014' },
17
+ { value: '11', name: 'MIL-STD-2525D(1)', standard: '2525D', released: '2018-08-02' },
18
+ { value: '12', name: 'APP-06(D)(2)', standard: 'APP-6D', released: 'Withdrawn' },
19
+ { value: '13', name: 'MIL-STD-2525E', standard: '2525E', released: '2022-12-31' },
20
+ { value: '14', name: 'APP-06(E)(1)', standard: 'APP-6E', released: 'October 2023' },
21
+ { value: '15', name: 'MIL-STD-2525E(1)', standard: '2525E', released: '2025-03-02' },
22
+ { value: '16', name: 'APP-06(E)(2)', standard: 'APP-6E', released: '2025-10-14' },
23
+ ];
24
+ /** Table A-II, first position: the context. */
25
+ exports.CONTEXTS = [
26
+ { value: '0', name: 'Reality' },
27
+ { value: '1', name: 'Exercise' },
28
+ { value: '2', name: 'Simulation' },
29
+ { value: '3', name: 'Restricted Target – Reality' },
30
+ { value: '4', name: 'No-Strike Entity – Reality' },
31
+ { value: '5', name: 'Restricted Target – Exercise' },
32
+ { value: '6', name: 'No-Strike Entity – Exercise' },
33
+ { value: '7', name: 'Restricted Target – Simulation' },
34
+ { value: '8', name: 'No-Strike Entity – Simulation' },
35
+ ];
36
+ /** Table A-II, second position: the standard identity, with its Table A-III group. */
37
+ exports.STANDARD_IDENTITIES = [
38
+ { value: '0', name: 'Pending', group: 'Unknown' },
39
+ { value: '1', name: 'Unknown', group: 'Unknown' },
40
+ { value: '2', name: 'Assumed Friend', group: 'Friend' },
41
+ { value: '3', name: 'Friend', group: 'Friend' },
42
+ { value: '4', name: 'Neutral', group: 'Neutral' },
43
+ { value: '5', name: 'Suspect/Joker', group: 'Hostile' },
44
+ { value: '6', name: 'Hostile/Faker', group: 'Hostile' },
45
+ ];
46
+ /** Table A-IV, Symbol sets (2525E). 2525D's 51–54 are not here: E folded them into 50. */
47
+ exports.SYMBOL_SETS = [
48
+ { value: '00', name: 'Unknown' },
49
+ { value: '01', name: 'Air' },
50
+ { value: '02', name: 'Air Missile' },
51
+ { value: '05', name: 'Space' },
52
+ { value: '06', name: 'Space Missile' },
53
+ { value: '10', name: 'Land Unit' },
54
+ { value: '11', name: 'Land Civilian Unit/Organization' },
55
+ { value: '15', name: 'Land Equipment' },
56
+ { value: '20', name: 'Land Installation' },
57
+ { value: '25', name: 'Control Measures and Planning Symbols' },
58
+ { value: '27', name: 'Dismounted Individuals' },
59
+ { value: '30', name: 'Sea Surface' },
60
+ { value: '35', name: 'Sea Subsurface' },
61
+ { value: '36', name: 'Mine Warfare' },
62
+ { value: '40', name: 'Activities' },
63
+ { value: '45', name: 'Atmospheric' },
64
+ { value: '46', name: 'Oceanographic' },
65
+ { value: '47', name: 'Meteorological Space' },
66
+ { value: '50', name: 'Signals Intelligence' },
67
+ { value: '60', name: 'Cyberspace - Virtual' },
68
+ ];
69
+ /** 2525D's signals-intelligence sets (2525D Table A-IV), accepted as 2525D input only. */
70
+ exports.SYMBOL_SETS_2525D_ONLY = [
71
+ { value: '50', name: 'Signals Intelligence – Space' },
72
+ { value: '51', name: 'Signals Intelligence – Air' },
73
+ { value: '52', name: 'Signals Intelligence – Land' },
74
+ { value: '53', name: 'Signals Intelligence – Surface' },
75
+ { value: '54', name: 'Signals Intelligence – Subsurface' },
76
+ ];
77
+ /** Table A-VI, Status. The same position may carry an operational condition instead (A.5.3.4.1). */
78
+ exports.STATUSES = [
79
+ { value: '0', name: 'Present' },
80
+ { value: '1', name: 'Planned/Anticipated/Suspect' },
81
+ { value: '2', name: 'Present/Fully capable' },
82
+ { value: '3', name: 'Present/Damaged' },
83
+ { value: '4', name: 'Present/Destroyed' },
84
+ { value: '5', name: 'Present/Full to capacity' },
85
+ ];
86
+ /** Table A-VII, Headquarters/task force/dummy: three flags, one digit. */
87
+ exports.HQ_TF_DUMMY = [
88
+ { value: '0', name: 'Unknown' },
89
+ { value: '1', name: 'Feint/Decoy/Dummy' },
90
+ { value: '2', name: 'Headquarters' },
91
+ { value: '3', name: 'Feint/Dummy Headquarters' },
92
+ { value: '4', name: 'Task Force' },
93
+ { value: '5', name: 'Feint/Dummy Task Force' },
94
+ { value: '6', name: 'Task Force Headquarters' },
95
+ { value: '7', name: 'Feint/Dummy Task Force Headquarters' },
96
+ ];
97
+ /** Table A-VIII, Amplifying descriptor (positions 9–10): echelon, mobility, towed array or leadership. */
98
+ exports.AMPLIFYING_DESCRIPTORS = [
99
+ { value: '00', name: 'Unknown', kind: 'none' },
100
+ { value: '11', name: 'Team/Crew', kind: 'echelon' },
101
+ { value: '12', name: 'Squad', kind: 'echelon' },
102
+ { value: '13', name: 'Section', kind: 'echelon' },
103
+ { value: '14', name: 'Platoon/Detachment', kind: 'echelon' },
104
+ { value: '15', name: 'Company/Battery/Troop', kind: 'echelon' },
105
+ { value: '16', name: 'Battalion/Squadron', kind: 'echelon' },
106
+ { value: '17', name: 'Regiment/Group', kind: 'echelon' },
107
+ { value: '18', name: 'Brigade', kind: 'echelon' },
108
+ { value: '21', name: 'Division', kind: 'echelon' },
109
+ { value: '22', name: 'Corps/MEF', kind: 'echelon' },
110
+ { value: '23', name: 'Army', kind: 'echelon' },
111
+ { value: '24', name: 'Army Group/Front', kind: 'echelon' },
112
+ { value: '25', name: 'Region/Theater', kind: 'echelon' },
113
+ { value: '26', name: 'Command', kind: 'echelon' },
114
+ { value: '31', name: 'Wheeled limited cross country', kind: 'mobility' },
115
+ { value: '32', name: 'Wheeled cross country', kind: 'mobility' },
116
+ { value: '33', name: 'Tracked', kind: 'mobility' },
117
+ { value: '34', name: 'Wheeled and tracked combination', kind: 'mobility' },
118
+ { value: '35', name: 'Towed', kind: 'mobility' },
119
+ { value: '36', name: 'Rail', kind: 'mobility' },
120
+ { value: '37', name: 'Pack animals', kind: 'mobility' },
121
+ { value: '41', name: 'Over-snow (prime mover)', kind: 'mobility' },
122
+ { value: '42', name: 'Sled', kind: 'mobility' },
123
+ { value: '51', name: 'Barge', kind: 'mobility' },
124
+ { value: '52', name: 'Amphibious', kind: 'mobility' },
125
+ { value: '61', name: 'Short towed array', kind: 'towedArray' },
126
+ { value: '62', name: 'Long towed array', kind: 'towedArray' },
127
+ { value: '71', name: 'Leader Individual', kind: 'leadership' },
128
+ ];
129
+ /** Table A-LX, Frame shape (position 23): overrides the frame the symbol set would draw. */
130
+ exports.FRAME_SHAPES = [
131
+ { value: '0', name: 'Unknown' },
132
+ { value: '1', name: 'Space' },
133
+ { value: '2', name: 'Air' },
134
+ { value: '3', name: 'Land Unit' },
135
+ { value: '4', name: 'Land Equipment' },
136
+ { value: '5', name: 'Land Installation' },
137
+ { value: '6', name: 'Dismounted Individuals' },
138
+ { value: '7', name: 'Sea Subsurface' },
139
+ { value: '8', name: 'Activity/Event' },
140
+ { value: '9', name: 'Cyberspace' },
141
+ { value: 'A', name: 'Sea Surface' },
142
+ ];
143
+ /** Looks a value up in one of the tables above. */
144
+ function lookup(table, value) {
145
+ return table.find((e) => e.value === value);
146
+ }