Setting of payload
This commit is contained in:
parent
8975ea17af
commit
f7304c5c7b
@ -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<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
|
||||
|
||||
<ActionBar
|
||||
loadingState={loadingState}
|
||||
acceptDisabled={!GWValid() || SBInFlight}
|
||||
accept={() => setLoadingState('loaded')}
|
||||
reject={() => setLoadingState('preview')}
|
||||
loadDisabled={!GWValid() || SBInFlight}
|
||||
importSB={handleSB}
|
||||
load={() => {
|
||||
setLoadingState('loaded');
|
||||
@ -226,7 +224,7 @@ const SBEntryPax: FC<SBEntryProps> = ({ WASMData, loadingState, username, setLoa
|
||||
unload={() => {
|
||||
setLoadingState('preview');
|
||||
|
||||
emptyAircraft();
|
||||
unloadAircraft();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@ -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<ActionBarProps> = ({ loadingState, acceptDisabled, accept, reject, importSB, load, unload }) => {
|
||||
const ActionBar: FC<ActionBarProps> = ({ loadingState, loadDisabled, importSB, load, unload }) => {
|
||||
return (
|
||||
<div className="relative flex w-full items-center justify-start gap-x-6">
|
||||
{/*TODO: HIDE FOR GSX SYNCED */}
|
||||
{loadingState === 'preview' && (
|
||||
<button
|
||||
className="middle none center rounded-lg bg-green-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-green-500/20 transition-all hover:shadow-lg hover:shadow-green-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
data-ripple-light="true"
|
||||
onClick={accept}
|
||||
disabled={acceptDisabled}
|
||||
onClick={load}
|
||||
disabled={loadDisabled}
|
||||
>
|
||||
Accept
|
||||
Load
|
||||
</button>
|
||||
)}
|
||||
{/*TODO: Make GSX optional (accepted state for NON GSX) */}
|
||||
{/*TODO: HIDE FOR GSX SYNCED */}
|
||||
{loadingState === 'loaded' && (
|
||||
<button
|
||||
className="middle none center rounded-lg bg-red-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-red-500/20 transition-all hover:shadow-lg hover:shadow-red-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
data-ripple-light="true"
|
||||
onClick={reject}
|
||||
onClick={unload}
|
||||
>
|
||||
Reject
|
||||
Unload
|
||||
</button>
|
||||
)}
|
||||
|
||||
@ -46,27 +45,6 @@ const ActionBar: FC<ActionBarProps> = ({ loadingState, acceptDisabled, accept, r
|
||||
Import from SimBrief
|
||||
</button>
|
||||
)}
|
||||
{/*TODO: Make GSX optional */}
|
||||
{/*
|
||||
{loadingState === 'accepted' && (
|
||||
<button
|
||||
className="middle none center rounded-lg bg-green-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-green-500/20 transition-all hover:shadow-lg hover:shadow-green-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
data-ripple-light="true"
|
||||
onClick={load}
|
||||
>
|
||||
Load
|
||||
</button>
|
||||
)}
|
||||
{loadingState === 'loaded' && (
|
||||
<button
|
||||
className="middle none center rounded-lg bg-red-600 px-6 py-3 font-sans text-xs font-bold uppercase text-white shadow-md shadow-red-500/20 transition-all hover:shadow-lg hover:shadow-red-500/40 focus:opacity-[0.85] focus:shadow-none active:opacity-[0.85] active:shadow-none disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none"
|
||||
data-ripple-light="true"
|
||||
onClick={unload}
|
||||
>
|
||||
Unload
|
||||
</button>
|
||||
)}
|
||||
*/}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@ -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<PaxProps> = ({ 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<PaxProps> = ({ 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<PaxProps> = ({ WASMData, username }) => {
|
||||
WASMData={WASMData}
|
||||
loadingState={loadingState}
|
||||
setLoadingState={setLoadingState}
|
||||
loadAircraft={() => {
|
||||
console.log('SET WEIGHT STATIONS');
|
||||
}}
|
||||
loadAircraft={loadAircraft}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
|
||||
@ -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<StationEntryProps> = ({ WASMData, loadingState, setLoa
|
||||
|
||||
<ActionBar
|
||||
loadingState={loadingState}
|
||||
acceptDisabled={!ZFWValid() || !GWValid()}
|
||||
accept={() => setLoadingState('accepted')}
|
||||
reject={() => setLoadingState('preview')}
|
||||
loadDisabled={!ZFWValid() || !GWValid()}
|
||||
load={() => {
|
||||
setLoadingState('loaded');
|
||||
|
||||
@ -221,7 +219,7 @@ const StationEntryPax: FC<StationEntryProps> = ({ WASMData, loadingState, setLoa
|
||||
unload={() => {
|
||||
setLoadingState('preview');
|
||||
|
||||
emptyAircraft();
|
||||
unloadAircraft();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@ -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<ZFWEntryProps> = ({ WASMData, loadingState, setLoadingStat
|
||||
|
||||
<ActionBar
|
||||
loadingState={loadingState}
|
||||
acceptDisabled={!GWValid()}
|
||||
accept={() => setLoadingState('accepted')}
|
||||
reject={() => setLoadingState('preview')}
|
||||
loadDisabled={!GWValid()}
|
||||
load={() => {
|
||||
setLoadingState('loaded');
|
||||
|
||||
@ -211,7 +209,7 @@ const ZFWEntryPax: FC<ZFWEntryProps> = ({ WASMData, loadingState, setLoadingStat
|
||||
unload={() => {
|
||||
setLoadingState('preview');
|
||||
|
||||
emptyAircraft();
|
||||
unloadAircraft();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@ -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,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
@ -1 +1 @@
|
||||
export type LoadingState = 'preview' | 'accepted' | 'loaded';
|
||||
export type LoadingState = 'preview' | 'loaded';
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -12,8 +12,6 @@
|
||||
|
||||
#include <MSFS/MSFS.h>
|
||||
#include <MSFS/MSFS_CommBus.h>
|
||||
#include <MSFS/MSFS_Core.h>
|
||||
#include <MSFS/MSFS_Render.h>
|
||||
#include <MSFS/Legacy/gauges.h>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -10,10 +10,14 @@
|
||||
# define __restrict__
|
||||
#endif
|
||||
|
||||
#include <MSFS/MSFS_WindowsTypes.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <SimConnect.h>
|
||||
|
||||
#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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user