This is the project for the Old Model Robots for OU's Dr. Davis's Configurable Robots Research. This is being published so future robots can be set up easily.

Dependencies:   FatFileSystem MCP3008 Motor PinDetect QTR_8A SRF05 SSD1308_128x64_I2C mbed

Committer:
DrewSchaef
Date:
Wed Nov 01 15:57:59 2017 +0000
Revision:
0:bcad524c1856
Published the project to allow access for future work on the Configurable Robots Research Project(s).

Who changed what in which revision?

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