You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.9 KiB
95 lines
2.9 KiB
#ifndef __YMODEM_H_
|
|
#define __YMODEM_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
|
|
#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, no crc and ack */
|
|
|
|
#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 */);
|
|
|
|
/*
|
|
* get more than one bytes every time.
|
|
*
|
|
* return `number of bytes` received, -1 on failure.
|
|
*/
|
|
int (*read_stream)(struct ymodem_xfer *, uint8_t *, int n, int timeout);
|
|
|
|
/*
|
|
* 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);
|
|
|
|
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));
|
|
|
|
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_ */
|
|
|
|
|