From 84b5d6a2c991da11e889d9d751fe0bb6c66eaea5 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Thu, 2 Jun 2016 23:32:38 -0500 Subject: [PATCH] SO FREAKING ANNOYINGLY CLOSE --- avr/send.c | 20 ++++++++++++++------ bin/main.c | 32 ++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/avr/send.c b/avr/send.c index 6209c49..b13050e 100644 --- a/avr/send.c +++ b/avr/send.c @@ -152,19 +152,24 @@ static uint16_t checksum() { } int main() { - uint16_t sum = 0; + uint16_t sum = 0, + c; uart_init(); sei(); while (1) { - uint8_t c; + uart_putchar('O', NULL); - while (flags != TABBY_SEND_READING) { - sleep_mode(); + c = uart_getchar(NULL); + + if (c == 'K') { + break; } + } + while (1) { if (flags & TABBY_SEND_COMPLETE) { uart_putchar(device, NULL); uart_putchar(status, NULL); @@ -172,6 +177,8 @@ int main() { flags = TABBY_SEND_READING; } + while (flags != TABBY_SEND_READING); + c = uart_getchar(NULL); switch (i) { @@ -250,9 +257,10 @@ int main() { } else if (b == header.size + 1) { sum |= c << 8; + i = 0; + b = 0; + if (sum == checksum()) { - i = 0; - b = 0; flags |= TABBY_SEND_BUFFERED; spi_start(); diff --git a/bin/main.c b/bin/main.c index e99b635..a88f0f2 100644 --- a/bin/main.c +++ b/bin/main.c @@ -25,11 +25,11 @@ static void usage(int argc, char **argv, char *message, ...) { } int main(int argc, char **argv) { - int fd, status; + int fd; tabby_printer_packet header; - uint8_t body[TABBY_PRINTER_MAX_PACKET_SIZE]; + uint16_t response; if (argc != 2) { usage(argc, argv, "No device specified"); @@ -42,19 +42,27 @@ int main(int argc, char **argv) { goto error_link_open; } - while (1) { - status = tabby_printer_packet_recv(fd, &header, &body); + header.preamble[0] = 0x88; + header.preamble[1] = 0x33; + header.type = 0x0f; + header.compression = 0; + header.size = 0; - if (status < 0) { - fprintf(stderr, "%s: %s: %s\n", - argv[0], "tabby_printer_packet_recv()", strerror(errno)); + printf("Waiting for AVR to reboot after CTS\n"); - continue; - } + sleep(1); - if (header.type == 0x04) { - write(1, body, header.size); - } + printf("Initializing link\n"); + + tabby_printer_link_init(fd); + + printf("Interrogating printer\n"); + + if (tabby_printer_packet_send(fd, &header, NULL, &response) < 0) { + fprintf(stderr, "%s: %s: %s: %s\n", + argv[0], "tabby_printer_packet_send()", argv[1], strerror(errno)); + } else { + printf("Got response code %04x\n", response); } tabby_link_close(fd);