mirror of
https://gitlab.com/eql/lqml.git
synced 2025-12-06 10:31:34 -08:00
example 'meshtastic': substitute Qt tile provider with Lisp one
This commit is contained in:
parent
d342d2c5a7
commit
2e63e44e46
11 changed files with 38 additions and 77 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
:serial t
|
:serial t
|
||||||
:depends-on (#-depends-loaded :my-cl-protobufs
|
:depends-on (#-depends-loaded :my-cl-protobufs
|
||||||
#-depends-loaded :trivial-package-local-nicknames
|
#-depends-loaded :trivial-package-local-nicknames
|
||||||
|
#-depends-loaded :usocket-server
|
||||||
#+mobile :s-http-server
|
#+mobile :s-http-server
|
||||||
#+mobile :zip) ; see 'hacks/zip/'
|
#+mobile :zip) ; see 'hacks/zip/'
|
||||||
:components ((:file "lisp/meshtastic-proto")
|
:components ((:file "lisp/meshtastic-proto")
|
||||||
|
|
@ -18,5 +19,6 @@
|
||||||
(:file "lisp/radios")
|
(:file "lisp/radios")
|
||||||
(:file "lisp/lora")
|
(:file "lisp/lora")
|
||||||
(:file "lisp/location")
|
(:file "lisp/location")
|
||||||
|
(:file "lisp/tile-provider")
|
||||||
(:file "lisp/main")))
|
(:file "lisp/main")))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ HEADERS += \
|
||||||
../../src/cpp/main.h \
|
../../src/cpp/main.h \
|
||||||
cpp/ble.h \
|
cpp/ble.h \
|
||||||
cpp/ble_meshtastic.h \
|
cpp/ble_meshtastic.h \
|
||||||
cpp/tile_provider.h \
|
|
||||||
cpp/qt.h
|
cpp/qt.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#include "qt.h"
|
#include "qt.h"
|
||||||
#include "ble_meshtastic.h"
|
#include "ble_meshtastic.h"
|
||||||
#include "tile_provider.h"
|
|
||||||
#include <ecl_fun.h>
|
#include <ecl_fun.h>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
#include <QSqlError>
|
#include <QSqlError>
|
||||||
|
|
@ -182,14 +181,4 @@ QVariant QT::localIp() {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant QT::startTileProvider() {
|
|
||||||
static bool start = true;
|
|
||||||
if (start) {
|
|
||||||
start = false;
|
|
||||||
int port = 1702;
|
|
||||||
new TileProvider(port);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ public:
|
||||||
// etc
|
// etc
|
||||||
Q_INVOKABLE QVariant dataPath();
|
Q_INVOKABLE QVariant dataPath();
|
||||||
Q_INVOKABLE QVariant localIp();
|
Q_INVOKABLE QVariant localIp();
|
||||||
Q_INVOKABLE QVariant startTileProvider();
|
|
||||||
|
|
||||||
QT();
|
QT();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ MOC_DIR = ./tmp/
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
ble.h \
|
ble.h \
|
||||||
ble_meshtastic.h \
|
ble_meshtastic.h \
|
||||||
tile_provider.h \
|
|
||||||
qt.h
|
qt.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QTcpServer>
|
|
||||||
#include <QTcpSocket>
|
|
||||||
#include <QtDebug>
|
|
||||||
|
|
||||||
// trivial local tile provider which doesn't need an API key
|
|
||||||
// (default Qt provider requires an API key from thunderforest.com)
|
|
||||||
|
|
||||||
class TileProvider : public QTcpServer {
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
TileProvider(int port = 0, QObject* parent = nullptr) : QTcpServer(parent) {
|
|
||||||
listen(QHostAddress::Any, port);
|
|
||||||
qDebug() << "tile provider started at IP" << serverAddress() << "port" << serverPort();
|
|
||||||
}
|
|
||||||
|
|
||||||
void incomingConnection(qintptr socket) override {
|
|
||||||
QTcpSocket* s = new QTcpSocket(this);
|
|
||||||
connect(s, &QTcpSocket::readyRead, this, &TileProvider::readClient);
|
|
||||||
connect(s, &QTcpSocket::disconnected, this, &TileProvider::discardClient);
|
|
||||||
s->setSocketDescriptor(socket);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void readClient() {
|
|
||||||
QString json = QStringLiteral(
|
|
||||||
"{\"UrlTemplate\": \"https://tile.openstreetmap.org/%z/%x/%y.png\","
|
|
||||||
" \"ImageFormat\": \"png\","
|
|
||||||
" \"QImageFormat\": \"Indexed8\","
|
|
||||||
" \"ID\": \"wmf-intl-1x\","
|
|
||||||
" \"MaximumZoomLevel\": 19,"
|
|
||||||
" \"MapCopyRight\": \"<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>\","
|
|
||||||
" \"DataCopyRight\": \"\"}");
|
|
||||||
|
|
||||||
QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
|
|
||||||
if (socket->canReadLine()) {
|
|
||||||
QString line = socket->readLine();
|
|
||||||
if (line.startsWith("GET")) {
|
|
||||||
QTextStream s(socket);
|
|
||||||
s.setCodec("UTF-8");
|
|
||||||
s << QStringLiteral("HTTP/1.0 200 Ok\r\n"
|
|
||||||
"Content-Type: application/json; charset=\"utf-8\"\r\n\r\n")
|
|
||||||
<< json
|
|
||||||
<< QStringLiteral("\r\n");
|
|
||||||
socket->close();
|
|
||||||
|
|
||||||
if (socket->state() == QTcpSocket::UnconnectedState) {
|
|
||||||
delete socket;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void discardClient() {
|
|
||||||
QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
|
|
||||||
socket->deleteLater();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@
|
||||||
|
|
||||||
(defun activate-map ()
|
(defun activate-map ()
|
||||||
(unless (q< |active| ui:*map-loader*)
|
(unless (q< |active| ui:*map-loader*)
|
||||||
(qt:start-tile-provider qt:*cpp*)
|
(start-tile-provider)
|
||||||
(q> |active| ui:*map-loader* t)
|
(q> |active| ui:*map-loader* t)
|
||||||
#+mobile
|
#+mobile
|
||||||
(destructuring-bind (lat lon time)
|
(destructuring-bind (lat lon time)
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@
|
||||||
#:position*
|
#:position*
|
||||||
#:position-count
|
#:position-count
|
||||||
#:set-position
|
#:set-position
|
||||||
|
#:start-tile-provider
|
||||||
#:tile-path
|
#:tile-path
|
||||||
#:update-my-position))
|
#:update-my-position))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
#:last-position
|
#:last-position
|
||||||
#:local-ip
|
#:local-ip
|
||||||
#:start-device-discovery
|
#:start-device-discovery
|
||||||
#:start-tile-provider
|
|
||||||
#:read*
|
#:read*
|
||||||
#:short-names
|
#:short-names
|
||||||
#:sql-query
|
#:sql-query
|
||||||
|
|
|
||||||
33
examples/meshtastic/lisp/tile-provider.lisp
Normal file
33
examples/meshtastic/lisp/tile-provider.lisp
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
(in-package :loc)
|
||||||
|
|
||||||
|
(defvar *tile-provider-json*
|
||||||
|
"{
|
||||||
|
\"UrlTemplate\": \"https://tile.openstreetmap.org/%z/%x/%y.png\",
|
||||||
|
\"ImageFormat\": \"png\",
|
||||||
|
\"QImageFormat\": \"Indexed8\",
|
||||||
|
\"ID\": \"wmf-intl-1x\",
|
||||||
|
\"MaximumZoomLevel\": 19,
|
||||||
|
\"MapCopyRight\": \"<a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>\",
|
||||||
|
\"DataCopyRight\": \"\"
|
||||||
|
}")
|
||||||
|
|
||||||
|
(defvar *newline* #.(format nil "~C~C" #\Return #\Newline))
|
||||||
|
|
||||||
|
(defun tile-provider-handler (stream)
|
||||||
|
(when (x:starts-with "GET" (read-line stream))
|
||||||
|
(princ (format nil "HTTP/1.0 200 Ok~AContent-Type: application/json; charset=\"utf-8\"~A~A"
|
||||||
|
*newline* *newline* *newline*)
|
||||||
|
stream)
|
||||||
|
(princ *tile-provider-json* stream)
|
||||||
|
(princ *newline* stream)
|
||||||
|
(finish-output)))
|
||||||
|
|
||||||
|
(defvar *tile-provider* nil)
|
||||||
|
|
||||||
|
(defun start-tile-provider ()
|
||||||
|
(unless *tile-provider*
|
||||||
|
(setf *tile-provider*
|
||||||
|
(mp:process-run-function
|
||||||
|
:tile-provider
|
||||||
|
(lambda () (usocket:socket-server (app:my-ip) 1702 'tile-provider-handler))))))
|
||||||
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
(asdf:load-system :my-cl-protobufs)
|
(asdf:load-system :my-cl-protobufs)
|
||||||
(asdf:load-system :trivial-package-local-nicknames)
|
(asdf:load-system :trivial-package-local-nicknames)
|
||||||
|
(asdf:load-system :usocket-server)
|
||||||
|
|
||||||
(push :depends-loaded *features*)
|
(push :depends-loaded *features*)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue