@microtronics/studio-cli 0.3.5 → 0.4.1

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 @@
1
+ {"version":3,"file":"xml.d.ts","sourceRoot":"","sources":["../../../src/dde/fileGenerators/xml.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,OAAO,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AAOlC,MAAM,WAAW,QAAQ;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAGD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,UAwLjD;AAgBD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,OAoB5E"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateXMLFromMap = generateXMLFromMap;
4
+ exports.patchValueWithArrayInfo = patchValueWithArrayInfo;
5
+ const coreDefinitions_1 = require("../coreDefinitions");
6
+ var TransferDirection = coreDefinitions_1.DDE_Core.TransferDirection;
7
+ var parseXMLValueWithRelation = coreDefinitions_1.DDE_Core.parseXMLValueWithRelation;
8
+ var parseXMLBitmask = coreDefinitions_1.DDE_Core.parseXMLBitmask;
9
+ var parseXMLDefaultValue = coreDefinitions_1.DDE_Core.parseXMLDefaultValue;
10
+ var fieldTypeDefinitions = coreDefinitions_1.DDE_Core.fieldTypeDefinitions;
11
+ // eslint-disable-next-line sonarjs/cognitive-complexity
12
+ function generateXMLFromMap(ddeMap) {
13
+ const indent = '';
14
+ const xml_ = [];
15
+ function xml(s, condition = true) {
16
+ if (!condition) {
17
+ return;
18
+ }
19
+ if (Array.isArray(s)) {
20
+ xml_.push.apply(xml_, s);
21
+ return;
22
+ }
23
+ xml_.push(indent + s);
24
+ }
25
+ function xmlAttr(attribute, val) {
26
+ if (attribute === 'mergeofs') {
27
+ return;
28
+ }
29
+ xml(`${attribute}=${val}`);
30
+ }
31
+ xml('// DDE STRUCTURE created by Microtronics Studio');
32
+ const rm2mraw = 'source=rm2mraw';
33
+ for (const [containerName, containerDefinition] of Object.entries(ddeMap.containers)) {
34
+ if (containerName.startsWith('histdata') &&
35
+ containerDefinition.transferDirection !== TransferDirection.deviceOnly) {
36
+ xml('<split>');
37
+ xml(rm2mraw);
38
+ xml('target=' + containerName);
39
+ xml('key=0' + containerName.substr(-1, 1));
40
+ xml('</split>');
41
+ }
42
+ xml('<table>');
43
+ xmlAttr('name', containerName); // output container-name as very first line (mandatory!)
44
+ xmlAttr('alias', containerDefinition.title);
45
+ xmlAttr('title', containerDefinition.title.replace('_', ' '));
46
+ const containerAttributes = {};
47
+ // enforce container's direction - 'up','up+','down','down+','both','both+'
48
+ // .upload/.download are reserved container attributes (already claimed during parsing)
49
+ if ([
50
+ TransferDirection.none,
51
+ TransferDirection.backendOnly,
52
+ TransferDirection.deviceOnly,
53
+ TransferDirection.down,
54
+ TransferDirection.downPlus
55
+ ].includes(containerDefinition.transferDirection)) {
56
+ // containerAttributes['upload'] = '0';
57
+ xmlAttr('upload', '0');
58
+ }
59
+ if ([
60
+ TransferDirection.none,
61
+ TransferDirection.backendOnly,
62
+ TransferDirection.deviceOnly,
63
+ TransferDirection.up,
64
+ TransferDirection.upPlus
65
+ ].includes(containerDefinition.transferDirection)) {
66
+ // containerAttributes['download'] = '0';
67
+ xmlAttr('download', '0');
68
+ }
69
+ // set edit=99 on upward containers to reject write access via API
70
+ if ([TransferDirection.up, TransferDirection.upPlus].includes(containerDefinition.transferDirection)) {
71
+ // containerAttributes['edit'] = '99';
72
+ xmlAttr('edit', '99');
73
+ }
74
+ //insert fields:
75
+ for (const field of containerDefinition.fields) {
76
+ if (field.type === 'shadow') {
77
+ continue;
78
+ }
79
+ const patchedField = patchFieldWithArrayInfo(field);
80
+ const typeDefinition = fieldTypeDefinitions[patchedField.type];
81
+ // build the field title:
82
+ let fieldTitle = parseXMLValueWithRelation('title', patchedField, ddeMap) || patchedField.name;
83
+ // only add the library prefix if the attribute is not referenced
84
+ if (!fieldTitle.startsWith('%') && patchedField.library) {
85
+ fieldTitle = `${patchedField.library}: ${fieldTitle}`;
86
+ }
87
+ const xmlField = {
88
+ title: fieldTitle,
89
+ alias: patchedField.name,
90
+ index: field.index,
91
+ ...containerAttributes
92
+ };
93
+ xmlField.byteofs = `${patchedField.byteOffset}`;
94
+ // add xml attributes based on field type
95
+ for (const [attribute, value] of Object.entries(typeDefinition.xml)) {
96
+ //@ts-ignore
97
+ xmlField[attribute] = value;
98
+ }
99
+ if (Object.hasOwn(typeDefinition, 'xmlOut')) {
100
+ typeDefinition.xmlOut(xmlField, patchedField, ddeMap);
101
+ }
102
+ // additional attributes from the dde
103
+ xmlField.units = parseXMLValueWithRelation('unit', patchedField, ddeMap);
104
+ xmlField.chmode = parseXMLValueWithRelation('channelMode', patchedField, ddeMap);
105
+ // warn and alarm thresholds
106
+ xmlField.ialarm_high = parseXMLValueWithRelation('chartAlarmHigh', patchedField, ddeMap);
107
+ xmlField.ialarm_low = parseXMLValueWithRelation('chartAlarmLow', patchedField, ddeMap);
108
+ xmlField.iwarn_high = parseXMLValueWithRelation('chartWarningHigh', patchedField, ddeMap);
109
+ xmlField.iwarn_low = parseXMLValueWithRelation('chartWarningLow', patchedField, ddeMap);
110
+ xmlField.hysterese = parseXMLValueWithRelation('chartHysteresis', patchedField, ddeMap);
111
+ xmlField.itrigger = parseXMLValueWithRelation('chartTriggerThreshold', patchedField, ddeMap);
112
+ xmlField.itriggerus = parseXMLValueWithRelation('chartTriggerRelation', patchedField, ddeMap);
113
+ xmlField.setpoint = parseXMLValueWithRelation('chartSetPoint', patchedField, ddeMap);
114
+ xmlField.bitmask = parseXMLBitmask(patchedField);
115
+ // process field as hex
116
+ if (patchedField.hex) {
117
+ xmlField.editmask = '%HEX%';
118
+ }
119
+ if (patchedField.readPermission) {
120
+ xmlField.view = patchedField.readPermission;
121
+ }
122
+ if (patchedField.writePermission) {
123
+ xmlField.edit = patchedField.writePermission;
124
+ }
125
+ if (patchedField.defaultValue !== undefined) {
126
+ xmlField.default = parseXMLDefaultValue(patchedField);
127
+ }
128
+ if (patchedField.utilsTransferInterval === true) {
129
+ xmlField.param0 = '%FFFF0005%transfer_interval';
130
+ }
131
+ xml('<field>');
132
+ if (patchedField.library) {
133
+ xml(`// declared by ${patchedField.library} library`, true);
134
+ }
135
+ for (const [attribute, value] of Object.entries(xmlField)) {
136
+ // if (attribute === 'byteofs') {
137
+ // xml(`// patching byte offset due to removed field`);
138
+ // }
139
+ if (value !== undefined) {
140
+ xmlAttr(attribute, `${value}`);
141
+ }
142
+ }
143
+ xml('</field>');
144
+ }
145
+ // end of container
146
+ if (!['alerts', 'applog'].includes(containerName)) {
147
+ xml('</table>');
148
+ xml('// ' + containerDefinition.size + ' bytes total size');
149
+ }
150
+ }
151
+ // insert alerts stream
152
+ xml('<split>');
153
+ xml(rm2mraw);
154
+ xml('target=alarm0');
155
+ xml('key=20'); // implicit hex!
156
+ xml('</split>');
157
+ // insert applog stream
158
+ xml('<split>');
159
+ xml(rm2mraw);
160
+ xml('target=applog0');
161
+ xml('key=28'); // implicit hex!
162
+ xml('</split>');
163
+ return xml_.join('\n');
164
+ }
165
+ function patchFieldWithArrayInfo(ddeField) {
166
+ const clonedField = structuredClone(ddeField);
167
+ const arrayIndex = ddeField.arrayRef?.index;
168
+ if (arrayIndex === undefined) {
169
+ return clonedField;
170
+ }
171
+ // eslint-disable-next-line prefer-const
172
+ for (let [attribute, value] of Object.entries(clonedField)) {
173
+ // @ts-ignore
174
+ clonedField[attribute] = patchValueWithArrayInfo(value, arrayIndex);
175
+ }
176
+ return clonedField;
177
+ }
178
+ /**
179
+ * Parse and resolve any {index} or {index+X} within the given value
180
+ * @param valueToPatch
181
+ * @param arrayIndex
182
+ */
183
+ function patchValueWithArrayInfo(valueToPatch, arrayIndex) {
184
+ // look for these phrases in attribute strings: "<a>i+<b>", "<a>o+<b>", "<a>n+<b>" (or "<a>i", "<a>o", "<a>n")
185
+ const valueNTHS = `${valueToPatch}`.match(/\{\d*(index)(\+\d*)?}/g);
186
+ if (valueNTHS) {
187
+ let patchedValue = valueToPatch;
188
+ valueNTHS.forEach((nth) => {
189
+ // normalize & parse "(xn+y)" string
190
+ const normalizedNTH = nth.replace(/\+0$/, '');
191
+ const scope = normalizedNTH.match(/index/)?.[0];
192
+ if (scope) {
193
+ const stepOffset = normalizedNTH.slice(1, -1).split(scope)[1];
194
+ const offset = parseInt(stepOffset) || 0;
195
+ // reassign the patched value
196
+ patchedValue = patchedValue.replace(nth, `${arrayIndex + offset}`);
197
+ }
198
+ });
199
+ return patchedValue;
200
+ }
201
+ else {
202
+ return valueToPatch;
203
+ }
204
+ }
205
+ //# sourceMappingURL=xml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yamlDdePreCompiler.d.ts","sourceRoot":"","sources":["../../src/dde/yamlDdePreCompiler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AAqBlC,yBAAiB,eAAe,CAAC;IAChC,MAAa,WAAW;QAMtB,OAAO,CAAC,QAAQ;QAChB,OAAO,CAAC,YAAY;QACpB,OAAO,CAAC,UAAU;QAPnB,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAmC;QAC1E,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiC;QACpE,OAAO,CAAC,eAAe,CAA0B;QACjD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;oBAEnC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAC3B,YAAY,EAAE,QAAQ,CAAC,WAAW,EAAE,EACpC,UAAU,EAAE,GAAG;QAGxB;;WAEG;QACI,cAAc,I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