Fix SB persist

This commit is contained in:
Kilian Hofmann 2025-06-19 16:05:54 +02:00
parent 390edd29b8
commit 2047c84d8d
5 changed files with 59 additions and 57 deletions

View File

@ -1,4 +1,4 @@
import { FC, useEffect, useRef, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants';
import { WASMDataF } from '../../types/WASMData'; import { WASMDataF } from '../../types/WASMData';
import { LoadingState, SimBrief } from '../../types/general'; import { LoadingState, SimBrief } from '../../types/general';
@ -18,11 +18,8 @@ const SBEntryF: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoadi
const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget); const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget);
const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel)); const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel));
const [fuelEnabled, setFuelEnabled] = useState(true); const [fuelEnabled, setFuelEnabled] = useState(true);
const [SBPlan, setSBPlan] = useState<SimBrief>();
const [SBInFlight, setSBInFlight] = useState(false); const [SBInFlight, setSBInFlight] = useState(false);
const cargo = useRef(0);
const ZFW = () => { const ZFW = () => {
if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.total); if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.total);
@ -75,11 +72,8 @@ const SBEntryF: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoadi
return; return;
} }
cargo.current = parseFloat(SBResponse.message.cargo) ?? 0;
updateData(undefined, SBResponse.message); updateData(undefined, SBResponse.message);
setSBPlan(SBResponse.message);
setFuel(parseFloat(SBResponse.message.fuel) ?? 0); setFuel(parseFloat(SBResponse.message.fuel) ?? 0);
setSBInFlight(false); setSBInFlight(false);
}; };
@ -96,8 +90,8 @@ const SBEntryF: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoadi
setFuelEnabled(inRangeOf(Math.round(WASMData.livePayload.fuel), fuel)); setFuelEnabled(inRangeOf(Math.round(WASMData.livePayload.fuel), fuel));
}, [WASMData.livePayload.fuel]); }, [WASMData.livePayload.fuel]);
const updateData = (_CGTarget?: number, _SBPlan?: SimBrief) => { const updateData = (_CGTarget?: number, SBPlan?: SimBrief) => {
CoherentCallSBEntryF(cargo.current ?? 0, _CGTarget ?? CGTarget, _SBPlan ?? SBPlan); CoherentCallSBEntryF(_CGTarget ?? CGTarget, SBPlan);
}; };
return ( return (
@ -139,7 +133,7 @@ const SBEntryF: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoadi
type="text" type="text"
placeholder="" placeholder=""
className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600"
value={SBPlan?.plannedZFW ?? WASMData.sbPlanned.ZFW} value={WASMData.sbPlanned.ZFW}
disabled disabled
/> />
</div> </div>
@ -149,7 +143,7 @@ const SBEntryF: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoadi
type="text" type="text"
placeholder="" placeholder=""
className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600"
value={SBPlan?.plannedGW ?? WASMData.sbPlanned.GW} value={WASMData.sbPlanned.GW}
disabled disabled
/> />
</div> </div>

View File

@ -1,4 +1,4 @@
import { FC, useEffect, useRef, useState } from 'react'; import { FC, useEffect, useState } from 'react';
import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants'; import { GSX_SERVICE_CALLED, GSX_SERVICE_FINISHED } from '../../constants';
import { WASMDataPax } from '../../types/WASMData'; import { WASMDataPax } from '../../types/WASMData';
import { LoadingState, SimBrief } from '../../types/general'; import { LoadingState, SimBrief } from '../../types/general';
@ -18,12 +18,8 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget); const [CGTarget, setCGTarget] = useState(WASMData.targetPayload.CGTarget);
const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel)); const [fuel, setFuel] = useState(Math.round(WASMData.livePayload.fuel));
const [fuelEnabled, setFuelEnabled] = useState(true); const [fuelEnabled, setFuelEnabled] = useState(true);
const [SBPlan, setSBPlan] = useState<SimBrief>();
const [SBInFlight, setSBInFlight] = useState(false); const [SBInFlight, setSBInFlight] = useState(false);
const numPax = useRef(0);
const cargo = useRef(0);
const ZFW = () => { const ZFW = () => {
if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.total); if (loadingState !== 'loaded' && !GSXActive()) return Math.round(WASMData.targetPayload.total);
@ -76,12 +72,8 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
return; return;
} }
cargo.current = parseFloat(SBResponse.message.cargo) ?? 0; updateData(undefined, SBResponse.message);
numPax.current = parseInt(SBResponse.message.pax) ?? 0;
updateData(SBResponse.message);
setSBPlan(SBResponse.message);
setFuel(parseFloat(SBResponse.message.fuel) ?? 0); setFuel(parseFloat(SBResponse.message.fuel) ?? 0);
setSBInFlight(false); setSBInFlight(false);
}; };
@ -95,11 +87,11 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
[WASMData.userData.isER] [WASMData.userData.isER]
); );
useEffect(() => { useEffect(() => {
setFuelEnabled(inRangeOf(Math.round(WASMData.livePayload.fuel), fuel)); setFuelEnabled((prev) => (!prev ? inRangeOf(Math.round(WASMData.livePayload.fuel), fuel) : prev));
}, [WASMData.livePayload.fuel]); }, [WASMData.livePayload.fuel]);
const updateData = (_CGTarget?: number, _SBPlan?: SimBrief) => { const updateData = (_CGTarget?: number, SBPlan?: SimBrief) => {
CoherentCallSBEntryPax(cargo.current ?? 0, numPax.current ?? 0, _CGTarget ?? CGTarget, _SBPlan ?? SBPlan); CoherentCallSBEntryPax(_CGTarget ?? CGTarget, SBPlan);
}; };
return ( return (
@ -141,7 +133,7 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
type="text" type="text"
placeholder="" placeholder=""
className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600"
value={SBPlan?.plannedZFW ?? WASMData.sbPlanned.ZFW} value={WASMData.sbPlanned.ZFW}
disabled disabled
/> />
</div> </div>
@ -151,7 +143,7 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
type="text" type="text"
placeholder="" placeholder=""
className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600" className="w-1/2 rounded-lg border border-white bg-zinc-700 px-3 py-2 text-right focus:border-blue-600 focus:ring-blue-600"
value={SBPlan?.plannedGW ?? WASMData.sbPlanned.GW} value={WASMData.sbPlanned.GW}
disabled disabled
/> />
</div> </div>

View File

@ -92,31 +92,30 @@ export const CoherentCallStationEntryF = (
); );
}; };
export const CoherentCallSBEntryPax = (cargo: number, numPax: number, CGTarget: number, SBPlan?: SimBrief) => { export const CoherentCallSBEntryPax = (CGTarget: number, SBPlan?: SimBrief) => {
Coherent.call( const payload = {
COHERENT_COMM_BUS_WASM_CALL, mode: MODE_SB_SET,
COMM_BUS_UPDATE_TARGET_EVENT, cargo: SBPlan?.cargo,
JSON.stringify({ numPax: SBPlan ? parseInt(SBPlan.pax as unknown as string) : undefined,
mode: MODE_SB_SET, CGTarget: CGTarget,
cargo: cargo, plannedZFW: SBPlan?.plannedZFW,
numPax: numPax, plannedGW: SBPlan?.plannedGW,
CGTarget: CGTarget, };
plannedZFW: SBPlan?.plannedZFW ?? 0, const string = JSON.stringify(payload);
plannedGW: SBPlan?.plannedGW ?? 0,
}) Coherent.call(COHERENT_COMM_BUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT, string);
);
}; };
export const CoherentCallSBEntryF = (cargo: number, CGTarget: number, SBPlan?: SimBrief) => { export const CoherentCallSBEntryF = (CGTarget: number, SBPlan?: SimBrief) => {
Coherent.call( Coherent.call(
COHERENT_COMM_BUS_WASM_CALL, COHERENT_COMM_BUS_WASM_CALL,
COMM_BUS_UPDATE_TARGET_EVENT, COMM_BUS_UPDATE_TARGET_EVENT,
JSON.stringify({ JSON.stringify({
mode: MODE_SB_SET, mode: MODE_SB_SET,
cargo: cargo, cargo: SBPlan?.cargo,
CGTarget: CGTarget, CGTarget: CGTarget,
plannedZFW: SBPlan?.plannedZFW ?? 0, plannedZFW: SBPlan?.plannedZFW,
plannedGW: SBPlan?.plannedGW ?? 0, plannedGW: SBPlan?.plannedGW,
}) })
); );
}; };

View File

@ -502,26 +502,36 @@ int receiveData(const char* buf) {
switch(mode) { switch(mode) {
// SB Entry // SB Entry
case 0: { case 0: {
if (!document.HasMember("cargo") || !document.HasMember("CGTarget") || !document.HasMember("plannedZFW") || !document.HasMember("plannedGW")) return -1;
unsigned int cargo = document["cargo"].GetInt();
double CGTarget = document["CGTarget"].GetDouble();
if (UserData->isCargo) { if (UserData->isCargo) {
targetFPayloadData->CGTarget = CGTarget; if(document.HasMember("CGTarget"))
targetFPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble(); targetFPayloadData->CGTarget = document["CGTarget"].GetDouble();
targetFPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble();
if (document.HasMember("plannedZFW"))
targetFPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble();
if (document.HasMember("plannedGW"))
targetFPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble();
if (document.HasMember("cargo"))
targetFPayloadData->sbPlanned.cargo = document["cargo"].GetInt();
distribute(targetFPayloadData, liveFuelData, cargo, UserData->isImperial, UserData->isER); distribute(targetFPayloadData, liveFuelData, targetFPayloadData->sbPlanned.cargo, UserData->isImperial, UserData->isER);
} }
else { else {
if (!document.HasMember("numPax")) return -1; if (document.HasMember("CGTarget"))
unsigned short numPax = document["numPax"].GetInt(); targetPaxPayloadData->CGTarget = document["CGTarget"].GetDouble();
targetPaxPayloadData->CGTarget = CGTarget; if (document.HasMember("plannedZFW"))
targetPaxPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble(); targetPaxPayloadData->sbPlanned.ZFW = document["plannedZFW"].GetDouble();
targetPaxPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble(); if (document.HasMember("plannedGW"))
targetPaxPayloadData->sbPlanned.GW = document["plannedGW"].GetDouble();
distribute(targetPaxPayloadData, liveFuelData, numPax, cargo, UserData->isImperial, UserData->isER); if (document.HasMember("numPax"))
targetPaxPayloadData->sbPlanned.pax = document["numPax"].GetInt();
if (document.HasMember("cargo"))
targetPaxPayloadData->sbPlanned.cargo = document["cargo"].GetInt();
distribute(targetPaxPayloadData, liveFuelData, targetPaxPayloadData->sbPlanned.pax, targetPaxPayloadData->sbPlanned.cargo, UserData->isImperial,
UserData->isER);
} }
break; break;
} }
@ -809,6 +819,10 @@ void sendData () {
// SB Planned // SB Planned
sbPlanned.AddMember("ZFW", UserData->isCargo ? targetFPayloadData->sbPlanned.ZFW: targetPaxPayloadData->sbPlanned.ZFW, allocator); sbPlanned.AddMember("ZFW", UserData->isCargo ? targetFPayloadData->sbPlanned.ZFW: targetPaxPayloadData->sbPlanned.ZFW, allocator);
sbPlanned.AddMember("GW", UserData->isCargo ? targetFPayloadData->sbPlanned.GW : targetPaxPayloadData->sbPlanned.GW, allocator); sbPlanned.AddMember("GW", UserData->isCargo ? targetFPayloadData->sbPlanned.GW : targetPaxPayloadData->sbPlanned.GW, allocator);
sbPlanned.AddMember("cargo", UserData->isCargo ? targetFPayloadData->sbPlanned.cargo : targetPaxPayloadData->sbPlanned.cargo, allocator);
if (!UserData->isCargo) {
sbPlanned.AddMember("pax", targetPaxPayloadData->sbPlanned.pax, allocator);
}
// Construct document // Construct document
document.AddMember("livePayload", livePayload.Move(), allocator); document.AddMember("livePayload", livePayload.Move(), allocator);

View File

@ -190,6 +190,8 @@ typedef struct {
struct sbPlanned { struct sbPlanned {
double ZFW; double ZFW;
double GW; double GW;
unsigned short pax;
unsigned int cargo;
} sbPlanned; } sbPlanned;
} paxPayloadData_t; } paxPayloadData_t;
typedef struct { typedef struct {
@ -250,6 +252,7 @@ typedef struct {
struct sbPlanned { struct sbPlanned {
double ZFW; double ZFW;
double GW; double GW;
unsigned int cargo;
} sbPlanned; } sbPlanned;
} fPayloadData_t; } fPayloadData_t;
typedef struct { typedef struct {