diff --git a/.gitignore b/.gitignore index 757028d..ae52947 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ palm-client/build/ .DS_Store # MeshCore build checkout (firmware/Makefile) firmware/meshcore/ + +# Palm SDK headers copied out of the Docker image for the editor (see Makefile: editor) +palm-client/.sdk/ +palm-client/compile_flags.txt diff --git a/palm-client/Makefile b/palm-client/Makefile index 66467b9..94a4c87 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -3,13 +3,14 @@ # make build build/visormesh.prc (in Docker if the toolchain isn't installed) # make test run the host-side protocol tests # make install install the .prc over the USB cradle (press HotSync when asked) +# make editor copy the SDK headers to .sdk/ and write compile_flags.txt for clangd # make clean APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/protocol.c src/transport_srm.c +SRCS = src/main.c src/protocol.c src/transport_srm.c src/ports.c OBJS = $(SRCS:src/%.c=build/%.o) CC = m68k-palmos-gcc @@ -66,4 +67,14 @@ install: all clean: rm -rf build -.PHONY: all test image install clean +# Editor support: clangd can't see the SDK inside the image, so copy it out. +editor: image + rm -rf .sdk && mkdir -p .sdk + cid=$$(docker create --platform linux/amd64 $(DOCKER_IMAGE)) && \ + docker cp -q $$cid:/opt/palmdev/sdk-3.5/include .sdk/sdk-3.5; docker rm $$cid >/dev/null + printf '%s\n' -std=gnu89 -D__palmos__=1 -Isrc -Wno-implicit-int -Wno-pointer-sign \ + -Wno-deprecated-non-prototype -Wno-incompatible-library-redeclaration \ + -Wno-ignored-attributes -Wno-pragma-once-outside-header > compile_flags.txt + find .sdk/sdk-3.5 -type d | sed 's|^|-I|' >> compile_flags.txt + +.PHONY: all test image install clean editor diff --git a/palm-client/resources/visormesh.rcp b/palm-client/resources/visormesh.rcp index dafb12b..45d11cf 100644 --- a/palm-client/resources/visormesh.rcp +++ b/palm-client/resources/visormesh.rcp @@ -11,7 +11,16 @@ BEGIN LABEL "MeshCore client for the Visor" AUTOID AT (5 20) LABEL "Radio:" AUTOID AT (5 45) FONT 1 LABEL "Not connected " ID MainStatusLabel AT (40 45) - BUTTON "Query radio" ID MainQueryButton AT (CENTER 140 AUTO AUTO) + BUTTON "Query radio" ID MainQueryButton AT (20 140 AUTO AUTO) + BUTTON "Ports" ID MainPortsButton AT (PREVRIGHT+10 PREVTOP AUTO AUTO) +END + +FORM ID PortsForm AT (0 0 160 160) +NOFRAME +USABLE +BEGIN + TITLE "Serial Ports" + BUTTON "Done" ID PortsDoneButton AT (CENTER 145 AUTO AUTO) END ALERT ID RomIncompatibleAlert diff --git a/palm-client/src/main.c b/palm-client/src/main.c index 965b924..857af93 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -2,6 +2,7 @@ #include "resources.h" #include "protocol.h" #include "transport.h" +#include "ports.h" #define VM_MIN_ROM_VERSION sysMakeROMVersion(3, 5, 0, sysROMStageRelease, 0) #define VM_QUERY_TIMEOUT (2 * SysTicksPerSecond()) @@ -88,6 +89,10 @@ static Boolean MainFormHandleEvent(EventType *event) QueryRadio(); return true; } + if (event->data.ctlSelect.controlID == MainPortsButton) { + FrmGotoForm(PortsForm); + return true; + } break; default: break; @@ -107,6 +112,8 @@ static Boolean AppHandleEvent(EventType *event) FrmSetActiveForm(form); if (formId == MainForm) FrmSetEventHandler(form, MainFormHandleEvent); + else if (formId == PortsForm) + FrmSetEventHandler(form, PortsFormHandleEvent); return true; } diff --git a/palm-client/src/ports.c b/palm-client/src/ports.c new file mode 100644 index 0000000..78d6c7c --- /dev/null +++ b/palm-client/src/ports.c @@ -0,0 +1,72 @@ +/* + * Diagnostics: lists the Serial Manager drivers on this device (creator, + * feature flags, description), to find which one reaches the USB cradle. + */ +#include +#include "resources.h" +#include "ports.h" + +#define LINE_H 11 +#define FIRST_Y 18 +#define MAX_LINES 11 + +static void DrawLine(UInt16 line, const Char *text) +{ + WinDrawChars(text, StrLen(text), 2, FIRST_Y + line * LINE_H); +} + +static void DrawPorts(void) +{ + DeviceInfoType info; + UInt16 count = 0, i, line = 0; + Char buf[48]; + Char crid[5]; + Err err; + + err = SrmGetDeviceCount(&count); + if (err != errNone) { + StrPrintF(buf, "SrmGetDeviceCount err 0x%x", err); + DrawLine(line, buf); + return; + } + StrPrintF(buf, "%u serial device(s):", count); + DrawLine(line++, buf); + + for (i = 0; i < count && line + 1 < MAX_LINES; i++) { + MemSet(&info, sizeof(info), 0); + err = SrmGetDeviceInfo(i, &info); + if (err != errNone) { + StrPrintF(buf, "%u: err 0x%x", i, err); + DrawLine(line++, buf); + continue; + } + MemMove(crid, &info.serDevCreator, 4); + crid[4] = 0; + StrPrintF(buf, "%u '%s' ftr %lx max %lu", i, crid, info.serDevFtrInfo, info.serDevMaxBaudRate); + DrawLine(line++, buf); + if (info.serDevPortInfoStr) { + StrNCopy(buf, " ", sizeof(buf)); + StrNCat(buf, info.serDevPortInfoStr, sizeof(buf)); + DrawLine(line++, buf); + } + } +} + +Boolean PortsFormHandleEvent(EventType *event) +{ + switch (event->eType) { + case frmOpenEvent: + FrmDrawForm(FrmGetActiveForm()); + DrawPorts(); + return true; + case ctlSelectEvent: + if (event->data.ctlSelect.controlID == PortsDoneButton) { + FrmGotoForm(MainForm); + return true; + } + break; + default: + break; + } + return false; +} diff --git a/palm-client/src/ports.h b/palm-client/src/ports.h new file mode 100644 index 0000000..5036a4f --- /dev/null +++ b/palm-client/src/ports.h @@ -0,0 +1,8 @@ +#ifndef VM_PORTS_H +#define VM_PORTS_H + +#include + +Boolean PortsFormHandleEvent(EventType *event); + +#endif diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index e56ee76..389cbdd 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -4,6 +4,10 @@ #define MainForm 1000 #define MainStatusLabel 1001 #define MainQueryButton 1002 +#define MainPortsButton 1003 + +#define PortsForm 1100 +#define PortsDoneButton 1101 #define RomIncompatibleAlert 2000