コード例 #1
0
int TinkerforgeSensors::init()
{
  // create IP connection
  ipcon_create(&ipcon);

  // connect to brickd
  if(ipcon_connect(&ipcon, this->host.c_str(), this->port) < 0) {
    std::cout << "could not connect to brickd!" << std::endl;
    return false;
  }

  // register connected callback to "cb_connected"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_CONNECTED,
    (void*)callbackConnected,
    this);

  // register enumeration callback to "cb_enumerate"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_ENUMERATE,
    (void*)callbackEnumerate,
    this);

  return 0;
}
コード例 #2
0
ファイル: laser_transform_core.cpp プロジェクト: asimay/ros
int LaserTransform::init()
{
  // create IP connection
  ipcon_create(&ipcon);

  // connect to brickd
  if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
    std::cout << "could not connect to brickd!" << std::endl;
    return false;
  }

  // register connected callback to "cb_connected"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_CONNECTED,
    (void*)callbackConnected,
    this);

  // register enumeration callback to "cb_enumerate"
  ipcon_register_callback(&ipcon,
    IPCON_CALLBACK_ENUMERATE,
    (void*)callbackEnumerate,
    this);

  return 0;
}
コード例 #3
0
void MasterConnectionImpl::connect(const std::string& host, Poco::UInt16 port)
{
	poco_assert (ipcon_get_connection_state(&_ipcon) == IPCON_CONNECTION_STATE_DISCONNECTED);
	int rc = ipcon_connect(&_ipcon, host.c_str(), port);
	switch (rc)
	{
	case E_OK:
		break;
	
	case E_TIMEOUT:
		throw Poco::TimeoutException();

	case E_HOSTNAME_INVALID:
		throw Poco::IOException("invalid hostname", host);
			
	default:
		throw Poco::IOException("cannot establish connection to master");
	}
	
	while (ipcon_get_connection_state(&_ipcon) == IPCON_CONNECTION_STATE_PENDING)
	{
		Poco::Thread::sleep(100);
	}
	
	ipcon_register_callback(&_ipcon, IPCON_CALLBACK_ENUMERATE, (void*) enumerate, this);
	rc = ipcon_enumerate(&_ipcon);
	if (rc != E_OK)
	{
		throw Poco::IOException();
	}
}
コード例 #4
0
int main(void) {
	SmokeDetector sd;

	ipcon_create(&sd.ipcon);

	while(true) {
		int rc = ipcon_connect(&sd.ipcon, HOST, PORT);
		if(rc < 0) {
			fprintf(stderr, "Could not connect to brickd: %d\n", rc);
			// TODO: sleep 1s
			continue;
		}
		break;
	}

	ipcon_register_callback(&sd.ipcon,
	                        IPCON_CALLBACK_ENUMERATE,
	                        (void *)cb_enumerate,
	                        (void *)&sd);

	ipcon_register_callback(&sd.ipcon,
	                        IPCON_CALLBACK_CONNECTED,
	                        (void *)cb_connected,
	                        (void *)&sd);

	while(true) {
		int rc = ipcon_enumerate(&sd.ipcon);
		if(rc < 0) {
			fprintf(stderr, "Could not enumerate: %d\n", rc);
			// TODO: sleep 1s
			continue;
		}
		break;
	}

	printf("Press key to exit\n");
	getchar();
	ipcon_destroy(&sd.ipcon);
	return 0;
}