Simons Wii controlled m3pi program

Dependencies:   mbed m3pi ID12RFIDIRQ

Committer:
chris
Date:
Wed May 18 14:50:46 2011 +0000
Revision:
0:0ab65a1aef12
Added some printing to the m3pi screen

Who changed what in which revision?

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