SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
deviceperseusscan.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include "deviceperseusscan.h"
19 #include "perseus-sdr.h"
20 #include <sstream>
21 #include <QtGlobal>
22 
23 
24 bool DevicePerseusScan::scan(int nbDevices)
25 {
26  if (nbDevices == 0)
27  {
28  qInfo("DevicePerseusScan::scan: no Perseus devices");
29  return true;
30  }
31 
32  bool done = true;
33  perseus_descr *descr;
34  eeprom_prodid prodid;
35 
36  for (int deviceIndex = 0; deviceIndex < nbDevices; deviceIndex++)
37  {
38  if ((descr = perseus_open(deviceIndex)) == 0)
39  {
40  qCritical("DevicePerseusScan::scan: device #%d open error: %s", deviceIndex, perseus_errorstr());
41  perseus_close(descr);
42  continue;
43  }
44 
45  if (perseus_firmware_download(descr, 0) < 0)
46  {
47  qCritical("DevicePerseusScan::scan: device #%d firmware download error: %s", deviceIndex, perseus_errorstr());
48  perseus_close(descr);
49  done = false;
50  continue;
51  }
52  else
53  {
54  qInfo("DevicePerseusScan::scan: device #%d firmware downloaded", deviceIndex);
55  }
56 
57  if (perseus_get_product_id(descr,&prodid) < 0)
58  {
59  qCritical("DevicePerseusScan::scan: device #%d get product id error: %s", deviceIndex, perseus_errorstr());
60  perseus_close(descr);
61  continue;
62  }
63  else
64  {
65  uint32_t sigA = (prodid.signature[5]<<16) + prodid.signature[4];
66  uint32_t sigB = (prodid.signature[3]<<16) + prodid.signature[2];
67  uint32_t sigC = (prodid.signature[1]<<16) + prodid.signature[0];
68  std::stringstream ss;
69  ss << prodid.sn << "-" << std::hex << sigA << "-" << sigB << "-" << sigC;
70  m_scans.push_back({ss.str(), prodid.sn, deviceIndex});
71  m_serialMap[m_scans.back().m_serial] = &m_scans.back();
72  perseus_close(descr);
73  }
74  }
75 
76  return done;
77 }
78 
80 {
81  m_scans.clear();
82  m_serialMap.clear();
83 }
84 
85 const std::string* DevicePerseusScan::getSerialAt(unsigned int index) const
86 {
87  if (index < m_scans.size()) {
88  return &(m_scans[index].m_serial);
89  } else {
90  return 0;
91  }
92 }
93 
95 {
96  if (index < m_scans.size()) {
97  return m_scans[index].m_serialNumber;
98  } else {
99  return 0;
100  }
101 }
102 
103 int DevicePerseusScan::getSequenceAt(unsigned int index) const
104 {
105  if (index < m_scans.size()) {
106  return m_scans[index].m_sequence;
107  } else {
108  return 0;
109  }
110 }
111 
112 int DevicePerseusScan::getSequenceFromSerial(const std::string& serial) const
113 {
114  std::map<std::string, DeviceScan*>::const_iterator it = m_serialMap.find(serial);
115  if (it == m_serialMap.end()) {
116  return -1;
117  } else {
118  return ((it->second)->m_sequence);
119  }
120 }
121 
122 void DevicePerseusScan::getSerials(std::vector<std::string>& serials) const
123 {
124  std::vector<DeviceScan>::const_iterator it = m_scans.begin();
125  serials.clear();
126 
127  for (; it != m_scans.end(); ++it) {
128  serials.push_back(it->m_serial);
129  }
130 }
131 
132 
133 
bool scan(int nbDevices)
false if one device had its firmware not yet downloaded
std::vector< DeviceScan > m_scans
void getSerials(std::vector< std::string > &serials) const
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned short uint16_t
Definition: rtptypes_win.h:44
const std::string * getSerialAt(unsigned int index) const
std::map< std::string, DeviceScan * > m_serialMap
int getSequenceAt(unsigned int index) const
int getSequenceFromSerial(const std::string &serial) const
uint16_t getSerialNumberAt(unsigned int index) const