Bonjour/Zerconf library

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

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