motion-master-client 0.0.19 → 0.0.20

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/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "motion-master-client",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "type": "commonjs",
5
5
  "description": "A library and CLI program used for communicating with Motion Master.",
6
6
  "dependencies": {
7
7
  "fast-deep-equal": "^3.1.3",
8
8
  "lodash": "^4.17.21",
9
- "long": "5.2.1",
9
+ "papaparse": "^5.4.1",
10
10
  "protobufjs": "^7.2.3",
11
- "roarr": "^7.14.1",
12
- "rxjs": "~7.5.0",
13
- "semver": "7.3.8",
11
+ "roarr": "^7.15.0",
12
+ "rxjs": "^7.8.1",
13
+ "semver": "7.4.0",
14
14
  "uuid": "^9.0.0"
15
15
  },
16
16
  "peerDependencies": {
17
- "tslib": "^2.4.0"
17
+ "tslib": "2.5.2"
18
18
  },
19
19
  "main": "./src/index.js",
20
20
  "types": "./src/index.d.ts"
package/src/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './lib/cia402';
2
+ export * from './lib/config-file';
2
3
  export * from './lib/device-log-line';
3
4
  export * from './lib/device-parameter';
5
+ export * from './lib/device';
4
6
  export * from './lib/hardware-description';
5
7
  export * from './lib/monitoring-config';
6
8
  export * from './lib/monitoring-entry';
package/src/index.js CHANGED
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/cia402"), exports);
5
+ tslib_1.__exportStar(require("./lib/config-file"), exports);
5
6
  tslib_1.__exportStar(require("./lib/device-log-line"), exports);
6
7
  tslib_1.__exportStar(require("./lib/device-parameter"), exports);
8
+ tslib_1.__exportStar(require("./lib/device"), exports);
7
9
  tslib_1.__exportStar(require("./lib/hardware-description"), exports);
8
10
  tslib_1.__exportStar(require("./lib/monitoring-config"), exports);
9
11
  tslib_1.__exportStar(require("./lib/monitoring-entry"), exports);
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/motion-master-client/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,gEAAsC;AACtC,iEAAuC;AACvC,qEAA2C;AAC3C,kEAAwC;AACxC,iEAAuC;AACvC,qEAA2C;AAC3C,6EAAmD;AACnD,6EAAmD;AACnD,iFAAuD;AACvD,oFAA0D;AAC1D,6EAAmD;AACnD,6EAAmD;AACnD,iFAAuD;AACvD,oFAA0D;AAC1D,0DAAgC;AAChC,wDAA8B;AAC9B,0DAAgC;AAChC,wEAA8C;AAC9C,gEAAsC;AACtC,sDAA4B;AAC5B,qDAA2B;AAC3B,qDAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/motion-master-client/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,4DAAkC;AAClC,gEAAsC;AACtC,iEAAuC;AACvC,uDAA6B;AAC7B,qEAA2C;AAC3C,kEAAwC;AACxC,iEAAuC;AACvC,qEAA2C;AAC3C,6EAAmD;AACnD,6EAAmD;AACnD,iFAAuD;AACvD,oFAA0D;AAC1D,6EAAmD;AACnD,6EAAmD;AACnD,iFAAuD;AACvD,oFAA0D;AAC1D,0DAAgC;AAChC,wDAA8B;AAC9B,0DAAgC;AAChC,wEAA8C;AAC9C,gEAAsC;AACtC,sDAA4B;AAC5B,qDAA2B;AAC3B,qDAA2B"}
@@ -1,38 +1,119 @@
1
1
  export declare const statuswordBits: string[];
2
- export declare enum StatuswordState {
3
- NOT_READY_TO_SWITCH_ON = 0,
4
- SWITCH_ON_DISABLED = 1,
5
- READY_TO_SWITCH_ON = 2,
6
- SWITCHED_ON = 3,
7
- OPERATION_ENABLED = 4,
8
- QUICK_STOP_ACTIVE = 5,
9
- FAULT_REACTION_ACTIVE = 6,
10
- FAULT = 7
2
+ /**
3
+ * CIA402 refers to the CANopen application profile for drives and motion control.
4
+ * It defines various states that a CiA402-compliant device, such as a motor drive, can be in.
5
+ *
6
+ * @enum
7
+ */
8
+ export declare enum Cia402State {
9
+ /**
10
+ * Not ready to switch on (NRS).
11
+ *
12
+ * This is the initial state where the drive is not ready to be switched on.
13
+ * In this state, the drive is not powered or initialized.
14
+ */
15
+ NOT_READY_TO_SWITCH_ON = "NOT_READY_TO_SWITCH_ON",
16
+ /**
17
+ * Switch on disabled (SOD).
18
+ *
19
+ * In this state, the drive is powered and initialized but cannot be switched on.
20
+ * This state is usually used for safety purposes or when certain conditions need to be met before enabling the drive.
21
+ */
22
+ SWITCH_ON_DISABLED = "SWITCH_ON_DISABLED",
23
+ /**
24
+ * Ready to switch on (RTS).
25
+ *
26
+ * In this state, the drive is ready to be switched on.
27
+ * It has been powered and initialized, and it is waiting for the switch-on command.
28
+ */
29
+ READY_TO_SWITCH_ON = "READY_TO_SWITCH_ON",
30
+ /**
31
+ * Switched on (SWO).
32
+ *
33
+ * When the switch-on command is received, the drive enters this state.
34
+ * In this state, the drive is energized and ready to start motion.
35
+ */
36
+ SWITCHED_ON = "SWITCHED_ON",
37
+ /**
38
+ * Operation enabled (OP).
39
+ *
40
+ * This state indicates that the drive is enabled and ready to perform its intended operation.
41
+ * It can receive motion commands and execute them.
42
+ */
43
+ OPERATION_ENABLED = "OPERATION_ENABLED",
44
+ /**
45
+ * Quick stop active (QSA).
46
+ *
47
+ * This state is used to bring the drive to an immediate stop.
48
+ * It is typically triggered by an emergency stop or a quick stop command.
49
+ */
50
+ QUICK_STOP_ACTIVE = "QUICK_STOP_ACTIVE",
51
+ /**
52
+ * Fault reaction active (FRA).
53
+ *
54
+ * When a fault or error condition occurs, the drive enters this state.
55
+ * It indicates that the drive is responding to the fault by taking appropriate actions,
56
+ * such as shutting down or entering a safe state.
57
+ */
58
+ FAULT_REACTION_ACTIVE = "FAULT_REACTION_ACTIVE",
59
+ /**
60
+ * Fault (FLT).
61
+ *
62
+ * This state signifies that a fault condition has been detected and the drive is no longer operational.
63
+ * It requires manual intervention or troubleshooting to resolve the fault
64
+ * and bring the drive back to a functional state.
65
+ */
66
+ FAULT = "FAULT"
11
67
  }
12
- export declare const statuswordStateLabels: string[];
13
- export declare const statuswordStateMap: Map<number, StatuswordState>;
14
- export declare function getStatuswordState(value: number): StatuswordState | undefined;
68
+ export declare const cia402StateMap: Map<number, Cia402State>;
69
+ export declare function getCia402State(value: number): Cia402State;
15
70
  export declare function isInternalLimitActive(statusword: number): boolean;
16
71
  export declare const controlwordBits: string[];
17
- export declare enum ControlwordState {
18
- SHUTDOWN = 0,
19
- SWITCH_ON = 1,
20
- SWITCH_ON_ENABLE_OPERATION = 2,
21
- DISABLE_VOLTAGE = 3,
22
- QUICK_STOP = 4,
23
- DISABLE_OPERATION = 5,
24
- ENABLE_OPERATION = 6,
25
- FAULT = 7
72
+ /**
73
+ * In the CiA402 standard for drives and motion control, the controlword is a key component
74
+ * used to command and control the operation of a CiA402-compliant device, such as a motor drive.
75
+ * The controlword is typically a 16-bit value,
76
+ * and it consists of several bits that represent different control commands.
77
+ *
78
+ * @enum
79
+ */
80
+ export declare enum ControlwordCommand {
81
+ SHUTDOWN = "SHUTDOWN",
82
+ SWITCH_ON = "SWITCH_ON",
83
+ SWITCH_ON_ENABLE_OPERATION = "SWITCH_ON_ENABLE_OPERATION",
84
+ DISABLE_VOLTAGE = "DISABLE_VOLTAGE",
85
+ /**
86
+ * Quick Stop.
87
+ *
88
+ * This command initiates a quick stop of the drive.
89
+ * When this bit is set to 1, the drive enters the "Quick stop active" state,
90
+ * causing the motor to decelerate and come to a stop as quickly as possible.
91
+ */
92
+ QUICK_STOP = "QUICK_STOP",
93
+ DISABLE_OPERATION = "DISABLE_OPERATION",
94
+ /**
95
+ * Enable Operation.
96
+ *
97
+ * This command enables the drive to perform its intended operation.
98
+ * When this bit is set to 1, the drive transitions from the "Ready to switch on" state to the "Operation enabled" state.
99
+ */
100
+ ENABLE_OPERATION = "ENABLE_OPERATION",
101
+ /**
102
+ * Fault Reset.
103
+ *
104
+ * This command resets a fault condition and clears any fault flags or errors that may have occurred.
105
+ * When this bit is set to 1, the drive attempts to recover from a fault and return to an operational state.
106
+ */
107
+ FAULT_RESET = "FAULT_RESET"
26
108
  }
27
- export declare const controlwordStateLabels: string[];
28
109
  /**
29
- * Return one of the controlword states based its value.
110
+ * Return one of the controlword commands based its value.
30
111
  *
31
112
  * NOTE: DISABLE_OPERATION and ENABLE_OPERATION are never returned.
32
113
  * Their values are the same as SWITCH_ON and SWITCH_ON_ENABLE_OPERATION.
33
114
  * What controlword is commanded depends on the transition.
34
115
  */
35
- export declare function getControlwordState(value: number): ControlwordState | undefined;
116
+ export declare function getCommandFromControlword(value: number): ControlwordCommand | undefined;
36
117
  export declare const controlwordOptions: {
37
118
  Shutdown: number;
38
119
  'Switch on': number;
@@ -41,8 +122,37 @@ export declare const controlwordOptions: {
41
122
  'Quick stop': number;
42
123
  'Disable operation': number;
43
124
  'Enable operation': number;
44
- Fault: number;
125
+ 'Fault reset': number;
45
126
  };
127
+ export declare const controlwordCommandOptions: ControlwordCommand[];
128
+ export declare const controlwordCommandBitmasks: {
129
+ SHUTDOWN: number[];
130
+ SWITCH_ON: number[];
131
+ SWITCH_ON_ENABLE_OPERATION: number[];
132
+ DISABLE_VOLTAGE: number[];
133
+ QUICK_STOP: number[];
134
+ DISABLE_OPERATION: number[];
135
+ ENABLE_OPERATION: number[];
136
+ FAULT_RESET: number[];
137
+ };
138
+ export declare function createControlwordCommand(value: number, command: ControlwordCommand): number;
139
+ /**
140
+ * CiA402 transitions.
141
+ *
142
+ * List of allowed transitions with controlword command.
143
+ *
144
+ * The following transitions are automatic:
145
+ * - 0: START -> NOT_READY_TO_SWITCH_ON
146
+ * - 1: NOT_READY_TO_SWITCH_ON -> SWITCH_ON_DISABLED
147
+ * - 13: ANY -> FAULT_REACTION_ACTIVE
148
+ * - 14: FAULT_REACTION_ACTIVE -> FAULT
149
+ */
150
+ export declare const cia402Transitions: {
151
+ from: Cia402State;
152
+ to: Cia402State;
153
+ transitions: number[];
154
+ command: ControlwordCommand;
155
+ }[];
46
156
  export declare enum ModesOfOperation {
47
157
  OPEN_LOOP_FIELD_MODE = -3,
48
158
  DIAGNOSTICS_MODE = -2,
package/src/lib/cia402.js CHANGED
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
- ////////////////
3
- // STATUSWORD //
4
- ////////////////
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.supportedDriveModesBits = exports.modesOfOperationOptions = exports.ModesOfOperation = exports.controlwordOptions = exports.getControlwordState = exports.controlwordStateLabels = exports.ControlwordState = exports.controlwordBits = exports.isInternalLimitActive = exports.getStatuswordState = exports.statuswordStateMap = exports.statuswordStateLabels = exports.StatuswordState = exports.statuswordBits = void 0;
3
+ exports.supportedDriveModesBits = exports.modesOfOperationOptions = exports.ModesOfOperation = exports.cia402Transitions = exports.createControlwordCommand = exports.controlwordCommandBitmasks = exports.controlwordCommandOptions = exports.controlwordOptions = exports.getCommandFromControlword = exports.ControlwordCommand = exports.controlwordBits = exports.isInternalLimitActive = exports.getCia402State = exports.cia402StateMap = exports.Cia402State = exports.statuswordBits = void 0;
7
4
  exports.statuswordBits = [
8
5
  'rtso = ready to switch on',
9
6
  'so = switched on',
@@ -22,49 +19,93 @@ exports.statuswordBits = [
22
19
  'ms = manufacturer-specific',
23
20
  'ms = manufacturer-specific',
24
21
  ];
25
- var StatuswordState;
26
- (function (StatuswordState) {
27
- StatuswordState[StatuswordState["NOT_READY_TO_SWITCH_ON"] = 0] = "NOT_READY_TO_SWITCH_ON";
28
- StatuswordState[StatuswordState["SWITCH_ON_DISABLED"] = 1] = "SWITCH_ON_DISABLED";
29
- StatuswordState[StatuswordState["READY_TO_SWITCH_ON"] = 2] = "READY_TO_SWITCH_ON";
30
- StatuswordState[StatuswordState["SWITCHED_ON"] = 3] = "SWITCHED_ON";
31
- StatuswordState[StatuswordState["OPERATION_ENABLED"] = 4] = "OPERATION_ENABLED";
32
- StatuswordState[StatuswordState["QUICK_STOP_ACTIVE"] = 5] = "QUICK_STOP_ACTIVE";
33
- StatuswordState[StatuswordState["FAULT_REACTION_ACTIVE"] = 6] = "FAULT_REACTION_ACTIVE";
34
- StatuswordState[StatuswordState["FAULT"] = 7] = "FAULT";
35
- })(StatuswordState = exports.StatuswordState || (exports.StatuswordState = {}));
36
- exports.statuswordStateLabels = [
37
- 'NOT READY TO SWITCH ON',
38
- 'SWITCH ON DISABLED',
39
- 'READY TO SWITCH ON',
40
- 'SWITCHED ON',
41
- 'OPERATION ENABLED',
42
- 'QUICK STOP ACTIVE',
43
- 'FAULT REACTION ACTIVE',
44
- 'FAULT',
45
- ];
46
- exports.statuswordStateMap = new Map([
47
- [0b00000000, StatuswordState.NOT_READY_TO_SWITCH_ON],
48
- [0b01000000, StatuswordState.SWITCH_ON_DISABLED],
49
- [0b00100001, StatuswordState.READY_TO_SWITCH_ON],
50
- [0b00100011, StatuswordState.SWITCHED_ON],
51
- [0b00100111, StatuswordState.OPERATION_ENABLED],
52
- [0b00000111, StatuswordState.QUICK_STOP_ACTIVE],
53
- [0b00001111, StatuswordState.FAULT_REACTION_ACTIVE],
54
- [0b00001000, StatuswordState.FAULT],
22
+ /**
23
+ * CIA402 refers to the CANopen application profile for drives and motion control.
24
+ * It defines various states that a CiA402-compliant device, such as a motor drive, can be in.
25
+ *
26
+ * @enum
27
+ */
28
+ var Cia402State;
29
+ (function (Cia402State) {
30
+ /**
31
+ * Not ready to switch on (NRS).
32
+ *
33
+ * This is the initial state where the drive is not ready to be switched on.
34
+ * In this state, the drive is not powered or initialized.
35
+ */
36
+ Cia402State["NOT_READY_TO_SWITCH_ON"] = "NOT_READY_TO_SWITCH_ON";
37
+ /**
38
+ * Switch on disabled (SOD).
39
+ *
40
+ * In this state, the drive is powered and initialized but cannot be switched on.
41
+ * This state is usually used for safety purposes or when certain conditions need to be met before enabling the drive.
42
+ */
43
+ Cia402State["SWITCH_ON_DISABLED"] = "SWITCH_ON_DISABLED";
44
+ /**
45
+ * Ready to switch on (RTS).
46
+ *
47
+ * In this state, the drive is ready to be switched on.
48
+ * It has been powered and initialized, and it is waiting for the switch-on command.
49
+ */
50
+ Cia402State["READY_TO_SWITCH_ON"] = "READY_TO_SWITCH_ON";
51
+ /**
52
+ * Switched on (SWO).
53
+ *
54
+ * When the switch-on command is received, the drive enters this state.
55
+ * In this state, the drive is energized and ready to start motion.
56
+ */
57
+ Cia402State["SWITCHED_ON"] = "SWITCHED_ON";
58
+ /**
59
+ * Operation enabled (OP).
60
+ *
61
+ * This state indicates that the drive is enabled and ready to perform its intended operation.
62
+ * It can receive motion commands and execute them.
63
+ */
64
+ Cia402State["OPERATION_ENABLED"] = "OPERATION_ENABLED";
65
+ /**
66
+ * Quick stop active (QSA).
67
+ *
68
+ * This state is used to bring the drive to an immediate stop.
69
+ * It is typically triggered by an emergency stop or a quick stop command.
70
+ */
71
+ Cia402State["QUICK_STOP_ACTIVE"] = "QUICK_STOP_ACTIVE";
72
+ /**
73
+ * Fault reaction active (FRA).
74
+ *
75
+ * When a fault or error condition occurs, the drive enters this state.
76
+ * It indicates that the drive is responding to the fault by taking appropriate actions,
77
+ * such as shutting down or entering a safe state.
78
+ */
79
+ Cia402State["FAULT_REACTION_ACTIVE"] = "FAULT_REACTION_ACTIVE";
80
+ /**
81
+ * Fault (FLT).
82
+ *
83
+ * This state signifies that a fault condition has been detected and the drive is no longer operational.
84
+ * It requires manual intervention or troubleshooting to resolve the fault
85
+ * and bring the drive back to a functional state.
86
+ */
87
+ Cia402State["FAULT"] = "FAULT";
88
+ })(Cia402State = exports.Cia402State || (exports.Cia402State = {}));
89
+ ;
90
+ exports.cia402StateMap = new Map([
91
+ [0b00000000, Cia402State.NOT_READY_TO_SWITCH_ON],
92
+ [0b01000000, Cia402State.SWITCH_ON_DISABLED],
93
+ [0b00100001, Cia402State.READY_TO_SWITCH_ON],
94
+ [0b00100011, Cia402State.SWITCHED_ON],
95
+ [0b00100111, Cia402State.OPERATION_ENABLED],
96
+ [0b00000111, Cia402State.QUICK_STOP_ACTIVE],
97
+ [0b00001111, Cia402State.FAULT_REACTION_ACTIVE],
98
+ [0b00001000, Cia402State.FAULT],
55
99
  ]);
56
- function getStatuswordState(value) {
57
- var _a;
58
- return (_a = exports.statuswordStateMap.get(value & 0b01101111)) !== null && _a !== void 0 ? _a : exports.statuswordStateMap.get(value & 0b01001111);
100
+ function getCia402State(value) {
101
+ var _a, _b;
102
+ return (_b = ((_a = exports.cia402StateMap.get(value & 0b01101111)) !== null && _a !== void 0 ? _a : exports.cia402StateMap.get(value & 0b01001111))) !== null && _b !== void 0 ? _b : Cia402State.NOT_READY_TO_SWITCH_ON;
59
103
  }
60
- exports.getStatuswordState = getStatuswordState;
104
+ exports.getCia402State = getCia402State;
61
105
  function isInternalLimitActive(statusword) {
62
106
  return (0x800 & statusword) === 0x800;
63
107
  }
64
108
  exports.isInternalLimitActive = isInternalLimitActive;
65
- /////////////////
66
- // CONTROLWORD //
67
- /////////////////
68
109
  exports.controlwordBits = [
69
110
  'so = switch on',
70
111
  'ev = enable voltage',
@@ -83,62 +124,79 @@ exports.controlwordBits = [
83
124
  'ms = manufacturer-specific',
84
125
  'ms = manufacturer-specific',
85
126
  ];
86
- var ControlwordState;
87
- (function (ControlwordState) {
88
- ControlwordState[ControlwordState["SHUTDOWN"] = 0] = "SHUTDOWN";
89
- ControlwordState[ControlwordState["SWITCH_ON"] = 1] = "SWITCH_ON";
90
- ControlwordState[ControlwordState["SWITCH_ON_ENABLE_OPERATION"] = 2] = "SWITCH_ON_ENABLE_OPERATION";
91
- ControlwordState[ControlwordState["DISABLE_VOLTAGE"] = 3] = "DISABLE_VOLTAGE";
92
- ControlwordState[ControlwordState["QUICK_STOP"] = 4] = "QUICK_STOP";
93
- ControlwordState[ControlwordState["DISABLE_OPERATION"] = 5] = "DISABLE_OPERATION";
94
- ControlwordState[ControlwordState["ENABLE_OPERATION"] = 6] = "ENABLE_OPERATION";
95
- ControlwordState[ControlwordState["FAULT"] = 7] = "FAULT";
96
- })(ControlwordState = exports.ControlwordState || (exports.ControlwordState = {}));
97
- exports.controlwordStateLabels = [
98
- 'SHUTDOWN',
99
- 'SWITCH ON',
100
- 'SWITCH ON + ENABLE OPERATION',
101
- 'DISABLE VOLTAGE',
102
- 'QUICK STOP',
103
- 'DISABLE OPERATION',
104
- 'ENABLE OPERATION',
105
- 'FAULT',
106
- ];
107
127
  /**
108
- * Return one of the controlword states based its value.
128
+ * In the CiA402 standard for drives and motion control, the controlword is a key component
129
+ * used to command and control the operation of a CiA402-compliant device, such as a motor drive.
130
+ * The controlword is typically a 16-bit value,
131
+ * and it consists of several bits that represent different control commands.
132
+ *
133
+ * @enum
134
+ */
135
+ var ControlwordCommand;
136
+ (function (ControlwordCommand) {
137
+ ControlwordCommand["SHUTDOWN"] = "SHUTDOWN";
138
+ ControlwordCommand["SWITCH_ON"] = "SWITCH_ON";
139
+ ControlwordCommand["SWITCH_ON_ENABLE_OPERATION"] = "SWITCH_ON_ENABLE_OPERATION";
140
+ ControlwordCommand["DISABLE_VOLTAGE"] = "DISABLE_VOLTAGE";
141
+ /**
142
+ * Quick Stop.
143
+ *
144
+ * This command initiates a quick stop of the drive.
145
+ * When this bit is set to 1, the drive enters the "Quick stop active" state,
146
+ * causing the motor to decelerate and come to a stop as quickly as possible.
147
+ */
148
+ ControlwordCommand["QUICK_STOP"] = "QUICK_STOP";
149
+ ControlwordCommand["DISABLE_OPERATION"] = "DISABLE_OPERATION";
150
+ /**
151
+ * Enable Operation.
152
+ *
153
+ * This command enables the drive to perform its intended operation.
154
+ * When this bit is set to 1, the drive transitions from the "Ready to switch on" state to the "Operation enabled" state.
155
+ */
156
+ ControlwordCommand["ENABLE_OPERATION"] = "ENABLE_OPERATION";
157
+ /**
158
+ * Fault Reset.
159
+ *
160
+ * This command resets a fault condition and clears any fault flags or errors that may have occurred.
161
+ * When this bit is set to 1, the drive attempts to recover from a fault and return to an operational state.
162
+ */
163
+ ControlwordCommand["FAULT_RESET"] = "FAULT_RESET";
164
+ })(ControlwordCommand = exports.ControlwordCommand || (exports.ControlwordCommand = {}));
165
+ /**
166
+ * Return one of the controlword commands based its value.
109
167
  *
110
168
  * NOTE: DISABLE_OPERATION and ENABLE_OPERATION are never returned.
111
169
  * Their values are the same as SWITCH_ON and SWITCH_ON_ENABLE_OPERATION.
112
170
  * What controlword is commanded depends on the transition.
113
171
  */
114
- function getControlwordState(value) {
172
+ function getCommandFromControlword(value) {
115
173
  if ((value & 0b1000111) === 0b0000110) {
116
- return ControlwordState.SHUTDOWN;
174
+ return ControlwordCommand.SHUTDOWN;
117
175
  }
118
176
  if ((value & 0b1001111) === 0b0000111) {
119
- return ControlwordState.SWITCH_ON;
177
+ return ControlwordCommand.SWITCH_ON;
120
178
  }
121
179
  if ((value & 0b1001111) === 0b0001111) {
122
- return ControlwordState.SWITCH_ON_ENABLE_OPERATION;
180
+ return ControlwordCommand.SWITCH_ON_ENABLE_OPERATION;
123
181
  }
124
182
  if ((value & 0b1000010) === 0b0000000) {
125
- return ControlwordState.DISABLE_VOLTAGE;
183
+ return ControlwordCommand.DISABLE_VOLTAGE;
126
184
  }
127
185
  if ((value & 0b1000110) === 0b0000010) {
128
- return ControlwordState.QUICK_STOP;
186
+ return ControlwordCommand.QUICK_STOP;
129
187
  }
130
188
  if ((value & 0b1001111) === 0b0000111) {
131
- return ControlwordState.DISABLE_OPERATION;
189
+ return ControlwordCommand.DISABLE_OPERATION;
132
190
  }
133
191
  if ((value & 0b1001111) === 0b0001111) {
134
- return ControlwordState.ENABLE_OPERATION;
192
+ return ControlwordCommand.ENABLE_OPERATION;
135
193
  }
136
194
  if ((value & 0b1000000) === 0b1000000) {
137
- return ControlwordState.FAULT;
195
+ return ControlwordCommand.FAULT_RESET;
138
196
  }
139
197
  return;
140
198
  }
141
- exports.getControlwordState = getControlwordState;
199
+ exports.getCommandFromControlword = getCommandFromControlword;
142
200
  exports.controlwordOptions = {
143
201
  'Shutdown': 0b00000110,
144
202
  'Switch on': 0b00000111,
@@ -147,11 +205,145 @@ exports.controlwordOptions = {
147
205
  'Quick stop': 0b00000010,
148
206
  'Disable operation': 0b00000111,
149
207
  'Enable operation': 0b00001111,
150
- 'Fault': 0b10000000, // fault reset 15
208
+ 'Fault reset': 0b10000000, // fault reset 15
151
209
  };
152
- ////////////////////////
153
- // MODES OF OPERATION //
154
- ////////////////////////
210
+ exports.controlwordCommandOptions = Object.values(ControlwordCommand);
211
+ exports.controlwordCommandBitmasks = {
212
+ [ControlwordCommand.SHUTDOWN]: [
213
+ 0b1111111101111110,
214
+ 0b0000000000000110,
215
+ ],
216
+ [ControlwordCommand.SWITCH_ON]: [
217
+ 0b1111111101110111,
218
+ 0b0000000000000111,
219
+ ],
220
+ [ControlwordCommand.SWITCH_ON_ENABLE_OPERATION]: [
221
+ 0b1111111101111111,
222
+ 0b0000000000001111,
223
+ ],
224
+ [ControlwordCommand.DISABLE_VOLTAGE]: [
225
+ 0b1111111101111101,
226
+ 0b0000000000000000,
227
+ ],
228
+ [ControlwordCommand.QUICK_STOP]: [
229
+ 0b1111111101111011,
230
+ 0b0000000000000010,
231
+ ],
232
+ [ControlwordCommand.DISABLE_OPERATION]: [
233
+ 0b1111111101110111,
234
+ 0b0000000000000111,
235
+ ],
236
+ [ControlwordCommand.ENABLE_OPERATION]: [
237
+ 0b1111111101111111,
238
+ 0b0000000000001111,
239
+ ],
240
+ [ControlwordCommand.FAULT_RESET]: [
241
+ 0b1111111111111111,
242
+ 0b0000000010000000,
243
+ ],
244
+ };
245
+ function createControlwordCommand(value, command) {
246
+ const bitmasks = exports.controlwordCommandBitmasks[command];
247
+ return ((value & bitmasks[0]) | bitmasks[1]);
248
+ }
249
+ exports.createControlwordCommand = createControlwordCommand;
250
+ /**
251
+ * CiA402 transitions.
252
+ *
253
+ * List of allowed transitions with controlword command.
254
+ *
255
+ * The following transitions are automatic:
256
+ * - 0: START -> NOT_READY_TO_SWITCH_ON
257
+ * - 1: NOT_READY_TO_SWITCH_ON -> SWITCH_ON_DISABLED
258
+ * - 13: ANY -> FAULT_REACTION_ACTIVE
259
+ * - 14: FAULT_REACTION_ACTIVE -> FAULT
260
+ */
261
+ exports.cia402Transitions = [
262
+ {
263
+ from: Cia402State.SWITCH_ON_DISABLED,
264
+ to: Cia402State.READY_TO_SWITCH_ON,
265
+ transitions: [2],
266
+ command: ControlwordCommand.SHUTDOWN,
267
+ },
268
+ {
269
+ from: Cia402State.READY_TO_SWITCH_ON,
270
+ to: Cia402State.SWITCHED_ON,
271
+ transitions: [3],
272
+ command: ControlwordCommand.SWITCH_ON,
273
+ },
274
+ {
275
+ from: Cia402State.READY_TO_SWITCH_ON,
276
+ to: Cia402State.OPERATION_ENABLED,
277
+ transitions: [3, 4],
278
+ command: ControlwordCommand.SWITCH_ON_ENABLE_OPERATION,
279
+ },
280
+ {
281
+ from: Cia402State.SWITCHED_ON,
282
+ to: Cia402State.OPERATION_ENABLED,
283
+ transitions: [4],
284
+ command: ControlwordCommand.ENABLE_OPERATION,
285
+ },
286
+ {
287
+ from: Cia402State.OPERATION_ENABLED,
288
+ to: Cia402State.SWITCHED_ON,
289
+ transitions: [5],
290
+ command: ControlwordCommand.DISABLE_OPERATION,
291
+ },
292
+ {
293
+ from: Cia402State.SWITCHED_ON,
294
+ to: Cia402State.READY_TO_SWITCH_ON,
295
+ transitions: [6],
296
+ command: ControlwordCommand.SHUTDOWN,
297
+ },
298
+ {
299
+ from: Cia402State.READY_TO_SWITCH_ON,
300
+ to: Cia402State.SWITCH_ON_DISABLED,
301
+ transitions: [7],
302
+ command: ControlwordCommand.DISABLE_VOLTAGE,
303
+ },
304
+ {
305
+ from: Cia402State.OPERATION_ENABLED,
306
+ to: Cia402State.READY_TO_SWITCH_ON,
307
+ transitions: [8],
308
+ command: ControlwordCommand.SHUTDOWN,
309
+ },
310
+ {
311
+ from: Cia402State.OPERATION_ENABLED,
312
+ to: Cia402State.SWITCH_ON_DISABLED,
313
+ transitions: [9],
314
+ command: ControlwordCommand.DISABLE_VOLTAGE,
315
+ },
316
+ {
317
+ from: Cia402State.SWITCHED_ON,
318
+ to: Cia402State.SWITCH_ON_DISABLED,
319
+ transitions: [10],
320
+ command: ControlwordCommand.DISABLE_VOLTAGE,
321
+ },
322
+ {
323
+ from: Cia402State.OPERATION_ENABLED,
324
+ to: Cia402State.QUICK_STOP_ACTIVE,
325
+ transitions: [11],
326
+ command: ControlwordCommand.QUICK_STOP,
327
+ },
328
+ {
329
+ from: Cia402State.QUICK_STOP_ACTIVE,
330
+ to: Cia402State.SWITCH_ON_DISABLED,
331
+ transitions: [12],
332
+ command: ControlwordCommand.DISABLE_VOLTAGE,
333
+ },
334
+ {
335
+ from: Cia402State.FAULT,
336
+ to: Cia402State.SWITCH_ON_DISABLED,
337
+ transitions: [15],
338
+ command: ControlwordCommand.FAULT_RESET,
339
+ },
340
+ {
341
+ from: Cia402State.QUICK_STOP_ACTIVE,
342
+ to: Cia402State.OPERATION_ENABLED,
343
+ transitions: [16],
344
+ command: ControlwordCommand.ENABLE_OPERATION,
345
+ },
346
+ ];
155
347
  var ModesOfOperation;
156
348
  (function (ModesOfOperation) {
157
349
  ModesOfOperation[ModesOfOperation["OPEN_LOOP_FIELD_MODE"] = -3] = "OPEN_LOOP_FIELD_MODE";