mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 02:30:38 -08:00
example 'meshtastic': minor update (define device to be used)
This commit is contained in:
parent
9ee7030350
commit
c77d993496
11 changed files with 90 additions and 35 deletions
|
|
@ -1,6 +1,7 @@
|
|||
(defsystem :app
|
||||
:serial t
|
||||
:depends-on (#-depends-loaded :uiop
|
||||
#-depends-loaded :cl-base64
|
||||
#-depends-loaded :my-cl-protobufs
|
||||
#-depends-loaded :trivial-package-local-nicknames)
|
||||
:components ((:file "lisp/package")
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ void BLE::startDeviceDiscovery() {
|
|||
|
||||
void BLE::addDevice(const QBluetoothDeviceInfo& device) {
|
||||
if (deviceFilter(device)) {
|
||||
qDebug() << "device added: " << device.name();
|
||||
qDebug() << "device added:" << device.name() << device.address().toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,29 @@ QObject* ini() {
|
|||
return qt;
|
||||
}
|
||||
|
||||
static QBluetoothDeviceInfo toDeviceInfo(const QVariantMap& map) {
|
||||
return QBluetoothDeviceInfo(QBluetoothAddress(map.value("address").toString()),
|
||||
map.value("name").toString(),
|
||||
0);
|
||||
}
|
||||
|
||||
QT::QT() : QObject() {
|
||||
ble = new BLE_ME;
|
||||
}
|
||||
|
||||
QVariant QT::startDeviceDiscovery() {
|
||||
QVariant QT::setDevice(const QVariant& vMap) {
|
||||
auto map = vMap.value<QVariantMap>();
|
||||
ble->setCurrentDevice(toDeviceInfo(map));
|
||||
return vMap;
|
||||
}
|
||||
|
||||
QVariant QT::startDeviceDiscovery(const QVariant& vMap) {
|
||||
auto map = vMap.value<QVariantMap>();
|
||||
if (!map.isEmpty()) {
|
||||
ble->currentDevice = toDeviceInfo(map);
|
||||
}
|
||||
ble->startDeviceDiscovery();
|
||||
return QVariant();
|
||||
return vMap;
|
||||
}
|
||||
|
||||
QVariant QT::read2() {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ class QT : public QObject {
|
|||
|
||||
public:
|
||||
// BLE_ME
|
||||
Q_INVOKABLE QVariant startDeviceDiscovery();
|
||||
Q_INVOKABLE QVariant setDevice(const QVariant&);
|
||||
Q_INVOKABLE QVariant startDeviceDiscovery(const QVariant& = QVariant());
|
||||
Q_INVOKABLE QVariant read2();
|
||||
Q_INVOKABLE QVariant write2(const QVariant&);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
(in-package :app)
|
||||
|
||||
;; set here the name and address of your 2 devices
|
||||
;; (see debug output during device discovery)
|
||||
|
||||
(defvar *device-1* '(:name "Meshtastic_128c" :address "F4:12:FA:9D:12:8D"))
|
||||
(defvar *device-2* '(:name "Meshtastic_1c9c" :address "F4:12:FA:9D:1C:9D"))
|
||||
|
||||
(defun ini ()
|
||||
(qt:ini)
|
||||
(qt:start-device-discovery qt:*ble*)
|
||||
(qt:start-device-discovery qt:*ble* *device-1*) ; set device (see above)
|
||||
(msg:load-messages)
|
||||
(q> |playing| ui:*loading* nil) ; shown during Lisp startup
|
||||
(q> |playing| ui:*busy* t)) ; shown during BLE setup
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
(:local-nicknames (:pr :cl-protobufs)
|
||||
(:me :cl-protobufs.meshtastic))
|
||||
(:export
|
||||
#:*channel*
|
||||
#:*channels*
|
||||
#:*config-lora*
|
||||
#:*my-node-info*
|
||||
|
|
@ -17,13 +18,16 @@
|
|||
#:*received*
|
||||
#:*region*
|
||||
#:*remote-node*
|
||||
#:channel-to-url
|
||||
#:start-config
|
||||
#:read-radio
|
||||
#:received-from-radio
|
||||
#:receiving-done
|
||||
#:send-message
|
||||
#:send-to-radio
|
||||
#:set-ready))
|
||||
#:set-fixed-pin
|
||||
#:set-ready
|
||||
#:url-to-channel))
|
||||
|
||||
(defpackage :messages
|
||||
(:nicknames :msg)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
(:export
|
||||
#:*ble*
|
||||
#:ini
|
||||
#:set-device
|
||||
#:start-device-discovery
|
||||
#:read*
|
||||
#:write*))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
(defvar *region* :eu-868) ; Europe 868 MHz
|
||||
|
||||
(defvar *primary-channel* nil)
|
||||
(defvar *my-channel* nil)
|
||||
(defvar *channels* nil)
|
||||
(defvar *my-node-info* nil)
|
||||
(defvar *node-infos* nil)
|
||||
|
|
@ -109,8 +109,9 @@
|
|||
(dolist (struct *received*)
|
||||
(cond ((me:from-radio.has-packet struct)
|
||||
(let* ((packet (me:from-radio.packet struct))
|
||||
(decoded (me:decoded packet))
|
||||
(payload (me:payload decoded)))
|
||||
(decoded (me:decoded packet)))
|
||||
(when decoded
|
||||
(let ((payload (me:payload decoded)))
|
||||
(case (me:portnum decoded)
|
||||
;; text-message
|
||||
(:text-message-app
|
||||
|
|
@ -123,7 +124,7 @@
|
|||
(msg:change-state (case (me:routing.error-reason
|
||||
(pr:deserialize-from-bytes 'me:routing payload))
|
||||
(:none :received))
|
||||
(me:request-id decoded))))))
|
||||
(me:request-id decoded))))))))
|
||||
;; my-info
|
||||
((me:from-radio.has-my-info struct)
|
||||
(setf *my-node-info* (me:my-node-num (me:my-info struct))))
|
||||
|
|
@ -136,9 +137,9 @@
|
|||
;; channel
|
||||
((me:from-radio.has-channel struct)
|
||||
(let ((channel (me:channel struct)))
|
||||
(if (eql :primary (me:role channel))
|
||||
(setf *primary-channel* channel)
|
||||
(push channel *channels*))))
|
||||
(when (eql :primary (me:role channel))
|
||||
(setf *my-channel* channel))
|
||||
(push channel *channels*)))
|
||||
;; config lora
|
||||
((me:from-radio.has-config struct)
|
||||
(let ((config (me:config struct)))
|
||||
|
|
@ -163,6 +164,10 @@
|
|||
:payload (pr:serialize-to-bytes admin-message)
|
||||
:want-response t)))))
|
||||
|
||||
(defun set-channel (channel)
|
||||
(send-admin (me:make-admin-message
|
||||
:set-channel (setf *my-channel* channel))))
|
||||
|
||||
(defun config-device ()
|
||||
"Absolut minimum necessary for sending text messages."
|
||||
;; lora settings
|
||||
|
|
@ -175,8 +180,24 @@
|
|||
:hop-limit 3
|
||||
:tx-enabled t))))
|
||||
;; channel settings
|
||||
(send-admin
|
||||
(me:make-admin-message
|
||||
:set-channel (me:make-channel
|
||||
(set-channel (me:make-channel
|
||||
:settings (me:make-channel-settings :psk (to-bytes (list 1)))
|
||||
:role :primary))))
|
||||
:role :primary)))
|
||||
|
||||
(defun channel-to-url (&optional channel)
|
||||
(let ((base64 (base64:usb8-array-to-base64-string
|
||||
(pr:serialize-to-bytes (or channel *my-channel*)))))
|
||||
;; remove padding, substitute characters as by definition
|
||||
(x:cc "https:/meshtastic.org/e/#"
|
||||
(string-right-trim "=" (substitute #\- #\+ (substitute #\_ #\/ base64))))))
|
||||
|
||||
(defun url-to-channel (url &optional (set t))
|
||||
(let ((base64 (+ 2 (subseq "/#" url))))
|
||||
;; re-add padding
|
||||
(setf base64 (x:cc base64
|
||||
(make-string (mod (length base64) 4) :initial-element #\=)))
|
||||
(let ((channel (pr:deserialize-from-bytes
|
||||
(base64:base64-string-to-usb8-array base64))))
|
||||
(if set
|
||||
(set-channel channel)
|
||||
channel))))
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ restart the phone.
|
|||
On Linux you might need to restart the bluetooth service if you want to pair
|
||||
a different device (after already pairing a first one).
|
||||
|
||||
To choose which app instance will use which device, set both name and address
|
||||
in [main.lisp](lisp/main.lisp), and set one app to `*device-1*` and the other
|
||||
to `*device-2*`.
|
||||
|
||||
|
||||
|
||||
Run
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
asdf:*central-registry*)
|
||||
|
||||
(asdf:load-system :uiop)
|
||||
(asdf:load-system :cl-base64)
|
||||
(asdf:load-system :trivial-package-local-nicknames)
|
||||
|
||||
;; may take very long on mobile devices
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 216 KiB After Width: | Height: | Size: 201 KiB |
Loading…
Add table
Add a link
Reference in a new issue