* Serial back end (Windows-specific).
*/
-/*
- * TODO:
- *
- * - sending breaks?
- * + looks as if you do this by calling SetCommBreak(handle),
- * then waiting a bit, then doing ClearCommBreak(handle). A
- * small job for timing.c, methinks.
- *
- * - why are we dropping data when talking to judicator?
- */
-
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
struct handle *out, *in;
void *frontend;
int bufsize;
+ long clearbreak_time;
+ int break_in_progress;
} *Serial;
static void serial_terminate(Serial serial)
handle_free(serial->in);
serial->in = NULL;
}
- if (serial->port) {
+ if (serial->port != INVALID_HANDLE_VALUE) {
+ if (serial->break_in_progress)
+ ClearCommBreak(serial->port);
CloseHandle(serial->port);
- serial->port = NULL;
+ serial->port = INVALID_HANDLE_VALUE;
}
}
const char *err;
serial = snew(struct serial_backend_data);
- serial->port = NULL;
+ serial->port = INVALID_HANDLE_VALUE;
serial->out = serial->in = NULL;
+ serial->bufsize = 0;
+ serial->break_in_progress = FALSE;
*backend_handle = serial;
serial->frontend = frontend_handle;
{
- char *msg = dupprintf("Opening serial device %s", host);
+ char *msg = dupprintf("Opening serial device %s", cfg->serline);
logevent(serial->frontend, msg);
}
HANDLE_FLAG_OVERLAPPED);
serial->in = handle_input_new(serport, serial_gotdata, serial,
HANDLE_FLAG_OVERLAPPED |
- HANDLE_FLAG_IGNOREEOF);
+ HANDLE_FLAG_IGNOREEOF |
+ HANDLE_FLAG_UNITBUFFER);
*realhost = dupstr(cfg->serline);
+ /*
+ * Specials are always available.
+ */
+ update_specials_menu(serial->frontend);
+
return NULL;
}
Serial serial = (Serial) handle;
serial_terminate(serial);
+ expire_timer_context(serial);
sfree(serial);
}
return;
}
+static void serbreak_timer(void *ctx, long now)
+{
+ Serial serial = (Serial)ctx;
+
+ if (now >= serial->clearbreak_time && serial->port) {
+ ClearCommBreak(serial->port);
+ serial->break_in_progress = FALSE;
+ logevent(serial->frontend, "Finished serial break");
+ }
+}
+
/*
* Send serial special codes.
*/
static void serial_special(void *handle, Telnet_Special code)
{
- /*
- * FIXME: serial break? XON? XOFF?
- */
+ Serial serial = (Serial) handle;
+
+ if (serial->port && code == TS_BRK) {
+ logevent(serial->frontend, "Starting serial break at user request");
+ SetCommBreak(serial->port);
+ /*
+ * To send a serial break on Windows, we call SetCommBreak
+ * to begin the break, then wait a bit, and then call
+ * ClearCommBreak to finish it. Hence, I must use timing.c
+ * to arrange a callback when it's time to do the latter.
+ *
+ * SUS says that a default break length must be between 1/4
+ * and 1/2 second. FreeBSD apparently goes with 2/5 second,
+ * and so will I.
+ */
+ serial->clearbreak_time =
+ schedule_timer(TICKSPERSEC * 2 / 5, serbreak_timer, serial);
+ serial->break_in_progress = TRUE;
+ }
+
return;
}
*/
static const struct telnet_special *serial_get_specials(void *handle)
{
- /*
- * FIXME: serial break? XON? XOFF?
- */
- return NULL;
+ static const struct telnet_special specials[] = {
+ {"Break", TS_BRK},
+ {NULL, TS_EXITMENU}
+ };
+ return specials;
}
static int serial_connected(void *handle)
static int serial_exitcode(void *handle)
{
Serial serial = (Serial) handle;
- if (serial->port != NULL)
+ if (serial->port != INVALID_HANDLE_VALUE)
return -1; /* still connected */
else
/* Exit codes are a meaningless concept with serial ports */