I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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