diff --git a/palm-client/Makefile b/palm-client/Makefile index 1245ba0..8059be8 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -10,7 +10,7 @@ APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/ports.c +SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/ports.c OBJS = $(SRCS:src/%.c=build/%.o) CC = m68k-palmos-gcc diff --git a/palm-client/resources/visormesh.rcp b/palm-client/resources/visormesh.rcp index 2486999..8bcb480 100644 --- a/palm-client/resources/visormesh.rcp +++ b/palm-client/resources/visormesh.rcp @@ -3,9 +3,18 @@ VERSION ID 1 "0.1" APPLICATIONICONNAME ID 1000 "VisorMesh" +MENU ID MainMenuBar +BEGIN + PULLDOWN "Options" + BEGIN + MENUITEM "Serial Ports..." ID MainMenuPorts "P" + END +END + FORM ID MainForm AT (0 0 160 160) NOFRAME USABLE +MENUID MainMenuBar BEGIN TITLE "VisorMesh" LABEL "Link:" AUTOID AT (5 18) FONT 1 @@ -24,8 +33,27 @@ BEGIN LABEL " " ID MainFirmwareLabel AT (50 90) BUTTON "Disconnect" ID MainConnectButton AT (5 140 AUTO AUTO) + BUTTON "Contacts" ID MainContactsButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) BUTTON "Settings" ID MainSettingsButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) - BUTTON "Ports" ID MainPortsButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) +END + +FORM ID ContactsForm AT (0 0 160 160) +NOFRAME +USABLE +BEGIN + TITLE "Contacts" + LIST "" ID ContactsList AT (0 16 160 121) VISIBLEITEMS 11 + LABEL " " ID ContactsStatusLabel AT (5 129) + BUTTON "Refresh" ID ContactsRefreshButton AT (5 145 AUTO AUTO) + BUTTON "Done" ID ContactsDoneButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) +END + +ALERT ID ContactInfoAlert +INFORMATION +BEGIN + TITLE "Contact" + MESSAGE "^1\n^2" + BUTTONS "OK" END FORM ID SettingsForm AT (0 0 160 160) diff --git a/palm-client/src/contacts.c b/palm-client/src/contacts.c new file mode 100644 index 0000000..2e134df --- /dev/null +++ b/palm-client/src/contacts.c @@ -0,0 +1,106 @@ +#include +#include "protocol.h" +#include "session.h" +#include "contacts.h" + +#define DB_NAME "VisorMeshContacts" +#define DB_TYPE 'cont' +#define DB_CREATOR 'VMsh' + +static DmOpenRef gDb = 0; + +Err ContactsOpen(void) +{ + LocalID id; + UInt16 attrs; + Err err; + + if (gDb) + return errNone; + id = DmFindDatabase(0, DB_NAME); + if (!id) { + err = DmCreateDatabase(0, DB_NAME, DB_CREATOR, DB_TYPE, false); + if (err != errNone) + return err; + id = DmFindDatabase(0, DB_NAME); + if (!id) + return DmGetLastErr(); + DmDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + attrs |= dmHdrAttrBackup; + DmSetDatabaseInfo(0, id, NULL, &attrs, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + } + gDb = DmOpenDatabase(0, id, dmModeReadWrite); + return gDb ? errNone : DmGetLastErr(); +} + +void ContactsClose(void) +{ + if (gDb) { + DmCloseDatabase(gDb); + gDb = 0; + } +} + +UInt16 ContactsCount(void) +{ + return gDb ? DmNumRecords(gDb) : 0; +} + +Boolean ContactsGet(UInt16 index, VmContact *out) +{ + MemHandle h; + + if (!gDb || index >= DmNumRecords(gDb)) + return false; + h = DmQueryRecord(gDb, index); + if (!h) + return false; + MemMove(out, MemHandleLock(h), sizeof(VmContact)); + MemHandleUnlock(h); + return true; +} + +static Int16 CompareByName(void *a, void *b, Int16 other, SortRecordInfoPtr ia, SortRecordInfoPtr ib, + MemHandle appInfo) +{ + return StrCaselessCompare(((VmContact *)a)->name, ((VmContact *)b)->name); +} + +/* SessionGetContacts callback: appends one record. */ +static Err AddContact(const VmContact *c, void *ctx) +{ + UInt16 index = dmMaxRecordIndex; + MemHandle h = DmNewRecord(gDb, &index, sizeof(VmContact)); + + if (!h) + return DmGetLastErr(); + DmWrite(MemHandleLock(h), 0, c, sizeof(VmContact)); + MemHandleUnlock(h); + DmReleaseRecord(gDb, index, true); + return errNone; +} + +Err ContactsRefresh(UInt32 *count) +{ + UInt16 oldCount, i; + UInt32 lastMod; + Err err; + + err = ContactsOpen(); + if (err != errNone) + return err; + oldCount = DmNumRecords(gDb); + + err = SessionGetContacts(0, AddContact, NULL, count, &lastMod); + + if (err != errNone) { + /* drop what this attempt added; keep the previous list */ + for (i = DmNumRecords(gDb); i > oldCount; i--) + DmRemoveRecord(gDb, i - 1); + return err; + } + for (i = 0; i < oldCount; i++) + DmRemoveRecord(gDb, 0); + DmQuickSort(gDb, CompareByName, 0); + return errNone; +} diff --git a/palm-client/src/contacts.h b/palm-client/src/contacts.h new file mode 100644 index 0000000..c6d0df3 --- /dev/null +++ b/palm-client/src/contacts.h @@ -0,0 +1,23 @@ +/* + * The contact list, kept in a Palm database so it survives between launches + * (and is backed up by HotSync). Records are VmContact structs, sorted by name. + */ +#ifndef VM_CONTACTS_H +#define VM_CONTACTS_H + +#include +#include "protocol.h" + +Err ContactsOpen(void); +void ContactsClose(void); +UInt16 ContactsCount(void); +Boolean ContactsGet(UInt16 index, VmContact *out); + +/* + * Downloads the radio's whole contact list and replaces the stored one. The + * old records are only removed once the download succeeds, so a failed + * refresh leaves the previous list intact. + */ +Err ContactsRefresh(UInt32 *count); + +#endif diff --git a/palm-client/src/contacts_form.c b/palm-client/src/contacts_form.c new file mode 100644 index 0000000..f74e945 --- /dev/null +++ b/palm-client/src/contacts_form.c @@ -0,0 +1,164 @@ +/* + * Contacts screen: the stored list (works offline), Refresh to download it + * from the radio, tap a contact for its details. + */ +#include +#include "resources.h" +#include "protocol.h" +#include "session.h" +#include "contacts.h" +#include "contacts_form.h" + +#define PALM_EPOCH_OFFSET 2082844800UL /* seconds from 1904-01-01 (Palm) to 1970-01-01 (Unix) */ + +static const Char *TypeName(UInt8 type) +{ + switch (type) { + case VM_ADV_TYPE_CHAT: return "Chat"; + case VM_ADV_TYPE_REPEATER: return "Repeater"; + case VM_ADV_TYPE_ROOM: return "Room"; + case VM_ADV_TYPE_SENSOR: return "Sensor"; + default: return "?"; + } +} + +static void FormatHops(Char *out, UInt8 pathLen) +{ + UInt8 hops = VM_PATH_HOPS(pathLen); + + if (pathLen == VM_PATH_UNKNOWN) + StrCopy(out, "flood"); + else if (hops == 0) + StrCopy(out, "direct"); + else + StrPrintF(out, "%u hop%s", hops, hops == 1 ? "" : "s"); +} + +/* List draw callback: name on the left, type and route on the right. */ +static void DrawContact(Int16 itemNum, RectangleType *bounds, Char **itemsText) +{ + VmContact c; + Char right[24], hops[12]; + Int16 rightW, nameW; + UInt16 nameLen; + Boolean fits; + + if (!ContactsGet((UInt16)itemNum, &c)) + return; + FormatHops(hops, c.outPathLen); + StrPrintF(right, "%s, %s", TypeName(c.type), hops); + rightW = FntCharsWidth(right, StrLen(right)); + WinDrawChars(right, StrLen(right), bounds->topLeft.x + bounds->extent.x - rightW - 2, bounds->topLeft.y); + + nameLen = StrLen(c.name); + nameW = bounds->extent.x - rightW - 8; + FntCharsInWidth(c.name, &nameW, &nameLen, &fits); + WinDrawChars(c.name, nameLen, bounds->topLeft.x + 1, bounds->topLeft.y); +} + +static void SetStatus(FormType *form, const Char *text) +{ + UInt16 index = FrmGetObjectIndex(form, ContactsStatusLabel); + + FrmHideObject(form, index); + FrmCopyLabel(form, ContactsStatusLabel, text); + FrmShowObject(form, index); +} + +static void LoadList(FormType *form, Boolean redraw) +{ + ListType *list = FrmGetObjectPtr(form, FrmGetObjectIndex(form, ContactsList)); + Char status[32]; + UInt16 n = ContactsCount(); + + LstSetListChoices(list, NULL, n); + LstSetDrawFunction(list, DrawContact); + LstSetSelection(list, noListSelection); + if (n == 0) + StrCopy(status, SessionIsConnected() ? "No contacts. Tap Refresh." : "No contacts stored."); + else + StrPrintF(status, "%u contact%s", n, n == 1 ? "" : "s"); + if (redraw) { + LstDrawList(list); + SetStatus(form, status); + } else { + FrmCopyLabel(form, ContactsStatusLabel, status); + } +} + +static void Refresh(FormType *form) +{ + UInt32 total = 0; + Char msg[40]; + Err err; + + if (!SessionIsConnected()) { + FrmCustomAlert(SettingsErrorAlert, "Connect to the radio first.", "", ""); + return; + } + SetStatus(form, "Downloading..."); + err = ContactsRefresh(&total); + LoadList(form, true); + if (err == errNone) + return; + if (err == vmErrNoReply) + StrCopy(msg, "No reply from the radio."); + else if (err == vmErrRadio) + StrCopy(msg, "The radio returned an error."); + else + StrPrintF(msg, "Refresh failed (0x%x).", err); + FrmCustomAlert(SettingsErrorAlert, msg, "", ""); +} + +static void ShowDetails(UInt16 index) +{ + VmContact c; + DateTimeType dt; + Char line[96], hops[12], key[16]; + + if (!ContactsGet(index, &c)) + return; + FormatHops(hops, c.outPathLen); + StrPrintF(key, "%02x%02x%02x%02x%02x%02x", c.pubKey[0], c.pubKey[1], c.pubKey[2], c.pubKey[3], + c.pubKey[4], c.pubKey[5]); + if (c.lastAdvert) { + TimSecondsToDateTime(c.lastAdvert + PALM_EPOCH_OFFSET, &dt); + StrPrintF(line, "%s, %s\nKey %s...\nLast advert %u-%02u-%02u %02u:%02u", TypeName(c.type), hops, key, + dt.year, dt.month, dt.day, dt.hour, dt.minute); + } else { + StrPrintF(line, "%s, %s\nKey %s...", TypeName(c.type), hops, key); + } + FrmCustomAlert(ContactInfoAlert, c.name, line, ""); +} + +Boolean ContactsFormHandleEvent(EventType *event) +{ + FormType *form = FrmGetActiveForm(); + + switch (event->eType) { + case frmOpenEvent: + ContactsOpen(); + LoadList(form, false); + FrmDrawForm(form); + return true; + case lstSelectEvent: + if (event->data.lstSelect.listID == ContactsList) { + ShowDetails((UInt16)event->data.lstSelect.selection); + return true; + } + break; + case ctlSelectEvent: + switch (event->data.ctlSelect.controlID) { + case ContactsRefreshButton: + Refresh(form); + return true; + case ContactsDoneButton: + FrmGotoForm(MainForm); + return true; + } + break; + default: + break; + } + return false; +} diff --git a/palm-client/src/contacts_form.h b/palm-client/src/contacts_form.h new file mode 100644 index 0000000..924d134 --- /dev/null +++ b/palm-client/src/contacts_form.h @@ -0,0 +1,8 @@ +#ifndef VM_CONTACTS_FORM_H +#define VM_CONTACTS_FORM_H + +#include + +Boolean ContactsFormHandleEvent(EventType *event); + +#endif diff --git a/palm-client/src/main.c b/palm-client/src/main.c index fc12f07..afbf779 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -5,6 +5,8 @@ #include "session.h" #include "ports.h" #include "settings.h" +#include "contacts.h" +#include "contacts_form.h" #define VM_MIN_ROM_VERSION sysMakeROMVersion(3, 5, 0, sysROMStageRelease, 0) #define VM_LABEL_CHARS 22 /* the info labels in the .rcp are padded to this width */ @@ -136,8 +138,8 @@ static Boolean MainFormHandleEvent(EventType *event) case MainConnectButton: ConnectOrDisconnect(form); return true; - case MainPortsButton: - FrmGotoForm(PortsForm); + case MainContactsButton: + FrmGotoForm(ContactsForm); return true; case MainSettingsButton: if (SessionIsConnected()) @@ -147,6 +149,12 @@ static Boolean MainFormHandleEvent(EventType *event) return true; } break; + case menuEvent: + if (event->data.menu.itemID == MainMenuPorts) { + FrmGotoForm(PortsForm); + return true; + } + break; default: break; } @@ -169,6 +177,8 @@ static Boolean AppHandleEvent(EventType *event) FrmSetEventHandler(form, PortsFormHandleEvent); else if (formId == SettingsForm) FrmSetEventHandler(form, SettingsFormHandleEvent); + else if (formId == ContactsForm) + FrmSetEventHandler(form, ContactsFormHandleEvent); return true; } @@ -199,6 +209,7 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags) FrmGotoForm(MainForm); AppEventLoop(); SessionDisconnect(); + ContactsClose(); FrmCloseAllForms(); } return errNone; diff --git a/palm-client/src/presets.c b/palm-client/src/presets.c index cebeadb..3e34e8b 100644 --- a/palm-client/src/presets.c +++ b/palm-client/src/presets.c @@ -1,11 +1,13 @@ /* - * MeshCore suggested radio presets. GENERATED by tools/gen_presets.py from - * tools/meshcore-presets.json (https://api.meshcore.nz/api/v1/config, fetched 2026-11-01). + * Radio presets: tools/local-presets.json (1 local) then MeshCore's + * suggested presets from tools/meshcore-presets.json (https://api.meshcore.nz/api/v1/config, + * fetched 2026-11-01). GENERATED by tools/gen_presets.py. * Don't edit by hand. */ #include "presets.h" const VmPreset gPresets[] = { + { "PhillyMesh", 919500UL, 500000UL, 10, 5, 2 }, { "Australia", 915800UL, 250000UL, 10, 5, 0 }, { "Australia (Narrow)", 916575UL, 62500UL, 7, 7, 0 }, { "Australia (Mid)", 915075UL, 125000UL, 9, 5, 0 }, diff --git a/palm-client/src/protocol.h b/palm-client/src/protocol.h index 035c8a0..6c95abf 100644 --- a/palm-client/src/protocol.h +++ b/palm-client/src/protocol.h @@ -66,6 +66,20 @@ typedef char Char; #define VM_PUSH_MSG_WAITING 0x83 #define VM_IS_PUSH(code) ((code) >= 0x80) +/* Advert types (contact.type) */ +#define VM_ADV_TYPE_CHAT 1 +#define VM_ADV_TYPE_REPEATER 2 +#define VM_ADV_TYPE_ROOM 3 +#define VM_ADV_TYPE_SENSOR 4 + +/* + * Path length bytes (contact out_path_len, message path_len): bits 7-6 are + * the path hash size - 1, bits 5-0 the hop count; 0xFF = no known path. + */ +#define VM_PATH_UNKNOWN 0xFF +#define VM_PATH_HOPS(len) ((UInt8)((len) & 0x3F)) +#define VM_PATH_HASH_BYTES(len) ((UInt8)(((len) >> 6) + 1)) + #define VM_TXT_TYPE_PLAIN 0 #define VM_TXT_TYPE_CLI_DATA 1 #define VM_TXT_TYPE_SIGNED_PLAIN 2 diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index 85e778c..2d9458e 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -4,7 +4,6 @@ #define MainForm 1000 #define MainNameLabel 1001 #define MainConnectButton 1002 -#define MainPortsButton 1003 #define MainSerialPush 1004 #define MainUsbPush 1005 #define MainFreqLabel 1006 @@ -12,6 +11,9 @@ #define MainPowerLabel 1008 #define MainFirmwareLabel 1009 #define MainSettingsButton 1010 +#define MainContactsButton 1011 +#define MainMenuBar 1000 +#define MainMenuPorts 1001 #define MainLinkGroup 1 #define SettingsForm 1200 @@ -32,6 +34,13 @@ #define SettingsHashGroup 2 #define SettingsErrorAlert 2001 +#define ContactInfoAlert 2002 + +#define ContactsForm 1300 +#define ContactsList 1301 +#define ContactsStatusLabel 1302 +#define ContactsRefreshButton 1303 +#define ContactsDoneButton 1304 #define PortsForm 1100 #define PortsDoneButton 1101 diff --git a/palm-client/src/session.c b/palm-client/src/session.c index 632a6e6..a29ba5e 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -14,25 +14,31 @@ static VmDeviceInfo gDevice; static VmSelfInfo gSelf; /* - * Reads frames until one with the wanted code arrives. Pushes are noted and - * skipped; RESP_ERR ends the wait. The reply is left in gDecoder.payload. + * Received bytes not yet fed to the decoder. Kept across calls because one + * read can hold the end of one frame and the start of the next (the contact + * list arrives as back-to-back frames). */ -static Err WaitFor(UInt8 code, Int32 timeout) +static UInt8 gRx[64]; +static UInt16 gRxPos, gRxLen; + +/* + * Reads frames until one whose code is code1 or code2 arrives (pass the same + * code twice to wait for one). Pushes are noted and skipped; RESP_ERR ends the + * wait. The reply is left in gDecoder.payload. + */ +static Err WaitForEither(UInt8 code1, UInt8 code2, Int32 timeout) { - UInt8 rx[32]; - UInt16 n, i; UInt32 deadline = TimGetTicks() + timeout; Err err; - while (TimGetTicks() < deadline) { - n = TransportRecv(rx, sizeof(rx), deadline - TimGetTicks(), &err); - for (i = 0; i < n; i++) { + for (;;) { + while (gRxPos < gRxLen) { UInt8 got; - if (!VmDecoderFeed(&gDecoder, rx[i]) || gDecoder.len == 0) + if (!VmDecoderFeed(&gDecoder, gRx[gRxPos++]) || gDecoder.len == 0) continue; got = gDecoder.payload[0]; - if (got == code) + if (got == code1 || got == code2) return errNone; if (got == VM_PUSH_MSG_WAITING) gMsgWaiting = true; @@ -40,8 +46,16 @@ static Err WaitFor(UInt8 code, Int32 timeout) return vmErrRadio; /* other pushes and stray replies are ignored */ } + if (TimGetTicks() >= deadline) + return vmErrNoReply; + gRxPos = 0; + gRxLen = TransportRecv(gRx, sizeof(gRx), deadline - TimGetTicks(), &err); } - return vmErrNoReply; +} + +static Err WaitFor(UInt8 code, Int32 timeout) +{ + return WaitForEither(code, code, timeout); } /* Sends a request frame and waits for the reply code, retrying sends the host isn't reading yet. */ @@ -93,6 +107,7 @@ Err SessionConnect(void) if (err != errNone) return err; VmDecoderReset(&gDecoder); + gRxPos = gRxLen = 0; gMsgWaiting = false; /* Over USB the Visor only appears to the host after SrmOpen; give the bridge time to attach. */ @@ -115,11 +130,45 @@ Err SessionRefresh(void) return QueryRadio(1); } +/* + * Two tries: the Visor's USB link can drop while idle and re-attach on the + * next send, and the settings commands are safe to repeat. + */ Err SessionCommand(const UInt8 *frame, UInt16 len) { if (!gConnected) return serErrNotOpen; - return Request(frame, len, VM_RESP_OK, 1); + return Request(frame, len, VM_RESP_OK, 2); +} + +Err SessionGetContacts(UInt32 since, SessionContactFn fn, void *ctx, UInt32 *count, UInt32 *lastMod) +{ + UInt8 frame[VM_HEADER_LEN + 5]; + UInt16 len; + VmContact c; + Err err; + + if (!gConnected) + return serErrNotOpen; + len = VmBuildGetContacts(frame, sizeof(frame), since); + err = Request(frame, len, VM_RESP_CONTACTS_START, 2); + if (err != errNone) + return err; + if (!VmParseContactsStart(gDecoder.payload, gDecoder.len, count)) + return vmErrBadReply; + + for (;;) { + err = WaitForEither(VM_RESP_CONTACT, VM_RESP_END_OF_CONTACTS, VM_REPLY_TIMEOUT); + if (err != errNone) + return err; + if (gDecoder.payload[0] == VM_RESP_END_OF_CONTACTS) + return VmParseEndOfContacts(gDecoder.payload, gDecoder.len, lastMod) ? errNone : vmErrBadReply; + if (!VmParseContact(gDecoder.payload, gDecoder.len, &c)) + return vmErrBadReply; + err = fn(&c, ctx); + if (err != errNone) + return err; + } } const VmDeviceInfo *SessionDevice(void) diff --git a/palm-client/src/session.h b/palm-client/src/session.h index 690dc04..b3e51bd 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -28,4 +28,13 @@ Err SessionCommand(const UInt8 *frame, UInt16 len); /* Re-reads DEVICE_INFO and SELF_INFO, e.g. after changing settings. */ Err SessionRefresh(void); +/* + * GET_CONTACTS: calls fn for each contact changed since 'since' (0 = all). + * count is the radio's total (not the filtered number); lastMod is the newest + * lastmod, to pass as 'since' next time. A non-zero return from fn stops the + * download (the rest of the list is left in the radio's output). + */ +typedef Err (*SessionContactFn)(const VmContact *c, void *ctx); +Err SessionGetContacts(UInt32 since, SessionContactFn fn, void *ctx, UInt32 *count, UInt32 *lastMod); + #endif diff --git a/palm-client/tests/test_protocol.c b/palm-client/tests/test_protocol.c index 4c00d34..f38f33f 100644 --- a/palm-client/tests/test_protocol.c +++ b/palm-client/tests/test_protocol.c @@ -178,6 +178,14 @@ static void test_settings_builders(void) CHECK(memcmp(out, hash, sizeof(hash)) == 0); } +static void test_path_len(void) +{ + CHECK(VM_PATH_HOPS(0x00) == 0 && VM_PATH_HASH_BYTES(0x00) == 1); + CHECK(VM_PATH_HOPS(0x02) == 2 && VM_PATH_HASH_BYTES(0x02) == 1); + CHECK(VM_PATH_HOPS(0x43) == 3 && VM_PATH_HASH_BYTES(0x43) == 2); /* PhillyMesh: 2-byte hashes */ + CHECK(VM_PATH_HOPS(0x81) == 1 && VM_PATH_HASH_BYTES(0x81) == 3); +} + static void test_decimals(void) { UInt32 v; @@ -315,6 +323,7 @@ int main(void) test_builders_match_bench_frames(); test_settings_builders(); test_decimals(); + test_path_len(); test_parse_self_info(); test_parse_contacts(); test_parse_messages(); diff --git a/palm-client/tools/gen_presets.py b/palm-client/tools/gen_presets.py index 4717d19..4626dfe 100755 --- a/palm-client/tools/gen_presets.py +++ b/palm-client/tools/gen_presets.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -"""Generates src/presets.c from tools/meshcore-presets.json (a snapshot of MeshCore's -suggested radio presets; the Visor has no internet to fetch them). +"""Generates src/presets.c from tools/local-presets.json (local meshes, listed +first) and tools/meshcore-presets.json (a snapshot of MeshCore's suggested +radio presets; the Visor has no internet to fetch them). tools/gen_presets.py # regenerate from the snapshot tools/gen_presets.py --fetch # refresh the snapshot first @@ -16,6 +17,7 @@ from decimal import Decimal HERE = os.path.dirname(os.path.abspath(__file__)) SNAPSHOT = os.path.join(HERE, 'meshcore-presets.json') +LOCAL = os.path.join(HERE, 'local-presets.json') OUT = os.path.join(HERE, '..', 'src', 'presets.c') URL = 'https://api.meshcore.nz/api/v1/config' @@ -40,8 +42,9 @@ def main(): if '--fetch' in sys.argv: fetch() snap = json.load(open(SNAPSHOT)) + local = json.load(open(LOCAL))['entries'] if os.path.exists(LOCAL) else [] rows = [] - for e in snap['entries']: + for e in local + snap['entries']: title = e['title'].encode('ascii', 'replace').decode() khz = int(Decimal(e['frequency']) * 1000) hz = int(Decimal(e['bandwidth']) * 1000) @@ -50,8 +53,9 @@ def main(): rows.append(f'\t{{ {c_string(title)}, {khz}UL, {hz}UL, {sf}, {cr}, {hash_size} }},') with open(OUT, 'w') as f: f.write(f'''/* - * MeshCore suggested radio presets. GENERATED by tools/gen_presets.py from - * tools/meshcore-presets.json ({snap["source"]}, fetched {snap["fetched"]}). + * Radio presets: tools/local-presets.json ({len(local)} local) then MeshCore's + * suggested presets from tools/meshcore-presets.json ({snap["source"]}, + * fetched {snap["fetched"]}). GENERATED by tools/gen_presets.py. * Don't edit by hand. */ #include "presets.h" diff --git a/palm-client/tools/local-presets.json b/palm-client/tools/local-presets.json new file mode 100644 index 0000000..1834129 --- /dev/null +++ b/palm-client/tools/local-presets.json @@ -0,0 +1,14 @@ +{ + "comment": "Local mesh presets, listed before MeshCore's in the app. Not overwritten by gen_presets.py --fetch.", + "entries": [ + { + "title": "PhillyMesh", + "description": "919.500MHz / SF10 / BW500 / CR5 / 2B", + "frequency": "919.500", + "spreading_factor": "10", + "bandwidth": "500", + "coding_rate": "5", + "network_settings": { "path_hash_size": 2 } + } + ] +}