Jump to content
The simFlight Network Forums

FSUIPC WebSocket Server Unknown Commands


Dabull

Recommended Posts

I am running the client and everything is connected, but when I try the following commands it says it is not recognized:

Unknown command: payload.read

Unknown command: offsets.declare

I am using the example requests from the website.

The only command that works is: about.read

I am running MSFS on Windows 10.

 

Can someone help find out what I may be doing wrong?

 

Thanks.

Link to comment
Share on other sites

Yes. I am on the latest version of of WebSocketServer. I am running JS code in VS Code.

 

Here is the code:

 

const WebSocket = require('ws');
var ws = new WebSocket('ws://localhost:2048/fsuipc/'"fsuipc");
 
// Handle the onopen event
ws.onopen = function () {
    console.log("Connection Open");
    var request = {
        command: 'offsets.declare',
        name: 'myOffsets',
        offsets: [
            { name: 'altitude'address: 0x0570type: 'int'size: 8 },
            { name: 'avionicsMaster'address: 0x2E80type: 'uint'size: 4 },
            { name: 'heading'address: 0x0580type: 'uint'size: 4 },
            { name: 'aircraftName'address: 0x3D00type: 'string'size: 256 },
        ]
    }
    ws.send(JSON.stringify(request));
    
    ws.close()
};
 
// Handle the onclose event
ws.onclose = function () {
    console.log("Connection Closed");
    // clear the WebSocket so we can try again
    ws = null;
};
 
// Handle the onerror event
ws.onerror = function (err) {
    console.error("WebSocket Error: ",err.message);
};
 
ws.onmessage = function (msg) {
    // parse the JCON string to a Javascript object
    var response = JSON.parse(msg.data);
 
    // If the response indicated success then we can proceed to process it 
    if (response.success) {
        // handle the response according to the command. 
        // could also use the name, or both.
        switch (response.command) {
            case "about.read":
                console.log(response.data)
                break;
            default:
                // Unhandled command
                console.log("Unknown command: " + response.command);
                break;
        }
    }
    else {
        // The request failed. Handle the errors here.
        // In this example we just display errors to the webpage
        var error = 'Error for ' + response.name + ' (' + response.command + '): ';
        error += response.errorCode + " - " + response.errorMessage;
        console.log(error);
    }
};
Link to comment
Share on other sites

The error message is being produced by the switch statement in the ws.onmessage() function:

       switch (response.command) {
            case "about.read":
                console.log(response.data)
                break;
            default:
                // Unhandled command
                console.log("Unknown command: " + response.command);
                break;
        }

You're not handling the "offsets.declare" response. Only "about.read". 

You can do one of two things:

Option 1:

Add a case statement for "offsets.declare" and all other commands you are using.

In the website example for reading offsets, the successful response from the 'declare' just posts a message to the screen:

http://fsuipcwebsockets.paulhenty.com/js/cmdoffsetsread.js

                    switch (response.command) {
                        case 'offsets.declare':
                            document.getElementById('successMessage').innerText = 'Offsets "' + response.name + '" have been declared';
                            break;
                        case "offsets.stop":
                            document.getElementById('successMessage').innerText = 'Updates for "' + response.name + '" have been stopped';
                            break;
                        case 'offsets.read':
                            switch (response.name) {
                                case 'myOffsets':
                                    showOffsetValues(response);
                                    break;
                            }
                            break;
                        default:
                            // Unhandled command
                            document.getElementById('errorMessage').innerText = 'Unknown command: ' + response.command;
                            break;
                    }

Option 2:

You might find it easier to just delete the 'default' case if you don't want to handle every type of incoming message.

Paul

Link to comment
Share on other sites

Ah. Silly me I didn't pay attention to that. I can make the offsets.declare call now.

But...I am not sure how to sequence the declare request and that read request to make it repeatable .

Does all the commands need to be in the ws.onopen function?

 

Link to comment
Share on other sites

Quote

Does all the commands need to be in the ws.onopen function?

If you just want something automatic that runs as soon as you start the script, then yes you would do both in the onopen function.

First send the the declare request, then the read request. Set the 'interval' property of the 'read' request to a number of milliseconds to get automatic (repeating) data updates.

Paul

Link to comment
Share on other sites

All offset data is stored as integers unless the Offset Status document says they are something else. Whether they are signed or unsigned is sometimes mentioned, but if not it should be obvious. e.g. A heading would be unsigned because you can't have a negative heading. Vertical speed would be signed because you can be going up or down.

The other common type you'll see is the floating point number.  The document will always tell you if the data is in floating point format; usually it will say FLOAT32 or FLOAT64.

There can also be strings. These are usually obvious (e.g. aircraft name) but where not, the documentation will say it's a string.

The websocket server also has additional types to make it easer to work with certain offsets:

lon and lat for offsets holding Longitude or Latitude values. This avoids a very tedious conversion between Flight Sim coordinates and Degrees

bits for offsets where each bit represents a different system. An example is the lights offset 0x0D0C where each bit is a different light. The documentation will make it clear what each bit represents. There is an example of this on the website. 

Paul

  • Like 1
Link to comment
Share on other sites

Funny you mentioned lat and lon I am trying to read those and the values don't look correct. 

I send this:

{name: 'latitude'address: 0x6010type: 'int'size: 8},
            {name: 'longitude'address: 0x6018type: 'int'size: 8},

But the returned values aren't correct. Is there another way to get those values?

Link to comment
Share on other sites

Honestly most of the values don't make sense:

I sent this:

offsets: [
            { name: 'aircraftName'address: 0x3D00type: 'string'size: 256 },
            { name: 'altitude'address: 0x0570type: 'uint'size: 8 },
            { name: 'heading'address: 0x0580type: 'uint'size: 4 },
            {name: 'groundSpeed'address: 0x6030type: 'uint'size: 8},
            {name: 'latitude'address: 0x6010type: 'int'size: 8},
            {name: 'longitude'address: 0x6018type: 'int'size: 8},
            {name: 'verticalSpeed'address: 0x030Ctype: 'int'size: 4},
            {name: 'onGround'address: 0x0366type: 'int'size: 2}
        ]

 

and I get this:

 

{
  aircraftName: 'Cessna CJ4 Citation WT',
  altitude: 61267640065450,
  heading: 1445037629,
  groundSpeed: 4641275633426061000,
  latitude: -4606115315203747000,
  longitude: -4588245414674943500,
  verticalSpeed: 8,
  onGround: 0
}

I have no clue what a floating point double is. How do I convert these values to something meaningful.

Link to comment
Share on other sites

The website explains and demonstrates how to deal with the values. I recommend going through the offsets examples.

The values stored in FSUIPC are encoded into integers. This is mainly for historic reasons regarding how computers used to process data a few decades ago.

You need to decode most integer values into real world units. For example your heading value is 1445037629. If you look at the offsets document, it gives the formula for converting to degrees as  *360/(65536*65536) for degrees TRUE.

1445037629 * 360 / (65536*65536) = 121.12 degrees true.

Note this is not degrees magnetic. To get the magnetic heading to need to subtract the magnetic variation from offset 0x02A0.

Latitude and Longitude need a similar conversion, but if you use the 'lat' and 'lon' datatypes instead of 'int' the server will do the conversion for you. You'll get back decimal degrees with no need for further conversion.

The offsets document has all the information you need to convert the data from FSUIPC units to human readable units.

Quote

I have no clue what a floating point double is

It's floating point number, so use the type 'float' instead of 'int' and you'll get the proper value. Floating point numbers are used in newer offsets and don't require any further conversion.

For the altitude the documentation recommends using 0x6020 (which is a float) instead of 0x0570.

For the vertical speed use 0x02C8 instead. The documentation says that 0x030C is just a copy of the VS on touchdown.

Using the correct offsets and types will get you most of the way there:

offsets: [
            { name: 'aircraftName', address: 0x3D00, type: 'string', size: 256 },
            { name: 'altitude', address: 0x6020, type: 'float', size: 8 },
            { name: 'heading', address: 0x0580, type: 'uint', size: 4 },
            {name: 'groundSpeed', address: 0x6030, type: 'float', size: 8},
            {name: 'latitude', address: 0x6010, type: 'lat', size: 8},
            {name: 'longitude', address: 0x6018, type: 'lon', size: 8},
            {name: 'verticalSpeed', address: 0x02C8, type: 'int', size: 4},
            {name: 'onGround', address: 0x0366, type: 'int', size: 2}
        ]

You'll still need to manually convert the heading and the vertical speed as described in the offsets document. The website also has an example of this (http://fsuipcwebsockets.paulhenty.com/#cmdoffsetsread.

The ground speed is in metres per second so you'll also need to convert that if you want other units like knots or kph. 

The altitude is in metres so you'll need to convert if you want to see it in feet.

Paul

Link to comment
Share on other sites

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.