@zimo-elektronik/zcan 1.0.45 → 1.0.47

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/src/MX10.ts CHANGED
@@ -172,7 +172,7 @@ export default class MX10
172
172
  sendMsg(msg: Message, force = false)
173
173
  {
174
174
  const buffer = msg.udp(this.myNID);
175
- this.logInfo.next("mx10.sendMsg: " + JSON.stringify(buffer));
175
+ // this.logInfo.next("mx10.sendMsg: " + JSON.stringify(buffer));
176
176
  this.send(buffer, force);
177
177
  }
178
178
 
@@ -270,65 +270,72 @@ export default class MX10
270
270
  // this.logInfo.next(JSON.stringify(message));
271
271
  this.printReadout(group, command, mode, nid, size, buffer, false);
272
272
 
273
- switch (group) {
274
- case 0x00:
275
- this.systemControl.parse(size, command, mode, nid, buffer);
276
- break;
277
- case 0x01:
278
- this.accessoryCommand.parse(size, command, mode, nid, buffer);
279
- break;
280
- case 0x02:
281
- this.vehicle.parse(size, command, mode, nid, buffer);
282
- break;
283
- case 0x05:
284
- this.trainControl.parse(size, command, mode, nid, buffer);
285
- break;
286
- case 0x06:
287
- case 0x16:
288
- this.trackCfg.parse(size, command, mode, nid, buffer);
289
- break;
290
- case 0x07:
291
- this.data.parse(size, command, mode, nid, buffer);
292
- break;
293
- case 0x08:
294
- this.info.parse(size, command, mode, nid, buffer);
295
- break;
296
- case 0x09:
297
- this.propertyConfig.parse(size, command, mode, nid, buffer);
298
- break;
299
- case 0x0a:
300
- this.network.parse(size, command, mode, nid, buffer);
301
- break;
302
- case 0x0b:
303
- this.railwayControl.parse(size, command, mode, nid, buffer);
304
- break;
305
- case 0x0c:
306
- this.zimoProgrammableScript.parse(size, command, mode, nid, buffer);
307
- break;
308
- case 0x0e:
309
- this.fileControl.parse(size, command, mode, nid, buffer);
310
- break;
311
- case 0x0f:
312
- this.fileTransfer.parse(size, command, mode, nid, buffer);
313
- break;
314
- case 0x12:
315
- this.lanLocoState.parse(size, command, mode, nid, buffer);
316
- break;
317
- case 0x17:
318
- this.lanData.parse(size, command, mode, nid, buffer);
319
- break;
320
- case 0x18:
321
- this.lanInfo.parse(size, command, mode, nid, buffer);
322
- break;
323
- case 0x1a:
324
- this.lanNetwork.parse(size, command, mode, nid, buffer);
325
- break;
326
- case 0x1c:
327
- this.lanZimoProgrammableScript.parse(size, command, mode, nid, buffer);
328
- break;
329
- default:
330
- // eslint-disable-next-line no-console
331
- // console.warn('Unknown group: ' + Number(group).toString(16));
273
+ try {
274
+ switch (group) {
275
+ case 0x00:
276
+ this.systemControl.parse(size, command, mode, nid, buffer);
277
+ break;
278
+ case 0x01:
279
+ this.accessoryCommand.parse(size, command, mode, nid, buffer);
280
+ break;
281
+ case 0x02:
282
+ this.vehicle.parse(size, command, mode, nid, buffer);
283
+ break;
284
+ case 0x05:
285
+ this.trainControl.parse(size, command, mode, nid, buffer);
286
+ break;
287
+ case 0x06:
288
+ case 0x16:
289
+ this.trackCfg.parse(size, command, mode, nid, buffer);
290
+ break;
291
+ case 0x07:
292
+ this.data.parse(size, command, mode, nid, buffer);
293
+ break;
294
+ case 0x08:
295
+ this.info.parse(size, command, mode, nid, buffer);
296
+ break;
297
+ case 0x09:
298
+ this.propertyConfig.parse(size, command, mode, nid, buffer);
299
+ break;
300
+ case 0x0a:
301
+ this.network.parse(size, command, mode, nid, buffer);
302
+ break;
303
+ case 0x0b:
304
+ this.railwayControl.parse(size, command, mode, nid, buffer);
305
+ break;
306
+ case 0x0c:
307
+ this.zimoProgrammableScript.parse(size, command, mode, nid, buffer);
308
+ break;
309
+ case 0x0e:
310
+ this.fileControl.parse(size, command, mode, nid, buffer);
311
+ break;
312
+ case 0x0f:
313
+ this.fileTransfer.parse(size, command, mode, nid, buffer);
314
+ break;
315
+ case 0x12:
316
+ this.lanLocoState.parse(size, command, mode, nid, buffer);
317
+ break;
318
+ case 0x17:
319
+ this.lanData.parse(size, command, mode, nid, buffer);
320
+ break;
321
+ case 0x18:
322
+ this.lanInfo.parse(size, command, mode, nid, buffer);
323
+ break;
324
+ case 0x1a:
325
+ this.lanNetwork.parse(size, command, mode, nid, buffer);
326
+ break;
327
+ case 0x1c:
328
+ this.lanZimoProgrammableScript.parse(size, command, mode, nid, buffer);
329
+ break;
330
+ case 0x2f:
331
+ break;
332
+ default:
333
+ this.logInfo.next('Zcan group ' + group + ' not parsed: ' + JSON.stringify(message));
334
+ }
335
+ } catch(err: any) {
336
+ this.logError.next('failed to parse zcan message: ' + JSON.stringify(message));
337
+ if(err.message)
338
+ this.logError.next(err.message);
332
339
  }
333
340
  }
334
341
 
@@ -69,8 +69,7 @@ export default class AccessoryCommandGroup {
69
69
  this.parseAccessoryPin(size, mode, nid, buffer);
70
70
  break;
71
71
  default:
72
- // eslint-disable-next-line no-console
73
- console.warn('command not parsed: ' + command.toString());
72
+ this.mx10.logInfo.next('accessoryCommandGroup command ' + command + ' not parsed: ' + JSON.stringify(buffer));
74
73
  }
75
74
  }
76
75
 
@@ -46,15 +46,15 @@ export default class DataGroup
46
46
  });
47
47
  this.groupCountQ.tx = ((header) => {
48
48
  const msg = new MsgGroupCount(header, groupNid);
49
- this.mx10.logInfo.next('groupCount query tx: ' + JSON.stringify(msg));
49
+ // this.mx10.logInfo.next('groupCount query tx: ' + JSON.stringify(msg));
50
50
  this.mx10.sendMsg(msg);
51
51
  });
52
52
  this.groupCountQ.match = ((msg) => {
53
- this.mx10.logInfo.next('groupCount query rx: ' + JSON.stringify(msg));
53
+ // this.mx10.logInfo.next('groupCount query rx: ' + JSON.stringify(msg));
54
54
  return (msg.group() === groupNid);
55
55
  })
56
56
  const rv = await this.groupCountQ.run();
57
- this.mx10.logInfo.next("mx10.groupCount.rv: " + JSON.stringify(rv));
57
+ // this.mx10.logInfo.next("mx10.groupCount.rv: " + JSON.stringify(rv));
58
58
  this.groupCountQ.unlock();
59
59
  this.groupCountQ = undefined;
60
60
  return rv;
@@ -72,12 +72,12 @@ export default class DataGroup
72
72
  });
73
73
  this.byIndexQ.tx = ((header) => {
74
74
  const msg = new MsgItemsByIndexReq(header, this.mx10.myNID, groupNid, index);
75
- this.mx10.logInfo.next('listItemsByIndex query tx: ' + JSON.stringify(msg));
75
+ // this.mx10.logInfo.next('listItemsByIndex query tx: ' + JSON.stringify(msg));
76
76
  this.mx10.sendMsg(msg);
77
77
  });
78
78
  this.byIndexQ.match = ((msg) => {
79
- this.mx10.logInfo.next('listItemsByIndex query rx: ' + JSON.stringify(msg));
80
- this.mx10.logInfo.next('listItemsByIndex query rx: ' + msg.itemNid());
79
+ // this.mx10.logInfo.next('listItemsByIndex query rx: ' + JSON.stringify(msg));
80
+ // this.mx10.logInfo.next('listItemsByIndex query rx: ' + msg.itemNid());
81
81
  const nid = msg.itemNid();
82
82
  switch(groupNid) {
83
83
  case 0:
@@ -231,11 +231,11 @@ export default class DataGroup
231
231
  switch (command)
232
232
  {
233
233
  case 0x00:
234
- this.mx10.logInfo.next('parseGroupCount: ' + JSON.stringify(buffer));
234
+ // this.mx10.logInfo.next('parseGroupCount: ' + JSON.stringify(buffer));
235
235
  this.parseGroupCount(size, mode, nid, buffer);
236
236
  break;
237
237
  case 0x01:
238
- this.mx10.logInfo.next('parseItemListByIndex: ' + JSON.stringify(buffer));
238
+ // this.mx10.logInfo.next('parseItemListByIndex: ' + JSON.stringify(buffer));
239
239
  this.parseItemListByIndex(size, mode, nid, buffer);
240
240
  break;
241
241
  case 0x02:
@@ -258,7 +258,7 @@ export default class DataGroup
258
258
  this.parseDataNameExtended(size, mode, nid, buffer);
259
259
  break;
260
260
  default:
261
- this.mx10.logInfo.next('command not parsed: ' + command.toString());
261
+ this.mx10.logInfo.next('dataGroup command ' + command + ' not parsed: ' + JSON.stringify(buffer));
262
262
  }
263
263
  }
264
264
 
@@ -17,12 +17,13 @@ import { MsgLocoGuiReq, MsgLocoGuiRsp } from './lanDataMsg';
17
17
  export default class LanDataGroup
18
18
  {
19
19
  public readonly onLocoGuiExtended = new Subject<MsgLocoGuiRsp>();
20
- public readonly onLocoGuiMXExtended = new Subject<LocoGuiMXExtended>();
20
+ // public readonly onOldLocoGuiExtended = new Subject<MsgOldLocoGuiRsp>();
21
21
  public readonly onDataValueExtended = new Subject<DataValueExtendedData>();
22
22
  public readonly onDataNameExtended = new Subject<DataNameExtendedData>();
23
23
  public readonly onLocoSpeedTabExtended = new Subject<LocoSpeedTabExtended>();
24
24
 
25
25
  private locoGuiQ: Query<MsgLocoGuiRsp> | undefined = undefined;
26
+ // private oldLocoGuiQ: Query<MsgOldLocoGuiRsp> | undefined = undefined;
26
27
 
27
28
  private mx10: MX10;
28
29
 
@@ -82,7 +83,7 @@ export default class LanDataGroup
82
83
  ]);
83
84
  }
84
85
 
85
- async locoGuiExtended(nid: number): Promise<MsgLocoGuiRsp | undefined>
86
+ async getLocoGuiExtended(nid: number): Promise<MsgLocoGuiRsp | undefined>
86
87
  {
87
88
  if(this.locoGuiQ !== undefined && !await this.locoGuiQ.lock()) {
88
89
  this.mx10.logInfo.next("mx10.locoGuiExtended: failed to acquire lock");
@@ -94,20 +95,77 @@ export default class LanDataGroup
94
95
  });
95
96
  this.locoGuiQ.tx = ((header) => {
96
97
  const msg = new MsgLocoGuiReq(header, nid, 0);
97
- this.mx10.logInfo.next('locoGuiExtended query tx: ' + JSON.stringify(msg));
98
+ // this.mx10.logInfo.next('locoGuiExtended query tx: ' + JSON.stringify(msg));
98
99
  this.mx10.sendMsg(msg);
99
100
  });
100
101
  this.locoGuiQ.match = ((msg) => {
101
- this.mx10.logInfo.next('locoGuiExtended query rx: ' + JSON.stringify(msg));
102
+ // this.mx10.logInfo.next('locoGuiExtended query rx: ' + JSON.stringify(msg));
102
103
  return (msg.locoNid() === nid);
103
104
  })
104
105
  const rv = await this.locoGuiQ.run();
105
- this.mx10.logInfo.next("mx10.locoGuiExtended.rv: " + JSON.stringify(rv));
106
+ // this.mx10.logInfo.next("mx10.locoGuiExtended.rv: " + JSON.stringify(rv));
106
107
  this.locoGuiQ.unlock();
107
108
  this.locoGuiQ = undefined;
108
109
  return rv;
109
110
  }
110
111
 
112
+ async setLocoGuiExtended(loco: Train): Promise<MsgLocoGuiRsp | undefined>
113
+ {
114
+ if(this.locoGuiQ !== undefined && !await this.locoGuiQ.lock()) {
115
+ this.mx10.logInfo.next("mx10.locoGuiExtended: failed to acquire lock");
116
+ return undefined;
117
+ }
118
+ this.locoGuiQ = new Query(MsgLocoGuiReq.header(MsgMode.CMD, this.mx10.myNID), this.onLocoGuiExtended);
119
+ this.locoGuiQ.log = ((msg) => {
120
+ this.mx10.logInfo.next(msg);
121
+ });
122
+ this.locoGuiQ.tx = ((header) => {
123
+ const msg = new MsgLocoGuiRsp(header, loco.nid, loco.subId, 0, 0, loco.group, loco.name,
124
+ loco.image ? parseInt(loco.image) : 0, 0, parseInt(loco.tacho), 0, loco.speedFwd, loco.speedRev,
125
+ loco.speedRange, loco.driveType, parseInt(loco.era), loco.countryCode,
126
+ loco.functions.map(fun => fun.icon ? parseInt(fun.icon) : 0), loco.functions.map(fun => fun.mode)
127
+ );
128
+ // this.mx10.logInfo.next('locoGuiExtended query tx: ' + JSON.stringify(msg));
129
+ this.mx10.sendMsg(msg);
130
+ });
131
+ this.locoGuiQ.match = ((msg) => {
132
+ // this.mx10.logInfo.next('locoGuiExtended query rx: ' + JSON.stringify(msg));
133
+ return (msg.locoNid() === loco.nid);
134
+ })
135
+ this.locoGuiQ.subscribe(false);
136
+ const rv = await this.locoGuiQ.run(40);
137
+ // this.mx10.logInfo.next("mx10.locoGuiExtended.rv: " + JSON.stringify(rv));
138
+ this.locoGuiQ.unlock();
139
+ this.locoGuiQ = undefined;
140
+ return rv;
141
+ }
142
+
143
+ // async oldLocoGuiExtended(nid: number): Promise<MsgOldLocoGuiRsp | undefined>
144
+ // {
145
+ // if(this.oldLocoGuiQ !== undefined && !await this.oldLocoGuiQ.lock()) {
146
+ // this.mx10.logInfo.next("mx10.locoGuiExtended: failed to acquire lock");
147
+ // return undefined;
148
+ // }
149
+ // this.oldLocoGuiQ = new Query(MsgOldLocoGuiReq.header(MsgMode.REQ, this.mx10.mx10NID), this.onOldLocoGuiExtended);
150
+ // this.oldLocoGuiQ.log = ((msg) => {
151
+ // this.mx10.logInfo.next(msg);
152
+ // });
153
+ // this.oldLocoGuiQ.tx = ((header) => {
154
+ // const msg = new MsgOldLocoGuiReq(header, nid, 0);
155
+ // this.mx10.logInfo.next('locoGuiExtended query tx: ' + JSON.stringify(msg));
156
+ // this.mx10.sendMsg(msg);
157
+ // });
158
+ // this.oldLocoGuiQ.match = ((msg) => {
159
+ // this.mx10.logInfo.next('locoGuiExtended query rx: ' + JSON.stringify(msg));
160
+ // return (msg.locoNid() === nid);
161
+ // })
162
+ // const rv = await this.oldLocoGuiQ.run();
163
+ // this.mx10.logInfo.next("mx10.locoGuiExtended.rv: " + JSON.stringify(rv));
164
+ // this.oldLocoGuiQ.unlock();
165
+ // this.oldLocoGuiQ = undefined;
166
+ // return rv;
167
+ // }
168
+
111
169
  // locoGuiExtended(NID: number)
112
170
  // {
113
171
  // this.mx10.sendData(0x17, 0x27, [
@@ -117,14 +175,14 @@ export default class LanDataGroup
117
175
  // ], 0b00);
118
176
  // }
119
177
 
120
- locoGuiMXExtended(NID: number)
121
- {
122
- this.mx10.sendData(0x17,0x28, [
123
- {value: this.mx10.mx10NID, length: 2},
124
- {value: NID, length: 2},
125
- {value: 0, length: 2},
126
- ], 0b00);
127
- }
178
+ // locoGuiMXExtended(NID: number)
179
+ // {
180
+ // this.mx10.sendData(0x17,0x28, [
181
+ // {value: this.mx10.mx10NID, length: 2},
182
+ // {value: NID, length: 2},
183
+ // {value: 0, length: 2},
184
+ // ], 0b00);
185
+ // }
128
186
 
129
187
  locoSpeedTapExtended(NID: number)
130
188
  {
@@ -136,10 +194,10 @@ export default class LanDataGroup
136
194
  ], 0b00);
137
195
  }
138
196
 
139
- mxUpdateFnIcons(destructuredBuffer: ZcanDataArray)
140
- {
141
- this.mx10.sendData(0x17, 0x28, destructuredBuffer, 0b01);
142
- }
197
+ // mxUpdateFnIcons(destructuredBuffer: ZcanDataArray)
198
+ // {
199
+ // this.mx10.sendData(0x17, 0x28, destructuredBuffer, 0b01);
200
+ // }
143
201
 
144
202
  parse(size: number, command: number, mode: number, nid: number, buffer: Buffer)
145
203
  {
@@ -151,15 +209,17 @@ export default class LanDataGroup
151
209
  case 0x10:
152
210
  this.parseDataNameExtended(size, mode, nid, buffer);
153
211
  break;
154
- case 0x27:
155
- this.parseLocoGuiExtended(size, mode, nid, buffer);
156
- break;
212
+ // case 0x27:
213
+ // this.parseOldLocoGuiExtended(size, mode, nid, buffer);
214
+ // break;
157
215
  case 0x28:
158
- this.parseLocoGuiMXExtended(size, mode, nid, buffer);
216
+ this.parseLocoGuiExtended(size, mode, nid, buffer);
159
217
  break;
160
218
  case 0x19:
161
219
  this.parseLocoSpeedTabExtended(size, mode, nid, buffer);
162
220
  break;
221
+ default:
222
+ this.mx10.logInfo.next('lanDataGroup command ' + command + ' not parsed: ' + JSON.stringify(buffer));
163
223
  }
164
224
  }
165
225
 
@@ -212,92 +272,46 @@ export default class LanDataGroup
212
272
  this.onDataNameExtended.next({nid: NID, name});
213
273
  }
214
274
 
215
- // 0x17.0x27
275
+ // 0x17.0x28
216
276
  private parseLocoGuiExtended(size: number, mode: number, nid: number, buffer: Buffer)
217
277
  {
218
278
  if(!this.onLocoGuiExtended.observed)
219
279
  return;
220
280
 
221
- const NID = buffer.readUInt16LE(0);
222
- const SubID = buffer.readUInt16LE(2);
223
- const vehicleGroup = buffer.readUInt16LE(4);
224
- const name = ExtendedASCII.byte2str(buffer.subarray(6, 32));
225
- const imageId = buffer.readUInt16LE(38);
226
- const tacho = buffer.readUInt16LE(40);
227
- const speedFwd = buffer.readUInt16LE(42);
228
- const speedRev = buffer.readUInt16LE(44);
229
- const speedRange = buffer.readUInt16LE(46);
230
- const driveType = buffer.readUInt16LE(48);
231
- const era = buffer.readUInt16LE(50);
232
- const countryCode = buffer.readUInt16LE(52);
233
- const functions: number[] = [];
234
- for (let i = 0; i < 32; i++) {
235
- const fun = buffer.readUInt16LE(54 + 2*i);
236
- functions.push(fun);
237
- }
238
-
239
- const msg = new MsgLocoGuiRsp(MsgLocoGuiRsp.header(mode, nid), NID, SubID, vehicleGroup, name, imageId, tacho, speedFwd, speedRev, speedRange,
240
- driveType, era, countryCode, functions);
241
-
242
- this.onLocoGuiExtended.next(msg);
243
-
244
- // // reading 64 bytes of functions
245
- // const functions = Array<TrainFunction>();
246
- // for (let i = 0; i < 32; i++) {
247
- // const icon = buffer.readUInt16LE(54 + i * 2);
248
- // const iconString =
249
- // icon === 0 ? String(i).padStart(2, '0') : String(icon);
250
- // functions.push({
251
- // mode: FunctionMode.switch,
252
- // active: false,
253
- // icon: iconString.padStart(4, icon === 0 ? '07' : '0'),
254
- // });
255
- // }
256
- // this.onLocoGuiExtended.next({nid: NID, subId: SubID, name: name, group: vehicleGroup,
257
- // image: imageId == 0 ? undefined : imageId.toString(), tacho: tacho.toString(),
258
- // speedFwd: speedFwd, speedRev: speedRev, speedRange: speedRange,
259
- // operatingMode: OperatingMode.UNKNOWN, driveType: driveType, era: this.parseEra(era),
260
- // countryCode: countryCode, functions,
261
- // });
262
- }
263
-
264
- // 0x17.0x28
265
- private parseLocoGuiMXExtended(size: number, mode: number, nid: number, buffer: Buffer)
266
- {
267
- if(!this.onLocoGuiMXExtended.observed)
268
- return;
281
+ // this.mx10.logInfo.next('parseLocoGuiExtended: ' + JSON.stringify(buffer));
269
282
 
270
283
  const NID = buffer.readUInt16LE(0);
271
- const name = ExtendedASCII.byte2str(buffer.subarray(12, 38));
284
+ const SubID = buffer.readUInt16LE(2);
285
+ const version = buffer.readUInt32LE(4);
286
+ const flags = buffer.readUInt16LE(8);
287
+ const group = buffer.readUInt16LE(10);
288
+ const name = ExtendedASCII.byte2str(buffer.subarray(12, 32));
272
289
  const imageId = buffer.readUInt16LE(44);
273
-
274
- // TODO: after documentation
275
- // const SubID = buffer.readUInt16LE(2);
276
- // const vehicleGroup = buffer.readUInt16LE(4);
277
-
278
- // const name = ExtendedASCII.byte2str(buffer.subarray(6, 32));
279
- // const imageId = buffer.readUInt16LE(38);
280
- // const tacho = buffer.readUInt16LE(40);
281
- // const speedFwd = buffer.readUInt16LE(42);
282
- // const speedRev = buffer.readUInt16LE(44);
283
- // const speedRange = buffer.readUInt16LE(46);
284
- // const driveType = buffer.readUInt16LE(48);
285
- // const era = buffer.readUInt16LE(50);
286
- // const countryCode = buffer.readUInt16LE(52);
287
-
288
- // reading 64 bytes of functions
289
- const functions = Array<TrainFunction>();
290
+ const imageCrc = buffer.readUInt32LE(46);
291
+ const tachoId = buffer.readUInt16LE(50);
292
+ const tachoCrc = buffer.readUInt32LE(52);
293
+ const speedFwd = buffer.readUInt16LE(56);
294
+ const speedRev = buffer.readUInt16LE(58);
295
+ const speedRank = buffer.readUInt16LE(60);
296
+ const driveType = buffer.readUInt16LE(62);
297
+ const era = buffer.readUInt16LE(64);
298
+ const countryCode = buffer.readUInt16LE(66);
299
+ const funImg: number[] = [];
290
300
  for (let i = 0; i < 64; i++) {
291
- const icon = buffer.readUInt16LE(68 + i * 2);
292
- const fxMode = buffer.readUInt16LE(196 + i * 2) as FunctionMode;
293
- const iconString = icon === 0 ? String(i).padStart(2, '0') : String(icon);
294
- functions.push({mode: fxMode, active: false, icon: iconString.padStart(4, icon === 0 ? '07' : '0'),
295
- });
301
+ const fun = buffer.readUInt16LE(68 + 2*i);
302
+ funImg.push(fun);
303
+ }
304
+ const funMode: number[] = [];
305
+ for (let i = 0; i < 64; i++) {
306
+ const fun = buffer.readUInt16LE(132 + 2*i);
307
+ funMode.push(fun);
296
308
  }
297
309
 
298
- //TODO: implement rest
299
- this.onLocoGuiMXExtended.next({nid: NID, name: name, image: imageId == 0 ? undefined : imageId.toString(),
300
- destructuredBuffer: this.destructureBuffer(buffer), functions});
310
+ const msg = new MsgLocoGuiRsp(MsgLocoGuiRsp.header(mode, nid), NID, SubID, version, flags, group, name,
311
+ imageId, imageCrc, tachoId, tachoCrc, speedFwd, speedRev, speedRank, driveType, era, countryCode,
312
+ funImg, funMode);
313
+
314
+ this.onLocoGuiExtended.next(msg);
301
315
  }
302
316
 
303
317
  // 0x17.0x19
@@ -3,10 +3,77 @@ import { Header, Message } from "../common/communication";
3
3
  import { TrainFunction } from "../docs_entrypoint";
4
4
 
5
5
 
6
+ // export class MsgOldLocoGuiReq extends Message
7
+ // {
8
+ // public static header(mode: MsgMode, nid: number): Header
9
+ // {return {group: 0x17, cmd: 0x27, mode: mode, nid: nid}}
10
+
11
+ // constructor(header: Header, locoNid: number, subNid: number)
12
+ // {
13
+ // super(header);
14
+ // super.push({value: locoNid, length: 2});
15
+ // super.push({value: subNid, length: 2});
16
+ // }
17
+ // locoNid(): number {return (this.data[0].value as number)}
18
+ // subNid(): number {return (this.data[1].value as number)}
19
+ // }
20
+
21
+ // export class MsgOldLocoGuiRsp extends Message
22
+ // {
23
+ // public static header(mode: MsgMode, nid: number): Header
24
+ // {return {group: 0x17, cmd: 0x27, mode: mode, nid: nid}}
25
+
26
+ // constructor(header: Header, locoNid: number, subNid: number, group: number, name: string, imageId: number,
27
+ // tacho: number, speedFwd: number, speedRev: number, speedRange: number, driveType: number, era: number,
28
+ // country: number, functions: number[])
29
+ // {
30
+ // super(header);
31
+ // super.push({value: locoNid, length: 2});
32
+ // super.push({value: subNid, length: 2});
33
+ // super.push({value: group, length: 2});
34
+ // super.push({value: name, length: 32});
35
+ // super.push({value: imageId, length: 2});
36
+ // super.push({value: tacho, length: 2});
37
+ // super.push({value: speedFwd, length: 2});
38
+ // super.push({value: speedRev, length: 2});
39
+ // super.push({value: speedRange, length: 2});
40
+ // super.push({value: driveType, length: 2});
41
+ // super.push({value: era, length: 2});
42
+ // super.push({value: country, length: 2});
43
+ // functions.forEach(funk => {
44
+ // super.push({value: funk, length: 2});
45
+ // });
46
+ // }
47
+ // locoNid(): number {return (this.data[0].value as number)}
48
+ // subNid(): number {return (this.data[1].value as number)}
49
+ // group(): number {return (this.data[2].value as number)}
50
+ // name(): string {return (this.data[3].value as string)}
51
+ // imageId(): number {return (this.data[4].value as number)}
52
+ // tacho(): number {return (this.data[5].value as number)}
53
+ // speedFwd(): number {return (this.data[6].value as number)}
54
+ // speedRev(): number {return (this.data[7].value as number)}
55
+ // speedRange(): number {return (this.data[8].value as number)}
56
+ // driveType(): number {return (this.data[9].value as number)}
57
+ // era(): number {return (this.data[10].value as number)}
58
+ // country(): number {return (this.data[11].value as number)}
59
+ // functions(): Array<TrainFunction>
60
+ // {
61
+ // const rv = Array<TrainFunction>();
62
+ // for (let i = 12; i < this.data.length; i++) {
63
+ // const icon = (this.data[i].value as number);
64
+ // const iconString = icon === 0 ? String(i).padStart(2, '0') : String(icon);
65
+ // rv.push({mode: FunctionMode.switch, active: false,
66
+ // icon: iconString.padStart(4, icon === 0 ? '07' : '0'),
67
+ // });
68
+ // }
69
+ // return rv;
70
+ // }
71
+ // }
72
+
6
73
  export class MsgLocoGuiReq extends Message
7
74
  {
8
75
  public static header(mode: MsgMode, nid: number): Header
9
- {return {group: 0x17, cmd: 0x27, mode: mode, nid: nid}}
76
+ {return {group: 0x17, cmd: 0x28, mode: mode, nid: nid}}
10
77
 
11
78
  constructor(header: Header, locoNid: number, subNid: number)
12
79
  {
@@ -21,51 +88,74 @@ export class MsgLocoGuiReq extends Message
21
88
  export class MsgLocoGuiRsp extends Message
22
89
  {
23
90
  public static header(mode: MsgMode, nid: number): Header
24
- {return {group: 0x17, cmd: 0x27, mode: mode, nid: nid}}
91
+ {return {group: 0x17, cmd: 0x28, mode: mode, nid: nid}}
25
92
 
26
- constructor(header: Header, locoNid: number, subNid: number, group: number, name: string, imageId: number,
27
- tacho: number, speedFwd: number, speedRev: number, speedRange: number, driveType: number, era: number,
28
- country: number, functions: number[])
93
+ constructor(header: Header, locoNid: number, subNid: number, version: number, flags: number, group: number,
94
+ name: string, imageId: number, imageCrc: number, tachoId: number, tachoCrc: number,
95
+ speedFwd: number, speedRev: number, speedRnk: number, driveType: number, era: number,
96
+ country: number, funImgs: number[], funModes: number[])
29
97
  {
30
98
  super(header);
31
99
  super.push({value: locoNid, length: 2});
32
100
  super.push({value: subNid, length: 2});
101
+ super.push({value: version, length: 4});
102
+ super.push({value: flags, length: 2});
33
103
  super.push({value: group, length: 2});
34
104
  super.push({value: name, length: 32});
35
105
  super.push({value: imageId, length: 2});
36
- super.push({value: tacho, length: 2});
106
+ super.push({value: imageCrc, length: 4});
107
+ super.push({value: tachoId, length: 2});
108
+ super.push({value: tachoCrc, length: 4});
37
109
  super.push({value: speedFwd, length: 2});
38
110
  super.push({value: speedRev, length: 2});
39
- super.push({value: speedRange, length: 2});
111
+ super.push({value: speedRnk, length: 2});
40
112
  super.push({value: driveType, length: 2});
41
113
  super.push({value: era, length: 2});
42
114
  super.push({value: country, length: 2});
43
- functions.forEach(funk => {
115
+ funImgs.forEach(funk => {
116
+ super.push({value: funk, length: 2});
117
+ });
118
+ funModes.forEach(funk => {
44
119
  super.push({value: funk, length: 2});
45
120
  });
46
121
  }
47
122
  locoNid(): number {return (this.data[0].value as number)}
48
123
  subNid(): number {return (this.data[1].value as number)}
49
- group(): number {return (this.data[2].value as number)}
50
- name(): string {return (this.data[3].value as string)}
51
- imageId(): number {return (this.data[4].value as number)}
52
- tacho(): number {return (this.data[5].value as number)}
53
- speedFwd(): number {return (this.data[6].value as number)}
54
- speedRev(): number {return (this.data[7].value as number)}
55
- speedRange(): number {return (this.data[8].value as number)}
56
- driveType(): number {return (this.data[9].value as number)}
57
- era(): number {return (this.data[10].value as number)}
58
- country(): number {return (this.data[11].value as number)}
124
+ group(): number {return (this.data[4].value as number)}
125
+ name(): string {return (this.data[5].value as string)}
126
+ imageId(): number {return (this.data[6].value as number)}
127
+ tacho(): number {return (this.data[8].value as number)}
128
+ speedFwd(): number {return (this.data[10].value as number)}
129
+ speedRev(): number {return (this.data[11].value as number)}
130
+ speedRnk(): number {return (this.data[12].value as number)}
131
+ driveType(): number {return (this.data[13].value as number)}
132
+ era(): number {return (this.data[14].value as number)}
133
+ country(): number {return (this.data[15].value as number)}
59
134
  functions(): Array<TrainFunction>
60
135
  {
61
136
  const rv = Array<TrainFunction>();
62
- for (let i = 12; i < this.data.length; i++) {
137
+ for (let i = 16; i < 80; i++) {
63
138
  const icon = (this.data[i].value as number);
64
139
  const iconString = icon === 0 ? String(i).padStart(2, '0') : String(icon);
65
140
  rv.push({mode: FunctionMode.switch, active: false,
66
141
  icon: iconString.padStart(4, icon === 0 ? '07' : '0'),
67
142
  });
68
143
  }
144
+ for (let i = 80; i < 144; i++) {
145
+ rv[i-80].mode = this.data[i].value as number;
146
+ }
69
147
  return rv;
70
148
  }
149
+ // funModes(): Array<TrainFunction>
150
+ // {
151
+ // const rv = Array<TrainFunction>();
152
+ // for (let i = 12; i < this.data.length; i++) {
153
+ // const icon = (this.data[i].value as number);
154
+ // const iconString = icon === 0 ? String(i).padStart(2, '0') : String(icon);
155
+ // rv.push({mode: FunctionMode.switch, active: false,
156
+ // icon: iconString.padStart(4, icon === 0 ? '07' : '0'),
157
+ // });
158
+ // }
159
+ // return rv;
160
+ // }
71
161
  }