-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecodercsv.cpp
More file actions
43 lines (34 loc) · 1.03 KB
/
decodercsv.cpp
File metadata and controls
43 lines (34 loc) · 1.03 KB
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
#include "decodercsv.h"
DecoderCsv::DecoderCsv(QObject *parent,Configuration* config) :
DecoderBase(parent,config)
{
}
void DecoderCsv::newData(const QByteArray& newBytes){
for(int i=0;i<newBytes.length();i++){
char c = newBytes[i];
if(13 == c || 10 == c){
packetSeparator();
}else{
if(packetStarted){
packetBytes.append(c);
if(packetBytes.length() > packetMaxLen){
packetBytes.clear(); //discard packet
packetStarted = false;
}
}
}
}
};
void DecoderCsv::packetSeparator(){
packetStarted = true;
if(!packetBytes.isEmpty()){
packetParts = packetBytes.split(',');
packetValues.clear();
QList<QByteArray>::iterator i;
for(i=packetParts.begin();i!=packetParts.end();i++){
packetValues.append((*i).toDouble());
}
emit newPacket(this);
}
packetBytes.clear();
};