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.
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
AMBEEngine Class Reference

#include <ambeengine.h>

Inherits QObject.

Classes

struct  AMBEController
 

Public Member Functions

 AMBEEngine ()
 
 ~AMBEEngine ()
 
void scan (std::vector< QString > &ambeDevices)
 
void releaseAll ()
 
int getNbDevices () const
 number of devices used More...
 
void getDeviceRefs (std::vector< QString > &devicesRefs)
 reference of the devices used (device path or url) More...
 
bool registerController (const std::string &deviceRef)
 create a new controller for the device in reference More...
 
void releaseController (const std::string &deviceRef)
 release controller resources for the device in reference More...
 
void pushMbeFrame (const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
 
QByteArray serialize () const
 
bool deserialize (const QByteArray &data)
 

Private Member Functions

void getComList ()
 

Static Private Member Functions

static std::string get_driver (const std::string &tty)
 
static void register_comport (std::vector< std::string > &comList, std::vector< std::string > &comList8250, const std::string &dir)
 
static void probe_serial8250_comports (std::vector< std::string > &comList, std::vector< std::string > comList8250)
 

Private Attributes

std::vector< AMBEControllerm_controllers
 
std::vector< std::string > m_comList
 
std::vector< std::string > m_comList8250
 
QMutex m_mutex
 

Detailed Description

Definition at line 36 of file ambeengine.h.

Constructor & Destructor Documentation

◆ AMBEEngine()

AMBEEngine::AMBEEngine ( )

Definition at line 46 of file ambeengine.cpp.

47 {}

◆ ~AMBEEngine()

AMBEEngine::~AMBEEngine ( )

Definition at line 49 of file ambeengine.cpp.

References getComList(), i, m_comList, m_comList8250, m_controllers, and scan().

50 {
51  qDebug("AMBEEngine::~AMBEEngine: %lu controllers", m_controllers.size());
52 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the call graph for this function:

Member Function Documentation

◆ deserialize()

bool AMBEEngine::deserialize ( const QByteArray &  data)

Definition at line 355 of file ambeengine.cpp.

References i, registerController(), and releaseAll().

Referenced by MainSettings::load().

356 {
357  if (data.size() <= 0)
358  {
359  qDebug("AMBEEngine::deserialize: invalid or no data");
360  return false;
361  }
362 
363  QStringList qDeviceList;
364  QDataStream *stream = new QDataStream(data);
365  (*stream) >> qDeviceList;
366  delete stream;
367 
368  releaseAll();
369 
370  for (int i = 0; i < qDeviceList.size(); ++i)
371  {
372  qDebug(" AMBEEngine::deserialize: %s", qDeviceList.at(i).toStdString().c_str());
373  registerController(qDeviceList.at(i).toStdString());
374  }
375 
376  return true;
377 }
bool registerController(const std::string &deviceRef)
create a new controller for the device in reference
Definition: ambeengine.cpp:214
void releaseAll()
Definition: ambeengine.cpp:261
int32_t i
Definition: decimators.h:244
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_driver()

std::string AMBEEngine::get_driver ( const std::string &  tty)
staticprivate

Definition at line 168 of file ambeengine.cpp.

Referenced by register_comport().

169 {
170  struct stat st;
171  std::string devicedir = tty;
172  // Append '/device' to the tty-path
173  devicedir += "/device";
174 
175  // Stat the devicedir and handle it if it is a symlink
176  if (lstat(devicedir.c_str(), &st) == 0 && S_ISLNK(st.st_mode))
177  {
178  char buffer[1024];
179  memset(buffer, 0, sizeof(buffer));
180  // Append '/driver' and return basename of the target
181  devicedir += "/driver";
182 
183  if (readlink(devicedir.c_str(), buffer, sizeof(buffer)) > 0) {
184  return basename(buffer);
185  }
186  }
187 
188  return "";
189 }
+ Here is the caller graph for this function:

◆ getComList()

void AMBEEngine::getComList ( )
private

Definition at line 74 of file ambeengine.cpp.

References m_comList, m_comList8250, probe_serial8250_comports(), and register_comport().

Referenced by scan(), and ~AMBEEngine().

75 {
76  int n;
77  struct dirent **namelist;
78  m_comList.clear();
79  m_comList8250.clear();
80  const char* sysdir = "/sys/class/tty/";
81 
82  // Scan through /sys/class/tty - it contains all tty-devices in the system
83  n = scandir(sysdir, &namelist, NULL, alphasort);
84  if (n < 0)
85  {
86  perror("scandir");
87  }
88  else
89  {
90  while (n--)
91  {
92  if (strcmp(namelist[n]->d_name, "..") && strcmp(namelist[n]->d_name, "."))
93  {
94  // Construct full absolute file path
95  std::string devicedir = sysdir;
96  devicedir += namelist[n]->d_name;
97  // Register the device
99  }
100 
101  free(namelist[n]);
102  }
103 
104  free(namelist);
105  }
106 
107  // Only non-serial8250 has been added to comList without any further testing
108  // serial8250-devices must be probe to check for validity
110 }
static void probe_serial8250_comports(std::vector< std::string > &comList, std::vector< std::string > comList8250)
Definition: ambeengine.cpp:137
static void register_comport(std::vector< std::string > &comList, std::vector< std::string > &comList8250, const std::string &dir)
Definition: ambeengine.cpp:114
std::vector< std::string > m_comList8250
Definition: ambeengine.h:85
std::vector< std::string > m_comList
Definition: ambeengine.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDeviceRefs()

void AMBEEngine::getDeviceRefs ( std::vector< QString > &  devicesRefs)

reference of the devices used (device path or url)

Definition at line 279 of file ambeengine.cpp.

References m_controllers.

Referenced by DSPEngine::getDVSerialNames(), and AMBEDevicesDialog::refreshInUseList().

280 {
281  std::vector<AMBEController>::const_iterator it = m_controllers.begin();
282 
283  while (it != m_controllers.end())
284  {
285  deviceNames.push_back(QString(it->device.c_str()));
286  ++it;
287  }
288 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the caller graph for this function:

◆ getNbDevices()

int AMBEEngine::getNbDevices ( ) const
inline

number of devices used

Definition at line 46 of file ambeengine.h.

Referenced by DSPEngine::hasDVSerialSupport().

+ Here is the caller graph for this function:

◆ probe_serial8250_comports()

void AMBEEngine::probe_serial8250_comports ( std::vector< std::string > &  comList,
std::vector< std::string >  comList8250 
)
staticprivate

Definition at line 137 of file ambeengine.cpp.

Referenced by getComList().

140 {
141  struct serial_struct serinfo;
142  std::vector<std::string>::iterator it = comList8250.begin();
143 
144  // Iterate over all serial8250-devices
145  while (it != comList8250.end())
146  {
147 
148  // Try to open the device
149  int fd = open((*it).c_str(), O_RDWR | O_NONBLOCK | O_NOCTTY);
150 
151  if (fd >= 0)
152  {
153  // Get serial_info
154  if (ioctl(fd, TIOCGSERIAL, &serinfo) == 0)
155  {
156  // If device type is no PORT_UNKNOWN we accept the port
157  if (serinfo.type != PORT_UNKNOWN) {
158  comList.push_back(*it);
159  }
160  }
161 
162  close(fd);
163  }
164  it++;
165  }
166 }
+ Here is the caller graph for this function:

◆ pushMbeFrame()

void AMBEEngine::pushMbeFrame ( const unsigned char *  mbeFrame,
int  mbeRateIndex,
int  mbeVolumeIndex,
unsigned char  channels,
bool  useHP,
int  upsampling,
AudioFifo audioFifo 
)

Definition at line 290 of file ambeengine.cpp.

References m_controllers, and m_mutex.

Referenced by DSPEngine::pushMbeFrame().

298 {
299  std::vector<AMBEController>::iterator it = m_controllers.begin();
300  std::vector<AMBEController>::iterator itAvail = m_controllers.end();
301  bool done = false;
302  QMutexLocker locker(&m_mutex);
303 
304  while (it != m_controllers.end())
305  {
306  if (it->worker->hasFifo(audioFifo))
307  {
308  it->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useLP, upsampling, audioFifo);
309  done = true;
310  }
311  else if (it->worker->isAvailable())
312  {
313  itAvail = it;
314  }
315 
316  ++it;
317  }
318 
319  if (!done)
320  {
321  if (itAvail != m_controllers.end())
322  {
323  int wNum = itAvail - m_controllers.begin();
324 
325  qDebug("AMBEEngine::pushMbeFrame: push %p on empty queue %d", audioFifo, wNum);
326  itAvail->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useLP, upsampling, audioFifo);
327  }
328  else
329  {
330  qDebug("AMBEEngine::pushMbeFrame: no DV device available. MBE frame dropped");
331  }
332  }
333 }
QMutex m_mutex
Definition: ambeengine.h:86
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the caller graph for this function:

◆ register_comport()

void AMBEEngine::register_comport ( std::vector< std::string > &  comList,
std::vector< std::string > &  comList8250,
const std::string &  dir 
)
staticprivate

Definition at line 114 of file ambeengine.cpp.

References get_driver().

Referenced by getComList().

118 {
119  // Get the driver the device is using
120  std::string driver = get_driver(dir);
121 
122  // Skip devices without a driver
123  if (driver.size() > 0)
124  {
125  //std::cerr << "register_comport: dir: "<< dir << " driver: " << driver << std::endl;
126  std::string devfile = std::string("/dev/") + basename((char *) dir.c_str());
127 
128  // Put serial8250-devices in a seperate list
129  if (driver == "serial8250") {
130  comList8250.push_back(devfile);
131  } else {
132  comList.push_back(devfile);
133  }
134  }
135 }
static std::string get_driver(const std::string &tty)
Definition: ambeengine.cpp:168
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerController()

bool AMBEEngine::registerController ( const std::string &  deviceRef)

create a new controller for the device in reference

Definition at line 214 of file ambeengine.cpp.

References m_controllers, and AMBEWorker::open().

Referenced by deserialize(), WebAPIAdapterSrv::instanceAMBEDevicesPatch(), WebAPIAdapterGUI::instanceAMBEDevicesPatch(), WebAPIAdapterGUI::instanceAMBEDevicesPut(), WebAPIAdapterSrv::instanceAMBEDevicesPut(), AMBEDevicesDialog::on_importAddress_clicked(), AMBEDevicesDialog::on_importAllSerial_clicked(), and AMBEDevicesDialog::on_importSerial_clicked().

215 {
216  AMBEWorker *worker = new AMBEWorker();
217 
218  if (worker->open(deviceRef))
219  {
220  m_controllers.push_back(AMBEController());
221  m_controllers.back().worker = worker;
222  m_controllers.back().thread = new QThread();
223  m_controllers.back().device = deviceRef;
224 
225  m_controllers.back().worker->moveToThread(m_controllers.back().thread);
226  connect(m_controllers.back().worker, SIGNAL(finished()), m_controllers.back().thread, SLOT(quit()));
227  connect(m_controllers.back().worker, SIGNAL(finished()), m_controllers.back().worker, SLOT(deleteLater()));
228  connect(m_controllers.back().thread, SIGNAL(finished()), m_controllers.back().thread, SLOT(deleteLater()));
229  connect(&m_controllers.back().worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), m_controllers.back().worker, SLOT(handleInputMessages()));
230  std::this_thread::sleep_for(std::chrono::seconds(1));
231  m_controllers.back().thread->start();
232 
233  return true;
234  }
235 
236  return false;
237 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
bool open(const std::string &deviceRef)
Either serial device or ip:port.
Definition: ambeworker.cpp:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ releaseAll()

void AMBEEngine::releaseAll ( )

Definition at line 261 of file ambeengine.cpp.

References m_controllers.

Referenced by deserialize(), WebAPIAdapterSrv::instanceAMBEDevicesDelete(), WebAPIAdapterGUI::instanceAMBEDevicesDelete(), WebAPIAdapterSrv::instanceAMBEDevicesPut(), WebAPIAdapterGUI::instanceAMBEDevicesPut(), and AMBEDevicesDialog::on_clearAmbeList_clicked().

262 {
263  std::vector<AMBEController>::iterator it = m_controllers.begin();
264 
265  while (it != m_controllers.end())
266  {
267  disconnect(&it->worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), it->worker, SLOT(handleInputMessages()));
268  it->worker->stop();
269  it->thread->wait(100);
270  it->worker->m_inputMessageQueue.clear();
271  it->worker->close();
272  qDebug() << "AMBEEngine::release: closed device at: " << it->device.c_str();
273  ++it;
274  }
275 
276  m_controllers.clear();
277 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the caller graph for this function:

◆ releaseController()

void AMBEEngine::releaseController ( const std::string &  deviceRef)

release controller resources for the device in reference

Definition at line 239 of file ambeengine.cpp.

References m_controllers.

Referenced by WebAPIAdapterGUI::instanceAMBEDevicesPatch(), WebAPIAdapterSrv::instanceAMBEDevicesPatch(), and AMBEDevicesDialog::on_removeAmbeDevice_clicked().

240 {
241  std::vector<AMBEController>::iterator it = m_controllers.begin();
242 
243  while (it != m_controllers.end())
244  {
245  if (it->device == deviceRef)
246  {
247  disconnect(&it->worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), it->worker, SLOT(handleInputMessages()));
248  it->worker->stop();
249  it->thread->wait(100);
250  it->worker->m_inputMessageQueue.clear();
251  it->worker->close();
252  qDebug() << "AMBEEngine::releaseController: closed device at: " << it->device.c_str();
253  m_controllers.erase(it);
254  break;
255  }
256 
257  ++it;
258  }
259 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the caller graph for this function:

◆ scan()

void AMBEEngine::scan ( std::vector< QString > &  ambeDevices)

Definition at line 191 of file ambeengine.cpp.

References AMBEWorker::close(), getComList(), m_comList, and AMBEWorker::open().

Referenced by WebAPIAdapterGUI::instanceAMBESerialGet(), WebAPIAdapterSrv::instanceAMBESerialGet(), AMBEDevicesDialog::populateSerialList(), MainBench::testAMBE(), and ~AMBEEngine().

192 {
193  getComList();
194  std::vector<std::string>::const_iterator it = m_comList.begin();
195  ambeDevices.clear();
196 
197  while (it != m_comList.end())
198  {
199  AMBEWorker *worker = new AMBEWorker();
200  qDebug("AMBEEngine::scan: com: %s", it->c_str());
201 
202  if (worker->open(*it))
203  {
204  ambeDevices.push_back(QString(it->c_str()));
205  worker->close();
206  }
207 
208  delete worker;
209  ++it;
210  }
211 }
std::vector< std::string > m_comList
Definition: ambeengine.h:84
void getComList()
Definition: ambeengine.cpp:74
bool open(const std::string &deviceRef)
Either serial device or ip:port.
Definition: ambeworker.cpp:48
void close()
Definition: ambeworker.cpp:53
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

QByteArray AMBEEngine::serialize ( ) const

Definition at line 335 of file ambeengine.cpp.

References m_controllers.

Referenced by MainSettings::save().

336 {
337  QStringList qDeviceList;
338  std::vector<AMBEController>::const_iterator it = m_controllers.begin();
339 
340  while (it != m_controllers.end())
341  {
342  qDebug("AMBEEngine::serialize: %s", it->device.c_str());
343  qDeviceList << QString(it->device.c_str());
344  ++it;
345  }
346 
347  QByteArray data;
348  QDataStream *stream = new QDataStream(&data, QIODevice::WriteOnly);
349  (*stream) << qDeviceList;
350  delete stream;
351 
352  return data;
353 }
std::vector< AMBEController > m_controllers
Definition: ambeengine.h:83
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_comList

std::vector<std::string> AMBEEngine::m_comList
private

Definition at line 84 of file ambeengine.h.

Referenced by getComList(), scan(), and ~AMBEEngine().

◆ m_comList8250

std::vector<std::string> AMBEEngine::m_comList8250
private

Definition at line 85 of file ambeengine.h.

Referenced by getComList(), and ~AMBEEngine().

◆ m_controllers

std::vector<AMBEController> AMBEEngine::m_controllers
private

◆ m_mutex

QMutex AMBEEngine::m_mutex
private

Definition at line 86 of file ambeengine.h.

Referenced by pushMbeFrame().


The documentation for this class was generated from the following files: