-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoderhdlc.cpp
More file actions
37 lines (32 loc) · 1.19 KB
/
decoderhdlc.cpp
File metadata and controls
37 lines (32 loc) · 1.19 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
#include "decoderhdlc.h"
DecoderHdlc::DecoderHdlc(QObject *parent,Configuration *config) :
DecoderBin(parent,config)
{
hdlc_esc = QByteArray::fromHex(config->get("_setup_","hdlc_esc","7d").toAscii())[0];
hdlc_sep = QByteArray::fromHex(config->get("_setup_","hdlc_sep","7e").toAscii())[0];
hdlc_xor = QByteArray::fromHex(config->get("_setup_","hdlc_xor","20").toAscii())[0];
escapeFlag = false;
}
void DecoderHdlc::newData(const QByteArray& newBytes){
//qDebug(newBytes.toHex());
for(int i=0;i<newBytes.length();i++){
char c = newBytes[i];
if(c == hdlc_sep){
packetSeparator();
}else{
if(packetStarted){
if(c == hdlc_esc && !escapeFlag){
escapeFlag = true;
}else{
if(escapeFlag) c = c ^ hdlc_xor;
escapeFlag = false;
packetBytes.append(c);
if(packetBytes.length() > packetMaxLen){
packetBytes.clear(); //discard packet
packetStarted = false;
}
}
}
}
}
};