예제 #1
0
// Send treatment plan
void Server::sendPlan()
{
    QHostAddress ipAddress("172.168.0.116");
    m_tcpServer->connectToHost(ipAddress, 6666);

    QDataStream m_sendOut(&m_outBlock, QIODevice::WriteOnly);
    m_sendOut.setVersion(QDataStream::Qt_4_6);

    qDebug() << "Sending plan...";
    QString sendInfo = writeSendInfo();

    // Write data
    connect(m_tcpServer, SIGNAL(bytesWritten(qint64)), this, SLOT(writtenBytes(qint64)));    // Check if the data has been all well written

    m_sendOut << qint64(0)
              << qint64(0)
              << m_plan.coordinate.spotNum
              << m_plan.coordinate.spotPosX
              << m_plan.coordinate.spotPosY
              << m_plan.coordinate.spotPosZ
              << m_plan.parameter.coolingTime
              << m_plan.parameter.dutyCycle
              << m_plan.parameter.sonicationPeriod
              << m_plan.parameter.sonicationTime
              << sendInfo;

    qDebug() << "sendInfo:" << sendInfo;

    m_totalBytes = m_outBlock.size();
    qDebug() << "m_totalBytes:" << m_totalBytes;
    m_sendOut.device()->seek(0);
    m_sendOut << qint64(2) << m_totalBytes;    // Find the head of array and write the haed information

    m_tcpServer->write(m_outBlock);

    m_sendTimeNum += 1;
    m_writtenBytes = 0;
    m_outBlock.resize(0);

    qDebug() << "Send finished";

    // Read send-back data
    connect(m_tcpServer, SIGNAL(readyRead()), this, SLOT(readSendBack()));

    m_tcpServer->waitForReadyRead(3000);

    qDebug() << m_receivedInfo;

    // Check the consistency of the send-back data
    if(m_receivedInfo == sendInfo)
    {
        qDebug() << "Send-back checked.";
        m_receivedInfo = "";
    }
    else
    {
        emit error_sendBackCheck();
        qDebug() << "Check failed ! emit error signal...";
    }
}
예제 #2
0
/**
 * LZW main compress function
 * @param s LZW state
 * @param inbuf Input buffer
 * @param insize Size of input buffer
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode(LZWEncodeState *s, const uint8_t *inbuf, int insize)
{
    int i;

    if(insize * 3 > (s->bufsize - s->output_bytes) * 2)
    {
        return -1;
    }

    if (s->last_code == LZW_PREFIX_EMPTY)
        clearTable(s);

    for (i = 0; i < insize; i++)
    {
        uint8_t c = *inbuf++;
        int code = findCode(s, c, s->last_code);
        if (s->tab[code].hash_prefix == LZW_PREFIX_FREE)
        {
            writeCode(s, s->last_code);
            addCode(s, c, s->last_code, code);
            code = hash(0, c);
        }
        s->last_code = s->tab[code].code;
        if (s->tabsize >= s->maxcode - 1)
        {
            clearTable(s);
        }
    }

    return writtenBytes(s);
}
예제 #3
0
파일: lzwenc.c 프로젝트: apakian/rtmp-cpp
/**
 * Write end code and flush bitstream
 * @param s LZW state
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode_flush(LZWEncodeState * s)
{
    if (s->last_code != -1)
        writeCode(s, s->last_code);
    writeCode(s, s->end_code);
    flush_put_bits(&s->pb);
    s->last_code = -1;

    return writtenBytes(s);
}
예제 #4
0
/**
 * Write end code and flush bitstream
 * @param s LZW state
 * @return Number of bytes written or -1 on error
 */
int ff_lzw_encode_flush(LZWEncodeState *s,
                        void (*lzw_flush_put_bits)(PutBitContext *))
{
    if (s->last_code != -1)
        writeCode(s, s->last_code);
    writeCode(s, s->end_code);
    lzw_flush_put_bits(&s->pb);
    s->last_code = -1;

    return writtenBytes(s);
}