BlackOneとAndroidの連携デモプログラム AndroidAccessoryを改造してBlackOneとAndroidが連携できるようにしました。 サポートしているのは、デモアプリの ”Buttons” B1-SW1, B2-SW2, B3-SW3 ”LED2” RGB-LED のみです。 LCDに表示するイメージをマイクロSDカードに入れてLCDのソケットに挿入しておく必要があります。 イメージは、320X240ドットで”\Image”という名前のフォルダの直下に”10.jpg”という名前で入れてください。

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Socket.h Source File

Socket.h

00001 /*
00002 Copyright (c) 2010 Peter Barrett
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 /* 
00024 Tue Apr 26 2011 Bart Janssens: added a socket listener
00025 */
00026 
00027 #ifndef SOCKET_H_INCLUDED
00028 #define SOCKET_H_INCLUDED
00029 
00030 #define SOCKET_HCI      1
00031 #define SOCKET_L2CAP    2
00032 #define SOCKET_RFCOM    3
00033 
00034 typedef struct
00035 {
00036     u8  AddressSpecific[0]; // BDADDR,psm etc
00037 } SocketAddrHdr;
00038 
00039 
00040 
00041 enum SocketState
00042 {
00043     SocketState_Unknown,
00044     SocketState_Opening,
00045     SocketState_Open,
00046     SocketState_Closing,
00047     SocketState_Closed,
00048     SocketState_Listen,
00049     SocketState_Accept
00050 };
00051 
00052 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
00053 
00054 class SocketListener
00055 {
00056     public:
00057     int ID;
00058     int Type;
00059     int port;
00060     SocketCallback Callback;
00061     void* userData;
00062 };
00063 
00064 //===========================================================================
00065 //===========================================================================
00066 //  Don't need to look at or use anything below this line:
00067 //  Internal representation of socket
00068 
00069 class SocketHandler;
00070 class SocketInternal
00071 {
00072     public:
00073 
00074     u8 ID;
00075     u8 State;
00076     u8 Type;
00077     u8 B0;
00078     int port;
00079     SocketCallback Callback;
00080     void* userData;
00081     u8  Data[0];    // Extra socket data starts here
00082 
00083     void Recv(const u8* data, int len)
00084     {
00085         Callback(ID,(SocketState)State,data,len,userData);
00086     }
00087 
00088     void SetState(SocketState state)
00089     {
00090         State = state;
00091         Callback(ID,(SocketState)State,0,0,userData);
00092     }
00093 };
00094 
00095 class SocketHandler
00096 {
00097     public:
00098     virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
00099     virtual int Create(SocketInternal* sock, SocketAddrHdr* addr) = 0;
00100     virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
00101     virtual int Close(SocketInternal* sock) = 0;
00102     virtual int Accept(SocketInternal* sock, SocketAddrHdr* addr) = 0;
00103 };
00104 
00105 int RegisterSocketHandler(int type, SocketHandler* handler);
00106 SocketInternal* GetSocketInternal(int socket);
00107 
00108 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData);   // Open a socket
00109 int Socket_Listen(int type, int port,SocketCallback callback, void* userData);
00110 int Socket_InUse(int type, int port);
00111 int Socket_Accept(int socket, SocketCallback callback, void* userData);
00112 SocketInternal* Socket_Create(int type,SocketAddrHdr* addr, int port);
00113 int Socket_Send(int socket, const u8* data, int len);
00114 int Socket_State(int socket);
00115 int Socket_Close(int socket);
00116 
00117 #define ERR_SOCKET_TYPE_NOT_FOUND -200
00118 #define ERR_SOCKET_NOT_FOUND -201
00119 #define ERR_SOCKET_NONE_LEFT -202
00120 #define ERR_SOCKET_IN_USE -203
00121 
00122 #endif // SOCKET_H_INCLUDED