diff --git a/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx b/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx index 4500b7b..8d22dd6 100644 --- a/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/SBEntry/SBEntryPax.tsx @@ -1,5 +1,5 @@ import { FC, useEffect, useRef, useState } from 'react'; -import { emptyAircraft } from '../../configs/shared'; +import { unloadAircraft } from '../../configs/shared'; import { COHERENT_COMBUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../../constants'; import { WASMDataPax } from '../../types/WASMData'; import { LoadingState } from '../../types/general'; @@ -214,9 +214,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa setLoadingState('loaded')} - reject={() => setLoadingState('preview')} + loadDisabled={!GWValid() || SBInFlight} importSB={handleSB} load={() => { setLoadingState('loaded'); @@ -226,7 +224,7 @@ const SBEntryPax: FC = ({ WASMData, loadingState, username, setLoa unload={() => { setLoadingState('preview'); - emptyAircraft(); + unloadAircraft(); }} /> diff --git a/PackageSources/js-bundle/src/components/actionbar/ActionBar.tsx b/PackageSources/js-bundle/src/components/actionbar/ActionBar.tsx index cf78ae9..b0eb0c8 100644 --- a/PackageSources/js-bundle/src/components/actionbar/ActionBar.tsx +++ b/PackageSources/js-bundle/src/components/actionbar/ActionBar.tsx @@ -3,35 +3,34 @@ import { LoadingState } from '../../types/general'; interface ActionBarProps { loadingState: LoadingState; - acceptDisabled: boolean; - accept: () => void; - reject: () => void; + loadDisabled: boolean; importSB?: () => void; load: () => void; unload: () => void; } -const ActionBar: FC = ({ loadingState, acceptDisabled, accept, reject, importSB, load, unload }) => { +const ActionBar: FC = ({ loadingState, loadDisabled, importSB, load, unload }) => { return (
+ {/*TODO: HIDE FOR GSX SYNCED */} {loadingState === 'preview' && ( )} - {/*TODO: Make GSX optional (accepted state for NON GSX) */} + {/*TODO: HIDE FOR GSX SYNCED */} {loadingState === 'loaded' && ( )} @@ -46,27 +45,6 @@ const ActionBar: FC = ({ loadingState, acceptDisabled, accept, r Import from SimBrief )} - {/*TODO: Make GSX optional */} - {/* - {loadingState === 'accepted' && ( - - )} - {loadingState === 'loaded' && ( - - )} - */}
); }; diff --git a/PackageSources/js-bundle/src/components/pax/Pax.tsx b/PackageSources/js-bundle/src/components/pax/Pax.tsx index 0ef8d0a..5f64e6f 100644 --- a/PackageSources/js-bundle/src/components/pax/Pax.tsx +++ b/PackageSources/js-bundle/src/components/pax/Pax.tsx @@ -1,4 +1,5 @@ import { FC, useState } from 'react'; +import { loadAircraft } from '../../configs/shared'; import { LoadingState } from '../../types/general'; import { WASMDataPax } from '../../types/WASMData'; import Profile from '../profile/Profile'; @@ -109,9 +110,7 @@ const Pax: FC = ({ WASMData, username }) => { loadingState={loadingState} username={username} setLoadingState={setLoadingState} - loadAircraft={() => { - console.log('SET WEIGHT SB'); - }} + loadAircraft={loadAircraft} /> )} {((username && selectedTab === 1) || (!username && selectedTab === 0)) && ( @@ -119,9 +118,7 @@ const Pax: FC = ({ WASMData, username }) => { WASMData={WASMData} loadingState={loadingState} setLoadingState={setLoadingState} - loadAircraft={() => { - console.log('SET WEIGHT ZFW'); - }} + loadAircraft={loadAircraft} /> )} {((username && selectedTab === 2) || (!username && selectedTab === 1)) && ( @@ -129,9 +126,7 @@ const Pax: FC = ({ WASMData, username }) => { WASMData={WASMData} loadingState={loadingState} setLoadingState={setLoadingState} - loadAircraft={() => { - console.log('SET WEIGHT STATIONS'); - }} + loadAircraft={loadAircraft} /> )} diff --git a/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx b/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx index e78ca31..f099b2d 100644 --- a/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/stationEntry/StationEntryPax.tsx @@ -1,5 +1,5 @@ import { FC, useEffect, useState } from 'react'; -import { emptyAircraft } from '../../configs/shared'; +import { unloadAircraft } from '../../configs/shared'; import { COHERENT_COMBUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../../constants'; import { LoadingState } from '../../types/general'; import { WASMDataPax } from '../../types/WASMData'; @@ -210,9 +210,7 @@ const StationEntryPax: FC = ({ WASMData, loadingState, setLoa setLoadingState('accepted')} - reject={() => setLoadingState('preview')} + loadDisabled={!ZFWValid() || !GWValid()} load={() => { setLoadingState('loaded'); @@ -221,7 +219,7 @@ const StationEntryPax: FC = ({ WASMData, loadingState, setLoa unload={() => { setLoadingState('preview'); - emptyAircraft(); + unloadAircraft(); }} /> diff --git a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx index 4a59bfd..be2aa9d 100644 --- a/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx +++ b/PackageSources/js-bundle/src/components/zfwEntry/ZFWEntryPax.tsx @@ -1,5 +1,5 @@ import { FC, useEffect, useState } from 'react'; -import { emptyAircraft } from '../../configs/shared'; +import { unloadAircraft } from '../../configs/shared'; import { COHERENT_COMBUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../../constants'; import { WASMDataPax } from '../../types/WASMData'; import { LoadingState } from '../../types/general'; @@ -200,9 +200,7 @@ const ZFWEntryPax: FC = ({ WASMData, loadingState, setLoadingStat setLoadingState('accepted')} - reject={() => setLoadingState('preview')} + loadDisabled={!GWValid()} load={() => { setLoadingState('loaded'); @@ -211,7 +209,7 @@ const ZFWEntryPax: FC = ({ WASMData, loadingState, setLoadingStat unload={() => { setLoadingState('preview'); - emptyAircraft(); + unloadAircraft(); }} /> diff --git a/PackageSources/js-bundle/src/configs/shared.ts b/PackageSources/js-bundle/src/configs/shared.ts index 4d68078..91a7a3d 100644 --- a/PackageSources/js-bundle/src/configs/shared.ts +++ b/PackageSources/js-bundle/src/configs/shared.ts @@ -1,11 +1,21 @@ -import { COHERENT_COMBUS_WASM_CALL, COMM_BUS_LIVE_DATA_EVENT } from '../constants'; +import { COHERENT_COMBUS_WASM_CALL, COMM_BUS_UPDATE_TARGET_EVENT } from '../constants'; -export const emptyAircraft = () => { +export const loadAircraft = () => { Coherent.call( COHERENT_COMBUS_WASM_CALL, - COMM_BUS_LIVE_DATA_EVENT, + COMM_BUS_UPDATE_TARGET_EVENT, JSON.stringify({ mode: 3, }) ); }; + +export const unloadAircraft = () => { + Coherent.call( + COHERENT_COMBUS_WASM_CALL, + COMM_BUS_UPDATE_TARGET_EVENT, + JSON.stringify({ + mode: 4, + }) + ); +}; diff --git a/PackageSources/js-bundle/src/types/general.d.ts b/PackageSources/js-bundle/src/types/general.d.ts index 8adadd5..284dc5c 100644 --- a/PackageSources/js-bundle/src/types/general.d.ts +++ b/PackageSources/js-bundle/src/types/general.d.ts @@ -1 +1 @@ -export type LoadingState = 'preview' | 'accepted' | 'loaded'; +export type LoadingState = 'preview' | 'loaded'; diff --git a/PackageSources/wasm-module/load-manager.cpp b/PackageSources/wasm-module/load-manager.cpp index 34087b2..d960f21 100644 --- a/PackageSources/wasm-module/load-manager.cpp +++ b/PackageSources/wasm-module/load-manager.cpp @@ -500,6 +500,28 @@ int receiveData(const char* buf) { } break; } + // Trigger load + case 3: { + if (UserData->isCargo) { + + } + else { + load(targetPaxPayloadData, simConnect, UserData->isImperial); + } + + break; + } + // Trigger unload + case 4: { + if (UserData->isCargo) { + + } + else { + unload(simConnect, UserData->isImperial); + } + + break; + } default: break; } diff --git a/PackageSources/wasm-module/load-manager.h b/PackageSources/wasm-module/load-manager.h index 61c91b9..456d459 100644 --- a/PackageSources/wasm-module/load-manager.h +++ b/PackageSources/wasm-module/load-manager.h @@ -12,8 +12,6 @@ #include #include -#include -#include #include #include @@ -29,25 +27,6 @@ #define COMM_BUS_LIVE_DATA_EVENT "khofmann_tfdi_md-11_load_manager_live_data" #define COMM_BUS_UPDATE_TARGET_EVENT "khofmann_tfdi_md-11_load_manager_update_target" -// SimConnect ENUMs -enum DATA_DEFINITIONS { - DATA_DEFINITION_EMPTY_WEIGHT, - DATA_DEFINITION_PAYLOAD_PAX, - DATA_DEFINITION_PAYLOAD_F, - DATA_DEFINITION_FUEL, - DATA_DEFINITION_GSX, - DATA_DEFINITION_USER_DATA, -}; - -enum DATA_REQUESTS { - DATA_REQUEST_EMPTY_WEIGHT, - DATA_REQUEST_PAYLOAD_PAX, - DATA_REQUEST_PAYLOAD_F, - DATA_REQUEST_FUEL, - DATA_REQUEST_GSX, - DATA_REQUEST_USER_DATA, -}; - void commBusUpdateTargetCallback(const char* args, unsigned int size, void* ctx); int receiveData(const char* buf); void sendData(); diff --git a/PackageSources/wasm-module/pax.cpp b/PackageSources/wasm-module/pax.cpp index a6add30..7b9bbf6 100644 --- a/PackageSources/wasm-module/pax.cpp +++ b/PackageSources/wasm-module/pax.cpp @@ -5,13 +5,13 @@ void distribute(paxPayloadData_t* const targetPayload, const FuelData_t* const f // Find payload, num pax and extra cargo double payload = ZFWTarget - targetPayload->empty - targetPayload->pilot - targetPayload->firstOfficer - targetPayload->engineer - targetPayload->cabinCrewFront - targetPayload->cabinCrewRear - targetPayload->leftAux - targetPayload->rightAux; - unsigned short numPax = std::max(0.0, std::min((double)MAX_PAX, floor(payload / (PAX_WEIGHT(isImperial) + BAG_WEIGHT(isImperial))))); + unsigned short numPax = max(0.0, min((double)MAX_PAX, floor(payload / (PAX_WEIGHT(isImperial) + BAG_WEIGHT(isImperial))))); unsigned int cargo = round(payload - numPax * PAX_WEIGHT(isImperial) - numPax * BAG_WEIGHT(isImperial)); distribute(targetPayload, fuel, numPax, cargo, isImperial); } -//SimBrief Entry, SB pax count and total cargo +//SimBrief Entry, SB pax count and extra cargo void distribute(paxPayloadData_t* const targetPayload, const FuelData_t* const fuel, unsigned short numPax, unsigned int cargo, const bool isImperial) { // Clear targetPayload->paxCount.business1 = targetPayload->paxCount.business2 = targetPayload->paxCount.economy1 = targetPayload->paxCount.economy2 = @@ -288,4 +288,19 @@ void calculateCGs(const paxPayloadData_t* const targetPayload, const FuelData_t* totalWeight += fuel->total; *TOCG = TO_PERCENT_MAC(totalMoment / totalWeight); -} \ No newline at end of file +} + + +void load(const paxPayloadData_t* const targetPayload, const HANDLE simConnect, const bool isImperial) { + paxPayloadData_t localPayload = {}; + memcpy(&localPayload, targetPayload, sizeof(localPayload)); + normalisePayload(&localPayload, isImperial); + + SimConnect_SetDataOnSimObject(simConnect, DATA_DEFINITION_PAYLOAD_PAX, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(paxPayloadDataSet_t), &localPayload); +} + +void unload(const HANDLE simConnect, const bool isImperial) { + paxPayloadDataSet_t localPayload = {}; + + SimConnect_SetDataOnSimObject(simConnect, DATA_DEFINITION_PAYLOAD_PAX, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(localPayload), &localPayload); +} diff --git a/PackageSources/wasm-module/pax.h b/PackageSources/wasm-module/pax.h index 5c96023..332532e 100644 --- a/PackageSources/wasm-module/pax.h +++ b/PackageSources/wasm-module/pax.h @@ -10,10 +10,14 @@ # define __restrict__ #endif +#include + #include #include +#include + #include "types.h" //ZFW Entry, fill pax first (pax+bag), rest is cargo @@ -28,3 +32,5 @@ void generatePayload(paxPayloadData_t* const targetPayload, const bool isImperia // For Station Entry: CALL AFTER `generatePayload` void normalisePayload(paxPayloadData_t* const targetPayload, const bool isImperial); void calculateCGs(const paxPayloadData_t* const targetPayload, const FuelData_t* const fuel, double* const ZFWCG, double* const TOCG, const bool isImperial); +void load(const paxPayloadData_t* const targetPayload, const HANDLE simConnect, const bool isImperial); +void unload(const HANDLE simConnect, const bool isImperial); diff --git a/PackageSources/wasm-module/types.h b/PackageSources/wasm-module/types.h index 9cda9bd..67c8625 100644 --- a/PackageSources/wasm-module/types.h +++ b/PackageSources/wasm-module/types.h @@ -101,6 +101,25 @@ #define TO_POUNDS(IS_IMPERIAL, VALUE) ((IS_IMPERIAL) ? (VALUE) : (VALUE) * 2.20462262185) #define FROM_POUNDS(IS_IMPERIAL, VALUE) ((IS_IMPERIAL) ? (VALUE) : (VALUE) * (1.0 / 2.20462262185)) +// SimConnect ENUMs +enum DATA_DEFINITIONS { + DATA_DEFINITION_EMPTY_WEIGHT, + DATA_DEFINITION_PAYLOAD_PAX, + DATA_DEFINITION_PAYLOAD_F, + DATA_DEFINITION_FUEL, + DATA_DEFINITION_GSX, + DATA_DEFINITION_USER_DATA, +}; + +enum DATA_REQUESTS { + DATA_REQUEST_EMPTY_WEIGHT, + DATA_REQUEST_PAYLOAD_PAX, + DATA_REQUEST_PAYLOAD_F, + DATA_REQUEST_FUEL, + DATA_REQUEST_GSX, + DATA_REQUEST_USER_DATA, +}; + // Data typedef struct { double isCargo; @@ -155,6 +174,29 @@ typedef struct { unsigned short total; } paxCount; } paxPayloadData_t; +typedef struct { + double pilot; + double firstOfficer; + double engineer; + double cabinCrewFront; + double business1Left; + double business1Center; + double business1Right; + double business2Left; + double business2Center; + double business2Right; + double economy1Left; + double economy1Center; + double economy1Right; + double economy2Left; + double economy2Center; + double economy2Right; + double cabinCrewRear; + double forwardCargo; + double rearCargo; + double leftAux; + double rightAux; +} paxPayloadDataSet_t; typedef struct { // SimConnect mapped @@ -181,6 +223,24 @@ typedef struct { double ZFWCG; double TOCG; } fPayloadData_t; +typedef struct { + // SimConnect mapped + double pilot; + double firstOfficer; + double engineer; + double upper1Left; + double upper1Right; + double upper2Left; + double upper2Right; + double upper3Left; + double upper3Right; + double upper4Left; + double upper4Right; + double lowerForward; + double lowerRear; + double leftAux; + double rightAux; +} fPayloadDataSet_t; typedef struct { // SimConnect mapped diff --git a/README.md b/README.md index 32955e5..bab64d5 100644 --- a/README.md +++ b/README.md @@ -14,5 +14,4 @@ TODO: - Persist SB data across page changes - Duplicate Input pages for F - WASM - - Setting of payload - GSX synced setting of payload