xref: /haiku/src/apps/serialconnect/XModem.h (revision 8bff17cfd8936c94ce414f390323e3c8aa639e13)
1ce058fa0SAdrien Destugues /*
2ce058fa0SAdrien Destugues  * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
3ce058fa0SAdrien Destugues  * Distributed under terms of the MIT license.
4ce058fa0SAdrien Destugues  */
5ce058fa0SAdrien Destugues 
6ce058fa0SAdrien Destugues 
7ce058fa0SAdrien Destugues #ifndef XMODEM_H
8ce058fa0SAdrien Destugues #define XMODEM_H
9ce058fa0SAdrien Destugues 
10*8bff17cfSAdrien Destugues #include "FileSender.h"
11ce058fa0SAdrien Destugues 
12ce058fa0SAdrien Destugues #include <Messenger.h>
13ce058fa0SAdrien Destugues #include <String.h>
14ce058fa0SAdrien Destugues 
15ce058fa0SAdrien Destugues 
16ce058fa0SAdrien Destugues class BDataIO;
17ce058fa0SAdrien Destugues class BHandler;
18ce058fa0SAdrien Destugues class BSerialPort;
19ce058fa0SAdrien Destugues 
20ce058fa0SAdrien Destugues 
21*8bff17cfSAdrien Destugues class XModemSender: public FileSender {
22ce058fa0SAdrien Destugues 	public:
23ce058fa0SAdrien Destugues 								XModemSender(BDataIO* source, BSerialPort* sink,
24ce058fa0SAdrien Destugues 									BHandler* listener);
25*8bff17cfSAdrien Destugues 		virtual					~XModemSender();
26ce058fa0SAdrien Destugues 
27*8bff17cfSAdrien Destugues 		virtual	bool			BytesReceived(const uint8_t* data,
28*8bff17cfSAdrien Destugues 									size_t length);
29ce058fa0SAdrien Destugues 	private:
30ce058fa0SAdrien Destugues 
31ce058fa0SAdrien Destugues 				void			SendBlock();
32ce058fa0SAdrien Destugues 				status_t		NextBlock();
33ce058fa0SAdrien Destugues 
34cd4d3a30SAdrien Destugues 				uint16_t		CRC(const uint8_t* buffer, size_t size);
35cd4d3a30SAdrien Destugues 
36ce058fa0SAdrien Destugues 	private:
37ce058fa0SAdrien Destugues 				BDataIO*		fSource;
38ce058fa0SAdrien Destugues 				BSerialPort*	fSink;
39ce058fa0SAdrien Destugues 				BMessenger		fListener;
40ce058fa0SAdrien Destugues 				off_t			fBlockNumber;
41ce058fa0SAdrien Destugues 				off_t			fSourceSize;
42ce058fa0SAdrien Destugues 				uint8_t			fBuffer[128];
43ce058fa0SAdrien Destugues 				bool			fEotSent;
44cd4d3a30SAdrien Destugues 				bool			fUseCRC;
45ce058fa0SAdrien Destugues 				BString			fStatus;
46ce058fa0SAdrien Destugues };
47ce058fa0SAdrien Destugues 
48ce058fa0SAdrien Destugues 
49ce058fa0SAdrien Destugues #endif /* !XMODEM_H */
50