Пример #1
0
/*
 * Sends a control event with code "code" and selection "selection"
 * to node "node", packing pkt->body with "data" which must be of
 * size "len".
 */
int node_ctrl(merlin_node *node, int code, uint selection, void *data,
			  uint32_t len, int msec)
{
	merlin_event pkt;

	if (len > sizeof(pkt.body)) {
		lerr("Attempted to send %u bytes of data when max is %u",
			 len, sizeof(pkt.body));
		bt_scan(NULL, 0);
		return -1;
	}

	memset(&pkt.hdr, 0, HDR_SIZE);

	pkt.hdr.sig.id = MERLIN_SIGNATURE;
	pkt.hdr.protocol = MERLIN_PROTOCOL_VERSION;
	gettimeofday(&pkt.hdr.sent, NULL);
	pkt.hdr.type = CTRL_PACKET;
	pkt.hdr.len = len;
	pkt.hdr.code = code;
	pkt.hdr.selection = selection & 0xffff;
	if (data)
		memcpy(&pkt.body, data, len);

	return node_send_event(node, &pkt, msec);
}
Пример #2
0
int	main(int argc, char **argv)
{
  printf("main::init...\n");
  bt_begin();
  printf("main::scan...\n");
  bt_scan();
  while (bt_scandone() == 0)
    {
      printf("waiting ...\n");
      sleep(1);
    }
  printf("main::end...\n");
  bt_end();
  return (0);
}
Пример #3
0
static Ret _bt_scan_start(void *ctx)
{
	FtkWidget *info;
	char temp[100];
	int i;

	info = ftk_widget_lookup((FtkWidget *)ctx, IDC_INFO);

	ftk_main_loop_remove_source(ftk_default_main_loop(), _timer);
	_timer = NULL;

	_bt_dev_num = bt_scan(_bt, _devices, BT_SCAN_MAX);
	if (_bt_dev_num > 0) {
		sprintf(temp, "검색 결과 : %d 개", _bt_dev_num);
		for (i = 0; i < _bt_dev_num; i++) {
			FtkListItemInfo info = {0};

			info.text = _devices[i].name;
			ftk_list_model_add(_model, &info);
		}

	} else if (_bt_dev_num == 0) {
		sprintf(temp, "검색 결과 없음");
	} else {
#ifdef __TEST__
		_bt_dev_num = 9;
		for (i = 0; i < 9; i++) {
			FtkListItemInfo info = {0};

			sprintf(temp, "test %d", i);
			info.text = temp;
			ftk_list_model_add(_model, &info);
		}
#endif
		sprintf(temp, "검색 실패");
	}

	if (info) ftk_widget_set_text(info, temp);

	return RET_OK;
}
Пример #4
0
/*****************************************************************************
 Open communications with GPS device.
 *****************************************************************************/
int coms_open(cmdlnopts_t *cmdopt) {
  int fd = -1;

  /* Open communication with device */
  if (cmdopt->devs != NULL) {
    /* Serial device name is provided */
    fd = dev_open(cmdopt->devs);
    if (fd < 0) {
      fprintf(stderr, "rtkgps: Error opening device %s [%s]\n", cmdopt->devs,
	      strerror(errno));
      exit(4);
    }
    if (dev_config_serial(fd, cmdopt->sspd) < 0) {
      fprintf(stderr, "rtkgps: Error setting device speed to %u [%s]\n",
      		cmdopt->sspd, strerror(errno));
      exit(4);
    }

    /* Display connection message in verbose mode */
    if (cmdopt->vflg) {
      printf("Opened device %s at %u baud\n", cmdopt->devs, cmdopt->sspd);
    }
  } else {
#if ENABLE_LINUX_BT-0
    static char btscs[24];
    /* Serial device name not provide: scan or use provide bluetooth address */
    if (cmdopt->btas == NULL) {
      /* Bluetooth address not specified: do a scan for a matching device */
      bt_device_t btd[32];
      int nbtd, nbgp = -1, n;

      /* Perform scan */
      nbtd = bt_scan(btd, 32);
      if (nbtd < 0) {
	fprintf(stderr, "rtkgps: Error perfoming bluetooth scan [%s]\n",
		strerror(errno));
	exit(4);
      }
      /* Report error if no devices found */
      if (nbtd == 0) {
	fprintf(stderr, "rtkgps: No bluetooth devices found during scan\n");
	exit(4);
      }
      /* Display scan result in verbose mode */
      if (cmdopt->vflg) {
	printf("Bluetooth scan:\n");
	bt_scan_print(stdout,  btd, nbtd);
      }
      /* Look for single bluetooth device named BlueGPS */
      for (n = 0; n < nbtd; n++) {
	if (strncmp(btd[n].name, "BlueGPS ", 8) == 0) {
	  if (nbgp == -1)
	    nbgp = n;
	  else {
	    /* Report error if multiple matching devices found */
	    fprintf(stderr, "rtkgps: Multiple BlueGPS devices found during"
		    " scan\n");
	    exit(4);
	  }
	}
      }
      if (nbgp == -1) {
	/* Report error if no matching devices found */
	fprintf(stderr, "rtkgps: No BlueGPS devices found during scan\n");
	exit(4);
      }
      /* Set selected device address from matching device address */
      ba2str(&btd[nbgp].bdaddr, btscs);

      cmdopt->btas = btscs;
      /* Display matching device details in verbose mode */
      if (cmdopt->vflg) {
	printf("Found appropriate device: ");
	bt_scan_print(stdout,  &btd[nbgp], 1);
      }
      /* This delay avoids "Operation already in progress" errors on
	 trying to open the bluetooth connection */
      sleep(1);
    }
    /* Open a connection to the selected bluetooth device */
    fd = bt_open(cmdopt->btas, 1);
    if (fd < 0) {
      fprintf(stderr, "rtkgps: Error connecting to %s [%s]\n", cmdopt->btas,
	      strerror(errno));
      exit(4);
    }
    /* Display connection message in verbose mode */
    if (cmdopt->vflg) {
      printf("Connected to %s\n", cmdopt->btas);
    }
#endif /* ENABLE_LINUX_BT */
  }

  return fd;
}