-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraceipc.cpp
More file actions
156 lines (131 loc) · 4.39 KB
/
Copy pathtraceipc.cpp
File metadata and controls
156 lines (131 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* Copyright (c) 2014-2015 Dmitry Osipenko <digetx@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h>
#include "traceipc.h"
TraceIPC::TraceIPC(QObject *parent) :
QObject(parent), m_reconnect(false)
{
connect(&m_socket, SIGNAL(connected()), this, SLOT(socket_connected()));
connect(&m_socket, SIGNAL(disconnected()), this, SLOT(socket_disconnected()));
connect(&m_socket, SIGNAL(readyRead()), this, SLOT(socket_readReady()));
connect(&m_socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(socket_error()));
connect(&m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
this, SLOT(socket_error()));
m_reconnect_timer.setSingleShot(true);
connect(&m_reconnect_timer, SIGNAL(timeout()), this, SLOT(Reconnect()));
}
void TraceIPC::connectTo(const QString &addr)
{
m_addr = addr;
#ifdef LOCAL_SOCKET
m_socket.connectToServer(m_addr);
#else
m_socket.connectToHost(m_addr, 19191);
#endif
}
void TraceIPC::Reconnect(void)
{
m_socket.reset();
connectTo(m_addr);
}
void TraceIPC::socket_connected(void)
{
qDebug() << "socket_connected";
emit connected();
}
void TraceIPC::socket_disconnected(void)
{
qDebug() << "socket_disconnected";
emit disconnected();
}
void TraceIPC::socket_readReady(void)
{
union {
u_int32_t magic;
TraceIPC::packet_cdma pak_cdma;
TraceIPC::packet_irq pak_irq;
TraceIPC::packet_txt pak_txt;
TraceIPC::packet_rw pak_rw;
char packet[36];
};
moar:
while (m_socket.bytesAvailable() < sizeof(packet))
if (!m_socket.waitForReadyRead())
return socket_error();
m_socket.read(packet, sizeof(packet));
switch (ntohl(magic)) {
case PACKET_TRACE_RW:
case PACKET_TRACE_RW_V2:
pak_rw.hwaddr = ntohl(pak_rw.hwaddr);
pak_rw.offset = ntohl(pak_rw.offset);
pak_rw.value = ntohl(pak_rw.value);
pak_rw.new_value = ntohl(pak_rw.new_value);
pak_rw.__old_is_write = ntohl(pak_rw.__old_is_write);
pak_rw.time = ntohl(pak_rw.time);
pak_rw.cpu_pc = ntohl(pak_rw.cpu_pc);
pak_rw.cpu_id = ntohl(pak_rw.cpu_id);
emit regAccess(pak_rw);
break;
case PACKET_TRACE_IRQ:
pak_irq.hwaddr = ntohl(pak_irq.hwaddr);
pak_irq.hwirq = ntohl(pak_irq.hwirq);
pak_irq.status = ntohl(pak_irq.status);
pak_irq.time = ntohl(pak_irq.time);
pak_irq.cpu_pc = ntohl(pak_irq.cpu_pc);
pak_irq.cpu_id = ntohl(pak_irq.cpu_id);
emit irqEvent(pak_irq);
break;
case PACKET_TRACE_TXT:
{
while (m_socket.bytesAvailable() < ntohl(pak_txt.text_sz))
if (!m_socket.waitForReadyRead())
return socket_error();
char *txt = new char[ntohl(pak_txt.text_sz)];
m_socket.read(txt, ntohl(pak_txt.text_sz));
emit message(txt);
break;
}
case PACKET_TRACE_CDMA:
pak_cdma.time = ntohl(pak_cdma.time);
pak_cdma.data = ntohl(pak_cdma.data);
pak_cdma.is_gather = ntohl(pak_cdma.is_gather);
pak_cdma.ch_id = ntohl(pak_cdma.ch_id);
emit chWrite(pak_cdma.ch_id, pak_cdma.time, pak_cdma.data,
pak_cdma.is_gather);
break;
default:
qDebug() << QString().sprintf("0x%08X", ntohl(magic));
Q_ASSERT(0);
break;
}
if (m_socket.bytesAvailable())
goto moar;
}
void TraceIPC::socket_error(void)
{
qDebug() << "socket_error" << m_socket.errorString();
m_reconnect_timer.start(1500);
}
void TraceIPC::changeAddr(const QString &addr)
{
m_addr = addr;
}
bool TraceIPC::send(void *cmd, qint64 size)
{
return m_socket.write((char*)cmd, size) == size;
}