Skip to content

Commit 18b9ad2

Browse files
committed
Gen device msg menus from yaml
1 parent f51ff40 commit 18b9ad2

14 files changed

+50
-56
lines changed

Diff for: .vitepress/config.mts

+38-51
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
1-
import { defineConfig } from 'vitepress'
2-
import { useSidebar } from 'vitepress-openapi'
3-
import { loadSpec } from '../swagger/load'
4-
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
5-
import { pagefindPlugin } from 'vitepress-plugin-pagefind'
1+
import path from 'path';
2+
import fs from 'fs';
3+
import yaml from 'js-yaml';
4+
import { defineConfig } from 'vitepress';
5+
import { useSidebar } from 'vitepress-openapi';
6+
import { loadSpec } from '../swagger/load';
7+
import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs';
8+
import { pagefindPlugin } from 'vitepress-plugin-pagefind';
69

7-
const sidebarSpec1 = useSidebar({ spec: loadSpec(1) })
8-
const sidebarSpec2 = useSidebar({ spec: loadSpec(2) })
10+
// Load protocol messages from YAML file
11+
const protocolYamlPath = path.resolve(__dirname, '../public/files/protocol-v3.yaml');
12+
const protocolYaml = fs.readFileSync(protocolYamlPath, 'utf8');
13+
const protocolData = yaml.load(protocolYaml);
14+
15+
// Generate menu items for protocol messages grouped by their respective groups
16+
const protocolMessages = protocolData.messages;
17+
const protocolGroups = protocolData.groups;
18+
const protocolMenuItems = Object.keys(protocolGroups)
19+
.filter(groupKey => !protocolGroups[groupKey].hidden)
20+
.map(groupKey => {
21+
const group = protocolGroups[groupKey];
22+
const items = Object.keys(protocolMessages)
23+
.filter(key => protocolMessages[key].group === groupKey)
24+
.map(key => ({
25+
text: `${key}: ${protocolMessages[key].name}`,
26+
link: `/devices/api/messages/${key}-${protocolMessages[key].name.toLowerCase().replace(/ /g, '-')}`
27+
}));
28+
return {
29+
text: group.name || groupKey,
30+
collapsed: true,
31+
items: items
32+
};
33+
});
34+
35+
const sidebarSpec1 = useSidebar({ spec: loadSpec(1) });
36+
const sidebarSpec2 = useSidebar({ spec: loadSpec(2) });
937

1038
// Function to make a sidebar group be collapsed
1139
function collapse(group) {
12-
group.collapsed = true
13-
return group
40+
group.collapsed = true;
41+
return group;
1442
}
1543

1644
function reorder(group: { items: { link: string }[] }, orderedLinks: string[]) {
@@ -224,48 +252,7 @@ export default defineConfig({
224252
{
225253
text: 'Messages',
226254
link: '/devices/api/messages/',
227-
items: [
228-
{
229-
text: 'Generic',
230-
collapsed: true,
231-
items: [
232-
{ text: '5: ACK', link: '/devices/api/messages/5-ack' },
233-
{ text: '6: Keepalive', link: '/devices/api/messages/6-keepalive' },
234-
]
235-
},
236-
{
237-
text: 'Device Services',
238-
collapsed: true,
239-
link: '/devices/api/messages/device-services',
240-
items: [
241-
{ text: '30: Transmit Now', link: '/devices/api/messages/30-device-transmit-now' },
242-
{ text: '31: GSM CFUN', link: '/devices/api/messages/31-device-gsm-cfun' },
243-
{ text: '32: GSM IMEI', link: '/devices/api/messages/32-device-gsm-imei' },
244-
{ text: '33: GSM ICCID', link: '/devices/api/messages/33-device-gsm-iccid' },
245-
{ text: '34: Status', link: '/devices/api/messages/34-device-status' },
246-
{ text: '35: ID', link: '/devices/api/messages/35-device-id' },
247-
{ text: '36: Time', link: '/devices/api/messages/36-device-time' },
248-
{ text: '37: Last Position', link: '/devices/api/messages/37-device-last-position' },
249-
{ text: '39: RTK', link: '/devices/api/messages/39-device-rtk' },
250-
{ text: '40: Haptics', link: '/devices/api/messages/40-device-haptics' },
251-
{ text: '41: Temperature', link: '/devices/api/messages/41-device-temperature' },
252-
{ text: '42: Buzzer', link: '/devices/api/messages/42-device-buzzer' },
253-
{ text: '44: Pressure', link: '/devices/api/messages/44-device-pressure' },
254-
]
255-
},
256-
{
257-
text: 'Device UX',
258-
collapsed: true,
259-
// link: '/devices/api/messages/device-ux',
260-
items: [
261-
{ text: '10009: Text Page', link: '/devices/api/messages/10009-ux-text-page' },
262-
{ text: '10010: Menu Page', link: '/devices/api/messages/10010-ux-menu-page' },
263-
{ text: '10011: Bitmap', link: '/devices/api/messages/10011-ux-bitmap' },
264-
{ text: '10013: Button Press', link: '/devices/api/messages/10013-ux-button-press' },
265-
{ text: '10014: Screen Refresh', link: '/devices/api/messages/10014-ux-screen-refresh' },
266-
]
267-
},
268-
]
255+
items: protocolMenuItems,
269256
},
270257
{
271258
text: 'Generate',
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: public/files/protocol-v3.yaml

+12-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ limits:
44
MAX_HEADER_FILED_LEN: 20 # As currently defined in Firmware
55
groups:
66
general:
7+
name: General
78
description: "General messages"
89
bootserver:
10+
hidden: true
11+
name: Bootserver
912
description: "Device to Boot server communication"
1013
livelink:
14+
hidden: true
15+
name: LiveLink
1116
description: "Device to LiveLink server communication"
1217
ondevice:
18+
name: Device Services
1319
description: "On device communication (between CPUs)"
1420
ondevice-ux:
21+
name: Device UX
1522
description: "On device communication (between CPUs), specifically for user interface and interactions"
1623
header:
1724
1:
@@ -72,7 +79,7 @@ header:
7279
name: "LORA Base Station"
7380
messages:
7481
5:
75-
name: "General ACK"
82+
name: "ACK"
7683
description: "General ACK message"
7784
group: "general"
7885
data:
@@ -85,7 +92,7 @@ messages:
8592
description: "ID of previous message being ACKed, if provided in the original message header"
8693
type: "uintn"
8794
6:
88-
name: "General Keep Alive"
95+
name: "Keep Alive"
8996
description: "General keep alive message"
9097
group: "general"
9198
10:
@@ -351,7 +358,7 @@ messages:
351358
# group: "ondevice-ux"
352359
10009:
353360
name: "UX Text Page"
354-
description: "UX text page"
361+
description: "Display or change a text page"
355362
group: "ondevice-ux"
356363
data:
357364
3:
@@ -380,8 +387,8 @@ messages:
380387
name: "Line 5"
381388
type: "ascii"
382389
10010:
383-
name: "UX Update Menu"
384-
description: "Update UX menu"
390+
name: "UX Menu Page"
391+
description: "Display or change a menu page"
385392
group: "ondevice-ux"
386393
data:
387394
2:

0 commit comments

Comments
 (0)