Dependents:   UMTSStickNetIfExample PMK_UMTSStickNetIfExample

Committer:
donatien
Date:
Fri Jul 09 14:51:11 2010 +0000
Revision:
0:45cd39946923

        

Who changed what in which revision?

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