Implement tabby_printer_packet_send()
This commit is contained in:
parent
4e3d8073b5
commit
8e460b56ea
2 changed files with 41 additions and 3 deletions
|
@ -32,10 +32,19 @@ typedef struct _tabby_printer_packet {
|
|||
} tabby_printer_packet;
|
||||
|
||||
/*
|
||||
* Methods for communicating with Game Boy as a printer
|
||||
* For receiving printer data packets from a Game Boy Camera
|
||||
*/
|
||||
int tabby_printer_packet_recv(int fd, tabby_printer_packet *header,
|
||||
int tabby_printer_packet_recv(int fd,
|
||||
tabby_printer_packet *header,
|
||||
void *body,
|
||||
uint16_t *checksum);
|
||||
|
||||
/*
|
||||
* For sending printer data packets to a Game Boy Printer
|
||||
*/
|
||||
int tabby_printer_packet_send(int fd,
|
||||
tabby_printer_packet *header,
|
||||
void *body,
|
||||
uint16_t *response);
|
||||
|
||||
#endif /* _TABBY_PRINTER_H */
|
||||
|
|
|
@ -24,7 +24,8 @@ static uint16_t checksum(tabby_printer_packet *header, void *body) {
|
|||
return checksum;
|
||||
}
|
||||
|
||||
int tabby_printer_packet_recv(int fd, tabby_printer_packet *header,
|
||||
int tabby_printer_packet_recv(int fd,
|
||||
tabby_printer_packet *header,
|
||||
void *body,
|
||||
uint16_t *sum) {
|
||||
ssize_t len;
|
||||
|
@ -89,3 +90,31 @@ int tabby_printer_packet_recv(int fd, tabby_printer_packet *header,
|
|||
error_io:
|
||||
return -errno;
|
||||
}
|
||||
|
||||
int tabby_printer_packet_send(int fd,
|
||||
tabby_printer_packet *header,
|
||||
void *body,
|
||||
uint16_t *response) {
|
||||
uint16_t sum = checksum(header, body);
|
||||
|
||||
if (write(fd, header, sizeof(*header)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (write(fd, body, header->size) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (write(fd, &sum, sizeof(sum)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (read(fd, response, sizeof(response)) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_io:
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue