Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f35269ad authored by John Lai's avatar John Lai Committed by Gerrit Code Review
Browse files

Merge "Floss: Add GATT client command for registering notification"

parents 56a2ed9c e6be4a25
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ fn build_commands() -> HashMap<String, CommandOption> {
                    "gatt write-characteristic <address> <handle> <NoRsp|Write|Prepare> <value>",
                ),
                String::from("gatt read-characteristic <address> <handle>"),
                String::from("gatt register-notification <address> <handle> <enable|disable>"),
                String::from("gatt register-server"),
            ],
            description: String::from("GATT tools"),
@@ -1051,6 +1052,31 @@ impl CommandHandler {
                    .unwrap()
                    .read_characteristic(client_id, addr, handle, auth_req);
            }
            "register-notification" => {
                let addr = String::from(get_arg(args, 1)?);
                let handle = String::from(get_arg(args, 2)?)
                    .parse::<i32>()
                    .or(Err("Failed to parse handle"))?;
                let enable = match &get_arg(args, 3)?[..] {
                    "enable" => true,
                    "disable" => false,
                    _ => {
                        return Err("Failed to parse enable".into());
                    }
                };

                let client_id = self
                    .lock_context()
                    .gatt_client_context
                    .client_id
                    .ok_or("GATT client is not yet registered.")?;

                self.lock_context()
                    .gatt_dbus
                    .as_ref()
                    .unwrap()
                    .register_for_notification(client_id, addr, handle, enable);
            }
            "register-server" => {
                let dbus_connection = self.lock_context().dbus_connection.clone();
                let dbus_crossroads = self.lock_context().dbus_crossroads.clone();