S.F.T. XMODEM Library  1.0
xmodem.h
Go to the documentation of this file.
00001 
00002 //                                                                          //
00003 //                                     _                      _             //
00004 //        __  __ _ __ ___    ___    __| |  ___  _ __ ___     | |__          //
00005 //        \ \/ /| '_ ` _ \  / _ \  / _` | / _ \| '_ ` _ \    | '_ \         //
00006 //         >  < | | | | | || (_) || (_| ||  __/| | | | | | _ | | | |        //
00007 //        /_/\_\|_| |_| |_| \___/  \__,_| \___||_| |_| |_|(_)|_| |_|        //
00008 //                                                                          //
00009 //                                                                          //
00011 //                                                                          //
00012 //          Copyright (c) 2012 by S.F.T. Inc. - All rights reserved         //
00013 //  Use, copying, and distribution of this software are licensed according  //
00014 //    to the LGPLv2.1, or a BSD-like license, as appropriate (see below)    //
00015 //                                                                          //
00017 
00018 #ifdef ARDUINO
00019 
00062 #else // ARDUINO
00063 
00106 #endif // ARDUINO
00107 
00122 #ifdef STANDALONE
00123 
00126 #endif // STANDALONE
00127 
00128 
00129 // determine if arduino build, define ARDUINO if not already done
00130 
00131 #if defined(__AVR__) || defined(AVR) || defined(__AVR) || defined(__AVR_ARCH__)
00132 #ifndef ARDUINO
00133 #define ARDUINO /* hopefully I cover all compiler variations */
00134 #endif // ARDUINO
00135 #endif // __AVR__
00136 
00137 
00138 #include <stdlib.h>
00139 
00140 // required include files
00141 #ifdef ARDUINO
00142 // arduino includes
00143 #include <Arduino.h>
00144 #include <SD.h>
00145 #include <HardwareSerial.h> /* may already be included by 'Arduino.h' */
00146 #include <avr/pgmspace.h>
00147 
00148 #elif WIN32
00149 // win32 includes
00150 #include <Windows.h>
00151 #include <io.h>
00152 #else // POSIX
00153 // posix includes
00154 #include <stdio.h>
00155 #include <stdlib.h>
00156 #include <unistd.h>
00157 #include <errno.h>
00158 #include <fcntl.h>
00159 #include <sys/time.h>
00160 #include <sys/ioctl.h> // for IOCTL definitions
00161 #include <memory.h>
00162 #endif // OS-dependent includes
00163 
00164 
00165 // required per-OS definitions
00166 #ifdef ARDUINO
00167 
00168 // file and serial types for Arduino
00169 #define FILE_TYPE File
00170 #define SERIAL_TYPE HardwareSerial *
00171 
00172 #elif defined(WIN32) // WINDOWS
00173 
00174 // file and serial types for WIN32
00175 #define FILE_TYPE HANDLE
00176 #define SERIAL_TYPE HANDLE
00177 
00178 #else // POSIX
00179 
00180 // file and serial types for POSIX
00181 #define FILE_TYPE int
00182 #define SERIAL_TYPE int
00183 
00184 #endif // ARDUINO
00185 
00186 
00187 // common definitions
00188 
00189 #define SILENCE_TIMEOUT 5000 /* 5 seconds */
00190 #define TOTAL_ERROR_COUNT 32
00191 #define ACK_ERROR_COUNT 8
00192 
00193 
00194 // Arduino build uses C++ so I must define functions properly
00195 
00196 #ifdef ARDUINO
00197 
00215 short XReceive(SDClass *pSD, HardwareSerial *pSer, const char *szFilename);
00216 
00232 int XSend(SDClass *pSD, HardwareSerial *pSer, const char *szFilename);
00233 
00234 #ifdef DEBUG_CODE
00235 const char *XMGetError(void);
00236 #endif // DEBUG_CODE
00237 
00238 #else // ARDUINO
00239 
00240 #ifdef __cplusplus
00241 extern "C" {
00242 #endif // __cplusplus
00243 
00259 int XReceive(SERIAL_TYPE hSer, const char *szFilename, int nMode);
00260 
00274 int XSend(SERIAL_TYPE hSer, const char *szFilename);
00275 
00276 #ifdef DEBUG_CODE
00277 const char *XMGetError(void);
00278 #endif // DEBUG_CODE
00279 
00280 #ifdef __cplusplus
00281 };
00282 #endif // __cplusplus
00283 
00284 #endif // ARDUINO
00285 
00286