tabby/bin/main.c
2016-06-03 23:01:22 -05:00

74 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <tabby/link.h>
#include <tabby/printer.h>
static void usage(int argc, char **argv, char *message, ...) {
if (message) {
va_list args;
va_start(args, message);
vfprintf(stderr, message, args);
fprintf(stderr, "\n");
va_end(args);
}
fprintf(stderr, "usage: %s device\n", argv[0]);
exit(1);
}
int main(int argc, char **argv) {
int fd;
tabby_printer_packet header;
uint16_t response;
if (argc != 2) {
usage(argc, argv, "No device specified");
}
if ((fd = tabby_link_open(argv[1])) < 0) {
fprintf(stderr, "%s: %s: %s: %s\n", argv[0], "tabby_link_open()",
argv[1], strerror(errno));
goto error_link_open;
}
header.preamble[0] = 0x88;
header.preamble[1] = 0x33;
header.type = 0x0f;
header.compression = 0;
header.size = 0;
printf("Waiting for AVR to reboot after CTS\n");
sleep(1);
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);
return 0;
error_link_open:
return 1;
}