|
Post by alexfish on Sept 24, 2022 20:42:33 GMT 1
Hi Joe have a file saved as gps.txt content 51.13333:1.3
in code below change path where gps.txt is import QtQuick 2.0 import QtQuick.Window 2.0 import QtLocation 5.15 import QtPositioning 5.15
Window { width: 512 height: 512 visible: true
Plugin { id: osmPlugin name: "osm" }
Map { id:mapview anchors.fill: parent plugin: osmPlugin center: QtPositioning.coordinate(59.91, 10.75) // Oslo zoomLevel: 14 }
MouseArea { id: mouseArea property variant lastCoordinate anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressAndHold:{ var xhr = new XMLHttpRequest; xhr.open("GET", "/home/pi/gps.txt"); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { var response = xhr.responseText.split(':');
console.log(response[0]); console.log(response[1]);
var lat = parseFloat(response[0]); var lon = parseFloat(response[1]);
mapview.center = QtPositioning.coordinate(lat,lon); var coordinate = mapview.toCoordinate(Qt.point(mouse.x,mouse.y));
console.log(coordinate);
} }; xhr.send();
} } }
thinking the qtmm to gps data can be used as per your demo code + here further reads can be written to a file , TODO : Find a callback feature in the qml to suit situation: ? Interesting I just found some bits relating to the engine an qml maps HEREdid a qmake & make result see picky :: follow the yellow brick road: BR Alex Attachments:
|
|
|
Post by bigbass on Sept 25, 2022 18:44:03 GMT 1
hello Alex good to see your progress I will give it a try and for the link I will try to port it that would be good for reading in a log file and less code to sort out LINUXI was and still am deep into getting this part working for linux runebook.dev/en/docs/qt/qtremoteobjects-indexANDROIDin android I have it working completely 100% because its a lot easier built in gps and the permission to use location connects to the inbuilt gpsd through sockets maybe the port changes but that works for where I am sourceforge.net/p/bacon-qt5/wiki/your_location_gps/working on making something close to that for linux Joe
|
|
|
Post by alexfish on Sept 25, 2022 20:41:55 GMT 1
Hi Joe
should be no need to write to file
can use the three functions on the QT side serial wifi, local , like gpsd linux , here gpsmm then Android m you have shown
You have shown all of these bits on different threads + the gpsmm here
as mentioned I was on the hunt for a specific callback ,was lucky to fined that demo.
so here we get the qml object then pass the changes of gps position using slot to the qml map , that is the qml callback IE notify position changed .... viola
Now can Baconise QT maps until the cows come home
BR Alex
PS :looking forward to your next demo + very willing to test
|
|
|
Post by bigbass on Sept 26, 2022 17:37:22 GMT 1
just on the light side of things while researching sockets it sent me here doc.qt.io/qt-6.2/qremoteobjectnode.html#heartbeatInterval-propand couldn't help but think about what porting this would say FUNCTION heartbeatIntervalChanged(int heartbeatInterval) TYPE int
IF heartbeatInterval == 0 THEN PRINT " You are dead but you won't see this message" ELSE PRINT " You get another chance " RETURN TRUE END IF END FUNCTION
CALL heartbeatIntervalChanged(1)
sorry I was reading to much and needed a break Joe
|
|
|
Post by alexfish on Sept 26, 2022 20:53:39 GMT 1
just on the light side of things while researching sockets it sent me here doc.qt.io/qt-6.2/qremoteobjectnode.html#heartbeatInterval-propand couldn't help but think about what porting this would say FUNCTION heartbeatIntervalChanged(int heartbeatInterval) TYPE int
IF heartbeatInterval == 0 THEN PRINT " You are dead but you won't see this message" ELSE PRINT " You get another chance " RETURN TRUE END IF END FUNCTION
CALL heartbeatIntervalChanged(1)
sorry I was reading to much and needed a break Joe in a lighthearted way .. one thing I know 'inheritance' can be very taxing FUNCTION inheritanceChanged(int inheritanceInterval) TYPE int
IF inheritanceInterval == 0 THEN PRINT " You are dead but you won't see this message" ELSE PRINT "Pay More tax " RETURN TRUE END IF END FUNCTION BR Alex
|
|
|
Post by alexfish on Sept 27, 2022 12:57:26 GMT 1
Hi Joe have managed to get the CLASS MarkerManager: public QObject in it complies : needs more work 1.remove file reads etc 2. sort timer 3. add the oneshot read the gpsd get the data and transfer to 4. add the marker function to qml file + redo the callback bits hope this helps item 3 & 4 relate main.moc ... total stuck thinking need to look further at this .pro & qmake & make Now my grey matter is starting to FRY...ee a make file 10 * size of prog total stuck stuck stuck. BR Alex Attachments:qtqml2.bac.bz2 (1.23 KB)
|
|
|
Post by alexfish on Sept 27, 2022 18:59:09 GMT 1
Did Further reading HEREesp note engine BR Alex
|
|
|
Post by bigbass on Sept 27, 2022 19:11:43 GMT 1
Hello Alex 'inheritance' can be very taxing Thanks I looked at your code and haven't solved all the problems on that list yet I decide to take a step backward and go here to clear my mind and go a step at a time as you know maps are complex doc-snapshots.qt.io/qt-mobility/tutorials-mapsdemo-part1.htmlin the past I was able to use CLASS in fltk and connect back to the class and communicate and remember I had to remove all the dot member code to use the c++ "new" then convert to using -> something like this in QT5 DECLARE app TYPE QGuiApplication* DECLARE engine TYPE QQmlApplicationEngine*
#MEMORY fix for bacon then do this notice the word new app = new QGuiApplication(argc, argv) engine = new QQmlApplicationEngine() then see it works here with the arrow operator -> engine->load(QUrl(QStringLiteral("main2.qml"))) app->exec() first step make sure you get all the headers ! Joe
|
|
|
Post by alexfish on Sept 27, 2022 19:33:14 GMT 1
Hi Joe
will look closer at those bits
looking in a logical sense of what i posted
somewhere in
engine->load(QUrl(QStringLiteral("./main.qml")))
there must be a get context something or set get blagh make slot foo engine has the main.qml object
engine->blagh .slot. set(foo)
or I am looking at this in the wrong context
esp when looking at this from the docs
int main(int argc, char *argv[]) { QApplication a(argc, argv);
MapsWidget w; w.show();
QList<QString> providers = QGeoServiceProvider::availableServiceProviders(); QGeoServiceProvider *serviceProvider = new QGeoServiceProvider(providers[0]);
w.initialize(serviceProvider->mappingManager());
return a.exec(); }
suppose here looking at the w.blagh* bits with pointer becomes like w-show(); and w->initialize
slotwise just a thought
w->center(lat,lon);
added:: osm maps c
at the timeout callback have
IF tracking THEN LOCAL maps TYPE OsmGpsMap * maps = OSM_GPS_MAP(user_data) osm_gps_map_gps_add (maps, NMEA.LAT,NMEA.LON,0) osm_gps_map_set_center((gpointer) maps, NMEA.LAT, NMEA.LON) END IF
compare qt maps doc
class MainWindow : public QMainWindow { private: QGeoPositionInfoSource *positionSource;
private slots: // slot to receive updates void updateMyPosition(QGeoPositionInfo info); };
context wise qml map has marker (generally a png) osm has
OsmGpsMapImage * osm_gps_map_image_add ()
BR Alex
|
|
|
Post by alexfish on Sept 27, 2022 22:29:07 GMT 1
Hi Joe tried timer in the main.qml source doc HEREnot the correct slot : tried position changed = segfault , so possible look further into the properties so for now have read external file RE: the gps.txt BR Alex the code for main.qml import QtQuick 2.0 import QtQuick.Window 2.0 import QtLocation 5.15 import QtPositioning 5.15
Window { width: 512 height: 512 visible: true
Plugin { id: osmPlugin name: "osm" }
Map { id:mapview anchors.fill: parent plugin: osmPlugin center: QtPositioning.coordinate(59.91, 10.75) // Oslo zoomLevel: 14 MapQuickItem{ id: marker anchorPoint.x: marker.width / 4 anchorPoint.y: marker.height coordinate: manager.position
}
}
Text { id: foo font.pointSize: 12 function set() { foo.text = Date() console.log(foo.text) var xhr = new XMLHttpRequest; xhr.open("GET", "/home/pi/gps.txt"); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { var response = xhr.responseText.split(':');
console.log(response[0]); console.log(response[1]);
var lat = parseFloat(response[0]); var lon = parseFloat(response[1]); mapview.center = QtPositioning.coordinate(lat,lon); } }; xhr.send();
} }
Timer { id: textTimer interval: 1000 repeat: true running: true triggeredOnStart: true onTriggered: foo.set() }
MouseArea { id: mouseArea property variant lastCoordinate anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressAndHold:{ var coordinate = mapview.toCoordinate(Qt.point(mouse.x,mouse.y));
console.log(coordinate);
} } }
to suppress file io errors add qputenv("QML_XHR_ALLOW_FILE_READ", QByteArray("1")) to the main QT code Added Text with concat postion Text { id: foo font.pointSize: 16 font.bold:true function set() { //foo.text=Date(); var xhr = new XMLHttpRequest; xhr.open("GET", "/home/pi/gps.txt"); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { var response = xhr.responseText.split(':');
console.log(response[0]); console.log(response[1]);
var lat = parseFloat(response[0]); var lon = parseFloat(response[1]); let result = response[0].concat(" : ",response[1]); foo.text=result; mapview.center = QtPositioning.coordinate(lat,lon); } }; xhr.send();
|
|
|
Post by alexfish on Sept 27, 2022 22:56:44 GMT 1
Hi Joe the bacon code for the writing to file ' example gpsd client ' original code source here https://gpsd.io/gpsd-client-example-code.html ' ported to bacon by bigbass then simplified readability with macros ' modified to compile in c++
PRAGMA INCLUDE <string.h> <stdio.h> <libgpsmm.h> <math.h> <iostream> PRAGMA COMPILER c++ PRAGMA LDFLAGS -Wall -pedantic -pthread -lgps PRAGMA OPTIONS -Wno-deprecated -Wno-writable-strings PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith
OPTION PARSE FALSE
CONST MODE_STR_NUM = 4
'add 6 zeros automatically to the seconds you want to wait 'dev is device or data the ADDRESS is handled in the macro to keep it easy
DEF FN GPSOPEN(ip,port,dev) = gps_open(ip, port, &dev) DEF FN STREAM(dev,op) = (void) gps_stream(&dev, op, NULL) DEF FN WAITFOR(dev,timesec) = gps_waiting(&dev, timesec * 1000000) DEF FN GPSREAD(dev) = gps_read(&dev, NULL, 0) DEF FN GPSCLOSE(dev) = (void)gps_close(&dev)
DECLARE mode_str[MODE_STR_NUM]= { \ "n/a", \ "None", \ "2D", \ "3D" \ } TYPE static char *
struct gps_data_t gps_data
' ip ,port ,device or data IF (0 ISNOT GPSOPEN("localhost", "2947", gps_data)) THEN EPRINT "Open error. Bye, bye" END END IF
STREAM(gps_data,WATCH_ENABLE | WATCH_JSON)
'wait for 5 seconds WHILE (WAITFOR(gps_data,5)) IF (-1 == GPSREAD(gps_data)) THEN EPRINT "Read error. Bye, bye" BREAK END IF
IF (MODE_SET ISNOT (MODE_SET & gps_data.set)) THEN 'did not even get mode, nothing to see here CONTINUE END IF
IF (0 > gps_data.fix.mode OR \ MODE_STR_NUM <= gps_data.fix.mode) THEN gps_data.fix.mode = 0 END IF
'PRINT "Fix mode: ", mode_str[gps_data.fix.mode], \ ' "Time: ", gps_data.fix.mode FORMAT "%s %s %s %d"
IF (TIME_SET == (TIME_SET & gps_data.set)) THEN ' not 32 bit safe
' PRINT gps_data.fix.time.tv_sec, \ ' gps_data.fix.time.tv_nsec FORMAT "%ld.%09ld "
ELSE PRINT "n/a " END IF
IF (isfinite(gps_data.fix.latitude) && \ isfinite(gps_data.fix.longitude)) THEN 'Display data from the GPS receiver if valid. PRINT gps_data.fix.latitude, gps_data.fix.longitude FORMAT "%.6f:%.6f\n" gps$ = STR$( gps_data.fix.latitude) & ":" & STR$( gps_data.fix.longitude) OPEN "gps.txt" FOR WRITING AS myfile WRITELN gps$ TO myfile CLOSE FILE myfile ELSE PRINT "Lat n/a Lon n/a\n" END IF
WEND
' When you are done... STREAM(gps_data,WATCH_DISABLE) GPSCLOSE(gps_data) does it work :: Yes that will do for now : from my side need to finish navigation 2 bits , same time will add a qmlmap tiles to qmlseamap tiles converter BR Alex
|
|
|
Post by alexfish on Sept 28, 2022 15:06:36 GMT 1
Hi Joe have updated main.qml have fun + BR Alex Attachments:main.qml.bz2 (1.78 KB)
|
|
|
Post by bigbass on Sept 28, 2022 18:36:00 GMT 1
Hey Alex thats it! reading on the qml dynamic side of things simplifies the code for all practical reasons thats a demo congratulations great job! of course we will add in some candy and maybe or not later do it with sockets P.S you might have to wash your hands well and get that fishy smell off after using that javascript javascript.info/xmlhttprequestthanks Joe
|
|
|
Post by alexfish on Sept 28, 2022 19:09:28 GMT 1
Hi Joe I had a chat with one of my boys , eyes just roll , and mumbled we use 'curl' or blag it did not get a lot of the howto , possible previous interaction about me and that word J in theory one should be able to make a plugin for readfile .. beyond my scope so... putting the bits together for your info + further r&d see archive dynamic2 , be aware there is a main.qml in the folder Should not see any stinking fish in the terminal that's the 'blag it' also note the use of ID: * and how those are used can give some eyecandy by converting to qmlmap to qmlseamap ADDED also note need to clean up exit from QT readport function as close&clean . as some times getting a read error OK sorted , possible can get rid of the counter since have break in the bits Archive Updated Updated again (wrong file) have fun + BR Alex Attachments:dynamic2.tar.gz (3.79 KB)
|
|
|
Post by alexfish on Sept 28, 2022 20:17:24 GMT 1
Hi All Updated archive above
BR Alex
|
|