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