motion-master-client 0.0.356 → 0.0.358
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 +1 -1
- package/src/api.js +21 -2
- package/src/api.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/config-file.js +6 -5
- package/src/lib/config-file.js.map +1 -1
- package/src/lib/motion-master-req-res-client.d.ts +27 -9
- package/src/lib/motion-master-req-res-client.js +90 -37
- package/src/lib/motion-master-req-res-client.js.map +1 -1
- package/src/lib/pdo.d.ts +61 -0
- package/src/lib/pdo.js +60 -0
- package/src/lib/pdo.js.map +1 -0
package/src/lib/pdo.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a string is a valid representation of a CANopen PDO mapping entry.
|
|
3
|
+
*
|
|
4
|
+
* A valid entry is a 32-bit hexadecimal value representing:
|
|
5
|
+
* - **Index** (16 bits)
|
|
6
|
+
* - **Subindex** (8 bits)
|
|
7
|
+
* - **Bit Length** (8 bits)
|
|
8
|
+
*
|
|
9
|
+
* It accepts formats with or without the '0x' prefix (e.g., "0x60400010" or "60400010").
|
|
10
|
+
*
|
|
11
|
+
* @param value The string to validate.
|
|
12
|
+
* @returns `true` if the string follows the PDO mapping entry hex format, `false` otherwise.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* isPdoMappingEntry('0x60400010'); // true
|
|
16
|
+
* isPdoMappingEntry('60400010'); // true
|
|
17
|
+
* isPdoMappingEntry('invalid'); // false
|
|
18
|
+
*/
|
|
19
|
+
export declare function isPdoMappingEntry(value: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Represents the components of a single CANopen PDO Mapping Entry.
|
|
22
|
+
*
|
|
23
|
+
* A PDO Mapping Entry is a 32-bit value describing which object dictionary parameter
|
|
24
|
+
* maps to a specific location in a PDO message.
|
|
25
|
+
*
|
|
26
|
+
* The 32-bit structure is defined as:
|
|
27
|
+
* - **Index (16-bit):** The object dictionary index (e.g., `0x6040`).
|
|
28
|
+
* - **Subindex (8-bit):** The specific sub-element of the object (e.g., `0x00`).
|
|
29
|
+
* - **Bit Length (8-bit):** The size of the data in bits (e.g., `16`).
|
|
30
|
+
*/
|
|
31
|
+
export interface PdoMappingEntry {
|
|
32
|
+
/**
|
|
33
|
+
* The Object Dictionary Index (16-bit unsigned integer).
|
|
34
|
+
*
|
|
35
|
+
* @example 0x6040 (Controlword)
|
|
36
|
+
*/
|
|
37
|
+
index: number;
|
|
38
|
+
/**
|
|
39
|
+
* The Object Dictionary Subindex (8-bit unsigned integer).
|
|
40
|
+
*
|
|
41
|
+
* @example 0x00 (Main value)
|
|
42
|
+
*/
|
|
43
|
+
subindex: number;
|
|
44
|
+
/**
|
|
45
|
+
* The length of the mapped parameter in bits (8-bit unsigned integer).
|
|
46
|
+
*
|
|
47
|
+
* @example 16 (for a 16-bit integer)
|
|
48
|
+
* @example 0x10 (hex representation of 16)
|
|
49
|
+
*/
|
|
50
|
+
bitLength: number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Parses a CANopen PDO Mapping Entry (32-bit value) into its components.
|
|
54
|
+
*
|
|
55
|
+
* Structure: Index (16-bit) | Subindex (8-bit) | Bit Length (8-bit)
|
|
56
|
+
*
|
|
57
|
+
* @param entry The mapping entry as a raw number or hex string (e.g., 0x60400010).
|
|
58
|
+
* @returns An object containing the parsed index, subindex, and bit length.
|
|
59
|
+
* @throws Error if the input string is not a valid hex number.
|
|
60
|
+
*/
|
|
61
|
+
export declare function parsePdoMappingEntry(entry: number | string): PdoMappingEntry;
|
package/src/lib/pdo.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePdoMappingEntry = exports.isPdoMappingEntry = void 0;
|
|
4
|
+
// Matches a hex string like "0x60400010" or "60400010"
|
|
5
|
+
// Captures: Group 1 (Index), Group 2 (Subindex), Group 3 (Bit Length)
|
|
6
|
+
const pdoMappingEntryRegExp = /^(?:0x)?([0-9a-fA-F]{4})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
|
|
7
|
+
/**
|
|
8
|
+
* Checks if a string is a valid representation of a CANopen PDO mapping entry.
|
|
9
|
+
*
|
|
10
|
+
* A valid entry is a 32-bit hexadecimal value representing:
|
|
11
|
+
* - **Index** (16 bits)
|
|
12
|
+
* - **Subindex** (8 bits)
|
|
13
|
+
* - **Bit Length** (8 bits)
|
|
14
|
+
*
|
|
15
|
+
* It accepts formats with or without the '0x' prefix (e.g., "0x60400010" or "60400010").
|
|
16
|
+
*
|
|
17
|
+
* @param value The string to validate.
|
|
18
|
+
* @returns `true` if the string follows the PDO mapping entry hex format, `false` otherwise.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* isPdoMappingEntry('0x60400010'); // true
|
|
22
|
+
* isPdoMappingEntry('60400010'); // true
|
|
23
|
+
* isPdoMappingEntry('invalid'); // false
|
|
24
|
+
*/
|
|
25
|
+
function isPdoMappingEntry(value) {
|
|
26
|
+
return pdoMappingEntryRegExp.test(value);
|
|
27
|
+
}
|
|
28
|
+
exports.isPdoMappingEntry = isPdoMappingEntry;
|
|
29
|
+
/**
|
|
30
|
+
* Parses a CANopen PDO Mapping Entry (32-bit value) into its components.
|
|
31
|
+
*
|
|
32
|
+
* Structure: Index (16-bit) | Subindex (8-bit) | Bit Length (8-bit)
|
|
33
|
+
*
|
|
34
|
+
* @param entry The mapping entry as a raw number or hex string (e.g., 0x60400010).
|
|
35
|
+
* @returns An object containing the parsed index, subindex, and bit length.
|
|
36
|
+
* @throws Error if the input string is not a valid hex number.
|
|
37
|
+
*/
|
|
38
|
+
function parsePdoMappingEntry(entry) {
|
|
39
|
+
let value;
|
|
40
|
+
if (typeof entry === 'string') {
|
|
41
|
+
// Determine base: if it starts with 0x, parse as 16, otherwise assume it might be 16 or 10.
|
|
42
|
+
// For PDO mapping strings, we safely assume Hex if it looks like standard "60400010".
|
|
43
|
+
// Using parseInt with radix 16 handles "0x" prefix automatically.
|
|
44
|
+
value = parseInt(entry, 16);
|
|
45
|
+
if (isNaN(value)) {
|
|
46
|
+
throw new Error(`Invalid PDO mapping entry string: "${entry}"`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
value = entry;
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
// Use zero-fill right shift (>>>) to ensure we handle unsigned 32-bit correctly
|
|
54
|
+
index: (value >>> 16) & 0xffff,
|
|
55
|
+
subindex: (value >>> 8) & 0xff,
|
|
56
|
+
bitLength: value & 0xff,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.parsePdoMappingEntry = parsePdoMappingEntry;
|
|
60
|
+
//# sourceMappingURL=pdo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdo.js","sourceRoot":"","sources":["../../../../../libs/motion-master-client/src/lib/pdo.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,sEAAsE;AACtE,MAAM,qBAAqB,GAAG,2DAA2D,CAAC;AAE1F;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,OAAO,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC;AAFD,8CAEC;AAqCD;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CAAC,KAAsB;IACzD,IAAI,KAAa,CAAC;IAElB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,4FAA4F;QAC5F,sFAAsF;QACtF,kEAAkE;QAClE,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAE5B,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE;YAChB,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,GAAG,CAAC,CAAC;SACjE;KACF;SAAM;QACL,KAAK,GAAG,KAAK,CAAC;KACf;IAED,OAAO;QACL,gFAAgF;QAChF,KAAK,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,GAAG,MAAM;QAC9B,QAAQ,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,GAAG,IAAI;QAC9B,SAAS,EAAE,KAAK,GAAG,IAAI;KACxB,CAAC;AACJ,CAAC;AAtBD,oDAsBC"}
|