Pulse Oximeter (NONIN) communicates with mbed via Bluetooth dongle and sends Heart Rate and Oxygen Saturation via GPRS module

Dependencies:   C12832 GPS GSM mbed

Fork of myBlueUSB_localfix by Nobuaki Aoki

Committer:
nobukuma
Date:
Sat Dec 07 14:19:00 2013 +0000
Revision:
0:003889bc474f
http://mbed.org/users/networker/code/myBlueUSB/ rev13??rev12??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nobukuma 0:003889bc474f 1 /*
nobukuma 0:003889bc474f 2 Copyright (c) 2010 Peter Barrett
nobukuma 0:003889bc474f 3
nobukuma 0:003889bc474f 4 Permission is hereby granted, free of charge, to any person obtaining a copy
nobukuma 0:003889bc474f 5 of this software and associated documentation files (the "Software"), to deal
nobukuma 0:003889bc474f 6 in the Software without restriction, including without limitation the rights
nobukuma 0:003889bc474f 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
nobukuma 0:003889bc474f 8 copies of the Software, and to permit persons to whom the Software is
nobukuma 0:003889bc474f 9 furnished to do so, subject to the following conditions:
nobukuma 0:003889bc474f 10
nobukuma 0:003889bc474f 11 The above copyright notice and this permission notice shall be included in
nobukuma 0:003889bc474f 12 all copies or substantial portions of the Software.
nobukuma 0:003889bc474f 13
nobukuma 0:003889bc474f 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
nobukuma 0:003889bc474f 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
nobukuma 0:003889bc474f 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
nobukuma 0:003889bc474f 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
nobukuma 0:003889bc474f 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
nobukuma 0:003889bc474f 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
nobukuma 0:003889bc474f 20 THE SOFTWARE.
nobukuma 0:003889bc474f 21 */
nobukuma 0:003889bc474f 22
nobukuma 0:003889bc474f 23 #ifndef SOCKET_H_INCLUDED
nobukuma 0:003889bc474f 24 #define SOCKET_H_INCLUDED
nobukuma 0:003889bc474f 25
nobukuma 0:003889bc474f 26 #define SOCKET_HCI 1
nobukuma 0:003889bc474f 27 #define SOCKET_L2CAP 2
nobukuma 0:003889bc474f 28 #define SOCKET_RFCOM 3
nobukuma 0:003889bc474f 29 #define SOCKET_SDP 4
nobukuma 0:003889bc474f 30
nobukuma 0:003889bc474f 31 #define SO_RECBUF 1
nobukuma 0:003889bc474f 32 #define SO_SNDBUF 2
nobukuma 0:003889bc474f 33 #define NOPROTOOPT -100
nobukuma 0:003889bc474f 34
nobukuma 0:003889bc474f 35 typedef struct
nobukuma 0:003889bc474f 36 {
nobukuma 0:003889bc474f 37 u8 AddressSpecific[0]; // BDADDR,psm etc
nobukuma 0:003889bc474f 38 } SocketAddrHdr;
nobukuma 0:003889bc474f 39
nobukuma 0:003889bc474f 40 enum SocketState
nobukuma 0:003889bc474f 41 {
nobukuma 0:003889bc474f 42 SocketState_Unknown,
nobukuma 0:003889bc474f 43 SocketState_Opening,
nobukuma 0:003889bc474f 44 SocketState_Open,
nobukuma 0:003889bc474f 45 SocketState_Closing,
nobukuma 0:003889bc474f 46 SocketState_Closed,
nobukuma 0:003889bc474f 47 SocketState_Listen,
nobukuma 0:003889bc474f 48 SocketState_Accepting,
nobukuma 0:003889bc474f 49 SocketState_L2CAP_WaitConnect = 8,
nobukuma 0:003889bc474f 50 SocketState_L2CAP_WaitConnectRsp,
nobukuma 0:003889bc474f 51 SocketState_L2CAP_WaitDisconnect,
nobukuma 0:003889bc474f 52 SocketState_L2CAP_Config_wait = 16,
nobukuma 0:003889bc474f 53 SocketState_L2CAP_Config_wait_send,
nobukuma 0:003889bc474f 54 SocketState_L2CAP_Config_wait_req,
nobukuma 0:003889bc474f 55 SocketState_L2CAP_Config_wait_rsp,
nobukuma 0:003889bc474f 56 SocketState_L2CAP_Config_wait_reqrsp
nobukuma 0:003889bc474f 57 };
nobukuma 0:003889bc474f 58
nobukuma 0:003889bc474f 59 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
nobukuma 0:003889bc474f 60
nobukuma 0:003889bc474f 61 int Socket_Create(int type, SocketCallback callback, void* userData); // Allocate a socket
nobukuma 0:003889bc474f 62 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData); // Open a socket
nobukuma 0:003889bc474f 63 int Socket_Listen(int type, int channel, SocketCallback callback, void* userData); // Open a socket passive
nobukuma 0:003889bc474f 64 int Socket_Accept(int type, int scid, int rxid, SocketCallback callback, void* userData); // Open a socket for an incoming connection
nobukuma 0:003889bc474f 65 int Socket_SetOpt(int socket, int so, int* data, int len);
nobukuma 0:003889bc474f 66 int Socket_GetOpt(int socket, int so, int* data, int len);
nobukuma 0:003889bc474f 67 int Socket_Send(int socket, const u8* data, int len);
nobukuma 0:003889bc474f 68 int Socket_State(int socket);
nobukuma 0:003889bc474f 69 int Socket_Close(int socket);
nobukuma 0:003889bc474f 70
nobukuma 0:003889bc474f 71 //===========================================================================
nobukuma 0:003889bc474f 72 //===========================================================================
nobukuma 0:003889bc474f 73 // Don't need to look at or use anything below this line:
nobukuma 0:003889bc474f 74 // Internal representation of socket
nobukuma 0:003889bc474f 75
nobukuma 0:003889bc474f 76 class SocketHandler;
nobukuma 0:003889bc474f 77 class SocketInternal
nobukuma 0:003889bc474f 78 {
nobukuma 0:003889bc474f 79 public:
nobukuma 0:003889bc474f 80
nobukuma 0:003889bc474f 81 u8 ID;
nobukuma 0:003889bc474f 82 u8 State;
nobukuma 0:003889bc474f 83 u8 Type;
nobukuma 0:003889bc474f 84 u8 B0;
nobukuma 0:003889bc474f 85 SocketCallback Callback;
nobukuma 0:003889bc474f 86 void* userData;
nobukuma 0:003889bc474f 87 u8 Data[0]; // Extra socket data starts here
nobukuma 0:003889bc474f 88
nobukuma 0:003889bc474f 89 void Recv(const u8* data, int len)
nobukuma 0:003889bc474f 90 {
nobukuma 0:003889bc474f 91 Callback(ID,(SocketState)State,data,len,userData);
nobukuma 0:003889bc474f 92 }
nobukuma 0:003889bc474f 93
nobukuma 0:003889bc474f 94 void SetState(SocketState state)
nobukuma 0:003889bc474f 95 {
nobukuma 0:003889bc474f 96 State = state;
nobukuma 0:003889bc474f 97 Callback(ID,(SocketState)State,0,0,userData);
nobukuma 0:003889bc474f 98 if (state == SocketState_Closed) {
nobukuma 0:003889bc474f 99 printf("Socket %d has been freed\n", ID);
nobukuma 0:003889bc474f 100 ID = 0;
nobukuma 0:003889bc474f 101 }
nobukuma 0:003889bc474f 102 }
nobukuma 0:003889bc474f 103 };
nobukuma 0:003889bc474f 104
nobukuma 0:003889bc474f 105 class SocketHandler
nobukuma 0:003889bc474f 106 {
nobukuma 0:003889bc474f 107 public:
nobukuma 0:003889bc474f 108 virtual int Create(SocketInternal* sock) { printf("SocketHandler::Create: not implemented for %s\n", Name()); return sock->ID;}
nobukuma 0:003889bc474f 109 virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
nobukuma 0:003889bc474f 110 virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
nobukuma 0:003889bc474f 111 virtual int Close(SocketInternal* sock) = 0;
nobukuma 0:003889bc474f 112 virtual int Listen(SocketInternal* sock, int channel) { printf("SocketHandler::Listen: not implemented for %s\n", Name());return 0;}
nobukuma 0:003889bc474f 113 virtual int Accept(SocketInternal* sock, int scid, int rxid) { printf("SocketHandler::Accept: not implemented for %s\n", Name());return 0;}
nobukuma 0:003889bc474f 114 virtual int SetOpt(SocketInternal* sock, int so, int* data, int len) { printf("SocketHandler::SetOpt: not implemented for %s\n", Name());return 0;}
nobukuma 0:003889bc474f 115 virtual int GetOpt(SocketInternal* sock, int so, int* data, int len) { printf("SocketHandler::GetOpt: not implemented for %s\n", Name());return 0;}
nobukuma 0:003889bc474f 116 virtual char* Name() { return "Base_SocketHandler";}
nobukuma 0:003889bc474f 117 };
nobukuma 0:003889bc474f 118
nobukuma 0:003889bc474f 119 int RegisterSocketHandler(int type, SocketHandler* handler);
nobukuma 0:003889bc474f 120 SocketInternal* GetSocketInternal(int socket);
nobukuma 0:003889bc474f 121
nobukuma 0:003889bc474f 122 #define ERR_SOCKET_TYPE_NOT_FOUND -200
nobukuma 0:003889bc474f 123 #define ERR_SOCKET_NOT_FOUND -201
nobukuma 0:003889bc474f 124 #define ERR_SOCKET_NONE_LEFT -202
nobukuma 0:003889bc474f 125 #define ERR_SOCKET_CANT_LISTEN -203
nobukuma 0:003889bc474f 126
nobukuma 0:003889bc474f 127 #endif // SOCKET_H_INCLUDED