I hate overflows as much as the next person
This commit is contained in:
parent
fc19701ec4
commit
be84cecfeb
5 changed files with 32 additions and 4 deletions
|
@ -29,7 +29,7 @@ OBJS = send.o recv.o printer.o link.o uart.o
|
|||
RECV_NAME = recv
|
||||
RECV_BIN = $(RECV_NAME).bin
|
||||
RECV_ELF = $(RECV_NAME).elf
|
||||
RECV_OBJS = recv.o link.o uart.o
|
||||
RECV_OBJS = recv.o printer.o link.o uart.o
|
||||
|
||||
SEND_NAME = send
|
||||
SEND_BIN = $(SEND_NAME).bin
|
||||
|
|
|
@ -3,6 +3,24 @@
|
|||
#include <tabby/avr/link.h>
|
||||
#include <tabby/avr/printer.h>
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
#include <tabby/printer.h>
|
||||
#include <tabby/avr/printer.h>
|
||||
#include <tabby/avr/uart.h>
|
||||
#include <tabby/avr/link.h>
|
||||
#include <tabby/avr.h>
|
||||
|
@ -66,12 +66,13 @@ ISR(SPI_STC_vect) {
|
|||
|
||||
case 5: {
|
||||
header.size |= in << 8;
|
||||
i++;
|
||||
|
||||
if (header.size > TABBY_PRINTER_PACKET_MAX_SIZE) {
|
||||
if (tabby_avr_printer_packet_toolarge(header.type, header.size)) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,13 @@ int main() {
|
|||
header.size |= c << 8;
|
||||
i++;
|
||||
|
||||
if (tabby_avr_printer_packet_toolarge(header.type,
|
||||
header.size)) {
|
||||
i = 0;
|
||||
b = 0;
|
||||
sheet_offset = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <tabby/printer.h>
|
||||
|
||||
int tabby_avr_printer_packet_toolarge(uint8_t type, uint16_t size);
|
||||
|
||||
void tabby_avr_printer_send_packet(uint8_t type,
|
||||
uint8_t *body,
|
||||
uint16_t size,
|
||||
|
|
Loading…
Add table
Reference in a new issue