{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "toc_visible": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "lhrTOp3dIPLU" }, "source": [ "### **AVIONES -Parte 2-**\n", "\n", "Para esta segunda parte se proporcionarán dos archivos diferentes con muestras tomadas por el SDR que contienen paquetes de datos enviados por los aviones. En uno de ellos tendrán que detectar al menos un vuelo, y en el otro al menos cuatro vuelos diferentes.\n", "\n", "En el código que sigue hay algunas funciones que los ayudarán a obtener los datos de los vuelos detectados, como la posición, velocidad, etc. Para poder utilizarlas, primero será necesario completar las celdas correspondientes con sus funciones detectar_preambulo y datosAbits creadas en la primera parte (con las modificaciones necesarias).\n", "\n", "Una vez que hayan agregado sus funciones y ejecuten todo el código, verán que en la sección archivos se crean varios archivos de texto identificados como: dato_numero de vuelo_fecha_hora, y dentro de ellos encontrarán el dato mencionado en el título.\n", "La última celda de código al final del notebbok se encarga de correr todas las funciones y dejar los archivos con los datos decodificados de vuelos que las funciones de ustedes pudieron detectar. \n", "Al final se explica que se debe hacer con los datos de los vuelos que detectaron para incluirlos en el informe final." ] }, { "cell_type": "code", "metadata": { "id": "g5dOsC8mHhNQ" }, "source": [ "from google.colab import files\n", "uploaded = files.upload()" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "QQcvZVZXWeqU" }, "source": [] }, { "cell_type": "code", "metadata": { "id": "nmmNH1qEHiIx" }, "source": [ "import numpy as np\n", "y = np.load('adsb_cmp.npy')" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "J-silcsZZokc" }, "source": [ "#AQUÍ DEBEN INCLUIR SU FUNCIÓN detectar_preambulo\n", "\n", "def detectPreamble(y):\n", "\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "EuEpYwDHsdMz" }, "source": [ "#AQUÍ DEBEN INCLUIR SU FUNCIÓN datosAbits\n", "\n", "def data2bit( msg ): \n", " " ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "Pql7YfoAUx3K" }, "source": [ "idx = detectPreamble(y)\n", "idx.pop() \n", "bits = np.zeros((len(idx),112))\n", "indice = 0\n", "ok = 0\n", "for i in idx:\n", " bits[indice] = np.array(data2bit(y[i:i+16+112*2]) ) \n", " #print(bits[indice])\n", " if bits[indice][0]==1 and bits[indice][1]==0 and bits[indice][2]==0 and bits[indice][3]==0 and bits[indice][4]==1:\n", " ok = ok + 1\n", " indice = indice + 1\n", "print(ok)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "OXOX-IhCE66D" }, "source": [ "# -*- coding: utf-8 -*-\n", "\"\"\"\n", "Created on Mon Dec 4 11:33:15 2017\n", "\n", "@author: belza\n", "\"\"\"\n", "import numpy as np\n", "import time\n", "class avion:\n", " addr = -1\n", " flightnum = 'UNKNOWN'\n", " planetype = 0\n", " lat0 = 0\n", " lat1 = 0\n", " lon0 = 0\n", " lat0 = 0\n", " time0 = -1\n", " time1 = -1\n", " cantidad_vistas =0\n", " cantidad_posiciones = 0\n", " cant_pos_procesadas = 0\n", " color = 0\n", " numero = 0\n", " hora_inicial = 0\n", " hora_final = 0\n", " directorio = \"\"\n", " \n", " \n", " \n", " def __init__( self, addr,numero,colores,directorio):\n", " self.addr = addr;\n", " self.posiciones = []\n", " self.headings = []\n", " self.alturas = []\n", " self.velocidades = []\n", " self.velocidades_vert =[]\n", " self.difs_bar =[]\n", " self.air_speeds = []\n", " self.numero = numero\n", " self.color = colores[self.numero]\n", " self.directorio = directorio\n", " self.hora_inicial = time.time()\n", " \n", " def addplanetype( self, planetype ):\n", " self.planetype = planetype;\n", " \n", " def addflightnum( self, flightnum ):\n", " self.flightnum = flightnum;\n", " \n", " def addposition( self, posicion ):\n", " self.posiciones.append(posicion);\n", " self.hora_final = time.time()\n", " \n", " def addaltura( self, altura, ):\n", " self.alturas.append([altura,time.time()]);\n", " self.hora_final = time.time()\n", "\n", " def addheading( self, heading ):\n", " self.headings.append([heading,time.time()]);\n", " self.hora_final = time.time()\n", "\n", " def addvelocidad( self, velocidad ):\n", " self.velocidades.append([velocidad,time.time()]);\n", " self.hora_final = time.time()\n", "\n", " def addvelocidad_vert( self, vert_rate_sign,vert_rate):\n", "\t if vert_rate_sign == 0:\n", "\t self.velocidades_vert.append([vert_rate,time.time()]);\n", "\t else:\n", "\t self.velocidades_vert.append([-vert_rate,time.time()]);\n", "\t self.hora_final = time.time()\n", "\n", " def adddif_bar( self, dif_bar_sign,dif_bar):\n", "\t if dif_bar_sign == 0:\n", "\t self.difs_bar.append([dif_bar,time.time()]);\n", "\t else:\n", "\t self.difs_bar.append([-dif_bar,time.time()]);\n", "\t self.hora_final = time.time()\n", "\n", " def addair_speed( self, air_speed ):\n", " self.air_speeds.append([air_speed,time.time()]);\n", " self.hora_final = time.time()\n", " \n", " def salvaryborrar_datos(self):\n", " if self.flightnum != 'UNKNOWN':\n", " f = open(\"lat_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for pos in self.posiciones:\n", " # aux = str(pos[0]) + \",\" + str(pos[1])+\"\\n\" \n", " # f.write(aux)\n", " \n", " np.savetxt(f, self.posiciones)\n", " f.close()\n", " self.posiciones = []\n", " f = open(\"alt_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for altura in self.alturas:\n", " # aux = str(altura[0])+\",\"+str(altura[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.alturas)\n", " self.alturas = []\n", " f.close()\n", " f = open(\"head_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for head in self.headings:\n", " # aux = str(head[0]*360.0/2.0/np.pi)+\",\"+str(head[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.headings)\n", " self.headings =[]\n", " f.close()\n", " f = open(\"vel_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for vel in self.velocidades:\n", " # aux = str(vel[0])+\",\"+str(vel[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.velocidades)\n", " self.velocidades =[]\n", " f.close()\n", " f = open(\"velvert_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for vel in self.velocidades_vert:\n", " # aux = str(vel[0])+\",\"+str(vel[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.velocidades_vert)\n", " self.velocidades_vert =[]\n", " f.close()\n", " f = open(\"difbar_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for vel in self.difs_bar:\n", " # aux = str(vel[0])+\",\"+str(vel[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.difs_bar)\n", " self.difs_bar =[]\n", " f.close()\n", " f = open(\"air_speed_\"+str(self.flightnum)+\"_\"+str(time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))), 'a')\n", " #for vel in self.air_speeds:\n", " # aux = str(vel[0])+\",\"+str(vel[1])+\"\\n\" \n", " # f.write(aux)\n", " #f.close()\n", " np.savetxt(f, self.air_speeds)\n", " self.air_speeds = []\n", " f.close()\n", "\n", " \n", " def nuevas_posiciones(self):\n", " pos = []\n", " if len(self.posiciones) >0:\n", " for posicion in self.posiciones:\n", " pos.append( [self.color,self.flightnum,posicion[0],posicion[1],self.numero,time.strftime(\"%b %d %Y %H:%M:%S\", time.gmtime(self.hora_inicial))] )\n", " return pos\n" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "p-7QSscy7hez" }, "source": [], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "TpWcAbwjAuh5" }, "source": [ "# -*- coding: utf-8 -*-\n", "\"\"\"\n", "Created on Thu Oct 5 13:22:17 2017\n", "\n", "@author: belza\n", "Partially adapted some code from public laboratories of Digital Signal Procesing course of Berkeley University\n", "and some code from gr-adsb project\n", "\"\"\"\n", "\n", "# Import functions and libraries\n", "from __future__ import division\n", "import numpy as np, matplotlib.pyplot as plt\n", "#from rtlsdr import RtlSdr\n", "import threading,time , queue\n", "import os\n", "#from mpl_toolkits.basemap import Basemap\n", "import tty\n", "import sys\n", "import termios\n", "import select,json\n", "#import avion as av\n", "\n", "MAX_VUELOS = 50\n", "my_coords = [0,0]\n", "cantidad_aviones = 0\n", "colors = plt.cm.rainbow(np.linspace(0, 3, MAX_VUELOS))\n", "directorio = \"/home/belza/Dropbox/proyectos/tallerine2018/vuelos/\"\n", "Lecturas = 0\n", "Salvar = False\n", "def bit2byte( bits ):\n", " msg = np.zeros( MODES_LONG_MSG_BYTES, dtype='int' )\n", "\n", " # Pack bits into bytes */\n", " for i in np.r_[:MODES_LONG_MSG_BITS:8]:\n", " for j in np.r_[:8]:\n", " msg[ i // 8] = msg[ i // 8] + (int(bits[i+j]) << (7-j))\n", " return msg\n", "\n", "\n", "\n", " \n", "MODES_LONG_MSG_BITS = 112\n", "MODES_SHORT_MSG_BITS = 56\n", "MODES_LONG_MSG_BYTES = int(112/8)\n", "MODES_SHORT_MSG_BYTES = int(56/8)\n", "\n", "\n", "modes_checksum_table = [\n", "0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178,\n", "0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13, 0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14,\n", "0x682e0a, 0x341705, 0xe5f186, 0x72f8c3, 0xc68665, 0x9cb936, 0x4e5c9b, 0xd8d449,\n", "0x939020, 0x49c810, 0x24e408, 0x127204, 0x093902, 0x049c81, 0xfdb444, 0x7eda22,\n", "0x3f6d11, 0xe04c8c, 0x702646, 0x381323, 0xe3f395, 0x8e03ce, 0x4701e7, 0xdc7af7,\n", "0x91c77f, 0xb719bb, 0xa476d9, 0xadc168, 0x56e0b4, 0x2b705a, 0x15b82d, 0xf52612,\n", "0x7a9309, 0xc2b380, 0x6159c0, 0x30ace0, 0x185670, 0x0c2b38, 0x06159c, 0x030ace,\n", "0x018567, 0xff38b7, 0x80665f, 0xbfc92b, 0xa01e91, 0xaff54c, 0x57faa6, 0x2bfd53,\n", "0xea04ad, 0x8af852, 0x457c29, 0xdd4410, 0x6ea208, 0x375104, 0x1ba882, 0x0dd441,\n", "0xf91024, 0x7c8812, 0x3e4409, 0xe0d800, 0x706c00, 0x383600, 0x1c1b00, 0x0e0d80,\n", "0x0706c0, 0x038360, 0x01c1b0, 0x00e0d8, 0x00706c, 0x003836, 0x001c1b, 0xfff409,\n", "0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,\n", "0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,\n", "0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000\n", "]\n", "\n", " \n", " \n", "def modesChecksum(msg, bits):\n", " crc = 0;\n", "\n", " if (bits == 112):\n", " offset = 0\n", " else:\n", " offset = 112 - 56\n", " \n", " for j in np.r_[:bits]:\n", "\n", " byte = j//8;\n", " bit = j%8;\n", " bitmask = 1 << (7 - bit);\n", "\n", " # If bit is set, xor with corresponding table entry.\n", " if (msg[byte] & bitmask):\n", " crc ^= modes_checksum_table[j+offset];\n", " \n", " return crc; # 24 bit checksum. \n", "\n", "\n", "def modesMessageLenByType( type ):\n", " if ( type == 16 or type == 17 or type == 19 or type == 20 or type == 21):\n", " return MODES_LONG_MSG_BITS\n", " else:\n", " return MODES_SHORT_MSG_BITS\n", " \n", "def fixSingleBitErrors( msg, bits ):\n", " for j in np.r_[:8]:\n", " byte = j // 8\n", " bitmask = 1 << (7 - (j%8))\n", " \n", " aux = msg[:int(bits/8)]\n", " \n", " crc1 = (aux[(int(bits/8))-3] << 16) |(aux[(int(bits/8))-2] << 8) |aux[(int(bits/8))-1];\n", " crc2 = modesChecksum(aux,bits)\n", " \n", " crcok = (crc1 == crc2)\n", " if ( crcok ):\n", " print(\"fixed\")\n", " for i in np.r_[:bits//8]:\n", " msg[i] = aux[i]\n", " \n", " return crcok\n", " \n", "def NL( rlat ):\n", " # A.1.7.2.d (page 9)\n", " NZ = 15\n", " return np.floor( 2 * np.pi / \n", " (np.arccos( 1 - (1 - np.cos( np.pi / (2 * NZ )) ) \n", " / np.cos( np.pi / 180 * abs(rlat) ) ** 2 )))\n", "\n", "\n", "def cprN( lat, isodd):\n", " nl = NL(lat) - isodd;\n", " if (nl < 1):\n", " nl = 1;\n", " return nl;\n", "\n", "def Dlon( lat, isodd):\n", " return 360.0 / cprN(lat, isodd)\n", "\n", " \n", "def cprmod( a, b ):\n", " res = a % b;\n", " if (res < 0):\n", " res = res + b;\n", " return res;\n", "\n", "\n", "def decodeCPR( plane ):\n", " plane.cantidad_posiciones = plane.cantidad_posiciones + 1\n", " AirDlat0 = 360.0 / 60\n", " AirDlat1 = 360.0 / 59\n", " \n", " lat0 = plane.lat0\n", " lat1 = plane.lat1\n", " lon0 = plane.lon0\n", " lon1 = plane.lon1\n", " \n", " j = np.floor(((59*lat0 - 60*lat1) / 131072) + 0.5)\n", " \n", " rlat0 = AirDlat0 * (cprmod(j,60) + lat0 / 131072)\n", " rlat1 = AirDlat1 * (cprmod(j,59) + lat1 / 131072)\n", " \n", " if (rlat0 >= 270):\n", " rlat0 = rlat0 - 360\n", " \n", " if (rlat1 >= 270):\n", " rlat1 = rlat1 - 360\n", " \n", " if (NL(rlat0) != NL(rlat1)):\n", " return;\n", " \n", " if (plane.time0 > plane.time1) :\n", "\n", " # Use even packet.\n", " ni = cprN(rlat0,0);\n", " m = np.floor((((lon0 * (NL(rlat0)-1)) -\n", " (lon1 * NL(rlat0))) / 131072) + 0.5);\n", " lon = Dlon(rlat0,0) * (cprmod(m,ni)+lon0/131072);\n", " lat = rlat0;\n", " else:\n", " # Use odd packet\n", " ni = cprN(rlat1,1);\n", " m = np.floor((((lon0 * (NL(rlat1)-1)) - \n", " (lon1 * NL(rlat1))) / 131072) + 0.5);\n", " lon = Dlon(rlat1,1) * (cprmod(m,ni)+lon1/131072);\n", " lat = rlat1;\n", " if ( lon > 180 ):\n", " lon = lon - 360; \n", " plane.addposition( (lat, lon) )\n", " \n", "def calcular_altura(plane, altura):\n", " q = altura & 0x0010\n", " print( \"--------------q-----------\", q)\n", " if q == 16:\n", " escala = 25\n", " else:\n", " escala = 100\n", " tmp1 = (altura & 0x1FE0) >> 1\n", " altitud_pies = ((altura & 0x0F) | tmp1 ) * escala - 1000\n", " plane.addaltura(altitud_pies * 0.3048)\n", "\n", "def decodeModesMessage( msg, plane_list ):\n", " global cantidad_aviones,colors,directorio \n", " ais_charset = np.array( list(\"?ABCDEFGHIJKLMNOPQRSTUVWXYZ????? ???????????????0123456789??????\"))\n", " #print(msg)\n", " # Get the message type ASAP as other operations depend on this\n", " msgtype = msg[0] >> 3\n", " msgbits = modesMessageLenByType(msgtype)\n", " \n", " \n", " # Get checksum. CRC is always the last three bytes.\n", " crc = (msg[(msgbits//8)-3] << 16) | (msg[(msgbits//8)-2] << 8) | msg[(msgbits//8)-1];\n", " crc2 = modesChecksum(msg,msgbits)\n", " crcok = (crc == crc2)\n", "\n", " # Correct 1-bit error\n", " if (not crcok):\n", " crcok = fixSingleBitErrors( msg, msgbits )\n", " \n", " \n", " # ICAO address ( airplane address )\n", " aa1 = msg[1]\n", " aa2 = msg[2]\n", " aa3 = msg[3]\n", " \n", " \n", " # Get DF 17 (ADSB) extended squitter types\n", " metype = msg[4] >> 3 # extended squitter message type\n", " mesub = msg[4] & 7\n", " \n", " if(crcok):\n", " print(\"crc: \",crcok,\" type: \",msgtype)\n", " \n", "# if ( (msgtype == 11) and crcok ):\n", "# addr = (aa1 << 16 ) | (aa2 << 8) | aa3\n", "# if ( addr in plane_list ):\n", "# plane = plane_list[addr]\n", "# print (\"avion ya encontrado addr \", addr)\n", "# else:\n", "# plane = Plane(addr)\n", "# plane_list[addr] = plane\n", "# if ( len(plane_list) == 1):\n", "# print \"Found %d plane\" % len(plane_list)\n", "# print (\"addr \", addr)\n", "# else:\n", "# print \"Found %d planes\" % len(plane_list)\n", "# print (\"addr \", addr)\n", " # Decode extended squitter, ignore all other messages\n", " if ( msgtype == 17 and crcok ):\n", " #if(crcok): \n", " addr = (aa1 << 16 ) | (aa2 << 8) | aa3\n", " \n", " # Add plane address to plane_list\n", " if ( addr in plane_list ):\n", " plane = plane_list[addr]\n", " plane.cantidad_vistas = plane.cantidad_vistas +1\n", " else:\n", " cantidad_aviones = cantidad_aviones +1\n", " plane = avion(addr,cantidad_aviones,colors,directorio)\n", " plane_list[addr] = plane\n", " plane.cantidad_vistas = 1\n", " if ( len(plane_list) == 1):\n", " print(\"Found %d plane\" % len(plane_list))\n", " else:\n", " print(\"Found %d planes\" % len(plane_list))\n", "# plane.addflightnum(\"100\")\n", "# plane.addposition( (37, 38) )\n", "# plane.heading.append(5000)\n", " if ( metype >=1 and metype <= 4 ):\n", " aircraft_type = metype - 1\n", " flight_index = np.array( [ msg[5] >> 2,\n", " ((msg[5]&3)<<4)|(msg[6]>>4),\n", " ((msg[6]&15)<<2)|(msg[7]>>6),\n", " msg[7]&63,\n", " msg[8]>>2,\n", " ((msg[8]&3)<<4)|(msg[9]>>4),\n", " ((msg[9]&15)<<2)|(msg[10]>>6),\n", " msg[10]&63] )\n", " \n", " flightnum = ais_charset[ flight_index ]\n", " \n", " plane.addplanetype( aircraft_type )\n", " plane.addflightnum( \"\".join( flightnum ) )\n", "\n", " elif ( metype >= 9 and metype <= 18 ):\n", " \n", " # latitude and longitude are in CPR format\n", " # here we implement the global decoding described in section 5.3.1:\n", " # http://adsb.tc.faa.gov/WG3_Meetings/Meeting29/1090-WP29-07-Draft_CPR101_Appendix.pdf\n", " # see also:\n", " # https://sites.google.com/site/adsbreceiver/\n", " # http://www.lll.lu/~edward/edward/adsb/DecodingADSBposition.html\n", " # http://aviation.stackexchange.com/questions/3707/ads-b-compact-position-report-nl-function\n", " \n", " \n", " isodd = msg[6] & (1<<2);\n", " lat_enc = ((msg[6] & 3) << 15) | (msg[7] << 7) | (msg[8] >> 1); \n", " lon_enc = ((msg[8] & 1) << 16) | (msg[9] << 8) | msg[10];\n", " \n", " \n", " if (isodd):\n", " plane.lat1 = lat_enc\n", " plane.lon1 = lon_enc\n", " plane.time1 = time.time()\n", " \n", " if (plane.time0 == -1):\n", " return\n", " else:\n", " plane.lat0 = lat_enc\n", " plane.lon0 = lon_enc\n", " plane.time0 = time.time()\n", " \n", " if (plane.time1 == -1):\n", " return\n", " \n", " if ( abs( plane.time0 - plane.time1 ) <= 10):\n", " decodeCPR( plane )\n", " altitud_enc = (msg[5] << 4) | (msg[6] >> 4) \n", " calcular_altura(plane,altitud_enc)\n", " elif ( metype == 19 and mesub >=1 and mesub <= 4 ):\n", " if ( mesub == 1 or mesub == 2):\n", " ew_dir = (msg[5]&4) >> 2;\n", " ew_velocity = ((msg[5]&3) << 8) | msg[6];\n", " ns_dir = (msg[7]&0x80) >> 7;\n", " ns_velocity = ((msg[7]&0x7f) << 3) | ((msg[8]&0xe0) >> 5);\n", " vert_rate_source = (msg[8]&0x10) >> 4;\n", " vert_rate_sign = (msg[8]&0x8) >> 3;\n", " vert_rate = ((msg[8]&7) << 6) | ((msg[9]&0xfc) >> 2);\n", " plane.addvelocidad_vert(vert_rate_sign,(vert_rate-1)*64)\n", " # Compute velocity and angle from the two speed components. \n", " velocity = np.sqrt(ns_velocity*ns_velocity+ew_velocity*ew_velocity);\n", " plane.addvelocidad(velocity)\n", " dif_bar_sign = (msg[10] & 0x40)>>6\n", " dif_bar = (msg[10] <<2) | (msg[11] & 0xc0)\n", " plane.adddif_bar(dif_bar_sign,dif_bar)\n", " if (velocity):\n", " ewv = ew_velocity;\n", " nsv = ns_velocity;\n", "\n", " if (ew_dir): ewv *= -1;\n", " if (ns_dir): nsv *= -1;\n", " heading = np.arctan2(ewv,nsv);\n", " \n", " # We don't want negative values but a 0-360 scale. \n", " if (heading < 0):\n", " heading += 2 * np.pi;\n", " else:\n", " heading = 0;\n", " plane.addheading( heading) \n", " if ( mesub == 3 or mesub == 4):\n", " plane.addheading( (360 / 128) * (((msg[5] & 3) << 5) | (msg[6] >> 3)) * np.pi / 180);\n", " plane.addair_speed(((msg[7]&0x7f)<<3)|(msg[8]>>5))\n", " \n", "\n", "#def sdr_read( Qin, sdr, N_samples, stop_flag ):\n", "# global Salvar, Lecturas\n", "# while ( not stop_flag.is_set() ):\n", "# data_chunk = np.array(abs(sdr.read_samples(N_samples))) # get samples \n", "# Qin.put( data_chunk.tolist() ) # append to list\n", "# if(Salvar == True):\n", "# Lecturas = Lecturas +1\n", "# f = open(directorio + str(Lecturas)+\".raw\",'w')\n", "# data_chunk.tofile(f)\n", "# f.close()\n", "# sdr.close()\n", "\n", "\n", "def signal_process( chunk,Qpos):#functions)#, stop_flag,Qpos ):\n", " \n", " #detectPreamble = functions[0]\n", " #data2bit = functions[1]\n", " plane_list = {};\n", " #while( not stop_flag.is_set() ):\n", " #chunk = Qin.get();\n", " idx_preamble = detectPreamble(chunk)\n", " idx_preamble.pop()\n", " for n in idx_preamble:\n", " bits = data2bit(chunk[n:(n+16+MODES_LONG_MSG_BITS*2)])\n", " if len(bits) == MODES_LONG_MSG_BITS :\n", " msg = bit2byte( bits )\n", " decodeModesMessage( msg, plane_list )\n", " flightnum = []\n", " print (plane_list) \n", " for addr in plane_list:\n", " plane = plane_list[addr]\n", " flightnum.append( plane.flightnum ) \n", " print(plane.flightnum)\n", " print(plane.cantidad_vistas)\n", " print(\" cantidad posiciones : \",plane.cantidad_posiciones, \" cantidad heading \",len(plane.headings))\n", " pos = plane.nuevas_posiciones()\n", " if len(pos)>0:\n", " Qpos.put(pos)\n", " plane.salvaryborrar_datos()\n", "#Qpos = queue.Queue()\n", "#signal_process(y,Qpos)" ], "execution_count": null, "outputs": [] }, { "cell_type": "code", "metadata": { "id": "NMg-Iq-C8-LK" }, "source": [ "import queue\n", "Qpos = queue.Queue()\n", "signal_process(y,Qpos)" ], "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "metadata": { "id": "2Pr66RFjU3k3" }, "source": [ "### **Ejercicio**\n", "\n", "Una vez obtenidos los archivos, deberán graficar sobre un mapa las posiciones de los vuelos detectados. Además, utilizando el resto de los datos, determinar la altura y velocidad del avión, y si se encontraba aterrizando, despegando, o simplemente de paso en el momento en que las muestras fueron tomadas." ] }, { "cell_type": "markdown", "metadata": { "id": "-5I5aRCUWgK5" }, "source": [ "### **Informe**\n", "\n", "Tendrán que entregar un informe final que incluya las modificaciones que tuvieron que realizar en sus funciones para capturar aviones en tiempo real. Además de las capturas que (esperamos) realizarán en la azotea de FING, deberán realizar capturas por su cuenta, buscando hallar la distancia máxima a la que detectan aviones. Deberán analizar la antena construida, viendo si su funcionamiento se acerca o no al esperado. También deberán mostrar las gráficas de (algunos de) los vuelos hallados sobre el mapa (o algún mapa) y presentar el resto de los datos obtenidos para cada vuelo (altura, velocidad,heading,etc.), análizandolos y explicándolos." ] } ] }