コード例 #1
0
ファイル: cli_serial.cpp プロジェクト: BOBRAPHTONE/openthread
void Serial::ReceiveTask(void)
{
    uint16_t bufLength;
    const uint8_t *buf;
    const uint8_t *end;

    buf = otPlatSerialGetReceivedBytes(&bufLength);
    end = buf + bufLength;

    for (; buf < end; buf++)
    {
        switch (*buf)
        {
        case '\r':
        case '\n':
            otPlatSerialSend(CRNL, sizeof(CRNL));

            if (mRxLength > 0)
            {
                mRxBuffer[mRxLength] = '\0';
                ProcessCommand();
            }

            break;

        case '\b':
        case 127:
            otPlatSerialSend(sEraseString, sizeof(sEraseString));

            if (mRxLength > 0)
            {
                mRxBuffer[--mRxLength] = '\0';
            }

            break;

        default:
            otPlatSerialSend(buf, 1);
            mRxBuffer[mRxLength++] = *buf;
            break;
        }
    }

    otPlatSerialHandleReceiveDone();
}
コード例 #2
0
void Serial::ReceiveTask(void)
{
    uint16_t bufLength;
    const uint8_t *buf;
    const uint8_t *cur;
    const uint8_t *end;

    buf = otPlatSerialGetReceivedBytes(&bufLength);

    end = buf + bufLength;

    for (cur = buf; cur < end; cur++)
    {
        switch (*cur)
        {
        case '\r':
	case '\n':
            otPlatSerialSend(CRNL, sizeof(CRNL));
            break;

        default:
            otPlatSerialSend(cur, 1);
            break;
        }
    }

    while (bufLength > 0 && mRxLength < kRxBufferSize)
    {
        switch (*buf)
        {
        case '\r':
        case '\n':
            if (mRxLength > 0)
            {
                mRxBuffer[mRxLength] = '\0';
                ProcessCommand();
            }

            break;

        case '\b':
        case 127:
            if (mRxLength > 0)
            {
                mRxBuffer[--mRxLength] = '\0';
                otPlatSerialSend(sEraseString, sizeof(sEraseString));
            }

            break;

        default:
            mRxBuffer[mRxLength++] = *buf;
            break;
        }

        buf++;
        bufLength--;
    }

    otPlatSerialHandleReceiveDone();
}
コード例 #3
0
ThreadError Serial::Output(const char *aBuf, uint16_t aBufLength)
{
    return otPlatSerialSend(reinterpret_cast<const uint8_t *>(aBuf), aBufLength);
}