<?xml version="1.0"?>

<!-- Airbus A320 FMGC -->
<!-- Copyright (c) 2021 Josh Davidson and Jonathan Redpath -->

<system name="A320: FMGC">
	
	<property value="350">/FMGC/internal/vmo-kts</property>
	
	<channel name="FMGC" execrate="8">
		
		<fcs_function name="/FMGC/internal/mmo-kts">
			<function>
				<product>
					<quotient>
						<property>/instrumentation/airspeed-indicator/indicated-speed-kt</property>
						<max> <!-- Prevent divide by 0 -->
							<property>/instrumentation/airspeed-indicator/indicated-mach</property>
							<value>0.0000001</value>
						</max>
					</quotient>
					<value>0.82</value>
				</product>
			</function>
		</fcs_function>
		
		<switch name="/FMGC/internal/vmo-mmo">
			<default value="/FMGC/internal/vmo-kts"/>
			<test logic="AND" value="/FMGC/internal/mmo-kts">
				/FMGC/internal/mmo-kts lt /FMGC/internal/vmo-kts
				position/wow eq 0
			</test>
		</switch>
		
		<fcs_function name="/FMGC/internal/vmo-mmo-plus-6">
			<function>
				<sum>
					<property>/FMGC/internal/vmo-mmo</property>
					<value>6</value>
				</sum>
			</function>
		</fcs_function>
		
		<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>