Class LVarHelper

java.lang.Object
com.mouseviator.fsuipc.helpers.LVarHelper

public class LVarHelper
extends java.lang.Object

This class implements a helper to manipulate LVars using FSUIPC. LVars are gauge variables. This class allows you to read, write and create LVars.

Manipulating LVars via FSUIPC requires 3 data requests, because it works with 3 offsets. Many functions in this class return all of them in an instance of LVarHelper.LVarResult. The main offset in use is 0D70, in which you write a string telling FSUIPC what to do with what LVar. I call it here a "control request" and it is the LVarHelper.LVarResult.getControlRequest(). The next offset is 0D6C and I reference it as "parameter request" here. Because it is the parameter for requested LVar operation, telling FSUIPC at which offset and in what format to place the result of LVar read operation, or where it will find the value for write/create operation. You will find this request in the result object as LVarHelper.LVarResult.getParamRequest(). The last data request is the result request (even thought that for write and create it is actually kind of source data request). It is the data request that will hold the result of the LVar read operation, or will hold the value to write or init new LVar with (create operation). This is the LVarHelper.LVarResult.getResultRequest() in the result object.

There are various functions for writing, creating LVar, which mostly differ just by the value type they accept.

Some functions also accepts an instance of FSUIPC class and a boolean parameter. These functions will also register the generated requests with given FSUIPC instance for one-time or continual processing (based on that boolean parameter)

Reading an LVar example

Here is an example how you would read an LVar value without this helper class. It first creates a "parameter request", which tells FSUIPC that we want to store the value of LVar being read at offset 0x66C0 as double value. Than we create "control request", which will tell FSUIPC to read the LVar. The third request is the one that Lvar value will be store in. Than we register all 3 request for one-time processing, process all the requests and print the result.


 // Construct the control param request. We will be reading the LVar, this param means:
 // Store an LVar value at offset 0x66C0 as 64-bit float value (It is the 0x00000 + 0x66C0. More about this in FSUIPC documentation)
 IntRequest paramReq = new IntRequest(0x0D6C);
 paramReq.setValue(0x066C0);
 paramReq.setType(IDataRequest.RequestType.WRITE);
 fsuipc.addOneTimeRequest(paramReq);

 //Construct the control request. The ":" tells FSUIPC to read the LVar, whose name follows
 StringRequest controlReq = new StringRequest(0x0D70, ":FSDT_GSX_DEBOARDING_STATE");
 fsuipc.addOneTimeRequest(controlReq);

 //The result request where the resulting 64-bit float (double) will be
 DoubleRequest resultReq = new DoubleRequest(0x66C0);
 fsuipc.addOneTimeRequest(resultReq);

 //Read the LVar value
 if (fsuipc.processRequestsOnce() == FSUIPC.PROCESS_RESULT_OK) {
       System.out.println("Read Okay");
       System.out.println("The value of lvar: FSDT_GSX_DEBOARDING_STATE is: " + resultReq.getValue());
 }
 

The same done using this helper class. You can see it si much simpler, as all of the code is hidden in the function. The function that takes an FSUIPC instance is used here, so not even needed to register the requests. Just call the helper function and process the requests.


 //Let the helper function construct all 3 requests and register them with FSUIPC for one-time processing
 LVarHelper.LVarResult lvarreq = lvarHelper.readLVar("FSDT_GSX_DEBOARDING_STATE", 0x66C0,LVarHelper.LVarValueFormat.DOUBLE , fsuipc, false);

 //Read the LVar value
 if (fsuipc.processRequestsOnce() == FSUIPC.PROCESS_RESULT_OK) {
       System.out.println("Read Okay");
       System.out.println("The value of lvar: FSDT_GSX_DEBOARDING_STATE is: " + lvarreq.getResultRequest().getValue());
 }
 

Writing an LVar or creating an LVar follows the same logic. Only in these cases, all generated requests will be write only. If you use the function that that registers the requests with FSUIPC, you may not need the resulting object at all. Unless you registered them for continual processing and need to remove them from processing later on.

If you will be registering the requests yourself, make sure that in the case of reading LVar you register them in the order:

and in the case of write/create:

So in the case of write/read, the control request needs to be registered last! So it has all required data when it comes to it.

You can also just use the request and other supporting classes defined in this helper class and write the "functions" by yourself.

Author:
Mouseviator