coexistence between TCP / IP and TELNET

I'm working with S7G2 176 pin. I have 2 thread where I implemented a TELNET server protocol in the first and a TCP/IP server in the second one. The problem is that one or the other is working, but not both togheter. If I compile normally I get the TCP working but not the TELNET server. If I want to get the TELNET server working I have to disable the AUTOSTART on the TCP thread. Of course in that case TCP doesn't work any more. Anothe method to get TELNET working is to comment in the TCP thread, the instruction that creates the IP instance:

nx_ip_create(&ip_0, "NetX IP Instance 0", BOARD_IP_ADDRESS, IP_SUBNET_MASK, &pool_0, nx_ether_driver_eth1,&ip_memory_area, sizeof(ip_memory_area), 1);  also in this case TCP is not working.

I assigned the same priority to the 2 thread and the same IP static address.

What can I do?

TCP file.c #######################################################################################

#include "TCP_IP.h"

#include "nx_api.h"

#include "TCP_IP_entry.h"

 

/* Server Thread entry function */

void TCP_IP_entry(void)

{

UINT status;

NX_PACKET * packet_ptr;

ULONG actual_status;

uint8_t TCPmessage[256];

uint8_t TCPresponse[256];

uint32_t NumDataByte;

 

/* Initialize the NetX system. */

nx_system_initialize();

 

/* Create a packet pool. */

status = nx_packet_pool_create(&pool_0, (CHAR*)&NomePool, (1536 + 32), &packet_pool_area, sizeof(packet_pool_area));

 

/* Check for pool creation error. */

if (status)

error_counter++;

 

/* Create an IP instance. */

status = nx_ip_create(&ip_0, "NetX IP Instance 0", BOARD_IP_ADDRESS, IP_SUBNET_MASK, &pool_0, nx_ether_driver_eth1,&ip_memory_area, sizeof(ip_memory_area), 1);

 

/* Check for IP create errors. */

if (status)

error_counter++;

 

status = nx_ip_fragment_enable(&ip_0);

 

if (status)

error_counter++;

 

/* Enable ARP and supply ARP cache memory for IP Instance 0. */

status = nx_arp_enable(&ip_0, &arp_memory_area, sizeof(arp_memory_area));

 

/* Check for ARP enable errors. */

if (status)

error_counter++;

 

/* Enable TCP traffic. */

status = nx_tcp_enable(&ip_0);

 

/* Check for TCP enable errors. */

if (status)

error_counter++;

 

/* Enable ICMP. */

status = nx_icmp_enable(&ip_0);

 

/* Check for errors. */

if (status)

error_counter++;

 

/* Ensure the IP instance has been initialized. */

status = nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &actual_status, NX_WAIT_FOREVER);

 

/* Check status... */

if (status != NX_SUCCESS)

{

 

error_counter++;

return;

}

 

/* Create a socket. */

status = nx_tcp_socket_create(&ip_0, &socket_echo, "Echo Server Socket", NX_IP_NORMAL,

NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 512, NX_NULL, NX_NULL);

 

/* Check for error. */

if (status)

error_counter++;

 

/* Setup this thread to listen. */

status = nx_tcp_server_socket_listen(&ip_0, TCP_SERVER_PORT, &socket_echo, MAX_CLIENT_CONN, NX_NULL);

 

/* Check for error. */

if (status)

error_counter++;

 

/* Loop to create and establish server connections. */

while(1)

{

/* Accept a client socket connection. */

//status = nx_tcp_server_socket_accept(&socket_echo, NX_WAIT_FOREVER);

status = nx_tcp_server_socket_accept(&socket_echo, 100); /* Corrisponde a 100 mSec */

/* Check for error. */

error_counter=0;

if(status==NX_NOT_CONNECTED)

{

error_counter--; /* In attesa di connessione */

}

if (status==NX_SUCCESS)

{

while(1)

{

/* Receive a TCP message from the socket. */

//status = nx_tcp_socket_receive(&socket_echo, &packet_ptr, NX_WAIT_FOREVER);

status = nx_tcp_socket_receive(&socket_echo, &packet_ptr, 100);

/* Check for error. */

if(status!=NX_NO_PACKET)

{

if (status!=NX_SUCCESS)

{

/* most likely got disconnected */

error_counter++;

break;

}

else

{

error_counter=0;

/* Estrazione del pacchetto */

status = nx_packet_data_retrieve(packet_ptr,TCPmessage,&NumDataByte);

 

status = nx_packet_allocate(&pool_0,&packet_ptr,NX_TCP_PACKET,NX_WAIT_FOREVER );

 

status = nx_packet_data_append(packet_ptr,TCPresponse,sizeof(TCPresponse)/8,&pool_0,NX_WAIT_FOREVER);

 

/* Echo back the received data this will also release the packet */

nx_tcp_socket_send(&socket_echo, packet_ptr, NX_WAIT_FOREVER);

}

}

}

/* Disconnect the server socket. */

status = nx_tcp_socket_disconnect(&socket_echo, NX_WAIT_FOREVER);

 

/* Check for error. */

if (status)

error_counter++;

 

/* Unaccept the server socket. */

status = nx_tcp_server_socket_unaccept(&socket_echo);

 

/* Check for error. */

if (status)

error_counter++;

 

/* Setup server socket for listening again. */

status = nx_tcp_server_socket_relisten(&ip_0, TCP_SERVER_PORT, &socket_echo);

 

/* Check for error. */

if (status)

error_counter++;

}

tx_thread_sleep (1); /* Corrisponde a 10mS */

}

}

TELNET file.c ##############################################################################

#include "telnet_server_thread.h"

 

uint8_t g_message[] = "telnet server\r\n";

/* TELNET Server Thread entry function */

void telnet_server_thread_entry (void)

{

UINT status = nx_telnet_server_start(&g_telnet_server0);

if (NX_SUCCESS != status)

{

while (1)

{

}

}

 

while (1)

{

tx_thread_sleep(10);

}

}

 

/* On Client connecting to the server */

void telnet_client_connect (NX_TELNET_SERVER * telnet_server_ptr, UINT logical_connection)

{

UINT status;

NX_PACKET * p_packet;

 

/* Allocate a packet */

status = nx_packet_allocate(&g_packet_pool0, &p_packet, NX_TCP_PACKET, NX_NO_WAIT);

 

/* Determine if there is a packet */

if (status == NX_SUCCESS)

{

/* Build a message 'Synergy Telnet Server' */

nx_packet_data_append(p_packet, g_message, sizeof(g_message), &g_packet_pool0, NX_NO_WAIT);

/* Send the packet to the client. */

status = nx_telnet_server_packet_send(telnet_server_ptr, logical_connection, p_packet, 100);

if (status)

{

nx_packet_release(p_packet);

}

}

}

 

/* On Client writing to the server */

void telnet_receive_data (NX_TELNET_SERVER * telnet_server_ptr,

UINT logical_connection,

NX_PACKET * packet_ptr)

{

UINT status;

UCHAR alpha;

 

/* Pick up first character */

alpha = packet_ptr->nx_packet_prepend_ptr[0];

 

/* Echo character */

status = nx_telnet_server_packet_send(telnet_server_ptr, logical_connection, packet_ptr, 100);

if (status)

{

nx_packet_release(packet_ptr);

}

 

/* Check for a disconnection (if message begins with 'q') */

if (alpha == 'Q')

{

nx_telnet_server_disconnect(telnet_server_ptr, logical_connection);

}

}

 

/* On client disconneecting from the Server */

void telnet_client_disconnect (NX_TELNET_SERVER * telnet_server_ptr, UINT logical_connection)

{

SSP_PARAMETER_NOT_USED(telnet_server_ptr);

SSP_PARAMETER_NOT_USED(logical_connection);

}

  • Hi Luigi,

    Please wait a little bit more until Synergy experts respond to your problem. Thank you for understanding.

    JB
    RenesasRulz Forum Moderator

    https://renesasrulz.com/
    https://academy.renesas.com/
    https://en-us.knowledgebase.renesas.com/

  • Hi Lui Luigi,

    Which SSP version are you using? Would you like to use NetX Telnet Server with other modules like Communications Framework, or just telnet server alone?

    In the code NetX IP Instance is created manually, is there any particular reason for doing this without the configurator?

    Regards,
    adboc
  • In reply to adboc:

    Hi Adboc. I'm using SSP1.4. My purpose is to use Telnet server with Teraterm as a remote client terminal to send commands to the board. At the same time I want to use the TCP/IP protocol because I implemented a ModBus Server. NETX IP instance is created manually because I used the example I found on
    renesasrulz.com/.../s7_5F00_sk_5F00_nx_5F00_tcp_5F00_client_5F00_1_5F00_0_5F00_0.zip. I don't know how to do with the configurator, but if there is any other method you can suggest me, I have no particular problem...
    In the next future I want to try using the Telnet communication framework to see if I can avoid all the interference, but I' will be back to office in September. Meanwhile, any suggestion is welcome.
    Thanks to all.
  • In reply to Lui Luigi:

    Hi Lui Luigi,

    You just need to add NetX Telnet Server to one of the thread and configure all modules. IP instances will be already created then and you may use it to start a custom TCP server. Please take a look at the example below running Telnet server and a custom TCP server simultaneously (NetX Telnet server has its own internal thread):

    S7G2_SK_NetX_Telnet_TCP_Server_1_4_0.zip

    Regards,
    adboc