DragonflightDesign
Resource contributor
- Messages
- 1,357
- Country

It's a fuel transfer function. Originally I drove Doug Dowson batty with this one via email - sorry Doug; there was a lot wrong with it which wasn't immediately obvious. I put it down and came back to it after a few months and fixed the calculation problems today. The transfer calculations now all work perfectly; the from_tank has its total reduced and the to_tank has its total increased, but the act of calling SimConnect_SetDataOnSimObject is doing nothing, despite HRESULT returning S_OK.
The data definitions:
Event check:
The pump_fuel function (or some relevant chunks anyway):
Screenshot of the tank struct showing that at the
line, tank zero has reduced from 764 to 754 gallons (fuel dump in progress):
but
never changes the tank level. Can anyone spot the fail please?
The data definitions:
Code:
enum DATA_DEFINITION_ID {
DEFINE_FUEL_LEVEL,
};
Code:
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK LEFT AUX QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK RIGHT AUX QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK CENTER QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK CENTER2 QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK CENTER3 QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK EXTERNAL1 QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK EXTERNAL2 QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK RIGHT TIP QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK LEFT TIP QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK LEFT MAIN QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUEL_LEVEL, "FUEL TANK RIGHT MAIN QUANTITY", "Gallons", SIMCONNECT_DATATYPE_FLOAT64);
Event check:
Code:
/ -----------------------------------------------------------------------------------------------------------------
void OnRecvEvent(SIMCONNECT_RECV_EVENT *pEvent, DWORD cbData)
{
switch (pEvent->uEventID)
{
case CLIENT_EVENT_1SEC:
{
// -----------------------------------------------------
// Fuel state
hr = SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_FUEL_STATE_DATA, DEFINE_FUEL_LEVEL, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);
// Transfer fuel function if pumps are on (flow_rate is not zero)
if (flow_rate)pump_fuel(hSimConnect, from_tank, to_tank, flow_rate);
The pump_fuel function (or some relevant chunks anyway):
Code:
void pump_fuel(HANDLE hSimConnect, double fromTank, double toTank, double flowRate)
{
(lots of calculation and timer code here)
from_tank_level = from_tank_level - level_change;
fuel_tanks[(int)from_tank] = from_tank_level;
// If not a fuel dump, calculate new level for to_tank and write it.
if (toTank != -1)
{
to_tank_level = to_tank_level + level_change;
fuel_tanks[(int)to_tank] = to_tank_level;
}
// Write the data
hRes=SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUEL_LEVEL, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, 11, sizeof(fuel_tanks), &fuel_tanks);
Screenshot of the tank struct showing that at the
Code:
fuel_tanks[(int)to_tank] = to_tank_level;
but
Code:
// Write the data
hRes=SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUEL_LEVEL, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, 11, sizeof(fuel_tanks), &fuel_tanks);




Just what I'm in the process of doing! I need to come back to this because I don't understand why REQUEST_FUEL_STATE_DATA isn't being hit. Got to be my definitions somewhere. I bet I'm in the wrong OnRecvXXXX. More research under way.