我想知道是否有人能夠幫助我處理C藍牙編程(Linux Bluez)的問題。 我使用的是Ubuntu 10.04,BlueZ 4.60。 我的目標是建立一個L2CAP套接字,其中在兩臺計算機之間發送數據的時間最短。 到目前爲止,我設法打開一個L2CAP套接字,但是這個套接字有無盡的重傳,我試圖改變它。我希望完全沒有重傳,因爲我需要以最小的延遲快速傳輸數據,並且數據的可靠性並不重要。取消L2CAP插座上的重新傳輸
我發現了一個在線示例,它處理更改套接字的flush timout,並導致如果某個數據包在一段時間後沒有響應,它將被丟棄,並且緩衝區中的下一個數據將被髮送。 的問題是,這個例子不起作用:-(
這裏是我的代碼,這種方法是bind命令之後調用:
int set_flush_timeout(bdaddr_t *ba, int timeout) { int err = 0, dd, dev_id; struct hci_conn_info_req *cr = 0; struct hci_request rq = { 0 };
struct {
uint16_t handle;
uint16_t flush_timeout;
} cmd_param;
struct {
uint8_t status;
uint16_t handle;
} cmd_response;
// find the connection handle to the specified bluetooth device
cr = (struct hci_conn_info_req*) malloc(
sizeof(struct hci_conn_info_req) +
sizeof(struct hci_conn_info));
bacpy(&cr->bdaddr, ba);
cr->type = ACL_LINK;
dev_id = hci_get_route(NULL);
dd = hci_open_dev(dev_id);
if(dd < 0) {
err = dd;
goto cleanup;
}
err = ioctl(dd, HCIGETCONNINFO, (unsigned long) cr);
if(err) goto cleanup;
// build a command packet to send to the bluetooth microcontroller
cmd_param.handle = cr->conn_info->handle;
cmd_param.flush_timeout = htobs(timeout);
rq.ogf = OGF_HOST_CTL;
rq.ocf = 0x28;
rq.cparam = &cmd_param;
rq.clen = sizeof(cmd_param);
rq.rparam = &cmd_response;
rq.rlen = sizeof(cmd_response);
rq.event = EVT_CMD_COMPLETE;
// send the command and wait for the response
err = hci_send_req(dd, &rq, 1);
if(err) goto cleanup;
if(cmd_response.status) {
err = -1;
errno = bt_error(cmd_response.status);
}
cleanup:
free(cr);
if(dd >= 0) close(dd);
return err;
}
什麼是我的錯 有誰知道這將解決我的問題。 代碼示例的另一種選擇也將是偉大的!
謝謝!
您顯示的代碼看起來正確。你能澄清你的意思是「它不工作」嗎?響應中的狀態碼是什麼?你試圖使用超時的價值是什麼?請注意,超時的單位是插槽(625微秒),最大值爲0x7ff – TJD 2012-03-15 16:27:02
「它不工作」意味着在行 「err = ioctl(dd,HCIGETCONNINFO,(unsigned long)cr);」 我得到錯誤= -1,這意味着有一些問題。 我試着用各種超時值(全部在正確的範圍內),它們都返回-1。 – eranre 2012-03-19 15:28:32