summaryrefslogtreecommitdiffstats
path: root/qtserialbluetooth.cpp
diff options
context:
space:
mode:
authorGravatar Claudiu Olteanu <olteanu.claudiu@ymail.com>2015-08-18 21:37:11 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-08-20 22:45:23 -0700
commite2cac92d2304b21e7745e37a18c98c47086fc4b4 (patch)
tree2f1431b6ec5a0aeaf8f23130a574480d7d2b4adc /qtserialbluetooth.cpp
parent7488f5500ed82047b66368b62d14595a166078e1 (diff)
downloadsubsurface-e2cac92d2304b21e7745e37a18c98c47086fc4b4.tar.gz
Add implementation for BTH custom serial open method on Windows platforms
Implement the custom serial open method using the WinSocket2 API. First the device address is converted from text representation into a sockaddr structure. Then a connection is initiated to the device using device's Serial Port service. Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qtserialbluetooth.cpp')
-rw-r--r--qtserialbluetooth.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index 37ea22597..0edd3d42b 100644
--- a/qtserialbluetooth.cpp
+++ b/qtserialbluetooth.cpp
@@ -51,7 +51,49 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
serial_port->timeout = -1;
#if defined(Q_OS_WIN)
- // TODO connect the device
+ // Create a RFCOMM socket
+ serial_port->socket = ::socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
+
+ if (serial_port->socket == INVALID_SOCKET)
+ return DC_STATUS_IO;
+
+ SOCKADDR_BTH socketBthAddress;
+ int socketBthAddressBth = sizeof (socketBthAddress);
+ char *address = strdup(devaddr);
+
+ ZeroMemory(&socketBthAddress, socketBthAddressBth);
+ qDebug() << "Trying to connect to address " << devaddr;
+
+ if (WSAStringToAddressA(address,
+ AF_BTH,
+ NULL,
+ (LPSOCKADDR) &socketBthAddress,
+ &socketBthAddressBth
+ ) != 0) {
+ qDebug() << "FAiled to convert the address " << address;
+ free(address);
+
+ return DC_STATUS_IO;
+ }
+
+ free(address);
+
+ socketBthAddress.addressFamily = AF_BTH;
+ socketBthAddress.port = BT_PORT_ANY;
+ memset(&socketBthAddress.serviceClassId, 0, sizeof(socketBthAddress.serviceClassId));
+ socketBthAddress.serviceClassId = SerialPortServiceClass_UUID;
+
+ // Try to connect to the device
+ if (::connect(serial_port->socket,
+ (struct sockaddr *) &socketBthAddress,
+ socketBthAddressBth
+ ) != 0) {
+ qDebug() << "Failed to connect to device";
+
+ return DC_STATUS_NODEVICE;
+ }
+
+ qDebug() << "Succesfully connected to device";
#else
// Create a RFCOMM socket
serial_port->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);