Rik Van Dyck / Mbed 2 deprecated Project_Embedded_C

Dependencies:   mbed DS1307 Servo TextLCD

Committer:
rikvandyck
Date:
Thu Dec 18 10:43:07 2014 +0000
Revision:
2:55b6fd49b738
Parent:
0:e1edd52b1ee2
Project_Embedded_C

Who changed what in which revision?

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