motion-master-client 0.0.246 → 0.0.248

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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Types defined here represent a JSON file structure of the SMM (Safety Motion Module) object dictionary.
3
+ */
4
+ type SmmOdParameter = {
5
+ parameterName: string;
6
+ variableName: string | null;
7
+ group: string | null;
8
+ index: number;
9
+ subindex: number;
10
+ description: string;
11
+ type: string;
12
+ typeRef?: string | null;
13
+ size: number;
14
+ unit: string | null;
15
+ min: number | null;
16
+ max: number | null;
17
+ defaultValue: number | string | null;
18
+ access: 'rw' | 'ro' | null;
19
+ };
20
+ type SmmOdEnumValue = {
21
+ identifier?: string;
22
+ value: number;
23
+ label: string;
24
+ axis?: number | null;
25
+ };
26
+ type SmmOdEnumType = {
27
+ type: string;
28
+ enum: SmmOdEnumValue[];
29
+ };
30
+ type SmmOdParameterCategory = 'safety' | 'manufacturer' | 'constants' | 'globalVariables';
31
+ type SmmOdParameters = {
32
+ [category in SmmOdParameterCategory]: SmmOdParameter[];
33
+ };
34
+ type SmmOdTypes = {
35
+ [key: string]: SmmOdEnumType;
36
+ };
37
+ export type SmmOd = {
38
+ parameters: SmmOdParameters;
39
+ types: SmmOdTypes;
40
+ };
41
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Types defined here represent a JSON file structure of the SMM (Safety Motion Module) object dictionary.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=smm-od.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smm-od.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/smm-od.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/src/lib/smm.d.ts CHANGED
@@ -1,62 +1,214 @@
1
1
  /// <reference types="node" />
2
2
  import PythonStruct, { DataType } from 'python-struct';
3
3
  import { Buffer } from 'buffer';
4
- export declare const smmGroupBitMasks: number[][];
4
+ /**
5
+ * Builds a bitmask for the safety parameters of a given group in the SMM parameter set.
6
+ *
7
+ * The bitmask is an array of bytes where each bit represents whether a specific safety
8
+ * parameter belongs to the specified group. The group index determines which group's
9
+ * parameters are marked as `1` in the bitmask, and others are marked as `0`.
10
+ *
11
+ * @param groupIndex - The index of the group for which to build the bitmask. The index corresponds
12
+ * to the position of the group in the safety parameters.
13
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
14
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
15
+ * otherwise, the `smmOdV2` format is used.
16
+ *
17
+ * @returns A `Uint8Array` representing the bitmask for the specified group. Each byte contains 8 bits,
18
+ * where each bit corresponds to a safety parameter.
19
+ *
20
+ * @throws If the `groupIndex` is out of range or if the parameter structure is not valid for the given version.
21
+ */
22
+ export declare function buildSmmParametersGroupBitmask(groupIndex: number, parameterStructVersion?: number): Uint8Array;
23
+ /**
24
+ * Builds the structure format strings for each group of parameters based on the given struct version.
25
+ *
26
+ * This function maps parameters in the `smmOd` object to their respective safety groups, processes
27
+ * them, and converts their types to structure format characters (e.g., `<` for little-endian).
28
+ * The function supports different versions of the parameter struct format, defaulting to version `0x0041`.
29
+ *
30
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
31
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
32
+ * otherwise, the `smmOdV2` format is used.
33
+ *
34
+ * @returns An array of structure format strings for each group of parameters.
35
+ */
36
+ export declare function buildSmmParametersGroupPackFormats(parameterStructVersion?: number): string[];
37
+ /**
38
+ * Builds the structure format string for all parameters based on the given struct version.
39
+ *
40
+ * This function processes the parameters in the `smmOd` object, converting each parameter's type
41
+ * to its corresponding structure format character (e.g., `<` for little-endian). It supports different
42
+ * versions of the parameter struct format, defaulting to version `0x0041`.
43
+ *
44
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
45
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
46
+ * otherwise, the `smmOdV2` format is used.
47
+ *
48
+ * @returns A structure format string representing all the parameters, starting with a `<` (little-endian).
49
+ */
50
+ export declare function buildSmmParametersPackFormat(parameterStructVersion?: number): string;
51
+ /**
52
+ * Calculates a CRC-32 checksum using a custom SMM-specific polynomial lookup table.
53
+ *
54
+ * This CRC implementation is tailored for Safety Motion Module (SMM) data validation,
55
+ * ensuring data integrity across packed buffers. It supports an initial CRC seed,
56
+ * allowing for chained calculations or non-standard CRC resets.
57
+ *
58
+ * @param buffer - The input data buffer (`Uint8Array`) for which to calculate the CRC.
59
+ * @param initial - The initial CRC value, typically `0xFFFFFFFF` for standard calculations.
60
+ *
61
+ * @returns The computed CRC-32 checksum as a 32-bit unsigned integer.
62
+ */
5
63
  export declare function calcSmmCRC32(buffer: Uint8Array, initial: number): number;
6
- export declare const smmGroupPackFormats: string[];
7
- export declare function calcSmmBitmask(values: DataType[], group: SmmVerificationGroupOrdinal): {
64
+ /**
65
+ * Packs SMM (Safety Motion Module) credentials (username and password) into a fixed-size binary format.
66
+ * Each field is padded or truncated to 24 bytes.
67
+ *
68
+ * @param username - The username to be packed. It will be padded or truncated to 24 bytes.
69
+ * @param password - The password to be packed. It will also be padded or truncated to 24 bytes.
70
+ *
71
+ * @returns A `Buffer` containing the packed username and password.
72
+ *
73
+ * @throws Error if the username or password contains invalid characters or types.
74
+ */
75
+ export declare function packSmmCredentials(username: string, password: string): Buffer;
76
+ /**
77
+ * Packs the new and old passwords into a fixed-size binary format for SMM (Safety Motion Module) password change operations.
78
+ * Each password is padded or truncated to 24 bytes.
79
+ *
80
+ * @param newPassword - The new password to be packed. It will be padded or truncated to 24 bytes.
81
+ * @param oldPassword - The current/old password to be packed. It will be padded or truncated to 24 bytes.
82
+ *
83
+ * @returns A `Buffer` containing the packed new and old passwords.
84
+ *
85
+ * @throws Error if either password contains invalid characters or types.
86
+ */
87
+ export declare function packSmmChangePassword(newPassword: string, oldPassword: string): Buffer;
88
+ /**
89
+ * Packs SMM (Safety Motion Module) parameter values into a binary buffer,
90
+ * following the specified SMM parameter structure version.
91
+ * It computes and appends a CRC32 checksum to ensure data integrity.
92
+ *
93
+ * @param values - An array of `DataType` values to be packed.
94
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
95
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
96
+ * otherwise, the `smmOdV2` format is used.
97
+ *
98
+ * @returns An object containing:
99
+ * - `buffer`: A `Buffer` with the packed values followed by the CRC32 checksum.
100
+ * - `crc`: The computed CRC32 checksum for the packed data.
101
+ * - `crcBuffer`: A `Buffer` representing the packed CRC32 checksum.
102
+ * - `values`: The original `DataType[]` values.
103
+ * - `valuesBuffer`: A `Buffer` containing the packed values (without the CRC).
104
+ *
105
+ * @throws Error if packing fails due to an invalid structure or value mismatch.
106
+ */
107
+ export declare function packSmmParameterValues(values: DataType[], parameterStructVersion?: number): {
108
+ buffer: Buffer;
109
+ crc: number;
110
+ crcBuffer: Buffer;
111
+ values: PythonStruct.DataType[];
112
+ valuesBuffer: Buffer;
113
+ };
114
+ /**
115
+ * Unpacks SMM (Safety Motion Module) parameter values from a `Uint8Array` buffer
116
+ * according to the specified parameter structure version.
117
+ *
118
+ * This function decodes the packed buffer back into its original data values,
119
+ * using the structure format defined for the given SMM parameter structure version.
120
+ *
121
+ * @param values - A `Uint8Array` representing the packed parameter values.
122
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
123
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
124
+ * otherwise, the `smmOdV2` format is used.
125
+ *
126
+ * @returns An array of unpacked values, decoded according to the structure format.
127
+ *
128
+ * @throws Error if the unpacking fails or the data format is incorrect.
129
+ */
130
+ export declare function unpackSmmParameterValues(values: Uint8Array, parameterStructVersion?: number): PythonStruct.DataType[];
131
+ /**
132
+ * Packs SMM (Safety Motion Module) parameter values into a buffer for verification,
133
+ * including a bitmask and CRC32 checksum to ensure data integrity.
134
+ *
135
+ * This function prepares data specifically for verification purposes, combining
136
+ * parameter values, a group-specific bitmask, and a CRC32 checksum.
137
+ *
138
+ * @param values - An array of `DataType` representing the parameter values to be packed.
139
+ * @param groupIndex - The index of the parameter group, determining the bitmask and packing format.
140
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
141
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
142
+ * otherwise, the `smmOdV2` format is used.
143
+ *
144
+ * @returns An object containing:
145
+ * - `buffer`: A `Uint8Array` combining the bitmask and CRC32 checksum for verification.
146
+ * - `crc`: The CRC32 checksum calculated from the packed data and bitmask.
147
+ *
148
+ * @throws Error if the groupIndex is invalid or packing fails.
149
+ */
150
+ export declare function packSmmParameterValuesForVerification(values: DataType[], groupIndex: number, parameterStructVersion?: number): {
8
151
  buffer: Uint8Array;
9
152
  crc: number;
10
153
  };
154
+ /**
155
+ * Packs a `Date` object into a binary buffer in a specific format for the SMM (Safety Motion Module).
156
+ * The date is serialized into the following fields: year (2 bytes), month (1 byte), day (1 byte),
157
+ * hours (1 byte), minutes (1 byte), seconds (1 byte), and a trailing byte (set to 0).
158
+ * The packed data can be used for storing or transmitting the date in a structured format compatible with SMM.
159
+ *
160
+ * @param date - The `Date` object to be packed. It is expected to be in UTC time.
161
+ *
162
+ * @returns A `Buffer` containing the packed date.
163
+ */
11
164
  export declare function packSmmDate(date: Date): Buffer;
165
+ /**
166
+ * Packs a validation report for the SMM (Safety Motion Module), including a CRC, date, and credentials.
167
+ * The function takes a content `Uint8Array`, a `Date`, a `username`, and a `password`, and returns an object
168
+ * containing the packed report, the CRC, and the credentials used for packing.
169
+ *
170
+ * The packed report includes the following components:
171
+ * - CRC32 checksum of the content.
172
+ * - The date packed into a specific format.
173
+ * - The credentials (username and password) packed into a specific format.
174
+ *
175
+ * @param content - The content of the validation report, as a `Uint8Array`.
176
+ * @param date - The date of the report to be packed into the format used by SMM.
177
+ * @param username - The username associated with the report.
178
+ * @param password - The password associated with the report.
179
+ *
180
+ * @returns An object containing:
181
+ * - `buffer`: A `Uint8Array` that includes the packed CRC, date, and credentials.
182
+ * - `crc`: The CRC32 checksum of the `content`.
183
+ * - `credentials`: The packed username and password.
184
+ */
12
185
  export declare function packSmmValidationReport(content: Uint8Array, date: Date, username: string, password: string): {
13
186
  buffer: Uint8Array;
14
187
  crc: number;
15
188
  credentials: Buffer;
16
189
  };
17
- export declare const smmPackFormat = "<H24sBHBBBBBHB2BihihIBIBBHBBIBBBIHHHhHBBHBBHiIBBHBHHiiBHHHiI4B4H4H4H4i4i4IiiI";
18
- export declare function packSmmParameterValues(values: DataType[], format?: string): {
19
- buffer: Buffer;
20
- crc: number;
21
- crcBuffer: Buffer;
22
- values: PythonStruct.DataType[];
23
- valuesBuffer: Buffer;
24
- };
25
- export declare function packSmmCredentials(username: string, password: string): Buffer;
26
- export declare function packSmmChangePassword(newPassword: string, oldPassword: string): Buffer;
190
+ /**
191
+ * Packs a CRC (Cyclic Redundancy Check) value into a 4-byte little-endian binary format.
192
+ * This is typically used for verifying software updates in the SMM (Safety Motion Module).
193
+ *
194
+ * @param crc - The CRC value to be packed, represented as a 32-bit unsigned integer.
195
+ *
196
+ * @returns A `Buffer` containing the packed CRC value in little-endian format.
197
+ *
198
+ * @throws Error if the provided CRC is not a valid number.
199
+ */
27
200
  export declare function packSmmSoftwareUpdateCrc(crc: number): Buffer;
28
- export declare function unpackSmmParameterValues(values: Uint8Array, format?: string): PythonStruct.DataType[];
29
- export declare enum SmmVerificationGroupOrdinal {
30
- GENERAL = 1,
31
- SAFETY_IO = 2,
32
- ANALOG_IN = 3,
33
- ENCODER_1 = 4,
34
- ENCODER_2 = 5,
35
- STO_SBC = 6,
36
- SOS = 7,
37
- SS1 = 8,
38
- SS2 = 9,
39
- SLS1 = 10,
40
- SLS2 = 11,
41
- SLS3 = 12,
42
- SLS4 = 13,
43
- SMS = 14
44
- }
45
- export declare const smmVerificationGroupNameToOrdinal: {
46
- 'General Parameters (General Parameters)': SmmVerificationGroupOrdinal;
47
- 'Safety IO (Digital I/O)': SmmVerificationGroupOrdinal;
48
- 'Safety IO (Analog Input)': SmmVerificationGroupOrdinal;
49
- 'Encoder selection (Encoders)': SmmVerificationGroupOrdinal;
50
- 'Encoder selection (Speed / position)': SmmVerificationGroupOrdinal;
51
- 'Safety functions (STO + SBC)': SmmVerificationGroupOrdinal;
52
- 'Safety functions (SOS)': SmmVerificationGroupOrdinal;
53
- 'Safety functions (SS1)': SmmVerificationGroupOrdinal;
54
- 'Safety functions (SS2)': SmmVerificationGroupOrdinal;
55
- 'Safety functions (SLS1)': SmmVerificationGroupOrdinal;
56
- 'Safety functions (SLS2)': SmmVerificationGroupOrdinal;
57
- 'Safety functions (SLS3)': SmmVerificationGroupOrdinal;
58
- 'Safety functions (SLS4)': SmmVerificationGroupOrdinal;
59
- 'Safety functions (SMS)': SmmVerificationGroupOrdinal;
60
- };
61
- export declare const smmVerificationGroupNames: string[];
62
- export type SmmVerificationGroupName = keyof typeof smmVerificationGroupNameToOrdinal;
201
+ /**
202
+ * Retrieves the names of all safety parameter groups from the specified parameter structure version.
203
+ *
204
+ * The function returns a list of unique group names based on the version of the parameter structure.
205
+ * It will select `smmOdV1` if the version is lower than `0x0203`, and `smmOdV2` otherwise.
206
+ *
207
+ * @param parameterStructVersion - The version of the parameter struct to use. Defaults to `0x0041`.
208
+ * If the version is less than `0x0203`, the `smmOdV1` format is used;
209
+ * otherwise, the `smmOdV2` format is used.
210
+ *
211
+ * @returns An array of strings representing the group names in the safety parameters.
212
+ */
213
+ export declare function getSmmParametersGroupNames(parameterStructVersion?: number): string[];
214
+ export declare const smmOdV1DefaultValues: any[];