Hi Paul,
I'd asked Mark a similar question in a personal email, below is my original email and Marks reply. It might be of help to you.
Hi Mark,
I'm adding a telnet interface to my project, using debug.c as a starting point. This all works fine.
What I would also like to do is to add a debug interface, which would be on a different TCPIP port than the standard Telnet port. Currently If I start using fnDebugMsg it will mess up my Telnet interface.
My thoughts are as follows.
1. Create fnTelnetMsg, fnTelnetDec, fnTelnetHex which are similar to the fnDebug... equivalents but use the Tenet Port.
2. Create a #define in debug.c that changes fnDebug... to fnTelnet... It may be better to do a replace the string "fnDebug" with "fnTelnet" in the code but I want to have minimal changes in the code.
3. I've just looked at the definitions of fnDebugMsg and it prints to the Network Queue rather than the a queue associated with the Telnet Port, so It may be a bit more complex than I first thought.
4. What would you suggest would be the best way to create Telnet functionality on two separate TCPIP ports, one for a Telnet interface and one for a Debug interface? would I need to duplicate the telnet.c code or could I re-use it on multiple ports?
5. If another TCPIP port is not required for debug comms I would like to be able to #define fnDebug.. as fnTelnet.. so I would have the same functionality as currently exists (both functions outputting to the same port).
6. I guess my question really relates to how to setup multiple Telnet sessions on Multiple TCPIP ports.
Cheers
Martin
Hi Martin
If the second TCP connection is on a different port it is necessary to have a second socket handler. This can of course be very similar to the present one in debug.c.
To have multiple TELNET sessions on the same TCP port the same code can be used but needs to be adapter to support multiple sessions (like in HTTP), meaning that any local variables have to be changed to arrays so that each session has its own set.
Assuming that you have 2 TCP TELNET (or TELNET like) connections open I would try to use the existing fnNetworkTx() method.
// We support the network transmit routine here
//
extern QUEUE_TRANSFER fnNetworkTx(unsigned char *output_buffer, QUEUE_TRANSFER nr_of_bytes)
{
return (fnSendBufTCP(Telnet_socket, output_buffer, nr_of_bytes, (TCP_BUF_SEND | TCP_BUF_SEND_REPORT_COPY)));
}
All debug type outputs will be sent here if the debug handle is a -1 (the default value).
But this is user code and can be modified to send to multiple outputs (for example), like UART, USB and Telnet, or multiple Telnet type sessions.
// We support the network transmit routine here
//
extern QUEUE_TRANSFER fnNetworkTx(unsigned char *output_buffer, QUEUE_TRANSFER nr_of_bytes)
{
fnPrint(serial_handle, output_buffer, nr_of_bytes); // send to serial output
return (fnSendBufTCP(Telnet_socket, output_buffer, nr_of_bytes, (TCP_BUF_SEND | TCP_BUF_SEND_REPORT_COPY))); // and TELNET
}
Since all output will pass this way it may be easiest to put a case in it:
// We support the network transmit routine here
//
extern QUEUE_TRANSFER fnNetworkTx(unsigned char *output_buffer, QUEUE_TRANSFER nr_of_bytes)
{
switch (DebugOutput) {
case STANDARD_OUTPUT:
return (fnSendBufTCP(Telnet_socket, output_buffer, nr_of_bytes, (TCP_BUF_SEND | TCP_BUF_SEND_REPORT_COPY)));
case SECOND_OUTPUT:
return (fnSendBufTCP(Second_Telnet_socket, output_buffer, nr_of_bytes, (TCP_BUF_SEND | TCP_BUF_SEND_REPORT_COPY)));
}
}
The new global variable DebugOutput can be used to select the output for individual messages.
DebugOutput = SECOND_OUTPUT;
fnDebugMsg(“Test”);
DebugOutput = STANDARD_OUTPUT;
Possibly a macro or cover function would help too. All output which is for the standard one doesn’t need to do anything special.
Regards
Mark