<!-- Airbus A320 FMGC -->

<!-- Copyright (c) 2019 Jonathan Redpath -->

<system name="A320: FMGC">

	<channel name="FMGC Power" execrate="8">
	
		<switch name="/systems/fmgc/power/power-1">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/electrical/bus/dc-ess-shed ge 25
			</test>
		</switch>
	
		<switch name="/systems/fmgc/power/power-2">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/electrical/bus/dc-2 ge 25
			</test>
		</switch>
		
		<actuator name="/systems/fmgc/power/power-1-timer">
			<input>/systems/fmgc/power/power-1</input>
			<rate_limit sense="decr">5</rate_limit>
			<rate_limit sense="incr">100</rate_limit>
		</actuator>
		
		<actuator name="/systems/fmgc/power/power-2-timer">
			<input>/systems/fmgc/power/power-2</input>
			<rate_limit sense="decr">5</rate_limit>
			<rate_limit sense="incr">100</rate_limit>
		</actuator>
		
		<switch name="/systems/fmgc/power/power-1-on">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/fmgc/power/power-1-timer ne 0
			</test>
		</switch>
	
		<switch name="/systems/fmgc/power/power-2-on">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/fmgc/power/power-2-timer ne 0
			</test>
		</switch>
		
	</channel>
	
	<channel name="Envelope Protection" execrate="8">
		
		<!-- VMCA -->
		<fcs_function name="/FMGC/internal/vmca-kt">
			<function>
				<table>
					<independentVar lookup="row">/position/altitude-ft</independentVar>
					<tableData>
						-2000	112.0
						 0		110.0
						 2000	108.0
						 4000	107.5
						 6000	105.5
						 8000	103.0
						 9200	101.2
						10000	100.0
						12000	 96.5
						14100	 93.5
					</tableData>
				</table>
			</function>
		</fcs_function>
		
		<!-- VMCG -->
		<fcs_function name="/FMGC/internal/vmcg-kt">
			<function>
				<table>
					<independentVar lookup="row">/position/altitude-ft</independentVar>
					<independentVar lookup="column">fcs/flap-pos-deg</independentVar>
					<tableData>
								10		15		20
						-2000	111.5	109.5	109.0
						 0		109.5	107.5	107.0
						 2000	107.5	105.5	105.0
						 4000	107.0	105.0	104.5
						 6000	105.0	103.0	103.0
						 8000	103.0	101.0	100.5
						 9200	101.0	 99.0	 98.5
						10000	100.0	 98.0	 97.5
						12000	 96.5	 94.5	 94.0
						14100	 93.0	 91.0	 91.0
					</tableData>
				</table>
			</function>
		</fcs_function>
		
	</channel>
	
	<channel name="FMGC" execrate="8">
	
		<switch name="/systems/fmgc/airborne">
			<default value="0"/>
			<test logic="OR" value="1">
				/gear/gear[1]/wow eq 0
				/gear/gear[2]/wow eq 0
			</test>
		</switch>
		
		<actuator name="/systems/fmgc/airborne-timer">
			<input>/systems/fmgc/airborne</input>
			<rate_limit sense="decr">100</rate_limit>
			<rate_limit sense="incr">0.2</rate_limit>
		</actuator>
		
		<switch name="/systems/fmgc/airborne-5-secs">
			<default value="0"/>
			<test logic="OR" value="1">
				/systems/fmgc/airborne-timer eq 1
			</test>
		</switch>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-1-to-3">
			<function>
				<abs>
					<difference>
						<property>/systems/navigation/adr/output/cas-1</property>
						<property>/systems/navigation/adr/output/cas-3</property>
					</difference>
				</abs>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-2-to-3">
			<function>
				<abs>
					<difference>
						<property>/systems/navigation/adr/output/cas-2</property>
						<property>/systems/navigation/adr/output/cas-3</property>
					</difference>
				</abs>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-2-to-1">
			<function>
				<abs>
					<difference>
						<property>/systems/navigation/adr/output/cas-2</property>
						<property>/systems/navigation/adr/output/cas-1</property>
					</difference>
				</abs>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-reject-all">
			<function>
				<ifthen>
					<and>
						<gt>
							<property>/systems/fmgc/cas-compare/cas-1-to-3</property>
							<value>5</value> <!-- todo - find proper value -->
						</gt>
						<gt>
							<property>/systems/fmgc/cas-compare/cas-2-to-1</property>
							<value>5</value>
						</gt>
						<gt>
							<property>/systems/fmgc/cas-compare/cas-2-to-3</property>
							<value>5</value>
						</gt>
					</and>
					<value>1</value>
					<value>0</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-reject-1"> <!-- 2 and 3 are the same but 1 is different -->
			<function>
				<ifthen>
					<or>
						<eq>
							<property>/systems/navigation/adr/operating-1</property>
							<value>0</value>
						</eq>
						<and>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-1-to-3</property>
								<value>5</value> <!-- todo - find proper value -->
							</gt>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-2-to-1</property>
								<value>5</value>
							</gt>
							<lt>
								<property>/systems/fmgc/cas-compare/cas-2-to-3</property>
								<value>5</value>
							</lt>
							<eq>
								<property>/systems/navigation/adr/operating-2</property>
								<value>1</value>
							</eq>
							<eq>
								<property>/systems/navigation/adr/operating-3</property>
								<value>1</value>
							</eq>
						</and>
					</or>
					<value>1</value>
					<value>0</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-reject-2"> <!-- 1 and 3 are the same but 2 is different -->
			<function>
				<ifthen>
					<or>
						<eq>
							<property>/systems/navigation/adr/operating-2</property>
							<value>0</value>
						</eq>
						<and>
							<lt>
								<property>/systems/fmgc/cas-compare/cas-1-to-3</property>
								<value>5</value>
							</lt>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-2-to-1</property>
								<value>5</value>
							</gt>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-2-to-3</property>
								<value>5</value>
							</gt>
							<eq>
								<property>/systems/navigation/adr/operating-1</property>
								<value>1</value>
							</eq>
							<eq>
								<property>/systems/navigation/adr/operating-3</property>
								<value>1</value>
							</eq>
						</and>
					</or>
					<value>1</value>
					<value>0</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/cas-compare/cas-reject-3"> <!-- 1 and 2 are the same but 3 is different -->
			<function>
				<ifthen>
					<or>
						<eq>
							<property>/systems/navigation/adr/operating-3</property>
							<value>0</value>
						</eq>
						<and>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-1-to-3</property>
								<value>5</value>
							</gt>
							<lt>
								<property>/systems/fmgc/cas-compare/cas-2-to-1</property>
								<value>5</value>
							</lt>
							<gt>
								<property>/systems/fmgc/cas-compare/cas-2-to-3</property>
								<value>5</value>
							</gt>
							<eq>
								<property>/systems/navigation/adr/operating-1</property>
								<value>1</value>
							</eq>
							<eq>
								<property>/systems/navigation/adr/operating-2</property>
								<value>1</value>
							</eq>
						</and>
					</or>
					<value>1</value>
					<value>0</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/active-airspeed-src-1">
			<function>
				<ifthen>
					<eq>
						<property>/systems/fmgc/cas-compare/cas-reject-1</property>
						<value>1</value>
					</eq>
					<value>3</value>
					<value>1</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/active-airspeed-1">
			<function>
				<ifthen>
					<eq>
						<property>/systems/fmgc/active-airspeed-src-1</property>
						<value>1</value>
					</eq>
					<property>/systems/navigation/adr/output/cas-1</property>
					<property>/systems/navigation/adr/output/cas-3</property>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/active-airspeed-src-2">
			<function>
				<ifthen>
					<eq>
						<property>/systems/fmgc/cas-compare/cas-reject-2</property>
						<value>1</value>
					</eq>
					<value>3</value>
					<value>2</value>
				</ifthen>
			</function>
		</fcs_function>
		
		<fcs_function name="/systems/fmgc/active-airspeed-2">
			<function>
				<ifthen>
					<eq>
						<property>/systems/fmgc/active-airspeed-src-2</property>
						<value>2</value>
					</eq>
					<property>/systems/navigation/adr/output/cas-2</property>
					<property>/systems/navigation/adr/output/cas-3</property>
				</ifthen>
			</function>
		</fcs_function>
	</channel>

</system>