Diff between 37267653ed6add1fbf2f05b2380822e176b8c721 and bf124080078e747909c0177f8780999e51f1c812

Changed Files

File Additions Deletions Status
proximity/monitor.c +13 -1 modified

Full Patch

diff --git a/proximity/monitor.c b/proximity/monitor.c
index a6bdf34..e271a5d 100644
--- a/proximity/monitor.c
+++ b/proximity/monitor.c
@@ -69,6 +69,8 @@ struct monitor {
 	char *linklosslevel;		/* Link Loss Alert Level */
 	char *immediatelevel;		/* Immediate Alert Level */
 	char *signallevel;		/* Path Loss RSSI level */
+	uint16_t linklosshandle;	/* Link Loss Characteristic
+					 * Value Handle */
 	guint attioid;
 };
 
@@ -145,8 +147,10 @@ static void char_discovered_cb(GSList *characteristics, guint8 status,
 
 	/* Assume there is a single Alert Level characteristic */
 	chr = characteristics->data;
+	monitor->linklosshandle = chr->value_handle;
 
-	gatt_write_cmd(monitor->attrib, chr->value_handle, &value, 1, NULL, NULL);
+	gatt_write_cmd(monitor->attrib, monitor->linklosshandle, &value, 1,
+								NULL, NULL);
 }
 
 static int write_alert_level(struct monitor *monitor)
@@ -154,6 +158,14 @@ static int write_alert_level(struct monitor *monitor)
 	struct att_range *linkloss = monitor->linkloss;
 	bt_uuid_t uuid;
 
+	if (monitor->linklosshandle) {
+		uint8_t value = str2level(monitor->linklosslevel);
+
+		gatt_write_cmd(monitor->attrib, monitor->linklosshandle,
+							&value, 1, NULL, NULL);
+		return 0;
+	}
+
 	bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
 
 	/* FIXME: use cache (requires service changed support) ? */