@ya-modbus/driver-sdk 0.5.1 → 0.7.0
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/CHANGELOG.md +28 -0
- package/dist/cjs/codec.d.ts.map +1 -0
- package/dist/cjs/codec.js +184 -0
- package/dist/cjs/codec.js.map +1 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +24 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/validators.d.ts.map +1 -0
- package/dist/cjs/validators.js +90 -0
- package/dist/cjs/validators.js.map +1 -0
- package/dist/esm/codec.d.ts +90 -0
- package/dist/esm/codec.d.ts.map +1 -0
- package/dist/esm/codec.js.map +1 -0
- package/dist/esm/errors.d.ts +64 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +31 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/validators.d.ts +75 -0
- package/dist/esm/validators.d.ts.map +1 -0
- package/dist/esm/validators.js.map +1 -0
- package/dist/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/package.json +25 -8
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/validators.d.ts.map +0 -1
- package/dist/validators.js.map +0 -1
- /package/dist/{codec.d.ts → cjs/codec.d.ts} +0 -0
- /package/dist/{errors.d.ts → cjs/errors.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{validators.d.ts → cjs/validators.d.ts} +0 -0
- /package/dist/{codec.js → esm/codec.js} +0 -0
- /package/dist/{errors.js → esm/errors.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{validators.js → esm/validators.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.7.0](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-sdk@0.6.0...@ya-modbus/driver-sdk@0.7.0) (2026-01-11)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **build:** add dual CommonJS/ESM package support ([#187](https://github.com/groupsky/ya-modbus/issues/187)) ([3d78130](https://github.com/groupsky/ya-modbus/commit/3d781304d42edba335cdc320ba25275f3b4ea6c9))
|
|
11
|
+
|
|
12
|
+
# 0.6.0 (2026-01-04)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- enable linting without build and fix monorepo build order ([#129](https://github.com/groupsky/ya-modbus/issues/129)) ([e4ba4fd](https://github.com/groupsky/ya-modbus/commit/e4ba4fdc61c8695c3ab0b9504ef340d19861c599)), closes [#130](https://github.com/groupsky/ya-modbus/issues/130)
|
|
17
|
+
- **release:** bump versions to 0.2.0 to bypass npm 24h block ([#148](https://github.com/groupsky/ya-modbus/issues/148)) ([aa2be6a](https://github.com/groupsky/ya-modbus/commit/aa2be6ae998f4443774b43507e7991601ec3068a))
|
|
18
|
+
- **release:** revert failed release and add missing publishConfig ([#147](https://github.com/groupsky/ya-modbus/issues/147)) ([60ea209](https://github.com/groupsky/ya-modbus/commit/60ea2091cbb350b0f474dc45d3ab33177b050764))
|
|
19
|
+
- **release:** revert failed release and cleanup tags ([#145](https://github.com/groupsky/ya-modbus/issues/145)) ([228ae2b](https://github.com/groupsky/ya-modbus/commit/228ae2b4da0c433e475825d068202efd3f0d3a5a)), closes [#143](https://github.com/groupsky/ya-modbus/issues/143) [#144](https://github.com/groupsky/ya-modbus/issues/144)
|
|
20
|
+
- use tsc --build and add composite to all packages ([6001bfa](https://github.com/groupsky/ya-modbus/commit/6001bfa77c6dd87930604b0e7eb6c342991b3988))
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
- add Dependabot with auto-merge and optimize dependencies ([790b31a](https://github.com/groupsky/ya-modbus/commit/790b31aa3282df56517d6d07052204b65c061cdc))
|
|
25
|
+
- add XYMD1 temperature/humidity sensor driver ([b657fc9](https://github.com/groupsky/ya-modbus/commit/b657fc9d142a1b7dcf0f0d82b53b415b5ed7f51a))
|
|
26
|
+
- **driver-sdk:** add reusable utilities for driver development ([#82](https://github.com/groupsky/ya-modbus/issues/82)) ([5283b8e](https://github.com/groupsky/ya-modbus/commit/5283b8ed36ab95f5f0719dd517f31e4ce6aeef09))
|
|
27
|
+
- **release:** add Lerna-Lite publishing with pre-release support ([#135](https://github.com/groupsky/ya-modbus/issues/135)) ([3db7542](https://github.com/groupsky/ya-modbus/commit/3db7542ddbb7bb150b4deab50d5c96e5d668c852))
|
|
28
|
+
- **transport:** extract transport package for code reusability ([#102](https://github.com/groupsky/ya-modbus/issues/102)) ([aea6946](https://github.com/groupsky/ya-modbus/commit/aea6946b40f502ff630c7a0ec599088899c30a90)), closes [#107](https://github.com/groupsky/ya-modbus/issues/107) [#108](https://github.com/groupsky/ya-modbus/issues/108) [#109](https://github.com/groupsky/ya-modbus/issues/109) [#91](https://github.com/groupsky/ya-modbus/issues/91)
|
|
29
|
+
|
|
30
|
+
### Reverts
|
|
31
|
+
|
|
32
|
+
- Revert "chore(release): publish packages" ([a6d080d](https://github.com/groupsky/ya-modbus/commit/a6d080deeacf306f4911b6d78eab05dac8bfa7a7))
|
|
33
|
+
|
|
6
34
|
## [0.5.1](https://github.com/groupsky/ya-modbus/compare/@ya-modbus/driver-sdk@0.5.0...@ya-modbus/driver-sdk@0.5.1) (2026-01-04)
|
|
7
35
|
|
|
8
36
|
**Note:** Version bump only for package @ya-modbus/driver-sdk
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUxE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWvE"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Buffer encoding/decoding utilities for Modbus register values
|
|
4
|
+
*
|
|
5
|
+
* These utilities handle common patterns in Modbus drivers like reading
|
|
6
|
+
* scaled integers (×10, ×100, ×1000) from register buffers.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.readScaledUInt16BE = readScaledUInt16BE;
|
|
10
|
+
exports.readScaledInt16BE = readScaledInt16BE;
|
|
11
|
+
exports.readScaledUInt32BE = readScaledUInt32BE;
|
|
12
|
+
exports.writeScaledUInt16BE = writeScaledUInt16BE;
|
|
13
|
+
exports.writeScaledInt16BE = writeScaledInt16BE;
|
|
14
|
+
/**
|
|
15
|
+
* Validate that a scale parameter is valid
|
|
16
|
+
*
|
|
17
|
+
* @param scale - Scale factor to validate
|
|
18
|
+
* @throws Error if scale is not finite or is not positive
|
|
19
|
+
*/
|
|
20
|
+
function validateScale(scale) {
|
|
21
|
+
if (!Number.isFinite(scale)) {
|
|
22
|
+
throw new Error('Invalid scale: must be a finite number');
|
|
23
|
+
}
|
|
24
|
+
if (scale <= 0) {
|
|
25
|
+
throw new Error('Invalid scale: must be greater than 0');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validate that a value for writing is valid
|
|
30
|
+
*
|
|
31
|
+
* @param value - Value to validate
|
|
32
|
+
* @throws Error if value is not finite
|
|
33
|
+
*/
|
|
34
|
+
function validateWriteValue(value) {
|
|
35
|
+
if (!Number.isFinite(value)) {
|
|
36
|
+
throw new Error('Invalid value: must be a finite number');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate that a scaled value fits within the target integer range
|
|
41
|
+
*
|
|
42
|
+
* @param scaledValue - Scaled value to validate
|
|
43
|
+
* @param min - Minimum allowed value (inclusive)
|
|
44
|
+
* @param max - Maximum allowed value (inclusive)
|
|
45
|
+
* @param typeName - Name of the target type for error messages
|
|
46
|
+
* @throws Error if scaled value is outside the valid range
|
|
47
|
+
*/
|
|
48
|
+
function validateRange(scaledValue, min, max, typeName) {
|
|
49
|
+
if (scaledValue < min || scaledValue > max) {
|
|
50
|
+
throw new Error(`Invalid scaled value: ${scaledValue} is outside ${typeName} range (${min} to ${max})`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validate that buffer has sufficient bytes for reading at the given offset
|
|
55
|
+
*
|
|
56
|
+
* @param buffer - Buffer to validate
|
|
57
|
+
* @param offset - Byte offset to start reading from
|
|
58
|
+
* @param bytesNeeded - Number of bytes required
|
|
59
|
+
* @param typeName - Name of the type being read for error messages
|
|
60
|
+
* @throws Error if buffer doesn't have enough bytes
|
|
61
|
+
*/
|
|
62
|
+
function validateBufferBounds(buffer, offset, bytesNeeded, typeName) {
|
|
63
|
+
const available = buffer.length - offset;
|
|
64
|
+
if (available < bytesNeeded) {
|
|
65
|
+
throw new Error(`Insufficient buffer size for ${typeName}: need ${bytesNeeded} bytes at offset ${offset}, ` +
|
|
66
|
+
`but only ${available} bytes available (buffer length: ${buffer.length})`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Read and scale an unsigned 16-bit integer from a buffer
|
|
71
|
+
*
|
|
72
|
+
* @param buffer - Buffer containing the register data
|
|
73
|
+
* @param offset - Byte offset to start reading from
|
|
74
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
75
|
+
* @returns Scaled floating-point value
|
|
76
|
+
* @throws Error if scale is not a finite positive number
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Device stores temperature as integer ×10 (235 = 23.5°C)
|
|
81
|
+
* const buffer = await transport.readInputRegisters(0, 1)
|
|
82
|
+
* const temperature = readScaledUInt16BE(buffer, 0, 10)
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
function readScaledUInt16BE(buffer, offset, scale) {
|
|
86
|
+
validateScale(scale);
|
|
87
|
+
validateBufferBounds(buffer, offset, 2, 'uint16');
|
|
88
|
+
const rawValue = buffer.readUInt16BE(offset);
|
|
89
|
+
return rawValue / scale;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read and scale a signed 16-bit integer from a buffer
|
|
93
|
+
*
|
|
94
|
+
* @param buffer - Buffer containing the register data
|
|
95
|
+
* @param offset - Byte offset to start reading from
|
|
96
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
97
|
+
* @returns Scaled floating-point value
|
|
98
|
+
* @throws Error if scale is not a finite positive number
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* // Device stores correction offset as signed integer ×10 (-50 = -5.0°C)
|
|
103
|
+
* const buffer = await transport.readHoldingRegisters(0x103, 1)
|
|
104
|
+
* const correction = readScaledInt16BE(buffer, 0, 10)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
function readScaledInt16BE(buffer, offset, scale) {
|
|
108
|
+
validateScale(scale);
|
|
109
|
+
validateBufferBounds(buffer, offset, 2, 'int16');
|
|
110
|
+
const rawValue = buffer.readInt16BE(offset);
|
|
111
|
+
return rawValue / scale;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Read and scale an unsigned 32-bit integer from a buffer
|
|
115
|
+
*
|
|
116
|
+
* @param buffer - Buffer containing the register data (2 consecutive registers)
|
|
117
|
+
* @param offset - Byte offset to start reading from
|
|
118
|
+
* @param scale - Scale factor (e.g., 100 for ×100 values)
|
|
119
|
+
* @returns Scaled floating-point value
|
|
120
|
+
* @throws Error if scale is not a finite positive number
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // Device stores total energy as 32-bit integer ×100 (1000000 = 10000.00 kWh)
|
|
125
|
+
* const buffer = await transport.readHoldingRegisters(0x0007, 2)
|
|
126
|
+
* const totalEnergy = readScaledUInt32BE(buffer, 0, 100)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
function readScaledUInt32BE(buffer, offset, scale) {
|
|
130
|
+
validateScale(scale);
|
|
131
|
+
validateBufferBounds(buffer, offset, 4, 'uint32');
|
|
132
|
+
const rawValue = buffer.readUInt32BE(offset);
|
|
133
|
+
return rawValue / scale;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Encode and scale a value to an unsigned 16-bit integer buffer
|
|
137
|
+
*
|
|
138
|
+
* @param value - Value to encode
|
|
139
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
140
|
+
* @returns 2-byte buffer containing the scaled value
|
|
141
|
+
* @throws Error if value is not finite, scale is invalid, or scaled value exceeds uint16 range
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Write humidity correction of 5.5% (stored as 55)
|
|
146
|
+
* const buffer = writeScaledUInt16BE(5.5, 10)
|
|
147
|
+
* await transport.writeMultipleRegisters(0x104, buffer)
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function writeScaledUInt16BE(value, scale) {
|
|
151
|
+
validateWriteValue(value);
|
|
152
|
+
validateScale(scale);
|
|
153
|
+
const scaledValue = Math.trunc(value * scale);
|
|
154
|
+
validateRange(scaledValue, 0, 0xffff, 'uint16');
|
|
155
|
+
const buffer = Buffer.allocUnsafe(2);
|
|
156
|
+
buffer.writeUInt16BE(scaledValue, 0);
|
|
157
|
+
return buffer;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Encode and scale a value to a signed 16-bit integer buffer
|
|
161
|
+
*
|
|
162
|
+
* @param value - Value to encode
|
|
163
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
164
|
+
* @returns 2-byte buffer containing the scaled value
|
|
165
|
+
* @throws Error if value is not finite, scale is invalid, or scaled value exceeds int16 range
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // Write temperature correction of -3.5°C (stored as -35)
|
|
170
|
+
* const buffer = writeScaledInt16BE(-3.5, 10)
|
|
171
|
+
* await transport.writeMultipleRegisters(0x103, buffer)
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
function writeScaledInt16BE(value, scale) {
|
|
175
|
+
validateWriteValue(value);
|
|
176
|
+
validateScale(scale);
|
|
177
|
+
// Use Math.trunc for predictable rounding toward zero (avoids floating-point precision issues)
|
|
178
|
+
const scaledValue = Math.trunc(value * scale);
|
|
179
|
+
validateRange(scaledValue, -0x8000, 0x7fff, 'int16');
|
|
180
|
+
const buffer = Buffer.allocUnsafe(2);
|
|
181
|
+
buffer.writeInt16BE(scaledValue, 0);
|
|
182
|
+
return buffer;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=codec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAsFH,gDAKC;AAkBD,8CAKC;AAkBD,gDAKC;AAiBD,kDAUC;AAiBD,gDAWC;AA9LD;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IACD,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAA;IAC1D,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,kBAAkB,CAAC,KAAa;IACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,WAAmB,EAAE,GAAW,EAAE,GAAW,EAAE,QAAgB;IACpF,IAAI,WAAW,GAAG,GAAG,IAAI,WAAW,GAAG,GAAG,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,yBAAyB,WAAW,eAAe,QAAQ,WAAW,GAAG,OAAO,GAAG,GAAG,CACvF,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,oBAAoB,CAC3B,MAAc,EACd,MAAc,EACd,WAAmB,EACnB,QAAgB;IAE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IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;AAahG;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAA;AACjF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error formatting utilities for consistent validation error messages
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatRangeError = formatRangeError;
|
|
7
|
+
exports.formatEnumError = formatEnumError;
|
|
8
|
+
function formatRangeError(name, ...args) {
|
|
9
|
+
if (args.length === 2) {
|
|
10
|
+
const [min, max] = args;
|
|
11
|
+
return `Invalid ${name}: must be between ${min} and ${max}`;
|
|
12
|
+
}
|
|
13
|
+
const [value, min, max] = args;
|
|
14
|
+
return `Invalid ${name}: received ${String(value)}, must be between ${min} and ${max}`;
|
|
15
|
+
}
|
|
16
|
+
function formatEnumError(name, ...args) {
|
|
17
|
+
if (args.length === 1) {
|
|
18
|
+
const [values] = args;
|
|
19
|
+
return `Invalid ${name}: must be one of ${values.join(', ')}`;
|
|
20
|
+
}
|
|
21
|
+
const [value, values] = args;
|
|
22
|
+
return `Invalid ${name}: received ${String(value)}, must be one of ${values.join(', ')}`;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAiCH,4CAUC;AA+BD,0CAUC;AAnDD,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,GAAG,IAAkD;IAErD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;QACvB,OAAO,WAAW,IAAI,qBAAqB,GAAG,QAAQ,GAAG,EAAE,CAAA;IAC7D,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;IAC9B,OAAO,WAAW,IAAI,cAAc,MAAM,CAAC,KAAK,CAAC,qBAAqB,GAAG,QAAQ,GAAG,EAAE,CAAA;AACxF,CAAC;AA+BD,SAAgB,eAAe,CAC7B,IAAY,EACZ,GAAG,IAA0D;IAE7D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;QACrB,OAAO,WAAW,IAAI,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAC/D,CAAC;IACD,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAC5B,OAAO,WAAW,IAAI,cAAc,MAAM,CAAC,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime SDK for ya-modbus device drivers
|
|
4
|
+
*
|
|
5
|
+
* Provides utilities for common driver development tasks:
|
|
6
|
+
* - Buffer encoding/decoding for scaled register values
|
|
7
|
+
* - Configuration validation with type narrowing
|
|
8
|
+
* - Consistent error message formatting
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {
|
|
13
|
+
* readScaledUInt16BE,
|
|
14
|
+
* createEnumValidator,
|
|
15
|
+
* formatEnumError,
|
|
16
|
+
* } from '@ya-modbus/driver-sdk'
|
|
17
|
+
*
|
|
18
|
+
* // Read scaled temperature value
|
|
19
|
+
* const buffer = await transport.readInputRegisters(1, 1)
|
|
20
|
+
* const temperature = readScaledUInt16BE(buffer, 0, 10)
|
|
21
|
+
*
|
|
22
|
+
* // Validate baud rate
|
|
23
|
+
* const isValidBaudRate = createEnumValidator([9600, 14400, 19200] as const)
|
|
24
|
+
* if (!isValidBaudRate(value)) {
|
|
25
|
+
* throw new Error(formatEnumError('baud rate', [9600, 14400, 19200]))
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const tslib_1 = require("tslib");
|
|
31
|
+
// Re-export all utilities
|
|
32
|
+
tslib_1.__exportStar(require("./codec.js"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./validators.js"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./errors.js"), exports);
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;AAEH,0BAA0B;AAC1B,qDAA0B;AAC1B,0DAA+B;AAC/B,sDAA2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,EAC9D,MAAM,EAAE,CAAC,GACR,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,CAIxC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,MAAM,CAIrC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation utilities for driver configuration values
|
|
4
|
+
*
|
|
5
|
+
* These utilities provide type-safe validation with proper TypeScript
|
|
6
|
+
* type narrowing for common configuration values like baud rates,
|
|
7
|
+
* device addresses, and numeric ranges.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.createEnumValidator = createEnumValidator;
|
|
11
|
+
exports.createRangeValidator = createRangeValidator;
|
|
12
|
+
exports.isValidInteger = isValidInteger;
|
|
13
|
+
/**
|
|
14
|
+
* Create a type-safe enum validator function
|
|
15
|
+
*
|
|
16
|
+
* Returns a type guard function that validates if a value is one of
|
|
17
|
+
* the allowed enum values. The returned function properly narrows
|
|
18
|
+
* TypeScript types.
|
|
19
|
+
*
|
|
20
|
+
* @param values - Readonly array of valid enum values
|
|
21
|
+
* @returns Type guard function that validates enum membership
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { createEnumValidator } from '@ya-modbus/driver-sdk'
|
|
26
|
+
*
|
|
27
|
+
* const VALID_BAUD_RATES = [9600, 14400, 19200] as const
|
|
28
|
+
* type ValidBaudRate = (typeof VALID_BAUD_RATES)[number]
|
|
29
|
+
*
|
|
30
|
+
* const isValidBaudRate = createEnumValidator(VALID_BAUD_RATES)
|
|
31
|
+
*
|
|
32
|
+
* if (isValidBaudRate(value)) {
|
|
33
|
+
* // value is now typed as ValidBaudRate
|
|
34
|
+
* const encoded = encodeBaudRate(value)
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function createEnumValidator(values) {
|
|
39
|
+
return (value) => {
|
|
40
|
+
return values.includes(value);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a numeric range validator function
|
|
45
|
+
*
|
|
46
|
+
* Returns a function that validates if a value is a finite number
|
|
47
|
+
* within the specified range (inclusive).
|
|
48
|
+
*
|
|
49
|
+
* @param min - Minimum valid value (inclusive)
|
|
50
|
+
* @param max - Maximum valid value (inclusive)
|
|
51
|
+
* @returns Validator function that checks range membership
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* import { createRangeValidator } from '@ya-modbus/driver-sdk'
|
|
56
|
+
*
|
|
57
|
+
* const isValidAddress = createRangeValidator(1, 247)
|
|
58
|
+
*
|
|
59
|
+
* if (isValidAddress(value)) {
|
|
60
|
+
* // value is a finite number between 1 and 247
|
|
61
|
+
* await writeAddress(value)
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function createRangeValidator(min, max) {
|
|
66
|
+
return (value) => {
|
|
67
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= min && value <= max;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate that a value is a finite integer
|
|
72
|
+
*
|
|
73
|
+
* Checks if a value is a number, finite, and has no fractional part.
|
|
74
|
+
*
|
|
75
|
+
* @param value - Value to validate
|
|
76
|
+
* @returns True if value is a finite integer
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { isValidInteger } from '@ya-modbus/driver-sdk'
|
|
81
|
+
*
|
|
82
|
+
* if (!isValidInteger(value)) {
|
|
83
|
+
* throw new Error('Device address must be an integer')
|
|
84
|
+
* }
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function isValidInteger(value) {
|
|
88
|
+
return typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AA2BH,kDAMC;AAwBD,oDAOC;AAmBD,wCAEC;AAnFD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,mBAAmB,CACjC,MAAS;IAET,OAAO,CAAC,KAAc,EAAsB,EAAE;QAC5C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAkB,CAAC,CAAA;IAC5C,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,SAAgB,oBAAoB,CAClC,GAAW,EACX,GAAW;IAEX,OAAO,CAAC,KAAc,EAAmB,EAAE;QACzC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAA;IAC5F,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AACvF,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Buffer encoding/decoding utilities for Modbus register values
|
|
3
|
+
*
|
|
4
|
+
* These utilities handle common patterns in Modbus drivers like reading
|
|
5
|
+
* scaled integers (×10, ×100, ×1000) from register buffers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Read and scale an unsigned 16-bit integer from a buffer
|
|
9
|
+
*
|
|
10
|
+
* @param buffer - Buffer containing the register data
|
|
11
|
+
* @param offset - Byte offset to start reading from
|
|
12
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
13
|
+
* @returns Scaled floating-point value
|
|
14
|
+
* @throws Error if scale is not a finite positive number
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // Device stores temperature as integer ×10 (235 = 23.5°C)
|
|
19
|
+
* const buffer = await transport.readInputRegisters(0, 1)
|
|
20
|
+
* const temperature = readScaledUInt16BE(buffer, 0, 10)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function readScaledUInt16BE(buffer: Buffer, offset: number, scale: number): number;
|
|
24
|
+
/**
|
|
25
|
+
* Read and scale a signed 16-bit integer from a buffer
|
|
26
|
+
*
|
|
27
|
+
* @param buffer - Buffer containing the register data
|
|
28
|
+
* @param offset - Byte offset to start reading from
|
|
29
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
30
|
+
* @returns Scaled floating-point value
|
|
31
|
+
* @throws Error if scale is not a finite positive number
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* // Device stores correction offset as signed integer ×10 (-50 = -5.0°C)
|
|
36
|
+
* const buffer = await transport.readHoldingRegisters(0x103, 1)
|
|
37
|
+
* const correction = readScaledInt16BE(buffer, 0, 10)
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function readScaledInt16BE(buffer: Buffer, offset: number, scale: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* Read and scale an unsigned 32-bit integer from a buffer
|
|
43
|
+
*
|
|
44
|
+
* @param buffer - Buffer containing the register data (2 consecutive registers)
|
|
45
|
+
* @param offset - Byte offset to start reading from
|
|
46
|
+
* @param scale - Scale factor (e.g., 100 for ×100 values)
|
|
47
|
+
* @returns Scaled floating-point value
|
|
48
|
+
* @throws Error if scale is not a finite positive number
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Device stores total energy as 32-bit integer ×100 (1000000 = 10000.00 kWh)
|
|
53
|
+
* const buffer = await transport.readHoldingRegisters(0x0007, 2)
|
|
54
|
+
* const totalEnergy = readScaledUInt32BE(buffer, 0, 100)
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function readScaledUInt32BE(buffer: Buffer, offset: number, scale: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Encode and scale a value to an unsigned 16-bit integer buffer
|
|
60
|
+
*
|
|
61
|
+
* @param value - Value to encode
|
|
62
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
63
|
+
* @returns 2-byte buffer containing the scaled value
|
|
64
|
+
* @throws Error if value is not finite, scale is invalid, or scaled value exceeds uint16 range
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* // Write humidity correction of 5.5% (stored as 55)
|
|
69
|
+
* const buffer = writeScaledUInt16BE(5.5, 10)
|
|
70
|
+
* await transport.writeMultipleRegisters(0x104, buffer)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function writeScaledUInt16BE(value: number, scale: number): Buffer;
|
|
74
|
+
/**
|
|
75
|
+
* Encode and scale a value to a signed 16-bit integer buffer
|
|
76
|
+
*
|
|
77
|
+
* @param value - Value to encode
|
|
78
|
+
* @param scale - Scale factor (e.g., 10 for ×10 values)
|
|
79
|
+
* @returns 2-byte buffer containing the scaled value
|
|
80
|
+
* @throws Error if value is not finite, scale is invalid, or scaled value exceeds int16 range
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Write temperature correction of -3.5°C (stored as -35)
|
|
85
|
+
* const buffer = writeScaledInt16BE(-3.5, 10)
|
|
86
|
+
* await transport.writeMultipleRegisters(0x103, buffer)
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function writeScaledInt16BE(value: number, scale: number): Buffer;
|
|
90
|
+
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUxE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAWvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.js","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KA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pC,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,KAAa;IAC7D,kBAAkB,CAAC,KAAK,CAAC,CAAA;IACzB,aAAa,CAAC,KAAK,CAAC,CAAA;IAEpB,+FAA+F;IAC/F,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;IAC7C,aAAa,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAEpD,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IACpC,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;IACnC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error formatting utilities for consistent validation error messages
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Format a range validation error message
|
|
6
|
+
*
|
|
7
|
+
* @param name - Field name for the error message
|
|
8
|
+
* @param min - Minimum valid value
|
|
9
|
+
* @param max - Maximum valid value
|
|
10
|
+
* @returns Formatted error message
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* formatRangeError('device address', 1, 247)
|
|
15
|
+
* // => 'Invalid device address: must be between 1 and 247'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function formatRangeError(name: string, min: number, max: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Format a range validation error message with the actual value
|
|
21
|
+
*
|
|
22
|
+
* @param name - Field name for the error message
|
|
23
|
+
* @param value - Actual value that was rejected
|
|
24
|
+
* @param min - Minimum valid value
|
|
25
|
+
* @param max - Maximum valid value
|
|
26
|
+
* @returns Formatted error message
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* formatRangeError('device address', 256, 1, 247)
|
|
31
|
+
* // => 'Invalid device address: received 256, must be between 1 and 247'
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatRangeError(name: string, value: unknown, min: number, max: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Format an enum validation error message
|
|
37
|
+
*
|
|
38
|
+
* @param name - Field name for the error message
|
|
39
|
+
* @param values - Valid enum values
|
|
40
|
+
* @returns Formatted error message
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* formatEnumError('baud rate', [9600, 14400, 19200])
|
|
45
|
+
* // => 'Invalid baud rate: must be one of 9600, 14400, 19200'
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatEnumError(name: string, values: readonly unknown[]): string;
|
|
49
|
+
/**
|
|
50
|
+
* Format an enum validation error message with the actual value
|
|
51
|
+
*
|
|
52
|
+
* @param name - Field name for the error message
|
|
53
|
+
* @param value - Actual value that was rejected
|
|
54
|
+
* @param values - Valid enum values
|
|
55
|
+
* @returns Formatted error message
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* formatEnumError('baud rate', 115200, [9600, 14400, 19200])
|
|
60
|
+
* // => 'Invalid baud rate: received 115200, must be one of 9600, 14400, 19200'
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatEnumError(name: string, value: unknown, values: readonly unknown[]): string;
|
|
64
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;AAChF;;;;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CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;IAC5B,OAAO,WAAW,IAAI,cAAc,MAAM,CAAC,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;AAC1F,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime SDK for ya-modbus device drivers
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for common driver development tasks:
|
|
5
|
+
* - Buffer encoding/decoding for scaled register values
|
|
6
|
+
* - Configuration validation with type narrowing
|
|
7
|
+
* - Consistent error message formatting
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import {
|
|
12
|
+
* readScaledUInt16BE,
|
|
13
|
+
* createEnumValidator,
|
|
14
|
+
* formatEnumError,
|
|
15
|
+
* } from '@ya-modbus/driver-sdk'
|
|
16
|
+
*
|
|
17
|
+
* // Read scaled temperature value
|
|
18
|
+
* const buffer = await transport.readInputRegisters(1, 1)
|
|
19
|
+
* const temperature = readScaledUInt16BE(buffer, 0, 10)
|
|
20
|
+
*
|
|
21
|
+
* // Validate baud rate
|
|
22
|
+
* const isValidBaudRate = createEnumValidator([9600, 14400, 19200] as const)
|
|
23
|
+
* if (!isValidBaudRate(value)) {
|
|
24
|
+
* throw new Error(formatEnumError('baud rate', [9600, 14400, 19200]))
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export * from './codec.js';
|
|
29
|
+
export * from './validators.js';
|
|
30
|
+
export * from './errors.js';
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,0BAA0B;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|