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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
|
/**
* @licence app begin@
* Copyright (C) 2011-2012 BMW AG
*
* This file is part of COVESA Project Dlt Viewer.
*
* Contributions are licensed to the COVESA Alliance under one or more
* Contribution License Agreements.
*
* \copyright
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
* this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* \file dummycontrolplugin.cpp
* For further information see http://www.covesa.global/.
* @licence end@
*/
#include <QtGui>
#include <QTextStream>
#include "dlttestrobotplugin.h"
DltTestRobotPlugin::DltTestRobotPlugin()
{
form = NULL;
counterMessages = 0;
counterNonVerboseMessages = 0;
counterVerboseMessages = 0;
dltFile = 0;
dltControl = 0;
ecuList = 0;
tcpSocket = 0;
port = 4490;
}
DltTestRobotPlugin::~DltTestRobotPlugin()
{
}
QString DltTestRobotPlugin::name()
{
return QString("DLT Test Robot Plugin");
}
QString DltTestRobotPlugin::pluginVersion(){
return DLT_TEST_ROBOT_PLUGIN_VERSION;
}
QString DltTestRobotPlugin::pluginInterfaceVersion(){
return PLUGIN_INTERFACE_VERSION;
}
QString DltTestRobotPlugin::description()
{
return QString();
}
QString DltTestRobotPlugin::error()
{
return QString();
}
bool DltTestRobotPlugin::loadConfig(QString /* filename */)
{
return true;
}
bool DltTestRobotPlugin::saveConfig(QString /* filename */)
{
return true;
}
QStringList DltTestRobotPlugin::infoConfig()
{
return QStringList();
}
QWidget* DltTestRobotPlugin::initViewer()
{
form = new DltTestRobot::Form(this);
start();
return form;
}
bool DltTestRobotPlugin::initControl(QDltControl *control)
{
dltControl = control;
return true;
}
bool DltTestRobotPlugin::initConnections(QStringList list)
{
ecuList = new QStringList(list);
return false;
}
bool DltTestRobotPlugin::controlMsg(int , QDltMsg &)
{
return false;
}
bool DltTestRobotPlugin::stateChanged(int, QDltConnection::QDltConnectionState, QString) {
return true;
}
bool DltTestRobotPlugin::autoscrollStateChanged(bool enabled)
{
Q_UNUSED(enabled)
return true;
}
void DltTestRobotPlugin::initMessageDecoder(QDltMessageDecoder* pMessageDecoder)
{
Q_UNUSED(pMessageDecoder);
}
void DltTestRobotPlugin::initMainTableView(QTableView* pTableView)
{
Q_UNUSED(pTableView);
}
void DltTestRobotPlugin::configurationChanged()
{}
void DltTestRobotPlugin::selectedIdxMsg(int , QDltMsg &) {
}
void DltTestRobotPlugin::selectedIdxMsgDecoded(int , QDltMsg &){
}
void DltTestRobotPlugin::initFileStart(QDltFile *file){
dltFile = file;
}
void DltTestRobotPlugin::initMsg(int , QDltMsg &){
}
void DltTestRobotPlugin::initMsgDecoded(int , QDltMsg &){
}
void DltTestRobotPlugin::initFileFinish(){
}
void DltTestRobotPlugin::updateFileStart(){
}
void DltTestRobotPlugin::updateMsg(int , QDltMsg &){
}
void DltTestRobotPlugin::updateMsgDecoded(int , QDltMsg &msg)
{
for(int num=0; num<filterEcuId.size(); num++)
{
if(filterEcuId[num]==msg.getEcuid() && filterAppId[num]==msg.getApid() && filterCtxId[num]==msg.getCtid() && tcpSocket)
{
QString text = msg.getEcuid() + " " + msg.getApid() + " " + msg.getCtid() + " " + msg.toStringPayload();
qDebug() << "DltTestRobot: send message" << text;
text += "\n";
tcpSocket->write(text.toLatin1());
}
}
}
void DltTestRobotPlugin::updateFileFinish(){
}
void DltTestRobotPlugin::readyRead()
{
// data on was received
while (tcpSocket && tcpSocket->canReadLine())
{
QString text = QString(tcpSocket->readLine());
if(text.size()>0)
{
text.chop(1);
// line is not empty
qDebug() << "DltTestRobot: readLine" << text;
QStringList list = text.split(' ');
if(list[0]=="injection" && ecuList)
{
QString ecuId = list[1];
for(int num=0;num<ecuList->length();num++)
{
if(ecuList->at(num).contains(ecuId) && dltControl)
{
list.removeAt(0);
list.removeAt(0);
dltControl->sendInjection(num,"DLT","Test",4096,list.join(' ').toLatin1());
qDebug() << "DltTestRobot: send injection" << list.join(' ');
}
}
}
else if(list[0]=="filter")
{
if(list[1]=="clear")
{
filterEcuId.clear();
filterAppId.clear();
filterCtxId.clear();
}
else if(list[1]=="add")
{
filterEcuId.append(list[2]);
filterAppId.append(list[3]);
filterCtxId.append(list[4]);
}
}
else if(list[0]=="newFile")
{
list.removeAt(0);
if(dltControl && !list.isEmpty())
dltControl->newFile(list.join(' ').toLatin1());
}
else if(list[0]=="openFile")
{
list.removeAt(0);
if(dltControl && !list.isEmpty())
dltControl->openFile(QStringList(list.join(' ').toLatin1()));
}
else if(list[0]=="saveAsFile")
{
list.removeAt(0);
if(dltControl && !list.isEmpty())
dltControl->saveAsFile(list.join(' ').toLatin1());
}
else if(list[0]=="reopenFile")
{
if(dltControl)
dltControl->reopenFile();
}
else if(list[0]=="clearFile")
{
if(dltControl)
dltControl->clearFile();
}
else if(list[0]=="quitDltViewer")
{
if(dltControl)
dltControl->quitDltViewer();
}
else if(list[0]=="marker")
{
if(dltControl)
dltControl->marker();
}
else if(list[0]=="connectAllEcu")
{
if(dltControl)
dltControl->connectAllEcu();
}
else if(list[0]=="disconnectAllEcu")
{
if(dltControl)
dltControl->disconnectAllEcu();
}
}
}
}
void DltTestRobotPlugin::newConnection()
{
tcpSocket = tcpServer.nextPendingConnection();
connect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
tcpServer.pauseAccepting();
//readData.clear();
qDebug() << "DltTestRobot: connected";
form->status("connected");
}
void DltTestRobotPlugin::connected()
{
}
void DltTestRobotPlugin::disconnected()
{
tcpSocket->close();
disconnect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
disconnect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));
//delete tcpSocket;
tcpSocket = 0;
tcpServer.resumeAccepting();
qDebug() << "DltTestRobot: disconnected";
form->status("listening");
}
unsigned int DltTestRobotPlugin::getPort() const
{
return port;
}
void DltTestRobotPlugin::setPort(unsigned int value)
{
port = value;
}
void DltTestRobotPlugin::start()
{
if(tcpServer.isListening())
return ;
tcpServer.setMaxPendingConnections(1);
if(tcpServer.listen(QHostAddress::Any,port)==true)
{
connect(&tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
form->status("listening");
qDebug() << "DltTestRobot: listening" << port;
}
else
{
form->status("error");
qDebug() << "DltTestRobot: error" << port;
}
form->start();
}
void DltTestRobotPlugin::stop()
{
if(tcpSocket && tcpSocket->isOpen())
{
disconnect(tcpSocket, SIGNAL(connected()), this, SLOT(connected()));
disconnect(tcpSocket, SIGNAL(disconnected()), this, SLOT(disconnected()));
tcpSocket->close();
}
disconnect(&tcpServer, SIGNAL(newConnection()), this, SLOT(newConnection()));
tcpServer.close();
form->status("stopped");
qDebug() << "DltTestRobot: stopped";
form->stop();
}
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(dlttestrobotplugin, DltTestRobotPlugin);
#endif
|