ymodem.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 #ifndef YMODEM_H
00033 #define YMODEM_H
00034 
00035 #include "serial_port.h"
00036 
00046 class YModem
00047     {
00048 protected:
00049     inline YModem(SerialPort& port)
00050         : Port(port)
00051         {}
00052 
00061     uint8_t Checksum(const uint8_t* data, size_t size);
00062 
00071     uint16_t CRC16(const uint8_t* data, size_t size);
00072 
00081     uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte);
00082 
00091     int InChar(unsigned timeout);
00092 
00096     void Cancel();
00097 
00101     enum ControlCharacters
00102         {
00103         SOH = 0x01,
00104         STX = 0x02,
00105         EOT = 0x04,
00106         ACK = 0x06,
00107         NAK = 0x15,
00108         CAN = 0x18
00109         };
00110 
00114     enum Error
00115         {
00116         ErrorTimeout                    = -200, 
00117         ErrorBlockRetriesExceded        = -201  
00118         };
00119 
00120 protected:
00124     SerialPort& Port;
00125     };
00126 
00127  // End of group
00129 
00130 #endif

Generated by  doxygen 1.6.1