30 #include <sys/ioctl.h> 32 #include <linux/serial.h> 41 #include <QDataStream> 51 qDebug(
"AMBEEngine::~AMBEEngine: %lu controllers",
m_controllers.size());
62 for (
int i = 1;
i <= 20;
i++)
64 sprintf(comCStr,
"COM%d",
i);
65 m_comList.push_back(std::string(comCStr));
77 struct dirent **namelist;
80 const char* sysdir =
"/sys/class/tty/";
83 n = scandir(sysdir, &namelist, NULL, alphasort);
92 if (strcmp(namelist[n]->d_name,
"..") && strcmp(namelist[n]->d_name,
"."))
95 std::string devicedir = sysdir;
96 devicedir += namelist[n]->d_name;
111 #endif // not Windows 115 std::vector<std::string>& comList,
116 std::vector<std::string>& comList8250,
117 const std::string& dir)
123 if (driver.size() > 0)
126 std::string devfile = std::string(
"/dev/") + basename((
char *) dir.c_str());
129 if (driver ==
"serial8250") {
130 comList8250.push_back(devfile);
132 comList.push_back(devfile);
138 std::vector<std::string>& comList,
139 std::vector<std::string> comList8250)
141 struct serial_struct serinfo;
142 std::vector<std::string>::iterator it = comList8250.begin();
145 while (it != comList8250.end())
149 int fd = open((*it).c_str(), O_RDWR | O_NONBLOCK | O_NOCTTY);
154 if (ioctl(fd, TIOCGSERIAL, &serinfo) == 0)
157 if (serinfo.type != PORT_UNKNOWN) {
158 comList.push_back(*it);
171 std::string devicedir = tty;
173 devicedir +=
"/device";
176 if (lstat(devicedir.c_str(), &st) == 0 && S_ISLNK(st.st_mode))
179 memset(buffer, 0,
sizeof(buffer));
181 devicedir +=
"/driver";
183 if (readlink(devicedir.c_str(), buffer,
sizeof(buffer)) > 0) {
184 return basename(buffer);
194 std::vector<std::string>::const_iterator it =
m_comList.begin();
200 qDebug(
"AMBEEngine::scan: com: %s", it->c_str());
202 if (worker->
open(*it))
204 ambeDevices.push_back(QString(it->c_str()));
212 #endif // not Windows 218 if (worker->
open(deviceRef))
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));
241 std::vector<AMBEController>::iterator it =
m_controllers.begin();
245 if (it->device == deviceRef)
247 disconnect(&it->worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), it->worker, SLOT(handleInputMessages()));
249 it->thread->wait(100);
250 it->worker->m_inputMessageQueue.clear();
252 qDebug() <<
"AMBEEngine::releaseController: closed device at: " << it->device.c_str();
263 std::vector<AMBEController>::iterator it =
m_controllers.begin();
267 disconnect(&it->worker->m_inputMessageQueue, SIGNAL(messageEnqueued()), it->worker, SLOT(handleInputMessages()));
269 it->thread->wait(100);
270 it->worker->m_inputMessageQueue.clear();
272 qDebug() <<
"AMBEEngine::release: closed device at: " << it->device.c_str();
281 std::vector<AMBEController>::const_iterator it =
m_controllers.begin();
285 deviceNames.push_back(QString(it->device.c_str()));
291 const unsigned char *mbeFrame,
294 unsigned char channels,
299 std::vector<AMBEController>::iterator it =
m_controllers.begin();
300 std::vector<AMBEController>::iterator itAvail =
m_controllers.end();
306 if (it->worker->hasFifo(audioFifo))
308 it->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useLP, upsampling, audioFifo);
311 else if (it->worker->isAvailable())
325 qDebug(
"AMBEEngine::pushMbeFrame: push %p on empty queue %d", audioFifo, wNum);
326 itAvail->worker->pushMbeFrame(mbeFrame, mbeRateIndex, mbeVolumeIndex, channels, useLP, upsampling, audioFifo);
330 qDebug(
"AMBEEngine::pushMbeFrame: no DV device available. MBE frame dropped");
337 QStringList qDeviceList;
338 std::vector<AMBEController>::const_iterator it =
m_controllers.begin();
342 qDebug(
"AMBEEngine::serialize: %s", it->device.c_str());
343 qDeviceList << QString(it->device.c_str());
348 QDataStream *stream =
new QDataStream(&data, QIODevice::WriteOnly);
349 (*stream) << qDeviceList;
357 if (data.size() <= 0)
359 qDebug(
"AMBEEngine::deserialize: invalid or no data");
363 QStringList qDeviceList;
364 QDataStream *stream =
new QDataStream(data);
365 (*stream) >> qDeviceList;
370 for (
int i = 0;
i < qDeviceList.size(); ++
i)
372 qDebug(
" AMBEEngine::deserialize: %s", qDeviceList.at(
i).toStdString().c_str());
static void probe_serial8250_comports(std::vector< std::string > &comList, std::vector< std::string > comList8250)
void getDeviceRefs(std::vector< QString > &devicesRefs)
reference of the devices used (device path or url)
static void register_comport(std::vector< std::string > &comList, std::vector< std::string > &comList8250, const std::string &dir)
std::vector< std::string > m_comList8250
void scan(std::vector< QString > &ambeDevices)
bool registerController(const std::string &deviceRef)
create a new controller for the device in reference
std::vector< std::string > m_comList
QByteArray serialize() const
bool deserialize(const QByteArray &data)
void pushMbeFrame(const unsigned char *mbeFrame, int mbeRateIndex, int mbeVolumeIndex, unsigned char channels, bool useHP, int upsampling, AudioFifo *audioFifo)
std::vector< AMBEController > m_controllers
bool open(const std::string &deviceRef)
Either serial device or ip:port.
static std::string get_driver(const std::string &tty)
void releaseController(const std::string &deviceRef)
release controller resources for the device in reference