HTTPClient using static IP

Dependencies:   mbed

Committer:
mr_q
Date:
Mon May 30 11:53:37 2011 +0000
Revision:
0:d8f2f7d5f31b
v0.01 Draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mr_q 0:d8f2f7d5f31b 1
mr_q 0:d8f2f7d5f31b 2 /*
mr_q 0:d8f2f7d5f31b 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mr_q 0:d8f2f7d5f31b 4
mr_q 0:d8f2f7d5f31b 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mr_q 0:d8f2f7d5f31b 6 of this software and associated documentation files (the "Software"), to deal
mr_q 0:d8f2f7d5f31b 7 in the Software without restriction, including without limitation the rights
mr_q 0:d8f2f7d5f31b 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mr_q 0:d8f2f7d5f31b 9 copies of the Software, and to permit persons to whom the Software is
mr_q 0:d8f2f7d5f31b 10 furnished to do so, subject to the following conditions:
mr_q 0:d8f2f7d5f31b 11
mr_q 0:d8f2f7d5f31b 12 The above copyright notice and this permission notice shall be included in
mr_q 0:d8f2f7d5f31b 13 all copies or substantial portions of the Software.
mr_q 0:d8f2f7d5f31b 14
mr_q 0:d8f2f7d5f31b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mr_q 0:d8f2f7d5f31b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mr_q 0:d8f2f7d5f31b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mr_q 0:d8f2f7d5f31b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mr_q 0:d8f2f7d5f31b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mr_q 0:d8f2f7d5f31b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mr_q 0:d8f2f7d5f31b 21 THE SOFTWARE.
mr_q 0:d8f2f7d5f31b 22 */
mr_q 0:d8f2f7d5f31b 23
mr_q 0:d8f2f7d5f31b 24 #ifndef USB_SERIAL_H
mr_q 0:d8f2f7d5f31b 25 #define USB_SERIAL_H
mr_q 0:d8f2f7d5f31b 26
mr_q 0:d8f2f7d5f31b 27 //DG 2010
mr_q 0:d8f2f7d5f31b 28 //Essentially a clone of Serial if
mr_q 0:d8f2f7d5f31b 29 #include "Stream.h"
mr_q 0:d8f2f7d5f31b 30 #include "mbed.h"
mr_q 0:d8f2f7d5f31b 31
mr_q 0:d8f2f7d5f31b 32 #include "drv/usb/UsbDevice.h"
mr_q 0:d8f2f7d5f31b 33 #include "drv/usb/UsbEndpoint.h"
mr_q 0:d8f2f7d5f31b 34
mr_q 0:d8f2f7d5f31b 35 namespace mbed {
mr_q 0:d8f2f7d5f31b 36
mr_q 0:d8f2f7d5f31b 37 class UsbSerial : public Stream {
mr_q 0:d8f2f7d5f31b 38
mr_q 0:d8f2f7d5f31b 39 public:
mr_q 0:d8f2f7d5f31b 40
mr_q 0:d8f2f7d5f31b 41 UsbSerial(UsbDevice* pDevice, int epIn, int epOut, const char* name = NULL);
mr_q 0:d8f2f7d5f31b 42 virtual ~UsbSerial();
mr_q 0:d8f2f7d5f31b 43 //Apart from the ctor/dtor, exactly the same protos as Serial
mr_q 0:d8f2f7d5f31b 44
mr_q 0:d8f2f7d5f31b 45 void baud(int baudrate);
mr_q 0:d8f2f7d5f31b 46
mr_q 0:d8f2f7d5f31b 47 enum Parity {
mr_q 0:d8f2f7d5f31b 48 None = 0,
mr_q 0:d8f2f7d5f31b 49 Odd = 1,
mr_q 0:d8f2f7d5f31b 50 Even = 2,
mr_q 0:d8f2f7d5f31b 51 Forced1 = 3,
mr_q 0:d8f2f7d5f31b 52 Forced0 = 4
mr_q 0:d8f2f7d5f31b 53 };
mr_q 0:d8f2f7d5f31b 54
mr_q 0:d8f2f7d5f31b 55 enum IrqType {
mr_q 0:d8f2f7d5f31b 56 RxIrq = 0
mr_q 0:d8f2f7d5f31b 57 , TxIrq
mr_q 0:d8f2f7d5f31b 58 };
mr_q 0:d8f2f7d5f31b 59
mr_q 0:d8f2f7d5f31b 60 void format(int bits, int parity, int stop);
mr_q 0:d8f2f7d5f31b 61
mr_q 0:d8f2f7d5f31b 62 class CDummy;
mr_q 0:d8f2f7d5f31b 63 template <class T>
mr_q 0:d8f2f7d5f31b 64 void attach(T* pCbItem, void (T::*pCbMeth)(), IrqType type = RxIrq)
mr_q 0:d8f2f7d5f31b 65 {
mr_q 0:d8f2f7d5f31b 66 if(type == RxIrq)
mr_q 0:d8f2f7d5f31b 67 {
mr_q 0:d8f2f7d5f31b 68 m_pInCbItem = (CDummy*) pCbItem;
mr_q 0:d8f2f7d5f31b 69 m_pInCbMeth = (void (CDummy::*)()) pCbMeth;
mr_q 0:d8f2f7d5f31b 70 }
mr_q 0:d8f2f7d5f31b 71 else
mr_q 0:d8f2f7d5f31b 72 {
mr_q 0:d8f2f7d5f31b 73 m_pOutCbItem = (CDummy*) pCbItem;
mr_q 0:d8f2f7d5f31b 74 m_pOutCbMeth = (void (CDummy::*)()) pCbMeth;
mr_q 0:d8f2f7d5f31b 75 }
mr_q 0:d8f2f7d5f31b 76 }
mr_q 0:d8f2f7d5f31b 77
mr_q 0:d8f2f7d5f31b 78 #if 0 // Inhereted from Stream, for documentation only
mr_q 0:d8f2f7d5f31b 79
mr_q 0:d8f2f7d5f31b 80 /* Function: putc
mr_q 0:d8f2f7d5f31b 81 * Write a character
mr_q 0:d8f2f7d5f31b 82 *
mr_q 0:d8f2f7d5f31b 83 * Variables:
mr_q 0:d8f2f7d5f31b 84 * c - The character to write to the serial port
mr_q 0:d8f2f7d5f31b 85 */
mr_q 0:d8f2f7d5f31b 86 int putc(int c);
mr_q 0:d8f2f7d5f31b 87
mr_q 0:d8f2f7d5f31b 88 /* Function: getc
mr_q 0:d8f2f7d5f31b 89 * Read a character
mr_q 0:d8f2f7d5f31b 90 *
mr_q 0:d8f2f7d5f31b 91 * Variables:
mr_q 0:d8f2f7d5f31b 92 * returns - The character read from the serial port
mr_q 0:d8f2f7d5f31b 93 */
mr_q 0:d8f2f7d5f31b 94 int getc();
mr_q 0:d8f2f7d5f31b 95
mr_q 0:d8f2f7d5f31b 96 /* Function: printf
mr_q 0:d8f2f7d5f31b 97 * Write a formated string
mr_q 0:d8f2f7d5f31b 98 *
mr_q 0:d8f2f7d5f31b 99 * Variables:
mr_q 0:d8f2f7d5f31b 100 * format - A printf-style format string, followed by the
mr_q 0:d8f2f7d5f31b 101 * variables to use in formating the string.
mr_q 0:d8f2f7d5f31b 102 */
mr_q 0:d8f2f7d5f31b 103 int printf(const char* format, ...);
mr_q 0:d8f2f7d5f31b 104
mr_q 0:d8f2f7d5f31b 105 /* Function: scanf
mr_q 0:d8f2f7d5f31b 106 * Read a formated string
mr_q 0:d8f2f7d5f31b 107 *
mr_q 0:d8f2f7d5f31b 108 * Variables:
mr_q 0:d8f2f7d5f31b 109 * format - A scanf-style format string,
mr_q 0:d8f2f7d5f31b 110 * followed by the pointers to variables to store the results.
mr_q 0:d8f2f7d5f31b 111 */
mr_q 0:d8f2f7d5f31b 112 int scanf(const char* format, ...);
mr_q 0:d8f2f7d5f31b 113
mr_q 0:d8f2f7d5f31b 114 #endif
mr_q 0:d8f2f7d5f31b 115
mr_q 0:d8f2f7d5f31b 116 /* Function: readable
mr_q 0:d8f2f7d5f31b 117 * Determine if there is a character available to read
mr_q 0:d8f2f7d5f31b 118 *
mr_q 0:d8f2f7d5f31b 119 * Variables:
mr_q 0:d8f2f7d5f31b 120 * returns - 1 if there is a character available to read, else 0
mr_q 0:d8f2f7d5f31b 121 */
mr_q 0:d8f2f7d5f31b 122 int readable();
mr_q 0:d8f2f7d5f31b 123
mr_q 0:d8f2f7d5f31b 124 /* Function: writeable
mr_q 0:d8f2f7d5f31b 125 * Determine if there is space available to write a character
mr_q 0:d8f2f7d5f31b 126 *
mr_q 0:d8f2f7d5f31b 127 * Variables:
mr_q 0:d8f2f7d5f31b 128 * returns - 1 if there is space to write a character, else 0
mr_q 0:d8f2f7d5f31b 129 */
mr_q 0:d8f2f7d5f31b 130 int writeable();
mr_q 0:d8f2f7d5f31b 131
mr_q 0:d8f2f7d5f31b 132 #ifdef MBED_RPC
mr_q 0:d8f2f7d5f31b 133 virtual const struct rpc_method *get_rpc_methods();
mr_q 0:d8f2f7d5f31b 134 static struct rpc_class *get_rpc_class();
mr_q 0:d8f2f7d5f31b 135 #endif
mr_q 0:d8f2f7d5f31b 136
mr_q 0:d8f2f7d5f31b 137 protected:
mr_q 0:d8f2f7d5f31b 138
mr_q 0:d8f2f7d5f31b 139 virtual int _getc();
mr_q 0:d8f2f7d5f31b 140 virtual int _putc(int c);
mr_q 0:d8f2f7d5f31b 141
mr_q 0:d8f2f7d5f31b 142 void onReadable();
mr_q 0:d8f2f7d5f31b 143 void onWriteable();
mr_q 0:d8f2f7d5f31b 144
mr_q 0:d8f2f7d5f31b 145 void onEpInTransfer();
mr_q 0:d8f2f7d5f31b 146 void onEpOutTransfer();
mr_q 0:d8f2f7d5f31b 147
mr_q 0:d8f2f7d5f31b 148 private:
mr_q 0:d8f2f7d5f31b 149
mr_q 0:d8f2f7d5f31b 150 UsbEndpoint m_epIn;
mr_q 0:d8f2f7d5f31b 151 UsbEndpoint m_epOut;
mr_q 0:d8f2f7d5f31b 152
mr_q 0:d8f2f7d5f31b 153 CDummy* m_pInCbItem;
mr_q 0:d8f2f7d5f31b 154 void (CDummy::*m_pInCbMeth)();
mr_q 0:d8f2f7d5f31b 155
mr_q 0:d8f2f7d5f31b 156 CDummy* m_pOutCbItem;
mr_q 0:d8f2f7d5f31b 157 void (CDummy::*m_pOutCbMeth)();
mr_q 0:d8f2f7d5f31b 158
mr_q 0:d8f2f7d5f31b 159 void startTx();
mr_q 0:d8f2f7d5f31b 160 void startRx();
mr_q 0:d8f2f7d5f31b 161
mr_q 0:d8f2f7d5f31b 162 Timeout m_txTimeout;
mr_q 0:d8f2f7d5f31b 163 volatile bool m_timeout;
mr_q 0:d8f2f7d5f31b 164
mr_q 0:d8f2f7d5f31b 165 volatile char* m_inBufEven;
mr_q 0:d8f2f7d5f31b 166 volatile char* m_inBufOdd;
mr_q 0:d8f2f7d5f31b 167 volatile char* m_inBufUsr;
mr_q 0:d8f2f7d5f31b 168 volatile char* m_inBufTrmt;
mr_q 0:d8f2f7d5f31b 169
mr_q 0:d8f2f7d5f31b 170 volatile char* m_outBufEven;
mr_q 0:d8f2f7d5f31b 171 volatile char* m_outBufOdd;
mr_q 0:d8f2f7d5f31b 172 volatile char* m_outBufUsr;
mr_q 0:d8f2f7d5f31b 173 volatile char* m_outBufTrmt;
mr_q 0:d8f2f7d5f31b 174
mr_q 0:d8f2f7d5f31b 175 volatile int m_inBufLen;
mr_q 0:d8f2f7d5f31b 176 volatile int m_outBufLen;
mr_q 0:d8f2f7d5f31b 177
mr_q 0:d8f2f7d5f31b 178 volatile char* m_pInBufPos;
mr_q 0:d8f2f7d5f31b 179 volatile char* m_pOutBufPos;
mr_q 0:d8f2f7d5f31b 180
mr_q 0:d8f2f7d5f31b 181
mr_q 0:d8f2f7d5f31b 182
mr_q 0:d8f2f7d5f31b 183 };
mr_q 0:d8f2f7d5f31b 184
mr_q 0:d8f2f7d5f31b 185 }
mr_q 0:d8f2f7d5f31b 186
mr_q 0:d8f2f7d5f31b 187
mr_q 0:d8f2f7d5f31b 188
mr_q 0:d8f2f7d5f31b 189 #endif