C_RESULT shutdown_com_server(void)
{
  com_close(&clt);
  com_close(&srv);

  com_shutdown();

  return C_OK;
}
Beispiel #2
0
int
main(int argc, char **argv)
{
    void *p;
    com_result_t r;
    int n;
    size_t s;
    IMalloc *allocator;

    (void) argc;
    (void) argv;

    com_init("com.googlecode.libcom.test-1");

    p = CoTaskMemAlloc(64);
    if(NULL == p)
    {
        fprintf(stderr, "Failed to allocate 64 bytes via CoTaskMemAlloc()\n");
        exit(EXIT_FAILURE);
    }
    if(COM_S_OK != (r = CoGetMalloc(1, &allocator)))
    {
        fprintf(stderr, "Failed to obtain reference to task allocator; result = 0x%08x\n", r);
        exit(EXIT_FAILURE);
    }
    if(1 != (n = IMalloc_DidAlloc(allocator, p)))
    {
        if(0 == n)
        {
            fprintf(stderr, "IMalloc::DidAlloc() claims task allocator was not responsible for allocated block\n");
        }
        else
        {
            fprintf(stderr, "IMalloc::DidAlloc() could not determine responsibility for allocated block\n");
        }
        exit(EXIT_FAILURE);
    }
    if(64 != (s = IMalloc_GetSize(allocator, p)))
    {
        fprintf(stderr, "IMalloc::GetSize() returned an incorrect size (%ul bytes)\n", s);
        exit(EXIT_FAILURE);
    }
    IMalloc_Free(allocator, p);
    puts("PASS");

    com_shutdown();
    return 0;
}
Beispiel #3
0
int main(int argc,char* argv[])
{
  com_config_t cfg;
  vp_com_connection_t conn;

  printf("---------- Network Adapter Inquiry ----------\n");
  com_networkAdapterLookUp(COM_BLUETOOTH,adapterinquiry_df);
  printf("---------------------------------------------\n");

  cfg.connection        = COM_BLUETOOTH;
  cfg.localAdapterName  = DEVICENAME;
  cfg.localIpAddress    = LOCALHOST;
  cfg.localIpSubmask    = "255.255.255.0";

  printf("--------------- INITIALISATION --------------\n");
  if(FAILED(com_init(&cfg)))
  {
    printf("Failed to init\n");
    com_shutdown();
    return -1;
  }
/*
  printf("----------- Remote Device Inquiry -----------\n");
  com_inquire(deviceinquiry,60000);
  printf("---------------------------------------------\n");
*/
  
  printf("---------- Tentative de connection ----------\n");
  com_strToAddress(BTADDR_SERVER,&conn.address);
  com_passKey("1234");
  if(FAILED(com_connect(&conn,1)))
  {
    printf("Failed to connect\n");
    com_shutdown();
    return -1;
  }

  printf("Connected to BTT\n");

  printf("---------- BNEP Connection ----------\n");
  {// Test d'execution bnep
    com_socket_t socket;
    Read read;

    socket.socket     = VP_COM_CLIENT;
    socket.protocol   = COM_BNEP;
    socket.serverHost = SERVERHOST;
    socket.port       = BTADDR_PORT;
  
    if(SUCCEED(com_open(&socket,&read,0)))
    {
      char buffer[10];
      int r = 10;
      printf("Connection BNEP succeeded\n");
      if(SUCCEED(read((void*)&socket,buffer,&r)))
        printf("Read succeed\n");
  
      printf("socket closed\n");
      com_close(&socket);
    }
  }

  sleep(1);

  printf("---------- RFCOMM Connection ----------\n");
  {// Test d'execution rfcomm
    com_socket_t socket;
    Write write;

    socket.socket    = VP_COM_CLIENT;
    socket.protocol  = COM_RFCOMM;
    socket.scn       = BTADDR_SCN;
  
    if(SUCCEED(com_open(&socket,0,&write)))
    {
      char buffer[10];
      int r = 10;
      printf("Connection RFCOMM succeeded\n");
      if(SUCCEED(write((void*)&socket,buffer,&r)))
        printf("Write succeed\n");
  
      printf("socket closed\n");
      com_close(&socket);
    }
  }

  sleep(1);

  printf("Deconnection\n");
  com_disconnect();

  printf("End of program\n");
  com_shutdown();

  return 0;
}
Beispiel #4
0
int main(void)
{
  com_config_t config;
  vp_com_connection_t connection;

  config.connection = VP_COM_WIFI;
  config.localAdapterName = "rausb0";

  connection.essid = "Drone";
  connection.channel = 10;

  if(FAILED(com_init(&config)))
    PRINT("com_init failed\n");

  if(FAILED(com_passKey("9F1C3EE11CBA230B27BF1C1B6F")))
    PRINT("com_passKey failed\n");

  if(FAILED(com_connect(&connection,1)))
    PRINT("com_connect failed\n");

  clt.socket      = VP_COM_CLIENT;
  clt.port        = DRONE_PORT;
  clt.serverHost  = DRONE_HOST;

  if(SUCCEED(com_open(&clt,&my_read,&my_write)))
  {
    int32_t i = 0;
    float st = timeGetTime();
    float et = timeGetTime();
    float db = 0.0f;
    float d = 0.0f;

    for(i=0; i < TIME_TO_SEND;i++)
    {
      int32_t received;

      PRINT("\r reception n° %d... ",i);

      received  = 0;
      size      = SIZE_TO_SEND;

      while(received != SIZE_TO_SEND)
      {
        my_read(&clt,buffer,&size);
        received += size;
        size = SIZE_TO_SEND - received;
      }

      PRINT("%d bytes           ",received);
    }

    et = timeGetTime();
    d = (et - st) / 1000.0f;
    if(d > 0)
    {
      float tx = SIZE_TO_SEND * TIME_TO_SEND / 1024.0f;
      db = tx / d;
    }
    PRINT("\n---------------\n");
    PRINT("Start Time : %f\n",st);
    PRINT("End Time : %f\n",et);
    PRINT("%d Kbytes sent in %f time\n",SIZE_TO_SEND * TIME_TO_SEND / 1024,d);
    PRINT("Debit: %f\n",db);
    PRINT("\n---------------\n");
  }
  else
  {
    PRINT("snif... pas connecte a la socket\n");
  }

  PRINT("Waiting for disconnection\n");
  vp_delay(5000);

  com_disconnect();
  PRINT("Disconnected\n");

  com_shutdown();

  return 0;
}