@robotical/raftjs 2.1.3 → 2.1.4

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 (30) hide show
  1. package/devdocs/decode-overrun-investigation.md +167 -0
  2. package/devdocs/message-panel-design.md +320 -0
  3. package/dist/react-native/RaftAttributeHandler.d.ts +10 -1
  4. package/dist/react-native/RaftAttributeHandler.js +60 -8
  5. package/dist/react-native/RaftAttributeHandler.js.map +1 -1
  6. package/dist/react-native/RaftChannelSimulated.d.ts +1 -0
  7. package/dist/react-native/RaftChannelSimulated.js +67 -0
  8. package/dist/react-native/RaftChannelSimulated.js.map +1 -1
  9. package/dist/react-native/RaftDeviceInfo.d.ts +5 -1
  10. package/dist/react-native/RaftDeviceManager.js +75 -32
  11. package/dist/react-native/RaftDeviceManager.js.map +1 -1
  12. package/dist/web/RaftAttributeHandler.d.ts +10 -1
  13. package/dist/web/RaftAttributeHandler.js +60 -8
  14. package/dist/web/RaftAttributeHandler.js.map +1 -1
  15. package/dist/web/RaftChannelSimulated.d.ts +1 -0
  16. package/dist/web/RaftChannelSimulated.js +67 -0
  17. package/dist/web/RaftChannelSimulated.js.map +1 -1
  18. package/dist/web/RaftDeviceInfo.d.ts +5 -1
  19. package/dist/web/RaftDeviceManager.js +75 -32
  20. package/dist/web/RaftDeviceManager.js.map +1 -1
  21. package/examples/dashboard/src/DeviceActionsForm.tsx +3 -0
  22. package/examples/dashboard/src/DeviceLineChart.tsx +5 -4
  23. package/examples/dashboard/src/DevicePanel.tsx +3 -0
  24. package/package.json +1 -1
  25. package/src/RaftAttributeHandler.ts +89 -9
  26. package/src/RaftChannelSimulated.test.ts +62 -0
  27. package/src/RaftChannelSimulated.ts +91 -0
  28. package/src/RaftDeviceInfo.ts +5 -1
  29. package/src/RaftDeviceManager.test.ts +35 -1
  30. package/src/RaftDeviceManager.ts +86 -33
@@ -403,8 +403,14 @@ export class DeviceManager implements RaftDeviceMgrIF{
403
403
  // Check if a device state already exists
404
404
  if (!(deviceKey in this._devicesState) || (this._devicesState[deviceKey].deviceTypeInfo === undefined)) {
405
405
 
406
- // Get the device type info
407
- const deviceTypeInfo = resolvedDeviceTypeInfo ?? await this.getDeviceTypeInfo(busNum.toString(), devTypeIdx.toString());
406
+ // Merge rationale: upstream's deviceid lookup carries
407
+ // per-instance name/role fields, while Robotical's simulator
408
+ // and older firmware still expose bus/type lookup. Try the
409
+ // richer endpoint first and fall back to the type record that
410
+ // was already loaded for payload-format detection.
411
+ const deviceTypeInfo = await this.getDeviceTypeInfo(deviceKey)
412
+ ?? resolvedDeviceTypeInfo
413
+ ?? await this.getDeviceTypeInfo(busNum.toString(), devTypeIdx.toString());
408
414
 
409
415
  // Debug
410
416
  // console.log(`DevMan.handleClientMsgBinary debugIdx ${debugMsgIndex} pollDataPos ${pollDataPos} busNum ${busNum} devAddr 0x${devAddr.toString(16)} devTypeIdx ${devTypeIdx} deviceTypeInfo ${JSON.stringify(deviceTypeInfo)}`);
@@ -482,11 +488,21 @@ export class DeviceManager implements RaftDeviceMgrIF{
482
488
 
483
489
  const sampleStartPos = pollDataPos;
484
490
  const sampleEndPos = pollDataPos + sampleLen;
491
+ // Merge rationale: keep Robotical's explicit sample
492
+ // boundary and add upstream diagnostics so malformed
493
+ // samples can be skipped with useful context.
485
494
  const newMsgBufIdx = this._attributeHandler.processMsgAttrGroup(rxMsg, sampleStartPos,
486
495
  deviceState.deviceTimeline, pollRespMetadata,
487
496
  deviceState.deviceAttributes,
488
497
  this._maxDatapointsToStore,
489
- sampleEndPos);
498
+ sampleEndPos,
499
+ {
500
+ deviceKey,
501
+ deviceType: deviceState.deviceType,
502
+ debugMsgIndex,
503
+ sampleStartIdx: sampleStartPos,
504
+ sampleEndIdx: sampleEndPos,
505
+ });
490
506
 
491
507
  if (newMsgBufIdx < 0)
492
508
  {
@@ -515,11 +531,21 @@ export class DeviceManager implements RaftDeviceMgrIF{
515
531
  while (pollDataPos + legacySampleLen <= samplesEndPos) {
516
532
  const sampleStartPos = pollDataPos;
517
533
  const sampleEndPos = pollDataPos + legacySampleLen;
534
+ // Legacy raw records are not length-prefixed, but
535
+ // the fixed sample span gives the same bound and
536
+ // diagnostic context to the attribute handler.
518
537
  const newMsgBufIdx = this._attributeHandler.processMsgAttrGroup(rxMsg, sampleStartPos,
519
538
  deviceState.deviceTimeline, pollRespMetadata,
520
539
  deviceState.deviceAttributes,
521
540
  this._maxDatapointsToStore,
522
- sampleEndPos);
541
+ sampleEndPos,
542
+ {
543
+ deviceKey,
544
+ deviceType: deviceState.deviceType,
545
+ debugMsgIndex,
546
+ sampleStartIdx: sampleStartPos,
547
+ sampleEndIdx: sampleEndPos,
548
+ });
523
549
 
524
550
  if (newMsgBufIdx < 0)
525
551
  {
@@ -632,8 +658,11 @@ export class DeviceManager implements RaftDeviceMgrIF{
632
658
  // Check if a device state already exists
633
659
  if (!(deviceKey in this._devicesState) || (this._devicesState[deviceKey].deviceTypeInfo === undefined)) {
634
660
 
635
- // Get the device type info
636
- const deviceTypeInfo = await this.getDeviceTypeInfo(busName, deviceTypeName);
661
+ // Prefer upstream's per-instance deviceid endpoint, but
662
+ // keep Robotical's bus/type fallback for simulated and
663
+ // older JSON publishers.
664
+ const deviceTypeInfo = await this.getDeviceTypeInfo(deviceKey)
665
+ ?? await this.getDeviceTypeInfo(busName, deviceTypeName);
637
666
 
638
667
  // Check if device record exists
639
668
  if (deviceKey in this._devicesState) {
@@ -802,71 +831,87 @@ export class DeviceManager implements RaftDeviceMgrIF{
802
831
  // Get device type info
803
832
  ////////////////////////////////////////////////////////////////////////////
804
833
 
805
- private async getDeviceTypeInfo(busName: string, deviceType: string): Promise<DeviceTypeInfo | undefined> {
834
+ private async getDeviceTypeInfo(deviceKey: string): Promise<DeviceTypeInfo | undefined>;
835
+ private async getDeviceTypeInfo(busName: string, deviceType: string): Promise<DeviceTypeInfo | undefined>;
836
+ private async getDeviceTypeInfo(deviceKeyOrBusName: string, deviceType?: string): Promise<DeviceTypeInfo | undefined> {
837
+ const cacheKey = deviceType === undefined ? deviceKeyOrBusName : deviceType;
838
+ const requestLabel = deviceType === undefined ? `deviceKey ${deviceKeyOrBusName}` : `deviceType ${deviceType}`;
839
+
806
840
  // Check if already in cache
807
- if (deviceType in this._cachedDeviceTypeRecs) {
808
- return this._cachedDeviceTypeRecs[deviceType];
841
+ if (cacheKey in this._cachedDeviceTypeRecs) {
842
+ return this._cachedDeviceTypeRecs[cacheKey];
809
843
  }
810
844
 
811
- // Check if there's already a pending request for this device type
812
- if (deviceType in this._pendingDeviceTypeRequests) {
813
- // console.log(`DevMan.getDeviceTypeInfo joining existing request queue for deviceType ${deviceType}`);
814
-
845
+ // Check if there's already a pending request for this device/type
846
+ if (cacheKey in this._pendingDeviceTypeRequests) {
815
847
  // Add this request to the waiting queue
816
848
  return new Promise<DeviceTypeInfo | undefined>((resolve, reject) => {
817
- this._pendingDeviceTypeRequests[deviceType].waitingQueue.push({ resolve, reject });
849
+ this._pendingDeviceTypeRequests[cacheKey].waitingQueue.push({ resolve, reject });
818
850
  });
819
851
  }
820
852
 
821
853
  // Check rate limiting for new requests
822
- if (deviceType in this._cachedDeviceTypePreviousAttemptTimes) {
823
- const timeSinceLastAttempt = Date.now() - this._cachedDeviceTypePreviousAttemptTimes[deviceType];
854
+ if (cacheKey in this._cachedDeviceTypePreviousAttemptTimes) {
855
+ const timeSinceLastAttempt = Date.now() - this._cachedDeviceTypePreviousAttemptTimes[cacheKey];
824
856
  if (timeSinceLastAttempt < this._minTimeBetweenDeviceTypeInfoRetrievalMs) {
825
- console.log(`DevMan.getDeviceTypeInfo rate limited for deviceType ${deviceType}`);
857
+ console.log(`DevMan.getDeviceTypeInfo rate limited for ${requestLabel}`);
826
858
  return undefined;
827
859
  }
828
860
  }
829
861
 
830
862
  // Create and cache the promise with an empty waiting queue
831
- const requestPromise = this.executeDeviceTypeInfoRequest(busName, deviceType);
832
- this._pendingDeviceTypeRequests[deviceType] = {
863
+ const requestPromise = this.executeDeviceTypeInfoRequest(deviceKeyOrBusName, deviceType);
864
+ this._pendingDeviceTypeRequests[cacheKey] = {
833
865
  promise: requestPromise,
834
866
  waitingQueue: []
835
867
  };
836
868
 
837
869
  try {
838
870
  const result = await requestPromise;
839
-
871
+
840
872
  // Resolve all waiting requests with the same result
841
- const waitingQueue = this._pendingDeviceTypeRequests[deviceType].waitingQueue;
873
+ const waitingQueue = this._pendingDeviceTypeRequests[cacheKey].waitingQueue;
842
874
  waitingQueue.forEach(({ resolve }) => resolve(result));
843
-
875
+
844
876
  return result;
845
877
  } catch (error) {
846
878
  // Reject all waiting requests with the same error
847
- const waitingQueue = this._pendingDeviceTypeRequests[deviceType].waitingQueue;
879
+ const waitingQueue = this._pendingDeviceTypeRequests[cacheKey].waitingQueue;
848
880
  waitingQueue.forEach(({ reject }) => reject(error));
849
-
850
- console.warn(`DevMan.getDeviceTypeInfo failed for ${deviceType}: ${error}`);
881
+
882
+ console.warn(`DevMan.getDeviceTypeInfo failed for ${requestLabel}: ${error}`);
851
883
  return undefined;
852
884
  } finally {
853
885
  // Clean up the pending request
854
- delete this._pendingDeviceTypeRequests[deviceType];
886
+ delete this._pendingDeviceTypeRequests[cacheKey];
855
887
  }
856
888
  }
857
889
 
858
- private async executeDeviceTypeInfoRequest(busName: string, deviceType: string): Promise<DeviceTypeInfo | undefined> {
859
- this._cachedDeviceTypePreviousAttemptTimes[deviceType] = Date.now();
860
-
890
+ private async executeDeviceTypeInfoRequest(deviceKeyOrBusName: string, deviceType?: string): Promise<DeviceTypeInfo | undefined> {
891
+ const cacheKey = deviceType === undefined ? deviceKeyOrBusName : deviceType;
892
+ this._cachedDeviceTypePreviousAttemptTimes[cacheKey] = Date.now();
893
+
861
894
  try {
862
- const cmd = "devman/typeinfo?bus=" + busName + "&type=" + deviceType;
895
+ // Merge rationale: support both upstream's per-device endpoint and
896
+ // Robotical's older bus/type endpoint. The deviceid response may
897
+ // include instance-specific name/role; the bus/type response keeps
898
+ // simulators and older firmware working.
899
+ const cmd = deviceType === undefined
900
+ ? "devman/typeinfo?deviceid=" + deviceKeyOrBusName
901
+ : "devman/typeinfo?bus=" + deviceKeyOrBusName + "&type=" + deviceType;
863
902
  const msgHandler = this._systemUtils?.getMsgHandler();
864
-
903
+
865
904
  if (msgHandler) {
866
905
  const msgRslt = await msgHandler.sendRICRESTURL<RaftDevTypeInfoResponse>(cmd);
867
906
  if (msgRslt && msgRslt.rslt === "ok") {
868
- this._cachedDeviceTypeRecs[deviceType] = msgRslt.devinfo;
869
- return msgRslt.devinfo;
907
+ // Merge devinfo (type-level) with top-level per-instance overrides (name, role)
908
+ const base: DeviceTypeInfo = msgRslt.devinfo
909
+ ? { ...msgRslt.devinfo }
910
+ : { name: "", desc: "", manu: "", type: "" };
911
+ if (msgRslt.name !== undefined) base.name = msgRslt.name;
912
+ if (msgRslt.role !== undefined) base.role = msgRslt.role;
913
+ this._cachedDeviceTypeRecs[cacheKey] = base;
914
+ return base;
870
915
  }
871
916
  }
872
917
  return undefined;
@@ -964,10 +1009,14 @@ export class DeviceManager implements RaftDeviceMgrIF{
964
1009
  }
965
1010
 
966
1011
  let attrPayloadLen = 0;
1012
+ let usesAbsolutePositions = false;
967
1013
  for (const attrDef of pollRespMetadata.a) {
968
1014
  if (!attrDef.t) {
969
1015
  return pollRespMetadata.b;
970
1016
  }
1017
+ if (attrDef.at !== undefined) {
1018
+ usesAbsolutePositions = true;
1019
+ }
971
1020
  try {
972
1021
  attrPayloadLen += structSizeOf(attrDef.t);
973
1022
  } catch {
@@ -975,6 +1024,10 @@ export class DeviceManager implements RaftDeviceMgrIF{
975
1024
  }
976
1025
  }
977
1026
 
1027
+ if (usesAbsolutePositions && pollRespMetadata.b > 0) {
1028
+ return pollRespMetadata.b;
1029
+ }
1030
+
978
1031
  // Cog v1.9.5 light metadata reports the direct-sensor payload size doubled,
979
1032
  // but the legacy raw record contains one fixed payload matching the attribute schema.
980
1033
  if ((attrPayloadLen > 0) && (pollRespMetadata.b > 0) && (attrPayloadLen <= pollRespMetadata.b)) {