-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathparser.cpp
123 lines (106 loc) · 3.49 KB
/
parser.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
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
#include "parser.h"
Parser::Parser(QObject *parent):
QObject(parent)
{
//Init regexp
temperatureRegxp.setCaseSensitivity(Qt::CaseInsensitive);
temperatureRegxp.setPatternSyntax(QRegExp::RegExp);
temperatureRegxp.setPattern("\\d+\\.\\d+"); // Find float in string
//Init values
readingFiles = false;
readingEEPROM = false;
EEPROMReadingStarted = false;
//Load settings
QSettings settings;
firmware = settings.value("printer/firmware").toInt();
}
Parser::~Parser()
{
}
void Parser::parse(QByteArray data)
{
if(!data.isEmpty()) //Dont need to process empty strings
{
if(readingFiles) //SD files list reading mode
{
if(!data.contains("End file list")) SDFilesList.append(data.remove(data.size()-2, 2));
else
{
readingFiles = false;
emit receivedSDFilesList(SDFilesList);
}
return;
}
if(readingEEPROM) // EEPROM reading mode
{
if(firmware == Repetier)
{
if(data.startsWith("EPR"))
{
emit receivedEEPROMLine(QString(data));
EEPROMReadingStarted = true;
}
else if(EEPROMReadingStarted)
{
readingEEPROM = false;
EEPROMReadingStarted = false;
emit recievingEEPROMDone();
}
return;
}
}
/*
if(data.startsWith("ok"))
{
QStringList tmp = QString(data).split(' ');
if(tmp.size() > 1)
emit receivedOkNum(tmp.at(1).toInt());
else emit receivedOkNum(0);
}
*/
else if(data.contains("T:"))
{
TemperatureReadings r;
if(temperatureRegxp.indexIn(QString(data)) != -1)
r.e = temperatureRegxp.cap(0).toDouble();
else r.e = 0;
if(temperatureRegxp.indexIn(QString(data), temperatureRegxp.matchedLength()) != -1)
r.b = temperatureRegxp.cap(0).toDouble();
else r.b = 0;
r.raw = QString(data);
emit receivedTemperature(r);
}
//else if(data.startsWith("wait")) emit receivedOkWait();
else if(data.startsWith("rs") || data.toLower().startsWith("resend"))
emit receivedResend(data.split(':').at(1).toInt());
else if(data.startsWith("!!")) emit receivedError();
else if(data.startsWith("Done")) emit receivedSDDone();
else if(data.startsWith("start")) emit receivedStart();
else if(data.startsWith("SD pr"))
{
SDProgress p;
QRegExp rxp("\\d+/\\d+");
QStringList tmp;
if(rxp.indexIn(data) != -1)
{
tmp = rxp.cap(0).split('/');
p.progress = tmp.at(0).toLong();
p.total = tmp.at(1).toLong();
}
else return;
emit receivedSDUpdate(p);
}
else if(data.startsWith("Not SD ")) emit receivedNotSDPrinting();
else if(data.contains("Begin file list"))
{
SDFilesList.clear();
readingFiles = true; //start reading files from SD
}
//else if(data.contains("REPETIER")) emit receivedFirmware(Repetier);
//else if(data.contains("MARLIN")) emit receivedFirmware(Marlin);
}
}
void Parser::setEEPROMReadingMode()
{
readingEEPROM = true;
}