NetTest.c example details
This program installs a UDP echo server (port 7), and a TCP server listening on port 1061.
To verify this program, first 'Ping' the DSP:
>ping 192.168.168.200
If the settings and network connections are correct, the pings will be replied.
The UDP Echo server will re-send (echo) anything it receives. To verify this, start Netcat (nc) with the following command
>nc -u 192.168.168.200 7
| | |
| | +-- port 7 = Echo Port
| +------------ the DSP's IP address
+-------------------- use UDP transfers
Any characters you type in the console window will be returned. NetCat doesn't send the characters immediately, it will send the entire string following a terminating CR. Please note that the maximum length of the character string is limited by the size of the buffer used for UDP echo (1472). You may also transmit a file by re-directing it to stdin:
>nc -u 192.168.168.200 7 < hello.txt
The TCP server will respond to any incoming request on port 1061 and return a short message. To verify this, start Netcat with the following command
>nc 192.168.168.200 1061
| |
| +-- port 1061 = the port the DSP listens to
+------------ the DSP's IP address
Type a CR, the DSP will respond with its message
- See also
- TCP Transmission Control Protocol , UDP User Datagram Protocol
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#define MAX_NBUFFER_SIZE (1500)
#include "..\..\..\Common\nbuffer.h"
#ifdef __cplusplus
extern "C" {
#endif
#pragma CODE_SECTION(udp_call_back , ".commontext")
#pragma CODE_SECTION(tcp_call_back , ".commontext")
#pragma CODE_SECTION(process_data , ".commontext")
#ifdef __cplusplus
}
#endif
#define USE_TCP_CALLBACK 1
#define MAX_UDP_BUFFERS 4
#ifdef USE_STATIC_MEMORY
#pragma DATA_SECTION(udp_buffer , ".data_slow");
#endif
{
0,
0,
0,
#else
1,
#endif
};
static char tcp_tx[27] =
"this is the DSP response\r\n";
#define TX_SIZE (uint32_t)sizeof(tcp_tx)
{
data_length = net_recv_event_handler (so,
CPrintf);
if (data_length)
{
{
}
if ( bctl-> OutOfBuffer )
{
bctl-> OutOfBuffer = FALSE;
}
bctl-> Buf[bctl-> ri].Size = data_length;
{
bctl-> pi = bctl-> ri;
}
{
bctl-> OutOfBuffer = TRUE;
}
}
}
#ifdef USE_TCP_CALLBACK
{
data_length = net_recv_event_handler (so,
CPrintf);
if (data_length)
{
}
}
#endif
{
{
return;
}
if ( bctl-> OutOfBuffer )
{
{
bctl-> OutOfBuffer = FALSE;
}
}
{
if ( bctl-> OutOfBuffer )
{
if ( bctl-> pi == bctl-> ri )
{
return;
}
}
buffer = (
char*)bctl-> Buf[bctl-> pi].Data;
size = (
uint32_t)bctl-> Buf[bctl-> pi].Size;
net_send_safe (so,
buffer , size, 0);
{
}
}
}
#pragma CODE_SECTION(main , ".commontext");
{
int main_loop = 1;
char conversion_buffer[16];
#ifndef USE_TCP_CALLBACK
#endif
CPrintf (
" *** timer %d mapped to CPU int %d ***\r\n",
{
}
{
}
1061,
{
}
#ifdef USE_TCP_CALLBACK
#endif
CPuts (
" network startup time [sec]: ");
"%"PRId32".%03"PRId32"\r\n"
CPuts (
"\r\n Entering main loop ...\r\n");
while ( main_loop )
{
{
CPuts (
"\r\n To verify this program, first 'ping' the DSP:\r\n");
CPuts (
" UDP test:\r\n");
}
#ifndef USE_TCP_CALLBACK
{
}
if (data_length)
{
data_length = 0;
}
#endif
{
{
}
}
}
return (0);
}