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 10ce058fa0SAdrien Destugues 11ce058fa0SAdrien Destugues #include <Messenger.h> 12ce058fa0SAdrien Destugues #include <String.h> 13ce058fa0SAdrien Destugues 14ce058fa0SAdrien Destugues 15ce058fa0SAdrien Destugues class BDataIO; 16ce058fa0SAdrien Destugues class BHandler; 17ce058fa0SAdrien Destugues class BSerialPort; 18ce058fa0SAdrien Destugues 19ce058fa0SAdrien Destugues 20ce058fa0SAdrien Destugues class XModemSender { 21ce058fa0SAdrien Destugues public: 22ce058fa0SAdrien Destugues XModemSender(BDataIO* source, BSerialPort* sink, 23ce058fa0SAdrien Destugues BHandler* listener); 24ce058fa0SAdrien Destugues ~XModemSender(); 25ce058fa0SAdrien Destugues 26*cd4d3a30SAdrien Destugues bool BytesReceived(const uint8_t* data, size_t length); 27ce058fa0SAdrien Destugues private: 28ce058fa0SAdrien Destugues 29ce058fa0SAdrien Destugues void SendBlock(); 30ce058fa0SAdrien Destugues status_t NextBlock(); 31ce058fa0SAdrien Destugues 32*cd4d3a30SAdrien Destugues uint16_t CRC(const uint8_t* buffer, size_t size); 33*cd4d3a30SAdrien Destugues 34ce058fa0SAdrien Destugues private: 35ce058fa0SAdrien Destugues BDataIO* fSource; 36ce058fa0SAdrien Destugues BSerialPort* fSink; 37ce058fa0SAdrien Destugues BMessenger fListener; 38ce058fa0SAdrien Destugues off_t fBlockNumber; 39ce058fa0SAdrien Destugues off_t fSourceSize; 40ce058fa0SAdrien Destugues uint8_t fBuffer[128]; 41ce058fa0SAdrien Destugues bool fEotSent; 42*cd4d3a30SAdrien Destugues bool fUseCRC; 43ce058fa0SAdrien Destugues BString fStatus; 44ce058fa0SAdrien Destugues }; 45ce058fa0SAdrien Destugues 46ce058fa0SAdrien Destugues 47ce058fa0SAdrien Destugues #endif /* !XMODEM_H */ 48