@zimo-elektronik/zcan 1.0.50 → 1.0.52

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.
@@ -1 +1 @@
1
- {"version":3,"file":"infoMsg.js","sourceRoot":"","sources":["../../src/info/infoMsg.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,OAAO,EAAiB,MAAM,yBAAyB,CAAC;AAKzE,MAAM,OAAO,UAAW,SAAQ,OAAO;IAE/B,MAAM,CAAC,MAAM,CAAC,IAAa,EAAE,GAAW,IAC9C,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAC,CAAA,CAAA,CAAC;IAElD,YAAY,MAAc,EAAE,IAAiB,EAAE,OAAsB,EAAE;QAEtE,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,KAAK,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAC,CAAC,CAAC;QACrC,IAAG,IAAI,CAAC,MAAM;YACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,KAA6B,OAAS,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAiC,CAAA,CAAA,CAAC;IACzF,IAAI,KAAwB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAe,CAAC,CAAC,CAAC,SAAS,CAAA,CAAA,CAAC;CACnG"}
1
+ {"version":3,"file":"infoMsg.js","sourceRoot":"","sources":["../../src/info/infoMsg.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,OAAO,EAAiB,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAe,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAIvD,M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IAAY;QAEpC,OAAO,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA;IAC/B,CAAC;IAEM,MAAM,CAAC,UAAU,CAAC,IAAY;QAEpC,OAAO,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,CAAA;IAC/B,CAAC;CACD"}
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
7
7
  "repository": "https://github.com/ZIMO-Elektronik/zcan",
8
- "version": "1.0.50",
8
+ "version": "1.0.52",
9
9
  "scripts": {
10
10
  "start": "node dist/main.js",
11
11
  "start:dev": "nodemon --ext js,ts,json,env --exec \"node --experimental-specifier-resolution=node --loader ts-node/esm\" src/main.ts",
@@ -110,18 +110,18 @@ export interface ModulePowerInfoData {
110
110
  temperature: number;
111
111
  }
112
112
 
113
- export interface BidiInfoData {
114
- nid: number;
115
- type: BidiType;
116
- data: BidiDirectionData | number;
117
- }
113
+ // export interface BidiInfoData {
114
+ // nid: number;
115
+ // type: BidiType;
116
+ // data: BidiDirectionData | number;
117
+ // }
118
118
 
119
- export interface BidiDirectionData {
120
- direction?: Direction;
121
- forwardOrReverse?: ForwardOrReverse;
122
- directionChange?: boolean;
123
- directionConfirm?: boolean;
124
- }
119
+ // export interface BidiDirectionData {
120
+ // direction?: Direction;
121
+ // forwardOrReverse?: ForwardOrReverse;
122
+ // directionChange?: boolean;
123
+ // directionConfirm?: boolean;
124
+ // }
125
125
 
126
126
  export interface VehicleStateData {
127
127
  nid: number;
@@ -2,9 +2,8 @@ import {Buffer} from 'buffer';
2
2
  import MX10 from '../MX10';
3
3
  import {Subject} from 'rxjs';
4
4
  import {Query} from '../common/communication';
5
- import {BidiInfoData, BidiDirectionData} from '../common/models';
6
- import {BidiType, Direction, ForwardOrReverse, ModInfoType, MsgMode} from '../common/enums';
7
- import { MsgModInfo } from './infoMsg';
5
+ import {ModInfoType, MsgMode} from '../common/enums';
6
+ import {MsgBidiInfo, MsgModInfo} from './infoMsg';
8
7
 
9
8
  /**
10
9
  *
@@ -14,10 +13,11 @@ export default class InfoGroup
14
13
  {
15
14
  private mx10: MX10;
16
15
 
17
- public readonly onBidiInfoChange = new Subject<BidiInfoData>();
16
+ public readonly onBidiInfoChange = new Subject<MsgBidiInfo>();
18
17
  public readonly onModuleInfoChange = new Subject<MsgModInfo>();
19
18
 
20
19
  private modInfoQ: Query<MsgModInfo> | undefined = undefined;
20
+ private bidiQ: Query<MsgBidiInfo> | undefined = undefined;
21
21
 
22
22
  constructor(mx10: MX10)
23
23
  {
@@ -30,7 +30,6 @@ export default class InfoGroup
30
30
  this.mx10.logInfo.next("mx10.getModuleInfo: failed to acquire lock");
31
31
  return undefined;
32
32
  }
33
-
34
33
  this.modInfoQ = new Query(MsgModInfo.header(MsgMode.REQ, nid), this.onModuleInfoChange);
35
34
  this.modInfoQ.log = ((msg) => {
36
35
  this.mx10.logInfo.next(msg);
@@ -52,6 +51,30 @@ export default class InfoGroup
52
51
  return rv;
53
52
  }
54
53
 
54
+ async getBidiInfo(locoNid: number, type: number): Promise<MsgBidiInfo | undefined>
55
+ {
56
+ if(this.bidiQ !== undefined && !await this.bidiQ.lock()) {
57
+ this.mx10.logInfo.next("mx10.getBidiInfo: failed to acquire lock");
58
+ return undefined;
59
+ }
60
+ this.bidiQ = new Query(MsgBidiInfo.header(MsgMode.REQ, locoNid), this.onBidiInfoChange);
61
+ this.bidiQ.tx = ((header) => {
62
+ const msg = new MsgBidiInfo(header, type, locoNid);
63
+ this.mx10.logInfo.next('bidi query tx: ' + JSON.stringify(msg));
64
+ this.mx10.sendMsg(msg);
65
+ });
66
+ this.bidiQ.match = ((msg) => {
67
+ this.mx10.logInfo.next('bidi query rx: ' + JSON.stringify(msg));
68
+ return (msg.type() === type);
69
+ })
70
+ this.bidiQ.subscribe(false);
71
+ const rv = await this.bidiQ.run();
72
+ this.mx10.logInfo.next("mx10.getBidiInfo.rv: " + JSON.stringify(rv));
73
+ this.bidiQ.unlock();
74
+ this.bidiQ = undefined;
75
+ return rv;
76
+ }
77
+
55
78
  parse(size: number, command: number, mode: number, nid: number, buffer: Buffer)
56
79
  {
57
80
  switch (command) {
@@ -87,41 +110,30 @@ export default class InfoGroup
87
110
  const type = buffer.readUInt16LE(2);
88
111
  const info = buffer.readUInt32LE(4);
89
112
 
90
- let data: BidiDirectionData | number = {};
91
- switch (type) {
92
- case BidiType.DIRECTION:
93
- data.direction = this.parseEastWest(info);
94
- data.directionChange = this.parseDirChange(info);
95
- data.directionConfirm = this.parseDirectionConfirm(info);
96
- data.forwardOrReverse = this.parseFwdRev(info);
97
- break;
98
- default:
99
- data = info;
100
- }
101
-
102
- this.onBidiInfoChange.next({nid: NID, type, data,});
113
+ const msg = new MsgBidiInfo(MsgBidiInfo.header(mode, NID), type, undefined, info);
114
+ this.onBidiInfoChange.next(msg);
103
115
  }
104
116
 
105
- private parseEastWest(data: number)
106
- {
107
- if ((data & 0x02) == 0x02)
108
- return Direction.EAST;
109
- return Direction.WEST;
110
- }
117
+ // private parseEastWest(data: number)
118
+ // {
119
+ // if ((data & 0x02) == 0x02)
120
+ // return Direction.EAST;
121
+ // return Direction.WEST;
122
+ // }
111
123
 
112
- private parseDirChange(data: number)
113
- {
114
- return (data & 0x04) == 0x04;
115
- }
124
+ // private parseDirChange(data: number)
125
+ // {
126
+ // return (data & 0x04) == 0x04;
127
+ // }
116
128
 
117
- private parseFwdRev(data: number)
118
- {
119
- if ((data & 0x01) == 0)
120
- return ForwardOrReverse.REVERSE;
121
- return ForwardOrReverse.FORWARD;
122
- }
123
- private parseDirectionConfirm(data: number)
124
- {
125
- return (data & 0x08) == 0x08;
126
- }
129
+ // private parseFwdRev(data: number)
130
+ // {
131
+ // if ((data & 0x01) == 0)
132
+ // return ForwardOrReverse.REVERSE;
133
+ // return ForwardOrReverse.FORWARD;
134
+ // }
135
+ // private parseDirectionConfirm(data: number)
136
+ // {
137
+ // return (data & 0x08) == 0x08;
138
+ // }
127
139
  }
@@ -18,4 +18,46 @@ export class MsgModInfo extends Message
18
18
  }
19
19
  type(): ModInfoType | undefined {return ((this.data[0].value as unknown) as ModInfoType)}
20
20
  info(): number | undefined {return this.data.length > 1 ? this.data[1].value as number : undefined}
21
+ }
22
+
23
+ export class MsgBidiInfo extends Message
24
+ {
25
+ public static header(mode: MsgMode, nid: number): Header
26
+ {return {group: 0x08, cmd: 0x05, mode: mode, nid}}
27
+
28
+ constructor(header: Header, type: number, nid?: number, info?: number)
29
+ {
30
+ super(header);
31
+
32
+ if(header.mode === MsgMode.REQ) {
33
+ super.push({value: nid || 0, length: 2});
34
+ super.push({value: type, length: 2});
35
+ } else {
36
+ super.push({value: type, length: 2});
37
+ super.push({value: info || 0, length: 4});
38
+ }
39
+ }
40
+ nid(): number {return this.header.mode === MsgMode.REQ ? this.data[0].value as number : this.header.nid || 0}
41
+ type(): number {return this.data[this.header.mode === MsgMode.REQ ? 1 : 0].value as number}
42
+ info(): number | undefined {return this.data.length > 1 ? this.data[1].value as number : undefined}
43
+
44
+ public static dirEast(info: number)
45
+ {
46
+ return ((info & 0x02) == 0x02)
47
+ }
48
+
49
+ public static dirChanging(info: number)
50
+ {
51
+ return ((info & 0x04) == 0x04)
52
+ }
53
+
54
+ public static dirForward(info: number)
55
+ {
56
+ return ((info & 0x01) == 0x01)
57
+ }
58
+
59
+ public static dirConfirm(info: number)
60
+ {
61
+ return ((info & 0x08) == 0x08)
62
+ }
21
63
  }