Example #1
0
//sending next line from buffer
void Printer::send_next(){
    //if printer inst connected then return
    if(!this->isConnected()){
        return;
    }
    //resend commands
    if(this->resendFrom<this->lineNum && this->resendFrom>-1){
        writeToPort(this->sentLines.at(this->resendFrom),this->resendFrom,false);
        this->resendFrom++;
        return;
    }
    this->resendFrom=-1;
    //send all commands from pri query
    while(this->priQuery.size()>0){
        writeToPort(this->priQuery.takeFirst());
        return;
    }
    //if there are lines to send in main buffer
    if(this->isPrinting && this->mainQuery.size()>0){
        writeToPort(this->mainQuery.takeFirst(),this->lineNum,true);
        emit progress(this->mainQuery.size());
        this->lineNum++;
    }
    else{
        if(this->isPrinting){
            emit printFinished(true);
        }
        this->isPrinting=false;
    }
}
int GrandChildProcess::execute() {

    printStarted();

    std::ifstream in;
    in.open(m_fileName.c_str());
    if (!in.good()) {
        return 0;
    }

    FileRecord fr;

    // TODO: se hace la suma de las valorizaciones aqui o en ChildProcess?

    double totalSum = 0.0;

    std::string line;
    while(getline(in, line)) {
        //cout << "line:" << line << endl;
        _vstring parts = Utils::split(line, ';');
        if (validLine(parts, fr)) {
            if (fr.idTipoFondo == m_fundType) {
                // Process as RF
                if (m_isFixedRent) {
                    // Check if idTipoInstrumentoFinanciero matches with the
                    // required rentType
                    if (fr.m_rentType == "RF") {
                        double t =
                            fr.cantidad / (1.0 + (fr.tasa / 360.0) * fr.diasAlVencimiento / 100.0);
                        totalSum += t;
                    }
                }
                // Process as RV
                else {
                    // Check if idTipoInstrumentoFinanciero matches with the
                    // required rentType
                    if (fr.m_rentType == "RV") {
                        totalSum += (fr.cantidad * fr.precio);
                    }
                }
            }
        }
    }

    in.close();

    m_parentPipe.writeString(
        m_fundType +
        std::string(",") + (m_isFixedRent ? "RF" : "RV") +
        std::string(",") + Utils::double2string(totalSum)
    );

    m_parentPipe.closeAll();

    printFinished();

    return 0;
}
Example #3
0
//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"));
           }
        }
    }
}