@espressif/rainmaker-neo-base-sdk 1.1.0 → 1.2.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.
Files changed (55) hide show
  1. package/dist/cjs/ESPRMNeoBase.js +1 -1
  2. package/dist/cjs/index.js +11 -0
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/proto/rmaker_local_ctrl.js +273 -0
  5. package/dist/cjs/proto/rmaker_local_ctrl.js.map +1 -0
  6. package/dist/cjs/services/ESPTransport/ESPDiscovery/ESPDiscoveryManager.js +5 -4
  7. package/dist/cjs/services/ESPTransport/ESPDiscovery/ESPDiscoveryManager.js.map +1 -1
  8. package/dist/cjs/services/ESPTransport/ESPLocalControlTransport.js +183 -116
  9. package/dist/cjs/services/ESPTransport/ESPLocalControlTransport.js.map +1 -1
  10. package/dist/cjs/services/ESPTransport/LocalControlSession.js +62 -0
  11. package/dist/cjs/services/ESPTransport/LocalControlSession.js.map +1 -0
  12. package/dist/cjs/types/transport.js +24 -0
  13. package/dist/cjs/types/transport.js.map +1 -1
  14. package/dist/cjs/utils/constants.js +70 -4
  15. package/dist/cjs/utils/constants.js.map +1 -1
  16. package/dist/cjs/utils/eventSubscriptionUtils.js +48 -4
  17. package/dist/cjs/utils/eventSubscriptionUtils.js.map +1 -1
  18. package/dist/esm/ESPRMNeoBase.js +1 -1
  19. package/dist/esm/index.js +2 -2
  20. package/dist/esm/proto/rmaker_local_ctrl.js +271 -0
  21. package/dist/esm/proto/rmaker_local_ctrl.js.map +1 -0
  22. package/dist/esm/services/ESPTransport/ESPDiscovery/ESPDiscoveryManager.js +5 -4
  23. package/dist/esm/services/ESPTransport/ESPDiscovery/ESPDiscoveryManager.js.map +1 -1
  24. package/dist/esm/services/ESPTransport/ESPLocalControlTransport.js +184 -117
  25. package/dist/esm/services/ESPTransport/ESPLocalControlTransport.js.map +1 -1
  26. package/dist/esm/services/ESPTransport/LocalControlSession.js +59 -0
  27. package/dist/esm/services/ESPTransport/LocalControlSession.js.map +1 -0
  28. package/dist/esm/types/transport.js +24 -1
  29. package/dist/esm/types/transport.js.map +1 -1
  30. package/dist/esm/utils/constants.js +65 -5
  31. package/dist/esm/utils/constants.js.map +1 -1
  32. package/dist/esm/utils/eventSubscriptionUtils.js +49 -5
  33. package/dist/esm/utils/eventSubscriptionUtils.js.map +1 -1
  34. package/dist/types/ESPRMNeoBase.d.ts +1 -1
  35. package/dist/types/proto/rmaker_local_ctrl.d.ts +137 -0
  36. package/dist/types/services/ESPTransport/ESPDiscovery/ESPDiscoveryManager.d.ts +4 -3
  37. package/dist/types/services/ESPTransport/ESPLocalControlTransport.d.ts +70 -23
  38. package/dist/types/services/ESPTransport/LocalControlSession.d.ts +24 -0
  39. package/dist/types/types/discovery.d.ts +1 -1
  40. package/dist/types/types/localControl.d.ts +26 -1
  41. package/dist/types/types/transport.d.ts +24 -2
  42. package/dist/types/utils/baseUtils.d.ts +1 -1
  43. package/dist/types/utils/constants.d.ts +65 -5
  44. package/dist/types/utils/eventSubscriptionUtils.d.ts +19 -3
  45. package/package.json +1 -1
  46. package/dist/cjs/proto/constants.js +0 -24
  47. package/dist/cjs/proto/constants.js.map +0 -1
  48. package/dist/cjs/proto/esp_local_ctrl.js +0 -787
  49. package/dist/cjs/proto/esp_local_ctrl.js.map +0 -1
  50. package/dist/esm/proto/constants.js +0 -24
  51. package/dist/esm/proto/constants.js.map +0 -1
  52. package/dist/esm/proto/esp_local_ctrl.js +0 -758
  53. package/dist/esm/proto/esp_local_ctrl.js.map +0 -1
  54. package/dist/types/proto/constants.d.ts +0 -15
  55. package/dist/types/proto/esp_local_ctrl.d.ts +0 -283
@@ -185,7 +185,7 @@ class ESPRMNeoBase {
185
185
  }
186
186
  /**
187
187
  * Sets the local control adapter used to talk to nodes over the LAN via
188
- * the `esp_local_ctrl` protocol.
188
+ * the `rmaker_local_ctrl` protocol.
189
189
  *
190
190
  * @param adapter - Adapter implementing {@link ESPLocalControlAdapterInterface}.
191
191
  * @throws {Error} If the SDK is not initialized or the adapter is invalid.
package/dist/cjs/index.js CHANGED
@@ -191,7 +191,12 @@ Object.defineProperty(exports, "ESPTransport", {
191
191
  get: function () { return provision.ESPTransport; }
192
192
  });
193
193
  exports.resolveNodeId = subscription.resolveNodeId;
194
+ exports.DEFAULT_LOCAL_CONTROL_PROTOCOL = transport.DEFAULT_LOCAL_CONTROL_PROTOCOL;
194
195
  exports.DEFAULT_TRANSPORT_ORDER = transport.DEFAULT_TRANSPORT_ORDER;
196
+ Object.defineProperty(exports, "ESPLocalControlProtocol", {
197
+ enumerable: true,
198
+ get: function () { return transport.ESPLocalControlProtocol; }
199
+ });
195
200
  Object.defineProperty(exports, "ESPTransportMode", {
196
201
  enumerable: true,
197
202
  get: function () { return transport.ESPTransportMode; }
@@ -269,6 +274,12 @@ exports.NodeWarnMessages = constants.NodeWarnMessages;
269
274
  exports.ProtocolType = constants.ProtocolType;
270
275
  exports.ProvErrorCodes = constants.ProvErrorCodes;
271
276
  exports.ProvisionType = constants.ProvisionType;
277
+ exports.RMAKER_LOCAL_CTRL_FRAGMENT_SIZE = constants.RMAKER_LOCAL_CTRL_FRAGMENT_SIZE;
278
+ exports.RMAKER_LOCAL_CTRL_VERSION_KEY = constants.RMAKER_LOCAL_CTRL_VERSION_KEY;
279
+ exports.RMakerLocalCtrlCapability = constants.RMakerLocalCtrlCapability;
280
+ exports.RMakerLocalCtrlEndpoint = constants.RMakerLocalCtrlEndpoint;
281
+ exports.RMakerLocalCtrlSetParamsStatus = constants.RMakerLocalCtrlSetParamsStatus;
282
+ exports.RMakerLocalCtrlTxtKey = constants.RMakerLocalCtrlTxtKey;
272
283
  exports.SDK_VERSION = constants.SDK_VERSION;
273
284
  exports.ScheduleErrorMessages = constants.ScheduleErrorMessages;
274
285
  exports.ScheduleSuccessMessages = constants.ScheduleSuccessMessages;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,273 @@
1
+ 'use strict';
2
+
3
+ /*
4
+ * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
5
+ *
6
+ * SPDX-License-Identifier: Apache-2.0
7
+ */
8
+ /**
9
+ * Codec for the `rmaker_local_ctrl` endpoint protocol, mirroring the firmware's
10
+ * `local_ctrl.proto` schema.
11
+ *
12
+ * Hand-rolled like {@link ClaimingProtoHelper} rather than generated: the
13
+ * schema is small, and generated `google-protobuf` modules cannot be pulled
14
+ * into a downstream Metro/RN bundle (see the note in `utils/export.ts`).
15
+ *
16
+ * Field numbers are the wire contract with deployed firmware — treat them as
17
+ * frozen:
18
+ * - `RMakerLocalCtrlPayload`: 1 = msg (varint), 10 = cmdGetData, 11 = respGetData
19
+ * - `CmdGetData`: 1 = DataType (varint), 2 = Offset (varint),
20
+ * 3 = Timestamp (varint), 4 = HasTimestamp (varint)
21
+ * - `RespGetData`: 1 = Status (varint), 2 = Buf
22
+ * - `PayloadBuf`: 1 = Offset (varint), 2 = Payload (bytes), 3 = TotalLen (varint)
23
+ *
24
+ * `Timestamp` / `HasTimestamp` are reserved for a future signed-response
25
+ * extension and are ignored by current firmware, so the encoder omits them.
26
+ *
27
+ * Only `get_params` / `get_config` use this schema; `set_params` carries raw
28
+ * JSON on the wire.
29
+ */
30
+ /**
31
+ * Status returned by the device for a data read.
32
+ */
33
+ exports.RMakerLocalCtrlStatus = void 0;
34
+ (function (RMakerLocalCtrlStatus) {
35
+ RMakerLocalCtrlStatus[RMakerLocalCtrlStatus["Success"] = 0] = "Success";
36
+ RMakerLocalCtrlStatus[RMakerLocalCtrlStatus["Fail"] = 1] = "Fail";
37
+ RMakerLocalCtrlStatus[RMakerLocalCtrlStatus["InvalidParam"] = 2] = "InvalidParam";
38
+ RMakerLocalCtrlStatus[RMakerLocalCtrlStatus["NoMemory"] = 3] = "NoMemory";
39
+ })(exports.RMakerLocalCtrlStatus || (exports.RMakerLocalCtrlStatus = {}));
40
+ /**
41
+ * Selects which document a read targets.
42
+ */
43
+ exports.RMakerLocalCtrlDataType = void 0;
44
+ (function (RMakerLocalCtrlDataType) {
45
+ /** The node's params JSON, as served by `get_params`. */
46
+ RMakerLocalCtrlDataType[RMakerLocalCtrlDataType["TypeParams"] = 0] = "TypeParams";
47
+ /** The node's config JSON, as served by `get_config`. */
48
+ RMakerLocalCtrlDataType[RMakerLocalCtrlDataType["TypeConfig"] = 1] = "TypeConfig";
49
+ })(exports.RMakerLocalCtrlDataType || (exports.RMakerLocalCtrlDataType = {}));
50
+ /**
51
+ * Message type discriminator carried on `RMakerLocalCtrlPayload.msg`.
52
+ */
53
+ exports.RMakerLocalCtrlMsgType = void 0;
54
+ (function (RMakerLocalCtrlMsgType) {
55
+ RMakerLocalCtrlMsgType[RMakerLocalCtrlMsgType["TypeCmdGetData"] = 0] = "TypeCmdGetData";
56
+ RMakerLocalCtrlMsgType[RMakerLocalCtrlMsgType["TypeRespGetData"] = 1] = "TypeRespGetData";
57
+ })(exports.RMakerLocalCtrlMsgType || (exports.RMakerLocalCtrlMsgType = {}));
58
+ /** Tag bytes written by the request encoder: `(fieldNumber << 3) | wireType`. */
59
+ const TAG_FIELD_1_VARINT = 0x08;
60
+ const TAG_FIELD_2_VARINT = 0x10;
61
+ const TAG_FIELD_10_BYTES = 0x52;
62
+ const WIRE_TYPE_VARINT = 0;
63
+ const WIRE_TYPE_BYTES = 2;
64
+ /**
65
+ * Encoder/decoder for `rmaker_local_ctrl` frames.
66
+ */
67
+ class RMakerLocalCtrlProtoHelper {
68
+ /**
69
+ * Builds a `CmdGetData` request for one fragment.
70
+ *
71
+ * An `offset` of 0 makes the device (re)generate and cache the document;
72
+ * subsequent offsets are served from that cache.
73
+ *
74
+ * @param dataType - Document to read.
75
+ * @param offset - Byte offset to read from.
76
+ * @returns The serialized request.
77
+ */
78
+ static createGetDataRequest(dataType, offset) {
79
+ const cmdGetData = this.concat([
80
+ // Both fields are written explicitly, including their proto3 zero values,
81
+ // matching how the reference clients frame this command.
82
+ new Uint8Array([TAG_FIELD_1_VARINT]),
83
+ this.encodeVarint(dataType),
84
+ new Uint8Array([TAG_FIELD_2_VARINT]),
85
+ this.encodeVarint(offset),
86
+ ]);
87
+ return this.concat([
88
+ new Uint8Array([TAG_FIELD_1_VARINT]),
89
+ this.encodeVarint(exports.RMakerLocalCtrlMsgType.TypeCmdGetData),
90
+ new Uint8Array([TAG_FIELD_10_BYTES]),
91
+ this.encodeVarint(cmdGetData.length),
92
+ cmdGetData,
93
+ ]);
94
+ }
95
+ /**
96
+ * Parses a `RespGetData` frame from the device.
97
+ *
98
+ * @param data - Raw response bytes.
99
+ * @returns The parsed payload. Absent fields keep their proto3 defaults.
100
+ */
101
+ static parseGetDataResponse(data) {
102
+ const result = {
103
+ msg: exports.RMakerLocalCtrlMsgType.TypeCmdGetData,
104
+ };
105
+ let index = 0;
106
+ while (index < data.length) {
107
+ const tag = data[index++];
108
+ const fieldNumber = tag >> 3;
109
+ const wireType = tag & 0x07;
110
+ if (fieldNumber === 1 && wireType === WIRE_TYPE_VARINT) {
111
+ const { value, newIndex } = this.readVarint(data, index);
112
+ result.msg = value;
113
+ index = newIndex;
114
+ continue;
115
+ }
116
+ if (fieldNumber === 11 && wireType === WIRE_TYPE_BYTES) {
117
+ const { value: length, newIndex } = this.readVarint(data, index);
118
+ result.respGetData = this.parseRespGetData(data.slice(newIndex, newIndex + length));
119
+ index = newIndex + length;
120
+ continue;
121
+ }
122
+ index = this.skipField(data, index, wireType);
123
+ }
124
+ return result;
125
+ }
126
+ /**
127
+ * Whether the device reported a successful read.
128
+ *
129
+ * @param response - Parsed response.
130
+ */
131
+ static isSuccess(response) {
132
+ return response.respGetData?.status === exports.RMakerLocalCtrlStatus.Success;
133
+ }
134
+ /**
135
+ * Returns the device's status as its enum name, for diagnostics.
136
+ *
137
+ * @param response - Parsed response.
138
+ * @returns The status name, or `"Unknown"` when absent.
139
+ */
140
+ static getStatus(response) {
141
+ const status = response.respGetData?.status;
142
+ return status === undefined
143
+ ? "Unknown"
144
+ : (exports.RMakerLocalCtrlStatus[status] ?? `Unknown(${status})`);
145
+ }
146
+ /**
147
+ * Offset the device answered with, which must match the requested offset.
148
+ *
149
+ * @param response - Parsed response.
150
+ */
151
+ static getOffset(response) {
152
+ return response.respGetData?.buf?.offset ?? 0;
153
+ }
154
+ /**
155
+ * Full document length reported by the device.
156
+ *
157
+ * @param response - Parsed response.
158
+ */
159
+ static getTotalLen(response) {
160
+ return response.respGetData?.buf?.totalLen ?? 0;
161
+ }
162
+ /**
163
+ * Fragment bytes carried by the response.
164
+ *
165
+ * @param response - Parsed response.
166
+ */
167
+ static getPayload(response) {
168
+ return response.respGetData?.buf?.payload ?? new Uint8Array(0);
169
+ }
170
+ // Private helper methods
171
+ static concat(parts) {
172
+ const totalLength = parts.reduce((sum, part) => sum + part.length, 0);
173
+ const result = new Uint8Array(totalLength);
174
+ let pos = 0;
175
+ for (const part of parts) {
176
+ result.set(part, pos);
177
+ pos += part.length;
178
+ }
179
+ return result;
180
+ }
181
+ static encodeVarint(value) {
182
+ const bytes = [];
183
+ let remaining = value;
184
+ while (remaining > 127) {
185
+ bytes.push((remaining & 0x7f) | 0x80);
186
+ remaining >>>= 7;
187
+ }
188
+ bytes.push(remaining & 0x7f);
189
+ return new Uint8Array(bytes);
190
+ }
191
+ static readVarint(data, index) {
192
+ let value = 0;
193
+ let shift = 0;
194
+ let byte;
195
+ do {
196
+ byte = data[index++];
197
+ value |= (byte & 0x7f) << shift;
198
+ shift += 7;
199
+ } while (byte & 0x80);
200
+ return { value, newIndex: index };
201
+ }
202
+ /** Advances past a field this codec does not read. */
203
+ static skipField(data, index, wireType) {
204
+ if (wireType === WIRE_TYPE_VARINT) {
205
+ return this.readVarint(data, index).newIndex;
206
+ }
207
+ if (wireType === WIRE_TYPE_BYTES) {
208
+ const { value: length, newIndex } = this.readVarint(data, index);
209
+ return newIndex + length;
210
+ }
211
+ return index + 1;
212
+ }
213
+ static parseRespGetData(data) {
214
+ // In proto3 an absent status defaults to 0, i.e. Success.
215
+ const result = { status: exports.RMakerLocalCtrlStatus.Success };
216
+ let index = 0;
217
+ while (index < data.length) {
218
+ const tag = data[index++];
219
+ const fieldNumber = tag >> 3;
220
+ const wireType = tag & 0x07;
221
+ if (fieldNumber === 1 && wireType === WIRE_TYPE_VARINT) {
222
+ const { value, newIndex } = this.readVarint(data, index);
223
+ result.status = value;
224
+ index = newIndex;
225
+ continue;
226
+ }
227
+ if (fieldNumber === 2 && wireType === WIRE_TYPE_BYTES) {
228
+ const { value: length, newIndex } = this.readVarint(data, index);
229
+ result.buf = this.parsePayloadBuf(data.slice(newIndex, newIndex + length));
230
+ index = newIndex + length;
231
+ continue;
232
+ }
233
+ index = this.skipField(data, index, wireType);
234
+ }
235
+ return result;
236
+ }
237
+ static parsePayloadBuf(data) {
238
+ const result = {
239
+ offset: 0,
240
+ payload: new Uint8Array(0),
241
+ totalLen: 0,
242
+ };
243
+ let index = 0;
244
+ while (index < data.length) {
245
+ const tag = data[index++];
246
+ const fieldNumber = tag >> 3;
247
+ const wireType = tag & 0x07;
248
+ if (fieldNumber === 1 && wireType === WIRE_TYPE_VARINT) {
249
+ const { value, newIndex } = this.readVarint(data, index);
250
+ result.offset = value;
251
+ index = newIndex;
252
+ continue;
253
+ }
254
+ if (fieldNumber === 2 && wireType === WIRE_TYPE_BYTES) {
255
+ const { value: length, newIndex } = this.readVarint(data, index);
256
+ result.payload = data.slice(newIndex, newIndex + length);
257
+ index = newIndex + length;
258
+ continue;
259
+ }
260
+ if (fieldNumber === 3 && wireType === WIRE_TYPE_VARINT) {
261
+ const { value, newIndex } = this.readVarint(data, index);
262
+ result.totalLen = value;
263
+ index = newIndex;
264
+ continue;
265
+ }
266
+ index = this.skipField(data, index, wireType);
267
+ }
268
+ return result;
269
+ }
270
+ }
271
+
272
+ exports.RMakerLocalCtrlProtoHelper = RMakerLocalCtrlProtoHelper;
273
+ //# sourceMappingURL=rmaker_local_ctrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rmaker_local_ctrl.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -14,9 +14,10 @@ var constants = require('../../../utils/constants.js');
14
14
  * adapter (see {@link ESPRMNeoBase.setLocalDiscoveryAdapter}).
15
15
  *
16
16
  * - With no discovery config, the default local protocol is used
17
- * (mDNS service `_esp_local_ctrl._tcp.` in the `local` domain).
18
- * - A custom {@link DiscoveryParamsInterface} can be supplied for other
19
- * discovery protocols.
17
+ * (mDNS service `_esp_rmaker_ctrl._tcp.` in the `local` domain — the
18
+ * service advertised by RainMaker Neo firmware).
19
+ * - A custom {@link DiscoveryParamsInterface} can be supplied to browse any
20
+ * other service type.
20
21
  */
21
22
  class ESPDiscoveryManager {
22
23
  /** Discovery parameters (service type / domain) passed to the adapter. */
@@ -31,7 +32,7 @@ class ESPDiscoveryManager {
31
32
  throw new Error("ESPLocalDiscoveryAdapter not set");
32
33
  }
33
34
  this.params = discoveryConfig || {
34
- serviceType: constants.ServiceType.ESP_LOCAL_CTRL_TCP,
35
+ serviceType: constants.ServiceType.ESP_RMAKER_LOCAL_CTRL_TCP,
35
36
  domain: discovery.ESPDiscoveryProtocol.local,
36
37
  };
37
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ESPDiscoveryManager.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ESPDiscoveryManager.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}