<?php
	require_once('database.php');

	if (!defined("HOST")) define("HOST", "http://" . htmlentities($_SERVER["HTTP_HOST"]));
	
	if(isset($_POST["action"]) && !empty($_POST["action"])) {
		$action = isset($_POST["action"])?htmlentities($_POST["action"]):"";
		switch($action) {
			case "getFields" : 
				$fields = isset($_POST["fields"])?($_POST["fields"]):"";
				$senderId = isset($_POST["id"])?($_POST["id"]):"";
				$senderInstance = isset($_POST["instance"])?($_POST["instance"]):"";
				echo getFields($fields, $senderId, $senderInstance);
				break;
			case "getAlarmState" :
				echo getAlarmState();
				break;
		}
	}
	
	/**
	 * Queries fields from processor
	 * @param string[] $fields An array of fieldIds
	 * @param string   $senderId The senderId of $fields
	 * @param string   $senderInstance The senderInstance of $fields
	 **/
	function getFields($fields, $senderId, $senderInstance) {
		$queryString = HOST . ":8080?FieldId=";
		$queryString .= implode(",", $fields);
		$queryString .= '&amp;SenderId=' . $senderId . '&amp;SenderInstance=' . $senderInstance;
		return file_get_contents(str_replace(" ", "%20", $queryString));
	}
	
	/**
	 * Queries set of alarms to see if any are active
	 **/
	function getAlarmState() {
		$activeAlarms = array();
		
		//Get number of alarms
		$alarmCount = count(explode(',', readDB('Alarms', 'AlarmList')));
		
		for ($i = 0; $i < $alarmCount; $i++) {
			$fieldId = '0x142' . $i;
			try {
				$alarmState = @file_get_contents(str_replace(" ", "%20", HOST . ":8080?FieldId=" . $fieldId));
				if ($alarmState === false) {
					return;
				}
			} catch (Exception $e) {
				return;
			}
			if ( intval( explode('=', $alarmState)[1] ) == 1 ) {
				array_push( $activeAlarms, $i );
			}
			return implode(',', $activeAlarms);
		}
	}
	
	/**
	 * Enumerator for field names
	 **/
	abstract class fieldEnum {
			
		// GPS
		const GPS_Latitude   	= '0x0100';
		const GPS_Longitude 	= '0x0101';
		const GPS_HDOP      	= '0x0102';
		const GPS_SOG_KTS       = '0x0103';
		const GPS_COG_TRUE      = '0x0104';
		const GPS_COG_MAG       = '0x0105';
		const GPS_TIME          = '0x0106';
		const GPS_TIME_HHMMSS   = '0x0107';
		const GPS_Variation     = '0x0108';
		const GPS_SOG_KMH       = '0x0109';
		const GPS_Latitude_NMEA = '0x0110';
		const GPS_Longitude_NMEA= '0x0111';
		const GPS_North_South   = '0x0112';
		const GPS_East_West     = '0x0113';
		const GPS_XTE           = '0x0120';
		const GPS_VMC           = '0x0121';
		const GPS_Dist_To_Wpt   = '0x0122';
		const GPS_Bear_To_Wpt_T = '0x0123';
		const GPS_Bear_To_Wpt_M = '0x0124';
		
		// Speed Board
		const Log_Pulse_Time    = '0x0200';
		const Log_Pulse_Count   = '0x0201';
		const Boat_Speed_Kts    = '0x0202';   
		const Boat_Speed_mps    = '0x0203';
		const Log_PulseFreq     = '0x0204';
		const Boat_Speed_kmh    = '0x0205';
		const Water_Temp_C      = '0x0210';
	 
		// Wind Board
		const Wind_Pulse_Time   = '0x0300';
		const Wind_Pulse_Count  = '0x0301';
		const Wind_MAWS_kts     = '0x0302';
		const Wind_MAWA_Raw     = '0x0303';
		const Wind_MAWS_mps     = '0x0304';
		const Wind_PulseFreq	= '0x0305';
		const Wind_MAWS_Raw		= '0x0306';
		const Wind_MAWA			= '0x0307';
		const Wind_Phase_Red    = '0x0320';
		const Wind_Phase_Green  = '0x0321';
		const Wind_Phase_Blue   = '0x0322';
		const Wind_MHU_Voltage  = '0x0323';
		const WIND_MHU_Error 	= '0x0336';
	 
		// Depth Board
		const Depth_Timestamp   = '0x0400';
		const Depth_Metres      = '0x0401';
		const Depth_Feet        = '0x0402';
		const Depth_Fathoms     = '0x0403';
		const Depth_Offest	  	= '0x0404';
		const Depth_Signal      = '0x0410';
		const Depth_Noise       = '0x0411';
		const Depth_Reliability = '0x0412';

		// Heading Data
		const Heading_True      = '0x0500';
		const Heading_Magnetic  = '0x0501';
		const MagneticVariation = '0x0502';
		const HeadingDeviation  = '0x0503';
		const Heading_Offset_T  = '0x0504';
		const Heading_Offset_M  = '0x0505';
		const Ship_Heading_True = '0x0510';
		const Ship_Heading_Magn = '0x0511';

		const Compass_Turn_Rate	= '0x0520';
		
		// Environment - Sensor data
		const Env_AirTemp_C    		= '0x0700';
		const Env_AirTemp_F    		= '0x0701';
		const Env_WaterTemp_C   	= '0x0702';
		const Env_WaterTemp_F   	= '0x0703';
		const Heel_Angle_Deg   		= '0x0710';
		const Rudder_Ang_Stbd_Deg 	= '0x0711';
		const Rudder_Ang_Port_Deg 	= '0x0712';
		const Barometer           	= '0x0720';
		const Mast_Rotation       	= '0x0721';
		const Trim_Angle          	= '0x0722';
		const CPU_Temperature		= '0x0730';
		const Interface_Temp      	= '0x0731';
		const Raw_Accel_X         	= '0x0740';
		const Raw_Accel_Y         	= '0x0741';
		const Raw_Accel_Z         	= '0x0742';
		const Raw_Total_Gravity   	= '0x0743';
        
		const Calc_Accel_X        	= '0x0750';
		const Calc_Accel_Y        	= '0x0751';
		const Calc_Accel_Z        	= '0x0752';
		const Calc_Total_Gravity  	= '0x0753';

		const Heel_Gyro_Rate		= '0x0766';
		const Pitch_Gyro_Rate		= '0x0767';
		
		// Analog Data
		const Raw_Analogue_Start  = '0x0800';
		const Raw_Analogue_Val_1  = '0x0801';
		const Raw_Analogue_Val_2  = '0x0802';
		const Raw_Analogue_Val_3  = '0x0803';
		const Raw_Analogue_Val_4  = '0x0804';
		const Raw_Analogue_Val_5  = '0x0805';
		const Raw_Analogue_Ref_1  = '0x0811';
		const Raw_Analogue_Ref_2  = '0x0812';
		const Raw_Analogue_Ref_3  = '0x0813';
		const Raw_Analogue_Ref_4  = '0x0814';
		const Raw_Analogue_Ref_5  = '0x0815';
		
		// Remote User Data Channels ( this could be endless )
		const Remote_User_Ch_0    = '0x0900';
		const Remote_User_Ch_1    = '0x0901';
		const Remote_User_Ch_2    = '0x0902';
		const Remote_User_Ch_3    = '0x0903';
		const Remote_User_Ch_4    = '0x0904';
		const Remote_User_Ch_5    = '0x0905';
		const Remote_User_Ch_6    = '0x0906';
		const Remote_User_Ch_7    = '0x0907';
		const Remote_User_Ch_8    = '0x0908';
		const Remote_User_Ch_9    = '0x0909';
		const Remote_User_Ch_10   = '0x0910';
		const Remote_User_Ch_11   = '0x0911';
		const Remote_User_Ch_12   = '0x0912';
		const Remote_User_Ch_13   = '0x0913';
		const Remote_User_Ch_14   = '0x0914';
		const Remote_User_Ch_15   = '0x0915';
		const Remote_User_Ch_16   = '0x0916';
		const Remote_User_Ch_17   = '0x0917';
		const Remote_User_Ch_18   = '0x0918';
		const Remote_User_Ch_19   = '0x0919';
		const Remote_User_Ch_20   = '0x0920';
		const Remote_User_Ch_21   = '0x0921';
		const Remote_User_Ch_22   = '0x0922';
		const Remote_User_Ch_23   = '0x0923';
		const Remote_User_Ch_24   = '0x0924';
		const Remote_User_Ch_25   = '0x0925';
		const Remote_User_Ch_26   = '0x0926';
		const Remote_User_Ch_27   = '0x0927';
		const Remote_User_Ch_28   = '0x0928';
		const Remote_User_Ch_29   = '0x0929';
		const Remote_User_Ch_30   = '0x0930';
		const Remote_User_Ch_31   = '0x0931';

		// Alarms
		const Contact_Closure_1   = '0x0951';
		const Contact_Closure_2   = '0x0952';

		// Loadcell Data
		const Loadcell_Start      = '0x0980';
		const Loadcell_Ch_1       = '0x0981';
		const Loadcell_Ch_2       = '0x0982';
		const Loadcell_Ch_3       = '0x0983';
		const Loadcell_Ch_4       = '0x0984';
		const Loadcell_Ch_5       = '0x0985';
		const Loadcell_Ch_6       = '0x0986';
		const Loadcell_Ch_7       = '0x0987';
		const Loadcell_Ch_8       = '0x0988';
		const Loadcell_End        = '0x0989';

		// Hardware Data
		const Fastnet_Resistance  = '0x0993';
	 
		// Calculated Position Data
		const Calc_Latitude     = '0x1100';
		const Calc_Longitude    = '0x1101';
		
		// MOB Information    
		const MOB_Start_Latitude    	= '0x1110';
		const MOB_Start_Longitude   	= '0x1111';
		const MOB_DR_Latitude       	= '0x1112';
		const MOB_DR_Longitude      	= '0x1113';
		const MOB_Ship_Range_m      	= '0x1114';
		const MOB_Ship_Bearing_T		= '0x1115';
		const MOB_Ship_Bearing_M  		= '0x1116';
		const MOB_Time_Since_Trigger 	= '0x1117';
		const MOB_GPS_Range_m 			= '0x1118';
		const MOB_GPS_Bearing_T			= '0x1119';
		const MOB_GPS_Bearing_M			= '0x111a';
		
		const Calc_Anchor_watch_Lat   = '0x1120';
		const Calc_Anchor_watch_Long  = '0x1121';
		const Calc_Anchor_watch_dist  = '0x1122';
		const Calc_Anchor_watch_bear  = '0x1123';
		
		const Proc_Date_Local			= '0x1140';
		const Proc_Time_Local			= '0x1141';
		const Proc_Date_UTC				= '0x1142';
		const Proc_Time_UTC				= '0x1143';
		const Proc_Date_UTC_ymd			= '0x1144';
		const Proc_SystemTime			= '0x1145';
		
		const External_TimeDelta 		= '0x1148';
		const External_TimeDeltaAvg		= '0x1149';
		const ST_UT_TimeDelta			= '0x1150';
	 
		// Calculated Speed data
		const Calc_BSP_kts      	    = '0x1200';
		const Calc_BSP_mps       	    = '0x1201';

		const Advanced_Heel_Calibration	= '0x1204';
		const Base_Boat_Speed			= '0x1205';
		const Adv_Heel_Corr_kts			= '0x1207';
		const Calc_Water_Log_m        	= '0x1210';
		const Calc_Water_Log_m_Total  	= '0x1211';
		const Calc_Water_Log_nm       	= '0x1212';
		const Calc_Water_Log_nm_Total 	= '0x1213';
		const Calc_Grnd_Log_m         	= '0x1220';
		const Calc_Grnd_Log_m_Total   	= '0x1221';
		const Calc_Grnd_Log_nm        	= '0x1222';
		const Calc_Grnd_Log_nm_Total  	= '0x1223';
	 
		// Current Data
		const Calc_Set_Deg_T		= '0x1230';
		const Calc_Set_Deg_M		= '0x1231';
		const Calc_Drift_kts		= '0x1232';
		const Calc_Drift_mps		= '0x1233';
		const Current_Error			= '0x1240';
	 
		// Calculated Wind Data
		const Calc_AWS_kts        = '0x1300';
		const Calc_AWS_mps        = '0x1301';
		const Calc_AWA_Degrees    = '0x1302';
		const Calc_MAWA_Degrees   = '0x1303';
		const Calc_MAWS_kts		  = '0x1304';
		const Calc_VMG_Wind_kts   = '0x1315';
		const Calc_Cur_Wind_Src   = '0x1317';
		const Calc_TWWS_Kts       = '0x1320';
		const Calc_TWWS_mps       = '0x1321';
		const Calc_TWWA_Deg       = '0x1322';
		const Calc_TWWA_Deg_Crse  = '0x1323';
		const Calc_TWWD_Deg_M     = '0x1324';
		const Calc_TWWD_Deg_T     = '0x1325';
		
		// Relative to Ground
		const Calc_TGWS_kts       = '0x1330';
		const Calc_TGWS_mps       = '0x1331';
		const Calc_TGWA_Deg       = '0x1332';
		const Calc_TGWA_Deg_Crse  = '0x1333';
		const Calc_TGWD_Deg_M     = '0x1334';
		const Calc_TGWD_Deg_T     = '0x1335';
	 
		const Calc_ETWA           = '0x1340';
		const Calc_ETWS           = '0x1341';
		const Calc_TWS_Correctn   = '0x1342';
		const Calc_TWA_Correctn   = '0x1343';
		const Calc_AWS_Correctn   = '0x1344';
		const Calc_AWA_Correctn   = '0x1345';
		const Calc_PointOfSail    = '0x1346';
		const Calc_Heading_TWA    = '0x1347';
		const Calc_Leeway         = '0x1348';
		const Calc_Tack           = '0x1349';
		const Calc_CAWS_kts       = '0x1350';
		const Calc_CAWS_mps       = '0x1351';
		const Calc_CAWA_Degrees   = '0x1352';
		const Calc_Heel_Spd_Corr  = '0x1353';
		const Calc_Heel_Ang_Corr  = '0x1354';
		const Calc_Sgn_Leeway     = '0x1355';
		const Calc_MMAWA_Corr     = '0x1356';
		const Calc_MMAWS_Corr	  = '0x1357';
		const Calc_MMAWA_PreCorr  = '0x1358';
		const Calc_MMAWS_PreCorr  = '0x1359';
		
		// Calculated Depth Data
		const Calc_Depth_Metres = '0x1401';
		const Calc_Depth_Feet   = '0x1402';
		const Calc_Depth_Fathoms= '0x1403';
		const System_Alarm		= '0x14ff';
		
		// Calculated Heading Data
		const Calc_Heading_True		= '0x1500';
		const Calc_Heading_Mag		= '0x1501';
		const Calc_Heading_Heel_Offset = '0x1502';
		const Calc_Heading_Total_Offset = '0x1503';
		const Calc_Course_Deg_T   	= '0x1520';
		const Calc_Course_Deg_M   	= '0x1521';
		
		//Calculated Environment Variables
		const Calc_Env_AirTemp_C	= '0x1700';
		const Calc_Env_WaterTemp_C	= '0x1702';
		const Calc_Barometer		= '0x1720';
		const Calc_Baro_3H_Change	= '0x1722';
		const Calc_Baro_State		= '0x1723';
		
		// Calculated Analog Data
		const Calc_Analogue_Start	= '0x1800';
		const Calc_Analogue_Val_1   = '0x1801';
		const Calc_Analogue_Val_2   = '0x1802';
		const Calc_Analogue_Val_3   = '0x1803';
		const Calc_Analogue_Val_4   = '0x1804';
		const Calc_Analogue_Val_5   = '0x1805';
		const Calc_Analogue_Ref_1   = '0x1811';
		const Calc_Analogue_Ref_2   = '0x1812';
		const Calc_Analogue_Ref_3   = '0x1813';
		const Calc_Analogue_Ref_4   = '0x1814';
		const Calc_Analogue_Ref_5   = '0x1805';
		
		const Calc_Slope_Offset_Start 	= '0x1820';
		const Calc_Analogue_Slope_1		= '0x1821';
		const Calc_Analogue_Slope_2		= '0x1822';
		const Calc_Analogue_Slope_3		= '0x1823';
		const Calc_Analogue_Slope_4		= '0x1824';
		const Calc_Analogue_Slope_5   	= '0x1825';
		const Calc_Analogue_Offset_1	= '0x1826';
		const Calc_Analogue_Offset_2	= '0x1827';
		const Calc_Analogue_Offset_3	= '0x1828';
		const Calc_Analogue_Offset_4	= '0x1829';
		const Calc_Analogue_Offset_5	= '0x182A';
		
		const Calc_Analogue_Voltage_Start	= '0x1830';
		const Calc_Analogue_Voltage_1		= '0x1831';
		const Calc_Analogue_Voltage_2		= '0x1832';
		const Calc_Analogue_Voltage_3		= '0x1833';
		const Calc_Analogue_Voltage_4		= '0x1834';
		const Calc_Analogue_Voltage_5		= '0x1835';
		
		const Calc_ATP_Voltage_Mon	= '0x1836';
		const Calc_ATP_Current_Mon 	= '0x1837';
		
		const BSPD_Source_1			= '0x2611';	
		const BSPD_Source_2			= '0x2621';
		const BSPD_Source_3			= '0x2631';
		const BSPD_Source_4			= '0x2641';

		const NMEA_LogRowCount 		= '0x5201';
		const Fastnet_LogRowCount	= '0x5202';
        const CAN_LogRowCount       = '0x5203';

		const Compass_Swing_Status	= '0x6101';
		const Compass_Swing_Prog	= '0x6102';
	}
	
	$fieldNames = array(
		//GPS Data
		'0x0100' => function(&$nameStr) {
			$nameStr = 'Latitude';
			return 0;
		},
		'0x0101' => function(&$nameStr) {
			$nameStr = 'Longitude';
			return 0;
		},
		'0x0102' => function(&$nameStr) {
			$nameStr = 'HDOP';
			return 0;
		},
		'0x0103' => function(&$nameStr) {
			$nameStr = 'SoG';
			return 0;
		},
		'0x0104' => function(&$nameStr) {
			$nameStr = 'CoG (True)';
			return '0x0105';
		},
		'0x0105' => function(&$nameStr) {
			$nameStr = 'CoG (Mag)';
			return 0;
		},
		'0x0106' => function(&$nameStr) {
			$nameStr = 'Time (s)';
			return 0;
		},
		'0x0107' => function(&$nameStr) {
			$nameStr = 'Time (hhmmss)';
			return 0;
		},
		'0x0108' => function(&$nameStr) {
			$nameStr = 'GNSS Variation';
			return 0;
		},
		'0x0109' => function(&$nameStr) {
			$nameStr = 'SoG (km/h)';
			return 0;
		},
		'0x0110' => function(&$nameStr) {
			$nameStr = 'Latitude (NMEA0183)';
			return 0;
		},
		'0x0111' => function(&$nameStr) {
			$nameStr = 'Longitude (NMEA0183)';
			return 0;
		},
		'0x0112' => function(&$nameStr) {
			$nameStr = 'North-South Position';
			return 0;
		},
		'0x0113' => function(&$nameStr) {
			$nameStr = 'East-West Position';
			return 0;
		},
		'0x0120' => function(&$nameStr) {
			$nameStr = 'XTE';
			return 0;
		},
		'0x0121' => function(&$nameStr) {
			$nameStr = 'VMG';
			return 0;
		},
		'0x0122' => function(&$nameStr) {
			$nameStr = 'Distance to Waypoint';
			return 0;
		},
		'0x0123' => function(&$nameStr) {
			$nameStr = 'Bearing to Waypoint (True)';
			return '0x0124';
		},
		'0x0124' => function(&$nameStr) {
			$nameStr = 'Bearing to Waypoint (Mag)';
			return 0;
		},
		
		// Speed Board
		'0x0200' => function(&$nameStr) {
			$nameStr = 'Log Pulse Time';
			return 0;
		},
		'0x0201' => function(&$nameStr) {
			$nameStr = 'Log Pulse Count';
			return 0;
		},
		'0x0202' => function(&$nameStr) {
			$nameStr = 'Boat Speed (kts)';
			return 0;
		},
		'0x0203' => function(&$nameStr) {
			$nameStr = 'Boat Speed (m/s)';
			return 0;
		},
	 
		// Wind Board
		'0x0300' => function(&$nameStr) {
			$nameStr = 'Wind Pulse Time';
			return 0;
		},
		'0x0301' => function(&$nameStr) {
			$nameStr = 'Wind Pulse Count';
			return 0;
		},
		'0x0302' => function(&$nameStr) {
			$nameStr = 'MAWS (kts)';
			return 0;
		},
		'0x0303' => function(&$nameStr) {
			$nameStr = 'MAWA';
			return 0;
		},
		'0x0304' => function(&$nameStr) {
			$nameStr = 'MAWS (m/s)';
			return 0;
		},
		'0x0305' => function(&$nameStr) {
			$nameStr = 'Wind Pulse Frequency';
			return 0;
		},
		'0x0320' => function(&$nameStr) {
			$nameStr = 'Red Phase';
			return 0;
		},
		'0x0321' => function(&$nameStr) {
			$nameStr = 'Green Phase';
			return 0;
		},
		'0x0322' => function(&$nameStr) {
			$nameStr = 'Blue Phase';
			return 0;
		},
		'0x0323' => function(&$nameStr) {
			$nameStr = 'MHU Voltage';
			return 0;
		},
	 
		// Depth Board
		'0x0400' => function(&$nameStr) {
			$nameStr = 'Depth Time';
			return 0;
		},
		'0x0401' => function(&$nameStr) {
			$nameStr = 'Depth (m)';
			
			return 0;
		},
		'0x0402' => function(&$nameStr) {
			$nameStr = 'Depth (ft)';
			return 0;
		},
		'0x0403' => function(&$nameStr) {
			$nameStr = 'Depth (fathoms)';
			return 0;
		},
		'0x0404' => function(&$nameStr) {
			$nameStr = 'Depth Offset';
			return 0;
		},	

		// Heading Data
		'0x0500' => function(&$nameStr) {
			$nameStr = 'Heading (True)';
			return '0x0501';
		},
		'0x0501' => function(&$nameStr) {
			$nameStr = 'Heading (Mag)';
			return 0;
		},
		'0x0502' => function(&$nameStr) {
			$nameStr = 'Variation';
			return 0;
		},
		'0x0503' => function(&$nameStr) {
			$nameStr = 'Deviation';
			return 0;
		},
		'0x0504' => function(&$nameStr) {
			$nameStr = 'Heading Offset (True)';
			return '0x0505';
		},
		'0x0505' => function(&$nameStr) {
			$nameStr = 'Heading Offset (Mag)';
			return 0;
		},
		
		//Environmental Constants
		'0x0700' => function(&$nameStr) {
			$nameStr = 'Air Temperature (C)';
			return 0;
		},
		'0x0701' => function(&$nameStr) {
			$nameStr = 'Air Temperature (F)';
			return 0;
		},
		'0x0702' => function(&$nameStr) {
			$nameStr = 'Water Temperature (C)';
			return 0;
		},
		'0x0703' => function(&$nameStr) {
			$nameStr = 'Water Temperature (F)';
			return 0;
		},
		'0x0710' => function(&$nameStr) {
			$nameStr = 'Heel Angle';
			return 0;
		},
		'0x0711' => function(&$nameStr) {
			$nameStr = 'Rudder Angle';
			return 0;
		},
		'0x0712' => function(&$nameStr) {
			$nameStr = 'Rudder Angle (Port)';
			return 0;
		},
		'0x0720' => function(&$nameStr) {
			$nameStr = 'Pressure';
			return 0;
		},
		'0x0721' => function(&$nameStr) {
			$nameStr = 'Mast Rotation';
			return 0;
		},
		'0x0722' => function(&$nameStr) {
			$nameStr = 'Trim Angle';
			return 0;
		},
		
		//Analog Data
		'0x0800' => function(&$nameStr) {
			$nameStr = 'Raw Analogue Start';
			return 0;
		},
		'0x0801' => function(&$nameStr) {
			$nameStr = 'Analogue Input 1 (Raw)';
			return 0;
		},
		'0x0802' => function(&$nameStr) {
			$nameStr = 'Analogue Input 2 (Raw)';
			return 0;
		},
		'0x0803' => function(&$nameStr) {
			$nameStr = 'Analogue Input 3 (Raw)';
			return 0;
		},
		'0x0804' => function(&$nameStr) {
			$nameStr = 'Analogue Input 4 (Raw)';
			return 0;
		},
		'0x0811' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 1 (Raw)';
			return 0;
		},
		'0x0812' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 2 (Raw)';
			return 0;
		},
		'0x0813' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 3 (Raw)';
			return 0;
		},
		'0x0814' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 4 (Raw)';
			return 0;
		},
	 
		// Calculated Position Data
		'0x1100' => function(&$nameStr) {
			$nameStr = 'Calculated Latitude';
			return 0;
		},
		'0x1101' => function(&$nameStr) {
			$nameStr = 'Calculated Longitude';
			return 0;
		},
		
		'0x1120' => function(&$nameStr) {
			$nameStr = 'Anchor Watch Latitude';
			return 0;
		},
		'0x1121' => function(&$nameStr) {
			$nameStr = 'Anchor Watch Longitude';
			return 0;
		},
		'0x1122' => function(&$nameStr) {
			$nameStr = 'Anchor Watch Distance';
			return 0;
		},
		'0x1120' => function(&$nameStr) {
			$nameStr = 'Anchor Watch Bearing';
			return 0;
		},
	 
		// Calculated Speed data
		'0x1200' => function(&$nameStr) {
			$nameStr = 'Displayed Boat Speed (kts)';
			return 0;
		},
		'0x1201' => function(&$nameStr) {
			$nameStr = 'Displayed Boat Speed (m/s)';
			return 0;
		},
		'0x1202' => function(&$nameStr) {
			$nameStr = 'Computed Boat Speed (kts)';
			return 0;
		},
		'0x1203' => function(&$nameStr) {
			$nameStr = 'Computed Boat Speed (m/s)';
			return 0;
		},
		'0x1210' => function(&$nameStr) {
			$nameStr = 'Water Log (m)';
			return 0;
		},
		'0x1211' => function(&$nameStr) {
			$nameStr = 'Water Log Total (m)';
			return 0;
		},
		'0x1212' => function(&$nameStr) {
			$nameStr = 'Water Log (nm)';
			return 0;
		},
		'0x1213' => function(&$nameStr) {
			$nameStr = 'Water Log Total (nm)';
			return 0;
		},
		'0x1220' => function(&$nameStr) {
			$nameStr = 'Ground Log (m)';
			return 0;
		},
		'0x1221' => function(&$nameStr) {
			$nameStr = 'Ground Log Total (m)';
			return 0;
		},
		'0x1222' => function(&$nameStr) {
			$nameStr = 'Ground Log (nm)';
			return 0;
		},
		'0x1223' => function(&$nameStr) {
			$nameStr = 'Ground Log Total (nm)';
			return 0;
		},
		
		// Current Data
		'0x1230' => function(&$nameStr) {
			$nameStr = 'Direction of Current (True)';
			return '0x1231';
		},
		'0x1231' => function(&$nameStr) {
			$nameStr = 'Direction of Current (Mag)';
			return 0;
		},
		'0x1232' => function(&$nameStr) {
			$nameStr = 'Speed of Current (kts)';
			return 0;
		},
		'0x1233' => function(&$nameStr) {
			$nameStr = 'Speed of Current (m/s)';
			return 0;
		},
	 
		// Calculated Wind Data
		'0x1300' => function(&$nameStr) {
			$nameStr = 'AWS (kts)';
			return 0;
		},
		'0x1301' => function(&$nameStr) {
			$nameStr = 'AWS (m/s)';
			return 0;
		},
		'0x1302' => function(&$nameStr) {
			$nameStr = 'AWA';
			return 0;
		},
		'0x1303' => function(&$nameStr) {
			$nameStr = 'MAWA';
			return 0;
		},
		'0x1315' => function(&$nameStr) {
			$nameStr = 'VMG Wind (kts)';
			return 0;
		},
		'0x1320' => function(&$nameStr) {
			$nameStr = 'TWS (kts)';
			return 0;
		},
		'0x1321' => function(&$nameStr) {
			$nameStr = 'TWS (m/s)';
			return 0;
		},
		'0x1322' => function(&$nameStr) {
			$nameStr = 'TWA';
			return 0;
		},
		'0x1323' => function(&$nameStr) {
			$nameStr = 'TWA Course';
			return 0;
		},
		'0x1324' => function(&$nameStr) {
			$nameStr = 'TWD (Mag)';
			return 0;
		},
		'0x1325' => function(&$nameStr) {
			$nameStr = 'TWD (True)';
			return '0x1324';
		},
		'0x1330' => function(&$nameStr) {
			$nameStr = 'TWS Ground (kts)';
			return 0;
		},
		'0x1331' => function(&$nameStr) {
			$nameStr = 'TWA Ground';
			return 0;
		},
		'0x1332' => function(&$nameStr) {
			$nameStr = 'TWA Course Ground';
			return 0;
		},
		'0x1333' => function(&$nameStr) {
			$nameStr = 'TWD Ground (Mag)';
			return 0;
		},
		'0x1334' => function(&$nameStr) {
			$nameStr = 'TWD Ground (True)';
			return '0x1333';
		},
	 
		'0x1340' => function(&$nameStr) {
			$nameStr = 'OTWA';
			return 0;
		},
		'0x1341' => function(&$nameStr) {
			$nameStr = 'OTWS';
			return 0;
		},
		'0x1342' => function(&$nameStr) {
			$nameStr = 'TWS Correction';
			return 0;
		},
		'0x1343' => function(&$nameStr) {
			$nameStr = 'TWA Correction';
			return 0;
		},
		'0x1344' => function(&$nameStr) {
			$nameStr = 'AWS Correction';
			return 0;
		},
		'0x1345' => function(&$nameStr) {
			$nameStr = 'AWA Correction';
			return 0;
		},
		'0x1346' => function(&$nameStr) {
			$nameStr = 'Point of Sail';
			return 0;
		},
		'0x1347' => function(&$nameStr) {
			$nameStr = 'Heading TWA';
			return 0;
		},
		'0x1348' => function(&$nameStr) {
			$nameStr = 'Leeway';
			return 0;
		},
		'0x1349' => function(&$nameStr) {
			$nameStr = 'Tack';
			return 0;
		},
		
		'0x1350' => function(&$nameStr) {
			$nameStr = 'CAWS (kts)';
			return 0;
		},
		'0x1351' => function(&$nameStr) {
			$nameStr = 'CAWS (m/s)';
			return 0;
		},
		'0x1352' => function(&$nameStr) {
			$nameStr = 'CAWA';
			return 0;
		},
		'0x1353' => function(&$nameStr) {
			$nameStr = 'Heel Correction (Speed)';
			return 0;
		},
		'0x1354' => function(&$nameStr) {
			$nameStr = 'Heel Correction (Angle)';
			return 0;
		},
		
		// Calculated Depth Data
		'0x1401' => function(&$nameStr) {
			$nameStr = 'Depth (m)';
			return 0;
		},
		'0x1402' => function(&$nameStr) {
			$nameStr = 'Depth (ft)';
			return 0;
		},
		'0x1403' => function(&$nameStr) {
			$nameStr = 'Depth (Fathoms)';
			return 0;
		},
		
		'0x14ff' => function(&$nameStr) {
			$nameStr = 'System Alarm';
			return 0;
		},

		// Calculated Heading Data
		'0x1500' => function(&$nameStr) {
			$nameStr = 'Heading (True)';
			return '0x1501';
		},
		'0x1501' => function(&$nameStr) {
			$nameStr = 'Heading (Mag)';
			return 0;
		},
		
		'0x1520' => function(&$nameStr) {
			$nameStr = 'Course (True)';
			return '0x1521';
		},
		'0x1521' => function(&$nameStr) {
			$nameStr = 'Course (Mag)';
			return 0;
		},
		
		// Calculated Analog Data
		'0x1800' => function(&$nameStr) {
			$nameStr = 'Calculated Analogue Start';
			return 0;
		},
		'0x1801' => function(&$nameStr) {
			$nameStr = 'Analogue Input 1';
			return 0;
		},
		'0x1802' => function(&$nameStr) {
			$nameStr = 'Analogue Input 2';
			return 0;
		},
		'0x1803' => function(&$nameStr) {
			$nameStr = 'Analogue Input 3';
			return 0;
		},
		'0x1804' => function(&$nameStr) {
			$nameStr = 'Analogue Input 4';
			return 0;
		},
		'0x1811' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 1';
			return 0;
		},
		'0x1812' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 2';
			return 0;
		},
		'0x1813' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 3';
			return 0;
		},
		'0x1814' => function(&$nameStr) {
			$nameStr = 'Analogue Reference 4';
			return 0;
		}
	);

?>
