/** * Pass in a string with the route, and return back an array * with the data about each segment of the route. Pass a schedule * result into it. * * You can pass in a PIREP, schedule, or ACARS result, as long as it * has the following fields: * lat * lng * route * * To cache the route, use ScheduleData::getRouteDetails() instead. * This function bypasses any cached info * * @param mixed $route_string This is a description * @return mixed This is the return value description * */ public static function parseRoute($schedule) { $fromlat = $schedule->deplat; $fromlng = $schedule->deplng; $route_string = $schedule->route; if ($route_string == '') { return array(); } // Remove any SID/STAR text $route_string = str_replace('SID', '', $route_string); $route_string = str_replace('STAR', '', $route_string); $navpoints = array(); $all_points = explode(' ', $route_string); foreach ($all_points as $key => $value) { if (empty($value) === true) { continue; } $navpoints[] = strtoupper(trim($value)); } $allpoints = array(); $total = count($navpoints); $airways = self::getAirways($navpoints); for ($i = 0; $i < $total; $i++) { $name = self::cleanName($navpoints[$i]); /* the current point is an airway, so go through the airway list and add each corresponding point between the entry and exit to the list. */ if (isset($airways[$name])) { $entry_name = self::cleanName($navpoints[$i - 1]); $exit_name = self::cleanName($navpoints[$i + 1]); $entry = self::getPointIndex($entry_name, $airways[$name]); $exit = self::getPointIndex($exit_name, $airways[$name]); if ($entry == -1) { $entry = $exit; } else { /* Add information abotu the entry point in first, if it's valid and exists */ $allpoints[$entry_name] = $airways[$name][$entry]; } if ($exit == -1) { continue; } if ($entry < $exit) { # Go forwards through the list adding each one for ($l = $entry; $l <= $exit; $l++) { $allpoints[$airways[$name][$l]->name] = $airways[$name][$l]; } } elseif ($entry > $exit) { # Go backwards through the list for ($l = $exit; $l >= $entry; $l--) { $point_name = self::cleanName($airways[$name][$l]->name); $allpoints[$point_name] = $airways[$name][$l]; } } elseif ($entry == $exit) { $point_name = self::cleanName($airways[$name][$l]->name); $allpoints[$point_name] = $airways[$name][$entry]; } # Now add the exit point, and increment the main counter by one if ($exit > -1) { $allpoints[$exit_name] = $airways[$name][$exit]; } continue; } else { /* This nav point already exists in the list, don't add it again */ if (isset($allpoints[$navpoints[$i]])) { continue; } /* Means it is a track, so go into processing it See if it's something like XXXX/YYYY */ if (substr_count($navpoints[$i], '/') > 0) { $name = $navpoints[$i]; $point_name = explode('/', $name); preg_match(self::$nat_pattern, $point_name[0], $matches); $coord = $matches[1]; $lat = $matches[2] . $coord[0] . $coord[1] . '.' . $coord[2] . $coord[3]; /* Match the second set of coordinates */ # Read the second set preg_match(self::$nat_pattern, $point_name[1], $matches); if ($matches == 0) { continue; } $coord = $matches[1]; $lng = $matches[2] . $coord[0] . $coord[1] . $coord[2] . '.' . $coord[3]; /* Now convert into decimal coordinates */ $coords = $lat . ' ' . $lng; $coords = Util::get_coordinates($coords); if (empty($coords['lat']) || empty($coords['lng'])) { unset($allpoints[$navpoints[$i]]); continue; } $tmp = new stdClass(); $tmp->id = 0; $tmp->type = NAV_TRACK; $tmp->name = $name; $tmp->title = $name; $tmp->lat = $coords['lat']; $tmp->lng = $coords['lng']; $tmp->airway = ''; $tmp->sequence = 0; $tmp->freq = ''; $allpoints[$navpoints[$i]] = $tmp; unset($point_name); unset($matches); unset($tmp); } else { $allpoints[$navpoints[$i]] = $navpoints[$i]; $navpoint_list[] = $navpoints[$i]; } } } $navpoint_list_details = self::getNavDetails($navpoint_list); foreach ($navpoint_list_details as $point => $list) { $allpoints[$point] = $list; } unset($navpoint_list_details); /* How will this work - loop through each point, and decide which one we'll use, determined by the one which is the shortest distance from the previous Go in the order of the ones passed in. */ foreach ($allpoints as $point_name => $point_details) { if (is_string($point_details)) { unset($allpoints[$point_name]); continue; } if (!is_array($point_details)) { continue; } $results_count = count($point_details); if ($results_count == 1) { $allpoints[$point_name] = $point_details[0]; } elseif ($results_count > 1) { /* There is more than one, so find the one with the shortest distance from the previous point out of all the ones */ $index = 0; $dist = 0; /* Set the inital settings */ $lowest_index = 0; $lowest = $point_details[$lowest_index]; $lowest_dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $lowest->lat, $lowest->lng); foreach ($point_details as $p) { $dist = SchedulesData::distanceBetweenPoints($fromlat, $fromlng, $p->lat, $p->lng); if ($dist < $lowest_dist) { $lowest_index = $index; $lowest_dist = $dist; } $index++; } $allpoints[$point_name] = $point_details[$lowest_index]; } $fromlat = $allpoints[$point_name]->lat; $fromlng = $allpoints[$point_name]->lng; } return $allpoints; }
Debug::log(print_r($fields, true), 'xacars'); $outstring = $pilotid; } elseif ($_REQUEST['DATA2'] == 'MESSAGE') { $data = $_REQUEST['DATA4']; $pilotid = $_REQUEST['DATA3']; /* Get the flight information, from ACARS, need to pull the latest flight data via the flight number since acars messages don't transmit the pilot ID */ preg_match("/Flight ID:.(.*)\n/", $data, $matches); $flight_data = ACARSData::get_flight_by_pilot($pilotid); Debug::log('Flight data:', 'xacars'); Debug::log(print_r($_REQUEST, true), 'xacars'); Debug::log('PilotID: ' . $pilotid, 'xacars'); // Get coordinates from ACARS message preg_match("/POS(.*)\n/", $data, $matches); $coords = Util::get_coordinates(trim($matches[1])); // Get our heading preg_match("/\\/HDG.(.*)\n/", $data, $matches); $heading = $matches[1]; // Get our altitude preg_match("/\\/ALT.(.*)\n/", $data, $matches); $alt = $matches[1]; // Get our speed preg_match("/\\/IAS.(.*)\\//", $data, $matches); $gs = $matches[1]; // Get the OUT time preg_match("/OUT.(.*) \\/ZFW/", $data, $matches); $deptime = $matches[1]; /* We don't need to update every field, just a few of them */ $fields = array('lat' => $coords['lat'], 'lng' => $coords['lng'], 'heading' => $heading, 'alt' => $alt, 'gs' => $gs, 'phasedetail' => 'Enroute');