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