From c477bfcdb78734be07a9e2f05c57d4fe10c19efd Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Sun, 20 Oct 2024 21:06:43 +0200 Subject: [PATCH] Read options once at start, start printer thread early Makes it possible to emulate printer with only one serial adapter. --- src/debian/changelog | 6 ++++++ src/lib/serial/c/simple_serial.c | 6 +----- src/lib/simple_serial.h | 3 +-- src/surl-server/main.c | 7 +++++-- src/surl-server/surl_protocol.h | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/debian/changelog b/src/debian/changelog index ed3745fe..6bb9c393 100644 --- a/src/debian/changelog +++ b/src/debian/changelog @@ -1,3 +1,9 @@ +a2tools (21.2.0.2) bionic; urgency=medium + + * Make it possible to use surl-server as only a printer emulator + + -- Colin Leroy-Mira Sun, 20 Oct 2024 21:28:19 +0200 + a2tools (21.1.0.2) bionic; urgency=medium * Virtual ImageWriter II on proxy diff --git a/src/lib/serial/c/simple_serial.c b/src/lib/serial/c/simple_serial.c index 23ef34cb..d9ccbdfa 100644 --- a/src/lib/serial/c/simple_serial.c +++ b/src/lib/serial/c/simple_serial.c @@ -170,7 +170,7 @@ static void simple_serial_write_defaults(void) { exit(1); } -static int simple_serial_read_opts(void) { +int simple_serial_read_opts(void) { static int opts_read_done = 0; FILE *fp = NULL; char buf[255]; @@ -320,15 +320,11 @@ int simple_serial_open_file(char *tty_path, int tty_speed) { } int simple_serial_open(void) { - /* Get options */ - simple_serial_read_opts(); ttyfd = simple_serial_open_file(opt_tty_path, opt_tty_speed); return ttyfd > 0 ? 0 : -1; } int simple_serial_open_printer(void) { - /* Get options */ - simple_serial_read_opts(); aux_ttyfd = simple_serial_open_file(opt_aux_tty_path, opt_aux_tty_speed); return aux_ttyfd > 0 ? 0 : -1; } diff --git a/src/lib/simple_serial.h b/src/lib/simple_serial.h index e35383eb..f0299fcc 100644 --- a/src/lib/simple_serial.h +++ b/src/lib/simple_serial.h @@ -89,8 +89,7 @@ char *tty_speed_to_str(int speed); void __fastcall__ simple_serial_read(char *ptr, size_t nmemb); void simple_serial_write_fast(const char *ptr, size_t nmemb); void simple_serial_write_fast_fd(int fd, const char *ptr, size_t nmemb); -const char *printer_get_iwem(void); -void printer_set_iwem(const char *str); +int simple_serial_read_opts(void); /* Full prototype for reading */ int __simple_serial_getc_with_tv_timeout(int fd, int timeout, int secs, int msecs); #endif diff --git a/src/surl-server/main.c b/src/surl-server/main.c index d63a6081..5bc5fb36 100644 --- a/src/surl-server/main.c +++ b/src/surl-server/main.c @@ -267,7 +267,12 @@ int main(int argc, char **argv) LOG("surl-server Protocol %d\n", SURL_PROTOCOL_VERSION); install_sig_handler(); + + /* Get options */ + simple_serial_read_opts(); + install_printer_thread(); + start_printer_thread(); curl_global_init(CURL_GLOBAL_ALL); @@ -281,8 +286,6 @@ int main(int argc, char **argv) } fflush(stdout); - start_printer_thread(); - while(1) { /* read request */ LOG("Waiting for request\n"); diff --git a/src/surl-server/surl_protocol.h b/src/surl-server/surl_protocol.h index ecc93022..d6d39cc1 100644 --- a/src/surl-server/surl_protocol.h +++ b/src/surl-server/surl_protocol.h @@ -3,7 +3,7 @@ /* Update in .inc too! */ #define SURL_PROTOCOL_VERSION 21 -#define VERSION "21.1.0" +#define VERSION "21.2.0" #define SURL_CLIENT_READY 0x2F #define HGR_LEN 8192U