/** * Process ACARS messages here * */ public function acars() { if (!isset($_REQUEST['DATA1'])) { die("0|Invalid Data"); } if (!isset($_REQUEST['DATA1'])) { die("0|Invalid Data"); } // TEST, BEGINFLIGHT, PAUSEFLIGHT, ENDFLIGHT and MESSAGE $method = strtoupper($_REQUEST['DATA2']); if (!isset($_REQUEST['DATA3'])) { $value = ''; } else { $value = $_REQUEST['DATA3']; } if (!isset($_REQUEST['DATA4'])) { $message = ''; } else { $message = $_REQUEST['DATA4']; } $this->log("Method: {$method}", 'fsfk'); $fields = array(); # Go through each method now if ($method == 'TEST') { $pilotid = $value; echo '1|30'; return; } elseif ($method == 'BEGINFLIGHT') { $flight_data = explode('|', $value); if (count($flight_data) < 10) { echo '0|Invalid login data'; return; } /*preg_match('/^([A-Za-z]*)(\d*)/', $flight_data[0], $matches); $code = $matches[1]; $pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');*/ $pilotid = PilotData::parsePilotID($flight_data[0]); $coords = $this->get_coordinates($flight_data[6]); $route = explode('~', $flight_data[5]); $depicao = $route[0]; $arricao = $route[count($route) - 1]; unset($route[0]); unset($route[count($route) - 1]); $route = implode(' ', $route); $flightinfo = SchedulesData::getProperFlightNum($flight_data[2]); $code = $flightinfo['code']; $flightnum = $flightinfo['flightnum']; $aircraft = $flight_data[3]; $heading = $flight_data[12]; $alt = $flight_data[7]; $gs = 0; $dist_remain = $flight_data[16]; $time_remain = 0; $deptime = time(); $online = 0; $fields = array('pilotid' => $pilotid, 'flightnum' => $code . $flightnum, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'route' => $route, 'alt' => $alt, 'gs' => $gs, 'depicao' => $depicao, 'arricao' => $arricao, 'distremain' => $dist_remain, 'timeremaining' => $time_remain, 'phasedetail' => 'On the ground', 'online' => $online, 'client' => 'fsfk'); } elseif ($method == 'MESSAGE') { $pilotid = $value; $flight_data = ACARSData::get_flight_by_pilot($pilotid); // Get the flight preg_match("/Flight ID: (.*)\n/", $message, $matches); $flightinfo = SchedulesData::getProperFlightNum($matches[1]); $code = $flightinfo['code']; $flightnum = $flightinfo['flightnum']; // Get the aircraft preg_match("/.*Aircraft Reg: \\.\\.(.*)\n/", $message, $matches); $aircraft_data = OperationsData::GetAircraftByReg(trim($matches[1])); $aircraft = $aircraft_data->id; $depicao = $flight_data->depicao; $arricao = $flight_data->arricao; // Get coordinates from ACARS message $count = preg_match("/POS(.*)\n/", $message, $matches); if ($count > 0) { $coords = $this->get_coordinates(trim($matches[1])); } else { $coords = array('lat' => $flight_data->lat, 'lng' => $flight_data->lng); } // Get our heading preg_match("/\\/HDG.(.*)\n/", $message, $matches); $heading = $matches[1]; // Get our altitude preg_match("/\\/ALT.(.*)\n/", $message, $matches); $alt = $matches[1]; // Get our speed preg_match("/\\/IAS.(.*)\\//", $message, $matches); $gs = $matches[1]; $fields = array('pilotid' => $pilotid, 'aircraft' => $aircraft, 'lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'alt' => $alt, 'gs' => $gs, 'phasedetail' => 'Enroute'); } elseif ($method == 'UPDATEFLIGHTPLAN') { $flight_id = $value; $flight_data = explode("|", $message); echo '1|'; return; } $depapt = OperationsData::GetAirportInfo($depicao); $dist_remain = SchedulesData::distanceBetweenPoints($coords->lat, $coords->lng, $depapt->lat, $depapt->lng); # Estimate the time remaining if ($gs != 0) { $time_remain = $dist_remain / $gs; } else { $time_remain = '0'; } $fields['distremain'] = $dist_remain; $fields['timeremaining'] = $time_remain; if ($deptime != '') { $fields['deptime'] = $deptime; } if ($arrtime != '') { $fields['arrtime'] = $arrtime; } Debug::log(print_r($fields, true), 'fsfk'); ACARSData::updateFlightData($pilotid, $fields); $id = DB::$insert_id; if ($method == 'BEGINFLIGHT') { echo '1|' . $pilotid; return; } echo '1|'; }
if (!OperationsData::GetAirportInfo($arricao)) { OperationsData::RetrieveAirportInfo($arricao); } # Get aircraft information $reg = trim($data[3]); $ac = OperationsData::GetAircraftByReg($reg); # Load info /* If no passengers set, then set it to the cargo */ $load = $data[14]; if (empty($load)) { $load = $data[15]; } # Convert the time to xx.xx $flighttime = floatval(str_replace(':', '.', $data[11])) * 1.0; /* Fuel conversion - XAcars only reports in lbs */ $fuelused = $data[12]; if (Config::Get('LiquidUnit') == '0') { # Convert to KGs, divide by density since d = mass * volume $fuelused = $fuelused * 0.45359237 / 0.8075; } elseif (Config::Get('LiquidUnit') == '1') { $fuelused = $fuelused * 6.84; } elseif (Config::Get('LiquidUnit') == '2') { $fuelused = $fuelused * 0.45359237; } $acars_data = ACARSData::get_flight_by_pilot($pilotid); $data = array('pilotid' => $pilotid, 'code' => $code, 'flightnum' => $flightnum, 'depicao' => $depicao, 'arricao' => $arricao, 'aircraft' => $ac->id, 'flighttime' => $flighttime, 'submitdate' => 'NOW()', 'route' => $acars_data->route, 'route_details' => $acars_data->route_details, 'comment' => $comment, 'fuelused' => $fuelused, 'source' => 'xacars', 'load' => $load, 'log' => $_GET['log']); Debug::log(print_r($data, true), 'xacars'); $ret = ACARSData::FilePIREP($pilotid, $data); echo '1|Success'; break; }