Skip to content

Commit

Permalink
Read options once at start, start printer thread early
Browse files Browse the repository at this point in the history
Makes it possible to emulate printer with only one
serial adapter.
  • Loading branch information
colinleroy committed Oct 20, 2024
1 parent 2f2e073 commit c477bfc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <[email protected]> Sun, 20 Oct 2024 21:28:19 +0200

a2tools (21.1.0.2) bionic; urgency=medium

* Virtual ImageWriter II on proxy
Expand Down
6 changes: 1 addition & 5 deletions src/lib/serial/c/simple_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/simple_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/surl-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand 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");
Expand Down
2 changes: 1 addition & 1 deletion src/surl-server/surl_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c477bfc

Please sign in to comment.