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