@adcops/autocore-react 3.0.40 → 3.3.2
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/additional-docs/AutoCoreTagContext.md +441 -0
- package/additional-docs/react_performance_notes.md +94 -0
- package/dist/assets/BlocklyLogo.d.ts +1 -0
- package/dist/assets/BlocklyLogo.d.ts.map +1 -0
- package/dist/assets/Distance.d.ts +1 -0
- package/dist/assets/Distance.d.ts.map +1 -0
- package/dist/assets/JogLong.d.ts +1 -0
- package/dist/assets/JogLong.d.ts.map +1 -0
- package/dist/assets/JogMedium.d.ts +1 -0
- package/dist/assets/JogMedium.d.ts.map +1 -0
- package/dist/assets/JogShort.d.ts +1 -0
- package/dist/assets/JogShort.d.ts.map +1 -0
- package/dist/assets/PythonLogo.d.ts +1 -0
- package/dist/assets/PythonLogo.d.ts.map +1 -0
- package/dist/assets/Rotation3D.d.ts +1 -0
- package/dist/assets/Rotation3D.d.ts.map +1 -0
- package/dist/assets/RotationCcw.d.ts +1 -0
- package/dist/assets/RotationCcw.d.ts.map +1 -0
- package/dist/assets/RotationCcwA.d.ts +1 -0
- package/dist/assets/RotationCcwA.d.ts.map +1 -0
- package/dist/assets/RotationCcwB.d.ts +1 -0
- package/dist/assets/RotationCcwB.d.ts.map +1 -0
- package/dist/assets/RotationCcwC.d.ts +1 -0
- package/dist/assets/RotationCcwC.d.ts.map +1 -0
- package/dist/assets/RotationCw.d.ts +1 -0
- package/dist/assets/RotationCw.d.ts.map +1 -0
- package/dist/assets/RotationCwA.d.ts +1 -0
- package/dist/assets/RotationCwA.d.ts.map +1 -0
- package/dist/assets/RotationCwB.d.ts +1 -0
- package/dist/assets/RotationCwB.d.ts.map +1 -0
- package/dist/assets/RotationCwC.d.ts +1 -0
- package/dist/assets/RotationCwC.d.ts.map +1 -0
- package/dist/assets/Run.d.ts +1 -0
- package/dist/assets/Run.d.ts.map +1 -0
- package/dist/assets/Speed.d.ts +1 -0
- package/dist/assets/Speed.d.ts.map +1 -0
- package/dist/assets/SpeedFast.d.ts +1 -0
- package/dist/assets/SpeedFast.d.ts.map +1 -0
- package/dist/assets/SpeedMedium.d.ts +1 -0
- package/dist/assets/SpeedMedium.d.ts.map +1 -0
- package/dist/assets/SpeedNone.d.ts +1 -0
- package/dist/assets/SpeedNone.d.ts.map +1 -0
- package/dist/assets/SpeedSlow.d.ts +1 -0
- package/dist/assets/SpeedSlow.d.ts.map +1 -0
- package/dist/assets/Walk.d.ts +1 -0
- package/dist/assets/Walk.d.ts.map +1 -0
- package/dist/assets/index.d.ts +1 -0
- package/dist/assets/index.d.ts.map +1 -0
- package/dist/components/AutoCoreDevPanel.d.ts +144 -0
- package/dist/components/AutoCoreDevPanel.d.ts.map +1 -0
- package/dist/components/AutoCoreDevPanel.js +1 -0
- package/dist/components/BlocklyEditor.d.ts +1 -0
- package/dist/components/BlocklyEditor.d.ts.map +1 -0
- package/dist/components/BlocklyEditor.js +1 -1
- package/dist/components/CodeEditor.d.ts +2 -1
- package/dist/components/CodeEditor.d.ts.map +1 -0
- package/dist/components/CodeEditor.js +1 -1
- package/dist/components/FileList.d.ts +1 -0
- package/dist/components/FileList.d.ts.map +1 -0
- package/dist/components/FileList.js +1 -1
- package/dist/components/FileSelect.d.ts +1 -0
- package/dist/components/FileSelect.d.ts.map +1 -0
- package/dist/components/FileSelect.js +1 -1
- package/dist/components/FitText.d.ts +1 -0
- package/dist/components/FitText.d.ts.map +1 -0
- package/dist/components/FitText.js +1 -1
- package/dist/components/Indicator.d.ts +2 -1
- package/dist/components/Indicator.d.ts.map +1 -0
- package/dist/components/Indicator.js +1 -1
- package/dist/components/IndicatorButton.d.ts +2 -1
- package/dist/components/IndicatorButton.d.ts.map +1 -0
- package/dist/components/IndicatorButton.js +1 -1
- package/dist/components/IndicatorRect.d.ts +2 -1
- package/dist/components/IndicatorRect.d.ts.map +1 -0
- package/dist/components/JogPanel.d.ts +1 -0
- package/dist/components/JogPanel.d.ts.map +1 -0
- package/dist/components/Lamp.d.ts +2 -1
- package/dist/components/Lamp.d.ts.map +1 -0
- package/dist/components/Lamp.js +1 -1
- package/dist/components/Osk.d.ts +1 -0
- package/dist/components/Osk.d.ts.map +1 -0
- package/dist/components/Osk.js +1 -1
- package/dist/components/OskDialog.d.ts +1 -0
- package/dist/components/OskDialog.d.ts.map +1 -0
- package/dist/components/ProgressBarWithValue.d.ts +1 -0
- package/dist/components/ProgressBarWithValue.d.ts.map +1 -0
- package/dist/components/ProgressBarWithValue.js +1 -1
- package/dist/components/TextInput.d.ts +62 -103
- package/dist/components/TextInput.d.ts.map +1 -0
- package/dist/components/TextInput.js +1 -1
- package/dist/components/ToggleGroup.d.ts +2 -1
- package/dist/components/ToggleGroup.d.ts.map +1 -0
- package/dist/components/ToggleGroup.js +1 -1
- package/dist/components/ValueDisplay.d.ts +3 -2
- package/dist/components/ValueDisplay.d.ts.map +1 -0
- package/dist/components/ValueDisplay.js +1 -1
- package/dist/components/ValueIndicator.d.ts +2 -1
- package/dist/components/ValueIndicator.d.ts.map +1 -0
- package/dist/components/ValueIndicator.js +1 -1
- package/dist/components/ValueInput.d.ts +2 -1
- package/dist/components/ValueInput.d.ts.map +1 -0
- package/dist/components/ValueInput.js +1 -1
- package/dist/core/ActionMode.d.ts +1 -0
- package/dist/core/ActionMode.d.ts.map +1 -0
- package/dist/core/AutoCoreTagContext.d.ts +98 -0
- package/dist/core/AutoCoreTagContext.d.ts.map +1 -0
- package/dist/core/AutoCoreTagContext.js +1 -0
- package/dist/core/AutoCoreTagTypes.d.ts +283 -0
- package/dist/core/AutoCoreTagTypes.d.ts.map +1 -0
- package/dist/core/AutoCoreTagTypes.js +1 -0
- package/dist/core/CoreStreamTypes.d.ts +345 -0
- package/dist/core/CoreStreamTypes.d.ts.map +1 -0
- package/dist/core/CoreStreamTypes.js +1 -0
- package/dist/core/EventEmitterContext.d.ts +113 -202
- package/dist/core/EventEmitterContext.d.ts.map +1 -0
- package/dist/core/EventEmitterContext.js +1 -1
- package/dist/core/IndicatorButtonState.d.ts +1 -0
- package/dist/core/IndicatorButtonState.d.ts.map +1 -0
- package/dist/core/IndicatorColor.d.ts +1 -0
- package/dist/core/IndicatorColor.d.ts.map +1 -0
- package/dist/core/MaskPatterns.d.ts +1 -0
- package/dist/core/MaskPatterns.d.ts.map +1 -0
- package/dist/core/NumerableTypes.d.ts +1 -0
- package/dist/core/NumerableTypes.d.ts.map +1 -0
- package/dist/core/NumerableTypes.js +1 -1
- package/dist/core/PositionContext.d.ts +1 -1
- package/dist/core/PositionContext.d.ts.map +1 -0
- package/dist/core/UniqueId.d.ts +1 -0
- package/dist/core/UniqueId.d.ts.map +1 -0
- package/dist/core/ValueSimulator.d.ts +2 -1
- package/dist/core/ValueSimulator.d.ts.map +1 -0
- package/dist/core/ValueSimulator.js +1 -1
- package/dist/core/hoc.d.ts +1 -0
- package/dist/core/hoc.d.ts.map +1 -0
- package/dist/core/hoc.js +1 -1
- package/dist/hooks/adsHooks.d.ts +1 -0
- package/dist/hooks/adsHooks.d.ts.map +1 -0
- package/dist/hooks/adsHooks.js +1 -1
- package/dist/hooks/commandHooks.d.ts +4 -3
- package/dist/hooks/commandHooks.d.ts.map +1 -0
- package/dist/hooks/commandHooks.js +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useAutoCoreTag.d.ts +26 -0
- package/dist/hooks/useAutoCoreTag.d.ts.map +1 -0
- package/dist/hooks/useAutoCoreTag.js +1 -0
- package/dist/hooks/useScaledValue.d.ts +1 -0
- package/dist/hooks/useScaledValue.d.ts.map +1 -0
- package/dist/hooks/useScaledValue.js +1 -1
- package/dist/hub/CommandMessage.d.ts +19 -9
- package/dist/hub/CommandMessage.d.ts.map +1 -0
- package/dist/hub/CommandMessage.js +1 -1
- package/dist/hub/DebugPanel.d.ts +31 -0
- package/dist/hub/DebugPanel.d.ts.map +1 -0
- package/dist/hub/DebugPanel.js +1 -0
- package/dist/hub/HubBase.d.ts +85 -130
- package/dist/hub/HubBase.d.ts.map +1 -0
- package/dist/hub/HubBase.js +1 -1
- package/dist/hub/HubSimulate.d.ts +42 -8
- package/dist/hub/HubSimulate.d.ts.map +1 -0
- package/dist/hub/HubSimulate.js +1 -1
- package/dist/hub/HubTauri.d.ts +25 -60
- package/dist/hub/HubTauri.d.ts.map +1 -0
- package/dist/hub/HubTauri.js +1 -1
- package/dist/hub/HubWebSocket.d.ts +34 -17
- package/dist/hub/HubWebSocket.d.ts.map +1 -0
- package/dist/hub/HubWebSocket.js +1 -1
- package/dist/hub/debug.d.ts +23 -0
- package/dist/hub/debug.d.ts.map +1 -0
- package/dist/hub/debug.js +1 -0
- package/dist/hub/index.d.ts +20 -4
- package/dist/hub/index.d.ts.map +1 -0
- package/dist/hub/index.js +1 -1
- package/package.json +32 -27
- package/readme.md +193 -22
- package/src/components/AutoCoreDevPanel.tsx +414 -0
- package/src/components/CodeEditor.tsx +2 -2
- package/src/components/FileList.tsx +7 -6
- package/src/components/FileSelect.tsx +2 -1
- package/src/components/Indicator.tsx +2 -2
- package/src/components/IndicatorButton.tsx +2 -2
- package/src/components/IndicatorRect.tsx +2 -2
- package/src/components/Lamp.tsx +3 -3
- package/src/components/TextInput.tsx +159 -240
- package/src/components/ToggleGroup.tsx +3 -3
- package/src/components/ValueDisplay.tsx +4 -4
- package/src/components/ValueIndicator.tsx +2 -2
- package/src/components/ValueInput.tsx +2 -2
- package/src/core/ActionMode.ts +1 -1
- package/src/core/AutoCoreTagContext.tsx +615 -0
- package/src/core/AutoCoreTagTypes.ts +334 -0
- package/src/core/CoreStreamTypes.ts +512 -0
- package/src/core/EventEmitterContext.tsx +257 -281
- package/src/core/IndicatorButtonState.ts +1 -1
- package/src/core/ValueSimulator.ts +2 -2
- package/src/core/hoc.tsx +1 -1
- package/src/hooks/adsHooks.tsx +21 -22
- package/src/hooks/commandHooks.tsx +23 -19
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useAutoCoreTag.ts +103 -0
- package/src/hooks/useScaledValue.tsx +1 -1
- package/src/hub/CommandMessage.ts +71 -19
- package/src/hub/DebugPanel.ts +280 -0
- package/src/hub/HubBase.ts +147 -223
- package/src/hub/HubSimulate.ts +93 -24
- package/src/hub/HubTauri.ts +87 -96
- package/src/hub/HubWebSocket.ts +133 -158
- package/src/hub/debug.ts +211 -0
- package/src/hub/index.ts +49 -39
- package/tsconfig.json +43 -28
- package/docs/classes/components_BlocklyEditor.BlocklyEditor.html +0 -124
- package/docs/classes/components_CodeEditor.CodeEditor.html +0 -128
- package/docs/classes/components_JogPanel.JogPanel.html +0 -138
- package/docs/classes/components_Lamp.Lamp.html +0 -105
- package/docs/classes/components_TextInput.TextInput.html +0 -115
- package/docs/classes/components_ValueIndicator.ValueIndicator.html +0 -119
- package/docs/classes/components_ValueInput.ValueInput.html +0 -113
- package/docs/classes/hub_HubWebSocket.HubWebSocket.html +0 -106
- package/docs/enums/components_JogPanel.JogDistanceAction.html +0 -5
- package/docs/enums/components_JogPanel.JogPanelAction.html +0 -18
- package/docs/enums/components_JogPanel.JogSpeedAction.html +0 -5
- package/docs/enums/core_ActionMode.ActionMode.html +0 -6
- package/docs/enums/core_IndicatorColor.IndicatorColor.html +0 -23
- package/docs/functions/assets_BlocklyLogo.default.html +0 -1
- package/docs/functions/assets_Distance.default.html +0 -1
- package/docs/functions/assets_JogLong.default.html +0 -1
- package/docs/functions/assets_JogMedium.default.html +0 -1
- package/docs/functions/assets_JogShort.default.html +0 -1
- package/docs/functions/assets_PythonLogo.default.html +0 -1
- package/docs/functions/assets_Rotation3D.default.html +0 -1
- package/docs/functions/assets_RotationCcw.default.html +0 -1
- package/docs/functions/assets_RotationCcwA.default.html +0 -1
- package/docs/functions/assets_RotationCcwB.default.html +0 -1
- package/docs/functions/assets_RotationCcwC.default.html +0 -1
- package/docs/functions/assets_RotationCw.default.html +0 -1
- package/docs/functions/assets_RotationCwA.default.html +0 -1
- package/docs/functions/assets_RotationCwB.default.html +0 -1
- package/docs/functions/assets_RotationCwC.default.html +0 -1
- package/docs/functions/assets_Run.default.html +0 -1
- package/docs/functions/assets_Speed.default.html +0 -1
- package/docs/functions/assets_SpeedFast.default.html +0 -1
- package/docs/functions/assets_SpeedMedium.default.html +0 -1
- package/docs/functions/assets_SpeedNone.default.html +0 -1
- package/docs/functions/assets_SpeedSlow.default.html +0 -1
- package/docs/functions/assets_Walk.default.html +0 -1
- package/docs/functions/components_BlocklyEditor.createCustomToolbox.html +0 -6
- package/docs/functions/components_FileList.FileList.html +0 -21
- package/docs/functions/components_FitText.FitText.html +0 -8
- package/docs/functions/components_ToggleGroup.ToggleGroup.html +0 -5
- package/docs/interfaces/components_JogPanel.JogPanelButtonDefinition.html +0 -5
- package/docs/interfaces/components_ToggleGroup.ToggleGroupProps.html +0 -618
- package/docs/interfaces/core_IndicatorButtonState.IndicatorButtonState.html +0 -10
- package/docs/interfaces/hub_CommandMessage.CommandMessage.html +0 -6
- package/docs/interfaces/hub_CommandMessage.CommandMessageResult.html +0 -4
- package/docs/modules/assets.html +0 -23
- package/docs/modules/assets_BlocklyLogo.html +0 -2
- package/docs/modules/assets_Distance.html +0 -2
- package/docs/modules/assets_JogLong.html +0 -2
- package/docs/modules/assets_JogMedium.html +0 -2
- package/docs/modules/assets_JogShort.html +0 -2
- package/docs/modules/assets_PythonLogo.html +0 -2
- package/docs/modules/assets_Rotation3D.html +0 -2
- package/docs/modules/assets_RotationCcw.html +0 -2
- package/docs/modules/assets_RotationCcwA.html +0 -2
- package/docs/modules/assets_RotationCcwB.html +0 -2
- package/docs/modules/assets_RotationCcwC.html +0 -2
- package/docs/modules/assets_RotationCw.html +0 -2
- package/docs/modules/assets_RotationCwA.html +0 -2
- package/docs/modules/assets_RotationCwB.html +0 -2
- package/docs/modules/assets_RotationCwC.html +0 -2
- package/docs/modules/assets_Run.html +0 -2
- package/docs/modules/assets_Speed.html +0 -2
- package/docs/modules/assets_SpeedFast.html +0 -2
- package/docs/modules/assets_SpeedMedium.html +0 -2
- package/docs/modules/assets_SpeedNone.html +0 -2
- package/docs/modules/assets_SpeedSlow.html +0 -2
- package/docs/modules/assets_Walk.html +0 -2
- package/docs/modules/components_BlocklyEditor.html +0 -5
- package/docs/modules/components_CodeEditor.html +0 -3
- package/docs/modules/components_FileList.html +0 -3
- package/docs/modules/components_FitText.html +0 -3
- package/docs/modules/components_JogPanel.html +0 -9
- package/docs/modules/components_Lamp.html +0 -4
- package/docs/modules/components_TextInput.html +0 -2
- package/docs/modules/components_ToggleGroup.html +0 -6
- package/docs/modules/components_ValueIndicator.html +0 -4
- package/docs/modules/components_ValueInput.html +0 -2
- package/docs/modules/core_ActionMode.html +0 -2
- package/docs/modules/core_IndicatorButtonState.html +0 -2
- package/docs/modules/core_IndicatorColor.html +0 -2
- package/docs/modules/hub_CommandMessage.html +0 -3
- package/docs/modules/hub_HubWebSocket.html +0 -2
- package/docs/types/components_IndicatorButton.IndicatorButtonOptionsType.html +0 -1
- package/docs/variables/components_BlocklyEditor.StandardToolbox.html +0 -1
- package/docs/variables/components_JogPanel.DefaultLinearJogButtons.html +0 -2
- package/docs/variables/components_JogPanel.DefaultRotationJogButtons.html +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAutoCoreTag.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutoCoreTag.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEzF,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,SAAS,SAAS,EAAE,EACpE,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAC3D,IAAI,EAAE,IAAI;8BAYc,CAAC,2CAA4B,CAAC;;;;;;;+BAyB7B,CAAC,4CAA6B,SAAS,CAAC,EAAE;4BAOrD,CAAC;;kCAY6B,CAAC;;;iCAUlB,CAAC,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,OAAO,mBAAM,CAAC,KAAK,CAAC,SAAQ,GAAG,EAAE;;;;;;;uCAW7C,MAAM;;EAKlD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:s=>{const{values:t,rawValues:u,isLoading:o,write:r,tap:n}=useContext(e),l=(e=>a.find(a=>a.fqdn===e))(s);if(!l)throw new Error(`useAutoCoreTag: unknown tagName '${String(s)}'`);const i=useCallback(e=>r(s,e),[r,s]),c=useCallback(()=>n?.(s),[n,s]);return{value:t[s],rawValue:u[s],write:i,tap:c,isLoading:o}},useAutoCoreTags:a=>{const{values:s,rawValues:t,isLoading:u,write:o}=useContext(e);return{values:useMemo(()=>Object.fromEntries(a.map(e=>[e,s[e]])),[s,a]),rawValues:useMemo(()=>Object.fromEntries(a.map(e=>[e,t[e]])),[t,a]),write:useCallback(async(e,a)=>{await o(e,a)},[o]),isLoading:u}},useAutoCoreSelect:(a,s=[])=>{const{values:t,isLoading:u}=useContext(e);return{selected:useMemo(()=>a(t),[t,...s]),isLoading:u}},useScales:()=>{const{scales:a,updateScale:s}=useContext(e),t=useCallback(e=>a[e],[a]);return{scales:a,updateScale:s,getScale:t}}}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScaledValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useScaledValue.tsx"],"names":[],"mappings":"AAaA;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAiB,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAG,MAAyB,CAAC;AAGzD,KAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,oBAAoB,CAoB5G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export const kNewtons2Pounds=1/4.4482216153;export function useScaledValue(e,t,s=0){const[u,c]=useState(e),[o,a]=useState((
|
|
1
|
+
import{useCallback,useState,useEffect}from"react";export const kMillimeters2Inches=1/25.4;export const kNewtons2Pounds=1/4.4482216153;export function useScaledValue(e,t,s=0){const[u,c]=useState(e),[o,a]=useState(()=>e*t+s);useEffect(()=>{a(u*t+s)},[u,t,s]);return[o,useCallback(e=>{c(e)},[t,s])]}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare enum MessageType {
|
|
2
|
+
NoOp = 0,
|
|
3
|
+
Response = 1,
|
|
4
|
+
Read = 2,
|
|
5
|
+
Write = 3,
|
|
6
|
+
Subscribe = 4,
|
|
7
|
+
Unsubscribe = 5,
|
|
8
|
+
Broadcast = 6,
|
|
9
|
+
Heartbeat = 7,
|
|
10
|
+
Control = 8,
|
|
11
|
+
Request = 10
|
|
5
12
|
}
|
|
6
13
|
export interface CommandMessage {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
transaction_id: number;
|
|
15
|
+
timecode: number;
|
|
16
|
+
topic: string;
|
|
17
|
+
message_type: MessageType;
|
|
18
|
+
data?: any;
|
|
19
|
+
success: boolean;
|
|
20
|
+
error_message: string;
|
|
12
21
|
}
|
|
22
|
+
//# sourceMappingURL=CommandMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommandMessage.d.ts","sourceRoot":"","sources":["../../src/hub/CommandMessage.ts"],"names":[],"mappings":"AAuBA,oBAAY,WAAW;IAEnB,IAAI,IAAI;IAGR,QAAQ,IAAI;IAGZ,IAAI,IAAI;IAGR,KAAK,IAAI;IAGT,SAAS,IAAI;IAGb,WAAW,IAAI;IAGf,SAAS,IAAI;IAGb,SAAS,IAAI;IAGb,OAAO,IAAI;IAGX,OAAO,KAAK;CACf;AAMD,MAAM,WAAW,cAAc;IAG3B,cAAc,EAAE,MAAM,CAAC;IAIvB,QAAQ,EAAE,MAAM,CAAC;IAKjB,KAAK,EAAE,MAAM,CAAC;IAGd,YAAY,EAAE,WAAW,CAAC;IAK1B,IAAI,CAAC,EAAE,GAAG,CAAC;IAIX,OAAO,EAAE,OAAO,CAAC;IAGjB,aAAa,EAAE,MAAM,CAAC;CAEzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export var MessageType;!function(e){e[e.NoOp=0]="NoOp",e[e.Response=1]="Response",e[e.Read=2]="Read",e[e.Write=3]="Write",e[e.Subscribe=4]="Subscribe",e[e.Unsubscribe=5]="Unsubscribe",e[e.Broadcast=6]="Broadcast",e[e.Heartbeat=7]="Heartbeat",e[e.Control=8]="Control",e[e.Request=10]="Request"}(MessageType||(MessageType={}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface DebugLog {
|
|
2
|
+
time: string;
|
|
3
|
+
type: "info" | "warn" | "error" | "send" | "recv";
|
|
4
|
+
source: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
declare class DebugPanel {
|
|
8
|
+
private container;
|
|
9
|
+
private logContainer;
|
|
10
|
+
private statsContainer;
|
|
11
|
+
private logs;
|
|
12
|
+
private maxLogs;
|
|
13
|
+
private stats;
|
|
14
|
+
constructor();
|
|
15
|
+
private injectPanel;
|
|
16
|
+
private setupElements;
|
|
17
|
+
private updateStats;
|
|
18
|
+
log(type: DebugLog["type"], source: string, message: string): void;
|
|
19
|
+
private renderLogs;
|
|
20
|
+
hubCreated(): void;
|
|
21
|
+
connectCalled(socketState: string): void;
|
|
22
|
+
wsOpened(url: string): void;
|
|
23
|
+
wsClosed(code: number, reason: string): void;
|
|
24
|
+
wsError(error: string): void;
|
|
25
|
+
messageSent(type: string, command: string, requestId: number): void;
|
|
26
|
+
messageReceived(type: string, command: string, requestId?: number): void;
|
|
27
|
+
updateState(state: string): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function getDebugPanel(): DebugPanel;
|
|
30
|
+
export default getDebugPanel;
|
|
31
|
+
//# sourceMappingURL=DebugPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebugPanel.d.ts","sourceRoot":"","sources":["../../src/hub/DebugPanel.ts"],"names":[],"mappings":"AAWA,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,cAAM,UAAU;IACd,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,OAAO,CAAO;IAGtB,OAAO,CAAC,KAAK,CASX;;IAOF,OAAO,CAAC,WAAW;IA2FnB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;IAsBnB,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAyBlE,OAAO,CAAC,UAAU;IAgBlB,UAAU,IAAI,IAAI;IAMlB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAOxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAO3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM5B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMnE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAMxE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjC;AAKD,wBAAgB,aAAa,IAAI,UAAU,CAO1C;AAKD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class DebugPanel{constructor(){Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"statsContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logs",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"maxLogs",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:{hubInstancesCreated:0,connectCalls:0,wsOpened:0,wsClosed:0,wsErrors:0,messagesSent:0,messagesReceived:0,currentState:"unknown"}}),this.injectPanel(),this.log("info","DebugPanel","Debug panel initialized")}injectPanel(){const e=document.getElementById("autocore-debug-panel");e&&e.remove(),this.container=document.createElement("div"),this.container.id="autocore-debug-panel",this.container.innerHTML='\n <style>\n #autocore-debug-panel {\n position: fixed;\n bottom: 10px;\n right: 10px;\n width: 400px;\n max-height: 300px;\n background: rgba(0, 0, 0, 0.9);\n color: #0f0;\n font-family: monospace;\n font-size: 11px;\n border: 1px solid #0f0;\n border-radius: 4px;\n z-index: 99999;\n overflow: hidden;\n }\n #autocore-debug-panel .header {\n background: #0f0;\n color: #000;\n padding: 4px 8px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n }\n #autocore-debug-panel .stats {\n padding: 4px 8px;\n border-bottom: 1px solid #0f0;\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 2px;\n }\n #autocore-debug-panel .stats span {\n color: #fff;\n }\n #autocore-debug-panel .stats .value {\n color: #ff0;\n }\n #autocore-debug-panel .logs {\n max-height: 180px;\n overflow-y: auto;\n padding: 4px;\n }\n #autocore-debug-panel .log-entry {\n margin: 1px 0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n #autocore-debug-panel .log-entry.info { color: #888; }\n #autocore-debug-panel .log-entry.warn { color: #fa0; }\n #autocore-debug-panel .log-entry.error { color: #f44; }\n #autocore-debug-panel .log-entry.send { color: #4f4; }\n #autocore-debug-panel .log-entry.recv { color: #44f; }\n #autocore-debug-panel .state-connected { color: #4f4 !important; }\n #autocore-debug-panel .state-disconnected { color: #f44 !important; }\n #autocore-debug-panel .state-connecting { color: #fa0 !important; }\n </style>\n <div class="header">\n <span>AutoCore Debug</span>\n <span id="debug-toggle">[_]</span>\n </div>\n <div id="debug-content">\n <div class="stats" id="debug-stats"></div>\n <div class="logs" id="debug-logs"></div>\n </div>\n ',document.body?(document.body.appendChild(this.container),this.setupElements()):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container),this.setupElements()})}setupElements(){this.statsContainer=document.getElementById("debug-stats"),this.logContainer=document.getElementById("debug-logs");const e=document.getElementById("debug-toggle"),t=document.getElementById("debug-content");e?.addEventListener("click",()=>{t&&(t.style.display="none"===t.style.display?"block":"none",e.textContent="none"===t.style.display?"[+]":"[_]")}),this.updateStats()}updateStats(){if(!this.statsContainer)return;const e="OPEN"===this.stats.currentState?"state-connected":"CONNECTING"===this.stats.currentState?"state-connecting":"state-disconnected";this.statsContainer.innerHTML=`\n <div><span>Hub Instances:</span> <span class="value">${this.stats.hubInstancesCreated}</span></div>\n <div><span>connect() calls:</span> <span class="value">${this.stats.connectCalls}</span></div>\n <div><span>WS Opened:</span> <span class="value">${this.stats.wsOpened}</span></div>\n <div><span>WS Closed:</span> <span class="value">${this.stats.wsClosed}</span></div>\n <div><span>WS Errors:</span> <span class="value">${this.stats.wsErrors}</span></div>\n <div><span>Msgs Sent:</span> <span class="value">${this.stats.messagesSent}</span></div>\n <div><span>Msgs Recv:</span> <span class="value">${this.stats.messagesReceived}</span></div>\n <div><span>WS State:</span> <span class="value ${e}">${this.stats.currentState}</span></div>\n `}log(e,t,n){const s=(new Date).toTimeString().slice(0,8),a={time:s,type:e,source:t,message:n};this.logs.push(a),this.logs.length>this.maxLogs&&this.logs.shift();this.renderLogs()}renderLogs(){this.logContainer&&(this.logContainer.innerHTML=this.logs.slice(-50).map(e=>`<div class="log-entry ${e.type}">[${e.time}] ${e.source}: ${e.message}</div>`).join(""),this.logContainer.scrollTop=this.logContainer.scrollHeight)}hubCreated(){this.stats.hubInstancesCreated++,this.log("warn","Hub",`NEW INSTANCE CREATED (total: ${this.stats.hubInstancesCreated})`),this.updateStats()}connectCalled(e){this.stats.connectCalls++,this.stats.currentState=e,this.log("info","Hub",`connect() called (socket state: ${e})`),this.updateStats()}wsOpened(e){this.stats.wsOpened++,this.stats.currentState="OPEN",this.log("info","WS",`OPENED: ${e}`),this.updateStats()}wsClosed(e,t){this.stats.wsClosed++,this.stats.currentState="CLOSED",this.log("warn","WS",`CLOSED: code=${e}, reason=${t}`),this.updateStats()}wsError(e){this.stats.wsErrors++,this.log("error","WS",`ERROR: ${e}`),this.updateStats()}messageSent(e,t,n){this.stats.messagesSent++,this.log("send","WS",`>>> ${e}/${t} (id=${n})`),this.updateStats()}messageReceived(e,t,n){this.stats.messagesReceived++,this.log("recv","WS",`<<< ${e}/${t} (id=${n??"none"})`),this.updateStats()}updateState(e){this.stats.currentState=e,this.updateStats()}}let debugPanel=null;export function getDebugPanel(){return debugPanel||(debugPanel=new DebugPanel,window.__AUTOCORE_DEBUG_PANEL__=debugPanel),debugPanel}getDebugPanel();export default getDebugPanel;
|
package/dist/hub/HubBase.d.ts
CHANGED
|
@@ -1,181 +1,136 @@
|
|
|
1
|
-
import { EventEmitterContextType } from '../core/EventEmitterContext';
|
|
2
|
-
import {
|
|
1
|
+
import type { EventEmitterContextType } from '../core/EventEmitterContext';
|
|
2
|
+
import type { CommandMessage } from "./CommandMessage";
|
|
3
|
+
import { MessageType } from "./CommandMessage";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* or something else.
|
|
5
|
+
* @class HubBase
|
|
6
|
+
* @abstract
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Abstract base class that defines the interface for communicating with the AutoCore backend.
|
|
9
|
+
* Implementations (like `HubWebSocket` or `HubTauri`) handle the specific transport mechanics.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
* The hub can be used to publish and subscribe to
|
|
12
|
-
* topics in the front-end, regardless of being connected to any backend.
|
|
11
|
+
* ## Core Responsibilities
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* return () => {
|
|
24
|
-
* unsubscribe(unsubscribeControlPower);
|
|
25
|
-
* }
|
|
26
|
-
* }, [] );
|
|
27
|
-
*
|
|
28
|
-
* const onPbPressed = () => {
|
|
29
|
-
* let count = 1;
|
|
30
|
-
* dispatch({
|
|
31
|
-
* topic: "my-awesome-topic",
|
|
32
|
-
* payload: count
|
|
33
|
-
* });
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* ```
|
|
37
|
-
* The hub should also be used for invoking events in the backend.
|
|
38
|
-
* This example will call the function "update_count" in the backend, passing
|
|
39
|
-
* the expected argument "count". Details of the interaction between the Hub and
|
|
40
|
-
* the backend will be handled by the appropriate HubBase sub-class, and should
|
|
41
|
-
* be transparent to the front end.
|
|
42
|
-
*
|
|
43
|
-
* ```
|
|
44
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
45
|
-
* const incrementCount = () => {
|
|
46
|
-
* count += 1;
|
|
47
|
-
* invoke('update_count', {"count": count});
|
|
48
|
-
* };
|
|
49
|
-
*
|
|
50
|
-
* Subscribing to a topic is simple. The type of value received is specific
|
|
51
|
-
* to the topic.
|
|
13
|
+
* 1. **Transport Abstraction**: Provides a unified API (`read`, `write`, `subscribe`) regardless of
|
|
14
|
+
* underlying transport (WS, IPC, etc.).
|
|
15
|
+
* 2. **Topic Mapping**: Maintains a bidirectional mapping between local `tagName` (UI friendly)
|
|
16
|
+
* and backend `FQDN` (Fully Qualified Domain Name).
|
|
17
|
+
* - `tagName`: "motorsEnable"
|
|
18
|
+
* - `FQDN`: "ADS.Main.bMotorsEnable"
|
|
19
|
+
* 3. **Event Dispatching**: Routes incoming messages from the backend to the `EventEmitterContext`.
|
|
52
20
|
*
|
|
53
|
-
*
|
|
54
|
-
* ```
|
|
55
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
56
|
-
* useEffect(() => {
|
|
57
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
58
|
-
* // The publisher sent a JSON object of 3D position values.
|
|
59
|
-
* setX(value.x);
|
|
60
|
-
* setY(value.y);
|
|
61
|
-
* setZ(value.z);
|
|
62
|
-
* setA(value.roll);
|
|
63
|
-
* setB(value.yaw);
|
|
64
|
-
* setC(value.pitch);
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* return () => {
|
|
68
|
-
* unsubscribe(unsubscripeMp);
|
|
69
|
-
* }
|
|
21
|
+
* ## Usage
|
|
70
22
|
*
|
|
71
|
-
*
|
|
23
|
+
* The `Hub` is typically accessed via the `EventEmitterContext`:
|
|
72
24
|
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const { hub } = useContext(EventEmitterContext);
|
|
27
|
+
* await hub.write("ADS.Main.nSpeed", 500);
|
|
73
28
|
* ```
|
|
74
|
-
*
|
|
75
29
|
*/
|
|
76
30
|
export declare abstract class HubBase {
|
|
31
|
+
/** Maps local tag names to backend FQDNs. */
|
|
77
32
|
protected localTopicToBackendTopicMap: Map<string, string>;
|
|
33
|
+
/** Maps backend FQDNs to local tag names. */
|
|
78
34
|
protected backendTopicToLocalMap: Map<string, string>;
|
|
79
|
-
|
|
80
|
-
protected backendFNameToLocalFNameMap: Map<string, string>;
|
|
35
|
+
/** Reference to the global event emitter for dispatching incoming messages. */
|
|
81
36
|
protected context: EventEmitterContextType | null;
|
|
37
|
+
/** Connection state tracker. */
|
|
82
38
|
protected isConnected_: boolean;
|
|
83
39
|
/**
|
|
84
40
|
* Constructor
|
|
85
41
|
*/
|
|
86
42
|
constructor();
|
|
87
43
|
/**
|
|
88
|
-
*
|
|
89
|
-
* should handle this as part of the initialization sequence. Because React can
|
|
90
|
-
* sometimes make (and destroy) multiple copies of the EventEmitterContext, it's important
|
|
91
|
-
* that the context be stored in the instance this way so that the HubBase can properly target
|
|
92
|
-
* right context.
|
|
44
|
+
* Links this Hub instance with the React application's Event Context.
|
|
93
45
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
46
|
+
* This connection allows the Hub to "push" messages into the React app by calling `context.dispatch()`.
|
|
47
|
+
* This is called automatically by `EventEmitterProvider` on initialization.
|
|
96
48
|
*
|
|
49
|
+
* @param context The React context instance.
|
|
97
50
|
*/
|
|
98
51
|
setContext(context: EventEmitterContextType | null): void;
|
|
99
52
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
53
|
+
* Sends a raw command message to the backend.
|
|
54
|
+
*
|
|
55
|
+
* @param topic The resource identifier (FQDN).
|
|
56
|
+
* @param messageType The operation to perform (Read, Write, etc.).
|
|
57
|
+
* @param payload The data payload.
|
|
58
|
+
* @returns A Promise that resolves with the server's response.
|
|
102
59
|
*/
|
|
103
|
-
abstract invoke(
|
|
60
|
+
abstract invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
|
|
104
61
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
62
|
+
* Request the current value of a resource.
|
|
63
|
+
*
|
|
64
|
+
* @param topic FQDN of the resource.
|
|
107
65
|
*/
|
|
108
|
-
|
|
66
|
+
read(topic: string, payload?: object): Promise<CommandMessage>;
|
|
109
67
|
/**
|
|
110
|
-
*
|
|
68
|
+
* Write a new value to a resource.
|
|
69
|
+
*
|
|
70
|
+
* @param topic FQDN of the resource.
|
|
71
|
+
* @param value The value to write.
|
|
111
72
|
*/
|
|
112
|
-
|
|
73
|
+
write(topic: string, value: any): Promise<CommandMessage>;
|
|
113
74
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
75
|
+
* Subscribe to updates for a specific resource.
|
|
76
|
+
*
|
|
77
|
+
* Registers a mapping so that when the server sends updates for `topic` (FQDN),
|
|
78
|
+
* the Hub will translate it to `tagName` before dispatching to the UI.
|
|
79
|
+
*
|
|
80
|
+
* @param tagName The local alias for this resource (e.g., "position").
|
|
81
|
+
* @param topic The backend FQDN (e.g., "ADS.Main.fPos").
|
|
82
|
+
* @param payload Optional subscription parameters (rate, deadband).
|
|
121
83
|
*/
|
|
122
|
-
|
|
84
|
+
subscribe(tagName: string, topic: string, payload?: object): Promise<CommandMessage>;
|
|
123
85
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
86
|
+
* Unsubscribe from updates.
|
|
87
|
+
*
|
|
88
|
+
* Uses the `tagName` to look up the FQDN and send the unsubscribe command.
|
|
89
|
+
* Also removes the local mapping.
|
|
90
|
+
*
|
|
91
|
+
* @param tagName The local alias to unsubscribe.
|
|
127
92
|
*/
|
|
128
|
-
|
|
93
|
+
unsubscribe(/* topic: string,*/ tagName: string, payload?: object): Promise<CommandMessage>;
|
|
129
94
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @param localTopic string
|
|
132
|
-
* @param backendTopic string
|
|
95
|
+
* Send a generic request (custom command).
|
|
133
96
|
*/
|
|
134
|
-
|
|
97
|
+
request(topic: string, payload?: object): Promise<CommandMessage>;
|
|
135
98
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @param localTopic string
|
|
99
|
+
* Update internal connection state.
|
|
138
100
|
*/
|
|
139
|
-
|
|
101
|
+
protected setIsConnected: (s: boolean) => void;
|
|
140
102
|
/**
|
|
141
|
-
*
|
|
142
|
-
* function name in the backend.
|
|
143
|
-
* @param localFName string
|
|
144
|
-
* @param backendFName string
|
|
103
|
+
* Check if currently connected to backend.
|
|
145
104
|
*/
|
|
146
|
-
|
|
105
|
+
isConnected: () => boolean;
|
|
147
106
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
107
|
+
* Dispatches an event to the React application.
|
|
108
|
+
*
|
|
109
|
+
* 1. Translates the `topic` (potentially an FQDN) to a local `tagName` if a mapping exists.
|
|
110
|
+
* 2. Calls `context.dispatch()` to notify local subscribers.
|
|
111
|
+
*
|
|
112
|
+
* This is the bridge between the backend transport and the frontend UI components.
|
|
113
|
+
*
|
|
114
|
+
* @param topic The topic from the message (usually FQDN).
|
|
115
|
+
* @param data The data payload.
|
|
150
116
|
*/
|
|
151
|
-
|
|
117
|
+
publish(topic: string, data: any | undefined): void;
|
|
152
118
|
/**
|
|
153
|
-
*
|
|
154
|
-
* registered, the local topic is returned.
|
|
155
|
-
* @param localTopic local topic name
|
|
156
|
-
* @returns string
|
|
119
|
+
* Registers a mapping between a local name and a backend FQDN.
|
|
157
120
|
*/
|
|
158
|
-
|
|
121
|
+
mapTopic(localTopic: string, backendTopic: string): void;
|
|
159
122
|
/**
|
|
160
|
-
*
|
|
161
|
-
* registered, the local FName is returned.
|
|
162
|
-
* @param localTopic local function name
|
|
163
|
-
* @returns string
|
|
123
|
+
* Removes a mapping.
|
|
164
124
|
*/
|
|
165
|
-
|
|
125
|
+
unmapTopic(localTopic: string): void;
|
|
166
126
|
/**
|
|
167
|
-
*
|
|
168
|
-
* registered, the backend topic is returned.
|
|
169
|
-
* @param backendTopic backend topic name
|
|
170
|
-
* @returns string
|
|
127
|
+
* Translates Local Name -> Backend FQDN.
|
|
171
128
|
*/
|
|
172
|
-
|
|
129
|
+
toBackendTopic(localTopic: string): string;
|
|
173
130
|
/**
|
|
174
|
-
*
|
|
175
|
-
* registered, the backend function name is returned.
|
|
176
|
-
* @param backendTopic backend function name
|
|
177
|
-
* @returns string
|
|
131
|
+
* Translates Backend FQDN -> Local Name.
|
|
178
132
|
*/
|
|
179
|
-
|
|
133
|
+
toLocalTopic(backendTopic: string): string;
|
|
180
134
|
}
|
|
181
135
|
export default HubBase;
|
|
136
|
+
//# sourceMappingURL=HubBase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubBase.d.ts","sourceRoot":"","sources":["../../src/hub/HubBase.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8BAAsB,OAAO;IAEzB,6CAA6C;IAC7C,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAEvF,6CAA6C;IAC7C,SAAS,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAElF,+EAA+E;IAC/E,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAQ;IAEzD,gCAAgC;IAChC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAS;IAGxC;;OAEG;;IAKH;;;;;;;OAOG;IACH,UAAU,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAQlD;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMnG;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9D;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAIzD;;;;;;;;;OASG;IACH,SAAS,CAAC,OAAO,EAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAKrF;;;;;;;OAOG;IACH,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAM7F;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQjE;;OAEG;IACH,SAAS,CAAC,cAAc,GAAI,GAAG,OAAO,UAErC;IAED;;OAEG;IACH,WAAW,QAAO,OAAO,CAExB;IAMD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAcnD;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAKxD;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAWpC;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAK1C;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAI7C;AAGD,eAAe,OAAO,CAAC"}
|
package/dist/hub/HubBase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"
|
|
1
|
+
import{MessageType}from"./CommandMessage";export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isConnected_",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"setIsConnected",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.isConnected_=e}}),Object.defineProperty(this,"isConnected",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.isConnected_})}setContext(e){this.context=e}read(e,t){return this.invoke(e,MessageType.Read,t)}write(e,t){return this.invoke(e,MessageType.Write,{value:t})}subscribe(e,t,i){return this.mapTopic(e,t),this.invoke(t,MessageType.Subscribe,i)}unsubscribe(e,t){const i=this.toBackendTopic(e);return this.unmapTopic(e),this.invoke(i,MessageType.Unsubscribe,t)}request(e,t){return this.invoke(e,MessageType.Request,t)}publish(e,t){const i=this.toLocalTopic(e);this.context?.dispatch({topic:i,payload:t})}mapTopic(e,t){this.localTopicToBackendTopicMap.set(e,t),this.backendTopicToLocalMap.set(t,e)}unmapTopic(e){if(this.localTopicToBackendTopicMap.has(e)){const t=this.localTopicToBackendTopicMap.get(e);this.localTopicToBackendTopicMap.delete(e),null!=t&&this.backendTopicToLocalMap.has(t)&&this.backendTopicToLocalMap.delete(t)}}toBackendTopic(e){return this.localTopicToBackendTopicMap.get(e)??e}toLocalTopic(e){return this.backendTopicToLocalMap.get(e)??e}}export default HubBase;
|
|
@@ -1,21 +1,55 @@
|
|
|
1
1
|
import { HubBase } from './HubBase';
|
|
2
|
-
import {
|
|
2
|
+
import type { CommandMessage } from "./CommandMessage";
|
|
3
|
+
import { MessageType } from "./CommandMessage";
|
|
3
4
|
/**
|
|
4
|
-
* Hub for simulating functionality when no backend is present.
|
|
5
|
+
* Hub for simulating backend functionality when no actual backend is present.
|
|
6
|
+
*
|
|
7
|
+
* Useful for development, testing, and demos without a running autocore-server.
|
|
8
|
+
* The simulator echoes back requests as successful responses after a configurable delay.
|
|
9
|
+
*
|
|
10
|
+
* ## Usage Examples
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { hub } = useContext(EventEmitterContext);
|
|
14
|
+
*
|
|
15
|
+
* // Read returns the topic as the "value"
|
|
16
|
+
* const result = await hub.read("ads.plc1.gio.bControlPowerOk");
|
|
17
|
+
* console.log(result.data); // { value: "ads.plc1.gio.bControlPowerOk" }
|
|
18
|
+
*
|
|
19
|
+
* // Write echoes back the written value
|
|
20
|
+
* await hub.write("ads.plc1.gio.nSetpoint", 100);
|
|
21
|
+
* ```
|
|
5
22
|
*/
|
|
6
23
|
export declare class HubSimulate extends HubBase {
|
|
24
|
+
private responseDelay;
|
|
7
25
|
/**
|
|
8
26
|
* Constructor
|
|
27
|
+
* @param responseDelay Simulated response delay in milliseconds (default: 20ms)
|
|
9
28
|
*/
|
|
10
|
-
constructor();
|
|
29
|
+
constructor(responseDelay?: number);
|
|
11
30
|
/**
|
|
12
|
-
*
|
|
31
|
+
* Simulate sending a message to a backend.
|
|
13
32
|
*
|
|
14
|
-
*
|
|
33
|
+
* For Read operations, returns the topic as the value.
|
|
34
|
+
* For Write operations, echoes back the payload.
|
|
35
|
+
* For all operations, returns a successful response after the configured delay.
|
|
36
|
+
*
|
|
37
|
+
* @param topic The FQDN of the resource
|
|
38
|
+
* @param messageType The action to perform
|
|
15
39
|
* @param payload Optional data payload
|
|
16
|
-
* @
|
|
17
|
-
|
|
40
|
+
* @returns Promise<CommandMessage> A simulated successful response
|
|
41
|
+
*/
|
|
42
|
+
invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
|
|
43
|
+
/**
|
|
44
|
+
* Simulate a broadcast from the "backend".
|
|
45
|
+
*
|
|
46
|
+
* This is useful for testing subscription handlers.
|
|
47
|
+
*
|
|
48
|
+
* @param topic The topic to broadcast on
|
|
49
|
+
* @param data The data to broadcast
|
|
50
|
+
* @param delay Optional delay before broadcasting (default: 0ms)
|
|
18
51
|
*/
|
|
19
|
-
|
|
52
|
+
simulateBroadcast(topic: string, data: any, delay?: number): void;
|
|
20
53
|
}
|
|
21
54
|
export default HubSimulate;
|
|
55
|
+
//# sourceMappingURL=HubSimulate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubSimulate.d.ts","sourceRoot":"","sources":["../../src/hub/HubSimulate.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAY,SAAQ,OAAO;IAEpC,OAAO,CAAC,aAAa,CAAS;IAE9B;;;OAGG;gBACS,aAAa,GAAE,MAAW;IAMtC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgD1F;;;;;;;;OAQG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,GAAE,MAAU,GAAG,IAAI;CAKvE;AAED,eAAe,WAAW,CAAC"}
|
package/dist/hub/HubSimulate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,s,
|
|
1
|
+
import{HubBase}from"./HubBase";import{MessageType}from"./CommandMessage";export class HubSimulate extends HubBase{constructor(e=20){super(),Object.defineProperty(this,"responseDelay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.responseDelay=e,this.setIsConnected(!0)}invoke(e,s,a){return new Promise(t=>{setTimeout(()=>{let r;switch(s){case MessageType.Read:r={value:e,simulated:!0};break;case MessageType.Write:r={written:!0,...a};break;case MessageType.Subscribe:r={subscribed:!0,topic:e};break;case MessageType.Unsubscribe:r={unsubscribed:!0,topic:e};break;default:r=a??{}}const i={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:r,success:!0,error_message:""};t(i)},this.responseDelay)})}simulateBroadcast(e,s,a=0){setTimeout(()=>{this.publish(e,s)},a)}}export default HubSimulate;
|
package/dist/hub/HubTauri.d.ts
CHANGED
|
@@ -1,75 +1,35 @@
|
|
|
1
1
|
import { HubBase } from './HubBase';
|
|
2
|
-
import {
|
|
2
|
+
import type { CommandMessage } from "./CommandMessage";
|
|
3
|
+
import { MessageType } from "./CommandMessage";
|
|
3
4
|
/**
|
|
4
5
|
* Hub for integrating with the Tauri backend.
|
|
5
6
|
*
|
|
6
|
-
* The
|
|
7
|
+
* The Tauri backend is expected to broadcast messages on the event
|
|
7
8
|
* name: 'autocore://broadcast_event'
|
|
8
9
|
*
|
|
9
10
|
* This hub will capture those messages and dispatch them globally to any
|
|
10
11
|
* listeners in the web app.
|
|
11
12
|
*
|
|
13
|
+
* ## Usage Examples
|
|
12
14
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
16
|
-
* useEffect(() => {
|
|
17
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
18
|
-
* // The rust backend sent a JSON object of 3D position values.
|
|
19
|
-
* setX(value.x);
|
|
20
|
-
* setY(value.y);
|
|
21
|
-
* setZ(value.z);
|
|
22
|
-
* setA(value.roll);
|
|
23
|
-
* setB(value.yaw);
|
|
24
|
-
* setC(value.pitch);
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* return () => {
|
|
28
|
-
* unsubscribe(unsubscripeMp);
|
|
29
|
-
* }
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const { hub } = useContext(EventEmitterContext);
|
|
30
17
|
*
|
|
31
|
-
*
|
|
18
|
+
* // Read a value
|
|
19
|
+
* const result = await hub.read("ads.plc1.gio.bControlPowerOk");
|
|
32
20
|
*
|
|
33
|
-
*
|
|
21
|
+
* // Write a value
|
|
22
|
+
* await hub.write("ads.plc1.gio.nSetpoint", 100);
|
|
34
23
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* the expected argument "count".
|
|
38
|
-
* ```
|
|
39
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
40
|
-
* const incrementCount = () => {
|
|
41
|
-
* count += 1;
|
|
42
|
-
* invoke('update_count', {"count": count});
|
|
43
|
-
* };
|
|
24
|
+
* // Subscribe to changes
|
|
25
|
+
* await hub.subscribe("modbus.holding_registers.5");
|
|
44
26
|
* ```
|
|
45
27
|
*
|
|
46
|
-
*
|
|
47
|
-
* topics in the front-end, without need of interacting with the Tauri backed.
|
|
28
|
+
* The hub can also publish/subscribe to frontend-only events:
|
|
48
29
|
*
|
|
30
|
+
* ```typescript
|
|
31
|
+
* hub.publish("ui/panel-opened", { panelId: "settings" });
|
|
49
32
|
* ```
|
|
50
|
-
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
51
|
-
* const [controlPower, setControlPower] = useState(false);
|
|
52
|
-
* useEffect(() => {
|
|
53
|
-
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
54
|
-
* setControlPower(value);
|
|
55
|
-
* });
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* return () => {
|
|
59
|
-
* unsubscribe(unsubscribeControlPower);
|
|
60
|
-
* }
|
|
61
|
-
* }, [] );
|
|
62
|
-
*
|
|
63
|
-
* const onPbPressed = () => {
|
|
64
|
-
* let count = 1;
|
|
65
|
-
* dispatch({
|
|
66
|
-
* topic: "my-awesome-topic",
|
|
67
|
-
* payload: count
|
|
68
|
-
* });
|
|
69
|
-
* }
|
|
70
|
-
*
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
33
|
*/
|
|
74
34
|
export declare class HubTauri extends HubBase {
|
|
75
35
|
/**
|
|
@@ -77,11 +37,16 @@ export declare class HubTauri extends HubBase {
|
|
|
77
37
|
*/
|
|
78
38
|
constructor();
|
|
79
39
|
/**
|
|
80
|
-
*
|
|
40
|
+
* Send a message to the Tauri backend.
|
|
41
|
+
*
|
|
42
|
+
* The topic and messageType are passed to a generic Tauri command handler
|
|
43
|
+
* that routes the request appropriately.
|
|
81
44
|
*
|
|
82
|
-
* @param
|
|
83
|
-
* @param
|
|
84
|
-
* @
|
|
45
|
+
* @param topic The FQDN of the resource (e.g., "ads.plc1.gio.bControlPowerOk")
|
|
46
|
+
* @param messageType The action to perform (Read, Write, Subscribe, etc.)
|
|
47
|
+
* @param payload Optional data payload (e.g., value to write)
|
|
48
|
+
* @returns Promise<CommandMessage> The response from the backend
|
|
85
49
|
*/
|
|
86
|
-
invoke(
|
|
50
|
+
invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
|
|
87
51
|
}
|
|
52
|
+
//# sourceMappingURL=HubTauri.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HubTauri.d.ts","sourceRoot":"","sources":["../../src/hub/HubTauri.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,QAAS,SAAQ,OAAO;IAEjC;;OAEG;;IA6BH;;;;;;;;;;OAUG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;CA8C7F"}
|
package/dist/hub/HubTauri.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";import{
|
|
1
|
+
import{HubBase}from"./HubBase";import{invoke as tauriInvoke}from"@tauri-apps/api/core";import{listen}from"@tauri-apps/api/event";import{MessageType}from"./CommandMessage";export class HubTauri extends HubBase{constructor(){super(),this.setIsConnected(!0),listen("autocore://broadcast_event",e=>{let o=JSON.parse(e.payload);void 0!==o.topic&&null!==o.topic&&(void 0!==o.payload&&null!==o.payload?this.publish(o.topic,o.payload):this.publish(o.topic,void 0))})}invoke(e,o,s){const t={topic:e,message_type:o,...s??{}};return new Promise((o,s)=>{tauriInvoke("autocore_invoke",t).then(s=>{if(s&&"object"==typeof s&&"topic"in s)o(s);else{const t={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:s,success:!0,error_message:""};o(t)}}).catch(o=>{const t={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:null,success:!1,error_message:o?.toString()||"Unknown error"};s(t)})})}}
|