#ifndef __YMODEM_H_ #define __YMODEM_H_ #ifdef __cplusplus extern "C" { #endif #include #define PACKET_SEQNO_INDEX (1) #define PACKET_SEQNO_COMP_INDEX (2) #define PACKET_HEADER (3) #define PACKET_TRAILER (2) #define PACKET_OVERHEAD (PACKET_HEADER + PACKET_TRAILER) #define PACKET_SIZE (128) #define PACKET_1K_SIZE (1024) #define FILE_NAME_LENGTH (256) #define FILE_SIZE_LENGTH (16) #define SOH (0x01) /* start of 128-byte data packet */ #define STX (0x02) /* start of 1024-byte data packet */ #define EOT (0x04) /* end of transmission */ #define ACK (0x06) /* acknowledge */ #define NAK (0x15) /* negative acknowledge */ #define CA (0x18) /* two of these in succession aborts transfer */ #define WANTCRC (0x43) /* 'C' == 0x43, request 16-bit CRC */ #define WANTG (0x47) /* 'G' == 0x47 */ #define ABORT1 (0x41) /* 'A' == 0x41, abort by user */ #define ABORT2 (0x61) /* 'a' == 0x61, abort by user */ /* 1s */ #define NAK_TIMEOUT (1000) #define MAX_ERRORS (10) /* base class for ymodem user */ struct ymodem_xfer { /* * get a character from serial line with timeout millseconds. * * c: received character. * timeout: wait for millseconds. * * return 0 on sucess, -1 on failure. */ int (*getc)(struct ymodem_xfer *, uint8_t *c, int timeout /* in millseconds */); /* * send a charactor to serial line. * * return 0 on sucess, -1 on failure. */ int (*putc)(struct ymodem_xfer *, uint8_t c); /* * ymodem file information. * * return < 0 abort ymodem transfer, 0 continue. */ int (*on_info)(struct ymodem_xfer *, const char *name, unsigned int size); /* * ymodem file data from serial line. * * return < 0 abort ymodem transfer, 0 continue. */ int (*on_data)(struct ymodem_xfer *, const void *data, unsigned int len); }; int ymodem_recv(struct ymodem_xfer *xfer); int ymodem_send(struct ymodem_xfer *xfer, uint8_t *buf, const uint8_t* sendFileName, uint32_t sizeFile); /* recv from serial */ struct serial; int serial_ymodem_recv(struct serial *, void *user, int (*on_info)(void *user, const char *name, unsigned int size), int (*on_data)(void *user, const void *data, unsigned int len)); /* recv from stdio */ int stdio_ymodem_recv(void *user, int (*_on_info)(void *user, const char *name, unsigned int size), int (*_on_data)(void *user, const void *data, unsigned int len)); #ifdef __cplusplus } #endif #endif /* __YMODEM_H_ */