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 USB_SERIAL_H
tax 0:66300c77c6e9 25 #define USB_SERIAL_H
tax 0:66300c77c6e9 26
tax 0:66300c77c6e9 27 //DG 2010
tax 0:66300c77c6e9 28 //Essentially a clone of Serial if
tax 0:66300c77c6e9 29 #include "Stream.h"
tax 0:66300c77c6e9 30 #include "mbed.h"
tax 0:66300c77c6e9 31
tax 0:66300c77c6e9 32 #include "drv/usb/UsbDevice.h"
tax 0:66300c77c6e9 33 #include "drv/usb/UsbEndpoint.h"
tax 0:66300c77c6e9 34
tax 0:66300c77c6e9 35 namespace mbed {
tax 0:66300c77c6e9 36
tax 0:66300c77c6e9 37 class UsbSerial : public Stream {
tax 0:66300c77c6e9 38
tax 0:66300c77c6e9 39 public:
tax 0:66300c77c6e9 40
tax 0:66300c77c6e9 41 UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL);
tax 0:66300c77c6e9 42 virtual ~UsbSerial();
tax 0:66300c77c6e9 43 //Apart from the ctor/dtor, exactly the same protos as Serial
tax 0:66300c77c6e9 44
tax 0:66300c77c6e9 45 void baud(int baudrate);
tax 0:66300c77c6e9 46
tax 0:66300c77c6e9 47 enum Parity {
tax 0:66300c77c6e9 48 None = 0,
tax 0:66300c77c6e9 49 Odd = 1,
tax 0:66300c77c6e9 50 Even = 2,
tax 0:66300c77c6e9 51 Forced1 = 3,
tax 0:66300c77c6e9 52 Forced0 = 4
tax 0:66300c77c6e9 53 };
tax 0:66300c77c6e9 54
tax 0:66300c77c6e9 55 enum IrqType {
tax 0:66300c77c6e9 56 RxIrq = 0
tax 0:66300c77c6e9 57 , TxIrq
tax 0:66300c77c6e9 58 };
tax 0:66300c77c6e9 59
tax 0:66300c77c6e9 60 void format(int bits, int parity, int stop);
tax 0:66300c77c6e9 61
tax 0:66300c77c6e9 62 class CDummy;
tax 0:66300c77c6e9 63 template <class T>
tax 0:66300c77c6e9 64 void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq)
tax 0:66300c77c6e9 65 {
tax 0:66300c77c6e9 66 if(type == RxIrq)
tax 0:66300c77c6e9 67 {
tax 0:66300c77c6e9 68 m_pInCbItem = (CDummy*) pCbItem;
tax 0:66300c77c6e9 69 m_pInCbMeth = (void (CDummy::*)()) pCbMeth;
tax 0:66300c77c6e9 70 }
tax 0:66300c77c6e9 71 else
tax 0:66300c77c6e9 72 {
tax 0:66300c77c6e9 73 m_pOutCbItem = (CDummy*) pCbItem;
tax 0:66300c77c6e9 74 m_pOutCbMeth = (void (CDummy::*)()) pCbMeth;
tax 0:66300c77c6e9 75 }
tax 0:66300c77c6e9 76 }
tax 0:66300c77c6e9 77
tax 0:66300c77c6e9 78 #if 0 // Inhereted from Stream, for documentation only
tax 0:66300c77c6e9 79
tax 0:66300c77c6e9 80 /* Function: putc
tax 0:66300c77c6e9 81 * Write a character
tax 0:66300c77c6e9 82 *
tax 0:66300c77c6e9 83 * Variables:
tax 0:66300c77c6e9 84 * c - The character to write to the serial port
tax 0:66300c77c6e9 85 */
tax 0:66300c77c6e9 86 int putc(int c);
tax 0:66300c77c6e9 87
tax 0:66300c77c6e9 88 /* Function: getc
tax 0:66300c77c6e9 89 * Read a character
tax 0:66300c77c6e9 90 *
tax 0:66300c77c6e9 91 * Variables:
tax 0:66300c77c6e9 92 * returns - The character read from the serial port
tax 0:66300c77c6e9 93 */
tax 0:66300c77c6e9 94 int getc();
tax 0:66300c77c6e9 95
tax 0:66300c77c6e9 96 /* Function: printf
tax 0:66300c77c6e9 97 * Write a formated string
tax 0:66300c77c6e9 98 *
tax 0:66300c77c6e9 99 * Variables:
tax 0:66300c77c6e9 100 * format - A printf-style format string, followed by the
tax 0:66300c77c6e9 101 * variables to use in formating the string.
tax 0:66300c77c6e9 102 */
tax 0:66300c77c6e9 103 int printf(const char* format, ...);
tax 0:66300c77c6e9 104
tax 0:66300c77c6e9 105 /* Function: scanf
tax 0:66300c77c6e9 106 * Read a formated string
tax 0:66300c77c6e9 107 *
tax 0:66300c77c6e9 108 * Variables:
tax 0:66300c77c6e9 109 * format - A scanf-style format string,
tax 0:66300c77c6e9 110 * followed by the pointers to variables to store the results.
tax 0:66300c77c6e9 111 */
tax 0:66300c77c6e9 112 int scanf(const char* format, ...);
tax 0:66300c77c6e9 113
tax 0:66300c77c6e9 114 #endif
tax 0:66300c77c6e9 115
tax 0:66300c77c6e9 116 /* Function: readable
tax 0:66300c77c6e9 117 * Determine if there is a character available to read
tax 0:66300c77c6e9 118 *
tax 0:66300c77c6e9 119 * Variables:
tax 0:66300c77c6e9 120 * returns - 1 if there is a character available to read, else 0
tax 0:66300c77c6e9 121 */
tax 0:66300c77c6e9 122 int readable();
tax 0:66300c77c6e9 123
tax 0:66300c77c6e9 124 /* Function: writeable
tax 0:66300c77c6e9 125 * Determine if there is space available to write a character
tax 0:66300c77c6e9 126 *
tax 0:66300c77c6e9 127 * Variables:
tax 0:66300c77c6e9 128 * returns - 1 if there is space to write a character, else 0
tax 0:66300c77c6e9 129 */
tax 0:66300c77c6e9 130 int writeable();
tax 0:66300c77c6e9 131
tax 0:66300c77c6e9 132 #ifdef MBED_RPC
tax 0:66300c77c6e9 133 virtual const struct rpc_method *get_rpc_methods();
tax 0:66300c77c6e9 134 static struct rpc_class *get_rpc_class();
tax 0:66300c77c6e9 135 #endif
tax 0:66300c77c6e9 136
tax 0:66300c77c6e9 137 protected:
tax 0:66300c77c6e9 138
tax 0:66300c77c6e9 139 virtual int _getc();
tax 0:66300c77c6e9 140 virtual int _putc(int c);
tax 0:66300c77c6e9 141
tax 0:66300c77c6e9 142 void onReadable();
tax 0:66300c77c6e9 143 void onWriteable();
tax 0:66300c77c6e9 144
tax 0:66300c77c6e9 145 void onEpInTransfer();
tax 0:66300c77c6e9 146 void onEpOutTransfer();
tax 0:66300c77c6e9 147
tax 0:66300c77c6e9 148 private:
tax 0:66300c77c6e9 149
tax 0:66300c77c6e9 150 UsbEndpoint m_epIn;
tax 0:66300c77c6e9 151 UsbEndpoint m_epOut;
tax 0:66300c77c6e9 152
tax 0:66300c77c6e9 153 CDummy* m_pInCbItem;
tax 0:66300c77c6e9 154 void (CDummy::*m_pInCbMeth)();
tax 0:66300c77c6e9 155
tax 0:66300c77c6e9 156 CDummy* m_pOutCbItem;
tax 0:66300c77c6e9 157 void (CDummy::*m_pOutCbMeth)();
tax 0:66300c77c6e9 158
tax 0:66300c77c6e9 159 void startTx();
tax 0:66300c77c6e9 160 void startRx();
tax 0:66300c77c6e9 161
tax 0:66300c77c6e9 162 Timeout m_txTimeout;
tax 0:66300c77c6e9 163 volatile bool m_timeout;
tax 0:66300c77c6e9 164
tax 0:66300c77c6e9 165 volatile char* m_inBufEven;
tax 0:66300c77c6e9 166 volatile char* m_inBufOdd;
tax 0:66300c77c6e9 167 volatile char* m_inBufUsr;
tax 0:66300c77c6e9 168 volatile char* m_inBufTrmt;
tax 0:66300c77c6e9 169
tax 0:66300c77c6e9 170 volatile char* m_outBufEven;
tax 0:66300c77c6e9 171 volatile char* m_outBufOdd;
tax 0:66300c77c6e9 172 volatile char* m_outBufUsr;
tax 0:66300c77c6e9 173 volatile char* m_outBufTrmt;
tax 0:66300c77c6e9 174
tax 0:66300c77c6e9 175 volatile int m_inBufLen;
tax 0:66300c77c6e9 176 volatile int m_outBufLen;
tax 0:66300c77c6e9 177
tax 0:66300c77c6e9 178 volatile char* m_pInBufPos;
tax 0:66300c77c6e9 179 volatile char* m_pOutBufPos;
tax 0:66300c77c6e9 180
tax 0:66300c77c6e9 181
tax 0:66300c77c6e9 182
tax 0:66300c77c6e9 183 };
tax 0:66300c77c6e9 184
tax 0:66300c77c6e9 185 }
tax 0:66300c77c6e9 186
tax 0:66300c77c6e9 187
tax 0:66300c77c6e9 188
tax 0:66300c77c6e9 189 #endif