ConnectionManager::ConnectionManager(QObject *parent) :
		QObject(parent), m_localDevInfo(new LocalDeviceInfo(this)), m_deviceListing(
				new DeviceListing(this)), s_model(
				new bb::cascades::GroupDataModel(
						QStringList() << "slideNum" << "slideType" << "image",
						this)) {
	s_cm = this;
	connect(this, SIGNAL(BTDeviceSignal(int, QString, QString)), this,
			SLOT(handleBTDeviceEvent(int, QString, QString)));
	connect(&m_IDT, SIGNAL(recordHeader(int,QString)),
			SLOT(recordHeader(int,QString)));
	connect(&m_IDT, SIGNAL(slide(int,int,QString)),
			SLOT(slide(int,int,QString)));
	connect(&m_IDT, SIGNAL(received()), SLOT(received()));

	bt_device_init(CMCallback);
	bt_spp_init();

	m_localDevInfo->update();

	m_record = 0;
	s_model->setSortingKeys(QStringList() << "slideType");
	s_model->setGrouping(bb::cascades::ItemGrouping::ByFullValue);
	is_connected = false;
	s_currentSlide = "Slide - ";
	s_currentNote = "";
}
BlueToothManager::BlueToothManager(Scope * sc) :
		GateFactory("BlueToothManager"), scope(sc), started(false), thread(NULL) {
	Gate g(this, "BlueToothManager()");
	if (ldev != NULL) {
		ldev = new LocalDeviceInfo();
	}
	g.log() << "init" << bt_device_init(btCallback);
	g.log() << "spp_init" << bt_spp_init();

	connect(this,SIGNAL(sppCallbackSignal(int)),this,SLOT(sppCallbackInternal(int)));
}
예제 #3
0
QBluetoothSocketPrivate::QBluetoothSocketPrivate()
    : socket(-1),
      socketType(QBluetoothServiceInfo::UnknownProtocol),
      state(QBluetoothSocket::UnconnectedState),
      socketError(QBluetoothSocket::NoSocketError),
      readNotifier(0),
      connectWriteNotifier(0),
      connecting(false),
      discoveryAgent(0),
      isServerSocket(false)
{
#ifdef QT_QNX_BT_BLUETOOTH
    if (!initCounter && (bt_spp_init() == -1))
        qCDebug(QT_BT_QNX) << "Could not initialize Bluetooth library. "
                           << qt_error_string(errno);

    initCounter++;
#else
    ppsRegisterControl();
#endif
}
예제 #4
0
/* 
 * bt_spp_start():
 *
 * Called by the main application to initialize and connect to a network
 *
 */
void bt_spp_start(void)
{
	hci_reset_all();
	l2cap_reset_all();
	sdp_reset_all();
	rfcomm_reset_all();

	LWIP_DEBUGF(BT_SPP_DEBUG, ("bt_spp_start\n"));

	hci_cmd_complete(command_complete);
	hci_pin_req(pin_req);
	hci_link_key_req(link_key_req);
	hci_link_key_not(link_key_not);
	bt_spp_state.btctrl = 0;
	bt_spp_state.p = NULL;
	hci_reset();

	if(bt_spp_init() != ERR_OK) /* Initialize the SPP role */
	{
		LWIP_DEBUGF(BT_SPP_DEBUG, ("bt_spp_start: couldn't init role\n"));
		return;
	}
}
ArduinoBTController::ArduinoBTController(QObject* parent)
    : QObject(parent)
{
    // Initialize the bt device and SPP library APIs.
    int errorCode;

    errorCode = bt_device_init(BTControllerCallbackArduino);
    errorCode = bt_spp_init();

    bt_remote_device_t **remote_device_array;
    bt_remote_device_t *next_remote_device = 0;

    // Retrieve and show all devices.
    remote_device_array = bt_disc_retrieve_devices(BT_DISCOVERY_ALL, 0);
    if (remote_device_array) {
        for (int i = 0; (next_remote_device = remote_device_array[i]); ++i) {
            QVariantMap map;
            char buffer[128];
            const int bufferSize = sizeof(buffer);

            bt_rdev_get_friendly_name(next_remote_device, buffer, bufferSize);
            map["deviceName"] = QString::fromLatin1(buffer);
            bt_rdev_get_addr(next_remote_device, buffer);
            map["deviceAddress"] = QString::fromLatin1(buffer);
            if ( (strcmp(buffer, "00:12:09:12:02:05") == 0) or  (strcmp(buffer, "20:13:06:18:04:04") == 0) ) { //this are my devicesis my device's mac adress
                qDebug() << "Found the BT device";
                int rssi = 0;
                bool ok = false;
                QString m_rssi;
                const QString unknown = tr("Unknown");
                bt_remote_device_t *remote_device = bt_rdev_get_device(buffer);

                ok = (bt_rdev_get_rssi(remote_device, &rssi) == 0);
                m_rssi = (ok ? QString::number(rssi) : unknown);

                const int fd = bt_spp_open(buffer, (char *) SPP_SERVICE_UUID,
                        false);

                if (fd >= 0) {

                    fflush(stdout);
                    if (fd >= 0) {
                        //starting the reciever/thread, I could use this to get data from a sensor
                            m_sppDataThread.init(fd,false);
                            m_sppDataThread.start();

                            //the shield has the bad habit of disconnecting if the app idles to long, so I'm sending a heartbeatsignal
                            m_keepAliveThread.init(fd);
                            m_keepAliveThread.start();

                            if (m_sppDataThread.active()) {
                                char buffer[80] = "HELLO"; //it is nice to say hello!
                                write(m_sppDataThread.getFD(), buffer, strlen(buffer));

                            }

                        }
                    } else {
                        qDebug() << "spp_open fail errno =" << QString::number(errno);
                    }

                }

            map["deviceClass"] = QString::number(
                    bt_rdev_get_device_class(next_remote_device,
                            BT_COD_DEVICECLASS));
            map["deviceType"] = tr("Bluetooth Devices  Paired");
            //  qDebug() << "map" << map;
        }
        bt_rdev_free_array(remote_device_array);
    }

    // Initialize the btdevice and SPP library APIs.
    bt_device_init(BTControllerCallbackArduino);
    bt_spp_init();
}