Dependencies:   mbed

Committer:
ICTFBI
Date:
Fri Oct 16 14:28:26 2015 +0000
Revision:
0:4edb816d21e1
Pre-update 16-10-15

Who changed what in which revision?

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