Simon Ford / Mbed 2 deprecated WiiRacing

Dependencies:   mbed m3pi ID12RFIDIRQ

Committer:
simon
Date:
Mon Apr 11 23:03:22 2011 +0000
Revision:
0:e2ef12467862

        

Who changed what in which revision?

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