File: dltsegmentationplugin.cpp

package info (click to toggle)
dlt-viewer 2.28.1-dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,524 kB
  • sloc: cpp: 31,907; ansic: 4,231; xml: 492; sh: 244; makefile: 81
file content (236 lines) | stat: -rw-r--r-- 5,738 bytes parent folder | download | duplicates (3)
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
/**
 * @licence app begin@
 * Copyright (C) 2023  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 dltsegmentationplugin.cpp
 * For further information see http://www.covesa.global/.
 * @licence end@
 */

#include <QtGui>

#include "dltsegmentationplugin.h"

DltSegmentationPlugin::DltSegmentationPlugin()
{
}

DltSegmentationPlugin::~DltSegmentationPlugin()
{

}

QString DltSegmentationPlugin::name()
{
    return QString("DLT Segmentation Plugin");
}

QString DltSegmentationPlugin::pluginVersion(){
    return DLT_SEGMENTATION_PLUGIN_VERSION;
}

QString DltSegmentationPlugin::pluginInterfaceVersion(){
    return PLUGIN_INTERFACE_VERSION;
}

QString DltSegmentationPlugin::description()
{
    return QString();
}

QString DltSegmentationPlugin::error()
{
    return QString();
}

bool DltSegmentationPlugin::loadConfig(QString /* filename */ )
{
    return true;
}

bool DltSegmentationPlugin::saveConfig(QString /* filename */)
{
    return true;
}

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

QWidget* DltSegmentationPlugin::initViewer()
{
    form = new DltSegmantationPlugin::Form();
    return form;
}

void DltSegmentationPlugin::selectedIdxMsg(int index, QDltMsg &/*msg*/) {
    Q_UNUSED(index)
    if(!dltFile)
        return;
}

void DltSegmentationPlugin::selectedIdxMsgDecoded(int , QDltMsg &/*msg*/){

}

void DltSegmentationPlugin::initFileStart(QDltFile *file){
if(nullptr == file)
        return;

    dltFile = file;

    segmentedMessages.clear();
}

void DltSegmentationPlugin::initMsg(int index, QDltMsg &msg){
    if(nullptr == dltFile)
         return;

    if(msg.getWithSegementation())
    {
        // add msg to
        segmentedMessages.append(index);
    }

}

void DltSegmentationPlugin::initMsgDecoded(int , QDltMsg &){
    if(nullptr == dltFile)
         return;
}

void DltSegmentationPlugin::initFileFinish(){
   if(nullptr == dltFile)
        return;
}

void DltSegmentationPlugin::updateFileStart(){
    if(nullptr == dltFile)
         return;
}

void DltSegmentationPlugin::updateMsg(int index, QDltMsg &msg){
    if(!dltFile)
        return;

    if(msg.getWithSegementation())
    {
        // add msg to
        segmentedMessages.append(index);
    }
}

void DltSegmentationPlugin::updateMsgDecoded(int index, QDltMsg &msg){
    Q_UNUSED(index)
    Q_UNUSED(msg)
    if(nullptr == dltFile)
         return;
}

void DltSegmentationPlugin::updateFileFinish(){
   if(nullptr == dltFile)
        return;
}

bool DltSegmentationPlugin::isMsg(QDltMsg & msg, int triggeredByUser)
{
    Q_UNUSED(msg);
    Q_UNUSED(triggeredByUser);

    if(msg.getWithSegementation())
    {
        if(msg.getSegmentationFrameType()==2)
        {
            // last Frame
            return true;
        }
    }

    return false;
}

bool DltSegmentationPlugin::decodeMsg(QDltMsg &msg, int triggeredByUser)
{
    Q_UNUSED(triggeredByUser);

    if(nullptr == dltFile)
         return false;

    if(msg.getWithSegementation())
    {
        if(msg.getSegmentationFrameType()==2)
        {
            // find position in array
            int index = msg.getIndex();
            QString appId = msg.getApid();
            QString ctxId = msg.getCtid();
            int lastIndex = segmentedMessages.indexOf(index);
            QByteArray payload = msg.getPayload();
            int consecutiveFrame=-1;

            // go back now to find chunks before with same app id and ctx id and descending consecutive frame
            for(int num=lastIndex-1;num>=0;num--)
            {
                QDltMsg msgChunk;
                dltFile->getMsg(segmentedMessages[num],msgChunk);
                if(msgChunk.getApid()==appId && msgChunk.getCtid()==ctxId)
                {
                    if(msgChunk.getSegmentationFrameType()==1)
                    {
                        payload.insert(0,msgChunk.getPayload());
                        if(consecutiveFrame==-1)
                        {
                            consecutiveFrame = msgChunk.getSegmentationConsecutiveFrame();
                        }
                        else if((consecutiveFrame-1) == msgChunk.getSegmentationConsecutiveFrame())
                        {
                            consecutiveFrame = msgChunk.getSegmentationConsecutiveFrame();
                        }
                        else
                        {
                            // wrong order of chunks
                            return false;
                        }
                    }
                    else if(msgChunk.getSegmentationFrameType()==0 && consecutiveFrame== 0)
                    {
                        payload.insert(0,msgChunk.getPayload());

                        if(msgChunk.getSegmentationTotalLength()==payload.length())
                        {
                            msg.setPayload(payload);
                            msg.parseArguments();
                            return true;
                        }
                        else
                        {
                            // wrong length of payload
                            return false;
                        }
                    }

                }
            }

            return false;
        }
    }

    return false;
}

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Q_EXPORT_PLUGIN2(dltsegmentationplugin, DltSegmentationPlugin);
#endif