@kuriousdesign/machine-sdk 1.0.6 → 1.0.7

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/README.md CHANGED
@@ -1,7 +1,17 @@
1
- @kuriousdesign/machine-sdk
1
+ # npm install @kuriousdesign/machine-sdk
2
2
  A shared SDK for data types and helper functions used in machine-related repositories.
3
- Installation
4
- npm install @kuriousdesign/machine-sdk
3
+
4
+ # Publishing to npm
5
+ first, commit you git changes
6
+ npm login (if not already)
7
+ npm version patch # 1.0.0 → 1.0.1
8
+ npm version minor # 1.0.0 → 1.1.0
9
+ npm version major # 1.0.0 → 2.0.0
10
+ npm publish
11
+
12
+
13
+ # Installation
14
+ npm install @kuriousdesign/machine-sdk@latest
5
15
 
6
16
  Usage
7
17
  import { Machine, formatTimestamp, isMachineActive } from '@kuriousdesign/machine-sdk';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kuriousdesign/machine-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Shared data types and helpers for machine-related repositories",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,9 @@
1
+ export enum BridgeCmds {
2
+ NONE = 1,
3
+ CONNECT = 2,
4
+ DISCONNECT = 3
5
+ }
6
+
7
+ export interface BridgeData {
8
+ connectedClients: number[];
9
+ }
@@ -1,12 +1,61 @@
1
1
  import { DeviceTypes } from './DeviceTypes'
2
2
 
3
+ export const DeviceConstants = {
4
+ DEVICE_CHILDREN_ARRAY_LEN: 10,
5
+ DEVICE_FAULTCODEARRAY_LEN: 10, //this value should be greater than equal to children array len
6
+ MAX_NUM_PARAMS: 10, //used for tasks and processes
7
+ NUM_ACTION_TYPES: 6, //this includes NONE
8
+ NUM_LOG_ENTRIES: 50,
9
+ MAX_NUM_OUTBOUND_AXIS_INTERLOCKS: 10,
10
+ UNIT_TEST_PROCESS_ID: 1100,
11
+ TIME_MS_AUTOCLEAR_DONE_BIT_TASK_OR_PROCESS: 250
12
+ };
13
+
14
+ export interface DebugLogData {
15
+ Msg: string;
16
+ TimeStamp: Date;
17
+ Id: number;
18
+ }
19
+
20
+ export const initialDebugLogData: DebugLogData = {
21
+ Msg: '',
22
+ TimeStamp: new Date(),
23
+ Id: 0
24
+ };
25
+
26
+
27
+ export interface DeviceLogData {
28
+ List: DebugLogData[];
29
+ LastIndex: number; // index of the most recent recorded entries
30
+ }
31
+
32
+ export const initialDeviceLogData: DeviceLogData = {
33
+ List: new Array(DeviceConstants.NUM_LOG_ENTRIES).fill(null),
34
+ LastIndex: 0
35
+ };
36
+
37
+
3
38
  export interface DeviceRegistration {
4
39
  mnemonic: string; // short hand notation for the device, e.g. IB for Bufferwall, IBG for gantry
5
40
  id: number; // this device id
6
41
  childIdArray: number[]; // array of child device ids
7
42
  parentId: number; // this is the parent id
8
43
  deviceType: DeviceTypes; // type of the device
9
- }
44
+ };
45
+
46
+ export interface DeviceActionRequestData {
47
+ SenderId: number;
48
+ ActionType: number; // ActionTypes enum
49
+ ActionId: number; // could be cmd, task or processId
50
+ ParamArray: number[]; // Array of LREAL values
51
+ };
52
+
53
+ export const initialDeviceActionRequestData: DeviceActionRequestData = {
54
+ SenderId: 0,
55
+ ActionType: 0,
56
+ ActionId: 0,
57
+ ParamArray: new Array(DeviceConstants.MAX_NUM_PARAMS).fill(0)
58
+ };
10
59
 
11
60
  export const initialDeviceRegistration: DeviceRegistration = {
12
61
  mnemonic: '',
@@ -136,6 +185,16 @@ export const initialDeviceStatus: DeviceStatus = {
136
185
  recordingLogs: false
137
186
  };
138
187
 
188
+ export enum ActionTypes {
189
+ MISSION = 0,
190
+ CMD = 1,
191
+ TASK = 2,
192
+ PROCESS = 3,
193
+ EXEC_METHOD = 4,
194
+ SCRIPT = 5,
195
+ COUNT = 6 // Update this value to match the number of action types
196
+ }
197
+
139
198
  export interface Device {
140
199
  is: DeviceStatus;
141
200
  errors: DeviceFaultData;
@@ -3,5 +3,8 @@ export enum DeviceTypes {
3
3
  Axis = 1,
4
4
  BoschAxis = 2, //need to deprecate this soon
5
5
  DualAxis = 3,
6
- Gantry = 4
6
+ Gantry = 4,
7
+ Bridge = 5, //used for communication
8
+ Machine = 6,
9
+ Robot = 7,
7
10
  }
@@ -11,3 +11,4 @@ export * from "./UserManagerFB";
11
11
  export * from "./TaskQueue";
12
12
  export * from "./RobData";
13
13
  export * from "./Devices";
14
+ export * from "./Bridge";
@@ -7,20 +7,133 @@ export enum VisibilityState {
7
7
  StrobingFast = 5,
8
8
  StrobingSlow = 6,
9
9
  GrowingSlow = 7,
10
+ };
11
+
12
+ export enum States {
13
+ ABORTING = -3,
14
+ ERROR = -2,
15
+ KILLED = -1,
16
+ INACTIVE = 0,
17
+ RESETTING = 50,
18
+ IDLE = 100,
19
+ RUNNING = 500,
20
+ STOPPING = 900,
21
+ PAUSED = 999,
22
+ DONE = 1000,
23
+ MANUAL = 1100,
24
+ UNKNOWN = 9999,
25
+ };
26
+
27
+ export function convertStateToString(state: States) {
28
+ switch (state) {
29
+ case States.ABORTING:
30
+ return "ABORTING";
31
+ case States.ERROR:
32
+ return "ERROR";
33
+ case States.KILLED:
34
+ return "KILLED";
35
+ case States.INACTIVE:
36
+ return "INACTIVE";
37
+ case States.RESETTING:
38
+ return "RESETTING";
39
+ case States.IDLE:
40
+ return "IDLE";
41
+ case States.RUNNING:
42
+ return "RUNNING";
43
+ case States.STOPPING:
44
+ return "STOPPING";
45
+ case States.PAUSED:
46
+ return "PAUSED";
47
+ case States.DONE:
48
+ return "DONE";
49
+ case States.MANUAL:
50
+ return "MANUAL";
51
+ case States.UNKNOWN:
52
+ return "UNKNOWN";
53
+ default:
54
+ return "UNKNOWN";
55
+ }
56
+ }
57
+
58
+ export function convertStateToColor(state: States) {
59
+
60
+ switch (state) {
61
+ case States.ABORTING:
62
+ return "text-darkred-500";
63
+ case States.ERROR:
64
+ return "text-red-500";
65
+ case States.KILLED:
66
+ return "text-gray-500";
67
+ case States.INACTIVE:
68
+ return "text-white";
69
+ case States.RESETTING:
70
+ return "text-lightblue-500";
71
+ case States.IDLE:
72
+ return "text-blue-500";
73
+ case States.RUNNING:
74
+ return "text-green-500";
75
+ case States.STOPPING:
76
+ return "text-orange-500";
77
+ case States.MANUAL:
78
+ return "text-purple-500";
79
+ case States.UNKNOWN:
80
+ return "text-pink-500";
81
+ }
10
82
  }
11
83
 
12
- export enum DeviceState {
13
- Faulted = -2,
14
- Killed = -1,
15
- Inactive = 0,
16
- Resetting = 50,
17
- Idle = 100,
18
- Running = 500,
19
- Stopping = 900,
20
- Aborting = 911,
21
- Paused = 999,
22
- Done = 1000,
23
- Manual = 2000,
84
+ export function getStateFromStep(step:number): States {
85
+ let state = States.UNKNOWN;
86
+ switch (step) {
87
+ case States.ABORTING:
88
+ state = States.ABORTING;
89
+ break;
90
+ case States.ERROR:
91
+ state = States.ERROR;
92
+ break;
93
+ case States.KILLED:
94
+ state = States.KILLED;
95
+ break;
96
+ case States.INACTIVE:
97
+ state = States.INACTIVE;
98
+ break;
99
+ case States.RESETTING:
100
+ state = States.RESETTING;
101
+ break;
102
+ case States.IDLE:
103
+ state = States.IDLE;
104
+ break;
105
+ case States.RUNNING:
106
+ state = States.RUNNING;
107
+ break;
108
+ case States.STOPPING:
109
+ state = States.STOPPING;
110
+ break;
111
+ case States.PAUSED:
112
+ state = States.PAUSED;
113
+ break;
114
+ case States.DONE:
115
+ state = States.DONE;
116
+ break;
117
+ case States.MANUAL:
118
+ state = States.MANUAL;
119
+ break;
120
+ case States.UNKNOWN:
121
+ state = States.UNKNOWN;
122
+ break;
123
+ }
124
+
125
+ if(state === States.UNKNOWN){
126
+ if (state >= States.RESETTING && state < States.IDLE) {
127
+ state = States.RESETTING;
128
+ } else if (state > States.IDLE && state < States.STOPPING) {
129
+ state = States.RUNNING;
130
+ } else if (state >= States.STOPPING && state < States.PAUSED) {
131
+ state = States.STOPPING;
132
+ } else if (state >= States.MANUAL && state < States.UNKNOWN) {
133
+ state = States.MANUAL;
134
+ }
135
+ }
136
+ return state;
24
137
  }
25
138
 
26
139
  export enum PartState {
@@ -7,10 +7,4 @@ export const MqttTopics = {
7
7
  BRIDGE_STATUS: 'bridge/status',
8
8
  BRIDGE_CMD: 'bridge/cmd',
9
9
  DEVICE_MAP: 'deviceMap',
10
- } as const;
11
-
12
-
13
- export const BridgeCmds = {
14
- CONNECT: 'connect',
15
- DISCONNECT: 'disconnect'
16
10
  } as const;