-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
387 lines (362 loc) · 11.1 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
'use strict';
const BinaryFile = require('binary-file');
// const FSC_00A00001_werk = new BinaryFile('files/FSC_00A00001_werk.fsc', 'r');
// (async function () {
// try {
// await FSC_00A00001_werk.open();
//
// await parse(FSC_00A00001_werk, log('FSC_00A00001_werk', 25));
//
// await FSC_00A00001_werk.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const FSC_00A00001_marketing = new BinaryFile('files/FSC_00A00001_marketing.fsc', 'r');
// (async function () {
// try {
// await FSC_00A00001_marketing.open();
//
// await parse(FSC_00A00001_marketing, log('FSC_00A00001_marketing', 25));
//
// await FSC_00A00001_marketing.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const FSC_00E50001 = new BinaryFile('files/FSC_00E50001.fsc', 'r');
// (async function () {
// try {
// await FSC_00E50001.open();
//
// await parse(FSC_00E50001, log('FSC_00E50001', 25));
//
// await FSC_00E50001.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
const FSC_BB81798_0120007C = new BinaryFile('files/FSC_BB81798_0120007C.fsc', 'r');
(async function () {
try {
await FSC_BB81798_0120007C.open();
await parse(FSC_BB81798_0120007C, log('FSC_BB81798_0120007C', 25));
await FSC_BB81798_0120007C.close();
} catch (err) {
console.log(`There was an error: ${err}`);
}
})();
//
// const myBinaryFile1 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1.open();
//
// await parse(myBinaryFile1, log('werk 0', 25));
//
// await myBinaryFile1.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile1_1 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703_grouppe_un_ki.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1_1.open();
//
// await parse(myBinaryFile1_1, log('werk 1', 25));
//
// await myBinaryFile1_1.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile1_2 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703_grouppe_un_ki_be.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1_2.open();
//
// await parse(myBinaryFile1_2, log('werk 2', 25));
//
// await myBinaryFile1_2.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile1_3 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703_grouppe_un_ki_be_ab.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1_3.open();
//
// await parse(myBinaryFile1_3, log('werk 3', 25));
//
// await myBinaryFile1_3.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
// const myBinaryFile1_4 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703_grouppe_un_ki_be_ab_ze.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1_4.open();
//
// await parse(myBinaryFile1_4, log('werk 4', 25));
//
// await myBinaryFile1_4.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
// const myBinaryFile1_5 = new BinaryFile('files/FSC_NU85056_0120007C_werk_703_grouppe_un_ki_be_ab_ze_ze.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile1_5.open();
//
// await parse(myBinaryFile1_5, log('werk 5', 25));
//
// await myBinaryFile1_5.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile2 = new BinaryFile('files/FSC_NU85056_0120007C_marketing_703.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile2.open();
//
// await parse(myBinaryFile2, log('marketing', 25));
//
// await myBinaryFile2.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile3 = new BinaryFile('files/FSC_NU85056_0120007C_kundle_703.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile3.open();
//
// await parse(myBinaryFile3, log('kundle 0', 25));
//
// await myBinaryFile3.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile3_1 = new BinaryFile('files/FSC_NU85056_0120007C_kundle_703_fgn_lang.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile3_1.open();
//
// await parse(myBinaryFile3_1, log('kundle 1', 25));
//
// await myBinaryFile3_1.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile3_2 = new BinaryFile('files/FSC_NU85056_0120007C_kundle_703_keine_indiv.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile3_2.open();
//
// await parse(myBinaryFile3_2, log('kundle 2', 25));
//
// await myBinaryFile3_2.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
//
// const myBinaryFile4 = new BinaryFile('files/FSC_NU85056_0120007C_vertrieb_703.fsc', 'r');
// (async function () {
// try {
// await myBinaryFile4.open();
//
// await parse(myBinaryFile4, log('vertrieb', 25));
//
// await myBinaryFile4.close();
//
// } catch (err) {
// console.log(`There was an error: ${err}`);
// }
// })();
let parse = async (binary, log) => {
let position = 0;
// for(let i = 0; i < 100; i++) {
// const value1 = await binary.readUInt16(i);
// if (value1 === 702 || value1 === 703) {
// log(i - 1, '^', await binary.readUInt8(i - 1));
// log(i, '=', value1);
// }
// const value2 = await binary.readString(3, i);
// if (value2 === '702' || value2 === '703') {
// log(i - 1, '^', await binary.readUInt8(i - 1));
// log(i, '=', value2);
// }
// }
const version = await binary.readUInt8(position);
log(position, 'version', version);
position += 1;
const swIdType = await binary.readUInt8(position);
log(position, 'swIdType', swIdType);
position += 1;
const appNr = await binary.readUInt16(2);
log(position, 'appNr', appNr);
position += 2;
const upgradeIndex = await binary.readUInt16(position);
log(position, 'upgradeIndex', upgradeIndex);
position += 2;
position += 2;
// -----
const lieferantenId = await binary.readString(8, position);
log(position, 'lieferantenId', lieferantenId);
position += 8;
const bestellNr = await binary.readString(7, position);
log(position, 'bestellNr', bestellNr);
position += 7;
const requesterAlgorithm = await binary.readUInt8(position);
//log(position, 'requesterAlgorithm', requesterAlgorithm);
position += 1;
switch(requesterAlgorithm) {
case 0:
const requesterAlgorithmTwo = await binary.readUInt8(position);
position += 1;
//log(position, 'requesterAlgorithmTwo', requesterAlgorithmTwo);
if (requesterAlgorithmTwo === 1) {
position -= 2;
log(position, 'requesterId', await binary.readUInt16(position));
log(position, 'requesterTyp', 'Werk');
position += 2;
} else {
log(position, 'requesterId', await binary.readUInt16(position));
log(position, 'requesterTyp', 'Marketing');
position += 2;
}
break;
case 2:
position -= 1;
log(position, 'requesterId', await binary.readUInt16(position));
log(position, 'requesterTyp', 'Werk');
position += 2;
break;
case 32:
const requesterAlgorithmThree = await binary.readUInt8(position);
if (requesterAlgorithmThree === 32) {
position += 1;
log(position, 'requesterId', await binary.readString(3, position));
log(position, 'requesterTyp', 'Vertrieb');
position += 3;
} else {
log(position, 'requesterId', await binary.readString(3, position));
log(position, 'requesterTyp', 'Kundle');
position += 3;
}
break;
default:
log(position, 'requesterAlgorithm', `unknown = ${requesterAlgorithm}`);
return ;
}
const indivMerkmType = await binary.readUInt8(position);
position += 1;
switch(indivMerkmType) {
case 0:
log(position, 'indivMerkmType', 'keine_indiv');
position += 2;
break;
case 1:
log(position, 'indivMerkmType', 'FGN_kurz');
log(position, 'fgnKurz', await binary.readString(8, position));
position += 9;
break;
case 2:
log(position, 'indivMerkmType', 'FGN_lang');
log(position, 'fgnKurz', await binary.readString(8, position));
position += 9;
break;
default:
log(position, 'indivMerkmType', `unknown = ${indivMerkmType}`);
return ;
}
position = await item(binary, position, log);
const fscsId = await binary.readUInt16(position);
log(position, 'fscsId', fscsId);
position += 2;
const date = await binary.readString(13, position);
log(position, 'date', datetime(date).toUTCString());
};
let item = async (binary, position, log) => {
const type = await binary.readUInt8(position);
//log(position, 'item-type', type);
position += 1;
switch(type) {
case 0:
position += 7;
break;
case 2:
position += 15;
position = await item(binary, position, log);
break;
case 3:
position += 17;
position = await item(binary, position, log);
break;
case 4:
position += 9;
position = await item(binary, position, log);
break;
case 5:
position += 9;
position = await item(binary, position, log);
break;
}
return position;
}
let log = (prefix = 'Log:', length = 4) => {
return function(position, key, value) {
console.log(`${pad(prefix, length)} (${position}) ${key}: ${value}`);
}
function pad(number, length) {
let str = '' + number;
while (str.length < length) {
str = ' ' + str;
}
return str;
}
};
const datetime = (dateString) => {
// YYYYMMDDhhmmZ
let reggie = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})Z/;
let dateArray = reggie.exec(dateString);
return new Date(
(+dateArray[1]),
(+dateArray[2])-1, // Careful, month starts at 0!
(+dateArray[3]),
(+dateArray[4]),
(+dateArray[5]),
0
);
};