HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mr_q 0:d8f2f7d5f31b 1
mr_q 0:d8f2f7d5f31b 2 /*
mr_q 0:d8f2f7d5f31b 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mr_q 0:d8f2f7d5f31b 4
mr_q 0:d8f2f7d5f31b 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mr_q 0:d8f2f7d5f31b 6 of this software and associated documentation files (the "Software"), to deal
mr_q 0:d8f2f7d5f31b 7 in the Software without restriction, including without limitation the rights
mr_q 0:d8f2f7d5f31b 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mr_q 0:d8f2f7d5f31b 9 copies of the Software, and to permit persons to whom the Software is
mr_q 0:d8f2f7d5f31b 10 furnished to do so, subject to the following conditions:
mr_q 0:d8f2f7d5f31b 11
mr_q 0:d8f2f7d5f31b 12 The above copyright notice and this permission notice shall be included in
mr_q 0:d8f2f7d5f31b 13 all copies or substantial portions of the Software.
mr_q 0:d8f2f7d5f31b 14
mr_q 0:d8f2f7d5f31b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mr_q 0:d8f2f7d5f31b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mr_q 0:d8f2f7d5f31b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mr_q 0:d8f2f7d5f31b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mr_q 0:d8f2f7d5f31b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mr_q 0:d8f2f7d5f31b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mr_q 0:d8f2f7d5f31b 21 THE SOFTWARE.
mr_q 0:d8f2f7d5f31b 22 */
mr_q 0:d8f2f7d5f31b 23
mr_q 0:d8f2f7d5f31b 24 #ifndef ATIF_H
mr_q 0:d8f2f7d5f31b 25 #define ATIF_H
mr_q 0:d8f2f7d5f31b 26
mr_q 0:d8f2f7d5f31b 27 #include "netCfg.h"
mr_q 0:d8f2f7d5f31b 28
mr_q 0:d8f2f7d5f31b 29 #include "mbed.h"
mr_q 0:d8f2f7d5f31b 30 #include "drv/serial/buf/SerialBuf.h"
mr_q 0:d8f2f7d5f31b 31 #include <list>
mr_q 0:d8f2f7d5f31b 32 using std::list;
mr_q 0:d8f2f7d5f31b 33
mr_q 0:d8f2f7d5f31b 34 //class Serial; //Pb w forward decl
mr_q 0:d8f2f7d5f31b 35
mr_q 0:d8f2f7d5f31b 36 enum ATErr
mr_q 0:d8f2f7d5f31b 37 {
mr_q 0:d8f2f7d5f31b 38 __AT_MIN = -0xFFFF,
mr_q 0:d8f2f7d5f31b 39 AT_CLOSED,
mr_q 0:d8f2f7d5f31b 40 AT_NOANSWER,
mr_q 0:d8f2f7d5f31b 41 AT_ERROR,
mr_q 0:d8f2f7d5f31b 42 AT_TIMEOUT,
mr_q 0:d8f2f7d5f31b 43 AT_BUSY,
mr_q 0:d8f2f7d5f31b 44 AT_PARSE,
mr_q 0:d8f2f7d5f31b 45 AT_INCOMPLETE,
mr_q 0:d8f2f7d5f31b 46 AT_OK = 0
mr_q 0:d8f2f7d5f31b 47 };
mr_q 0:d8f2f7d5f31b 48
mr_q 0:d8f2f7d5f31b 49 class ATIf : public SerialBuf
mr_q 0:d8f2f7d5f31b 50 {
mr_q 0:d8f2f7d5f31b 51 public:
mr_q 0:d8f2f7d5f31b 52
mr_q 0:d8f2f7d5f31b 53 ATIf();
mr_q 0:d8f2f7d5f31b 54 virtual ~ATIf();
mr_q 0:d8f2f7d5f31b 55
mr_q 0:d8f2f7d5f31b 56 #if 0
mr_q 0:d8f2f7d5f31b 57 template<class T>
mr_q 0:d8f2f7d5f31b 58 //void attachSignal( const char* sigName, T* pItem, bool (T::*pMethod)(ATIf*, bool, bool*) ); //Attach Signal ("Unsollicited response code" in Telit_AT_Reference_Guide.pdf) to an handler fn
mr_q 0:d8f2f7d5f31b 59 //Linker bug : Must be defined here :(
mr_q 0:d8f2f7d5f31b 60 void attachSignal( const char* sigName, T* pItem, bool (T::*pMethod)(ATIf*, bool, bool*) ) //Attach Signal ("Unsollicited response code" in Telit_AT_Reference_Guide.pdf) to an handler fn
mr_q 0:d8f2f7d5f31b 61 {
mr_q 0:d8f2f7d5f31b 62 ATSigHandler sig(sigName, (ATSigHandler::CDummy*)pItem, (bool (ATSigHandler::CDummy::*)(ATIf*, bool, bool*))pMethod);
mr_q 0:d8f2f7d5f31b 63 m_signals.push_back(sig);
mr_q 0:d8f2f7d5f31b 64 }
mr_q 0:d8f2f7d5f31b 65 void detachSignal( const char* sigName );
mr_q 0:d8f2f7d5f31b 66 #endif
mr_q 0:d8f2f7d5f31b 67
mr_q 0:d8f2f7d5f31b 68 ATErr open(Serial* pSerial); //Deactivate echo, etc
mr_q 0:d8f2f7d5f31b 69 #if NET_USB_SERIAL
mr_q 0:d8f2f7d5f31b 70 ATErr open(UsbSerial* pUsbSerial); //Deactivate echo, etc
mr_q 0:d8f2f7d5f31b 71 #endif
mr_q 0:d8f2f7d5f31b 72 ATErr close(); //Release port
mr_q 0:d8f2f7d5f31b 73
mr_q 0:d8f2f7d5f31b 74 int printf(const char* format, ... );
mr_q 0:d8f2f7d5f31b 75 int scanf(const char* format, ... );
mr_q 0:d8f2f7d5f31b 76 void setTimeout(int timeout); //used by scanf
mr_q 0:d8f2f7d5f31b 77 void setLineMode(bool lineMode); //Switch btw line & raw fns
mr_q 0:d8f2f7d5f31b 78 //void setSignals(bool signalsEnable);
mr_q 0:d8f2f7d5f31b 79 ATErr flushBuffer(); //Discard input buffer
mr_q 0:d8f2f7d5f31b 80 ATErr flushLine(int timeout); //Discard input buffer until CRLF is encountered
mr_q 0:d8f2f7d5f31b 81
mr_q 0:d8f2f7d5f31b 82 protected:
mr_q 0:d8f2f7d5f31b 83 //virtual bool onRead(); //Inherited from SerialBuf, return true if data is incomplete
mr_q 0:d8f2f7d5f31b 84 ATErr rawOpen(Serial* pSerial, int baudrate); //Simple open function for similar non-conforming protocols
mr_q 0:d8f2f7d5f31b 85
mr_q 0:d8f2f7d5f31b 86 public:
mr_q 0:d8f2f7d5f31b 87 /* ATErr command(const char* cmd, char* result, int resultLen, int timeout); */ //Kinda useless
mr_q 0:d8f2f7d5f31b 88 ATErr write(const char* cmd, bool lineMode = false);
mr_q 0:d8f2f7d5f31b 89 ATErr read(char* result, int resultMaxLen, int timeout, bool lineMode = false, int resultMinLen = 0);
mr_q 0:d8f2f7d5f31b 90 bool isOpen();
mr_q 0:d8f2f7d5f31b 91 ATErr checkOK(); //Helper fn to quickly check that OK has been returned
mr_q 0:d8f2f7d5f31b 92
mr_q 0:d8f2f7d5f31b 93 private:
mr_q 0:d8f2f7d5f31b 94 int readLine(char* line, int maxLen, int timeout); //Read a single line from serial port
mr_q 0:d8f2f7d5f31b 95 int writeLine(const char* line); //Write a single line to serial port
mr_q 0:d8f2f7d5f31b 96
mr_q 0:d8f2f7d5f31b 97 int readRaw(char* str, int maxLen, int timeout = 0, int minLen = 0); //Read from serial port in buf
mr_q 0:d8f2f7d5f31b 98 int writeRaw(const char* str); //Write directly to serial port
mr_q 0:d8f2f7d5f31b 99
mr_q 0:d8f2f7d5f31b 100 volatile int m_readTimeout;
mr_q 0:d8f2f7d5f31b 101 volatile bool m_lineMode;
mr_q 0:d8f2f7d5f31b 102 //bool m_signalsEnable;
mr_q 0:d8f2f7d5f31b 103 bool m_isOpen;
mr_q 0:d8f2f7d5f31b 104
mr_q 0:d8f2f7d5f31b 105 char* m_tmpBuf;
mr_q 0:d8f2f7d5f31b 106
mr_q 0:d8f2f7d5f31b 107 #if 0
mr_q 0:d8f2f7d5f31b 108 class ATSigHandler
mr_q 0:d8f2f7d5f31b 109 {
mr_q 0:d8f2f7d5f31b 110 class CDummy;
mr_q 0:d8f2f7d5f31b 111 public:
mr_q 0:d8f2f7d5f31b 112 ATSigHandler(const char* name, CDummy* cbObj, bool (CDummy::*cbMeth)(ATIf* pIf, bool beg, bool* pMoreData)) : m_cbObj(cbObj), m_cbMeth(cbMeth), m_name(name)
mr_q 0:d8f2f7d5f31b 113 {}
mr_q 0:d8f2f7d5f31b 114 protected:
mr_q 0:d8f2f7d5f31b 115 CDummy* m_cbObj;
mr_q 0:d8f2f7d5f31b 116 bool (CDummy::*m_cbMeth)(ATIf* pIf, bool beg, bool* pMoreData); //*pMoreData set to true if needs to read next line, beg = true if beginning of new code
mr_q 0:d8f2f7d5f31b 117 const char* m_name;
mr_q 0:d8f2f7d5f31b 118
mr_q 0:d8f2f7d5f31b 119 friend class ATIf;
mr_q 0:d8f2f7d5f31b 120 };
mr_q 0:d8f2f7d5f31b 121
mr_q 0:d8f2f7d5f31b 122 volatile ATSigHandler* m_pCurrentSignal; //Signal that asked more data
mr_q 0:d8f2f7d5f31b 123
mr_q 0:d8f2f7d5f31b 124 bool handleSignal(); //Returns true if signal has been handled
mr_q 0:d8f2f7d5f31b 125 list<ATSigHandler> m_signals;
mr_q 0:d8f2f7d5f31b 126 #endif
mr_q 0:d8f2f7d5f31b 127
mr_q 0:d8f2f7d5f31b 128 };
mr_q 0:d8f2f7d5f31b 129
mr_q 0:d8f2f7d5f31b 130 #endif