2017-01-07 05:24:09 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Edouard Griffiths, F4EXB //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
2019-04-11 00:39:30 -04:00
|
|
|
// (at your option) any later version. //
|
2017-01-07 05:24:09 -05:00
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-01-07 18:33:11 -05:00
|
|
|
#include <stdio.h>
|
2018-11-13 15:11:17 -05:00
|
|
|
#include <QtGlobal>
|
2017-01-07 05:24:09 -05:00
|
|
|
#include "devicehackrf.h"
|
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
DeviceHackRF::DeviceHackRF()
|
2017-01-07 18:33:11 -05:00
|
|
|
{
|
2017-08-31 18:46:43 -04:00
|
|
|
hackrf_error rc = (hackrf_error) hackrf_init();
|
2017-01-07 18:33:11 -05:00
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
if (rc != HACKRF_SUCCESS) {
|
2018-11-13 15:11:17 -05:00
|
|
|
qCritical("DeviceHackRF::open_hackrf: failed to initiate HackRF library %s", hackrf_error_name(rc));
|
2017-01-07 18:33:11 -05:00
|
|
|
}
|
2017-08-31 18:46:43 -04:00
|
|
|
}
|
2017-01-07 18:33:11 -05:00
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
DeviceHackRF::~DeviceHackRF()
|
|
|
|
{
|
|
|
|
hackrf_exit();
|
2017-01-07 18:33:11 -05:00
|
|
|
}
|
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
DeviceHackRF& DeviceHackRF::instance()
|
2017-04-13 20:09:36 -04:00
|
|
|
{
|
2017-08-31 18:46:43 -04:00
|
|
|
static DeviceHackRF inst;
|
|
|
|
return inst;
|
|
|
|
}
|
2017-04-13 20:09:36 -04:00
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
hackrf_device *DeviceHackRF::open_hackrf(int sequence)
|
|
|
|
{
|
|
|
|
instance();
|
2017-04-13 20:09:36 -04:00
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
return open_hackrf_from_sequence(sequence);
|
|
|
|
}
|
2017-04-13 20:09:36 -04:00
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
hackrf_device *DeviceHackRF::open_hackrf(const char * const serial)
|
|
|
|
{
|
|
|
|
hackrf_error rc;
|
2017-04-13 20:09:36 -04:00
|
|
|
hackrf_device *hackrf_ptr;
|
|
|
|
|
2017-08-31 18:46:43 -04:00
|
|
|
instance();
|
|
|
|
|
2017-04-13 20:09:36 -04:00
|
|
|
rc = (hackrf_error) hackrf_open_by_serial(serial, &hackrf_ptr);
|
|
|
|
|
|
|
|
if (rc == HACKRF_SUCCESS)
|
|
|
|
{
|
|
|
|
return hackrf_ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-13 15:11:17 -05:00
|
|
|
qCritical("DeviceHackRF::open_hackrf: error #%d: %s", (int) rc, hackrf_error_name(rc));
|
2017-04-13 20:09:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-07 05:24:09 -05:00
|
|
|
hackrf_device *DeviceHackRF::open_hackrf_from_sequence(int sequence)
|
|
|
|
{
|
2019-10-10 19:36:00 -04:00
|
|
|
instance();
|
|
|
|
|
2017-01-07 05:24:09 -05:00
|
|
|
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
|
2019-10-10 19:36:00 -04:00
|
|
|
|
|
|
|
if (hackrf_devices == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-01-07 05:24:09 -05:00
|
|
|
hackrf_device *hackrf_ptr;
|
|
|
|
hackrf_error rc;
|
|
|
|
|
|
|
|
rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, sequence, &hackrf_ptr);
|
2019-10-10 19:36:00 -04:00
|
|
|
hackrf_device_list_free(hackrf_devices);
|
2017-01-07 05:24:09 -05:00
|
|
|
|
|
|
|
if (rc == HACKRF_SUCCESS)
|
|
|
|
{
|
|
|
|
return hackrf_ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-13 15:11:17 -05:00
|
|
|
qCritical("DeviceHackRF::open_hackrf_from_sequence: error #%d: %s", (int) rc, hackrf_error_name(rc));
|
2017-01-07 05:24:09 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-17 13:54:13 -04:00
|
|
|
void DeviceHackRF::enumOriginDevices(const QString& hardwareId, PluginInterface::OriginDevices& originDevices)
|
|
|
|
{
|
2019-10-10 19:36:00 -04:00
|
|
|
instance();
|
|
|
|
|
2019-09-17 13:54:13 -04:00
|
|
|
hackrf_device_list_t *hackrf_devices = hackrf_device_list();
|
2019-09-24 15:30:53 -04:00
|
|
|
|
|
|
|
if (hackrf_devices == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-17 13:54:13 -04:00
|
|
|
hackrf_device *hackrf_ptr;
|
|
|
|
read_partid_serialno_t read_partid_serialno;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i < hackrf_devices->devicecount; i++)
|
|
|
|
{
|
|
|
|
hackrf_error rc = (hackrf_error) hackrf_device_list_open(hackrf_devices, i, &hackrf_ptr);
|
|
|
|
|
|
|
|
if (rc == HACKRF_SUCCESS)
|
|
|
|
{
|
|
|
|
qDebug("DeviceHackRF::enumOriginDevices: try to enumerate HackRF device #%d", i);
|
|
|
|
|
|
|
|
rc = (hackrf_error) hackrf_board_partid_serialno_read(hackrf_ptr, &read_partid_serialno);
|
|
|
|
|
|
|
|
if (rc != HACKRF_SUCCESS)
|
|
|
|
{
|
|
|
|
qDebug("DeviceHackRF::enumOriginDevices: failed to read serial no: %s", hackrf_error_name(rc));
|
|
|
|
hackrf_close(hackrf_ptr);
|
|
|
|
continue; // next
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t serial_msb = read_partid_serialno.serial_no[2];
|
|
|
|
uint32_t serial_lsb = read_partid_serialno.serial_no[3];
|
|
|
|
|
|
|
|
QString serial_str = QString::number(serial_msb, 16) + QString::number(serial_lsb, 16);
|
|
|
|
//uint64_t serial_num = (((uint64_t) serial_msb)<<32) + serial_lsb;
|
|
|
|
QString displayedName(QString("HackRF[%1] %2").arg(i).arg(serial_str));
|
|
|
|
|
|
|
|
originDevices.append(PluginInterface::OriginDevice(
|
|
|
|
displayedName,
|
|
|
|
hardwareId,
|
|
|
|
serial_str,
|
|
|
|
i,
|
|
|
|
1,
|
|
|
|
1
|
|
|
|
));
|
|
|
|
|
|
|
|
qDebug("DeviceHackRF::enumOriginDevices: enumerated HackRF device #%d", i);
|
|
|
|
|
|
|
|
hackrf_close(hackrf_ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("DeviceHackRF::enumOriginDevices: failed to enumerate HackRF device #%d: %s", i, hackrf_error_name(rc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hackrf_device_list_free(hackrf_devices);
|
|
|
|
}
|
2017-01-07 05:24:09 -05:00
|
|
|
|