-
Notifications
You must be signed in to change notification settings - Fork 0
/
displaybase.cpp
60 lines (44 loc) · 2.12 KB
/
displaybase.cpp
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
#include "displaybase.h"
DisplayBase::DisplayBase(QObject *parent,Configuration* config) :
QObject(parent)
{
this->config = config;
}
DisplayBase* createDisplay(QObject *parent,Configuration *config){
return new DisplayBase(parent,config);
};
void DisplayBase::newPacket(DecoderBase* decoder){
QByteArray displayResult;
QString display = config->get("_setup_","display","raw");
if(display == "list"){
QByteArray display_sep = QByteArray::fromPercentEncoding(
config->get("_setup_","display_sep",",").toAscii()
);
int display_skip_transparent = config->get("_setup_","display_skip_transparent","0").toInt();
QList<QVariant> packetValues = decoder->getPacketValues();
QList<QByteArray> packetParts = decoder->getPacketParts();
bool first = true;
for(int i=0; i < MIN(config->fields.length(),packetValues.length()); i++){
QString field = config->fields[i];
QByteArray format = config->get(field,"format","%f").toAscii();
int precision = config->get(field,"precision","6").toInt();
if(!display_skip_transparent || config->get(field,"color") != "transparent"){
if(!first) displayResult += QString(display_sep);
QByteArray v = format;
v.replace(QByteArray("%g"),QByteArray::number(packetValues[i].toDouble(),'g',precision));
v.replace(QByteArray("%f"),QByteArray::number(packetValues[i].toDouble(),'f',precision));
v.replace(QByteArray("%d"),QByteArray::number(packetValues[i].toInt(),'f',0));
v.replace(QByteArray("%n"),field.toAscii());
v.replace(QByteArray("%s"),packetParts[i]);
v.replace(QByteArray("%x"),packetParts[i].toHex());
displayResult += v;
first = false;
}
}
emit newDisplay(displayResult);
}else if(display == "hex"){
emit newDisplay(decoder->getPacketBytes().toHex());
}else{
emit newDisplay(decoder->getPacketBytes());
}
}