Commit Diff


commit - 6bcd77273bd44b0ef787cca4a1902f6e898fdd8f
commit + a4a98bd84c66a3d4fdc7b0e46a99aaa7b2efbc40
blob - c731e794abb8063c2dfcbab8fd8c5fde30e419e8
blob + 7449db06ef11d571d5fbbbecbaf809c20217e372
--- Cargo.lock
+++ Cargo.lock
@@ -18,17 +18,6 @@ source = "registry+https://github.com/rust-lang/crates
 checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
 
 [[package]]
-name = "async-trait"
-version = "0.1.58"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
 name = "atty"
 version = "0.2.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -56,7 +45,7 @@ name = "ble-throughput-client"
 version = "0.1.0"
 dependencies = [
  "anyhow",
- "btleplug",
+ "bluer",
  "env_logger",
  "futures",
  "log",
@@ -66,182 +55,66 @@ dependencies = [
 ]
 
 [[package]]
-name = "block"
-version = "0.1.6"
+name = "bluer"
+version = "0.15.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
-
-[[package]]
-name = "bluez-async"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e81db626818b179ab5fc3393b7ac77462335f716b302ef1ff1866473ab6ddb25"
+checksum = "fbe1b56a42432f65f98bf616be9e43bb498e104010a2c5eb9f89cdcc97e7bdb4"
 dependencies = [
- "async-trait",
- "bitflags",
- "bluez-generated",
+ "custom_debug",
  "dbus",
+ "dbus-crossroads",
  "dbus-tokio",
+ "displaydoc",
  "futures",
- "itertools",
- "log",
- "serde",
- "serde-xml-rs",
- "thiserror",
- "tokio",
- "uuid",
-]
-
-[[package]]
-name = "bluez-generated"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33ad8f302dd79411881cd0181f3bd9fc91a959b71c3a13159bd8a07d2c40dc7f"
-dependencies = [
- "dbus",
-]
-
-[[package]]
-name = "btleplug"
-version = "0.10.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de2583ed1bbad11cc75649a771a4a340dff69809643f760832f4a1e8cb9f617c"
-dependencies = [
- "async-trait",
- "bitflags",
- "bluez-async",
- "cocoa",
- "dashmap",
- "dbus",
- "futures",
- "jni",
- "jni-utils",
+ "hex",
+ "lazy_static",
  "libc",
  "log",
- "objc",
- "once_cell",
- "static_assertions",
- "thiserror",
+ "nix",
+ "num-derive",
+ "num-traits",
+ "pin-project",
+ "serde",
+ "serde_json",
+ "strum",
  "tokio",
  "tokio-stream",
  "uuid",
- "windows",
 ]
 
 [[package]]
 name = "bytes"
-version = "1.2.1"
+version = "1.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
+checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
 
 [[package]]
-name = "cesu8"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
-
-[[package]]
 name = "cfg-if"
 version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
 
 [[package]]
-name = "cocoa"
-version = "0.24.0"
+name = "custom_debug"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f63902e9223530efb4e26ccd0cf55ec30d592d3b42e21a28defc42a9586e832"
+checksum = "e8225047674d65dcf4321e6bd3e060bdbbe940604a99b1559827f3e61c498d1e"
 dependencies = [
- "bitflags",
- "block",
- "cocoa-foundation",
- "core-foundation",
- "core-graphics",
- "foreign-types",
- "libc",
- "objc",
+ "custom_debug_derive",
 ]
 
 [[package]]
-name = "cocoa-foundation"
-version = "0.1.0"
+name = "custom_debug_derive"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
+checksum = "9b35d34eb004bf2d33c093f1c55ee77829e8654644288d3b6afd8c2d99d23729"
 dependencies = [
- "bitflags",
- "block",
- "core-foundation",
- "core-graphics-types",
- "foreign-types",
- "libc",
- "objc",
+ "proc-macro2",
+ "syn",
+ "synstructure",
 ]
 
 [[package]]
-name = "combine"
-version = "4.6.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
-dependencies = [
- "bytes",
- "memchr",
-]
-
-[[package]]
-name = "core-foundation"
-version = "0.9.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
-dependencies = [
- "core-foundation-sys",
- "libc",
-]
-
-[[package]]
-name = "core-foundation-sys"
-version = "0.8.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
-
-[[package]]
-name = "core-graphics"
-version = "0.22.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
-dependencies = [
- "bitflags",
- "core-foundation",
- "core-graphics-types",
- "foreign-types",
- "libc",
-]
-
-[[package]]
-name = "core-graphics-types"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
-dependencies = [
- "bitflags",
- "core-foundation",
- "foreign-types",
- "libc",
-]
-
-[[package]]
-name = "dashmap"
-version = "5.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
-dependencies = [
- "cfg-if",
- "hashbrown",
- "lock_api",
- "once_cell",
- "parking_lot_core",
-]
-
-[[package]]
 name = "dbus"
 version = "0.9.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -255,6 +128,15 @@ dependencies = [
 ]
 
 [[package]]
+name = "dbus-crossroads"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "554114296d012b33fdaf362a733db6dc5f73c4c9348b8b620ddd42e61b406e30"
+dependencies = [
+ "dbus",
+]
+
+[[package]]
 name = "dbus-tokio"
 version = "0.7.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -266,10 +148,15 @@ dependencies = [
 ]
 
 [[package]]
-name = "either"
-version = "1.8.0"
+name = "displaydoc"
+version = "0.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
+checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
 
 [[package]]
 name = "env_logger"
@@ -285,21 +172,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "foreign-types"
-version = "0.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
-dependencies = [
- "foreign-types-shared",
-]
-
-[[package]]
-name = "foreign-types-shared"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
-
-[[package]]
 name = "futures"
 version = "0.3.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -400,10 +272,10 @@ dependencies = [
 ]
 
 [[package]]
-name = "hashbrown"
-version = "0.12.3"
+name = "heck"
+version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
+checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
 
 [[package]]
 name = "hermit-abi"
@@ -415,56 +287,30 @@ dependencies = [
 ]
 
 [[package]]
+name = "hex"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
+
+[[package]]
 name = "humantime"
 version = "2.1.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
 
 [[package]]
-name = "itertools"
-version = "0.10.5"
+name = "itoa"
+version = "1.0.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
-dependencies = [
- "either",
-]
+checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
 
 [[package]]
-name = "jni"
-version = "0.19.0"
+name = "lazy_static"
+version = "1.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec"
-dependencies = [
- "cesu8",
- "combine",
- "jni-sys",
- "log",
- "thiserror",
- "walkdir",
-]
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
 
 [[package]]
-name = "jni-sys"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
-
-[[package]]
-name = "jni-utils"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0d3a00638470bedd9bcbea85292bef2207e6db984079db0bd70148a449cdb457"
-dependencies = [
- "dashmap",
- "futures",
- "jni",
- "log",
- "once_cell",
- "static_assertions",
- "uuid",
-]
-
-[[package]]
 name = "libc"
 version = "0.2.137"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -480,16 +326,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "lock_api"
-version = "0.4.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
-dependencies = [
- "autocfg",
- "scopeguard",
-]
-
-[[package]]
 name = "log"
 version = "0.4.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -499,15 +335,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "malloc_buf"
-version = "0.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
-dependencies = [
- "libc",
-]
-
-[[package]]
 name = "memchr"
 version = "2.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -526,6 +353,37 @@ dependencies = [
 ]
 
 [[package]]
+name = "nix"
+version = "0.24.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
+dependencies = [
+ "bitflags",
+ "cfg-if",
+ "libc",
+]
+
+[[package]]
+name = "num-derive"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
 name = "num_cpus"
 version = "1.13.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -536,31 +394,23 @@ dependencies = [
 ]
 
 [[package]]
-name = "objc"
-version = "0.2.7"
+name = "pin-project"
+version = "1.0.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
+checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc"
 dependencies = [
- "malloc_buf",
+ "pin-project-internal",
 ]
 
 [[package]]
-name = "once_cell"
-version = "1.15.0"
+name = "pin-project-internal"
+version = "1.0.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
-
-[[package]]
-name = "parking_lot_core"
-version = "0.9.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0"
+checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55"
 dependencies = [
- "cfg-if",
- "libc",
- "redox_syscall",
- "smallvec",
- "windows-sys",
+ "proc-macro2",
+ "quote",
+ "syn",
 ]
 
 [[package]]
@@ -636,15 +486,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "redox_syscall"
-version = "0.2.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
-dependencies = [
- "bitflags",
-]
-
-[[package]]
 name = "regex"
 version = "1.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -662,19 +503,16 @@ source = "registry+https://github.com/rust-lang/crates
 checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
 
 [[package]]
-name = "same-file"
-version = "1.0.6"
+name = "rustversion"
+version = "1.0.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
-dependencies = [
- "winapi-util",
-]
+checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
 
 [[package]]
-name = "scopeguard"
-version = "1.1.0"
+name = "ryu"
+version = "1.0.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
 
 [[package]]
 name = "serde"
@@ -686,18 +524,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "serde-xml-rs"
-version = "0.5.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "65162e9059be2f6a3421ebbb4fef3e74b7d9e7c60c50a0e292c6239f19f1edfa"
-dependencies = [
- "log",
- "serde",
- "thiserror",
- "xml-rs",
-]
-
-[[package]]
 name = "serde_derive"
 version = "1.0.147"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -709,6 +535,17 @@ dependencies = [
 ]
 
 [[package]]
+name = "serde_json"
+version = "1.0.89"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
 name = "slab"
 version = "0.4.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -718,12 +555,6 @@ dependencies = [
 ]
 
 [[package]]
-name = "smallvec"
-version = "1.10.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
-
-[[package]]
 name = "socket2"
 version = "0.4.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -734,12 +565,28 @@ dependencies = [
 ]
 
 [[package]]
-name = "static_assertions"
-version = "1.1.0"
+name = "strum"
+version = "0.24.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
+checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
+dependencies = [
+ "strum_macros",
+]
 
 [[package]]
+name = "strum_macros"
+version = "0.24.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "rustversion",
+ "syn",
+]
+
+[[package]]
 name = "syn"
 version = "1.0.103"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -751,6 +598,18 @@ dependencies = [
 ]
 
 [[package]]
+name = "synstructure"
+version = "0.12.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "unicode-xid",
+]
+
+[[package]]
 name = "termcolor"
 version = "1.1.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -760,33 +619,15 @@ dependencies = [
 ]
 
 [[package]]
-name = "thiserror"
-version = "1.0.37"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
-dependencies = [
- "thiserror-impl",
-]
-
-[[package]]
-name = "thiserror-impl"
-version = "1.0.37"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
 name = "tokio"
 version = "1.21.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
 dependencies = [
  "autocfg",
+ "bytes",
  "libc",
+ "memchr",
  "mio",
  "num_cpus",
  "pin-project-lite",
@@ -815,43 +656,27 @@ dependencies = [
  "futures-core",
  "pin-project-lite",
  "tokio",
- "tokio-util",
 ]
 
 [[package]]
-name = "tokio-util"
-version = "0.7.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740"
-dependencies = [
- "bytes",
- "futures-core",
- "futures-sink",
- "pin-project-lite",
- "tokio",
-]
-
-[[package]]
 name = "unicode-ident"
 version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
 
 [[package]]
+name = "unicode-xid"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
+
+[[package]]
 name = "uuid"
 version = "1.2.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83"
-
-[[package]]
-name = "walkdir"
-version = "2.3.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
 dependencies = [
- "same-file",
- "winapi",
- "winapi-util",
+ "getrandom",
 ]
 
 [[package]]
@@ -892,121 +717,58 @@ source = "registry+https://github.com/rust-lang/crates
 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 
 [[package]]
-name = "windows"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a3ed69de2c1f8d0524a8a3417a80a85dd316a071745fbfdf5eb028b310058ab"
-dependencies = [
- "windows_aarch64_gnullvm 0.41.0",
- "windows_aarch64_msvc 0.41.0",
- "windows_i686_gnu 0.41.0",
- "windows_i686_msvc 0.41.0",
- "windows_x86_64_gnu 0.41.0",
- "windows_x86_64_gnullvm 0.41.0",
- "windows_x86_64_msvc 0.41.0",
-]
-
-[[package]]
 name = "windows-sys"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
 dependencies = [
- "windows_aarch64_gnullvm 0.42.0",
- "windows_aarch64_msvc 0.42.0",
- "windows_i686_gnu 0.42.0",
- "windows_i686_msvc 0.42.0",
- "windows_x86_64_gnu 0.42.0",
- "windows_x86_64_gnullvm 0.42.0",
- "windows_x86_64_msvc 0.42.0",
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
 ]
 
 [[package]]
 name = "windows_aarch64_gnullvm"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "163d2761774f2278ecb4e6719e80b2b5e92e5a2be73a7bcd3ef624dd5e3091fd"
-
-[[package]]
-name = "windows_aarch64_gnullvm"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
 
 [[package]]
 name = "windows_aarch64_msvc"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ef005ff2bceb00d3b84166a359cc19084f9459754fd3fe5a504dee3dddcd0a0c"
-
-[[package]]
-name = "windows_aarch64_msvc"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
 
 [[package]]
 name = "windows_i686_gnu"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02b4df2d51e32f03f8b4b228e487828c03bcb36d97b216fc5463bcea5bb1440b"
-
-[[package]]
-name = "windows_i686_gnu"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
 
 [[package]]
 name = "windows_i686_msvc"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "568a966834571f2f3267f07dd72b4d8507381f25e53d056808483b2637385ef7"
-
-[[package]]
-name = "windows_i686_msvc"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
 
 [[package]]
 name = "windows_x86_64_gnu"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fc395dac1adf444e276d096d933ae7961361c8cda3245cffef7a9b3a70a8f994"
-
-[[package]]
-name = "windows_x86_64_gnu"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
 
 [[package]]
 name = "windows_x86_64_gnullvm"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "90e8ec22b715d5b436e1d59c8adad6c744dc20cd984710121d5836b4e8dbb5e0"
-
-[[package]]
-name = "windows_x86_64_gnullvm"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
 
 [[package]]
 name = "windows_x86_64_msvc"
-version = "0.41.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8b9761f0216b669019df1512f6e25e5ee779bf61c5cdc43c7293858e7efd7926"
-
-[[package]]
-name = "windows_x86_64_msvc"
 version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
-
-[[package]]
-name = "xml-rs"
-version = "0.8.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
blob - cb4e81ba99070d7bc4e550a10b68117fe794098b
blob + f7f0677ba2555ffae33c0aea3dde345e56a81a8b
--- Cargo.toml
+++ Cargo.toml
@@ -6,10 +6,10 @@ edition = "2021"
 
 [dependencies]
 anyhow = "1.0.66"
-btleplug = "0.10.1"
 env_logger = "0.9.1"
 futures = "0.3.25"
 log = "0.4.17"
 tokio = { version = "1.21.2", features = ["rt-multi-thread", "macros"] }
 uuid = "1.2.1"
 rand = "0.8.5"
+bluer = { version = "0.15.1", features = ["bluetoothd"] }
blob - 2c7259e1ff4937fca95ff41df230c79d34d4200c
blob + 0c8d3ed560e0d50acf2a3e85a19d8e8bb55a6f23
--- src/main.rs
+++ src/main.rs
@@ -1,58 +1,66 @@
+use std::collections::HashMap;
+
+use bluer::{gatt::remote::Characteristic, AdapterEvent, Device};
+use futures::StreamExt;
 use log::*;
-use std::time::Duration;
-use tokio::time;
-
-use btleplug::api::{Central, Characteristic, Manager as _, Peripheral, ScanFilter, WriteType};
-use btleplug::platform::Manager;
 use uuid::Uuid;
 
 //const ESP_MAC_ADDR: [u8; 6] = [0x60, 0x55, 0xf9, 0xc1, 0x1e, 0x2e];
-const LAPTOP_MAC_ADDR: [u8; 6] = [0xF8, 0x34, 0x41, 0x42, 0x08, 0x32];
+//const LAPTOP_MAC_ADDR: [u8; 6] = [0xCD, 0x09, 0xE7, 0x6F, 0x73, 0xBA];
 const SERVICE_UUID: Uuid = Uuid::from_u128(0x061f8f7050293e727e62a46aa61cda68);
 //const BUFFER_READY_UUID: Uuid = Uuid::from_u128(0x78844add576bb4cd3c40f1f3d536a38a);
 const DATA_BUFFER_UUID: Uuid = Uuid::from_u128(0xb57fc8740ebd1d2695ae2d31db630a54);
 const BUFFER_LEN_UUID: Uuid = Uuid::from_u128(0x3e0fb4716b176bbc63b82b70b6cf54dd);
 const SERVICE_CHARACTERISTICS: [Uuid; 2] = [BUFFER_LEN_UUID, DATA_BUFFER_UUID];
 
-async fn find_device(
-    adapter: &btleplug::platform::Adapter,
-    mac_addr: [u8; 6],
-) -> Result<Option<btleplug::platform::Peripheral>, btleplug::Error> {
-    info!(
-        "Scanning for device ({:?}) with adapter {:?}",
-        mac_addr, adapter
-    );
+async fn find_characteristic(
+    device: &Device,
+) -> anyhow::Result<Option<HashMap<Uuid, Characteristic>>> {
+    let addr = device.address();
+    let uuids = device.uuids().await?.unwrap_or_default();
 
-    // TODO: device should advertise service so that ScanFilter can be used with the service ID
-    adapter.start_scan(ScanFilter::default()).await?;
-    info!("Scanning for 10 seconds");
-    time::sleep(Duration::from_secs(10)).await;
-    let peripherals = adapter.peripherals().await?;
-    info!(
-        "Found peripherals: {:?}",
-        peripherals.iter().map(|p| p.address()).collect::<Vec<_>>()
-    );
+    debug!("Scanning device {} for required characteristics", addr);
 
-    for p in peripherals {
-        let props = p.properties().await?.unwrap();
-        if props.address != mac_addr.into() {
-            continue;
+    if !uuids.contains(&SERVICE_UUID) {
+        debug!("Device doesn't contain service");
+        return Ok(None);
+    }
+    debug!("Device contains required service");
+
+    if !device.is_connected().await? {
+        debug!("Not connected to device. Connecting...");
+        device.connect().await?;
+    }
+    debug!("Connected to device");
+
+    let mut chars: HashMap<Uuid, Characteristic> = HashMap::new();
+    for service in device.services().await? {
+        debug!("Inspecting service {}", service.id());
+        let cs = service.characteristics().await?;
+
+        for c in cs {
+            let uuid = c.uuid().await?;
+            if SERVICE_CHARACTERISTICS.contains(&uuid) {
+                chars.insert(uuid, c);
+            }
         }
-        info!("Found device! Properties: {:?}", props);
-        return Ok(Some(p));
     }
 
-    error!("Could not find device");
-    Ok(None)
+    if chars.is_empty() || chars.len() != SERVICE_CHARACTERISTICS.len() {
+        debug!("Not all characteristics are supplied in device");
+        Ok(None)
+    } else {
+        Ok(Some(chars))
+    }
 }
 
-async fn get_buffer_len(
-    peripheral: &btleplug::platform::Peripheral,
-    characteristic: &Characteristic,
-) -> Result<usize, btleplug::Error> {
+async fn get_buffer_len(c: &Characteristic) -> anyhow::Result<usize> {
     const LEN_USIZE: usize = std::mem::size_of::<usize>();
-    let payload = peripheral.read(characteristic).await?;
+    if !c.flags().await?.read {
+        anyhow::bail!("Buffer len characteristic can't be read");
+    }
 
+    let payload = c.read().await?;
     let buf: [u8; LEN_USIZE] = std::iter::repeat(0u8)
         .take(LEN_USIZE - payload.len())
         .chain(payload.into_iter())
@@ -67,79 +75,61 @@ async fn get_buffer_len(
 async fn main() -> anyhow::Result<()> {
     env_logger::init();
 
-    let manager: Manager = Manager::new().await?;
-    let adapter_list = manager.adapters().await?;
+    let dev_name = std::env::var("BLUETOOTH_DEVICE").expect("BLUETOOTH_DEVICE env var not set");
 
-    // TODO: only allow adapters that support BLE 5.0 or higher
-    if adapter_list.is_empty() {
-        anyhow::bail!("No adapters found");
-    }
+    let session = bluer::Session::new().await?;
+    let adapter = session.adapter(&dev_name)?;
+    adapter.set_powered(true).await?;
+    debug!("Adapter ready");
 
-    let mut esp: Option<btleplug::platform::Peripheral> = None;
-    for adapter in adapter_list.iter() {
-        let peripheral = find_device(adapter, LAPTOP_MAC_ADDR).await?;
-        if peripheral.is_some() {
-            esp = peripheral;
-            break;
+    let discover = adapter.discover_devices().await?;
+    debug!("Started discovering devices");
+    futures::pin_mut!(discover);
+
+    let mut device: Option<Device> = None;
+    let mut chars: Option<HashMap<Uuid, Characteristic>> = None;
+    while let Some(evt) = discover.next().await {
+        match evt {
+            AdapterEvent::DeviceAdded(addr) => {
+                debug!("Discovered device with address {}", addr);
+                device = Some(adapter.device(addr)?);
+                if let Some(cs) = find_characteristic(device.as_ref().unwrap()).await? {
+                    debug!("Characteristics found");
+                    chars = Some(cs);
+                    break;
+                }
+            }
+            AdapterEvent::DeviceRemoved(addr) => {
+                info!("Device removed: {}", addr);
+            }
+            _ => {}
         }
     }
 
-    let esp = esp.unwrap_or_else(|| panic!("Peripheral with MAC {:?} not found", LAPTOP_MAC_ADDR));
-    info!("Connecting to {:?}", LAPTOP_MAC_ADDR);
-    esp.connect().await?;
-    info!("Discovering services");
-    esp.discover_services().await?;
-    let service = match esp.services().into_iter().find(|s| s.uuid == SERVICE_UUID) {
-        Some(s) => s,
-        None => anyhow::bail!("ESP doesn't provide service with UUID {:?}", SERVICE_UUID),
-    };
-    // TODO: assert DLE with length 251
-
-    // check if service has all the characteristics that are needed
-    // not checking if they have the correct properties...
-    if !SERVICE_CHARACTERISTICS
-        .iter()
-        .all(|c| service.characteristics.iter().any(|ca| ca.uuid == *c))
-    {
-        anyhow::bail!(
-            "Service {:?} of peripheral with MAC {:?} doesn't provide all the characteristics: {:?}",
-            SERVICE_UUID,
-            LAPTOP_MAC_ADDR,
-            SERVICE_CHARACTERISTICS
-        );
-    } else {
-        info!("Service {:?} provides all characteristics", SERVICE_UUID);
+    let chars = chars.unwrap_or_else(|| panic!("Required characteristics could not be found"));
+    if device.is_none() {
+        panic!("Not connected to any device");
     }
+    let device = device.unwrap();
 
-    // get the buffer length the esp set to know how big the buffer is
-    let buffer_len_char = service
-        .characteristics
-        .iter()
-        .find(|c| c.uuid == BUFFER_LEN_UUID)
-        .unwrap();
-    let buffer_len = get_buffer_len(&esp, buffer_len_char).await?;
-    info!("ESP buffer length: {}", buffer_len);
+    let buffer_len = get_buffer_len(chars.get(&BUFFER_LEN_UUID).unwrap()).await?;
+    debug!("buffer len: {}", buffer_len);
+    let buffer_write_char = chars.get(&DATA_BUFFER_UUID).unwrap();
+    // write without response
+    let writer = buffer_write_char.write_io().await?;
 
-    let data_buffer_char = service
-        .characteristics
-        .iter()
-        .find(|c| c.uuid == DATA_BUFFER_UUID)
-        .unwrap();
-
     info!("Sending (512 byte * 8) * 1024 iterations / (10^3) = 4194.304 kbit");
     for _ in 0..1024 {
         let buffer: Vec<u8> = std::iter::repeat_with(rand::random)
             .take(buffer_len)
             .collect();
 
-        esp.write(data_buffer_char, &buffer, WriteType::WithoutResponse)
-            .await?;
+        writer.send(&buffer).await?;
     }
 
+    tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
     info!("Done");
-    tokio::time::sleep(std::time::Duration::from_secs(60)).await;
-    esp.disconnect().await?;
-    info!("Disconnected");
+    device.disconnect().await?;
 
     Ok(())
 }