#include #include #include 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_send_packet(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_send_packet(TABBY_PRINTER_PACKET_INIT, NULL, 0, response); } void tabby_avr_printer_send_inquiry(tabby_printer_response *response) { tabby_avr_printer_send_packet(TABBY_PRINTER_PACKET_INQUIRY, NULL, 0, response); } void tabby_avr_printer_job_start(tabby_printer_job *job, tabby_printer_response *response) { tabby_avr_printer_send_packet(TABBY_PRINTER_PACKET_JOB, job->data, sizeof(*job), response); } void tabby_avr_printer_send_data(uint8_t *data, uint16_t size, tabby_printer_response *response) { tabby_avr_printer_send_packet(TABBY_PRINTER_PACKET_DATA, data, size, response); } void tabby_avr_printer_send_sheet(uint8_t *sheet, uint16_t size, tabby_printer_response *response) { int i; tabby_avr_printer_init(response); for (i=0; i