@robotical/raftjs 2.1.0 → 2.1.3
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/devdocs/devbin-backwards-compatibility.md +105 -0
- package/devdocs/pseudocode-to-js-transpiler.md +563 -0
- package/dist/react-native/PseudocodeTranspiler.d.ts +6 -0
- package/dist/react-native/PseudocodeTranspiler.js +115 -0
- package/dist/react-native/PseudocodeTranspiler.js.map +1 -0
- package/dist/react-native/RaftAttributeHandler.d.ts +1 -1
- package/dist/react-native/RaftAttributeHandler.js +108 -32
- package/dist/react-native/RaftAttributeHandler.js.map +1 -1
- package/dist/react-native/RaftChannelBLE.web.d.ts +4 -0
- package/dist/react-native/RaftChannelBLE.web.js +59 -21
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -1
- package/dist/react-native/RaftChannelSimulated.d.ts +1 -0
- package/dist/react-native/RaftChannelSimulated.js +9 -5
- package/dist/react-native/RaftChannelSimulated.js.map +1 -1
- package/dist/react-native/RaftChannelWebSocket.js +16 -1
- package/dist/react-native/RaftChannelWebSocket.js.map +1 -1
- package/dist/react-native/RaftConnector.d.ts +29 -1
- package/dist/react-native/RaftConnector.js +177 -11
- package/dist/react-native/RaftConnector.js.map +1 -1
- package/dist/react-native/RaftCustomAttrHandler.d.ts +2 -2
- package/dist/react-native/RaftCustomAttrHandler.js +32 -44
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -1
- package/dist/react-native/RaftDeviceInfo.d.ts +18 -0
- package/dist/react-native/RaftDeviceInfo.js +8 -0
- package/dist/react-native/RaftDeviceInfo.js.map +1 -1
- package/dist/react-native/RaftDeviceManager.d.ts +30 -3
- package/dist/react-native/RaftDeviceManager.js +618 -107
- package/dist/react-native/RaftDeviceManager.js.map +1 -1
- package/dist/react-native/RaftDeviceMgrIF.d.ts +11 -2
- package/dist/react-native/RaftDeviceStates.d.ts +27 -3
- package/dist/react-native/RaftDeviceStates.js +31 -6
- package/dist/react-native/RaftDeviceStates.js.map +1 -1
- package/dist/react-native/RaftFileHandler.d.ts +1 -1
- package/dist/react-native/RaftFileHandler.js +101 -34
- package/dist/react-native/RaftFileHandler.js.map +1 -1
- package/dist/react-native/RaftMicroPythonConsoleClient.d.ts +38 -0
- package/dist/react-native/RaftMicroPythonConsoleClient.js +45 -0
- package/dist/react-native/RaftMicroPythonConsoleClient.js.map +1 -0
- package/dist/react-native/RaftMsgHandler.d.ts +1 -1
- package/dist/react-native/RaftMsgHandler.js +6 -3
- package/dist/react-native/RaftMsgHandler.js.map +1 -1
- package/dist/react-native/RaftPublish.d.ts +2 -0
- package/dist/react-native/RaftPublish.js +81 -0
- package/dist/react-native/RaftPublish.js.map +1 -0
- package/dist/react-native/RaftStreamHandler.d.ts +11 -0
- package/dist/react-native/RaftStreamHandler.js +66 -0
- package/dist/react-native/RaftStreamHandler.js.map +1 -1
- package/dist/react-native/RaftStruct.d.ts +2 -2
- package/dist/react-native/RaftStruct.js +97 -26
- package/dist/react-native/RaftStruct.js.map +1 -1
- package/dist/react-native/RaftSystemType.d.ts +1 -0
- package/dist/react-native/RaftSystemUtils.d.ts +17 -1
- package/dist/react-native/RaftSystemUtils.js +51 -0
- package/dist/react-native/RaftSystemUtils.js.map +1 -1
- package/dist/react-native/RaftTimezone.d.ts +16 -0
- package/dist/react-native/RaftTimezone.js +153 -0
- package/dist/react-native/RaftTimezone.js.map +1 -0
- package/dist/react-native/RaftTypes.d.ts +46 -1
- package/dist/react-native/RaftTypes.js.map +1 -1
- package/dist/react-native/RaftUpdateManager.js +1 -1
- package/dist/react-native/RaftUpdateManager.js.map +1 -1
- package/dist/react-native/main.d.ts +3 -0
- package/dist/react-native/main.js +8 -1
- package/dist/react-native/main.js.map +1 -1
- package/dist/web/PseudocodeTranspiler.d.ts +6 -0
- package/dist/web/PseudocodeTranspiler.js +115 -0
- package/dist/web/PseudocodeTranspiler.js.map +1 -0
- package/dist/web/RaftAttributeHandler.d.ts +1 -1
- package/dist/web/RaftAttributeHandler.js +108 -32
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannelBLE.web.d.ts +4 -0
- package/dist/web/RaftChannelBLE.web.js +59 -21
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/web/RaftChannelSimulated.d.ts +1 -0
- package/dist/web/RaftChannelSimulated.js +9 -5
- package/dist/web/RaftChannelSimulated.js.map +1 -1
- package/dist/web/RaftChannelWebSocket.js +16 -1
- package/dist/web/RaftChannelWebSocket.js.map +1 -1
- package/dist/web/RaftConnector.d.ts +29 -1
- package/dist/web/RaftConnector.js +177 -11
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftCustomAttrHandler.d.ts +2 -2
- package/dist/web/RaftCustomAttrHandler.js +32 -44
- package/dist/web/RaftCustomAttrHandler.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +18 -0
- package/dist/web/RaftDeviceInfo.js +8 -0
- package/dist/web/RaftDeviceInfo.js.map +1 -1
- package/dist/web/RaftDeviceManager.d.ts +30 -3
- package/dist/web/RaftDeviceManager.js +618 -107
- package/dist/web/RaftDeviceManager.js.map +1 -1
- package/dist/web/RaftDeviceMgrIF.d.ts +11 -2
- package/dist/web/RaftDeviceStates.d.ts +27 -3
- package/dist/web/RaftDeviceStates.js +31 -6
- package/dist/web/RaftDeviceStates.js.map +1 -1
- package/dist/web/RaftFileHandler.d.ts +1 -1
- package/dist/web/RaftFileHandler.js +101 -34
- package/dist/web/RaftFileHandler.js.map +1 -1
- package/dist/web/RaftMicroPythonConsoleClient.d.ts +38 -0
- package/dist/web/RaftMicroPythonConsoleClient.js +45 -0
- package/dist/web/RaftMicroPythonConsoleClient.js.map +1 -0
- package/dist/web/RaftMsgHandler.d.ts +1 -1
- package/dist/web/RaftMsgHandler.js +6 -3
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftPublish.d.ts +2 -0
- package/dist/web/RaftPublish.js +81 -0
- package/dist/web/RaftPublish.js.map +1 -0
- package/dist/web/RaftStreamHandler.d.ts +11 -0
- package/dist/web/RaftStreamHandler.js +66 -0
- package/dist/web/RaftStreamHandler.js.map +1 -1
- package/dist/web/RaftStruct.d.ts +2 -2
- package/dist/web/RaftStruct.js +97 -26
- package/dist/web/RaftStruct.js.map +1 -1
- package/dist/web/RaftSystemType.d.ts +1 -0
- package/dist/web/RaftSystemUtils.d.ts +17 -1
- package/dist/web/RaftSystemUtils.js +51 -0
- package/dist/web/RaftSystemUtils.js.map +1 -1
- package/dist/web/RaftTimezone.d.ts +16 -0
- package/dist/web/RaftTimezone.js +153 -0
- package/dist/web/RaftTimezone.js.map +1 -0
- package/dist/web/RaftTypes.d.ts +46 -1
- package/dist/web/RaftTypes.js.map +1 -1
- package/dist/web/RaftUpdateManager.js +1 -1
- package/dist/web/RaftUpdateManager.js.map +1 -1
- package/dist/web/main.d.ts +3 -0
- package/dist/web/main.js +8 -1
- package/dist/web/main.js.map +1 -1
- package/examples/dashboard/package.json +2 -2
- package/examples/dashboard/src/DeviceActionsForm.tsx +177 -17
- package/examples/dashboard/src/DeviceLineChart.tsx +16 -3
- package/examples/dashboard/src/DevicePanel.tsx +92 -11
- package/examples/dashboard/src/DeviceSelectDialog.tsx +224 -0
- package/examples/dashboard/src/DeviceStatsPanel.tsx +76 -0
- package/examples/dashboard/src/DevicesPanel.tsx +11 -0
- package/examples/dashboard/src/LogConfigPanel.tsx +357 -0
- package/examples/dashboard/src/LogFilesPanel.tsx +200 -0
- package/examples/dashboard/src/LoggingPanel.tsx +264 -0
- package/examples/dashboard/src/Main.tsx +12 -2
- package/examples/dashboard/src/SettingsScreen.tsx +9 -4
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +10 -3
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +37 -3
- package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +10 -2
- package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +41 -7
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +34 -3
- package/examples/dashboard/src/styles.css +766 -1
- package/notes/web-ble-reconnect-retry.md +69 -0
- package/package.json +10 -7
- package/src/PseudocodeTranspiler.test.ts +372 -0
- package/src/PseudocodeTranspiler.ts +127 -0
- package/src/RaftAttributeHandler.ts +152 -76
- package/src/RaftChannelBLE.web.ts +62 -20
- package/src/RaftChannelSimulated.ts +10 -5
- package/src/RaftChannelWebSocket.ts +16 -2
- package/src/RaftConnector.ts +204 -17
- package/src/RaftCustomAttrHandler.ts +35 -45
- package/src/RaftDeviceInfo.ts +27 -0
- package/src/RaftDeviceManager.test.ts +164 -0
- package/src/RaftDeviceManager.ts +705 -127
- package/src/RaftDeviceMgrIF.ts +13 -2
- package/src/RaftDeviceStates.ts +49 -8
- package/src/RaftFileHandler.ts +112 -39
- package/src/RaftMicroPythonConsoleClient.ts +78 -0
- package/src/RaftMsgHandler.ts +8 -4
- package/src/RaftPublish.ts +92 -0
- package/src/RaftStreamHandler.ts +84 -1
- package/src/RaftStruct.test.ts +229 -0
- package/src/RaftStruct.ts +101 -37
- package/src/RaftSystemType.ts +1 -0
- package/src/RaftSystemUtils.ts +59 -0
- package/src/RaftTimezone.ts +151 -0
- package/src/RaftTypes.ts +57 -1
- package/src/RaftUpdateManager.ts +1 -1
- package/src/main.ts +3 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { DeviceManager } from "./RaftDeviceManager";
|
|
2
|
+
import { DeviceTypeInfo } from "./RaftDeviceInfo";
|
|
3
|
+
import RaftSystemUtils from "./RaftSystemUtils";
|
|
4
|
+
|
|
5
|
+
function makeTypeInfo(name: string, respBytes: number, attrs: Array<{ n: string; t: string }>): DeviceTypeInfo {
|
|
6
|
+
return {
|
|
7
|
+
name,
|
|
8
|
+
desc: name,
|
|
9
|
+
manu: "Robotical",
|
|
10
|
+
type: name,
|
|
11
|
+
resp: {
|
|
12
|
+
b: respBytes,
|
|
13
|
+
a: attrs.map(attr => ({ ...attr, u: "", r: [0, 0] }))
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function makeDeviceManager(typeInfos: Record<string, DeviceTypeInfo>): Promise<DeviceManager> {
|
|
19
|
+
const msgHandler = {
|
|
20
|
+
sendRICRESTURL: jest.fn(async (cmd: string) => {
|
|
21
|
+
const deviceType = new URLSearchParams(cmd.split("?")[1]).get("type");
|
|
22
|
+
const devinfo = deviceType ? typeInfos[deviceType] : undefined;
|
|
23
|
+
return devinfo ? { rslt: "ok", devinfo } : { rslt: "fail" };
|
|
24
|
+
})
|
|
25
|
+
};
|
|
26
|
+
const systemUtils = {
|
|
27
|
+
getMsgHandler: () => msgHandler,
|
|
28
|
+
getPublishTopicName: () => "devbin"
|
|
29
|
+
} as unknown as RaftSystemUtils;
|
|
30
|
+
|
|
31
|
+
const deviceManager = new DeviceManager();
|
|
32
|
+
await deviceManager.setup(systemUtils);
|
|
33
|
+
return deviceManager;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("DeviceManager binary devbin parsing", () => {
|
|
37
|
+
const accelInfo = makeTypeInfo("MXC400xXC", 7, [
|
|
38
|
+
{ n: "x", t: ">h" },
|
|
39
|
+
{ n: "y", t: ">h" },
|
|
40
|
+
{ n: "z", t: ">h" },
|
|
41
|
+
{ n: "status", t: "B" }
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
it("decodes current length-prefixed records", async () => {
|
|
45
|
+
const deviceManager = await makeDeviceManager({ "4": accelInfo });
|
|
46
|
+
const rxMsg = Uint8Array.from([
|
|
47
|
+
0x00, 0x80,
|
|
48
|
+
0xDB, 0xFF, 0x00,
|
|
49
|
+
0x00, 0x12,
|
|
50
|
+
0x81,
|
|
51
|
+
0x00, 0x00, 0x00, 0x15,
|
|
52
|
+
0x00, 0x04,
|
|
53
|
+
0x05,
|
|
54
|
+
0x09,
|
|
55
|
+
0x00, 0x01,
|
|
56
|
+
0x00, 0x01,
|
|
57
|
+
0x00, 0x02,
|
|
58
|
+
0x00, 0x03,
|
|
59
|
+
0x04
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
await deviceManager.handleClientMsgBinary(rxMsg);
|
|
63
|
+
|
|
64
|
+
const deviceState = deviceManager.getDeviceState("1_15");
|
|
65
|
+
expect(deviceState.deviceType).toBe("MXC400xXC");
|
|
66
|
+
expect(deviceState.deviceTimeline.totalSamplesAdded).toBe(1);
|
|
67
|
+
expect(deviceState.deviceAttributes.x.values).toEqual([1]);
|
|
68
|
+
expect(deviceState.deviceAttributes.y.values).toEqual([2]);
|
|
69
|
+
expect(deviceState.deviceAttributes.z.values).toEqual([3]);
|
|
70
|
+
expect(deviceState.deviceAttributes.status.values).toEqual([4]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("decodes Cog v1.9.5 legacy raw accelerometer records", async () => {
|
|
74
|
+
const deviceManager = await makeDeviceManager({ "4": accelInfo });
|
|
75
|
+
const rxMsg = Uint8Array.from([
|
|
76
|
+
0x00, 0x80,
|
|
77
|
+
0x00, 0x10,
|
|
78
|
+
0x81,
|
|
79
|
+
0x00, 0x00, 0x00, 0x15,
|
|
80
|
+
0x00, 0x04,
|
|
81
|
+
0x00, 0x01,
|
|
82
|
+
0x00, 0x01,
|
|
83
|
+
0x00, 0x02,
|
|
84
|
+
0x00, 0x03,
|
|
85
|
+
0x04
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
await deviceManager.handleClientMsgBinary(rxMsg);
|
|
89
|
+
|
|
90
|
+
const deviceState = deviceManager.getDeviceState("1_15");
|
|
91
|
+
expect(deviceState.deviceType).toBe("MXC400xXC");
|
|
92
|
+
expect(deviceState.deviceTimeline.totalSamplesAdded).toBe(1);
|
|
93
|
+
expect(deviceState.deviceAttributes.x.values).toEqual([1]);
|
|
94
|
+
expect(deviceState.deviceAttributes.y.values).toEqual([2]);
|
|
95
|
+
expect(deviceState.deviceAttributes.z.values).toEqual([3]);
|
|
96
|
+
expect(deviceState.deviceAttributes.status.values).toEqual([4]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("decodes Cog v1.9.5 legacy raw records inside a devbin envelope", async () => {
|
|
100
|
+
const deviceManager = await makeDeviceManager({ "4": accelInfo });
|
|
101
|
+
const rxMsg = Uint8Array.from([
|
|
102
|
+
0x00, 0x80,
|
|
103
|
+
0xDB, 0xFF, 0x00,
|
|
104
|
+
0x00, 0x10,
|
|
105
|
+
0x81,
|
|
106
|
+
0x00, 0x00, 0x00, 0x15,
|
|
107
|
+
0x00, 0x04,
|
|
108
|
+
0x00, 0x01,
|
|
109
|
+
0x00, 0x01,
|
|
110
|
+
0x00, 0x02,
|
|
111
|
+
0x00, 0x03,
|
|
112
|
+
0x04
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
await deviceManager.handleClientMsgBinary(rxMsg);
|
|
116
|
+
|
|
117
|
+
const deviceState = deviceManager.getDeviceState("1_15");
|
|
118
|
+
expect(deviceState.deviceType).toBe("MXC400xXC");
|
|
119
|
+
expect(deviceState.deviceTimeline.totalSamplesAdded).toBe(1);
|
|
120
|
+
expect(deviceState.deviceAttributes.x.values).toEqual([1]);
|
|
121
|
+
expect(deviceState.deviceAttributes.y.values).toEqual([2]);
|
|
122
|
+
expect(deviceState.deviceAttributes.z.values).toEqual([3]);
|
|
123
|
+
expect(deviceState.deviceAttributes.status.values).toEqual([4]);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("keeps Cog v1.9.5 direct device records distinct when bus and address are both zero", async () => {
|
|
127
|
+
const lightInfo = makeTypeInfo("LightSensors", 16, [
|
|
128
|
+
{ n: "ch0", t: ">H" },
|
|
129
|
+
{ n: "ch1", t: ">H" },
|
|
130
|
+
{ n: "ch2", t: ">H" },
|
|
131
|
+
{ n: "ch3", t: ">H" }
|
|
132
|
+
]);
|
|
133
|
+
const powerInfo = makeTypeInfo("Power", 1, [
|
|
134
|
+
{ n: "battery", t: "B" }
|
|
135
|
+
]);
|
|
136
|
+
const deviceManager = await makeDeviceManager({ "2": lightInfo, "3": powerInfo });
|
|
137
|
+
const rxMsg = Uint8Array.from([
|
|
138
|
+
0x00, 0x80,
|
|
139
|
+
0x00, 0x11,
|
|
140
|
+
0x80,
|
|
141
|
+
0x00, 0x00, 0x00, 0x00,
|
|
142
|
+
0x00, 0x02,
|
|
143
|
+
0x00, 0x01,
|
|
144
|
+
0x00, 0x0a,
|
|
145
|
+
0x00, 0x0b,
|
|
146
|
+
0x00, 0x0c,
|
|
147
|
+
0x00, 0x0d,
|
|
148
|
+
0x00, 0x0a,
|
|
149
|
+
0x80,
|
|
150
|
+
0x00, 0x00, 0x00, 0x00,
|
|
151
|
+
0x00, 0x03,
|
|
152
|
+
0x00, 0x02,
|
|
153
|
+
0x63
|
|
154
|
+
]);
|
|
155
|
+
|
|
156
|
+
await deviceManager.handleClientMsgBinary(rxMsg);
|
|
157
|
+
|
|
158
|
+
const devicesState = deviceManager.getDevicesState();
|
|
159
|
+
expect(devicesState["0_0_2"].deviceType).toBe("LightSensors");
|
|
160
|
+
expect(devicesState["0_0_2"].deviceAttributes.ch0.values).toEqual([10]);
|
|
161
|
+
expect(devicesState["0_0_3"].deviceType).toBe("Power");
|
|
162
|
+
expect(devicesState["0_0_3"].deviceAttributes.battery.values).toEqual([99]);
|
|
163
|
+
});
|
|
164
|
+
});
|