SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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