This is a for debugging \\\\\\\"BLUE USB\\\\\\\". You can connect with HCI mode. How to connect White Wizard Board TANK *White Wizard Board - Motor Driver Board * p 21 - IN_R1 * p 22 - IN_R2 * p 23 - IN_L2 * p 24 - IN_L1

Dependencies:   mbed

Committer:
halfpitch
Date:
Sun Jul 10 01:31:52 2011 +0000
Revision:
0:a6476c138e84

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
halfpitch 0:a6476c138e84 1 /*
halfpitch 0:a6476c138e84 2 Copyright (c) 2010 Peter Barrett
halfpitch 0:a6476c138e84 3
halfpitch 0:a6476c138e84 4 Permission is hereby granted, free of charge, to any person obtaining a copy
halfpitch 0:a6476c138e84 5 of this software and associated documentation files (the "Software"), to deal
halfpitch 0:a6476c138e84 6 in the Software without restriction, including without limitation the rights
halfpitch 0:a6476c138e84 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
halfpitch 0:a6476c138e84 8 copies of the Software, and to permit persons to whom the Software is
halfpitch 0:a6476c138e84 9 furnished to do so, subject to the following conditions:
halfpitch 0:a6476c138e84 10
halfpitch 0:a6476c138e84 11 The above copyright notice and this permission notice shall be included in
halfpitch 0:a6476c138e84 12 all copies or substantial portions of the Software.
halfpitch 0:a6476c138e84 13
halfpitch 0:a6476c138e84 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
halfpitch 0:a6476c138e84 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
halfpitch 0:a6476c138e84 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
halfpitch 0:a6476c138e84 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
halfpitch 0:a6476c138e84 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
halfpitch 0:a6476c138e84 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
halfpitch 0:a6476c138e84 20 THE SOFTWARE.
halfpitch 0:a6476c138e84 21 */
halfpitch 0:a6476c138e84 22
halfpitch 0:a6476c138e84 23 #ifndef SOCKET_H_INCLUDED
halfpitch 0:a6476c138e84 24 #define SOCKET_H_INCLUDED
halfpitch 0:a6476c138e84 25
halfpitch 0:a6476c138e84 26 #define SOCKET_HCI 1
halfpitch 0:a6476c138e84 27 #define SOCKET_L2CAP 2
halfpitch 0:a6476c138e84 28 #define SOCKET_RFCOM 3
halfpitch 0:a6476c138e84 29
halfpitch 0:a6476c138e84 30 typedef struct
halfpitch 0:a6476c138e84 31 {
halfpitch 0:a6476c138e84 32 u8 AddressSpecific[0]; // BDADDR,psm etc
halfpitch 0:a6476c138e84 33 } SocketAddrHdr;
halfpitch 0:a6476c138e84 34
halfpitch 0:a6476c138e84 35 enum SocketState
halfpitch 0:a6476c138e84 36 {
halfpitch 0:a6476c138e84 37 SocketState_Unknown,
halfpitch 0:a6476c138e84 38 SocketState_Opening,
halfpitch 0:a6476c138e84 39 SocketState_Open,
halfpitch 0:a6476c138e84 40 SocketState_Closing,
halfpitch 0:a6476c138e84 41 SocketState_Closed
halfpitch 0:a6476c138e84 42 };
halfpitch 0:a6476c138e84 43
halfpitch 0:a6476c138e84 44 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
halfpitch 0:a6476c138e84 45
halfpitch 0:a6476c138e84 46 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData); // Open a socket
halfpitch 0:a6476c138e84 47 int Socket_Send(int socket, const u8* data, int len);
halfpitch 0:a6476c138e84 48 int Socket_State(int socket);
halfpitch 0:a6476c138e84 49 int Socket_Close(int socket);
halfpitch 0:a6476c138e84 50
halfpitch 0:a6476c138e84 51 //===========================================================================
halfpitch 0:a6476c138e84 52 //===========================================================================
halfpitch 0:a6476c138e84 53 // Don't need to look at or use anything below this line:
halfpitch 0:a6476c138e84 54 // Internal representation of socket
halfpitch 0:a6476c138e84 55
halfpitch 0:a6476c138e84 56 class SocketHandler;
halfpitch 0:a6476c138e84 57 class SocketInternal
halfpitch 0:a6476c138e84 58 {
halfpitch 0:a6476c138e84 59 public:
halfpitch 0:a6476c138e84 60
halfpitch 0:a6476c138e84 61 u8 ID;
halfpitch 0:a6476c138e84 62 u8 State;
halfpitch 0:a6476c138e84 63 u8 Type;
halfpitch 0:a6476c138e84 64 u8 B0;
halfpitch 0:a6476c138e84 65 SocketCallback Callback;
halfpitch 0:a6476c138e84 66 void* userData;
halfpitch 0:a6476c138e84 67 u8 Data[0]; // Extra socket data starts here
halfpitch 0:a6476c138e84 68
halfpitch 0:a6476c138e84 69 void Recv(const u8* data, int len)
halfpitch 0:a6476c138e84 70 {
halfpitch 0:a6476c138e84 71 Callback(ID,(SocketState)State,data,len,userData);
halfpitch 0:a6476c138e84 72 }
halfpitch 0:a6476c138e84 73
halfpitch 0:a6476c138e84 74 void SetState(SocketState state)
halfpitch 0:a6476c138e84 75 {
halfpitch 0:a6476c138e84 76 State = state;
halfpitch 0:a6476c138e84 77 Callback(ID,(SocketState)State,0,0,userData);
halfpitch 0:a6476c138e84 78 }
halfpitch 0:a6476c138e84 79 };
halfpitch 0:a6476c138e84 80
halfpitch 0:a6476c138e84 81 class SocketHandler
halfpitch 0:a6476c138e84 82 {
halfpitch 0:a6476c138e84 83 public:
halfpitch 0:a6476c138e84 84 virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
halfpitch 0:a6476c138e84 85 virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
halfpitch 0:a6476c138e84 86 virtual int Close(SocketInternal* sock) = 0;
halfpitch 0:a6476c138e84 87 };
halfpitch 0:a6476c138e84 88
halfpitch 0:a6476c138e84 89 int RegisterSocketHandler(int type, SocketHandler* handler);
halfpitch 0:a6476c138e84 90 SocketInternal* GetSocketInternal(int socket);
halfpitch 0:a6476c138e84 91
halfpitch 0:a6476c138e84 92 #define ERR_SOCKET_TYPE_NOT_FOUND -200
halfpitch 0:a6476c138e84 93 #define ERR_SOCKET_NOT_FOUND -201
halfpitch 0:a6476c138e84 94 #define ERR_SOCKET_NONE_LEFT -202
halfpitch 0:a6476c138e84 95
halfpitch 0:a6476c138e84 96 #endif // SOCKET_H_INCLUDED