Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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();
            
        }
    }

};

 

 

Posted

I'm glad you fixed it.

For the benefit of others searching for the same problem, the easiest way to work with Longitude and Latitude offsets is to declare them with the types 'lon' and 'lat'.

 

        var request = {
            command: 'offsets.declare',
            name: 'allSettingsOffsets',
            offsets: [
                { name: 'playerLon', address: 0x0568, type: 'lon', size: 8 },
                { name: 'playerLat', address: 0x0560, type: 'lat', size: 8 }
            ]
        }

This will return the values in degrees decimal, so you won't need to do any conversion maths on the client side. 

Paul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.