diff --git a/CHANGELOG.md b/CHANGELOG.md index fcf91c9..a67a98d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how Security -- in case of vulnerabilities. --> +## [0.17.0] + +### Changed + +- Properly close connections when an instrument model is `drop`'d + ## [0.16.1] ### Fixed @@ -59,7 +65,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - Using `read_password`instead of `prompt_password` of rpassword crate (TSP-517) -[Unreleased]: https://github.com/tektronix/tsp-toolkit-kic-lib/compare/v0.16.1..HEAD +[Unreleased]: https://github.com/tektronix/tsp-toolkit-kic-lib/compare/v0.17.0..HEAD +[0.17.0]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.17.0 [0.16.1]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.16.1 [0.15.1]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.15.1 [0.15.0]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.15.0 diff --git a/Cargo.lock b/Cargo.lock index 11c920e..edc4314 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anyhow" @@ -103,15 +103,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9" [[package]] name = "cc" -version = "1.0.101" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" [[package]] name = "cfg-if" @@ -130,7 +130,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -324,6 +324,12 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "http" version = "1.1.0" @@ -337,9 +343,9 @@ dependencies = [ [[package]] name = "http-body" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http", @@ -366,9 +372,9 @@ checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "hyper" -version = "1.3.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", @@ -419,9 +425,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" +checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" dependencies = [ "bytes", "futures-channel", @@ -569,13 +575,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ + "hermit-abi", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -633,9 +640,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.0" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" dependencies = [ "memchr", ] @@ -648,9 +655,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" -version = "0.10.64" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.6.0", "cfg-if", @@ -680,9 +687,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.102" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", @@ -778,9 +785,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "predicates" -version = "3.1.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" dependencies = [ "anstyle", "predicates-core", @@ -788,15 +795,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" [[package]] name = "predicates-tree" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" dependencies = [ "predicates-core", "termtree", @@ -946,9 +953,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.10" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "once_cell", "rustls-pki-types", @@ -975,9 +982,9 @@ checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" [[package]] name = "rustls-webpki" -version = "0.102.4" +version = "0.102.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" dependencies = [ "ring", "rustls-pki-types", @@ -1018,9 +1025,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", "core-foundation", @@ -1031,9 +1038,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" +checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" dependencies = [ "core-foundation-sys", "libc", @@ -1041,18 +1048,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", @@ -1061,11 +1068,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.118" +version = "1.0.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -1144,9 +1152,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.68" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -1200,18 +1208,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -1220,9 +1228,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -1245,9 +1253,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.38.0" +version = "1.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +checksum = "daa4fb1bc778bd6f04cbfc4bb2d06a7396a8f299dc33ea1900cedaa316f467b1" dependencies = [ "backtrace", "bytes", @@ -1255,7 +1263,7 @@ dependencies = [ "mio", "pin-project-lite", "socket2", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1358,7 +1366,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "tsp-toolkit-kic-lib" -version = "0.16.1" +version = "0.17.0" dependencies = [ "anyhow", "bytes", @@ -1423,9 +1431,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "want" @@ -1524,7 +1532,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1542,7 +1550,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -1562,18 +1570,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -1584,9 +1592,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1596,9 +1604,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1608,15 +1616,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1626,9 +1634,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1638,9 +1646,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1650,9 +1658,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1662,9 +1670,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winreg" diff --git a/Cargo.toml b/Cargo.toml index 8a56382..528ded0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tsp-toolkit-kic-lib" description = "A library specifically enabling communication to the Keithley product-line of instruments" -version = "0.16.1" +version = "0.17.0" authors = ["Keithley Instruments, LLC"] edition = "2021" repository = "https://github.com/tektronix/tsp-toolkit-kic-lib" diff --git a/src/model/ki2600.rs b/src/model/ki2600.rs index 96629a2..b4b98d1 100644 --- a/src/model/ki2600.rs +++ b/src/model/ki2600.rs @@ -4,6 +4,7 @@ use std::{ }; use bytes::Buf; +use tracing::trace; use crate::{ instrument::{ @@ -161,13 +162,26 @@ impl Flash for Instrument { } impl Read for Instrument { + #[tracing::instrument(skip(self, buf))] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { - self.interface.read(buf) + let b = self.interface.read(buf)?; + let ascii = String::from_utf8_lossy(buf); + let ascii = ascii.trim_end().trim_matches(['\0', '\n', '\r']); + if !ascii.is_empty() { + trace!("read from instrument: '{ascii}'"); + } + Ok(b) } } impl Write for Instrument { + #[tracing::instrument(skip(self))] fn write(&mut self, buf: &[u8]) -> std::io::Result { + if String::from_utf8_lossy(buf).contains("password") { + trace!("writing to instrument: 'password ****'"); + } else { + trace!("writing to instrument: '{}'", String::from_utf8_lossy(buf)); + } self.interface.write(buf) } @@ -184,7 +198,13 @@ impl NonBlock for Instrument { impl Drop for Instrument { fn drop(&mut self) { - let _ = self.interface.write_all(b"password\n"); + trace!("Calling 2600 instrument drop"); + let _ = self.write_all(b"password\n"); + std::thread::sleep(Duration::from_millis(100)); + let _ = self.write_all(b"*RST\n"); + std::thread::sleep(Duration::from_millis(100)); + let _ = self.write_all(b"abort\n"); + std::thread::sleep(Duration::from_millis(100)); } } @@ -271,6 +291,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -410,6 +435,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -552,6 +582,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -604,6 +639,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -682,6 +722,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -757,6 +802,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -832,6 +882,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -913,6 +968,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -965,10 +1025,14 @@ mod unit { .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() - .times(1) - .in_sequence(&mut seq) + .times(..) .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) diff --git a/src/model/ki3700.rs b/src/model/ki3700.rs index 1e3e832..d212bb7 100644 --- a/src/model/ki3700.rs +++ b/src/model/ki3700.rs @@ -168,7 +168,8 @@ impl NonBlock for Instrument { impl Drop for Instrument { fn drop(&mut self) { - let _ = self.interface.write_all(b"password\n"); + let _ = self.write_all(b"abort\n"); + let _ = self.write_all(b"*RST\n"); } } @@ -255,6 +256,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -394,6 +400,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -536,6 +547,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -588,6 +604,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -666,6 +687,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -741,6 +767,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -816,6 +847,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -897,6 +933,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"password\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -948,9 +989,8 @@ mod unit { .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() - .times(1) - .in_sequence(&mut seq) - .withf(|buf: &[u8]| buf == b"password\n") + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() diff --git a/src/model/tti.rs b/src/model/tti.rs index a27a1e0..010cb89 100644 --- a/src/model/tti.rs +++ b/src/model/tti.rs @@ -5,6 +5,7 @@ use std::{ use bytes::Buf; use language::{CmdLanguage, Language}; +use tracing::{self, trace}; use crate::{ instrument::{ @@ -161,13 +162,26 @@ impl Flash for Instrument { } impl Read for Instrument { + #[tracing::instrument(skip(self, buf))] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { - self.interface.read(buf) + let b = self.interface.read(buf)?; + let ascii = String::from_utf8_lossy(buf); + let ascii = ascii.trim_end().trim_matches(['\0', '\n', '\r']); + if !ascii.is_empty() { + trace!("read from instrument: '{ascii}'"); + } + Ok(b) } } impl Write for Instrument { + #[tracing::instrument(skip(self))] fn write(&mut self, buf: &[u8]) -> std::io::Result { + if String::from_utf8_lossy(buf).contains("login") { + trace!("writing to instrument: 'login ****'"); + } else { + trace!("writing to instrument: '{}'", String::from_utf8_lossy(buf)); + } self.interface.write(buf) } @@ -183,8 +197,15 @@ impl NonBlock for Instrument { } impl Drop for Instrument { + #[tracing::instrument(skip(self))] fn drop(&mut self) { + trace!("Calling TTI instrument drop"); + let _ = self.write_all(b"abort\n"); + std::thread::sleep(Duration::from_millis(100)); + let _ = self.write_all(b"*RST\n"); + std::thread::sleep(Duration::from_millis(100)); let _ = self.write_all(b"logout\n"); + std::thread::sleep(Duration::from_millis(100)); } } @@ -263,6 +284,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -401,6 +427,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -537,6 +568,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -593,6 +629,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -650,6 +691,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -697,6 +743,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -735,6 +786,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -756,6 +812,7 @@ mod unit { fn write_script() { let optional_writes: Vec> = vec![ (*b"logout\n").into(), + (*b"*RST\n").into(), (*b"abort\n").into(), (*b"_orig_prompts = localnode.prompts localnode.prompts = 0\n").into(), (*b"localnode.prompts = _orig_prompts _orig_prompts = nil\n").into(), @@ -800,6 +857,7 @@ mod unit { fn write_script_run() { let optional_writes: Vec> = vec![ (*b"logout\n").into(), + (*b"*RST\n").into(), (*b"abort\n").into(), (*b"_orig_prompts = localnode.prompts localnode.prompts = 0\n").into(), (*b"localnode.prompts = _orig_prompts _orig_prompts = nil\n").into(), @@ -845,6 +903,7 @@ mod unit { fn write_script_save() { let optional_writes: Vec> = vec![ (*b"logout\n").into(), + (*b"*RST\n").into(), (*b"abort\n").into(), (*b"_orig_prompts = localnode.prompts localnode.prompts = 0\n").into(), (*b"localnode.prompts = _orig_prompts _orig_prompts = nil\n").into(), @@ -891,6 +950,7 @@ mod unit { fn write_script_save_run() { let optional_writes: Vec> = vec![ (*b"logout\n").into(), + (*b"*RST\n").into(), (*b"abort\n").into(), (*b"_orig_prompts = localnode.prompts localnode.prompts = 0\n").into(), (*b"localnode.prompts = _orig_prompts _orig_prompts = nil\n").into(), @@ -982,6 +1042,11 @@ mod unit { .times(..) .withf(|buf: &[u8]| buf == b"logout\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) diff --git a/src/model/versatest.rs b/src/model/versatest.rs index 578b4e4..05b888a 100644 --- a/src/model/versatest.rs +++ b/src/model/versatest.rs @@ -16,7 +16,7 @@ use crate::{ }; use bytes::Buf; use language::Language; -use serde::{Deserialize, Serialize}; +use tracing::trace; pub struct Instrument { info: Option, @@ -113,13 +113,22 @@ impl Login for Instrument { impl Script for Instrument {} impl Read for Instrument { + #[tracing::instrument(skip(self))] fn read(&mut self, buf: &mut [u8]) -> std::io::Result { - self.interface.read(buf) + let b = self.interface.read(buf)?; + let ascii = String::from_utf8_lossy(buf); + let ascii = ascii.trim_end().trim_matches(['\0', '\n', '\r']); + if !ascii.is_empty() { + trace!("read from instrument: '{ascii}'"); + } + Ok(b) } } impl Write for Instrument { + #[tracing::instrument(skip(self))] fn write(&mut self, buf: &[u8]) -> std::io::Result { + trace!("writing to instrument: '{}'", String::from_utf8_lossy(buf)); self.interface.write(buf) } @@ -128,17 +137,6 @@ impl Write for Instrument { } } -/// The information necessary to flash an instrument. -#[derive(Serialize, Deserialize, Debug)] -struct FirmwareInfo { - /// For VersaTest only: `true` - the firmware is for a module; `false`: the firmware is for the mainframe - #[serde(rename = "IsModule")] - is_module: bool, - - /// For VersaTest only: The slot number of the module to update. - #[serde(rename = "Slot")] - slot: u8, -} pub const VERSATEST_FLASH_UTIL_STR: &[u8] = include_bytes!("resources/flashUtil.tsp"); impl Flash for Instrument { fn flash_firmware( @@ -200,6 +198,17 @@ impl NonBlock for Instrument { } } +impl Drop for Instrument { + #[tracing::instrument(skip(self))] + fn drop(&mut self) { + trace!("Calling MP5000 instrument drop"); + let _ = self.write_all(b"*RST\n"); + std::thread::sleep(Duration::from_millis(100)); + let _ = self.write_all(b"abort\n"); + std::thread::sleep(Duration::from_millis(100)); + } +} + #[cfg(test)] mod unit { use std::{ @@ -277,6 +286,11 @@ mod unit { } Ok(msg.len()) }); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -407,6 +421,11 @@ mod unit { } Ok(msg.len()) }); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -539,6 +558,11 @@ mod unit { } Ok(msg.len()) }); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -583,6 +607,11 @@ mod unit { } Ok(msg.len()) }); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -654,6 +683,11 @@ mod unit { .in_sequence(&mut seq) .withf(|buf: &[u8]| buf == b"\nendscript\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -722,6 +756,11 @@ mod unit { .in_sequence(&mut seq) .withf(|buf: &[u8]| buf == b"test_script.run()\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -790,6 +829,11 @@ mod unit { .in_sequence(&mut seq) .withf(|buf: &[u8]| buf == b"test_script.save()\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -866,6 +910,11 @@ mod unit { .withf(|buf: &[u8]| buf == b"test_script.run()\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..) @@ -923,6 +972,11 @@ mod unit { .in_sequence(&mut seq) .withf(|buf: &[u8]| buf == b"firmware.update()\n") .returning(|buf: &[u8]| Ok(buf.len())); + interface + .expect_write() + .times(..) + .withf(|buf: &[u8]| buf == b"*RST\n") + .returning(|buf: &[u8]| Ok(buf.len())); interface .expect_write() .times(..)