-
Notifications
You must be signed in to change notification settings - Fork 12
/
xmodem.h
72 lines (53 loc) · 1.66 KB
/
xmodem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef INCLUDED_XMODEM_H
#define INCLUDED_XMODEM_H
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/* Protocol variants */
typedef enum
{
XMODEM_MODE_ORIGINAL,
XMODEM_MODE_CRC
} xmodem_mode_t;
/* Configuration parameters */
typedef struct
{
/* Enable/disable logging during the transfer.
*
* 0 = fatal errors only
* 1 = errors only
* 2 = verbose logging
* 3 = log all bytes received
*/
int logLevel;
/* Enable the CRC variant of the protocol */
bool useCrc;
/* Enable decoding of escape characters */
bool useEscape;
} xmodem_config_t;
/* Currently active configuration */
extern xmodem_config_t xmodem_config;
/* Change configuration */
void xmodem_set_config(xmodem_mode_t mode);
/* Receive a file. Note that XMODEM pads files to the next multiple of 128,
* using character 26.
*
* Returns the amount of data received - always a multiple of 128.
*
* outputBuffer: where to store the received data
* bufferSize: maximum number of bytes to store in outputBuffer
* message: an optional prompt to start the transfer
* inputhandler: an optional function to handle unexpected input before the transfer
*
* If message is provided, it will be printed every few seconds until the
* first data is received.
*
* If inputhandler is provided, it will be called if unexpected input is received before
* the transfer begins. The unexpected input character will be passed to the handler,
* which should return 'true' if it handled it.
*/
int xmodem_receive(void* outputBuffer, size_t bufferSize, const char *message, bool (*inputhandler)());
/* Dumps cached log data to stdout. */
void xmodem_dumplog();
#endif