mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-16 04:45:18 +03:00
We now successfully fetch and parse ublox data and send as msp messages
This commit is contained in:
parent
ee98c70807
commit
a3f6a99d02
4 changed files with 91 additions and 34 deletions
|
@ -1588,11 +1588,14 @@ var mspHelper = (function () {
|
||||||
FC.OSD_CUSTOM_ELEMENTS .items.push(customElement)
|
FC.OSD_CUSTOM_ELEMENTS .items.push(customElement)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MSPCodes.MSP2_INAV_GPS_UBLOX_COMMAND:
|
||||||
|
// Just and ACK from the fc.
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.log('Unknown code detected: ' + dataHandler.code);
|
console.log('Unknown code detected: 0x' + dataHandler.code.toString(16));
|
||||||
} else {
|
} else {
|
||||||
console.log('FC reports unsupported message error: ' + dataHandler.code);
|
console.log('FC reports unsupported message error: 0x' + dataHandler.code.toString(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger callbacks, cleanup/remove callback after trigger
|
// trigger callbacks, cleanup/remove callback after trigger
|
||||||
|
|
|
@ -49,7 +49,7 @@ var ublox = (function () {
|
||||||
var currentCommand;
|
var currentCommand;
|
||||||
|
|
||||||
function resetUbloxState() {
|
function resetUbloxState() {
|
||||||
console.log("Reset ublox state");
|
//console.log("Reset ublox state");
|
||||||
hasFirstHeader = false;
|
hasFirstHeader = false;
|
||||||
hasSecondHeader = false;
|
hasSecondHeader = false;
|
||||||
ubxClass = false;
|
ubxClass = false;
|
||||||
|
@ -61,19 +61,20 @@ var ublox = (function () {
|
||||||
currentCommand = [];
|
currentCommand = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function splitUbloxData(ubxBytes) {
|
function splitUbloxData(ubxBytesBuffer) {
|
||||||
console.log("type of data: " +typeof(ubxBytes));
|
console.log("type of data: " +typeof(ubxBytesBuffer));
|
||||||
console.log("splitUbloxData: " + ubxBytes.length);
|
console.log("splitUbloxData: " + ubxBytesBuffer.byteLength);
|
||||||
|
let ubxBytes = new DataView(ubxBytesBuffer);
|
||||||
|
|
||||||
var ubxCommands = []
|
var ubxCommands = []
|
||||||
resetUbloxState()
|
resetUbloxState()
|
||||||
|
|
||||||
for(var i = 0; i < ubxBytes.length;++i) {
|
for(var i = 0; i < ubxBytes.byteLength;++i) {
|
||||||
let c = ubxBytes.charCodeAt(i);
|
let c = ubxBytes.getUint8(i);
|
||||||
//let c = ubxBytes[i];
|
//console.log("byte: 0x" + c.toString(16));
|
||||||
if (!hasFirstHeader) {
|
if (!hasFirstHeader) {
|
||||||
if (c == 0xb5) {
|
if (c == 0xb5) {
|
||||||
console.log("First header");
|
//console.log("First header");
|
||||||
hasFirstHeader = true;
|
hasFirstHeader = true;
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
continue;
|
continue;
|
||||||
|
@ -86,7 +87,7 @@ var ublox = (function () {
|
||||||
}
|
}
|
||||||
if (!hasSecondHeader) {
|
if (!hasSecondHeader) {
|
||||||
if (c == 0x62) {
|
if (c == 0x62) {
|
||||||
console.log("Second header");
|
//console.log("Second header");
|
||||||
hasSecondHeader = true;
|
hasSecondHeader = true;
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
continue;
|
continue;
|
||||||
|
@ -99,18 +100,18 @@ var ublox = (function () {
|
||||||
}
|
}
|
||||||
if (!ubxClass) {
|
if (!ubxClass) {
|
||||||
ubxClass = true;
|
ubxClass = true;
|
||||||
console.log("ubxClass: 0x"+ (c).toString(16));
|
//console.log("ubxClass: 0x"+ (c).toString(16));
|
||||||
currentCommand.push(c)
|
currentCommand.push(c)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!ubxId) {
|
if (!ubxId) {
|
||||||
ubxId = true;
|
ubxId = true;
|
||||||
console.log("ubxId: 0x"+ (c).toString(16));
|
//console.log("ubxId: 0x"+ (c).toString(16));
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!lenLow) {
|
if (!lenLow) {
|
||||||
console.log("Len low");
|
//console.log("Len low");
|
||||||
lenLow = true;
|
lenLow = true;
|
||||||
//(int) c
|
//(int) c
|
||||||
payloadLen = c;
|
payloadLen = c;
|
||||||
|
@ -118,17 +119,17 @@ var ublox = (function () {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!lenHigh) {
|
if (!lenHigh) {
|
||||||
console.log("Len high");
|
//console.log("Len high");
|
||||||
lenHigh = true;
|
lenHigh = true;
|
||||||
// (int)c
|
// (int)c
|
||||||
payloadLen = (c << 8) | payloadLen;
|
payloadLen = (c << 8) | payloadLen;
|
||||||
console.log("Payload len " + payloadLen);
|
//console.log("Payload len " + payloadLen);
|
||||||
payloadLen += 2; // add crc bytes;
|
payloadLen += 2; // add crc bytes;
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (skipped < payloadLen - 1) {
|
if (skipped < payloadLen - 1) {
|
||||||
console.log("payload + crc");
|
//console.log("payload + crc");
|
||||||
skipped = skipped + 1;
|
skipped = skipped + 1;
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
continue;
|
continue;
|
||||||
|
@ -137,7 +138,7 @@ var ublox = (function () {
|
||||||
skipped = skipped + 1;
|
skipped = skipped + 1;
|
||||||
currentCommand.push(c);
|
currentCommand.push(c);
|
||||||
ubxCommands.push(currentCommand);
|
ubxCommands.push(currentCommand);
|
||||||
console.log("Adding command");
|
//console.log("Adding command");
|
||||||
resetUbloxState();
|
resetUbloxState();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -145,18 +146,30 @@ var ublox = (function () {
|
||||||
return ubxCommands
|
return ubxCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
function processOnlineData(data) {
|
function getBinaryData(url, successCallback, failCallback) {
|
||||||
assistnowOnline = splitUbloxData(data);
|
const req = new XMLHttpRequest();
|
||||||
|
req.open("GET", url, true);
|
||||||
|
req.responseType = "arraybuffer";
|
||||||
|
|
||||||
console.log("Assitnow online commands:" + assistnowOnline.length);
|
if (successCallback != null) {
|
||||||
}
|
req.onload = (event) => {
|
||||||
|
successCallback(req.response);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function processOfflineData(data) {
|
if (failCallback != null) {
|
||||||
assistnowOffline = splitUbloxData(data);
|
req.onerror = (event) => {
|
||||||
console.log("Assitnow offline commands:" + assistnowOffline.length);
|
failCallback(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.send(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function loadError(event) {
|
||||||
|
GUI.alert("Error loading AssistNow data");
|
||||||
|
}
|
||||||
|
|
||||||
// For more info on assistnow, check:
|
// For more info on assistnow, check:
|
||||||
// https://developer.thingstream.io/guides/location-services/assistnow-user-guide
|
// https://developer.thingstream.io/guides/location-services/assistnow-user-guide
|
||||||
|
@ -167,22 +180,29 @@ var ublox = (function () {
|
||||||
let url = `https://${ offlineServers[0] }/GetOfflineData.ashx?token=${globalSettings.assistnowApiKey};gnss=${offline_gnss};format=${fmt};period=${period};resolution=1;alm=${offline_alm};`
|
let url = `https://${ offlineServers[0] }/GetOfflineData.ashx?token=${globalSettings.assistnowApiKey};gnss=${offline_gnss};format=${fmt};period=${period};resolution=1;alm=${offline_alm};`
|
||||||
console.log(url);
|
console.log(url);
|
||||||
|
|
||||||
$.get(url, processOfflineData).fail(function() {GUI.alert("Error loading Offline data")});
|
function processOfflineData(data) {
|
||||||
|
assistnowOffline = splitUbloxData(data);
|
||||||
if(callback != null) {
|
console.log("Assitnow offline commands:" + assistnowOffline.length);
|
||||||
callback("");
|
callback(assistnowOffline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBinaryData(url, processOfflineData, loadError);
|
||||||
|
//$.get(url, processOfflineData).fail(function() {GUI.alert("Error loading Offline data")});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.loadAssistnowOnline = function(callback) {
|
self.loadAssistnowOnline = function(callback) {
|
||||||
//url = "https://online-live1.services.u-blox.com/GetOnlineData.ashx?token=" + online_token + ";gnss=" + gnss + ";datatype=eph,alm,aux,pos;format=" + fmt + ";"
|
//url = "https://online-live1.services.u-blox.com/GetOnlineData.ashx?token=" + online_token + ";gnss=" + gnss + ";datatype=eph,alm,aux,pos;format=" + fmt + ";"
|
||||||
let url = `https://${ onlineServers[0] }/GetOnlineData.ashx?token=${globalSettings.assistnowApiKey};gnss=${ gnss };datatype=eph,alm,aux,pos;format=${ fmt }`;
|
let url = `https://${ onlineServers[0] }/GetOnlineData.ashx?token=${globalSettings.assistnowApiKey};gnss=${ gnss };datatype=eph,alm,aux,pos;format=${ fmt }`;
|
||||||
|
|
||||||
$.get(url, processOnlineData).fail(function() {GUI.alert("Error loading Offline data")});
|
function processOnlineData(data) {
|
||||||
|
assistnowOnline = splitUbloxData(data);
|
||||||
|
|
||||||
if(callback != null) {
|
console.log("Assitnow online commands:" + assistnowOnline.length);
|
||||||
callback("");
|
callback(assistnowOnline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//$.get(url, processOnlineData).fail(function() {GUI.alert("Error loading Offline data")});
|
||||||
|
getBinaryData(url, processOnlineData, loadError);
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
|
@ -5923,5 +5923,14 @@
|
||||||
},
|
},
|
||||||
"gpsLoadAssistnowOnlineButton": {
|
"gpsLoadAssistnowOnlineButton": {
|
||||||
"message": "Load AssistNow Online"
|
"message": "Load AssistNow Online"
|
||||||
|
},
|
||||||
|
"gpsAssistnowStart": {
|
||||||
|
"message": "Assistnow data transfer starting..."
|
||||||
|
},
|
||||||
|
"gpsAssistnowDone": {
|
||||||
|
"message": "Assistnow data transfer complete."
|
||||||
|
},
|
||||||
|
"gpsAssistnowUpdate": {
|
||||||
|
"message": "Assistnow messages sent."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
29
tabs/gps.js
29
tabs/gps.js
|
@ -421,8 +421,33 @@ TABS.gps.initialize = function (callback) {
|
||||||
|
|
||||||
function processUbloxData(data) {
|
function processUbloxData(data) {
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
// foreach data
|
//console.log("processing data type: " + typeof(data));
|
||||||
//mspHelper.sendUbloxCommand(d);
|
let totalSent = 0;
|
||||||
|
let total = data.length;
|
||||||
|
|
||||||
|
var ubloxChainer = MSPChainerClass();
|
||||||
|
var chain = [];
|
||||||
|
|
||||||
|
GUI.log(i18n.getMessage('gpsAssistnowStart'));
|
||||||
|
data.forEach((item) => {
|
||||||
|
chain.push(function (callback) {
|
||||||
|
//console.log("UBX command: " + item.length);
|
||||||
|
mspHelper.sendUbloxCommand(item, callback);
|
||||||
|
totalSent++;
|
||||||
|
if((totalSent % 100) == 0) {
|
||||||
|
GUI.log(totalSent + '/' + total + ' ' + i18n.getMessage('gpsAssistnowUpdate'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ubloxChainer.setChain(chain);
|
||||||
|
ubloxChainer.setExitPoint(function () {
|
||||||
|
if ((totalSent % 100) != 0) {
|
||||||
|
GUI.log(totalSent + '/' + total + ' ' + i18n.getMessage('gpsAssistnowUpdate'));
|
||||||
|
}
|
||||||
|
GUI.log(i18n.getMessage('gpsAssistnowDone'));
|
||||||
|
});
|
||||||
|
|
||||||
|
ubloxChainer.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue