mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-07-12 13:55:22 -04:00
Don't connect twice, as that results in multiple signals being emitted
for each download. Speed up reading of airport DB. Fix a few compiler warnings.
This commit is contained in:
parent
a27226fa06
commit
bd3c5343e3
@ -1182,7 +1182,6 @@ void ADSBDemodGUI::on_getOSNDB_clicked(bool checked)
|
|||||||
{
|
{
|
||||||
// Download Opensky network database to a file
|
// Download Opensky network database to a file
|
||||||
QUrl dbURL(QString(OSNDB_URL));
|
QUrl dbURL(QString(OSNDB_URL));
|
||||||
connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &ADSBDemodGUI::downloadFinished);
|
|
||||||
m_progressDialog = new QProgressDialog(this);
|
m_progressDialog = new QProgressDialog(this);
|
||||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
m_progressDialog->setCancelButton(nullptr);
|
m_progressDialog->setCancelButton(nullptr);
|
||||||
@ -1199,7 +1198,6 @@ void ADSBDemodGUI::on_getAirportDB_clicked(bool checked)
|
|||||||
{
|
{
|
||||||
// Download Opensky network database to a file
|
// Download Opensky network database to a file
|
||||||
QUrl dbURL(QString(AIRPORTS_URL));
|
QUrl dbURL(QString(AIRPORTS_URL));
|
||||||
connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &ADSBDemodGUI::downloadFinished);
|
|
||||||
m_progressDialog = new QProgressDialog(this);
|
m_progressDialog = new QProgressDialog(this);
|
||||||
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
m_progressDialog->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
m_progressDialog->setCancelButton(nullptr);
|
m_progressDialog->setCancelButton(nullptr);
|
||||||
@ -1560,6 +1558,7 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb
|
|||||||
|
|
||||||
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
|
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
|
||||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(onMenuDialogCalled(const QPoint &)));
|
||||||
|
connect(&m_dlm, &HttpDownloadManager::downloadComplete, this, &ADSBDemodGUI::downloadFinished);
|
||||||
|
|
||||||
m_adsbDemod = reinterpret_cast<ADSBDemod*>(rxChannel); //new ADSBDemod(m_deviceUISet->m_deviceSourceAPI);
|
m_adsbDemod = reinterpret_cast<ADSBDemod*>(rxChannel); //new ADSBDemod(m_deviceUISet->m_deviceSourceAPI);
|
||||||
m_adsbDemod->setMessageQueueToGUI(getInputMessageQueue());
|
m_adsbDemod->setMessageQueueToGUI(getInputMessageQueue());
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
#include "adsbdemodstats.h"
|
#include "adsbdemodstats.h"
|
||||||
|
|
||||||
class ADSBDemodSink;
|
class ADSBDemodSink;
|
||||||
class ADSBDemodSettings;
|
struct ADSBDemodSettings;
|
||||||
class ADSBDemodStats;
|
struct ADSBDemodStats;
|
||||||
|
|
||||||
class ADSBDemodSinkWorker : public QThread {
|
class ADSBDemodSinkWorker : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
ADSBDemodSinkWorker(ADSBDemodSink *sink) :
|
ADSBDemodSinkWorker(ADSBDemodSink *sink) :
|
||||||
m_sink(sink),
|
m_sink(sink),
|
||||||
m_demodStats(),
|
m_demodStats(),
|
||||||
m_correlationThresholdLinear(0.02),
|
m_correlationThresholdLinear(0.02f),
|
||||||
m_crc()
|
m_crc()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ struct AircraftInformation {
|
|||||||
int operatorICAOCol = 11;
|
int operatorICAOCol = 11;
|
||||||
int registeredCol = 15;
|
int registeredCol = 15;
|
||||||
|
|
||||||
qDebug() << "readOSNDB: " << filename;
|
qDebug() << "AircraftInformation::readOSNDB: " << filename;
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
QByteArray utfFilename = filename.toUtf8();
|
QByteArray utfFilename = filename.toUtf8();
|
||||||
@ -106,19 +106,19 @@ struct AircraftInformation {
|
|||||||
int icao = 0;
|
int icao = 0;
|
||||||
char *icaoString = NULL;
|
char *icaoString = NULL;
|
||||||
char *registration = NULL;
|
char *registration = NULL;
|
||||||
int registrationLen = 0;
|
size_t registrationLen = 0;
|
||||||
char *manufacturerName = NULL;
|
char *manufacturerName = NULL;
|
||||||
int manufacturerNameLen = 0;
|
size_t manufacturerNameLen = 0;
|
||||||
char *model = NULL;
|
char *model = NULL;
|
||||||
int modelLen = 0;
|
size_t modelLen = 0;
|
||||||
char *owner = NULL;
|
char *owner = NULL;
|
||||||
int ownerLen = 0;
|
size_t ownerLen = 0;
|
||||||
char *operatorName = NULL;
|
char *operatorName = NULL;
|
||||||
int operatorNameLen = 0;
|
size_t operatorNameLen = 0;
|
||||||
char *operatorICAO = NULL;
|
char *operatorICAO = NULL;
|
||||||
int operatorICAOLen = 0;
|
size_t operatorICAOLen = 0;
|
||||||
char *registered = NULL;
|
char *registered = NULL;
|
||||||
int registeredLen = 0;
|
size_t registeredLen = 0;
|
||||||
|
|
||||||
p = strtok(row, ",");
|
p = strtok(row, ",");
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -213,9 +213,9 @@ struct AircraftInformation {
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qDebug() << "Failed to open " << filename;
|
qDebug() << "AircraftInformation::readOSNDB: Failed to open " << filename;
|
||||||
|
|
||||||
qDebug() << "readOSNDB - read " << cnt << " aircraft";
|
qDebug() << "AircraftInformation::readOSNDB: Read " << cnt << " aircraft";
|
||||||
|
|
||||||
return aircraftInfo;
|
return aircraftInfo;
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ struct AircraftInformation {
|
|||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
QHash<int, AircraftInformation *> *aircraftInfo = nullptr;
|
QHash<int, AircraftInformation *> *aircraftInfo = nullptr;
|
||||||
|
|
||||||
qDebug() << "AircraftInformation::readFastOSNDB: " << filename;
|
qDebug() << "AircraftInformation::readFastDB: " << filename;
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
QByteArray utfFilename = filename.toUtf8();
|
QByteArray utfFilename = filename.toUtf8();
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "csv.h"
|
||||||
#include "adsbdemodsettings.h"
|
#include "adsbdemodsettings.h"
|
||||||
|
|
||||||
#define AIRPORTS_URL "https://ourairports.com/data/airports.csv"
|
#define AIRPORTS_URL "https://ourairports.com/data/airports.csv"
|
||||||
@ -56,11 +60,11 @@ struct AirportInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read OurAirport's airport CSV file
|
// Read OurAirport's airport CSV file
|
||||||
|
// See comments for readOSNDB
|
||||||
static QHash<int, AirportInformation *> *readAirportsDB(const QString &filename)
|
static QHash<int, AirportInformation *> *readAirportsDB(const QString &filename)
|
||||||
{
|
{
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
QHash<int, AirportInformation *> *airportInfo = new QHash<int, AirportInformation *>();
|
QHash<int, AirportInformation *> *airportInfo = nullptr;
|
||||||
airportInfo->reserve(70000);
|
|
||||||
|
|
||||||
// Column numbers used for the data as of 2020/10/28
|
// Column numbers used for the data as of 2020/10/28
|
||||||
int idCol = 0;
|
int idCol = 0;
|
||||||
@ -73,71 +77,130 @@ struct AirportInformation {
|
|||||||
|
|
||||||
qDebug() << "AirportInformation::readAirportsDB: " << filename;
|
qDebug() << "AirportInformation::readAirportsDB: " << filename;
|
||||||
|
|
||||||
QFile file(filename);
|
FILE *file;
|
||||||
if (file.open(QIODevice::ReadOnly))
|
QByteArray utfFilename = filename.toUtf8();
|
||||||
|
if ((file = fopen(utfFilename.constData(), "r")) != NULL)
|
||||||
{
|
{
|
||||||
QList<QByteArray> colNames;
|
char row[2048];
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
// Read header
|
if (fgets(row, sizeof(row), file))
|
||||||
if (!file.atEnd())
|
|
||||||
{
|
{
|
||||||
QByteArray row = file.readLine().trimmed();
|
airportInfo = new QHash<int, AirportInformation *>();
|
||||||
colNames = row.split(',');
|
airportInfo->reserve(70000);
|
||||||
// Work out which columns the data is in, based on the headers
|
|
||||||
idx = colNames.indexOf("id");
|
// Read header
|
||||||
if (idx >= 0)
|
int idx = 0;
|
||||||
|
char *p = strtok(row, ",");
|
||||||
|
while (p != NULL)
|
||||||
|
{
|
||||||
|
if (!strcmp(p, "id"))
|
||||||
idCol = idx;
|
idCol = idx;
|
||||||
idx = colNames.indexOf("ident");
|
else if (!strcmp(p, "ident"))
|
||||||
if (idx >= 0)
|
|
||||||
identCol = idx;
|
identCol = idx;
|
||||||
idx = colNames.indexOf("type");
|
else if (!strcmp(p, "type"))
|
||||||
if (idx >= 0)
|
|
||||||
typeCol = idx;
|
typeCol = idx;
|
||||||
idx = colNames.indexOf("name");
|
else if (!strcmp(p, "name"))
|
||||||
if (idx >= 0)
|
|
||||||
nameCol = idx;
|
nameCol = idx;
|
||||||
idx = colNames.indexOf("latitude_deg");
|
else if (!strcmp(p, "latitude_deg"))
|
||||||
if (idx >= 0)
|
|
||||||
latitudeCol = idx;
|
latitudeCol = idx;
|
||||||
idx = colNames.indexOf("longitude_deg");
|
else if (!strcmp(p, "longitude_deg"))
|
||||||
if (idx >= 0)
|
|
||||||
longitudeCol = idx;
|
longitudeCol = idx;
|
||||||
idx = colNames.indexOf("elevation_ft");
|
else if (!strcmp(p, "elevation_ft"))
|
||||||
if (idx >= 0)
|
|
||||||
elevationCol = idx;
|
elevationCol = idx;
|
||||||
|
p = strtok(NULL, ",");
|
||||||
|
idx++;
|
||||||
}
|
}
|
||||||
// Read data
|
// Read data
|
||||||
while (!file.atEnd())
|
while (fgets(row, sizeof(row), file))
|
||||||
{
|
{
|
||||||
QByteArray row = file.readLine();
|
int id = 0;
|
||||||
QList<QByteArray> cols = row.split(',');
|
char *idString = NULL;
|
||||||
|
char *ident = NULL;
|
||||||
|
size_t identLen = 0;
|
||||||
|
char *type = NULL;
|
||||||
|
size_t typeLen = 0;
|
||||||
|
char *name = NULL;
|
||||||
|
size_t nameLen = 0;
|
||||||
|
float latitude = 0.0f;
|
||||||
|
char *latitudeString = NULL;
|
||||||
|
size_t latitudeLen = 0;
|
||||||
|
float longitude = 0.0f;
|
||||||
|
char *longitudeString = NULL;
|
||||||
|
size_t longitudeLen = 0;
|
||||||
|
float elevation = 0.0f;
|
||||||
|
char *elevationString = NULL;
|
||||||
|
size_t elevationLen = 0;
|
||||||
|
|
||||||
bool ok = false;
|
p = strtok(row, ",");
|
||||||
int id = trimQuotes(cols[idCol]).toInt(&ok, 10);
|
idx = 0;
|
||||||
if (ok)
|
while (p != NULL)
|
||||||
{
|
{
|
||||||
QString ident = trimQuotes(cols[identCol]);
|
// Read strings, stripping quotes
|
||||||
QString type = trimQuotes(cols[typeCol]);
|
if (idx == idCol)
|
||||||
QString name = trimQuotes(cols[nameCol]);
|
{
|
||||||
float latitude = cols[latitudeCol].toFloat();
|
idString = p;
|
||||||
float longitude = cols[longitudeCol].toFloat();
|
idString[strlen(idString)] = '\0';
|
||||||
float elevation = cols[elevationCol].toFloat();
|
id = strtol(idString, NULL, 10);
|
||||||
|
}
|
||||||
|
else if (idx == identCol)
|
||||||
|
{
|
||||||
|
ident = p+1;
|
||||||
|
identLen = strlen(ident)-1;
|
||||||
|
ident[identLen] = '\0';
|
||||||
|
}
|
||||||
|
else if (idx == typeCol)
|
||||||
|
{
|
||||||
|
type = p+1;
|
||||||
|
typeLen = strlen(type)-1;
|
||||||
|
type[typeLen] = '\0';
|
||||||
|
}
|
||||||
|
else if (idx == nameCol)
|
||||||
|
{
|
||||||
|
name = p+1;
|
||||||
|
nameLen = strlen(name)-1;
|
||||||
|
name[nameLen] = '\0';
|
||||||
|
}
|
||||||
|
else if (idx == latitudeCol)
|
||||||
|
{
|
||||||
|
latitudeString = p;
|
||||||
|
latitudeLen = strlen(latitudeString)-1;
|
||||||
|
latitudeString[latitudeLen] = '\0';
|
||||||
|
latitude = atof(latitudeString);
|
||||||
|
}
|
||||||
|
else if (idx == longitudeCol)
|
||||||
|
{
|
||||||
|
longitudeString = p;
|
||||||
|
longitudeLen = strlen(longitudeString)-1;
|
||||||
|
longitudeString[longitudeLen] = '\0';
|
||||||
|
longitude = atof(longitudeString);
|
||||||
|
}
|
||||||
|
else if (idx == elevationCol)
|
||||||
|
{
|
||||||
|
elevationString = p;
|
||||||
|
elevationLen = strlen(elevationString)-1;
|
||||||
|
elevationString[elevationLen] = '\0';
|
||||||
|
elevation = atof(elevationString);
|
||||||
|
}
|
||||||
|
p = strtok(NULL, ",");
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
if (type != "closed")
|
// Only create the entry if we have some interesting data
|
||||||
|
if (((latitude != 0.0f) || (longitude != 0.0f)) && (type && strcmp(type, "closed")))
|
||||||
{
|
{
|
||||||
AirportInformation *airport = new AirportInformation();
|
AirportInformation *airport = new AirportInformation();
|
||||||
airport->m_id = id;
|
airport->m_id = id;
|
||||||
airport->m_ident = ident;
|
airport->m_ident = QString(ident);
|
||||||
if (type == "small_airport")
|
if (!strcmp(type, "small_airport"))
|
||||||
airport->m_type = ADSBDemodSettings::AirportType::Small;
|
airport->m_type = ADSBDemodSettings::AirportType::Small;
|
||||||
else if (type == "medium_airport")
|
else if (!strcmp(type, "medium_airport"))
|
||||||
airport->m_type = ADSBDemodSettings::AirportType::Medium;
|
airport->m_type = ADSBDemodSettings::AirportType::Medium;
|
||||||
else if (type == "large_airport")
|
else if (!strcmp(type, "large_airport"))
|
||||||
airport->m_type = ADSBDemodSettings::AirportType::Large;
|
airport->m_type = ADSBDemodSettings::AirportType::Large;
|
||||||
else if (type == "heliport")
|
else if (!strcmp(type, "heliport"))
|
||||||
airport->m_type = ADSBDemodSettings::AirportType::Heliport;
|
airport->m_type = ADSBDemodSettings::AirportType::Heliport;
|
||||||
airport->m_name = name;
|
airport->m_name = QString(name);
|
||||||
airport->m_latitude = latitude;
|
airport->m_latitude = latitude;
|
||||||
airport->m_longitude = longitude;
|
airport->m_longitude = longitude;
|
||||||
airport->m_elevation = elevation;
|
airport->m_elevation = elevation;
|
||||||
@ -146,12 +209,12 @@ struct AirportInformation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
file.close();
|
fclose(file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
qDebug() << "Failed to open " << filename << " " << file.errorString();
|
qDebug() << "AirportInformation::readAirportsDB: Failed to open " << filename;
|
||||||
|
|
||||||
qDebug() << "AirportInformation::readAirportsDB: - read " << cnt << " airports";
|
qDebug() << "AirportInformation::readAirportsDB: Read " << cnt << " airports";
|
||||||
|
|
||||||
return airportInfo;
|
return airportInfo;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user