Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

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