From 8f42003e3661bef447eeaaefb07052d8f126a867 Mon Sep 17 00:00:00 2001 From: "pls.153" Date: Wed, 9 Aug 2023 09:45:05 +0200 Subject: [PATCH] example 'meshtastic': handle faulty bytes from radio; display exact date (tap); revisions --- examples/meshtastic/lisp/lora.lisp | 17 ++++++++++++----- examples/meshtastic/lisp/messages.lisp | 9 +++++++++ examples/meshtastic/lisp/package.lisp | 2 ++ examples/meshtastic/qml/ext/Group.qml | 2 +- examples/meshtastic/qml/ext/Messages.qml | 5 +++++ examples/meshtastic/readme-usage.md | 10 ++++++---- examples/meshtastic/readme.md | 5 ++--- 7 files changed, 37 insertions(+), 13 deletions(-) diff --git a/examples/meshtastic/lisp/lora.lisp b/examples/meshtastic/lisp/lora.lisp index da68f4d..c3b8973 100644 --- a/examples/meshtastic/lisp/lora.lisp +++ b/examples/meshtastic/lisp/lora.lisp @@ -31,6 +31,7 @@ (defvar *ready* nil) (defvar *reading* nil) (defvar *received* nil) +(defvar *received-faulty* nil) (defvar *schedule-clear* t) (defun to-bytes (list) @@ -101,7 +102,7 @@ (t (msg:check-utf8-length (q< |text| ui:*edit*)) (unless (q< |tooLong| ui:*edit*) - (incf msg:*message-id*) + (msg:message-id) (when (stringp *receiver*) (setf *receiver* (name-to-node *receiver*))) (send-to-radio @@ -139,10 +140,16 @@ (progn (setf *notify-id* bytes) (read-radio)) - (let ((from-radio (pr:deserialize-from-bytes 'me:from-radio bytes))) + (multiple-value-bind (from-radio error) + (ignore-errors (pr:deserialize-from-bytes 'me:from-radio bytes)) (setf *reading* t) - (pr:print-json from-radio) - (push from-radio *received*))) + (if from-radio + (progn + (pr:print-json from-radio) + (push from-radio *received*)) + (progn + (qlog "received faulty bytes: ~A" error) + (push bytes *received-faulty*))))) (values)) (defun receiving-done () ; see Qt @@ -279,7 +286,7 @@ (defun send-admin (admin-message) (send-to-radio (to-radio :to (me:num *my-node-info*) - :id (incf msg:*message-id*) + :id (msg:message-id) :hop-limit 3 :want-ack t :priority :reliable diff --git a/examples/meshtastic/lisp/messages.lisp b/examples/meshtastic/lisp/messages.lisp index dd2b66c..b5c0c5f 100644 --- a/examples/meshtastic/lisp/messages.lisp +++ b/examples/meshtastic/lisp/messages.lisp @@ -3,6 +3,9 @@ (defvar *message-id* 0) (defvar *states* '(:not-received :sending :received)) +(defun message-id () + (mod (incf *message-id*) #.(expt 2 32))) + (defun show-message-p (message) (let ((user (app:setting :latest-receiver))) (and user (or (string= user (getf message :receiver)) @@ -73,6 +76,12 @@ (app:toast (tr "message copied") 2) (values)) +(defun show-date (timestamp) ; see QML + (multiple-value-bind (sec min hour day month year) + (decode-universal-time (parse-integer timestamp)) + (app:toast (format nil "~D-~2,'0D-~2,'0D ~2,'0D:~2,'0D:~2,'0D" + year month day hour min sec)))) + (defun find-clicked () (let ((show (not (q< |visible| ui:*find-text*)))) (q> |visible| ui:*find-text* show) diff --git a/examples/meshtastic/lisp/package.lisp b/examples/meshtastic/lisp/package.lisp index 9eca34b..886f6bf 100644 --- a/examples/meshtastic/lisp/package.lisp +++ b/examples/meshtastic/lisp/package.lisp @@ -80,8 +80,10 @@ #:clear-find #:echo-message #:find-text + #:message-id #:message-press-and-hold #:receiver-changed + #:show-date #:show-messages)) (defpackage :radios diff --git a/examples/meshtastic/qml/ext/Group.qml b/examples/meshtastic/qml/ext/Group.qml index 8cb82a0..2efc96f 100644 --- a/examples/meshtastic/qml/ext/Group.qml +++ b/examples/meshtastic/qml/ext/Group.qml @@ -189,7 +189,7 @@ Rectangle { group.setProperty(index, "customName", text) Lisp.call("group:name-edited", model.radioName, text) if (text === "") text = qsTr("Anonym") - Qt.callLater(group.sortRenamed, text, index) + Qt.callLater(group.sortRenamed, text, index) // 'Qt.callLater': prevent UI thread related crash } } diff --git a/examples/meshtastic/qml/ext/Messages.qml b/examples/meshtastic/qml/ext/Messages.qml index c25c2b8..7e6d899 100644 --- a/examples/meshtastic/qml/ext/Messages.qml +++ b/examples/meshtastic/qml/ext/Messages.qml @@ -121,6 +121,11 @@ Rectangle { font.family: fontText.name color: "#505050" text: model.hour + + MouseArea { + anchors.fill: parent + onClicked: Lisp.call("msg:show-date", model.timestamp) + } } Text { diff --git a/examples/meshtastic/readme-usage.md b/examples/meshtastic/readme-usage.md index 84a7017..f8211f1 100644 --- a/examples/meshtastic/readme-usage.md +++ b/examples/meshtastic/readme-usage.md @@ -39,7 +39,9 @@ Messages The initial view shows the messages between you and a chosen person. You choose the desired person in the **Group** view (swipe to the left). -To copy a message to the clipboard, simply press-and-hold it. +To copy a message to the clipboard, press-and-hold it. + +To see the exact date of a message, tap on its hour. The search function (icon on the right) should be intuitive. The search term (case insensitive) is highlighted in red. Tap again on the search icon to leave @@ -115,9 +117,9 @@ any other device. The desktop data paths are: -* Linux: `~/.local/share/cl-meshtastic/data/` -* macOS: `~/Library/Application Support/cl-meshtastic/data/` -* Windows: TODO +* Linux: `/home//.local/share/cl-meshtastic/data/` +* macOS: `/Users//Library/Application Support/cl-meshtastic/data/` +* Windows: `C:\Users\\AppData\Local\cl-meshtastic\data\` Tips diff --git a/examples/meshtastic/readme.md b/examples/meshtastic/readme.md index 806cb14..d196729 100644 --- a/examples/meshtastic/readme.md +++ b/examples/meshtastic/readme.md @@ -57,9 +57,8 @@ The macOS version must be compiled first and started from Finder (not the console), otherwise BLE permissions will not work (if run from console, the app will show a BLE exception and consume 100% CPU). -It should also work on Windows >= 10, but this is not tested yet. - -Since this is WIP, it may currently not work on all platforms (e.g. mobile). +It should also work on Windows 10 and later, but the bluetooth part is not +tested yet.