ymodem_rx.h

Go to the documentation of this file.
00001 /*
00002 This program is distributed under the terms of the 'MIT license'. The text
00003 of this licence follows...
00004 
00005 Copyright (c) 2006 J.D.Medhurst (a.k.a. Tixy)
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a copy
00008 of this software and associated documentation files (the "Software"), to deal
00009 in the Software without restriction, including without limitation the rights
00010 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011 copies of the Software, and to permit persons to whom the Software is
00012 furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00020 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023 THE SOFTWARE.
00024 */
00025 
00032 #include "ymodem.h"
00033 
00038 class YModemRx : public YModem
00039     {
00040 public:
00046     YModemRx(SerialPort& port);
00047 
00051     class OutStream
00052         {
00053     public:
00063         virtual int Open(const char* fileName, size_t size) =0;
00064 
00073         virtual int Out(const uint8_t* data, size_t size) =0;
00074 
00078         inline virtual ~OutStream() {}
00079         };
00080 
00090     int ReceiveX(OutStream& out, unsigned timeout, bool useCrc);
00091 
00101     int ReceiveY(OutStream& out, unsigned timeout, bool gMode);
00102 
00106     enum RxError
00107         {
00108         ErrorOutputStreamError              = -400, 
00109         ErrorTransmitterNotBehaving         = -401, 
00110         ErrorTranferTerminatedByTransmitter = -402, 
00111         ErrorReceivedBadData                = -403, 
00112         ErrorMultipleFilesSent              = -404  
00113         };
00114 
00115 private:
00119     class OutBlock0 : public OutStream
00120         {
00121     public:
00122         OutBlock0();
00123         int Open(const char* fileName, size_t size);
00124         int Out(const uint8_t* data, size_t size);
00125         int Parse(const char*& fileName, size_t& fileSize);
00126     private:
00127         uint8_t Buffer[1024];   
00128         size_t Size;            
00129         };
00130 
00131     int ReceiveInitialise(OutStream& out,unsigned timeout);
00132     int ReceiveBlock(OutStream& out);
00133     int OutChar(uint8_t c);
00134 private:
00135     size_t BlockNumber;
00136     bool ExpectCRC;     
00137     bool SendBlockACK;
00138     uint8_t ModeChar;
00139     uint8_t NAKChar;
00140     };
00141 
00142 

Generated by  doxygen 1.6.1