File: speedplugin.cpp

package info (click to toggle)
dlt-viewer 2.23.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,432 kB
  • sloc: cpp: 27,832; ansic: 4,454; xml: 491; sh: 154; makefile: 75
file content (311 lines) | stat: -rw-r--r-- 8,233 bytes parent folder | download
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
/**
 * @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/.
 *
 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011,2012
 *         Gernot Wirschal  <Gernot.Wirschal@bmw.de> BMW 2018
 *
 * \file speedplugin.cpp
 * For further information see http://www.covesa.global/.
 * @licence end@
 */

/*
 *  Last build with QT5.8, QWT 6.1.3 for Windows
*/

#include <QtGui>
#include "speedplugin.h"

SpeedPlugin::SpeedPlugin()
{
    //qDebug() << "SpeedPlugin::SpeedPlugin" << __LINE__ << __FILE__;
    form = NULL;
    dltFile = NULL;
    msgIndex = 0;
}

SpeedPlugin::~SpeedPlugin()
{
}

QString SpeedPlugin::name()
{
    return QString("Speed Plugin");
}

/*
The plugin has to return a version number in the format X.Y.Z.
• X should count up in case of really heavy changes (API changes or purpose changes)
• Y should count up when the module is reworked internally, functions are added etc
• Z should count up whenever a bug is fixed
Recommendation: #define <plugin name>_PLUGIN_VERSION "X.Y.Z" in your plugin header
file.*/
QString SpeedPlugin::pluginVersion()
{
    //qDebug() << "SpeedPlugin::pluginVersion" << __LINE__ << __FILE__;
    return SPEEDPLUGINVERSION;
}

/* The plugin has to return a version number of the used plugin interface. The plugin interface provides
the PLUGIN_INTERFACE_VERSION definition for this purpose.*/
QString SpeedPlugin::pluginInterfaceVersion()
{
    return PLUGIN_INTERFACE_VERSION;
}

QString SpeedPlugin::description()
{
    return QString("Shows up something");
}


/* The plugin can provide an error message for the last failed function call. In some cases the DLT Viewer
can display this message to the user. You can also just return an empty QString if you don’t care about
this.*/
QString SpeedPlugin::error()
{
    return QString();
}

/* The plugin can use configuration stored in files. This can be a single file or a directory containing several
files. This function is called whenever a new file gets loaded.*/
bool SpeedPlugin::loadConfig(QString filename)
{
    Q_UNUSED(filename);
    //qDebug() << "SpeedPlugin::loadConfig" << __LINE__ << __FILE__;
    return true;
}



/* Currently not used by DLT Viewer.*/
bool SpeedPlugin::saveConfig(QString /* filename */)
{
    return true;
}

QStringList SpeedPlugin::infoConfig()
{
    return QStringList();
}


/* Called when loading the plugin. The created widget must be returned.*/
QWidget* SpeedPlugin::initViewer()
{
    //qDebug() << "SpeedPlugin::initViewer" << __LINE__ << __FILE__;
    form = new Form();
    return form;
}


/*
An undecoded log message was selected in the message table. The Viewer plugin can now show additional
information about this message.
*/
void SpeedPlugin::selectedIdxMsg(int index, QDltMsg &msg)
{
  Q_UNUSED(index);
  //qDebug() << "SpeedPlugin::selectedIdxMsg" << __LINE__ << __FILE__;
  QDltArgument argument;
  if( (msg.getApid().compare("SPEE") == 0) && (msg.getCtid().compare("SIG") == 0))
      {
          if(msg.getArgument(1,argument))
          {
           form->setSpeedLCD(argument,msg.getTimestamp());
          }
      }
}


/*
A decoded log message was selected in the message table. The Viewer plugin can now show additional
information about this message.
*/
void SpeedPlugin::selectedIdxMsgDecoded(int , QDltMsg &/*msg*/)
{

}


/*
This function is called every time a new log file is opened by the Viewer, or a new log file is created, and
before any messages are processed with initMsg() and initMsgDecoded().
*/
void SpeedPlugin::initFileStart(QDltFile *file)
{
    //qDebug() << "SpeedPlugin::initFileStart with " << file->getFileName() << __LINE__ << __FILE__;
    dltFile = file;
}

/*
This function is called every time a new undecoded message is being processed when loading or creating
a new log file.
*/
void SpeedPlugin::initMsg(int index, QDltMsg &msg)
{
 Q_UNUSED(msg);
 Q_UNUSED(index);
 //qDebug() << "SpeedPlugin::initMsg" << __LINE__ << __FILE__;
}


/* This function is called every time a new decoded message is being processed when loading or creating a
new log file.*/
void SpeedPlugin::initMsgDecoded(int , QDltMsg &)
{
//empty. Implemented because derived plugin interface functions are virtual.
}


/*
This function is called after a log file was opened by the Viewer, or a new log file was created, and after
all messages were processed with initMsg() and initMsgDecoded().
*/
void SpeedPlugin::initFileFinish()
{
  //qDebug() << "SpeedPlugin::initFileFinish" << __LINE__ << __FILE__;
    if(NULL == dltFile)
    {
        qDebug() << "no dltFile in" << __LINE__ << __FILE__;
        return;
    }

QByteArray buffer;
QDltMsg msg;
QDltArgument argument;
for(;msgIndex<dltFile->size();msgIndex++)
{

   buffer =  dltFile->getMsg(msgIndex);

   if(buffer.isEmpty())
       break;

   msg.setMsg(buffer);

    if( (msg.getApid().compare("SPEE") == 0) && (msg.getCtid().compare("SIG") == 0))
    {
        if(msg.getArgument(1,argument))
        {
          form->setSpeedLCD(argument,msg.getTimestamp());
          form->setSpeedGraph(argument,msg.getTimestamp());
        }

    }
 }
}


/* This function is called every time a new undecoded message was received by the Viewer. */
void SpeedPlugin::updateMsg(int index, QDltMsg &msg)
{
    Q_UNUSED(index);
    //qDebug() << "SpeedPlugin::updateMsg" << __LINE__ << __FILE__<< index;
    
    QDltArgument argument;

    if( (msg.getApid().compare("SPEE") == 0) && (msg.getCtid().compare("SIG") == 0))
        {
            if(true == msg.getArgument(1,argument))
            {
                //qDebug() << msg.getArgument(1,argument) << argument.toString();
                form->setSpeedLCD(argument,msg.getTimestamp());
                form->setSpeedGraph(argument,msg.getTimestamp());
                /*
                // just some example for seinding a message injection
                QString value = argument.toString();
                if (value.toInt() == 20)
                {
                    QString data = QString("%1").arg(index);
                    qDebug() << "Send injection with" << data << "at" << value;
                    dltControl->sendInjection(0,"SPEE","SIG",4098,data.toLatin1());
                }
                */
           }
        }
}


/* This function is called every time a new message was received by the Viewer and before the message is
processed with updateMsg() and updateMsgDecoded().*/
void SpeedPlugin::updateFileStart()
{
 //qDebug() << "updateFileStart" <<__LINE__ << __FILE__;
}

/* This function is called every time a new decoded message was received by the Viewer.*/
void SpeedPlugin::updateMsgDecoded(int , QDltMsg &)
{
//empty. Implemented because derived plugin interface functions are virtual.
}


/* This function is called every time a new message was received by the Viewer and after the message was
processed with updateMsg() and updateMsgDecoded().*/
void SpeedPlugin::updateFileFinish()
{
  //qDebug() << "SpeedPlugin::updateFileFinish" <<__LINE__ << __FILE__;
}

/* QDltPluginControlInterface */
bool SpeedPlugin::initControl(QDltControl *control)
{
   dltControl = control;
return true;
}

bool SpeedPlugin::initConnections(QStringList list)
{
return true;
}

bool SpeedPlugin::controlMsg(int index, QDltMsg &msg)
{
Q_UNUSED(index);
Q_UNUSED(msg);
return true;
}

bool SpeedPlugin::stateChanged(int index, QDltConnection::QDltConnectionState connectionState, QString hostname)
{
Q_UNUSED(index);
Q_UNUSED(connectionState);
return true;
}

bool SpeedPlugin::autoscrollStateChanged(bool enabled)
{
Q_UNUSED(enabled);
return true;
}

void SpeedPlugin::initMessageDecoder(QDltMessageDecoder* pMessageDecoder)
{
Q_UNUSED(pMessageDecoder);
}

void SpeedPlugin::initMainTableView(QTableView* pTableView)
{
 Q_UNUSED(pTableView);
}

void SpeedPlugin::configurationChanged()
{

}

#ifndef QT5
Q_EXPORT_PLUGIN2(speedplugin, SpeedPlugin);
#endif