Está en la página 1de 2

c.

php 06/08/2020 13:59:05

<?php

// https://mode-s.org/decode/adsb/introduction.html

function str2bin($str)
{
$out=""; $str=str_split($str,1);
foreach ($str as $a)
{$out .= sprintf('%04d', decbin(hexdec($a)));}
return $out;
}

$str="8D34508F201432CF060000303030";
$bin=str2bin($str);

/*
en este caso

Retransmisión ADS-B, utilizando los mismos códigos de tipo y formatos de mensaje definidos para los
mensajes ADS-B DF=17

1-5 DF
6-8 CAPACIDAD
9-32 AAC DIRECCIÓN ANUNCIADA ICAO
33-88 ME MENSAJE ESPONTÁNEO AMPLIADO, 5 PRIMEROS BITS TIPO DE MENSAJE
89-112 PI PARIDAD INTERROGADOR

10001 101 001101000101000010001111


DF=17 CA AAC

00100 000 000101 000011 001011 001111 000001 100000 000000 000000 001100000011000000110000
ME PI

ME es tipo de mensaje 5 bits + 3 bits a/c type + call sign 48 bits

TIPO DE MENSAJE 00100 = 4, IDENTIFICACIÓN DE LA AERONAVE


*/

// AAC a partir del bit 9 contar 24 bits = 6 chars, o a partir del tercer hex-char

$aac=substr($str,2,6);

// se consulta api en flightradar24

$headers=array(
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/75.0.3770.102 Safari/537.36 Vivaldi/2.6.1566.44",
"Accept: application/json, text/javascript, */*; q=0.01"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,180);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"GET");
curl_setopt($ch, CURLOPT_URL,
"https://api.flightradar24.com/common/v1/search.json?fetchBy=reg&query=$aac");
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 180);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_FAILONERROR,0);
curl_setopt($ch, CURLOPT_REFERER, "https://www.flightradar24.com/data");
$auth=json_decode(curl_exec($ch));

$regid=$auth->result->response->aircraft->data[0]->registration;

Page 1 of 2
c.php 06/08/2020 13:59:05

/*
from https://mode-s.org/decode/adsb/identification.html

call sign

a partir del bit 40 tomar 48bits en grupos de 6.

Transformaciones

A - Z : 1 - 26
0 - 9 : 48 - 57
_ : 32
*/

$callsign=str_split(substr($bin,40,48),6);$csign="";

foreach ($callsign as $c)


{
$dec=bindec($c);
if ($dec)
switch ($dec)
{
case $dec<27: $csign.=chr($dec+64);break;
case $dec=32: $csign.="_";break;
case $dec<58: $csign.=chr($dec+47);
}
}

echo $regid.$csign; // EC-MGMECKOA_

Page 2 of 2

También podría gustarte