Ejemplo n.º 1
0
bool spherebot::send(QString cmd)
{
    if(port->isOpen())
    {
        port->flush();
        lastSentLine.clear();
        lastSentLine.append(cmd);
        if(cmd.size() != 0)
        {
            if(cmd[cmd.size()-1] == '\n') cmd.chop(1);
        }
        cmd.append(" ");
        cmd.append(generateChecksumString(cmd));
        qDebug()<<"Sending: " + cmd;
        cmd.append("\n");
        port->write((const char*)cmd.toUtf8(),cmd.length());
    }
    else
    {
        qDebug()<<port->errorString()<<" port is not open";
        return false;
    }
    cmd.chop(1);
    emit dataSent(cmd);
    return true;
}
bool spherebot::send(QString cmd)
{
    if(port->isOpen())
    {
        while( lastLine.endsWith('\n')) lastLine.chop(1);

        cmd.append(" ");
        cmd.append(generateChecksumString(cmd));
        cmd.append("\n");

        if(bot_connected)
        {
            if(lastLineTransmitted)
            {
                qDebug()<<"Sending: " + cmd;
                port->write((const char*)cmd.toUtf8(),cmd.length());

                lastLine = cmd;
                lastLineTransmitted = false;
                timeout_timer->start();
            }
            else
            {
                toSendBuffer.push_back(cmd);
            }
        }
        else
        {
            toSendBuffer.push_back(cmd);
            qDebug()<<"Buffer: " << toSendBuffer<< endl;
            retry_timer->start();
        }
    }
    else
    {
        qDebug()<<port->errorString()<<" port is not open";
        return false;
    }
    return true;
}