Пример #1
0
/*
=======================================
    UDPv4 接收线程
=======================================
*/
CR_API uint_t STDCALL
qst_udpv4_main (
  __CR_IN__ void_t* parm
    )
{
    sQstComm*   ctx = (sQstComm*)parm;

    /* 工作循环 */
    while (!ctx->comm.quit)
    {
        ansi_t  data[65536];

        /* 一个个封包读 */
        ctx->size = socket_udp_recv(ctx->comm.obj.netw, data, sizeof(data));
        if (ctx->size == 0 || ctx->size > sizeof(data)) {
            thread_sleep(20);
            continue;
        }

        /* 文本模式处理 */
        if (ctx->comm.text)
            ctx->size = qst_txt_mode(data, ctx->size);

        /* 渲染读到的内容 */
        _ENTER_COM_SINGLE_
        ctx->comm.render(parm, data, ctx->size);
        _LEAVE_COM_SINGLE_
    }

    /* 退出时关闭套接字 */
    socket_close(ctx->comm.obj.netw);
    return (QST_OKAY);
}
Пример #2
0
/*
=======================================
    RS232 接收线程
=======================================
*/
CR_API uint_t STDCALL
qst_rs232_main (
  __CR_IN__ void_t* parm
    )
{
    sQstComm*   ctx = (sQstComm*)parm;

    /* 工作循环 */
    while (!ctx->comm.quit)
    {
        uint_t  back;
        ansi_t  cha, *data;

        /* 一个个字节读 */
        back = sio_read(ctx->comm.obj.port, &cha, 1);
        if (back == 1) {
            if (CR_VCALL(ctx->bufs)->putb_no(ctx->bufs, cha))
                ctx->size += 1;
            continue;
        }
        if (back != 0) {
            thread_sleep(20);
            continue;
        }

        /* 文本模式处理 */
        if (ctx->size == 0)
            continue;
        data = (ansi_t*)(CR_VCALL(ctx->bufs)->flush(ctx->bufs));
        if (ctx->comm.text)
            ctx->size = qst_txt_mode(data, ctx->size);

        /* 渲染读到的内容 */
        _ENTER_COM_SINGLE_
        ctx->comm.render(parm, data, ctx->size);
        _LEAVE_COM_SINGLE_

        /* 缓存指针复位 */
        CR_VCALL(ctx->bufs)->reput(ctx->bufs, 0);
        ctx->size = 0;
    }

    /* 退出时关闭串口 */
    sio_close(ctx->comm.obj.port);
    return (QST_OKAY);
}