Example #1
8
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
    GMainLoop *loop;
    GError * err = NULL;

    // Sensors
    Sensors s;

    s.scan();
    

    // Bluetooth scan
    //
    Bluetooth b;
    b.scan();

#if 0
    GIOChannel *channel = g_io_channel_unix_new(b.Handle());
    g_io_add_watch(channel,
		   (GIOCondition)(G_IO_IN | G_IO_OUT | G_IO_ERR | G_IO_HUP),
		   onEvent,
		   channel);
#endif
    
    //b.close();

    
    // socket server
    //
    GSocketService * server = g_socket_service_new();

    g_socket_listener_add_inet_port((GSocketListener*)server,
				    PORT,
				    NULL,
				    &err);
    if (err != NULL) {
	g_error("ERROR: %s", err->message);
    }

    g_signal_connect (server, "incoming", G_CALLBACK(onConnection), NULL);

    g_socket_service_start(server);

    // mainloop and timer
    //
    loop = g_main_loop_new ( NULL , FALSE );

    g_timeout_add (5000 , OnTimer , loop); 
    g_main_loop_run (loop);
    g_main_loop_unref(loop);

    return 0;
}
Example #2
0
//=============================================================================
// Sub functions
static void connect_bt(Lcd &lcd, char bt_name[16])
{
    //CHAR  name[16] = "Kachi";
    U8 address[7];

    lcd.clear();

    if (mBluetooth.getDeviceAddress(address)) // get the device address
    {
        lcd.putf("sn", "BD_ADDR:");
        for (SINT i=0; i<7; i++) lcd.putf("x", address[i],2);

        mBluetooth.setFriendlyName(bt_name); // set the friendly device name
        if (mBluetooth.getFriendlyName(bt_name)) // display the friendly device name
        {
            lcd.putf("nssn", "BD_NAME: ", bt_name);
        }

        lcd.putf("nsn", "Connecting BT...");
        lcd.putf("sn",  "ENTR to cancel.");
        lcd.disp();

        if (mBluetooth.waitForConnection("1234", 0)) // wait forever
        {
            lcd.putf("s", "Connected.");
        }
    }
    else
    {
        lcd.putf("s", "BT Failed.");
    }

    lcd.putf("ns", "Press Touch.");
    lcd.disp();
}
void onBTdisconnect(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();
	bool b =bt->onDisconnect(bt);

	sprintf(data->result_text,"%s",b?"disconnect success":"disconnect fail");
}
void BTrecv(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();
	String recv=NULL;
	bool b=bt->FileRecv(bt,&recv);
	sprintf(data->result_text,"%s",b?"File Receiving on":"reciving failed");



}
Example #5
0
//=============================================================================
// 1msec timer interrupt hook
void user_1ms_isr_type2(void)
{
    (void)SignalCounter(SysTimerCnt); // Alarm counter

    SleeperMonitor(); // Need for Nxt and I2C device classes

    if (mNxt.getButtons() == Nxt::ENTR_ON && !mBluetooth.isConnected())
    {
        mBluetooth.cancelWaitForConnection(); // Cancel Bluetooth connection process
    }
}
int main(){

	// First check to see if Bluetooth is available
	if(!Bluetooth::available()){
		printf("Bluetooth not available\n");
		return 0;
	}

	// Print all detected devices
	Bluetooth::printDevices();

	// Create a Bluetooth object
	Bluetooth bt;

	// Choose an address of the device to open
	const char * addr = "68:86:e7:03:09:5e"; // Sphero
	//const char * addr = "04:e4:51:fd:f4:69"; // Phone


	// Open an RFCOMM connection
	if(bt.openRFCOMM(addr)){
		printf("opened RFCOMM connection on channel %d\n", bt.channel());
	}
	else{
		printf("error opening RFCOMM connection\n");
		return 0;
	}

	// At this point, you should be able to send/recv data
	std::vector<unsigned char> buffer;

	// Send data
	/*
	buffer.push_back('H');
	buffer.push_back('e');
	buffer.push_back('l');
	buffer.push_back('l');
	buffer.push_back('o');
	bt.send(buffer);
	//*/

	// Receive data (e.g., a server response)
	/*
	if(bt.recv(buffer)){
		printf("received %d bytes: ", buffer.size());
		for(unsigned i=0; i<buffer.size(); ++i){
			printf("%x ", buffer[i]);
		}
		printf("\n");
	}
	//*/
}
Example #7
0
int main(void) {

    Bluetooth b;
    Test test;

    cout << b.enable() << endl;
    b.register_receiver<Test,&Test::call_me>(&test);

    while(1) {}


    b.disable();
    pthread_exit(NULL);
}
void onBTconnect(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();

	bool b = bt->onConnect(bt);
	if(b==true){

		sprintf(data->result_text,"connect success<br>mac_address:<br>%s",((BluetoothExtends*)bt)->remoteMACAddr);
	}
	else
	{
	sprintf(data->result_text,"%s","connect fail");
	}

}
void BTsend(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();
	if(bt-> isConnected(bt)){
	String sendfilepath= getSharedResourceFile("music/Over the Horizon.mp3");
	bool b=bt->FileSend(bt,sendfilepath);
		if(b){
		sprintf(data->result_text,"%s<br>sending to<br>%s",sendfilepath,((BluetoothExtends*)bt)->remoteMACAddr);
		free(sendfilepath);
		}
		else
		{
			sprintf(data->result_text,"File sending failed");
		}
	}
	else
	{
		sprintf(data->result_text,"not connected");
	}
}
void isBTconnected(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();
	bool x= bt->isConnected(bt);
	sprintf(data->result_text,"%s",x?"is connected":"not connected");
}
void isBTaccessible(notification_data* data)
{
	Bluetooth bt = bluetooth_get_instance();
	bt->isAccessible(bt);
	sprintf(data->result_text,"%s",bt?"is accessible":"not accessible");
}