Beispiel #1
0
int init_rpc2()
{
    char server[50];
    if (discover_services(server) == -1) {
        return -1;
    }

    return 0;
}
Beispiel #2
0
static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
	if (err) {
		set_state(STATE_DISCONNECTED);
		error("%s\n", err->message);
		return;
	}

	attrib = g_attrib_new(iochannel);
	g_attrib_register(attrib, ATT_OP_HANDLE_NOTIFY, GATTRIB_ALL_HANDLES,
						events_handler, attrib, NULL);
	g_attrib_register(attrib, ATT_OP_HANDLE_IND, GATTRIB_ALL_HANDLES,
						events_handler, attrib, NULL);
	set_state(STATE_CONNECTED);
	rl_printf("Connection successful\n");

        discover_services();
}
int main(int argc, char **argv)
{
  char addr[18];
  char *handle, *value;
  int ret, choice;

  printf("*********************************\n");
  printf("**** Nod Labs test framework ****\n");
  printf("*********************************\n");

  /* initialize a glib event loop */
  event_loop = g_main_loop_new(NULL, FALSE);

  printf("Scanning for all BTLE devices in proximity...");
  printf("Press ^C to stop scanning\n");

  if(ret = cmd_lescan(0) < 0) {
    printf("Scanning failed!! Quitting %d\n", ret);
    exit(-1);
  }

  printf("Enter the device to connect: ");
  scanf("%s", addr);

  ret = 0;
  if (ret = cmd_connect(addr, NULL) < 0) {
    printf("Connection failed %d\n", ret);
    exit(-2);
  } else {
    printf("Connected to [%s]\n", addr);
  }

  printf("SERVICES:\n");
  discover_services((gpointer)attrib);

  printf("\nCHARACTERISTICS:\n");
  discover_characteristics((gpointer)attrib, CHAR_START, CHAR_END);

  /* IMP: If the native bluez stack is running while this test runs, then the
   * keys get cached in the system(on which this is running). Next time, when this
   * test case is being run, it will fail to change the security level to
   * anything other than "low". To resolve this issue, we need to check for
   * the paired devices in bluetoothctl (using cmd 'show devices') and remove
   * the device from bluez device cache.
   *
   * HIGH security level is needed for initiating the bonding with the device. This
   * is important as HID services need the link to be encrypted.
   */
  if (cmd_set_sec_level("high") < 0) {
    printf("Failed to set the security level to HIGH\n");
    exit(-1);
  } else {
    printf("Security level set to HIGH\n");
  }

  /* Now, enable battery and nControl notifications in the ring */
  control_service(non_os_indexes, GET_SZ(non_os_indexes), ENABLE_NOTIFICATION);

  /*
   * TODO: Make sure the below mode list is up-to-date with
   * the numbers used in the f/w
   */

  ret = 0;
  printf("Which mode you want to enable?\n");
  printf("1. TTM\n");
  printf("2. Free pointer\n");
  printf("3. OpenSpatial (Pose6D & Buttons)\n");
  printf("0. Exit\n");
  printf("Enter your choice: ");
  scanf("%d", &choice);
  printf("\n");

  if (!choice) {
    exit(0);
  }
  /* update the mode accordingly */
  change_mode((gpointer)attrib, choice);

  /* We have an active connection, with the data ready to be received */
  set_state(STATE_CONNACTIVE);

  /* let the signal handler do necessary cleanup before proceeding to disconnect */
  wait_for_cleanup = 1;

  /* below loop will control the event loop for receiving the data */
  g_main_loop_run(event_loop);

  while (wait_for_cleanup);

  printf("Disconnecting from device [%s]\n", addr);

  cmd_disconnect();

  /* un-initialize glib event loop */
  g_main_loop_unref(event_loop);

  return 0;
}