Hello,
I'm using FSUIPC web socket for my web project but i could not got a latitude longitude information via 0568 and 0560 offsets. I'm getting nonsensical numbers. Can you help me please. My javascript code is under the below.
var cmdoffsetsread = new function () {
var ws = null; // WebSocket
this.start = function() {
};
this.stop = function () {
if (ws) {
ws.close();
}
};
var clearMessages = function () {
document.getElementById("connectionStatus").innerText = ws ? "Connection Open" : "Connection Closed";
};
this.openConnection = function () {
if (!ws) {
clearMessages();
var serverURL = document.getElementById("serverURL").value;
ws = new WebSocket(serverURL, "fsuipc");
ws.onopen = function () {
document.getElementById("connectionStatus").innerText = "Connection Open";
cmdoffsetsread.send_main_offsets();
cmdoffsetsread.send_main_read_request();
};
ws.onclose = function () {
cmdoffsetsread.send_stop_request();
document.getElementById("connectionStatus").innerText = "Connection Closed";
ws = null;
};
ws.onerror = function () {
document.getElementById("connectionStatus").innerText = "WebSocket Error";
};
ws.onmessage = function (msg) {
var response = JSON.parse(msg.data);
if (response.success) {
switch (response.command) {
case 'offsets.declare':
document.getElementById('connectionStatus').innerText = 'All settings loaded and instructor panel started';
break;
case "offsets.stop":
document.getElementById('connectionStatus').innerText = 'Updates for "' + response.name + '" have been stopped';
break;
case 'offsets.read':
switch (response.name) {
case 'allSettingsOffsets':
showOffsetValues(response);
break;
}
break;
default:
document.getElementById('connectionStatus').innerText = 'Unknown command: ' + response.command;
break;
}
}
else {
var error = 'Error for ' + response.name + ' (' + response.command + '): ';
error += response.errorCode + " - " + response.connectionStatus;
document.getElementById("connectionStatus").innerText = error;
}
};
}
}
var showOffsetValues = function (response) {
//VARIABLES
var playerLon = (((response.data.playerLon / 10001750) / 65536.0) / 65536.0) * 90.0;
// longitude
document.getElementById("latitude_longitude").value = playerLon;
}
this.send_main_offsets = function () {
clearMessages();
var request = {
command: 'offsets.declare',
name: 'allSettingsOffsets',
offsets: [
{ name: 'playerLon', address: 0x0568, type: 'uint', size: 8 }
]
}
if (ws) {
ws.send(JSON.stringify(request));
}
}
this.send_main_read_request = function () {
clearMessages();
var request = {
command: 'offsets.read',
name: 'allSettingsOffsets',
interval: 100
}
if (ws) {
ws.send(JSON.stringify(request));
}
}
this.send_stop_request = function () {
clearMessages();
var request = {
command: 'offsets.stop',
name: 'allSettingsOffsets'
}
if (ws) {
ws.send(JSON.stringify(request));
}
}
this.closeConnection = function () {
if (ws) {
clearMessages();
ws.close();
}
}
};