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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
|
/**
* @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 filetransferplugin.cpp
* For further information see http://www.covesa.global/.
* @licence end@
*/
#include <QtGui>
#include <QMessageBox>
#include <QApplication>
#include <QDir>
#include <QtDebug>
#include "filetransferplugin.h"
#include "file.h"
FiletransferPlugin::FiletransferPlugin()
{
form = NULL;
dltFile = NULL;
}
FiletransferPlugin::~FiletransferPlugin()
{
}
QString FiletransferPlugin::name()
{
return plugin_name_displayed;
}
QString FiletransferPlugin::pluginVersion()
{
return FILETRANSFER_PLUGIN_VERSION;
}
QString FiletransferPlugin::pluginInterfaceVersion()
{
return PLUGIN_INTERFACE_VERSION;
}
QString FiletransferPlugin::description()
{
QString description("This plugin enables the user to get a list of embedded files in a dlt log and save these files to disk. ");
description += ("For more informations about this plugin please have a look on the dlt filetransfer documentation (generate it with doxygen).");
return description;
}
QString FiletransferPlugin::error()
{
return errorText;
}
bool FiletransferPlugin::loadConfig(QString filename)
{
if ( filename.length() <= 0 )
{
// no configuration file provided, return to default configuration
config.setDefault();
// return no error
errorText = "";
return true;
}
QFile file(filename);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
errorText = "Can not load configuration File: ";
errorText.append(filename);
return false;
}
config.setDefault();
ft_autosave = false;
form->setAutoSave(config.getAutoSavePath(), ft_autosave);
QXmlStreamReader xml(&file);
while (!xml.atEnd()) {
xml.readNext();
if(xml.isStartElement())
{
if(xml.name() == QString("TAG_FLST"))
{
config.setFlstTag( xml.readElementText() );
}
if(xml.name() == QString("TAG_FLDA"))
{
config.setFldaTag( xml.readElementText() );
}
if(xml.name() == QString("TAG_FLFI"))
{
config.setFlfiTag( xml.readElementText() );
}
if(xml.name() == QString("TAG_FLER"))
{
config.setFlerTag( xml.readElementText() );
}
if(xml.name() == QString("TAG_FLCTID"))
{
config.setFlCtIdTag( xml.readElementText() );
}
if(xml.name() == QString("AUTOSAVE"))
{
config.setAutoSavePath( xml.readElementText() );
ft_autosave = true;
if (!QDir(config.getAutoSavePath()).exists())
{
if ( false == QDir().mkpath(config.getAutoSavePath()) )
{
if ( dltControl->silentmode == true )
{
qDebug() << "ERROR creating autosave folder" << config.getAutoSavePath();
}
else
{
QMessageBox::warning(0, QString("ERROR creating autosave folder"), config.getAutoSavePath());
}
}
}
form->setAutoSave(config.getAutoSavePath(), true);
}
}
}
if (xml.hasError())
{
if ( dltControl->silentmode == true )
{
qDebug() << plugin_name_displayed << QString("XML Parser error %1 at line %2").arg(xml.errorString()).arg(xml.lineNumber());
}
else
{
QMessageBox::warning(0, QString("XML Parser error"), xml.errorString());
}
}
file.close();
return true;
}
bool FiletransferPlugin::saveConfig(QString /*filename*/)
{
return true;
}
QStringList FiletransferPlugin::infoConfig()
{
QStringList list;
list.append("TAG_FLCTID: "+ config.getFlCtIdTag());
list.append("TAG_FLST: "+ config.getFlstTag());
list.append("TAG_FLDA: "+ config.getFldaTag());
list.append("TAG_FLFI: "+ config.getFlfiTag());
list.append("TAG_FLER: "+ config.getFlerTag());
if ( true == ft_autosave )
{
list.append("Autosave: "+ config.getAutoSavePath());
}
return list;
}
QWidget* FiletransferPlugin::initViewer()
{
form = new FileTransferPlugin::Form();
return form;
}
void FiletransferPlugin::selectedIdxMsg(int , QDltMsg &)
{
//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::selectedIdxMsgDecoded(int , QDltMsg &)
{
//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::initFileStart(QDltFile *file)
{
if (plugin_is_active == false )
{
qDebug() << "Activate plugin" << plugin_name_displayed << FILETRANSFER_PLUGIN_VERSION;
plugin_is_active = true;
}
dltFile = file;
form->getTreeWidget()->clear();
form->clearSelectedFiles();
}
void FiletransferPlugin::initMsg(int index, QDltMsg &msg)
{
// this function is called when live trace is acvtive
updateFiletransfer(index,msg);
}
void FiletransferPlugin::initMsgDecoded(int , QDltMsg &)
{
//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::initFileFinish()
{
//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::updateFileStart()
{
//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::updateMsg(int index, QDltMsg &msg)
{
// this function is called when a dlt file is read
updateFiletransfer(index,msg);
// end of void function
}
void FiletransferPlugin::updateMsgDecoded(int , QDltMsg &)
{//empty. Implemented because derived plugin interface functions are virtual.
}
void FiletransferPlugin::updateFileFinish()
{
}
void FiletransferPlugin::updateFiletransfer(int index, QDltMsg &msg)
{
QDltArgument msgFirstArgument;
QDltArgument msgLastArgument;
if(NULL == dltFile)
{
//qDebug()<< "dltfile object does not exist";
return;
}
if(msg.getType() != QDltMsg::DltTypeLog)
{
return;
}
if(config.getFlCtIdTag().compare(msg.getCtid()) != 0)
{
// message is not of CTID defined to indicate file transfer
return;
}
if(!msg.getArgument(PROTOCOL_ALL_STARTFLAG,msgFirstArgument))
{
return;
}
// so we have a valid file transfer packet and now we look for the tag contained in the message
if(msgFirstArgument.toString().compare(config.getFldaTag()) == 0 ) // Filetransfer Update
{
msg.getArgument(PROTOCOL_FLDA_ENDFLAG,msgLastArgument);
if(msgLastArgument.toString().compare(config.getFldaTag()) == 0)
{
doFLDA(index,&msg);
}
return;
}
if(msgFirstArgument.toString().compare(config.getFlstTag()) == 0 ) // Filetransfer Start
{
msg.getArgument(PROTOCOL_FLST_ENDFLAG,msgLastArgument);
if(msgLastArgument.toString().compare(config.getFlstTag()) == 0)
{
doFLST(&msg);
}
return;
}
if(msgFirstArgument.toString().compare(config.getFlfiTag()) == 0 ) // Filetransfer Stop
{
msg.getArgument(PROTOCOL_FLFI_ENDFLAG,msgLastArgument);
if(msgLastArgument.toString().compare(config.getFlfiTag()) == 0)
{
doFLDA(index,&msg);
}
return;
}
if (msgFirstArgument.toString().compare(config.getFlerTag()) == 0 )
{
msg.getArgument(PROTOCOL_FLER_ENDFLAG,msgLastArgument);
if(msgLastArgument.toString().compare(config.getFlerTag()) == 0)
{
doFLER(&msg);
}
return;
}
// end of void function
}
void FiletransferPlugin::doFLST(QDltMsg *msg)
{
QDltArgument argument;
msg->getArgument(PROTOCOL_FLST_FILEID,argument);
File *file = new File(dltFile,0);
if ( file == NULL )
{
qDebug() << "Unable to create file object in " << __LINE__ << __FILE__;
return;
}
// set the attributes of the dynamic widget
file->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled );
file->setCheckState(COLUMN_CHECK, Qt::Unchecked);
msg->getArgument(PROTOCOL_FLST_FILEID,argument);
file->setFileSerialNumber(argument.toString());
msg->getArgument(PROTOCOL_FLST_FILENAME,argument);
file->setFilename(argument.toString());
msg->getArgument(PROTOCOL_FLST_FILEDATE,argument);
file->setFileCreationDate(argument.toString());
msg->getArgument(PROTOCOL_FLST_SIZE,argument);
file->setSizeInBytes(argument.toString());
msg->getArgument(PROTOCOL_FLST_PACKAGES,argument);
file->setPackages(argument.toString());
msg->getArgument(PROTOCOL_FLST_BUFFERSIZE,argument);
file->setBuffersize(argument.toString());
emit(form->additem_signal(file));
return;
}
void FiletransferPlugin::doFLDA(int index,QDltMsg *msg)
{
QDltArgument argument;
QDltArgument packageNumber;
msg->getArgument(PROTOCOL_FLDA_FILEID,argument);
msg->getArgument(PROTOCOL_FLDA_PACKAGENR,packageNumber);
emit(form->handleupdate_signal(argument.toString(),packageNumber.toString(), index ));
return;
}
void FiletransferPlugin::doFLIF(QDltMsg *msg)
{
Q_UNUSED(msg);
//empty.
//not implemented yet. Would handle extended file information: file serialnumber, name ,size, creation date, number of packages
}
void FiletransferPlugin::doFLER(QDltMsg *msg)
{
QDltArgument filename;
msg->getArgument(PROTOCOL_FLER_FILENAME,filename);
QDltArgument errorCode1;
msg->getArgument(PROTOCOL_FLER_ERRCODE1,errorCode1);
QDltArgument errorCode2;
msg->getArgument(PROTOCOL_FLER_ERRCODE2,errorCode2);
emit(form->handle_errorsignal(filename.toString(),errorCode1.toString(),errorCode2.toString(),msg->getTimeString()));
}
bool FiletransferPlugin::command(QString command, QList<QString> params)
{
if(!dltFile)
{
qDebug()<< "FiletransferPlugin not active !";
return false;
}
if(command.compare("export", Qt::CaseInsensitive) == 0)
{
if(params.length() != 1)
{
errorText = "Need one parameter, path to save to.";
return false;
}
QString exp_path = params.at(0);
QChar backslash('\"');
if ( exp_path.at(exp_path.length()-1) == backslash )
{
exp_path.chop(1);//remove the last \", which would cause problems under windows
}
QDir extract_dir(QDir::fromNativeSeparators ( exp_path ));
if(false == extract_dir.exists())
{
if (!extract_dir.mkpath("."))
{
errorText = "Failed to create directory " + params.at(0);
return false;
}
}
else
{
qDebug() << "Created" << params.at(0);
}
return exportAll(extract_dir);
}
errorText = "Unknown command " + command;
return false;
}
bool FiletransferPlugin::exportAll(QDir extract_dir)
{
bool ret = true;
QApplication::processEvents();
emit(form->export_signal(extract_dir,&errorText, &ret));
return ret;
}
/* Control Plugin methods */
// these are only needed to get information about silent mode via
// dltcontrol
bool FiletransferPlugin::initControl(QDltControl *control)
{
dltControl = control;
return true;
}
bool FiletransferPlugin::initConnections(QStringList list)
{
Q_UNUSED(list);
return true;
}
bool FiletransferPlugin::controlMsg(int , QDltMsg &)
{
return true;
}
bool FiletransferPlugin::stateChanged(int index, QDltConnection::QDltConnectionState connectionState,QString hostname)
{
Q_UNUSED(index);
Q_UNUSED(connectionState);
Q_UNUSED(hostname);
return true;
}
bool FiletransferPlugin::autoscrollStateChanged(bool enabled)
{
Q_UNUSED(enabled);
return true;
}
void FiletransferPlugin::initMessageDecoder(QDltMessageDecoder* pMessageDecoder)
{
Q_UNUSED(pMessageDecoder);
}
void FiletransferPlugin::initMainTableView(QTableView* pTableView)
{
Q_UNUSED(pTableView);
}
void FiletransferPlugin::configurationChanged()
{}
#ifndef QT5
Q_EXPORT_PLUGIN2(filetransferplugin, FiletransferPlugin)
#endif
|