Hello,
As Sling said there are some bugs regarding si variables.
I found the following problems:
1. When you use
si_variable_create and you initialize the variable with a value, that value isn't returned from the xplane plugin. So when you subscribe to this variable you always get 0.
Code: Select all
var_id = si_variable_create("testVar", "FLOAT", 1.2)
function callback_function(myvar)
print(myvar)
end
si_variable_subscribe("testVar", "FLOAT", callback_function)
Returns:0
If you write to this variable using the
si_variable_write then the plugin returns the values.
Code: Select all
var_id = si_variable_create("testVar", "FLOAT", 1.2)
[b]si_variable_write(var_id, 2.2) [/b]
function callback_function(myvar)
print(myvar)
end
si_variable_subscribe("testVar", "FLOAT", callback_function)
Returns: 2.2000000476837
2. The
request_callback doesn't work on si_variables subscriptions.
Some analysis to help you with debugging:
si_variable_create sends the following JSON:
Code: Select all
write_df:{
"key": "testVarFLOAT",
"size": 1,
"type": "FLOAT",
"type_size": 1,
"offset": 0,
"force": false,
"value": "1.200000",
"unit": "FLOAT" --- THIS IS THE DIFFERENCE
}
The plugin answers with 0
si_variable_write sends the following JSON:
Code: Select all
write_df:{
"key": "testVarFLOAT",
"size": 1,
"type": "FLOAT",
"type_size": 1,
"offset": 0,
"force": false,
"value": "2.200000"
}
The plugin answers with a value.
However, the value contains wrong floating points (2.2000000476837), and then you always have to use string.format to deal with them.
I guess that is because when you are programming in Java and you deal with decimal numbers and it is advisable to use
BigDecimal instead of
Double when you need to present numbers with precision.
Consider the following example:
Code: Select all
System.out.println("Subtract Double-Double 1-1.1 = " + (1.0 - 1.1) );
BigDecimal aa = BigDecimal.valueOf(1);
BigDecimal bb = BigDecimal.valueOf(1.1);
aa = aa.subtract(bb);
System.out.println("Subtract BigDecimal-BigDecimal 1-1.1 = " + aa);
Output:
Subtract Double-Double 1-1.1 = -0.10000000000000009
Subtract BigDecimal-BigDecimal 1-1.1 = -0.1
Please use BigDecimal or something equivalent for C++ (i have no idea) if it needs to be changed in the plugin.
And lastly, AM sends continuously the
write_df JSON for the same si_variable with the same values, that creates useless network traffic.
Hope that helps, cheers