From 7801272830647de86d0eaa6d84babcaca3c22d1b Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Thu, 5 Nov 2026 14:50:04 -0500 Subject: [PATCH] palm-client: Radio Stats (Go menu, or Stats on Node): the radio's battery, storage, uptime, queue, last signal, airtime and packet counts, read every 5 s, with a graph of its noise floor. Heard Packets (Go menu): the last 40 packets from the RX log, filtered to chat or adverts, a tap showing one in full with its repeaters. info_fmt.c shares the path text with Path Details. The resources also hold the forms and alerts for the features that follow --- palm-client/Makefile | 2 +- palm-client/resources/visormesh.rcp | 204 ++++++++++++++++++++++++- palm-client/src/info_fmt.c | 55 +++++++ palm-client/src/info_fmt.h | 20 +++ palm-client/src/main.c | 10 ++ palm-client/src/msg_menu.c | 44 +----- palm-client/src/node_form.c | 3 + palm-client/src/packets_form.c | 227 ++++++++++++++++++++++++++++ palm-client/src/packets_form.h | 15 ++ palm-client/src/resources.h | 48 ++++++ palm-client/src/session.c | 55 +++++++ palm-client/src/session.h | 12 ++ palm-client/src/stats_form.c | 214 ++++++++++++++++++++++++++ palm-client/src/stats_form.h | 12 ++ 14 files changed, 880 insertions(+), 41 deletions(-) create mode 100644 palm-client/src/info_fmt.c create mode 100644 palm-client/src/info_fmt.h create mode 100644 palm-client/src/packets_form.c create mode 100644 palm-client/src/packets_form.h create mode 100644 palm-client/src/stats_form.c create mode 100644 palm-client/src/stats_form.h diff --git a/palm-client/Makefile b/palm-client/Makefile index 844f198..d2b8492 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -11,7 +11,7 @@ APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/title.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c src/reaction_fmt.c src/reactions.c src/rxpath.c src/msg_menu.c src/protocol2.c +SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/title.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c src/pins.c src/shots.c src/db.c src/reaction_fmt.c src/reactions.c src/rxpath.c src/msg_menu.c src/protocol2.c src/info_fmt.c src/stats_form.c src/packets_form.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 0a0428f..8b8d1f1 100644 --- a/palm-client/resources/visormesh.rcp +++ b/palm-client/resources/visormesh.rcp @@ -28,6 +28,44 @@ BEGIN MENUITEM "Contacts" ID MainMenuContacts "T" MENUITEM "Node" ID MainMenuNode "N" MENUITEM "Map" ID MainMenuMap "W" + MENUITEM "-" AUTOID + MENUITEM "Heard Packets" ID MainMenuPackets + MENUITEM "Radio Stats" ID MainMenuStats + MENUITEM "Trace Path" ID MainMenuTrace + END + PULLDOWN "Options" + BEGIN + MENUITEM "Connect" ID MainMenuConnect + MENUITEM "Flood Scopes..." ID MainMenuScopes "O" + MENUITEM "Preferences..." ID MainMenuSounds "R" + MENUITEM "-" AUTOID + MENUITEM "Serial Ports..." ID MainMenuPorts "I" + MENUITEM "Font Preview" ID MainMenuFontPreview "F" + MENUITEM "Screenshot" ID MainMenuShot "Z" + MENUITEM "Screenshot in 5 s" ID MainMenuShotLater "D" + MENUITEM "-" AUTOID + MENUITEM "About VisorMesh" ID MainMenuAbout + END +END + +MENU ID ContactsMenuBar +BEGIN + PULLDOWN "Go" + BEGIN + MENUITEM "Conversations" ID MainMenuHome "H" + MENUITEM "Contacts" ID MainMenuContacts "T" + MENUITEM "Node" ID MainMenuNode "N" + MENUITEM "Map" ID MainMenuMap "W" + MENUITEM "-" AUTOID + MENUITEM "Heard Packets" ID MainMenuPackets + MENUITEM "Radio Stats" ID MainMenuStats + MENUITEM "Trace Path" ID MainMenuTrace + END + PULLDOWN "Contacts" + BEGIN + MENUITEM "Beam My Contact" ID MainMenuBeamSelf "B" + MENUITEM "Blocked Senders..." ID MainMenuBlocked + MENUITEM "Remove Stale Contacts..." ID MainMenuStale END PULLDOWN "Options" BEGIN @@ -52,6 +90,10 @@ BEGIN MENUITEM "Contacts" ID MainMenuContacts "T" MENUITEM "Node" ID MainMenuNode "N" MENUITEM "Map" ID MainMenuMap "W" + MENUITEM "-" AUTOID + MENUITEM "Heard Packets" ID MainMenuPackets + MENUITEM "Radio Stats" ID MainMenuStats + MENUITEM "Trace Path" ID MainMenuTrace END PULLDOWN "Edit" BEGIN @@ -67,6 +109,7 @@ BEGIN PULLDOWN "Options" BEGIN MENUITEM "Message Actions..." ID MainMenuMessage "Y" + MENUITEM "Insert Mention..." ID MainMenuMention "J" MENUITEM "-" AUTOID MENUITEM "Connect" ID MainMenuConnect MENUITEM "Flood Scopes..." ID MainMenuScopes "O" @@ -105,6 +148,10 @@ BEGIN MENUITEM "Contacts" ID MainMenuContacts "T" MENUITEM "Node" ID MainMenuNode "N" MENUITEM "Map" ID MainMenuMap "W" + MENUITEM "-" AUTOID + MENUITEM "Heard Packets" ID MainMenuPackets + MENUITEM "Radio Stats" ID MainMenuStats + MENUITEM "Trace Path" ID MainMenuTrace END PULLDOWN "Channel" BEGIN @@ -133,6 +180,10 @@ BEGIN MENUITEM "Contacts" ID MainMenuContacts "T" MENUITEM "Node" ID MainMenuNode "N" MENUITEM "Map" ID MainMenuMap "W" + MENUITEM "-" AUTOID + MENUITEM "Heard Packets" ID MainMenuPackets + MENUITEM "Radio Stats" ID MainMenuStats + MENUITEM "Trace Path" ID MainMenuTrace END PULLDOWN "Edit" BEGIN @@ -152,10 +203,12 @@ BEGIN MENUITEM "Leave Channel" ID MainMenuLeaveChannel "L" MENUITEM "Mute Channel" ID MainMenuMuteChannel "M" MENUITEM "Channel Scope..." ID MainMenuChannelScope "E" + MENUITEM "Beam Channel" ID MainMenuBeamChannel "B" END PULLDOWN "Options" BEGIN MENUITEM "Message Actions..." ID MainMenuMessage "Y" + MENUITEM "Insert Mention..." ID MainMenuMention "J" MENUITEM "-" AUTOID MENUITEM "Connect" ID MainMenuConnect MENUITEM "Flood Scopes..." ID MainMenuScopes "O" @@ -197,7 +250,8 @@ BEGIN BUTTON "Send" ID ConvoSendButton AT (1 147 AUTO AUTO) BUTTON "Back" ID ConvoBackButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO) GRAFFITISTATEINDICATOR AT (150 148) - LIST "" ID ConvoActionList AT (28 16 80 AUTO) NONUSABLE VISIBLEITEMS 5 + LIST "" ID ConvoActionList AT (28 16 80 AUTO) NONUSABLE VISIBLEITEMS 6 + LIST "" ID ConvoMentionList AT (10 16 140 AUTO) NONUSABLE VISIBLEITEMS 8 END /* Node: this radio's details, connection and settings */ @@ -225,6 +279,7 @@ BEGIN BUTTON "Settings" ID MainSettingsButton AT (5 127 AUTO AUTO) BUTTON "Advert" ID MainAdvertButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) + BUTTON "Stats" ID MainStatsButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) BUTTON "Disconnect" ID MainConnectButton AT (5 145 AUTO AUTO) BUTTON "Done" ID MainDoneButton AT (PREVRIGHT+6 PREVTOP AUTO AUTO) END @@ -232,7 +287,7 @@ END FORM ID ContactsForm AT (0 0 160 160) NOFRAME USABLE -MENUID MainMenuBar +MENUID ContactsMenuBar BEGIN TITLE "Contacts " GADGET ID ContactsGadget AT (0 16 153 128) @@ -240,6 +295,7 @@ BEGIN BUTTON "Refresh" ID ContactsRefreshButton AT (1 147 AUTO AUTO) BUTTON "Done" ID ContactsDoneButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO) BUTTON "Add" ID ContactsAddButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO) + LIST "" ID ContactsBlockedList AT (10 16 140 AUTO) NONUSABLE VISIBLEITEMS 8 END /* One contact: details and signal history */ @@ -255,7 +311,7 @@ BEGIN BUTTON "Message" ID ContactMessageButton AT (PREVRIGHT+4 PREVTOP AUTO AUTO) BUTTON "Login" ID ContactLoginButton AT (PREVRIGHT+4 PREVTOP AUTO AUTO) BUTTON "More" ID ContactMoreButton AT (PREVRIGHT+4 PREVTOP AUTO AUTO) - LIST "Admin Console" "Reset Path" "Remove" ID ContactMoreList AT (90 111 68 AUTO) NONUSABLE VISIBLEITEMS 3 + LIST "" ID ContactMoreList AT (84 60 74 AUTO) NONUSABLE VISIBLEITEMS 8 END FORM ID ContactAddForm AT (0 0 160 160) @@ -598,3 +654,145 @@ BEGIN MESSAGE "Remove ^1 from the radio? Its messages stay on the Visor." BUTTONS "Leave" "Cancel" END + +/* Radio Stats: the companion radio's own report (stats_form.c) */ +FORM ID StatsForm AT (0 0 160 160) +NOFRAME +USABLE +MENUID MainMenuBar +BEGIN + TITLE "Radio Stats" + BUTTON "Done" ID StatsDoneButton AT (1 147 AUTO AUTO) +END + +/* Heard Packets: the radio's RX log (packets_form.c) */ +FORM ID PacketsForm AT (0 0 160 160) +NOFRAME +USABLE +MENUID MainMenuBar +BEGIN + TITLE "Heard Packets" + GADGET ID PacketsGadget AT (0 16 153 128) + SCROLLBAR ID PacketsScroll AT (153 16 7 128) VALUE 0 MIN 0 MAX 0 PAGESIZE 1 + BUTTON "Done" ID PacketsDoneButton AT (1 147 AUTO AUTO) + PUSHBUTTON "All" ID PacketsAllPush AT (60 147 26 12) GROUP PacketsFilterGroup + PUSHBUTTON "Chat" ID PacketsMsgPush AT (PREVRIGHT+1 PREVTOP 30 12) GROUP PacketsFilterGroup + PUSHBUTTON "Adverts" ID PacketsAdvertPush AT (PREVRIGHT+1 PREVTOP 40 12) GROUP PacketsFilterGroup +END + +ALERT ID PacketAlert +INFORMATION +BEGIN + TITLE "Packet" + MESSAGE "^1" + BUTTONS "OK" +END + +/* Trace Path: hops out and back, SNR at each (trace_form.c); for a contact, also its route */ +FORM ID TraceForm AT (0 0 160 160) +NOFRAME +USABLE +MENUID EditMenuBar +BEGIN + TITLE "Trace Path" + LABEL " " ID TraceForLabel AT (3 16) + LABEL "Hops:" AUTOID AT (3 29) FONT 1 + FIELD ID TraceField AT (32 29 97 12) UNDERLINED SINGLELINE EDITABLE MAXCHARS 60 + BUTTON "Add" ID TraceAddButton AT (132 28 26 12) + CHECKBOX "Round trip (back the same way)" ID TraceRoundCheck AT (1 42 AUTO 12) + GADGET ID TraceGadget AT (0 56 153 88) + SCROLLBAR ID TraceScroll AT (153 56 7 88) VALUE 0 MIN 0 MAX 0 PAGESIZE 1 + BUTTON "Trace" ID TraceGoButton AT (1 147 AUTO AUTO) + BUTTON "Set Route" ID TraceRouteButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO) + BUTTON "Done" ID TraceDoneButton AT (PREVRIGHT+5 PREVTOP AUTO AUTO) + GRAFFITISTATEINDICATOR AT (150 148) + LIST "" ID TraceHopList AT (40 16 118 AUTO) NONUSABLE VISIBLEITEMS 10 +END + +ALERT ID TraceRouteAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Set Route" + MESSAGE "Send to ^1 ^2?" + BUTTONS "Set Route" "Cancel" +END + +ALERT ID PingAlert +INFORMATION +BEGIN + TITLE "Ping" + MESSAGE "^1" + BUTTONS "OK" +END + +ALERT ID StaleAlert +CONFIRMATION +DEFAULTBUTTON 3 +BEGIN + TITLE "Remove Stale Contacts" + MESSAGE "Remove contacts the radio hasn't heard an advert from in:" + BUTTONS "2 weeks" "1 month" "3 months" "Cancel" +END + +ALERT ID StaleConfirmAlert +WARNING +DEFAULTBUTTON 1 +BEGIN + TITLE "Remove Stale Contacts" + MESSAGE "Remove ^1 from the radio? Kept: contacts you have messages with, ones never heard (added by key) and ones you're logged into. Their messages stay on the Visor." + BUTTONS "Remove" "Cancel" +END + +ALERT ID BlockAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Block" + MESSAGE "Hide messages and reactions from ^1? Unblock under Contacts > Blocked Senders." + BUTTONS "Block" "Cancel" +END + +ALERT ID UnblockAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Unblock" + MESSAGE "Show messages from ^1 again?" + BUTTONS "Unblock" "Cancel" +END + +ALERT ID InboxContactAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Contact Received" + MESSAGE "Add ^1 (^2) to the radio's contacts?" + BUTTONS "Add" "Later" "Discard" +END + +ALERT ID InboxChannelAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Channel Received" + MESSAGE "Join ^1?" + BUTTONS "Join" "Later" "Discard" +END + +ALERT ID HashtagAlert +CONFIRMATION +DEFAULTBUTTON 1 +BEGIN + TITLE "Join Channel" + MESSAGE "Join ^1? Anyone who knows the name can read it." + BUTTONS "Join" "Cancel" +END + +ALERT ID NoteAlert +INFORMATION +BEGIN + TITLE "VisorMesh" + MESSAGE "^1" + BUTTONS "OK" +END diff --git a/palm-client/src/info_fmt.c b/palm-client/src/info_fmt.c new file mode 100644 index 0000000..e375d0f --- /dev/null +++ b/palm-client/src/info_fmt.c @@ -0,0 +1,55 @@ +#include +#include "session.h" +#include "contacts.h" +#include "ui/text.h" +#include "info_fmt.h" + +void InfoClock(Char *out, UInt16 size, const Char *label, UInt32 utc) +{ + DateTimeType dt, now; + Char s[40]; + + TimSecondsToDateTime(SessionLocalPalm(utc), &dt); + TimSecondsToDateTime(SessionLocalPalm(SessionNow()), &now); + if (dt.year != now.year || dt.month != now.month || dt.day != now.day) + StrPrintF(s, "%s %u/%u %02u:%02u:%02u", label, dt.month, dt.day, dt.hour, dt.minute, dt.second); + else + StrPrintF(s, "%s %02u:%02u:%02u", label, dt.hour, dt.minute, dt.second); + StrNCat(out, s, size); +} + +void InfoHop(Char *out, UInt16 size, const UInt8 *hash, UInt8 hashSize) +{ + VmContact c; + Char hex[12]; + UInt16 len; + + TxtHex(hash, hashSize, hex); + StrNCat(out, hex, size); + if (ContactsFindByPrefixN(hash, hashSize, &c)) { + StrNCat(out, " ", size); + len = StrLen(out); + StrNCat(out, c.name, len + 12 + 1 < size ? len + 12 + 1 : size); + } +} + +void InfoVia(Char *out, UInt16 size, const UInt8 *path, UInt16 pathBytes, UInt8 hashSize, UInt16 hops) +{ + Char more[16]; + UInt16 i; + + if (hashSize == 0) + return; + for (i = 0; i + hashSize <= pathBytes; i += hashSize) { + if (StrLen(out) + 40 > size) { /* room for one more entry and the end */ + StrNCat(out, ", ...", size); + return; + } + StrNCat(out, i ? ", " : " ", size); + InfoHop(out, size, path + i, hashSize); + } + if (hops > pathBytes / hashSize) { + StrPrintF(more, " +%u more", hops - pathBytes / hashSize); + StrNCat(out, more, size); + } +} diff --git a/palm-client/src/info_fmt.h b/palm-client/src/info_fmt.h new file mode 100644 index 0000000..0639027 --- /dev/null +++ b/palm-client/src/info_fmt.h @@ -0,0 +1,20 @@ +/* + * Text shared by the detail alerts (a message's path, a heard packet, a + * trace): clock times and repeater lists with the names of matching + * contacts. Each appends to out, a string of size bytes, and stops short of + * the end. + */ +#ifndef VM_INFO_FMT_H +#define VM_INFO_FMT_H + +#include +#include "sections.h" /* this module is in the fifth code segment */ + +/* "label HH:MM:SS" in local time, with the date if it isn't today. */ +void InfoClock(Char *out, UInt16 size, const Char *label, UInt32 utc) VM_SECT5; +/* "3F2A RptA": a hop's hash and up to 12 characters of a contact it matches. */ +void InfoHop(Char *out, UInt16 size, const UInt8 *hash, UInt8 hashSize) VM_SECT5; +/* " 3F2A RptA, 91C0, ..." for pathBytes of hops (hashSize each); "+N more" if hops is more than that. */ +void InfoVia(Char *out, UInt16 size, const UInt8 *path, UInt16 pathBytes, UInt8 hashSize, UInt16 hops) VM_SECT5; + +#endif diff --git a/palm-client/src/main.c b/palm-client/src/main.c index 64e224f..953b44e 100644 --- a/palm-client/src/main.c +++ b/palm-client/src/main.c @@ -24,6 +24,8 @@ #include "channel_form.h" #include "bgcheck.h" #include "shots.h" +#include "stats_form.h" +#include "packets_form.h" #include "ui/draw.h" #include "ui/title.h" @@ -54,6 +56,8 @@ static Boolean HandleMenu(UInt16 itemID) case MainMenuContacts: FrmGotoForm(ContactsForm); return true; case MainMenuNode: FrmGotoForm(MainForm); return true; case MainMenuMap: FrmGotoForm(MapForm); return true; + case MainMenuStats: FrmGotoForm(StatsForm); return true; + case MainMenuPackets: FrmGotoForm(PacketsForm); return true; case MainMenuPorts: FrmGotoForm(PortsForm); return true; case MainMenuFontPreview: FrmGotoForm(FontPreviewForm); return true; case MainMenuSounds: SoundsFormOpen(FrmGetActiveFormID()); return true; @@ -101,6 +105,8 @@ static Boolean AppHandleEvent(EventType *event) case SoundsForm: FrmSetEventHandler(form, SoundsFormHandleEvent); break; case ScopesForm: FrmSetEventHandler(form, ScopesFormHandleEvent); break; case MapForm: FrmSetEventHandler(form, MapFormHandleEvent); break; + case StatsForm: FrmSetEventHandler(form, StatsFormHandleEvent); break; + case PacketsForm: FrmSetEventHandler(form, PacketsFormHandleEvent); break; } return true; } @@ -236,6 +242,10 @@ static void Poll(void) FrmUpdateForm(formId, VM_UPDATE_DATA); if (formId == ConvoForm) ConvoFormIdle(); + else if (formId == StatsForm) + StatsFormIdle(); + else if (formId == PacketsForm) + PacketsFormIdle(); } static void AppEventLoop(void) diff --git a/palm-client/src/msg_menu.c b/palm-client/src/msg_menu.c index 6020f2f..7236da8 100644 --- a/palm-client/src/msg_menu.c +++ b/palm-client/src/msg_menu.c @@ -8,6 +8,7 @@ #include "app.h" #include "ui/text.h" #include "ui/emoji.h" +#include "info_fmt.h" #include "msg_menu.h" static Int16 Popup(const RectangleType *b, UInt16 listId, UInt16 areaId, Char **items, UInt16 n) VM_SECT3; @@ -16,7 +17,6 @@ static UInt16 React(UInt16 msg) VM_SECT3; static UInt16 Reply(UInt16 msg, UInt16 fieldId) VM_SECT3; static void SendDm(const Char *name) VM_SECT3; static void PathDetails(UInt16 msg) VM_SECT3; -static void AppendClock(Char *out, const Char *label, UInt32 utc) VM_SECT3; static Boolean Matches(const VmReact *r, const UInt8 *hash, const Char *name, Boolean channel) VM_SECT3; #define ACT_REACT 0 @@ -220,29 +220,14 @@ static void SendDm(const Char *name) AppOpenConversation(&conv); } -/* "label HH:MM:SS" in local time, and the date if it isn't today. */ -static void AppendClock(Char *out, const Char *label, UInt32 utc) -{ - DateTimeType dt, now; - - TimSecondsToDateTime(SessionLocalPalm(utc), &dt); - TimSecondsToDateTime(SessionLocalPalm(SessionNow()), &now); - out += StrLen(out); - if (dt.year != now.year || dt.month != now.month || dt.day != now.day) - StrPrintF(out, "%s %u/%u %02u:%02u:%02u", label, dt.month, dt.day, dt.hour, dt.minute, dt.second); - else - StrPrintF(out, "%s %02u:%02u:%02u", label, dt.hour, dt.minute, dt.second); -} - static void PathDetails(UInt16 msg) { const VmMsgHeader *h = MessagesLock(msg); VmMsgHeader hdr; VmMsgExtra ex; - VmContact c; Boolean hasEx; - Char text[300], hex[8], snr[8]; - UInt16 i, hops, len; + Char text[300], snr[8]; + UInt16 hops; if (!h) return; @@ -251,7 +236,7 @@ static void PathDetails(UInt16 msg) hasEx = MessagesExtra(msg, &ex); text[0] = 0; if (hdr.dir == VM_DIR_OUT) { - AppendClock(text, "Sent", hdr.timestamp); + InfoClock(text, sizeof(text), "Sent", hdr.timestamp); StrCat(text, "\n"); switch (hdr.status) { case VM_ST_PENDING: StrCat(text, "Waiting for the radio"); break; @@ -262,9 +247,9 @@ static void PathDetails(UInt16 msg) FrmCustomAlert(PathAlert, text, "", ""); return; } - AppendClock(text, "Sent", hdr.timestamp); /* the sender's clock */ + InfoClock(text, sizeof(text), "Sent", hdr.timestamp); /* the sender's clock */ StrCat(text, "\n"); - AppendClock(text, "Got", hdr.received); + InfoClock(text, sizeof(text), "Got", hdr.received); StrCat(text, "\n"); hops = VM_PATH_HOPS(hdr.pathLen); if (hdr.pathLen == VM_PATH_UNKNOWN) @@ -281,22 +266,7 @@ static void PathDetails(UInt16 msg) StrCat(text, "Repeaters not recorded"); } else { StrCat(text, "Via"); - for (i = 0; i + ex.hashSize <= ex.pathBytes; i += ex.hashSize) { - if (StrLen(text) > sizeof(text) - 80) { /* room for one more entry and the end */ - StrCat(text, ", ..."); - break; - } - TxtHex(ex.path + i, ex.hashSize, hex); - StrCat(text, i ? ", " : " "); - StrCat(text, hex); - if (ContactsFindByPrefixN(ex.path + i, ex.hashSize, &c)) { - len = StrLen(text); - StrCat(text, " "); - StrNCat(text, c.name, len + 1 + 12 + 1); /* up to 12 of the name */ - } - } - if (ex.hops * ex.hashSize > ex.pathBytes) - StrPrintF(text + StrLen(text), " +%u more", ex.hops - ex.pathBytes / ex.hashSize); + InfoVia(text, sizeof(text), ex.path, ex.pathBytes, ex.hashSize, ex.hops); } FrmCustomAlert(PathAlert, text, "", ""); } diff --git a/palm-client/src/node_form.c b/palm-client/src/node_form.c index 7cc4605..78fc4c0 100644 --- a/palm-client/src/node_form.c +++ b/palm-client/src/node_form.c @@ -217,6 +217,9 @@ Boolean NodeFormHandleEvent(EventType *event) case MainAdvertButton: SendAdvert(); return true; + case MainStatsButton: + FrmGotoForm(StatsForm); + return true; case MainDoneButton: FrmGotoForm(HomeForm); return true; diff --git a/palm-client/src/packets_form.c b/palm-client/src/packets_form.c new file mode 100644 index 0000000..e1e60d3 --- /dev/null +++ b/palm-client/src/packets_form.c @@ -0,0 +1,227 @@ +/* + * Heard Packets: the last packets the radio received (its RX log pushes), + * newest first, with what kind, the route, the signal and who it was from or + * came through. All, Chat (direct and channel messages) or Adverts. A tap + * shows one in full. Kept in memory while the app runs. + */ +#include +#include "resources.h" +#include "session.h" +#include "contacts.h" +#include "info_fmt.h" +#include "ui/draw.h" +#include "ui/text.h" +#include "ui/rowlist.h" +#include "packets_form.h" + +static Boolean Shown(const VmRxLog *rx) VM_SECT5; +static void Filter(void) VM_SECT5; +static const Char *TypeName(UInt8 type) VM_SECT5; +static void DrawRow(UInt16 row, const RectangleType *b, void *ctx) VM_SECT5; +static void Details(UInt16 row) VM_SECT5; +static void Reload(Boolean draw) VM_SECT5; + +#define PKT_MAX 40 + +#define SHOW_ALL 0 +#define SHOW_CHAT 1 +#define SHOW_ADVERTS 2 + +typedef struct { + UInt32 time; + VmRxLog rx; +} Packet; + +static Packet gPkts[PKT_MAX]; +static UInt16 gCount = 0, gNext = 0; +static UInt32 gNoted = 0; /* bumped per packet, so an open screen knows to reload */ +static UInt32 gShownNoted; +static UInt8 gShow = SHOW_ALL; +static UInt8 gRows[PKT_MAX]; /* shown rows: indexes into gPkts, newest first */ +static UInt16 gRowCount; +static RowList gList; + +void PacketsNote(const VmRxLog *rx, UInt32 now) +{ + gPkts[gNext].time = now; + gPkts[gNext].rx = *rx; + gNext = (gNext + 1) % PKT_MAX; + if (gCount < PKT_MAX) + gCount++; + gNoted++; +} + +static Boolean Shown(const VmRxLog *rx) +{ + switch (gShow) { + case SHOW_CHAT: return rx->payloadType == VM_PAYLOAD_TXT || rx->payloadType == VM_PAYLOAD_GRP_TXT; + case SHOW_ADVERTS: return rx->payloadType == VM_PAYLOAD_ADVERT; + } + return true; +} + +static void Filter(void) +{ + UInt16 i, k; + + gRowCount = 0; + for (i = 0; i < gCount; i++) { + k = (gNext + PKT_MAX - 1 - i) % PKT_MAX; + if (Shown(&gPkts[k].rx)) + gRows[gRowCount++] = (UInt8)k; + } +} + +/* MeshCore's payload types (Packet.h). A switch, not a table: sections.h. */ +static const Char *TypeName(UInt8 type) +{ + switch (type) { + case 0: return "Request"; + case 1: return "Response"; + case 2: return "DM"; + case 3: return "Ack"; + case 4: return "Advert"; + case 5: return "Channel"; + case 6: return "Ch data"; + case 7: return "Anon req"; + case 8: return "Path"; + case 9: return "Trace"; + case 10: return "Multipart"; + case 11: return "Control"; + case 15: return "Raw"; + } + return "Other"; +} + +/* "17:32:05 Advert 3 hops 6.2 dB" and who it's from or came through. */ +static void DrawRow(UInt16 row, const RectangleType *b, void *ctx) +{ + const Packet *p = &gPkts[gRows[row]]; + const VmRxLog *rx = &p->rx; + FontID old = FntSetFont(vmSmallFont); + Coord x = b->topLeft.x + 1, y = b->topLeft.y, right = b->topLeft.x + b->extent.x - 1; + DateTimeType dt; + VmContact c; + Char line[48], snr[8]; + Coord left; + + TimSecondsToDateTime(SessionLocalPalm(p->time), &dt); + StrPrintF(line, "%02u:%02u:%02u", dt.hour, dt.minute, dt.second); + WinDrawChars(line, StrLen(line), x, y); + WinDrawChars(TypeName(rx->payloadType), StrLen(TypeName(rx->payloadType)), x + 34, y); + if (!rx->flood) + StrCopy(line, "direct"); + else + StrPrintF(line, "%u hop%s", rx->hops, rx->hops == 1 ? "" : "s"); + WinDrawChars(line, StrLen(line), x + 72, y); + TxtFormatSnr(snr, (Int8)rx->snrQ); + left = DrawRight(snr, right, y); + /* an advert's node, else the last relay, by name if we know it */ + line[0] = 0; + if (rx->isAdvert && ContactsFindByPrefixN(rx->advertKey, 6, &c)) + StrCopy(line, c.name); + else if (rx->fromLen && rx->fromLen <= 3) + InfoHop(line, sizeof(line), rx->from, rx->fromLen); + if (line[0]) + DrawCut(line, x + 104, y, left - 3 - (x + 104)); + FntSetFont(old); +} + +static void Details(UInt16 row) +{ + const Packet *p = &gPkts[gRows[row]]; + const VmRxLog *rx = &p->rx; + VmContact c; + Char text[240], snr[8], hex[16]; + + StrCopy(text, TypeName(rx->payloadType)); + if (rx->isAdvert) { + TxtHex(rx->advertKey, 6, hex); + StrCat(text, " from "); + if (ContactsFindByPrefixN(rx->advertKey, 6, &c)) { + StrNCat(text, c.name, StrLen(text) + 20); + StrCat(text, " "); + } + StrCat(text, hex); + } else if (rx->payloadType == VM_PAYLOAD_TXT && rx->payloadLen >= 2) { + /* a DM names its ends by the first byte of their keys */ + TxtHex(rx->payload, 1, hex); + StrPrintF(text + StrLen(text), " to %s", hex); + TxtHex(rx->payload + 1, 1, hex); + StrPrintF(text + StrLen(text), " from %s", hex); + } + StrCat(text, "\n"); + InfoClock(text, sizeof(text), "Heard", p->time); + TxtFormatSnr(snr, (Int8)rx->snrQ); + StrPrintF(text + StrLen(text), "\nSNR %s, RSSI %d dBm\n", snr, (Int16)rx->rssi); + if (!rx->flood) { + StrCat(text, "Sent direct"); + if (rx->hops) { + StrCat(text, ", route left:"); + InfoVia(text, sizeof(text), rx->path, rx->pathBytes, rx->hashSize, rx->hops); + } + } else if (rx->hops == 0) { + StrCat(text, "Flood, heard from its sender"); + } else { + StrPrintF(text + StrLen(text), "Flood, %u hop%s via", rx->hops, rx->hops == 1 ? "" : "s"); + InfoVia(text, sizeof(text), rx->path, rx->pathBytes, rx->hashSize, rx->hops); + } + FrmCustomAlert(PacketAlert, text, "", ""); +} + +static void Reload(Boolean draw) +{ + Filter(); + gShownNoted = gNoted; + RowListSetCount(&gList, gRowCount); + if (draw) + RowListDraw(&gList); +} + +Boolean PacketsFormHandleEvent(EventType *event) +{ + FormType *form = FrmGetActiveForm(); + Int16 tapped = -1; + UInt16 id; + + switch (event->eType) { + case frmOpenEvent: + RowListInit(&gList, PacketsGadget, PacketsScroll, VM_ROW_H, DrawRow, NULL, NULL); + id = gShow == SHOW_CHAT ? PacketsMsgPush : gShow == SHOW_ADVERTS ? PacketsAdvertPush : PacketsAllPush; + FrmSetControlGroupSelection(form, PacketsFilterGroup, id); + Reload(false); + FrmDrawForm(form); + RowListDraw(&gList); + return true; + case frmUpdateEvent: + if (event->data.frmUpdate.updateCode == frmRedrawUpdateCode) + FrmDrawForm(form); + Reload(true); + return true; + case ctlSelectEvent: + switch (event->data.ctlSelect.controlID) { + case PacketsAllPush: gShow = SHOW_ALL; Reload(true); return true; + case PacketsMsgPush: gShow = SHOW_CHAT; Reload(true); return true; + case PacketsAdvertPush: gShow = SHOW_ADVERTS; Reload(true); return true; + case PacketsDoneButton: + FrmGotoForm(HomeForm); + return true; + } + break; + default: + break; + } + if (RowListHandleEvent(&gList, event, &tapped)) { + if (tapped >= 0) + Details((UInt16)tapped); + return true; + } + return false; +} + +void PacketsFormIdle(void) +{ + /* newest first: keep the top in view as packets arrive */ + if (gShownNoted != gNoted && gList.top == 0) + Reload(true); +} diff --git a/palm-client/src/packets_form.h b/palm-client/src/packets_form.h new file mode 100644 index 0000000..9dbc31a --- /dev/null +++ b/palm-client/src/packets_form.h @@ -0,0 +1,15 @@ +/* Heard Packets (Go menu): the last packets the radio received, from its RX log pushes. */ +#ifndef VM_PACKETS_FORM_H +#define VM_PACKETS_FORM_H + +#include +#include "sections.h" /* this module is in the fifth code segment */ +#include "protocol.h" + +/* Every RX log push (session.c), whatever screen is open. */ +void PacketsNote(const VmRxLog *rx, UInt32 now) VM_SECT5; +Boolean PacketsFormHandleEvent(EventType *event) VM_SECT5; +/* On idle events while the screen is open: shows new packets when it's at the top. */ +void PacketsFormIdle(void) VM_SECT5; + +#endif diff --git a/palm-client/src/resources.h b/palm-client/src/resources.h index cc9114e..bbc59e4 100644 --- a/palm-client/src/resources.h +++ b/palm-client/src/resources.h @@ -33,6 +33,16 @@ #define MainMenuAbout 1019 #define MainMenuConnect 1021 /* also a tap on "offline" in the title */ #define MainMenuMessage 1022 /* conversations: the newest message's actions (convo_form.c) */ +#define MainMenuStats 1023 /* Go: Radio Stats */ +#define MainMenuPackets 1024 /* Go: Heard Packets */ +#define MainMenuTrace 1025 /* Go: Trace Path */ +#define MainMenuMention 1026 /* conversations: insert a @mention */ +#define MainMenuBeamChannel 1027 /* Channel: beam it */ +#define ContactsMenuBar 1028 /* Go, Contacts (Beam, Blocked, Stale), Options */ +#define MainMenuStale 1029 +#define MainMenuBlocked 1030 +#define MainMenuBeamSelf 1031 +#define MainStatsButton 1040 #define AboutAlert 1020 #define ConvoChanMenuBar 1014 /* Go, Edit, Channel (Add, Leave, Mute, Scope), Options */ #define ConvoMenuBar 1017 /* Go, Edit, Options: a DM, the console */ @@ -67,6 +77,7 @@ #define ContactsRefreshButton 1303 #define ContactsDoneButton 1304 #define ContactsAddButton 1305 +#define ContactsBlockedList 1306 /* Contacts > Blocked Senders popup */ #define ContactForm 1800 #define ContactGadget 1801 @@ -116,6 +127,7 @@ #define ConvoSendButton 1604 #define ConvoBackButton 1605 #define ConvoActionList 1606 /* tap-and-hold popup (msg_menu.c) */ +#define ConvoMentionList 1609 /* "@" or Options > Insert Mention (mention.c) */ #define PathAlert 1607 #define ReactionsAlert 1608 @@ -174,6 +186,42 @@ #define MapInButton 2504 #define MapAlert 2505 +#define StatsForm 2600 +#define StatsDoneButton 2601 + +#define PacketsForm 2700 +#define PacketsGadget 2701 +#define PacketsScroll 2702 +#define PacketsDoneButton 2703 +#define PacketsAllPush 2704 +#define PacketsMsgPush 2705 +#define PacketsAdvertPush 2706 +#define PacketsFilterGroup 6 +#define PacketAlert 2707 + +#define TraceForm 2800 +#define TraceField 2801 +#define TraceAddButton 2802 +#define TraceHopList 2803 +#define TraceRoundCheck 2804 +#define TraceGadget 2805 +#define TraceScroll 2806 +#define TraceGoButton 2807 +#define TraceRouteButton 2808 +#define TraceDoneButton 2809 +#define TraceForLabel 2810 +#define TraceRouteAlert 2811 +#define PingAlert 2812 + +#define StaleAlert 2900 +#define StaleConfirmAlert 2901 +#define BlockAlert 2902 +#define UnblockAlert 2903 +#define InboxContactAlert 2904 +#define InboxChannelAlert 2905 +#define HashtagAlert 2906 +#define NoteAlert 2907 /* a plain message with an OK button (^1) */ + #define SmallFontRes 1000 #define LargeFontRes 1001 #define EmojiArtRes 1002 diff --git a/palm-client/src/session.c b/palm-client/src/session.c index dbcb20e..7d3562f 100644 --- a/palm-client/src/session.c +++ b/palm-client/src/session.c @@ -19,6 +19,8 @@ #include "rxpath.h" #include "reactions.h" #include "reaction_fmt.h" +#include "protocol2.h" +#include "packets_form.h" #define VM_APP_NAME "VisorMesh" #define VM_REPLY_TIMEOUT (2 * SysTicksPerSecond()) @@ -122,6 +124,7 @@ static void HandlePush(void) if (VmParseRxLog(gDecoder.payload, gDecoder.len, &rx)) { HeardRecord(&rx, SessionNow()); RxPathNote(&rx, SessionNow()); + PacketsNote(&rx, SessionNow()); } } else if (code == VM_PUSH_ADVERT || code == VM_PUSH_NEW_ADVERT || code == VM_PUSH_PATH_UPDATED) { /* NEW_ADVERT is the radio's first sight of a node (MyMesh::onDiscoveredContact is_new) */ @@ -898,6 +901,58 @@ Err SessionRetry(UInt16 index) return SendRecord(index); } +Err SessionQuery(const UInt8 *frame, UInt16 len, UInt8 code, UInt8 *reply, UInt16 size, UInt16 *got) +{ + Err err; + + if (!gConnected) + return serErrNotOpen; + if (len == 0) + return vmErrBadReply; + err = Request(frame, len, code, 2); + if (err != errNone) + return err; + *got = gDecoder.len < size ? gDecoder.len : size; + MemMove(reply, gDecoder.payload, *got); + return errNone; +} + +Err SessionTrace(const UInt8 *path, UInt16 pathBytes, UInt8 hashSize, VmTrace *out, UInt32 *tripMs) +{ + static const UInt8 sentCode[] = { VM_RESP_SENT }; + static const UInt8 traceCode[] = { VM_PUSH_TRACE_DATA }; + UInt8 frame[VM_HEADER_LEN + 10 + VM_TRACE_MAX]; + UInt32 tag = TimGetTicks() ^ ((UInt32)SysRandom(0) << 16) ^ TimGetSeconds(), start, deadline; + UInt16 len = VmBuildTrace(frame, sizeof(frame), tag, hashSize, path, pathBytes); + VmSent sent; + Err err; + + if (!gConnected) + return serErrNotOpen; + if (len == 0) + return vmErrTooLong; + start = TimGetTicks(); + /* one try: a repeated trace would go out twice */ + err = RequestAny(frame, len, sentCode, 1, 1); + if (err == errNone && !VmParseSent(gDecoder.payload, gDecoder.len, &sent)) + err = vmErrBadReply; + if (err != errNone) + return err; + /* the radio's estimate for the whole path, plus slack */ + deadline = start + (sent.timeoutMs + 2000UL) / 1000UL * SysTicksPerSecond(); + for (;;) { + err = WaitForAny(traceCode, 1, (Int32)(deadline - TimGetTicks())); + if (err != errNone) + return err; + if (VmParseTrace(gDecoder.payload, gDecoder.len, out) && out->tag == tag) + break; + if ((Int32)(TimGetTicks() - deadline) >= 0) + return vmErrNoReply; + } + *tripMs = (TimGetTicks() - start) * 1000UL / SysTicksPerSecond(); + return errNone; +} + /* After a quiet minute, asks the radio the time, so a lost link shows (RequestAny) while idle. */ #define VM_QUIET_TICKS (60 * SysTicksPerSecond()) diff --git a/palm-client/src/session.h b/palm-client/src/session.h index 5ef07b9..993d548 100644 --- a/palm-client/src/session.h +++ b/palm-client/src/session.h @@ -9,6 +9,7 @@ #include #include "protocol.h" #include "messages.h" +#include "protocol2.h" #define vmErrNoReply (appErrorClass | 1) /* radio didn't answer in time */ #define vmErrRadio (appErrorClass | 2) /* radio replied RESP_ERR */ @@ -71,6 +72,17 @@ Err SessionSetDefaultScope(const Char *name); Err SessionAskRegions(const UInt8 *pubKey, Char *names, UInt16 size); const VmSelfInfo *SessionSelf(void); +/* + * Sends a request whose reply has this code (safe to repeat: reads, two + * tries) and copies up to size bytes of the reply (code byte first). + */ +Err SessionQuery(const UInt8 *frame, UInt16 len, UInt8 code, UInt8 *reply, UInt16 size, UInt16 *got); +/* + * Sends a trace along path (protocol2.h: it must lead back to us) and waits + * for its answer: vmErrNoReply if none came in the radio's estimate. tripMs + * is from the send to the answer. + */ +Err SessionTrace(const UInt8 *path, UInt16 pathBytes, UInt8 hashSize, VmTrace *out, UInt32 *tripMs); /* Sends a complete command frame and requires RESP_OK. */ Err SessionCommand(const UInt8 *frame, UInt16 len); /* diff --git a/palm-client/src/stats_form.c b/palm-client/src/stats_form.c new file mode 100644 index 0000000..d5fac80 --- /dev/null +++ b/palm-client/src/stats_form.c @@ -0,0 +1,214 @@ +/* + * Radio Stats: what the companion radio reports about itself (battery, + * storage, uptime, queue, last signal, airtime, packet counts) and a graph + * of its noise floor, read every few seconds while the screen is open. The + * noise samples are kept for the session, so the graph carries on when the + * screen is opened again. + */ +#include +#include "resources.h" +#include "session.h" +#include "protocol2.h" +#include "ui/draw.h" +#include "ui/text.h" +#include "stats_form.h" + +static void Read(void) VM_SECT5; +static void FormatSecs(Char *out, UInt32 s) VM_SECT5; +static void DrawText(Coord y, const Char *s) VM_SECT5; +static void DrawGraph(const RectangleType *g) VM_SECT5; +static void Draw(void) VM_SECT5; + +#define STATS_EVERY (5 * SysTicksPerSecond()) +#define NOISE_MAX 60 /* samples: 5 minutes */ +#define GRAPH_TOP 94 +#define GRAPH_H 40 + +static VmStats gStats; +static VmBattery gBatt; +static Boolean gHasBatt; +static Err gErr; +static UInt32 gReadAt; +static Int16 gNoise[NOISE_MAX]; +static UInt16 gNoiseCount = 0, gNoiseNext = 0; + +static void Read(void) +{ + UInt8 frame[VM_HEADER_LEN + 2], reply[32]; + UInt16 len, got, t; + Err err; + + gReadAt = TimGetTicks(); + MemSet(&gStats, sizeof(gStats), 0); + gErr = errNone; + if (!SessionIsConnected()) { + gErr = serErrNotOpen; + return; + } + len = VmBuildCode(frame, sizeof(frame), VM_CMD_GET_BATT_AND_STORAGE); + gHasBatt = SessionQuery(frame, len, VM_RESP_BATT_AND_STORAGE, reply, sizeof(reply), &got) == errNone && + VmParseBattery(reply, got, &gBatt); + for (t = VM_STATS_CORE; t <= VM_STATS_PACKETS; t++) { + len = VmBuildGetStats(frame, sizeof(frame), (UInt8)t); + err = SessionQuery(frame, len, VM_RESP_STATS, reply, sizeof(reply), &got); + if (err == errNone) + VmParseStats(reply, got, &gStats); + else + gErr = err; + } + if (gStats.hasRadio) { + gNoise[gNoiseNext] = gStats.noiseFloor; + gNoiseNext = (gNoiseNext + 1) % NOISE_MAX; + if (gNoiseCount < NOISE_MAX) + gNoiseCount++; + } +} + +/* "45s", "12m", "3h 20m", "2d 4h" */ +static void FormatSecs(Char *out, UInt32 s) +{ + if (s < 60) + StrPrintF(out, "%lus", s); + else if (s < 3600) + StrPrintF(out, "%lum", s / 60); + else if (s < 86400UL) + StrPrintF(out, "%luh %lum", s / 3600, s / 60 % 60); + else + StrPrintF(out, "%lud %luh", s / 86400UL, s / 3600 % 24); +} + +static void DrawText(Coord y, const Char *s) +{ + WinDrawChars(s, StrLen(s), 3, y); +} + +/* The noise floor samples, oldest at the left; the scale fits what's there, at least 10 dB. */ +static void DrawGraph(const RectangleType *g) +{ + Int16 lo = 0, hi = 0, v, i, k; + Coord x, y, w = g->extent.x, h = g->extent.y; + Char s[12]; + + for (i = 0; i < (Int16)gNoiseCount; i++) { + v = gNoise[i]; + if (i == 0 || v < lo) + lo = v; + if (i == 0 || v > hi) + hi = v; + } + if (hi - lo < 10) { + lo = (lo + hi) / 2 - 5; + hi = lo + 10; + } + WinDrawGrayLine(g->topLeft.x, g->topLeft.y + h - 1, g->topLeft.x + w - 1, g->topLeft.y + h - 1); + WinDrawGrayLine(g->topLeft.x, g->topLeft.y, g->topLeft.x + w - 1, g->topLeft.y); + StrPrintF(s, "%d", hi); + DrawRight(s, g->topLeft.x + w + 22, g->topLeft.y - 4); + StrPrintF(s, "%d", lo); + DrawRight(s, g->topLeft.x + w + 22, g->topLeft.y + h - 7); + for (i = 0; i < (Int16)gNoiseCount; i++) { + k = (Int16)((gNoiseNext + NOISE_MAX - gNoiseCount + i) % NOISE_MAX); + x = g->topLeft.x + w - ((Int16)gNoiseCount - i) * (w / NOISE_MAX); + y = g->topLeft.y + h - 1 - (Coord)((Int32)(gNoise[k] - lo) * (h - 1) / (hi - lo)); + WinDrawLine(x, y, x, g->topLeft.y + h - 1); + if (w / NOISE_MAX > 1) + WinDrawLine(x + 1, y, x + 1, g->topLeft.y + h - 1); + } +} + +static void Draw(void) +{ + FontID old = FntSetFont(vmSmallFont); + RectangleType r; + Char line[48], a[16], b[16], snr[8]; + Coord y = 18, step = VM_ROW_H; + + RctSetRectangle(&r, 0, 16, 160, 127); + WinEraseRectangle(&r, 0); + if (gErr == serErrNotOpen) { + DrawText(y, "Connect to the radio first (Node)."); + FntSetFont(old); + return; + } + if (gHasBatt) { + StrPrintF(line, "Battery %u.%02u V", gBatt.battMv / 1000, (gBatt.battMv % 1000) / 10); + if (gBatt.hasStorage) + StrPrintF(line + StrLen(line), ", storage %lu of %lu KB", gBatt.usedKb, gBatt.totalKb); + DrawText(y, line); + y += step; + } + if (gStats.hasCore) { + FormatSecs(a, gStats.uptimeSecs); + StrPrintF(line, "Up %s, %u queued", a, gStats.queueLen); + if (gStats.errFlags) + StrPrintF(line + StrLen(line), ", errors %x", gStats.errFlags); + DrawText(y, line); + y += step; + } + if (gStats.hasRadio) { + TxtFormatSnr(snr, gStats.lastSnrQ); + StrPrintF(line, "Noise %d dBm, last heard %d dBm %s", gStats.noiseFloor, (Int16)gStats.lastRssi, snr); + DrawText(y, line); + y += step; + FormatSecs(a, gStats.txAirSecs); + FormatSecs(b, gStats.rxAirSecs); + StrPrintF(line, "Airtime: sending %s, receiving %s", a, b); + DrawText(y, line); + y += step; + } + if (gStats.hasPackets) { + StrPrintF(line, "Received %lu: %lu flood, %lu direct", gStats.recv, gStats.recvFlood, gStats.recvDirect); + DrawText(y, line); + y += step; + StrPrintF(line, "Sent %lu: %lu flood, %lu direct", gStats.sent, gStats.sentFlood, gStats.sentDirect); + DrawText(y, line); + y += step; + } + if (!gStats.hasCore && !gStats.hasRadio && !gStats.hasPackets) { + DrawText(y, gErr == vmErrRadio ? "This firmware doesn't report stats." : "The radio didn't answer."); + FntSetFont(old); + return; + } + DrawSection("noise floor, dBm, last 5 min", 0, GRAPH_TOP - 12, 160); + RctSetRectangle(&r, 3, GRAPH_TOP, 130, GRAPH_H); + if (gNoiseCount) + DrawGraph(&r); + FntSetFont(old); +} + +void StatsFormIdle(void) +{ + if (TimGetTicks() - gReadAt >= STATS_EVERY) { + Read(); + Draw(); + } +} + +Boolean StatsFormHandleEvent(EventType *event) +{ + FormType *form = FrmGetActiveForm(); + + switch (event->eType) { + case frmOpenEvent: + FrmDrawForm(form); + Read(); + Draw(); + return true; + case frmUpdateEvent: + /* new messages and contacts don't change what's shown: the next read does */ + if (event->data.frmUpdate.updateCode == frmRedrawUpdateCode) { + FrmDrawForm(form); + Draw(); + } + return true; + case ctlSelectEvent: + if (event->data.ctlSelect.controlID == StatsDoneButton) { + FrmGotoForm(MainForm); + return true; + } + break; + default: + break; + } + return false; +} diff --git a/palm-client/src/stats_form.h b/palm-client/src/stats_form.h new file mode 100644 index 0000000..5f9632b --- /dev/null +++ b/palm-client/src/stats_form.h @@ -0,0 +1,12 @@ +/* Radio Stats (Go menu, or Stats on Node): the companion radio's own report and its noise floor. */ +#ifndef VM_STATS_FORM_H +#define VM_STATS_FORM_H + +#include +#include "sections.h" /* this module is in the fifth code segment */ + +Boolean StatsFormHandleEvent(EventType *event) VM_SECT5; +/* On idle events while the screen is open: reads the radio again every few seconds. */ +void StatsFormIdle(void) VM_SECT5; + +#endif