Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop link quality #1841

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Store network configuration in GSettings instead of /var/lib/blueman/network.state.
* Replace custom MessageArea widget with regular Gtk.InfoBar
* Drop auto-power feature. BlueZ now has the AutoEnable setting for even better auto-powering.
* Do not use pointless link quality value

### Bugs fixed

Expand Down
28 changes: 6 additions & 22 deletions blueman/gui/manager/ManagerDeviceList.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ def __init__(self, adapter: Optional[str] = None, inst: Optional["Blueman"] = No
{"id": "rssi_pb", "type": GdkPixbuf.Pixbuf, "renderer": Gtk.CellRendererPixbuf(),
"render_attrs": {}, "view_props": {"spacing": 0},
"celldata_func": (self._set_cell_data, "rssi")},
{"id": "lq_pb", "type": GdkPixbuf.Pixbuf, "renderer": Gtk.CellRendererPixbuf(),
"render_attrs": {}, "view_props": {"spacing": 0},
"celldata_func": (self._set_cell_data, "lq")},
{"id": "tpl_pb", "type": GdkPixbuf.Pixbuf, "renderer": Gtk.CellRendererPixbuf(),
"render_attrs": {}, "view_props": {"spacing": 0},
"celldata_func": (self._set_cell_data, "tpl")},
Expand All @@ -61,7 +58,6 @@ def __init__(self, adapter: Optional[str] = None, inst: Optional["Blueman"] = No
{"id": "objpush", "type": bool}, # used to set Send File button
{"id": "battery", "type": float},
{"id": "rssi", "type": float},
{"id": "lq", "type": float},
{"id": "tpl", "type": float},
{"id": "icon_info", "type": Gtk.IconInfo},
{"id": "cell_fader", "type": CellFade},
Expand Down Expand Up @@ -474,22 +470,18 @@ def _update_power_levels(self, tree_iter: Gtk.TreeIter, device: Device, cinfo: c
# cinfo init may fail for bluetooth devices version 4 and up
# FIXME Workaround is horrible and we should show something better
if cinfo.failed:
bars.update({"rssi": 100.0, "tpl": 100.0, "lq": 100.0})
bars.update({"rssi": 100.0, "tpl": 100.0})
else:
try:
bars["rssi"] = max(50 + float(cinfo.get_rssi()) / 127 * 50, 10)
except ConnInfoReadError:
bars["rssi"] = 50
try:
bars["lq"] = max(float(cinfo.get_lq()) / 255 * 100, 10)
except ConnInfoReadError:
bars["lq"] = 10
try:
bars["tpl"] = max(50 + float(cinfo.get_tpl()) / 127 * 50, 10)
except ConnInfoReadError:
bars["tpl"] = 50

if row["battery"] == row["rssi"] == row["tpl"] == row["lq"] == 0:
if row["battery"] == row["rssi"] == row["tpl"] == 0:
self._prepare_fader(row["cell_fader"]).animate(start=0.0, end=1.0, duration=400)

w = 14 * self.get_scale_factor()
Expand All @@ -502,12 +494,12 @@ def _update_power_levels(self, tree_iter: Gtk.TreeIter, device: Device, cinfo: c
self.set(tree_iter, **{name: perc, f"{name}_pb": icon})

def _disable_power_levels(self, tree_iter: Gtk.TreeIter) -> None:
row = self.get(tree_iter, "cell_fader", "battery", "rssi", "lq", "tpl")
if row["battery"] == row["rssi"] == row["tpl"] == row["lq"] == 0:
row = self.get(tree_iter, "cell_fader", "battery", "rssi", "tpl")
if row["battery"] == row["rssi"] == row["tpl"] == 0:
return

self.set(tree_iter, battery=0, rssi=0, lq=0, tpl=0)
self._prepare_fader(row["cell_fader"], lambda: self.set(tree_iter, battery_pb=None, rssi_pb=None, lq_pb=None,
self.set(tree_iter, battery=0, rssi=0, tpl=0)
self._prepare_fader(row["cell_fader"], lambda: self.set(tree_iter, battery_pb=None, rssi_pb=None,
tpl_pb=None)).animate(start=1.0, end=0.0, duration=400)

def _prepare_fader(self, fader: AnimBase, callback: Optional[Callable[[], None]] = None) -> AnimBase:
Expand Down Expand Up @@ -559,7 +551,6 @@ def tooltip_query(self, _tw: Gtk.Widget, x: int, y: int, _kb: bool, tooltip: Gtk

elif path[1] == self.columns["battery_pb"] \
or path[1] == self.columns["tpl_pb"] \
or path[1] == self.columns["lq_pb"] \
or path[1] == self.columns["rssi_pb"]:
tree_iter = self.get_iter(path[0])
assert tree_iter is not None
Expand All @@ -572,7 +563,6 @@ def tooltip_query(self, _tw: Gtk.Widget, x: int, y: int, _kb: bool, tooltip: Gtk

battery = self.get(tree_iter, "battery")["battery"]
rssi = self.get(tree_iter, "rssi")["rssi"]
lq = self.get(tree_iter, "lq")["lq"]
tpl = self.get(tree_iter, "tpl")["tpl"]

if battery != 0:
Expand Down Expand Up @@ -600,12 +590,6 @@ def tooltip_query(self, _tw: Gtk.Widget, x: int, y: int, _kb: bool, tooltip: Gtk
lines.append(_("Received Signal Strength: %(rssi)u%% <i>(%(rssi_state)s)</i>") %
{"rssi": rssi, "rssi_state": rssi_state})

if lq != 0:
if path[1] == self.columns["lq_pb"]:
lines.append(_("<b>Link Quality: %(lq)u%%</b>") % {"lq": lq})
else:
lines.append(_("Link Quality: %(lq)u%%") % {"lq": lq})

if tpl != 0:
if tpl < 30:
tpl_state = _("Low")
Expand Down
10 changes: 0 additions & 10 deletions data/icons/pixmaps/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ pixmaps_DATA = \
blueman-battery-80.png \
blueman-battery-90.png \
blueman-battery-100.png \
blueman-lq-10.png \
blueman-lq-20.png \
blueman-lq-30.png \
blueman-lq-40.png \
blueman-lq-50.png \
blueman-lq-60.png \
blueman-lq-70.png \
blueman-lq-80.png \
blueman-lq-90.png \
blueman-lq-100.png \
blueman-rssi-10.png \
blueman-rssi-20.png \
blueman-rssi-30.png \
Expand Down
Binary file removed data/icons/pixmaps/blueman-lq-10.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-100.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-20.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-30.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-40.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-50.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-60.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-70.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-80.png
Binary file not shown.
Binary file removed data/icons/pixmaps/blueman-lq-90.png
Binary file not shown.
10 changes: 0 additions & 10 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ install_data(
'data/icons/pixmaps/blueman-battery-80.png',
'data/icons/pixmaps/blueman-battery-90.png',
'data/icons/pixmaps/blueman-battery-100.png',
'data/icons/pixmaps/blueman-lq-10.png',
'data/icons/pixmaps/blueman-lq-20.png',
'data/icons/pixmaps/blueman-lq-30.png',
'data/icons/pixmaps/blueman-lq-40.png',
'data/icons/pixmaps/blueman-lq-50.png',
'data/icons/pixmaps/blueman-lq-60.png',
'data/icons/pixmaps/blueman-lq-70.png',
'data/icons/pixmaps/blueman-lq-80.png',
'data/icons/pixmaps/blueman-lq-90.png',
'data/icons/pixmaps/blueman-lq-100.png',
'data/icons/pixmaps/blueman-rssi-10.png',
'data/icons/pixmaps/blueman-rssi-20.png',
'data/icons/pixmaps/blueman-rssi-30.png',
Expand Down
4 changes: 2 additions & 2 deletions module/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ BUILT_SOURCES = _blueman.c

bluemanlibdir = $(pyexecdir)
bluemanlib_LTLIBRARIES = _blueman.la
_blueman_la_CFLAGS = $(BLUEZ_CFLAGS) $(PYGOBJECT_CFLAGS) $(PYTHON_CFLAGS) \
_blueman_la_CFLAGS = $(BLUEZ_CFLAGS) $(PYTHON_CFLAGS) \
-DSN_API_NOT_YET_FROZEN
_blueman_la_LDFLAGS = -module -avoid-version -fPIC
_blueman_la_LIBADD = $(BLUEZ_LIBS) $(PYGOBJECT_LIBS) $(PYTHON_LIBS)
_blueman_la_LIBADD = $(BLUEZ_LIBS) $(PYTHON_LIBS)
_blueman_la_SOURCES = \
_blueman.c \
libblueman.c \
Expand Down
32 changes: 0 additions & 32 deletions module/_blueman.pyx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
# coding=utf-8
#cython: language_level=3
import logging

cdef extern from "malloc.h":
cdef void free(void *ptr)
Expand All @@ -14,7 +13,6 @@ cdef extern from "bluetooth/bluetooth.h":
unsigned char b[6]

int ba2str(bdaddr_t *ba, char *str)
int str2ba(char *str, bdaddr_t *ba)

cdef extern from "bluetooth/hci.h":
cdef struct hci_dev_stats:
Expand Down Expand Up @@ -81,14 +79,12 @@ cdef extern from "libblueman.h":

cdef int connection_init(int dev_id, char *addr, conn_info_handles *ci)
cdef int connection_get_rssi(conn_info_handles *ci, signed char *ret_rssi)
cdef int connection_get_lq(conn_info_handles *ci, unsigned char *ret_lq)
cdef int connection_get_tpl(conn_info_handles *ci, signed char *ret_tpl, unsigned char type)
cdef int connection_close(conn_info_handles *ci)
cdef int c_get_rfcomm_channel "get_rfcomm_channel" (unsigned short service_class, char* btd_addr)
cdef int get_rfcomm_list(rfcomm_dev_list_req **ret)
cdef int c_create_rfcomm_device "create_rfcomm_device" (char *local_address, char *remote_address, int channel)
cdef int c_release_rfcomm_device "release_rfcomm_device" (int id)
cdef float get_page_timeout(int hdev)
cdef int _create_bridge(char* name)
cdef int _destroy_bridge(char* name)

Expand All @@ -103,11 +99,8 @@ ERR = {
-4:"Get connection info failed",
-5:"Read RSSI failed",
-6:"Read transmit power level request failed",
-7:"Read Link quality failed",
-8:"Getting rfcomm list failed",
-9:"ERR_SOCKET_FAILED",
-10:"ERR_CANT_READ_PAGE_TIMEOUT",
-11:"ERR_READ_PAGE_TIMEOUT",
-12: "Can't bind RFCOMM socket",
-13: "Can't connect RFCOMM socket",
-14: "Can't create RFCOMM TTY",
Expand Down Expand Up @@ -253,14 +246,6 @@ cdef class conn_info:

return rssi

def get_lq(self):
cdef unsigned char lq
res = connection_get_lq(&self.ci, &lq)
if res < 0:
raise ConnInfoReadError(ERR[res])

return lq

def get_tpl(self, tp=0):
cdef signed char tpl
res = connection_get_tpl(&self.ci, &tpl, tp)
Expand All @@ -269,17 +254,6 @@ cdef class conn_info:

return tpl

def page_timeout(py_hci_name="hci0"):
py_bytes_hci_name = py_hci_name.encode("UTF-8")
cdef char* hci_name = py_bytes_hci_name

dev_id = int(hci_name[3:])
ret = get_page_timeout(dev_id)
if ret < 0:
raise Exception, ERR[ret]
else:
return ret

def device_info(py_hci_name="hci0"):
py_bytes_hci_name = py_hci_name.encode("UTF-8")
cdef char* hci_name = py_bytes_hci_name
Expand Down Expand Up @@ -324,9 +298,3 @@ def device_info(py_hci_name="hci0"):
("stat", dict(x))]

return dict(z)

cdef extern from "glib-object.h":
ctypedef struct GObject

cdef extern from "pygobject.h":
cdef GObject* pygobject_get(object)
59 changes: 2 additions & 57 deletions module/libblueman.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static inline unsigned long __tv_to_jiffies(const struct timeval *tv)

return jif/10000;
}

int _create_bridge(const char* name) {
int sock;
sock = socket(AF_INET, SOCK_STREAM, 0);
Expand Down Expand Up @@ -132,7 +132,7 @@ int _destroy_bridge(const char* name) {
return 0;
}

int find_conn(int s, int dev_id, long arg)
static int find_conn(int s, int dev_id, long arg)
{
struct hci_conn_list_req *cl;
struct hci_conn_info *ci;
Expand Down Expand Up @@ -220,16 +220,6 @@ int connection_get_rssi(struct conn_info_handles *ci, int8_t *ret_rssi)

}

int connection_get_lq(struct conn_info_handles *ci, uint8_t *ret_lq)
{
uint8_t lq;
if (hci_read_link_quality(ci->dd, htobs(ci->handle), &lq, 1000) < 0) {
return ERR_READ_LQ_FAILED;
}
*ret_lq = lq;
return 1;
}

int connection_get_tpl(struct conn_info_handles *ci, int8_t *ret_tpl, uint8_t type)
{
int8_t level;
Expand Down Expand Up @@ -431,48 +421,3 @@ int release_rfcomm_device(int id) {
return 0;
}
}

float get_page_timeout(int hdev)
{
struct hci_request rq;
int s;
float ret;

if ((s = hci_open_dev(hdev)) < 0) {
ret = ERR_HCI_DEV_OPEN_FAILED;
goto out;
}

memset(&rq, 0, sizeof(rq));

uint16_t timeout;
read_page_timeout_rp rp;

rq.ogf = OGF_HOST_CTL;
rq.ocf = OCF_READ_PAGE_TIMEOUT;
rq.rparam = &rp;
rq.rlen = READ_PAGE_TIMEOUT_RP_SIZE;

if (hci_send_req(s, &rq, 1000) < 0) {
ret = ERR_CANT_READ_PAGE_TIMEOUT;
goto out;
}
if (rp.status) {
ret = ERR_READ_PAGE_TIMEOUT;
goto out;
}

timeout = btohs(rp.timeout);
ret = ((float)timeout * 0.625);

out:
if (s >= 0)
hci_close_dev(s);
return ret;
}






6 changes: 0 additions & 6 deletions module/libblueman.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#define ERR_GET_CONN_INFO_FAILED -4
#define ERR_READ_RSSI_FAILED -5
#define ERR_READ_TPL_FAILED -6
#define ERR_READ_LQ_FAILED -7
#define ERR_GET_RFCOMM_LIST_FAILED -8
#define ERR_SOCKET_FAILED -9
#define ERR_CANT_READ_PAGE_TIMEOUT -10
#define ERR_READ_PAGE_TIMEOUT -11
#define ERR_BIND_FAILED -12
#define ERR_CONNECT_FAILED -13
#define ERR_CREATE_DEV_FAILED -14
Expand All @@ -20,17 +17,14 @@ struct conn_info_handles {
int dd;
};

int find_conn(int s, int dev_id, long arg);
int connection_init(int dev_id, char *addr, struct conn_info_handles *ci);
int connection_get_rssi(struct conn_info_handles *ci, int8_t *ret_rssi);
int connection_get_lq(struct conn_info_handles *ci, uint8_t *ret_lq);
int connection_get_tpl(struct conn_info_handles *ci, int8_t *ret_tpl, uint8_t type);
int connection_close(struct conn_info_handles *ci);
int get_rfcomm_channel(uint16_t uuid, char* btd_addr);
int get_rfcomm_list(struct rfcomm_dev_list_req **result);
int create_rfcomm_device(char *local_address, char *remote_address, int channel);
int release_rfcomm_device(int id);
float get_page_timeout(int hdev);

int _create_bridge(const char* name);
int _destroy_bridge(const char* name);
2 changes: 0 additions & 2 deletions stubs/_blueman.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class conn_info:
failed: bool
def __init__(self, addr: str, hci_name: str) -> None: ...
def deinit(self) -> None: ...
def get_lq(self) -> int: ...
def get_rssi(self) -> int: ...
def get_tpl(self) -> int: ...
def init(self) -> None: ...
Expand All @@ -52,7 +51,6 @@ def create_bridge(name: str = "pan1") -> None: ...
def create_rfcomm_device(local_address: str, remote_address: str, channel: int) -> int: ...
def destroy_bridge(name: str = "pan1") -> None: ...
def device_info(hci_name: str = "hci0") -> _HciInfo: ...
def page_timeout(hci_name: str = "hci0") -> float: ...
def get_rfcomm_channel(uuid: int, bdaddr: str) -> Optional[int]: ...
def release_rfcomm_device(id: int) -> int: ...
def rfcomm_list() -> List[_RfcommDev]: ...