@synapticon/motion-master-client 6.0.0-alpha.29 → 6.0.0-alpha.31
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/dist/sdo.d.ts +2 -0
- package/dist/sdo.js +9 -2
- package/package.json +1 -1
package/dist/sdo.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const SDO_TYPES: readonly ["uint8", "int8", "uint16", "int16", "uint32", "int32", "uint64", "int64", "float32", "float64", "string", "raw"];
|
|
2
2
|
export type SdoType = (typeof SDO_TYPES)[number];
|
|
3
3
|
export declare const SDO_TYPE_HINT: Record<SdoType, string>;
|
|
4
|
+
export declare function parseIntegerFlexible(s: string): bigint | null;
|
|
5
|
+
export declare function isIntegerSdoType(type: SdoType): boolean;
|
|
4
6
|
export declare function encodeSdoValue(type: SdoType, raw: string): {
|
|
5
7
|
bytes: number[];
|
|
6
8
|
} | {
|
package/dist/sdo.js
CHANGED
|
@@ -29,7 +29,9 @@ const INT_ENC = {
|
|
|
29
29
|
uint64: { size: 8, signed: false }, int64: { size: 8, signed: true },
|
|
30
30
|
};
|
|
31
31
|
// Accepts decimal (with optional leading '-') or 0x-prefixed hex; returns null on anything else.
|
|
32
|
-
|
|
32
|
+
// Signed hex is signed-magnitude ("-0x1"), not two's-complement — so a value round-trips through
|
|
33
|
+
// the range check in encodeSdoValue regardless of the base it was entered in.
|
|
34
|
+
export function parseIntegerFlexible(s) {
|
|
33
35
|
if (/^-?[0-9]+$/.test(s))
|
|
34
36
|
return BigInt(s);
|
|
35
37
|
if (/^0[xX][0-9a-fA-F]+$/.test(s))
|
|
@@ -38,12 +40,17 @@ function parseBigIntFlexible(s) {
|
|
|
38
40
|
return -BigInt(s.slice(1));
|
|
39
41
|
return null;
|
|
40
42
|
}
|
|
43
|
+
// True for the fixed-width integer types — the ones a value can meaningfully be shown and edited
|
|
44
|
+
// in hexadecimal (floats and strings have no base; `raw` is already entered as hex bytes).
|
|
45
|
+
export function isIntegerSdoType(type) {
|
|
46
|
+
return type in INT_ENC;
|
|
47
|
+
}
|
|
41
48
|
// Encodes a human-entered value into the little-endian byte sequence for an SDO download.
|
|
42
49
|
export function encodeSdoValue(type, raw) {
|
|
43
50
|
const s = raw.trim();
|
|
44
51
|
const meta = INT_ENC[type];
|
|
45
52
|
if (meta) {
|
|
46
|
-
const n =
|
|
53
|
+
const n = parseIntegerFlexible(s);
|
|
47
54
|
if (n === null)
|
|
48
55
|
return { error: 'Not a valid integer' };
|
|
49
56
|
const bits = BigInt(meta.size * 8);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synapticon/motion-master-client",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.31",
|
|
4
4
|
"description": "Isomorphic TypeScript client for Motion Master: the generated HTTP API client, the WebSocket connection, and helpers.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|