Exemple #1
0
static int  ICACHE_FLASH_ATTR ws_app_msg_received(http_connection *c){

	NODE_DBG("Webscoket app msg received %p",c);

	struct ws_app_context *context = (struct ws_app_context*)c->reverse;

	ws_frame *msg = (ws_frame *)c->cgi.argument;
	if(msg==NULL)
		return HTTP_WS_CGI_MORE; //just ignore and move on

	if(msg->SIZE <=0)
		return HTTP_WS_CGI_MORE; //just ignore and move on

	char * s = msg->DATA;
	char *last = s+msg->SIZE;

    //os_printf("%.*s", msg->SIZE, msg->DATA);
    #ifdef DEVELOP_VERSION
        uart_write(UART0, msg->DATA,msg->SIZE);
    #endif
    
    hdlc_tx_frame( msg->DATA, msg->SIZE);
	
    return HTTP_WS_CGI_MORE;

}
void hdlc_test(void)
{
    u8_t data;

    // Enable RS-485 PIO for loopback operation
    BIT_SET_HI(PORT_RS485_TX_EN_O, BIT_RS485_TX_EN_O);
    BIT_SET_HI(DDR_RS485_TX_EN_O, BIT_RS485_TX_EN_O);

    BIT_SET_LO(PORT_RS485_RX_EN_O, BIT_RS485_RX_EN_O);
    BIT_SET_HI(DDR_RS485_RX_EN_O, BIT_RS485_RX_EN_O);

    // Initialise modules
    uart0_init();
    uart1_init();
    printf_init();
    hdlc_init(&hdlc_on_rx_frame);

    // Enable global interrupts
    sei();
        
    // Send an HDLC packet
    data = 0x55;
    hdlc_tx_frame(&data,1);

    // Process received data
    for(;;)
    {
        if(uart1_get_rx_byte(&data))
        {
            PRINTF("%02X ", data);
            // Feed received data to HDLC layer
            hdlc_on_rx_byte(data);
        }
    }
}
Exemple #3
0
SPAN_DECLARE_NONSTD(void) fax_modems_hdlc_tx_frame(void *user_data, const uint8_t *msg, int len)
{
    fax_modems_state_t *s;

    s = (fax_modems_state_t *) user_data;

    hdlc_tx_frame(&s->hdlc_tx, msg, len);
}
Exemple #4
0
static void fax_send_hdlc(void *user_data, const uint8_t *msg, int len)
{
    fax_state_t *s;

    s = (fax_state_t *) user_data;
    
    hdlc_tx_frame(&s->modems.hdlc_tx, msg, len);
}
Exemple #5
0
static void fax_send_hdlc(void *user_data, const uint8_t *msg, int len)
{
    fax_state_t *s;

    s = (fax_state_t *) user_data;
    
    hdlc_tx_frame(&(s->hdlctx), msg, len);
    s->first_tx_hdlc_frame = FALSE;
}
Exemple #6
0
static int test_hdlc_octet_count_handling(void)
{
    int i;
    int j;
    int nextbyte;

    printf("Testing the octet_counting handling using CRC-16 (bit by bit)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 2, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, TRUE, 0, frame_handler, NULL);
    //hdlc_rx_set_max_frame_len(&rx, 50);
    hdlc_rx_set_octet_counting_report_interval(&rx, 16);
    underflow_reported = FALSE;
    framing_ok_reported = FALSE;
    framing_ok_reports = 0;

    hdlc_tx_flags(&tx, 10);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 0;
    for (i = 0;  i < 8*1000000;  i++)
    {
        nextbyte = hdlc_tx_get_bit(&tx);
        hdlc_rx_put_bit(&rx, nextbyte);
        if (framing_ok_reported)
        {
            printf("Framing OK reported at bit %d (%d)\n", i, framing_ok_reports);
            framing_ok_reported = FALSE;
        }
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            for (j = 0;  j < 20;  j++)
            {
                nextbyte = hdlc_tx_get_bit(&tx);
                hdlc_rx_put_bit(&rx, nextbyte);
                if (framing_ok_reported)
                {
                    printf("Framing OK reported at bit %d (%d) - %d\n", i, framing_ok_reports, frame_handled);
                    framing_ok_reported = FALSE;
                }
            }
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                if (frame_failed)
                    printf("Frame failed.\n");
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            hdlc_tx_abort(&tx);
            //hdlc_tx_corrupt_frame(&tx);
            frame_handled = FALSE;
        }
    }

    printf("Tests passed.\n");
    return 0;
}
Exemple #7
0
static int test_hdlc_crc_error_handling(void)
{
    int i;
    int j;
    int nextbyte;
    int corrupt;

    printf("Testing CRC error handling using CRC-16 (bit by bit)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 2, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, TRUE, 5, frame_handler, NULL);
    underflow_reported = FALSE;
    framing_ok_reported = FALSE;
    framing_ok_reports = 0;

    hdlc_tx_flags(&tx, 10);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 100;
    corrupt = FALSE;
    for (i = 0;  i < 8*1000000;  i++)
    {
        nextbyte = hdlc_tx_get_bit(&tx);
        hdlc_rx_put_bit(&rx, nextbyte);
        if (framing_ok_reported)
        {
            printf("Framing OK reported at bit %d (%d)\n", i, framing_ok_reports);
            framing_ok_reported = FALSE;
        }
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            for (j = 0;  j < 20;  j++)
            {
                nextbyte = hdlc_tx_get_bit(&tx);
                hdlc_rx_put_bit(&rx, nextbyte);
                if (framing_ok_reported)
                {
                    printf("Framing OK reported at bit %d (%d) - %d\n", i, framing_ok_reports, frame_handled);
                    framing_ok_reported = FALSE;
                }
            }
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                if (!corrupt)
                {
                    printf("Frame not received when it should be correct.\n");
                    return -1;
                }
            }
            else
            {
                if (corrupt)
                {
                    printf("Frame received when it should be corrupt.\n");
                    return -1;
                }
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            if ((corrupt = rand() & 1))
                hdlc_tx_corrupt_frame(&tx);
            frame_handled = FALSE;
        }
    }

    printf("Tests passed.\n");
    return 0;
}
Exemple #8
0
static int test_hdlc_frame_length_error_handling(void)
{
    int i;
    int j;
    int nextbyte;

    printf("Testing frame length error handling using CRC-16 (bit by bit)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 2, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, TRUE, 5, frame_handler, NULL);
    hdlc_rx_set_max_frame_len(&rx, 100);
    underflow_reported = FALSE;
    framing_ok_reported = FALSE;
    framing_ok_reports = 0;

    hdlc_tx_flags(&tx, 10);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 0;
    for (i = 0;  i < 8*1000000;  i++)
    {
        nextbyte = hdlc_tx_get_bit(&tx);
        hdlc_rx_put_bit(&rx, nextbyte);
        if (framing_ok_reported)
        {
            printf("Framing OK reported at bit %d (%d)\n", i, framing_ok_reports);
            framing_ok_reported = FALSE;
        }
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            for (j = 0;  j < 20;  j++)
            {
                nextbyte = hdlc_tx_get_bit(&tx);
                hdlc_rx_put_bit(&rx, nextbyte);
                if (framing_ok_reported)
                {
                    printf("Framing OK reported at bit %d (%d) - %d\n", i, framing_ok_reports, frame_handled);
                    framing_ok_reported = FALSE;
                }
            }
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                /* We should get a failure when the length reaches 101 */
                if (ref_len == 101)
                {
                    printf("Tests passed.\n");
                    return 0;
                }
                if (frame_failed)
                    printf("Frame failed.\n");
                printf("Frame not received at length %d.\n", ref_len);
                return -1;
            }
            else
            {
                /* We should get a failure when the length reaches 101 */
                if (ref_len > 100)
                {
                    printf("Tests failed.\n");
                    return -1;
                }
            }
            ref_len++;
            hdlc_tx_frame(&tx, buf, ref_len);
            frame_handled = FALSE;
        }
    }
    /* We shouldn't reach here */
    printf("Tests failed.\n");
    return -1;
}
Exemple #9
0
static int test_hdlc_modes(void)
{
    int i;
    int j;
    int len;
    int nextbyte;
    int progress;
    int progress_delay;
    uint8_t bufx[100];

    /* Try sending HDLC messages with CRC-16 */
    printf("Testing with CRC-16 (byte by byte)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 1, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, FALSE, 5, frame_handler, NULL);
    underflow_reported = FALSE;

    start = rdtscll();
    hdlc_tx_flags(&tx, 40);
    /* Push an initial message so we should NOT get an underflow after the preamble. */
    ref_len = cook_up_msg(buf);
    hdlc_tx_frame(&tx, buf, ref_len);
    frame_handled = FALSE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    for (i = 0;  i < 1000000;  i++)
    {
        nextbyte = hdlc_tx_get_byte(&tx);
        hdlc_rx_put_byte(&rx, nextbyte);
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            nextbyte = hdlc_tx_get_byte(&tx);
            hdlc_rx_put_byte(&rx, nextbyte);
            frames_sent++;
            bytes_sent += ref_len;
            if (!frame_handled)
            {
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            frame_handled = FALSE;
        }
    }
    end = rdtscll();
    check_result();

    /* Now try sending HDLC messages with CRC-16 */
    printf("Testing with CRC-16 (chunk by chunk)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 1, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, FALSE, 5, frame_handler, NULL);
    underflow_reported = FALSE;

    start = rdtscll();
    hdlc_tx_flags(&tx, 40);
    /* Push an initial message so we should NOT get an underflow after the preamble. */
    ref_len = cook_up_msg(buf);
    hdlc_tx_frame(&tx, buf, ref_len);
    frame_handled = FALSE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    for (i = 0;  i < 10000;  i++)
    {
        len = hdlc_tx_get(&tx, bufx, 100);
        hdlc_rx_put(&rx, bufx, len);
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            len = hdlc_tx_get(&tx, bufx, 100);
            hdlc_rx_put(&rx, bufx, len);
            frames_sent++;
            bytes_sent += ref_len;
            if (!frame_handled)
            {
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            frame_handled = FALSE;
        }
    }
    end = rdtscll();
    check_result();

    /* Now try sending HDLC messages with CRC-16 bit by bit */
    printf("Testing with CRC-16 (bit by bit)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, FALSE, 2, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, FALSE, FALSE, 5, frame_handler, NULL);
    underflow_reported = FALSE;

    start = rdtscll();
    hdlc_tx_flags(&tx, 40);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 0;
    for (i = 0;  i < 8*1000000;  i++)
    {
        nextbyte = hdlc_tx_get_bit(&tx);
        hdlc_rx_put_bit(&rx, nextbyte);
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            for (j = 0;  j < 20;  j++)
            {
                nextbyte = hdlc_tx_get_bit(&tx);
                hdlc_rx_put_bit(&rx, nextbyte);
            }
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            frame_handled = FALSE;
        }
    }
    end = rdtscll();
    check_result();

    /* Now try sending HDLC messages with CRC-32 */
    printf("Testing with CRC-32 (byte by byte)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, TRUE, 1, FALSE, underflow_handler, NULL);
    hdlc_rx_init(&rx, TRUE, FALSE, 1, frame_handler, NULL);
    underflow_reported = FALSE;

    start = rdtscll();
    hdlc_tx_flags(&tx, 40);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 0;
    for (i = 0;  i < 1000000;  i++)
    {
        nextbyte = hdlc_tx_get_byte(&tx);
        hdlc_rx_put_byte(&rx, nextbyte);
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            nextbyte = hdlc_tx_get_byte(&tx);
            hdlc_rx_put_byte(&rx, nextbyte);
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, ref_len);
            frame_handled = FALSE;
        }
    }
    end = rdtscll();
    check_result();

    /* Now try progressive mode with CRC-16 */
    printf("Testing progressive mode with CRC-16 (byte by byte)\n");
    frame_len_errors = 0;
    frame_data_errors = 0;
    hdlc_tx_init(&tx, TRUE, 1, TRUE, underflow_handler, NULL);
    hdlc_rx_init(&rx, TRUE, FALSE, 1, frame_handler, NULL);
    underflow_reported = FALSE;

    start = rdtscll();
    hdlc_tx_flags(&tx, 40);
    /* Don't push an initial message so we should get an underflow after the preamble. */
    /* Lie for the first message, as there isn't really one */
    frame_handled = TRUE;
    frame_failed = FALSE;
    progress = 9999;
    progress_delay = 9999;
    frames_sent = 0;
    bytes_sent = 0;
    ref_len = 0;
    for (i = 0;  i < 1000000;  i++)
    {
        nextbyte = hdlc_tx_get_byte(&tx);
        hdlc_rx_put_byte(&rx, nextbyte);
        if (underflow_reported)
        {
            underflow_reported = FALSE;
            nextbyte = hdlc_tx_get_byte(&tx);
            hdlc_rx_put_byte(&rx, nextbyte);
            if (ref_len)
            {
                frames_sent++;
                bytes_sent += ref_len;
            }
            if (!frame_handled)
            {
                printf("Frame not received.\n");
                return -1;
            }
            ref_len = cook_up_msg(buf);
            hdlc_tx_frame(&tx, buf, 10);
            progress = 10;
            progress_delay = 8;
            frame_handled = FALSE;
        }
        if (progress < ref_len  &&  progress_delay-- <= 0)
        {
            if (hdlc_tx_frame(&tx, buf + progress, (progress + 10 <= ref_len)  ?  10  :  ref_len - progress) < 0)
            {
                printf("Failed to add progressively\n");
                return -1;
            }
            progress += 10;
            progress_delay = 8;
        }
    }
    end = rdtscll();
    check_result();

    printf("Tests passed.\n");
    return 0;
}