First step: AutoIP compiled in and working

Dependencies:   mbed

Committer:
darran
Date:
Fri Jun 18 09:11:35 2010 +0000
Revision:
0:55a05330f8cc

        

Who changed what in which revision?

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