SoDaRadio-5.0.3-master:8901fb5
soda_hamlib_listener.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2017 Matthew H. Reilly (kb1vc)
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include "soda_hamlib_listener.hpp"
30 #include "soda_hamlib_handler.hpp"
31 
32 
34  GUISoDa::HamlibHandler * _handler,
35  QObject *parent) : QThread(parent),
36  handler_p(_handler),
37  socket_desc(desc)
38 {
39  // not much else to do.
40 }
41 
43 {
44  socket_p = new QTcpSocket();
45 
46  if(!socket_p->setSocketDescriptor(socket_desc)) {
47  emit error(socket_p->error());
48  return;
49  }
50 
51  connect(socket_p, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
52  connect(socket_p, SIGNAL(disconnected()), this, SLOT(disconnected()));
53 
54  exec();
55 }
56 
58  QByteArray array = socket_p->read(socket_p->bytesAvailable());
59 
60  char * as = array.data();
61 
62  int lim = array.count();
63  for(int i = 0; i < lim; i++) {
64  if(as[i] == '\n') {
66  current_command = QString("");
67  }
68  else {
69  current_command.append(as[i]);
70  }
71  }
72 }
73 
75  qDebug() << "\n\nHamlib listener got disconnect!!!\n\n";
76  socket_p->deleteLater();
77 }
HamlibListener(qintptr desc, HamlibHandler *_handler, QObject *parent=0)
void processCommand(const QString &cmd, QTcpSocket *socket_p)
void error(QTcpSocket::SocketError err)