43 #define MIN(a, b) ((a) < (b)? (a) : (b))
47 PROCESS(shell_tcpsend_process,
"tcpsend");
50 "tcpsend <host> <port>: open a TCP connection",
51 &shell_tcpsend_process);
54 #define MAX_SERVERLEN 16
56 static uip_ipaddr_t serveraddr;
57 static char server[MAX_SERVERLEN + 1];
59 static struct telnet_state s;
61 static unsigned char running;
63 #define MAX_LINELEN 80
65 static char outputline[MAX_LINELEN];
66 static uint8_t sending;
69 telnet_text_output(
struct telnet_state *s,
char *text1,
char *text2)
71 char buf1[MAX_SERVERLEN];
74 strncpy(buf1, text1,
sizeof(buf1));
76 if(len <
sizeof(buf1) - 1) {
84 telnet_newdata(
struct telnet_state *s,
char *data, uint16_t len)
90 send_line(
struct telnet_state *s,
char *data,
int len)
93 strncpy(outputline, data, MIN(
sizeof(outputline), len));
94 telnet_send(s, data, len);
97 shell_output_str(&tcpsend_command,
"Cannot send data, still sending previous data",
"");
102 telnet_sent(
struct telnet_state *s)
108 telnet_closed(
struct telnet_state *s)
110 telnet_text_output(s, server,
"connection closed");
115 telnet_aborted(
struct telnet_state *s)
117 telnet_text_output(s, server,
"connection aborted");
122 telnet_timedout(
struct telnet_state *s)
124 telnet_text_output(s, server,
"connection timed out");
129 telnet_connected(
struct telnet_state *s)
131 telnet_text_output(s, server,
"connected");
143 next = strchr(data,
' ');
146 "tcpsend <server> <port>: server as address",
"");
151 strncpy(server, data,
sizeof(server));
157 telnet_connect(&s, &serveraddr, port);
163 if(input->len1 + input->len2 == 0) {
167 if(input->len1 > 0) {
168 send_line(&s, input->data1, input->len1);
175 if((
char *)data !=
NULL &&
178 telnet_connect(&s, server, serveraddr, nick);
190 shell_tcpsend_init(
void)
Hostname is fresh and usable.
void shell_output_str(struct shell_command *c, char *text1, const char *text2)
Output strings from a shell command.
#define PROCESS_EXIT()
Exit the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
Main header file for the Contiki shell
#define NULL
The null pointer.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
void shell_output(struct shell_command *c, void *data1, int len1, const void *data2, int len2)
Output data from a shell command.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
unsigned long shell_strtolong(const char *str, const char **retstr)
Convert a string to a number.
CCIF process_event_t resolv_event_found
Event that is broadcasted when a DNS name has been resolved.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
Structure for shell input data.
void shell_register_command(struct shell_command *c)
Register a command with the shell.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
int shell_event_input
The event number for shell input data.
process_event_t tcpip_event
The uIP event.
#define SHELL_COMMAND(name, command, description, process)
Define a shell command.