37 #include "contiki-net.h"
42 #include "simpletelnet.h"
47 static struct ctk_label telnethostlabel =
49 static char telnethost[25];
50 static struct ctk_textentry telnethosttextentry =
53 static struct ctk_label telnetportlabel =
55 static char telnetport[6];
56 static struct ctk_textentry telnetporttextentry =
59 static struct ctk_button telnetconnectbutton =
61 static struct ctk_button telnetdisconnectbutton =
64 static char telnetline[31];
65 static struct ctk_textentry telnetlinetextentry =
66 {
CTK_TEXTENTRY(0, 3, TELNET_ENTRY_WIDTH, 1, telnetline, TELNET_ENTRY_WIDTH)};
68 static struct ctk_button telnetsendbutton =
69 {
CTK_BUTTON(TELNET_ENTRY_WIDTH + 2, 3, 4,
"Send")};
71 static struct ctk_label telnetstatus =
72 {
CTK_LABEL(0, TELNET_WINDOW_HEIGHT - 1, TELNET_WINDOW_WIDTH, 1,
"")};
74 static struct ctk_separator telnetsep1 =
77 static struct ctk_separator telnetsep2 =
78 {
CTK_SEPARATOR(0, TELNET_WINDOW_HEIGHT - 2, TELNET_WINDOW_WIDTH)};
80 static char telnettext[TELNET_WINDOW_WIDTH*TELNET_TEXTAREA_HEIGHT];
81 static struct ctk_label telnettextarea =
82 {
CTK_LABEL(0, 5, TELNET_WINDOW_WIDTH, TELNET_TEXTAREA_HEIGHT, telnettext)};
84 static struct telnet_state ts_appstate;
89 static char sendline[31+2];
91 PROCESS(simpletelnet_process,
"Telnet client");
93 AUTOSTART_PROCESSES(&simpletelnet_process);
100 for(i = 1; i < TELNET_TEXTAREA_HEIGHT; ++i) {
101 memcpy(&telnettext[(i - 1) * TELNET_WINDOW_WIDTH], &telnettext[i * TELNET_WINDOW_WIDTH], TELNET_WINDOW_WIDTH);
103 memset(&telnettext[(TELNET_TEXTAREA_HEIGHT - 1) * TELNET_WINDOW_WIDTH], 0, TELNET_WINDOW_WIDTH);
112 len = (
unsigned int)strlen(text);
119 }
else if(*text ==
'\r') {
121 }
else if(*text >=
' ') {
122 telnettext[(TELNET_TEXTAREA_HEIGHT - 1) * TELNET_WINDOW_WIDTH + i] = *text;
124 if(i == TELNET_WINDOW_WIDTH) {
153 uip_ipaddr_t addr, *addrptr;
160 for(cptr = telnethost; *cptr !=
' ' && *cptr != 0; ++cptr);
167 resolv_query(telnethost);
168 show(
"Resolving host...");
177 for(cptr = telnetport; *cptr !=
' ' && *cptr != 0; ++cptr) {
178 if(*cptr < '0' || *cptr >
'9') {
179 show(
"Port number error");
182 port = 10 * port + *cptr -
'0';
188 show(
"Out of memory error");
192 show(
"Connecting...");
203 ctk_window_new(&telnetwindow, TELNET_WINDOW_WIDTH, TELNET_WINDOW_HEIGHT,
"Simple telnet");
205 strcpy(telnetport,
"23");
231 if(w == (
struct ctk_widget *)&telnetsendbutton) {
232 strcpy(sendline, telnetline);
233 sendlen = (int)strlen(sendline);
234 petsciiconv_toascii(sendline, sendlen);
235 sendline[sendlen++] = ISO_CR;
236 sendline[sendlen++] = ISO_NL;
237 if(telnet_send(&ts_appstate, sendline, sendlen)) {
244 }
else if(w == (
struct ctk_widget *)&telnetdisconnectbutton) {
245 telnet_close(&ts_appstate);
247 }
else if(w == (
struct ctk_widget *)&telnetconnectbutton) {
253 if(strcmp(data, telnethost) == 0) {
257 show(
"Host not found");
262 #
if CTK_CONF_WINDOWCLOSE
265 ev == PROCESS_EVENT_EXIT) {
277 telnet_connected(
struct telnet_state *s)
283 telnet_closed(
struct telnet_state *s)
285 show(
"Connection closed");
289 telnet_sent(
struct telnet_state *s)
291 petsciiconv_topetscii(sendline,
sizeof(sendline));
299 telnet_aborted(
struct telnet_state *s)
301 show(
"Connection reset by peer");
305 telnet_timedout(
struct telnet_state *s)
307 show(
"Connection timed out");
311 telnet_newdata(
struct telnet_state *s,
char *data, uint16_t len)
313 petsciiconv_topetscii(data, len);
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_window_close
Emitted when a window is closed.
#define CTK_SEPARATOR(x, y, w)
Instantiating macro for the ctk_separator widget.
#define CTK_TEXTENTRY_CLEAR(e)
Clears a text entry widget and sets the cursor to the start of the text line.
process_event_t ctk_signal_button_activate
Same as ctk_signal_widget_activate.
Hostname was not found in the cache.
Hostname is fresh and usable.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
#define PROCESS_BEGIN()
Define the beginning of a process.
Representation of a uIP TCP connection.
CCIF struct uip_conn * tcp_connect(uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
Open a TCP connection to the specified IP address and port.
#define CTK_TEXTENTRY(x, y, w, h, text, len)
Instantiating macro for the ctk_textentry widget.
#define ctk_label_set_text(l, t)
Set the text of a label.
#define NULL
The null pointer.
void ctk_window_redraw(struct ctk_window *w)
Redraw a window.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
CCIF process_event_t resolv_event_found
Event that is broadcasted when a DNS name has been resolved.
PETSCII/ASCII conversion functions.
#define LOADER_UNLOAD()
Unload a program from memory.
CCIF uint16_t uip_htons(uint16_t val)
Convert a 16-bit quantity from host byte order to network byte order.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
process_event_t tcpip_event
The uIP event.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
The generic CTK widget structure that contains all other widget structures.
unsigned char w
The width of the widget in character coordinates.
void process_exit(struct process *p)
Cause a process to exit.