SoDaRadio-5.0.3-master:8901fb5
qtgui
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
33
GUISoDa::HamlibListener::HamlibListener
(qintptr desc,
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
42
void
GUISoDa::HamlibListener::run
()
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
57
void
GUISoDa::HamlibListener::readyRead
() {
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'
) {
65
handler_p
->
processCommand
(
current_command
,
socket_p
);
66
current_command
= QString(
""
);
67
}
68
else
{
69
current_command
.append(as[i]);
70
}
71
}
72
}
73
74
void
GUISoDa::HamlibListener::disconnected
() {
75
qDebug() <<
"\n\nHamlib listener got disconnect!!!\n\n"
;
76
socket_p
->deleteLater();
77
}
GUISoDa::HamlibListener::run
void run()
Definition:
soda_hamlib_listener.cpp:42
GUISoDa::HamlibListener::HamlibListener
HamlibListener(qintptr desc, HamlibHandler *_handler, QObject *parent=0)
Definition:
soda_hamlib_listener.cpp:33
GUISoDa::HamlibHandler::processCommand
void processCommand(const QString &cmd, QTcpSocket *socket_p)
Definition:
soda_hamlib_handler.cpp:121
soda_hamlib_handler.hpp
GUISoDa::HamlibListener::socket_p
QTcpSocket * socket_p
Definition:
soda_hamlib_listener.hpp:60
GUISoDa::HamlibListener::error
void error(QTcpSocket::SocketError err)
GUISoDa::HamlibListener::handler_p
HamlibHandler * handler_p
Definition:
soda_hamlib_listener.hpp:57
GUISoDa::HamlibListener::socket_desc
qintptr socket_desc
Definition:
soda_hamlib_listener.hpp:58
GUISoDa::HamlibListener::disconnected
void disconnected()
Definition:
soda_hamlib_listener.cpp:74
GUISoDa::HamlibListener::readyRead
void readyRead()
Definition:
soda_hamlib_listener.cpp:57
soda_hamlib_listener.hpp
GUISoDa::HamlibHandler
Definition:
soda_hamlib_handler.hpp:43
GUISoDa::HamlibListener::current_command
QString current_command
Definition:
soda_hamlib_listener.hpp:59
Generated on Sun Sep 24 2017 12:16:38 for SoDaRadio-5.0.3-master:8901fb5 by
1.8.13