//proper parsing of responce void Printer::processResponce(QString responce){ if(!this->connectionActive){ this->connectionActive=true; emit connected(true); } //add data to buffer inBuffer.append(responce); //send full responces to fifo if(inBuffer.contains("\n")){ responseBuffer.append(inBuffer.left(inBuffer.lastIndexOf("\n")+1).split("\n",QString::SkipEmptyParts)); } //clear buffer inBuffer.remove(0,inBuffer.lastIndexOf("\n")+1); //proccess all responces from fifo while(responseBuffer.size()>0){ QString lastResponse=responseBuffer.takeFirst(); emit write_to_console("Got responce: "+ lastResponse); //if its temp status if(lastResponse.contains("T:") || lastResponse.contains("B:")){ bool ok; double bed_temp = lastResponse.mid(lastResponse.indexOf("B:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("B:"))-lastResponse.indexOf("B:")-2).toDouble(&ok); if(ok){ last_bed_temp=bed_temp; } double head_temp = lastResponse.mid(lastResponse.indexOf("T:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("T:"))-lastResponse.indexOf("T:")-2).toDouble(&ok); if(ok){ last_head_temp=head_temp; } emit currentTemp(last_head_temp,0.0,last_bed_temp); } //if its response for position command //if we are printing then continue if(lastResponse.startsWith("ok")){ if(!this->isPaused){ emit clearToSend(); } } //if its error else if(lastResponse.startsWith("Error")){ } //resend line else if(lastResponse.toLower().startsWith("resend") || lastResponse.startsWith("rs")){ bool ok; int toResend; // toResend=QString::number(lastResponse.toLower().remove(QRegExp("[\\D]"))); toResend=lastResponse.toLower().remove(QRegExp("[\\D]")).toInt(&ok); if(ok){ this->resendFrom=toResend; } else{ write_to_console(tr("something is horribly wrong")); } } } }
//proper parsing of responce void Printer::processResponce(QString responce){ if(!this->connectionActive){ this->connectionActive=true; emit connected(true); } //add data to buffer inBuffer.append(responce); //send full responces to fifo if(inBuffer.contains("\n")){ responseBuffer.append(inBuffer.left(inBuffer.lastIndexOf("\n")+1).split("\n",QString::SkipEmptyParts)); } //clear buffer inBuffer.remove(0,inBuffer.lastIndexOf("\n")+1); //proccess all responces from fifo while(responseBuffer.size()>0){ QString lastResponse=responseBuffer.takeFirst(); emit write_to_console("Got responce: "+ lastResponse); //if its temp status if(lastResponse.contains("T:") || lastResponse.contains("B:")){ bool ok; double bed_temp = lastResponse.mid(lastResponse.indexOf("B:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("B:"))-lastResponse.indexOf("B:")-2).toDouble(&ok); if(ok){ last_bed_temp=bed_temp; } double head_temp = lastResponse.mid(lastResponse.indexOf("T:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("T:"))-lastResponse.indexOf("T:")-2).toDouble(&ok); if(ok){ last_head_temp=head_temp; } emit currentTemp(last_head_temp,0.0,last_bed_temp); } //if its something about sd card if(lastResponse.contains("Begin file list")){ this->sdFiles.clear(); this->updatingFileList=true; } if(this->updatingFileList){ this->sdFiles.append(lastResponse.toLower()); } if(lastResponse.contains("End file list")){ this->updatingFileList=false; this->sdFiles.removeFirst(); this->sdFiles.removeLast(); emit SDFileList(this->sdFiles); } if(lastResponse.contains("SD printing byte")){ QString prog=lastResponse.right(lastResponse.length()-lastResponse.lastIndexOf(" ")-1); QStringList values = prog.split("/"); emit progress(values.at(0).toInt(), values.at(1).toInt()); if(values.at(0).toInt()==values.at(1).toInt()){ emit printFinished(true); this->sdPrint=false; } } //if its response for position command //if we are printing then continue if(lastResponse.startsWith("ok")){ if(!this->isPaused){ emit clearToSend(); } } //if its error else if(lastResponse.startsWith("Error")){ } //resend line else if(lastResponse.toLower().startsWith("resend") || lastResponse.startsWith("rs")){ bool ok; int toResend; // toResend=QString::number(lastResponse.toLower().remove(QRegExp("[\\D]"))); toResend=lastResponse.toLower().remove(QRegExp("[\\D]")).toInt(&ok); if(ok){ this->resendFrom=toResend; if(!this->isPaused){ emit clearToSend(); } } else{ emit write_to_console(tr("something is horribly wrong")); } } } }