#include #include #include int tabby_avr_printer_packet_toolarge(uint8_t type, uint16_t size) { switch (type) { case TABBY_PRINTER_PACKET_JOB: { if (size > sizeof(tabby_printer_job)) { return 1; } } case TABBY_PRINTER_PACKET_DATA: { if (size > TABBY_PRINTER_PACKET_MAX_SIZE) { return 1; } } } return 0; } static uint16_t checksum(tabby_printer_packet *header, uint8_t *body) { uint16_t sum = 0; int i; for (i=2; idata[i]; } for (i=0; isize; i++) { sum += body[i]; } return sum; } void tabby_avr_printer_packet_send(uint8_t type, uint8_t *body, uint16_t size, tabby_printer_response *response) { tabby_printer_packet header = { .preamble = { TABBY_PRINTER_SYNC_1, TABBY_PRINTER_SYNC_2 }, .type = type, .compression = TABBY_PRINTER_COMPRESSION_NONE, .size = size }; uint16_t sum = checksum(&header, body); int i; for (i=0; i> 8); response->device = tabby_avr_link_send_byte(0); response->status = tabby_avr_link_send_byte(0); } void tabby_avr_printer_init(tabby_printer_response *response) { tabby_avr_printer_packet_send(TABBY_PRINTER_PACKET_INIT, NULL, 0, response); } void tabby_avr_printer_inquiry_send(tabby_printer_response *response) { tabby_avr_printer_packet_send(TABBY_PRINTER_PACKET_INQUIRY, NULL, 0, response); } void tabby_avr_printer_job_start(tabby_printer_job *job, tabby_printer_response *response) { tabby_avr_printer_packet_send(TABBY_PRINTER_PACKET_JOB, job->data, sizeof(*job), response); } void tabby_avr_printer_data_send(uint8_t *data, uint16_t size, tabby_printer_response *response) { tabby_avr_printer_packet_send(TABBY_PRINTER_PACKET_DATA, data, size, response); } void tabby_avr_printer_sheet_send(uint8_t *sheet, uint16_t size, tabby_printer_response *response) { int i; tabby_avr_printer_init(response); for (i=0; i