ArDrone SDK 1.8 added
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / ARDroneLib / VP_SDK / Examples / common / com_client.c
1 #include "common.h"
2
3 #include <Com/com.h>
4 #include <Api/error.h>
5
6 #include "com_client.h"
7
8 static com_config_t     config;
9 static com_socket_t     clt;
10 static com_connection_t connection;
11 static Read             read;
12 static Write            write;
13
14 C_RESULT init_com_client(void)
15 {
16   config.connection       = COM_BLUETOOTH;
17   config.localAdapterName = DEVICENAME;
18   config.localIpAddress   = CLIENTHOST;
19   config.localIpSubmask   = SUBMASK;
20
21   if(FAILED(com_init(&config)))
22     return C_FAIL;
23
24   return C_OK;
25 }
26
27 C_RESULT run_com_client(COM_PROTOCOL protocol)
28 {
29   com_strToAddress(BTADDR_SERVER,&connection.address);
30
31   com_passKey(PIN_CODE);
32   if(FAILED(com_connect(&connection,1)))
33     return C_FAIL;
34
35   clt.socket    = COM_CLIENT;
36   clt.protocol  = protocol;
37
38   if(protocol == COM_RFCOMM)
39   {
40     clt.scn = BTADDR_SCN;
41   }
42   else if(protocol == COM_BNEP)
43   {
44     clt.port        = BTADDR_PORT;
45     clt.serverHost  = SERVERHOST;
46   }
47   else
48     return C_FAIL;
49
50   if(FAILED(com_open(&clt,&read,&write)))
51     return C_FAIL;
52
53   return C_OK;
54 }
55
56 C_RESULT shutdown_com_client(void)
57 {
58   com_close(&clt);
59
60   com_disconnect();
61   com_shutdown();
62
63   return C_OK;
64 }
65
66 C_RESULT read_client(int8_t* buffer, int32_t* size)
67 {
68   return read(&clt,buffer,size);
69 }
70
71 C_RESULT write_client(const int8_t* buffer, int32_t* size)
72 {
73   return write(&clt,buffer,size);
74 }