Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ba3211371 | ||
|
|
c8d5cd71c4 | ||
|
|
c74e8ebaca | ||
|
|
282f0b195c | ||
|
|
1857a9e1a0 | ||
|
|
b7a77cbed8 | ||
|
|
606ae85781 | ||
|
|
ad9b0dc868 | ||
|
|
aaf049bbfc | ||
|
|
8b7b0c70b4 | ||
|
|
3ae80efdde | ||
|
|
7901d82c4b | ||
|
|
8f7aab3f80 | ||
|
|
e593548746 | ||
|
|
2fd433c3b0 | ||
|
|
5399f9fc49 | ||
|
|
6b4961d7bc | ||
|
|
fc7c665166 | ||
|
|
ae437c0d24 | ||
|
|
b343746718 |
@@ -76,13 +76,19 @@ dependencies = [
|
||||
name = "alkane-gui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"aes",
|
||||
"alkane-core",
|
||||
"alkane-discovery",
|
||||
"asic-rs",
|
||||
"base64 0.21.7",
|
||||
"ecb",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"md5crypt",
|
||||
"measurements",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tokio",
|
||||
"wx-rs",
|
||||
]
|
||||
|
||||
@@ -19,3 +19,11 @@ tokio = { version = "1", features = ["rt"] }
|
||||
futures-util = "0.3"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
# WhatsMiner :4028 token-auth access check (round 12 #8b) -- same crates the
|
||||
# vendored asic-rs whatsminer backend uses, so no new versions enter the lock.
|
||||
md5crypt = "1"
|
||||
sha2 = "0.10"
|
||||
aes = "0.8"
|
||||
ecb = "0.1"
|
||||
base64 = "0.21"
|
||||
hex = "0.4"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M240 8L48 296h112L128 504 336 216H224L272 8z"/></svg>
|
||||
|
After Width: | Height: | Size: 145 B |
@@ -0,0 +1 @@
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="511.104248pt" height="512.144915pt" viewBox="0 0 511.104248 512.144915" preserveAspectRatio="xMidYMid meet"><g transform="translate(-0.500000,511.997478) scale(0.100000,-0.100000)" fill="currentColor" stroke="none"><path d="M82 5103 c-52 -25 -77 -69 -77 -133 0 -41 6 -63 22 -86 49 -68 -31 -64 1237 -64 l1146 0 0 -150 0 -150 -323 0 c-292 0 -332 -2 -403 -20 -201 -52 -370 -228 -414 -432 -8 -34 -11 -94 -8 -155 5 -90 12 -119 52 -214 6 -14 -9 -17 -121 -22 -142 -7 -205 -22 -304 -73 -123 -65 -229 -192 -272 -329 -33 -106 -30 -264 7 -360 15 -38 30 -77 32 -85 4 -12 -9 -20 -49 -33 -76 -24 -163 -83 -228 -156 -160 -176 -193 -424 -86 -638 61 -123 195 -242 315 -280 40 -13 52 -21 48 -33 -2 -8 -17 -46 -32 -85 -38 -95 -41 -253 -7 -360 56 -178 206 -323 393 -380 32 -9 108 -19 182 -22 l126 -6 -25 -66 c-31 -81 -42 -233 -23 -319 45 -210 221 -387 433 -437 94 -22 1622 -22 1716 0 108 26 188 71 272 155 126 125 176 255 167 437 -5 90 -12 119 -52 214 -6 14 9 17 122 22 147 6 246 33 337 92 110 70 199 186 238 310 33 106 30 264 -7 360 -15 39 -30 77 -32 85 -4 12 9 20 49 33 211 67 377 303 377 537 0 233 -167 470 -378 537 -40 13 -52 21 -48 33 2 8 17 47 32 85 37 96 40 254 7 360 -39 122 -130 241 -240 311 -89 58 -188 85 -335 91 -113 5 -128 8 -122 22 40 95 47 124 52 214 6 119 -7 184 -55 287 -46 97 -157 210 -254 257 -117 58 -159 63 -516 63 l-323 0 0 150 0 150 618 0 617 0 210 -211 c116 -116 227 -219 247 -230 122 -63 256 59 207 187 -5 16 -60 79 -121 141 l-112 113 313 0 c346 0 360 2 404 64 31 43 31 129 0 172 -50 70 173 64 -2535 64 -2230 0 -2446 -2 -2476 -17z m3337 -918 c94 -52 141 -134 141 -244 -1 -102 -60 -192 -155 -237 l-50 -24 -795 0 -795 0 -50 24 c-61 28 -116 87 -140 149 -26 70 -17 172 21 235 31 49 104 105 158 121 18 6 363 9 821 8 l790 -2 54 -30z m649 -834 c95 -43 162 -147 162 -251 0 -66 -30 -131 -85 -187 -84 -83 -84 -83 -593 -83 l-434 0 -55 50 c-281 257 -719 257 -1005 0 l-57 -51 -453 3 c-452 3 -453 3 -500 26 -92 45 -158 151 -158 252 0 119 99 235 221 259 24 5 688 8 1474 8 l1430 -2 53 -24z m-1317 -623 c130 -64 224 -184 249 -317 5 -29 10 -98 10 -151 0 -53 -5 -122 -10 -151 -25 -133 -119 -253 -249 -317 -73 -36 -77 -37 -191 -37 -114 0 -118 1 -191 37 -125 62 -210 164 -244 293 -20 79 -20 271 0 350 39 149 147 263 300 318 38 13 74 17 151 15 93 -3 107 -6 175 -40z m-924 -235 c-16 -51 -16 -415 0 -465 l11 -38 -547 0 -548 0 -62 31 c-87 43 -138 117 -148 213 -11 110 44 211 145 263 l64 33 548 0 548 0 -11 -37z m2580 24 c60 -22 117 -72 148 -128 26 -46 30 -64 30 -129 0 -65 -4 -83 -30 -129 -31 -56 -88 -106 -148 -128 -23 -8 -187 -12 -578 -12 l-546 -1 13 68 c17 86 17 318 0 405 l-13 67 546 -1 c391 0 555 -4 578 -12z m-2349 -878 c286 -256 725 -255 1006 1 l55 51 453 -3 c452 -3 453 -3 500 -26 90 -44 158 -151 158 -247 0 -99 -69 -204 -162 -246 l-53 -24 -1455 0 -1455 0 -53 24 c-95 43 -162 147 -162 251 0 66 30 131 85 187 83 82 79 81 588 82 l439 1 56 -51z m1342 -820 c97 -43 160 -138 160 -240 0 -111 -47 -192 -141 -244 l-54 -30 -783 -3 c-518 -2 -796 1 -822 8 -59 16 -131 70 -164 122 -38 63 -47 165 -21 235 24 62 79 121 140 149 l50 24 795 0 c778 0 796 -1 840 -21z"/></g></svg>
|
||||
|
After Width: | Height: | Size: 3.0 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M128 192l128 0 0-64c0-35.3-28.7-64-64-64s-64 28.7-64 64l0 64zm-64 0l0-64C64 57.3 121.3 0 192 0S320 57.3 320 128l0 64c35.3 0 64 28.7 64 64l0 192c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 256c0-35.3 28.7-64 64-64zm256 64l-256 0 0 192 256 0 0-192z"/></svg>
|
||||
|
After Width: | Height: | Size: 522 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--!Font Awesome Free 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2026 Fonticons, Inc.--><path d="M181.5 261.1L194.4 267.5C200.3 270.5 206.8 272 213.5 272C237 272 256.1 252.9 256.1 229.4L256.1 208C256.1 172.7 227.4 144 192.1 144L128.1 144C92.8 144 64.1 172.7 64.1 208L64.1 229.4C64.1 252.9 83.2 272 106.7 272C113.3 272 119.8 270.5 125.8 267.5C135.1 262.8 142.2 259.3 147 256.9L135.1 249C130.6 246 128 241 128 235.7L128 232C128 218.7 138.7 208 152 208L168 208C181.3 208 192 218.7 192 232L192 235.7C192 241 189.3 246 184.9 249L173.1 256.9L181.5 261.1zM172.9 310.5L160 304.1L147.1 310.5C134.5 316.8 120.6 320.1 106.6 320.1C103 320.1 99.5 319.9 96 319.5L96 320.1C96 355.4 124.7 384.1 160 384.1L224 384.1C241.7 384.1 256 398.4 256 416.1C256 433.8 241.7 448.1 224 448.1L384 448.1L384 384.1C384 360.4 396.9 339.7 416 328.7C425.4 323.3 436.3 320.1 448 320.1L448 304.1C448 277.6 469.5 256.1 496 256.1C504.8 256.1 512 263.3 512 272.1L512 368.1C512 376.9 519.2 384.1 528 384.1C536.8 384.1 544 376.9 544 368.1L544 268.4C544 220.2 513.2 177.4 467.4 162.1L458.9 159.3C450.9 156.6 446.3 148.2 448.5 140C450.7 131.8 458.8 126.8 467.1 128.4L487 132.4C576 150.1 640 228.2 640 318.9L640 320L640 320C640 443.7 539.7 544 416 544L255.4 544C132 544 32 444 32 320.6L32 280.8C21.9 266.2 16 248.5 16 229.4L16 208L16 206.6C6.7 203.3 0 194.5 0 184C0 170.7 10.7 160 24 160L26.8 160C44.8 122.2 83.3 96 128 96L192 96C236.7 96 275.2 122.2 293.2 160L296 160C309.3 160 320 170.7 320 184C320 194.5 313.3 203.3 304 206.6L304 208L304 229.4C304 230.8 304 232.2 303.9 233.7C315.9 227.5 329.6 224.1 344 224.1L352 224.1C369.7 224.1 384 238.4 384 256.1C384 273.8 369.7 288.1 352 288.1L344 288.1C330.7 288.1 320 298.8 320 312.1L320 320.1L376.4 320.1C361.2 337.1 352 359.5 352 384.1L320 384.1C277.7 384.1 241.8 356.7 229 318.8C223.9 319.7 218.7 320.1 213.4 320.1C199.3 320.1 185.5 316.8 172.9 310.5zM96 192C104.8 192 112 199.2 112 208C112 216.8 104.8 224 96 224C87.2 224 80 216.8 80 208C80 199.2 87.2 192 96 192zM208 208C208 199.2 215.2 192 224 192C232.8 192 240 199.2 240 208C240 216.8 232.8 224 224 224C215.2 224 208 216.8 208 208z"/></svg>
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M460.7 39.3l-2.2-2.1c-4.7-4.6-11.5-6.4-17.9-4.7s-11.4 6.6-13.1 13l-.8 2.9c-3.3 11.8-5.1 23.7-5.5 35.6 24.3 20.6 42.9 47.8 53.3 78.8-8.2-1.9-16.5-2.9-25-2.9-.6 0-1.1 0-1.7 0-18.4-44-56.5-77.4-103.6-89.3l-3.4-.9c-6.2-1.6-12.9-.6-18.5 2.6-10.8 6.2-15.6 19.5-11.2 31.1 14.9 39.5 44.3 71.4 81.4 89.7-3.7 6.6-6.4 14-7.6 21.8L279.7 154.9c-30.9-17.7-65.9-26.9-101.5-26.9-32.3 0-62.2 16.8-78.9 44.4-10.3-12.5-25.8-20.4-43.2-20.4-30.9 0-56 25.1-56 56s25.1 56 56 56c11.3 0 21.8-3.3 30.6-9.1 4.9 17.2 14.5 33.1 28.4 45.9L257.2 431.2C269 442 284.4 448 300.4 448L416 448c17.7 0 32-14.3 32-32s-14.3-32-32-32l-96 0 0-43.5c0-42.9-28.4-80.5-69.6-92.3l-30.8-8.8c-8.5-2.4-13.4-11.3-11-19.8s11.3-13.4 19.8-11l30.8 8.8c55 15.7 92.8 65.9 92.8 123.1l0 15.7 56-32.4 6.4-3.7 101.3 0c33.3 0 60.3-27 60.3-60.3 0-18.1-8.2-35.3-22.2-46.7l-34.6-28.2c-4.6-3.7-9.4-7.1-14.5-10 8.4-49.3-7.8-100-43.9-135.5zm-318.5 382c-14.7 9.8-18.7 29.7-8.9 44.4s29.7 18.7 44.4 8.9l46-30.7-48.6-44.5-32.9 22zM480 240a16 16 0 1 1 32 0 16 16 0 1 1 -32 0z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M384 249.2c0 21.4-17.4 38.8-38.8 38.8L70.8 288C49.4 288 32 270.6 32 249.2L32 208c0-97.2 78.8-176 176-176s176 78.8 176 176l0 41.2zM480 288c-2 0-4-.1-5.9-.3-16.3 53.3-64.3 92.7-122.1 96l0 56.2c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-56-32 0 0 56c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-56-32 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l312 0c39.8 0 72-32.2 72-72l0-72c0-35.3 28.7-64 64-64 53 0 96 43 96 96l0 16c0 35.3-28.7 64-64 64l-32 0zm16-64a16 16 0 1 0 0-32 16 16 0 1 0 0 32z"/></svg>
|
||||
|
After Width: | Height: | Size: 761 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M320 128c0-35.3 28.7-64 64-64s64 28.7 64 64l0 128 64 0 0-128C512 57.3 454.7 0 384 0S256 57.3 256 128l0 64-192 0c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l256 0c35.3 0 64-28.7 64-64l0-192c0-35.3-28.7-64-64-64l0-64zM64 256l256 0 0 192-256 0 0-192z"/></svg>
|
||||
|
After Width: | Height: | Size: 520 B |
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 640"><!--! Font Awesome Pro 7.3.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2026 Fonticons, Inc. --><path fill="currentColor" d="M205 64L434.9 64L439.3 82.4L475.6 234.9C478.5 247 480 259.5 480 272C480 352.2 421 418.7 344 430.2L344 560L432 560L432 608L208 608L208 560L296 560L296 430.2C219 418.6 160 352.2 160 272C160 259.5 161.5 247 164.4 234.9L200.7 82.4L205 64zM243 112L211 246C209 254.5 208 263.2 208 272C208 333.9 258.2 384 320 384C381.8 384 432 333.8 432 272C432 263.3 431 254.5 429 246L397.1 112L371.3 112L384.1 176L320.1 216L352.1 320L256.1 216L328.1 144L306.8 112L243.1 112z"/></svg>
|
||||
|
After Width: | Height: | Size: 721 B |
@@ -14,10 +14,29 @@
|
||||
//! rather than add an HTTP+digest crate, so the offline/vendored build is
|
||||
//! unaffected. `Some(true)` = locked, `Some(false)` = unlocked, `None` =
|
||||
//! indeterminate (unreachable, or an endpoint/vendor this probe doesn't cover).
|
||||
//!
|
||||
//! WhatsMiner has no such digest-gated web endpoint (it returns a 307 redirect
|
||||
//! for the Antminer paths, so the curl probe always read "indeterminate" and the
|
||||
//! table fell back to a capability guess that marked older units "locked" even
|
||||
//! with the default login -- round 12 #8b). Instead we run the WhatsMiner
|
||||
//! :4028 token handshake: `get_token` (unauthenticated) yields a salt, we derive
|
||||
//! the AES key from the password, and send a NON-mutating encrypted `summary`.
|
||||
//! An encrypted reply means the key (hence password) was accepted -> unlocked;
|
||||
//! a plaintext `enc json load err` means it was rejected -> locked.
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use std::net::{SocketAddr, TcpStream};
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
|
||||
use aes::Aes256;
|
||||
use aes::cipher::{BlockEncryptMut, KeyInit, block_padding::ZeroPadding};
|
||||
use base64::Engine;
|
||||
use base64::engine::general_purpose::STANDARD as BASE64;
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
type Aes256EcbEnc = ecb::Encryptor<Aes256>;
|
||||
|
||||
/// Classify a miner's access state from an HTTP status code string (curl's
|
||||
/// `%{http_code}` output). Conservative: anything other than a clear
|
||||
/// authenticated/unauthorized answer is `None`.
|
||||
@@ -35,12 +54,16 @@ fn endpoint(_firmware: &str) -> &'static str {
|
||||
"/cgi-bin/get_miner_conf.cgi"
|
||||
}
|
||||
|
||||
/// Probe one miner's access state over its web API with the given credentials.
|
||||
/// Returns `Ok(Some(true/false))` on a decisive lock/unlock answer, `Ok(None)`
|
||||
/// if reachable-but-indeterminate or a vendor this probe doesn't cover, or
|
||||
/// `Err` only on a failure to run curl at all.
|
||||
pub fn probe_access(ip: &str, firmware: &str, user: &str, pass: &str) -> Result<Option<bool>, String> {
|
||||
let url = format!("http://{ip}{}", endpoint(firmware));
|
||||
/// Probe one miner's access state. `make` is the miner brand ("Whatsminer" /
|
||||
/// "Antminer"): WhatsMiner uses the :4028 token handshake, everything else the
|
||||
/// digest-auth web probe. Returns `Ok(Some(true/false))` on a decisive
|
||||
/// lock/unlock answer, `Ok(None)` if indeterminate, `Err` only on a probe that
|
||||
/// could not run at all.
|
||||
pub fn probe_access(ip: &str, make: &str, user: &str, pass: &str) -> Result<Option<bool>, String> {
|
||||
if make.eq_ignore_ascii_case("whatsminer") {
|
||||
return Ok(probe_whatsminer_access(ip, &whatsminer_password_candidates()));
|
||||
}
|
||||
let url = format!("http://{ip}{}", endpoint(make));
|
||||
let userpass = format!("{user}:{pass}");
|
||||
let mut cmd = Command::new("curl");
|
||||
cmd.args([
|
||||
@@ -96,6 +119,114 @@ fn wait_with_timeout(mut cmd: Command, timeout: Duration) -> Result<std::process
|
||||
}
|
||||
}
|
||||
|
||||
/// Passwords to try for a WhatsMiner access check: a user-set per-firmware
|
||||
/// override (round 12 #13) wins; otherwise the two factory defaults ("admin" for
|
||||
/// V1/V2, "super" for V3). All attempts are non-mutating, so trying both is safe.
|
||||
fn whatsminer_password_candidates() -> Vec<String> {
|
||||
if let Some((_, pass)) = crate::credentials::load_firmware_credentials().get("WhatsMiner Stock") {
|
||||
if !pass.is_empty() {
|
||||
return vec![pass.clone()];
|
||||
}
|
||||
}
|
||||
vec!["admin".to_string(), "super".to_string()]
|
||||
}
|
||||
|
||||
/// One WhatsMiner :4028 request/response (the miner closes the socket after it
|
||||
/// replies). Returns the NUL-trimmed body.
|
||||
fn wm_rpc(ip: &str, payload: &str, timeout: Duration) -> Result<String, String> {
|
||||
let addr: SocketAddr = format!("{ip}:4028")
|
||||
.parse()
|
||||
.map_err(|e| format!("bad address {ip}: {e}"))?;
|
||||
let mut stream = TcpStream::connect_timeout(&addr, timeout).map_err(|e| e.to_string())?;
|
||||
stream.set_read_timeout(Some(timeout)).ok();
|
||||
stream.set_write_timeout(Some(timeout)).ok();
|
||||
stream.write_all(payload.as_bytes()).map_err(|e| e.to_string())?;
|
||||
let mut buf = Vec::new();
|
||||
let mut chunk = [0u8; 4096];
|
||||
loop {
|
||||
match stream.read(&mut chunk) {
|
||||
Ok(0) => break,
|
||||
Ok(n) => {
|
||||
buf.extend_from_slice(&chunk[..n]);
|
||||
if buf.len() > 1 << 20 {
|
||||
break; // cap a runaway response
|
||||
}
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&buf).trim_matches('\u{0}').to_string())
|
||||
}
|
||||
|
||||
/// AES-256-ECB encrypt `data` under SHA256(pwd_md5), base64-encoded -- the exact
|
||||
/// scheme the WhatsMiner btminer API expects (mirrors the vendored asic-rs
|
||||
/// whatsminer v2 backend).
|
||||
fn wm_aes_ecb_enc(pwd_md5: &str, data: &str) -> Option<String> {
|
||||
let key = Sha256::digest(pwd_md5.as_bytes()); // 32 bytes
|
||||
let mut buffer = data.as_bytes().to_vec();
|
||||
while !buffer.len().is_multiple_of(16) {
|
||||
buffer.push(0);
|
||||
}
|
||||
let ct = Aes256EcbEnc::new_from_slice(&key)
|
||||
.ok()?
|
||||
.encrypt_padded_mut::<ZeroPadding>(&mut buffer, data.len())
|
||||
.ok()?;
|
||||
Some(BASE64.encode(ct))
|
||||
}
|
||||
|
||||
/// Check a WhatsMiner's access via the :4028 token handshake, trying each
|
||||
/// candidate password. Returns `Some(false)` (unlocked) on the first password
|
||||
/// the miner accepts, `Some(true)` (locked) if all are rejected, `None` if the
|
||||
/// miner is unreachable or speaks an unexpected dialect. Non-mutating: only
|
||||
/// `get_token` and a read-only `summary` are ever sent.
|
||||
fn probe_whatsminer_access(ip: &str, passwords: &[String]) -> Option<bool> {
|
||||
let timeout = Duration::from_secs(6);
|
||||
let mut reachable = false;
|
||||
for pass in passwords {
|
||||
// 1. get_token (no auth) -> salt / newsalt / time.
|
||||
let tok_resp = match wm_rpc(ip, "{\"command\":\"get_token\"}", timeout) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return None,
|
||||
};
|
||||
let v: serde_json::Value = match serde_json::from_str(&tok_resp) {
|
||||
Ok(v) => v,
|
||||
Err(_) => return None,
|
||||
};
|
||||
let Some(msg) = v.get("Msg") else { return None };
|
||||
let (Some(salt), Some(newsalt), Some(time)) = (
|
||||
msg.get("salt").and_then(|s| s.as_str()),
|
||||
msg.get("newsalt").and_then(|s| s.as_str()),
|
||||
msg.get("time").and_then(|s| s.as_str()),
|
||||
) else {
|
||||
return None;
|
||||
};
|
||||
reachable = true;
|
||||
// 2. Derive the md5crypt password hash + write-token from the password.
|
||||
let crypted = md5crypt::md5crypt(pass.as_bytes(), salt.as_bytes());
|
||||
let full = String::from_utf8_lossy(&crypted);
|
||||
let Some(pwd_md5) = full.split('$').nth(3) else { continue };
|
||||
let sign_crypted = md5crypt::md5crypt(format!("{pwd_md5}{time}").as_bytes(), newsalt.as_bytes());
|
||||
let sign_full = String::from_utf8_lossy(&sign_crypted);
|
||||
let host_sign = sign_full.split('$').nth(3).unwrap_or("");
|
||||
// 3. Send an encrypted, read-only `summary`. If the AES key (from the
|
||||
// password) is right the miner replies encrypted; if wrong it returns
|
||||
// a plaintext "enc json load err".
|
||||
let cmd = format!("{{\"command\":\"summary\",\"token\":\"{host_sign}\"}}");
|
||||
let Some(enc) = wm_aes_ecb_enc(pwd_md5, &cmd) else { continue };
|
||||
let payload = format!("{{\"enc\":1,\"data\":\"{enc}\"}}");
|
||||
let resp = match wm_rpc(ip, &payload, timeout) {
|
||||
Ok(s) => s,
|
||||
Err(_) => return None,
|
||||
};
|
||||
if resp.contains("\"enc\"") {
|
||||
return Some(false); // accepted -> unlocked/writable
|
||||
}
|
||||
// rejected -> try the next candidate password
|
||||
}
|
||||
// Reached the miner and every candidate password was rejected -> locked.
|
||||
if reachable { Some(true) } else { None }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -112,4 +243,15 @@ mod tests {
|
||||
assert_eq!(classify_http_code(" 200 "), Some(false), "whitespace tolerated");
|
||||
assert_eq!(classify_http_code(""), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whatsminer_aes_ecb_matches_reference() {
|
||||
// Deterministic vector from the verified btminer scheme: AES-256-ECB over
|
||||
// SHA256(pwd_md5), zero-padded, base64. Guards the WhatsMiner access
|
||||
// handshake crypto (round 12 #8b) without needing a live miner.
|
||||
assert_eq!(
|
||||
wm_aes_ecb_enc("abc123def456", "{\"command\":\"summary\"}").as_deref(),
|
||||
Some("jn5Wru/5hhMtU1IgamxLoUd/YTxaLTxEeiCQxu5pO+Q=")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! is the one place that fans a saved username/password out across the whole
|
||||
//! firmware registry, so `scan`'s callers never have to think about it.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
|
||||
|
||||
@@ -14,6 +15,10 @@ use asic_rs::core::traits::miner::MinerAuth;
|
||||
use crate::scan::config_path;
|
||||
|
||||
pub const CREDENTIALS_FILE: &str = "scan-credentials.txt";
|
||||
/// Per-firmware default logins the operator can override (round 12 #13). One
|
||||
/// `firmware-name<TAB>user<TAB>pass` line per firmware, 0600 like the others.
|
||||
/// Keyed by the firmware registry's Display name (see `firmware_default_creds`).
|
||||
pub const FIRMWARE_CREDENTIALS_FILE: &str = "firmware-credentials.txt";
|
||||
/// SSH login for the control board (used by the PIC probe; distinct from the
|
||||
/// web/API scan credentials above -- miners' SSH root login is usually not the
|
||||
/// same account as the web digest-auth login).
|
||||
@@ -87,16 +92,115 @@ pub fn clear_credentials() -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a `MinerFactory` with the saved credentials (if any) applied as
|
||||
/// discovery auth for every firmware backend, so scans, refreshes, config
|
||||
/// actions, and firmware flashes all authenticate against a non-default
|
||||
/// login the same way. With no saved credentials this is plain `MinerFactory::new()`
|
||||
/// and every backend falls back to its own default auth.
|
||||
/// The stock/default login each firmware ships with, keyed by the firmware
|
||||
/// registry's Display name (round 12 #13). These seed the per-firmware editor and
|
||||
/// let it tell an override from an unchanged default; they mirror the
|
||||
/// `default_auth()` constants in the vendored asic-rs backends (a single
|
||||
/// best-guess per registry entry, since a stock entry can span several backend
|
||||
/// versions). asic-rs does not expose these at the entry level, so they are
|
||||
/// duplicated here; a firmware absent from this table defaults to blank.
|
||||
pub fn firmware_default_creds() -> &'static [(&'static str, &'static str, &'static str)] {
|
||||
&[
|
||||
("AntMiner Stock", "root", "root"),
|
||||
("WhatsMiner Stock", "admin", "admin"),
|
||||
("Braiins", "root", "root"),
|
||||
("VNish", "", "admin"),
|
||||
("LuxOS", "root", "root"),
|
||||
("UMC OS", "", "letmein"),
|
||||
("Marathon", "root", "root"),
|
||||
("VolcMiner Stock", "root", "ltc@dog"),
|
||||
("Elphapex Stock", "root", "root"),
|
||||
("FutureBit Stock", "futurebit", "futurebit123"),
|
||||
("SealMiner Stock", "seal", "seal"),
|
||||
("Auradine Stock", "admin", "admin"),
|
||||
("AvalonMiner Stock", "", ""),
|
||||
("Nerdaxe Stock", "", ""),
|
||||
("Proto Stock", "", ""),
|
||||
("Bitaxe Stock", "", ""),
|
||||
]
|
||||
}
|
||||
|
||||
/// The shipped default login for a firmware, or `("","")` if unknown.
|
||||
pub fn firmware_default_for(name: &str) -> (String, String) {
|
||||
firmware_default_creds()
|
||||
.iter()
|
||||
.find(|(n, _, _)| *n == name)
|
||||
.map(|(_, u, p)| (u.to_string(), p.to_string()))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Load the operator's per-firmware credential overrides, keyed by firmware
|
||||
/// Display name. Malformed lines are skipped.
|
||||
pub fn load_firmware_credentials() -> HashMap<String, (String, String)> {
|
||||
let mut map = HashMap::new();
|
||||
let Ok(s) = std::fs::read_to_string(config_path(FIRMWARE_CREDENTIALS_FILE)) else {
|
||||
return map;
|
||||
};
|
||||
for line in s.lines() {
|
||||
let mut parts = line.splitn(3, '\t');
|
||||
let (Some(name), user) = (parts.next(), parts.next()) else {
|
||||
continue;
|
||||
};
|
||||
if name.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let user = user.unwrap_or("").to_string();
|
||||
let pass = parts.next().unwrap_or("").to_string();
|
||||
map.insert(name.to_string(), (user, pass));
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
/// Save the per-firmware credential overrides (0600), sorted by name for a
|
||||
/// stable file. An empty map clears the file.
|
||||
pub fn save_firmware_credentials(map: &HashMap<String, (String, String)>) -> std::io::Result<()> {
|
||||
if map.is_empty() {
|
||||
return clear_firmware_credentials();
|
||||
}
|
||||
let p = config_path(FIRMWARE_CREDENTIALS_FILE);
|
||||
if let Some(dir) = p.parent() {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
let mut f = std::fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.mode(0o600)
|
||||
.open(&p)?;
|
||||
f.set_permissions(std::fs::Permissions::from_mode(0o600))?;
|
||||
let mut names: Vec<&String> = map.keys().collect();
|
||||
names.sort();
|
||||
for name in names {
|
||||
let (user, pass) = &map[name];
|
||||
f.write_all(format!("{name}\t{user}\t{pass}\n").as_bytes())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove the per-firmware overrides file, if any. Not an error if none exists.
|
||||
pub fn clear_firmware_credentials() -> std::io::Result<()> {
|
||||
clear_creds_file(FIRMWARE_CREDENTIALS_FILE)
|
||||
}
|
||||
|
||||
/// Build a `MinerFactory` with saved credentials applied as discovery auth.
|
||||
/// Precedence per firmware backend: a per-firmware override (round 12 #13) wins;
|
||||
/// otherwise the single global scan credential (if set) applies to every backend;
|
||||
/// otherwise the backend falls back to its own default auth. With nothing saved
|
||||
/// this is plain `MinerFactory::new()`.
|
||||
pub fn configured_factory() -> MinerFactory {
|
||||
let mut factory = MinerFactory::new();
|
||||
if let Some((user, pass)) = load_credentials() {
|
||||
for fw in asic_rs::factory::default_firmware_registry() {
|
||||
factory = factory.with_firmware_discovery_auth(fw.as_ref(), MinerAuth::new(user.clone(), pass.clone()));
|
||||
let global = load_credentials();
|
||||
let per_fw = load_firmware_credentials();
|
||||
if global.is_none() && per_fw.is_empty() {
|
||||
return factory;
|
||||
}
|
||||
for fw in asic_rs::factory::default_firmware_registry() {
|
||||
let cred = per_fw
|
||||
.get(&fw.to_string())
|
||||
.cloned()
|
||||
.or_else(|| global.clone());
|
||||
if let Some((user, pass)) = cred {
|
||||
factory = factory.with_firmware_discovery_auth(fw.as_ref(), MinerAuth::new(user, pass));
|
||||
}
|
||||
}
|
||||
factory
|
||||
@@ -149,6 +253,35 @@ mod tests {
|
||||
assert_eq!(load_credentials(), None, "cleared -> None");
|
||||
clear_credentials().unwrap(); // idempotent: clearing an already-clear store is not an error
|
||||
|
||||
// Per-firmware overrides (round 12 #13). Kept in this same test because
|
||||
// HOME is process-global: a second #[test] mutating it would race under
|
||||
// cargo's default parallel runner.
|
||||
assert!(load_firmware_credentials().is_empty(), "no file -> empty map");
|
||||
let mut fw = HashMap::new();
|
||||
fw.insert("WhatsMiner Stock".to_string(), ("super".to_string(), "sup3r".to_string()));
|
||||
fw.insert("VNish".to_string(), ("".to_string(), "hunter2".to_string()));
|
||||
save_firmware_credentials(&fw).unwrap();
|
||||
// 0600, and it round-trips (an empty username survives the tab format).
|
||||
let fwpath = config_path(FIRMWARE_CREDENTIALS_FILE);
|
||||
assert_eq!(
|
||||
std::fs::metadata(&fwpath).unwrap().permissions().mode() & 0o777,
|
||||
0o600,
|
||||
"per-firmware creds file must be 0600"
|
||||
);
|
||||
let back = load_firmware_credentials();
|
||||
assert_eq!(back.get("WhatsMiner Stock"), Some(&("super".into(), "sup3r".into())));
|
||||
assert_eq!(back.get("VNish"), Some(&("".into(), "hunter2".into())));
|
||||
assert_eq!(back.len(), 2);
|
||||
// Shipped-default lookup: known firmware resolves, unknown blanks.
|
||||
assert_eq!(firmware_default_for("AntMiner Stock"), ("root".into(), "root".into()));
|
||||
assert_eq!(firmware_default_for("nonexistent"), (String::new(), String::new()));
|
||||
// Overrides + no global still builds a factory.
|
||||
let _ = configured_factory();
|
||||
// Saving an empty map clears the file (no stale overrides linger).
|
||||
save_firmware_credentials(&HashMap::new()).unwrap();
|
||||
assert!(load_firmware_credentials().is_empty(), "empty save -> cleared");
|
||||
clear_firmware_credentials().unwrap(); // idempotent
|
||||
|
||||
match prev {
|
||||
Some(v) => std::env::set_var("HOME", v),
|
||||
None => std::env::remove_var("HOME"),
|
||||
|
||||
@@ -60,6 +60,28 @@ impl Board {
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
// Air-cooled WhatsMiners report an ambient reading (asic-rs surfaces it in
|
||||
// its fluid_temperature field); the scan routes it to env_temp for
|
||||
// air-cooled models, so the demo mirrors that (round 11 #17).
|
||||
let env_temp_c = if self.mining && self.make.eq_ignore_ascii_case("whatsminer") {
|
||||
27.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
// Per-hashboard health dots for the Boards column (round 11 #10): mining
|
||||
// units show three green dots, except two demo cases -- the slow S21 Pro
|
||||
// has one faulted (red) board, and one VNish S19 has a board that wasn't
|
||||
// detected (grey) -- so the offline demo exercises all three states.
|
||||
use crate::model::BoardHealth::{Fault, Missing, Ok};
|
||||
let board_status = if self.mining {
|
||||
match self.ip {
|
||||
"10.255.1.149" => vec![Ok, Fault, Ok],
|
||||
"10.255.1.166" => vec![Ok, Ok, Missing],
|
||||
_ => vec![Ok, Ok, Ok],
|
||||
}
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
// Firmware-flash capability is modeled on the real Bitmain/Antminer
|
||||
// upgrade path (S17/S19/S21 family); WhatsMiner boards in this fleet
|
||||
// don't advertise it, so both true and false show up and the
|
||||
@@ -91,6 +113,7 @@ impl Board {
|
||||
power_w: self.power,
|
||||
chip_temp_c: self.temp,
|
||||
board_temps,
|
||||
env_temp_c,
|
||||
fan_rpms,
|
||||
worker: self.worker.to_string(),
|
||||
is_mining: self.mining,
|
||||
@@ -101,10 +124,13 @@ impl Board {
|
||||
hostname: format!("miner-{last_octet}"),
|
||||
hashboards: boards,
|
||||
expected_hashboards: Some(3),
|
||||
board_status,
|
||||
total_chips: chips,
|
||||
psu_fan_rpm: if self.mining { self.fan * 0.9 } else { 0.0 },
|
||||
uptime_secs: if self.mining { 3600 * 24 * 2 + 3600 * 5 } else { 0 },
|
||||
light_flashing: Some(false),
|
||||
// One unit is "being located" so the Light column's yellow dot is
|
||||
// demonstrable offline (round 11 #10).
|
||||
light_flashing: Some(self.ip == "10.255.1.167"),
|
||||
pool_url: if self.worker.is_empty() { String::new() } else { "stratum+tcp://pool.blueflare:3333".to_string() },
|
||||
pools: if self.worker.is_empty() {
|
||||
Vec::new()
|
||||
|
||||
@@ -21,6 +21,24 @@ fn main() {
|
||||
std::process::exit(run_selftest());
|
||||
}
|
||||
|
||||
// Headless access-probe check: `ALKANE_ACCESS_PROBE="<ip> <make>"` prints the
|
||||
// lock state the real access probe computes (no GUI, no wx), so the WhatsMiner
|
||||
// :4028 token check and the Antminer digest check can be verified directly.
|
||||
if let Some(spec) = std::env::var_os("ALKANE_ACCESS_PROBE") {
|
||||
let spec = spec.to_string_lossy();
|
||||
let mut it = spec.split_whitespace();
|
||||
let ip = it.next().unwrap_or("");
|
||||
let make = it.next().unwrap_or("");
|
||||
let (user, pass) = credentials::load_credentials().unwrap_or_default();
|
||||
match access_probe::probe_access(ip, make, &user, &pass) {
|
||||
Ok(Some(true)) => println!("ACCESS {ip} {make}: LOCKED"),
|
||||
Ok(Some(false)) => println!("ACCESS {ip} {make}: UNLOCKED"),
|
||||
Ok(None) => println!("ACCESS {ip} {make}: INDETERMINATE"),
|
||||
Err(e) => println!("ACCESS {ip} {make}: ERROR {e}"),
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
// Bootstrap the wx app + main frame (upstream bridge).
|
||||
wx_rs::init_app("alkane-toolkit", 1280, 800);
|
||||
// Follow the system light/dark appearance.
|
||||
|
||||
@@ -236,6 +236,16 @@ impl MinerCaps {
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-hashboard health for the Boards column's status dots (round 11 #10):
|
||||
/// green = present and hashing, red = present but idle/faulty, grey = expected
|
||||
/// but not detected at all.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BoardHealth {
|
||||
Ok,
|
||||
Fault,
|
||||
Missing,
|
||||
}
|
||||
|
||||
/// One miner's telemetry snapshot, flattened from asic-rs `MinerData` into the
|
||||
/// scalar fields the table can display. Absent metrics are `None` / empty /
|
||||
/// 0.0 and render as a blank cell.
|
||||
@@ -295,7 +305,14 @@ pub struct MinerRow {
|
||||
/// Per-hashboard chip temperature (hottest chip per board), shown in the
|
||||
/// Chip-temp column as "77 / 64 / 74". Empty falls back to the average.
|
||||
pub board_temps: Vec<f64>,
|
||||
/// Coolant/immersion-fluid temperature (liquid-cooled miners only).
|
||||
pub fluid_temp_c: f64,
|
||||
/// Environment/ambient air temperature. asic-rs reports air-cooled miners'
|
||||
/// ambient reading in its `fluid_temperature` field (see the WhatsMiner
|
||||
/// backends' "Env Temp"/"environment-temperature" key); the scan routes it
|
||||
/// here for air-cooled models so it isn't mislabelled as a fluid temp
|
||||
/// (round 11 #17).
|
||||
pub env_temp_c: f64,
|
||||
pub outlet_temp_c: f64,
|
||||
/// Individual cooling-fan RPMs (empty if unknown). PSU fan is tracked
|
||||
/// separately below since it is not part of the cooling-fan set.
|
||||
@@ -308,6 +325,10 @@ pub struct MinerRow {
|
||||
pub expected_chips: Option<u32>,
|
||||
pub hashboards: Option<u32>,
|
||||
pub expected_hashboards: Option<u32>,
|
||||
/// Per-hashboard health for the Boards status dots (round 11 #10), one entry
|
||||
/// per expected board, ordered by position (index 0 = board 1). Empty = no
|
||||
/// per-board data (the cell renders blank).
|
||||
pub board_status: Vec<BoardHealth>,
|
||||
// pool: active-pool convenience fields, plus the (url, worker) of each
|
||||
// configured pool (miners usually allow up to 3 redundant pools).
|
||||
pub worker: String,
|
||||
@@ -379,6 +400,11 @@ pub fn flash_confirmed(input: &str) -> bool {
|
||||
pub enum Column {
|
||||
Ip,
|
||||
Hashrate,
|
||||
/// Sort-only pseudo-column (round 11 #16): the actual/expected hashrate
|
||||
/// ratio. Deliberately NOT in `ALL_COLUMNS`, so it never appears in the
|
||||
/// column picker or the display order; it exists only as a `sort` target the
|
||||
/// Hashrate header cycles into.
|
||||
HashrateRel,
|
||||
Power,
|
||||
ChipTemp,
|
||||
Cooling,
|
||||
@@ -392,6 +418,7 @@ pub enum Column {
|
||||
Status,
|
||||
Efficiency,
|
||||
FluidTemp,
|
||||
EnvTemp,
|
||||
OutletTemp,
|
||||
PsuFan,
|
||||
FanCount,
|
||||
@@ -402,7 +429,6 @@ pub enum Column {
|
||||
Hostname,
|
||||
Serial,
|
||||
ApiVersion,
|
||||
ControlBoard,
|
||||
Cpu,
|
||||
BoardCode,
|
||||
Algorithm,
|
||||
@@ -442,6 +468,7 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::Status,
|
||||
Column::Efficiency,
|
||||
Column::FluidTemp,
|
||||
Column::EnvTemp,
|
||||
Column::OutletTemp,
|
||||
Column::PsuFan,
|
||||
Column::FanCount,
|
||||
@@ -452,7 +479,6 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::Hostname,
|
||||
Column::Serial,
|
||||
Column::ApiVersion,
|
||||
Column::ControlBoard,
|
||||
Column::Cpu,
|
||||
Column::BoardCode,
|
||||
Column::Algorithm,
|
||||
@@ -474,16 +500,19 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::Pool3Worker,
|
||||
];
|
||||
|
||||
/// The columns shown by default (UI-SPEC), after the fixed IP column.
|
||||
pub const DEFAULT_VISIBLE: [Column; 8] = [
|
||||
/// The columns shown by default (UI-SPEC), after the fixed IP column, in display
|
||||
/// order: model, errors, hashrate, power, chip temp, firmware, CPU, boards
|
||||
/// (hashboard health), access.
|
||||
pub const DEFAULT_VISIBLE: [Column; 9] = [
|
||||
Column::Model,
|
||||
Column::Error,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Cooling,
|
||||
Column::Firmware,
|
||||
Column::Worker,
|
||||
Column::Model,
|
||||
Column::Status,
|
||||
Column::Cpu,
|
||||
Column::Hashboards,
|
||||
Column::Locked,
|
||||
];
|
||||
|
||||
impl Column {
|
||||
@@ -491,6 +520,7 @@ impl Column {
|
||||
match self {
|
||||
Column::Ip => "IP",
|
||||
Column::Hashrate => "Hashrate",
|
||||
Column::HashrateRel => "Rel. hashrate",
|
||||
Column::Power => "Power",
|
||||
Column::ChipTemp => "Chip temp",
|
||||
Column::Cooling => "Fan (RPM)",
|
||||
@@ -504,6 +534,7 @@ impl Column {
|
||||
Column::Status => "Status",
|
||||
Column::Efficiency => "Efficiency (J/TH)",
|
||||
Column::FluidTemp => "Fluid temp",
|
||||
Column::EnvTemp => "Env temp",
|
||||
Column::OutletTemp => "Outlet temp",
|
||||
Column::PsuFan => "PSU fan (RPM)",
|
||||
Column::FanCount => "Fans",
|
||||
@@ -514,9 +545,8 @@ impl Column {
|
||||
Column::Hostname => "Hostname",
|
||||
Column::Serial => "Serial",
|
||||
Column::ApiVersion => "API ver",
|
||||
Column::ControlBoard => "Control board",
|
||||
Column::Cpu => "CPU",
|
||||
Column::BoardCode => "Board",
|
||||
Column::BoardCode => "Control Board",
|
||||
Column::Algorithm => "Algorithm",
|
||||
Column::Pic => "PIC",
|
||||
Column::Locked => "Access",
|
||||
@@ -541,8 +571,9 @@ impl Column {
|
||||
match self {
|
||||
Column::Ip => 130,
|
||||
Column::Hashrate => 110,
|
||||
Column::HashrateRel => 110,
|
||||
Column::Power => 90,
|
||||
Column::ChipTemp | Column::FluidTemp | Column::OutletTemp => 95,
|
||||
Column::ChipTemp | Column::FluidTemp | Column::EnvTemp | Column::OutletTemp => 95,
|
||||
Column::Cooling | Column::PsuFan => 100,
|
||||
Column::Firmware => 110,
|
||||
Column::FwVersion => 130,
|
||||
@@ -557,7 +588,6 @@ impl Column {
|
||||
Column::ExpectedFans | Column::TuningPercent => 90,
|
||||
Column::Mac | Column::Hostname | Column::Serial => 150,
|
||||
Column::ApiVersion | Column::Light => 90,
|
||||
Column::ControlBoard => 130,
|
||||
Column::Cpu => 70,
|
||||
Column::BoardCode => 70,
|
||||
Column::Algorithm => 100,
|
||||
@@ -579,10 +609,12 @@ impl Column {
|
||||
matches!(
|
||||
self,
|
||||
Column::Hashrate
|
||||
| Column::HashrateRel
|
||||
| Column::Power
|
||||
| Column::Efficiency
|
||||
| Column::ChipTemp
|
||||
| Column::FluidTemp
|
||||
| Column::EnvTemp
|
||||
| Column::OutletTemp
|
||||
| Column::Cooling
|
||||
| Column::PsuFan
|
||||
@@ -630,10 +662,16 @@ impl Column {
|
||||
let none = f64::NEG_INFINITY;
|
||||
match self {
|
||||
Column::Hashrate => SortKey::Num(r.hashrate_ths),
|
||||
// Relative hashrate = actual/expected; unknown expectation sorts to
|
||||
// the bottom (round 11 #16).
|
||||
Column::HashrateRel => {
|
||||
SortKey::Num(actual_expected_ratio(r.hashrate_ths, r.expected_ths).unwrap_or(none))
|
||||
}
|
||||
Column::Power => SortKey::Num(r.power_w),
|
||||
Column::Efficiency => SortKey::Num(if r.efficiency > 0.0 { r.efficiency } else { none }),
|
||||
Column::ChipTemp => SortKey::Num(r.chip_temp_c),
|
||||
Column::FluidTemp => SortKey::Num(r.fluid_temp_c),
|
||||
Column::EnvTemp => SortKey::Num(r.env_temp_c),
|
||||
Column::OutletTemp => SortKey::Num(r.outlet_temp_c),
|
||||
Column::Cooling => SortKey::Num(if r.fan_rpms.is_empty() {
|
||||
none
|
||||
@@ -644,7 +682,21 @@ impl Column {
|
||||
Column::FanCount => SortKey::Num(r.fan_count.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::ExpectedFans => SortKey::Num(r.expected_fans.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::TotalChips => SortKey::Num(r.total_chips.map(|v| v as f64).unwrap_or(none)),
|
||||
Column::Hashboards => SortKey::Num(r.hashboards.map(|v| v as f64).unwrap_or(none)),
|
||||
// The Boards column shows per-hashboard health dots, so sort by the
|
||||
// number of ONLINE (green) boards -- surfacing units with dead/missing
|
||||
// boards -- with the total board count as a tiebreaker (so full-health
|
||||
// units still order by how many boards they have). Falls back to the
|
||||
// reported board count when no per-board health is available (round 11).
|
||||
Column::Hashboards => {
|
||||
if r.board_status.is_empty() {
|
||||
SortKey::Num(r.hashboards.map(|v| v as f64).unwrap_or(none))
|
||||
} else {
|
||||
let online =
|
||||
r.board_status.iter().filter(|h| matches!(h, BoardHealth::Ok)).count();
|
||||
let total = r.board_status.len();
|
||||
SortKey::Num((online * 100 + total) as f64)
|
||||
}
|
||||
}
|
||||
Column::Uptime => SortKey::Num(if r.uptime_secs > 0 { r.uptime_secs as f64 } else { none }),
|
||||
Column::BestShare => SortKey::Num(r.best_share.unwrap_or(none)),
|
||||
Column::SessionBestShare => SortKey::Num(r.session_best_share.unwrap_or(none)),
|
||||
@@ -674,6 +726,11 @@ impl Column {
|
||||
match self {
|
||||
Column::Ip => r.ip.clone(),
|
||||
Column::Hashrate => combined_si(r.hashrate_ths, r.expected_ths),
|
||||
// Never displayed as its own column; rendered as a percentage only for
|
||||
// completeness (e.g. a debug/self-test read of the cell).
|
||||
Column::HashrateRel => actual_expected_ratio(r.hashrate_ths, r.expected_ths)
|
||||
.map(|ratio| format!("{:.0}%", ratio * 100.0))
|
||||
.unwrap_or_default(),
|
||||
Column::Power => {
|
||||
if r.power_w > 0.0 {
|
||||
format_si(r.power_w, "W")
|
||||
@@ -692,6 +749,7 @@ impl Column {
|
||||
}
|
||||
}
|
||||
Column::FluidTemp => num(r.fluid_temp_c, 1, " C"),
|
||||
Column::EnvTemp => num(r.env_temp_c, 1, " C"),
|
||||
Column::OutletTemp => num(r.outlet_temp_c, 1, " C"),
|
||||
Column::Cooling => {
|
||||
r.fan_rpms.iter().map(|&v| format_fan_rpm(v)).collect::<Vec<_>>().join("/")
|
||||
@@ -713,7 +771,6 @@ impl Column {
|
||||
Column::Hostname => r.hostname.clone(),
|
||||
Column::Serial => r.serial.clone(),
|
||||
Column::ApiVersion => r.api_version.clone(),
|
||||
Column::ControlBoard => r.control_board.clone(),
|
||||
Column::Cpu => r.cpu.clone(),
|
||||
Column::BoardCode => r.board_code.clone(),
|
||||
Column::Algorithm => r.algorithm.clone(),
|
||||
@@ -838,9 +895,17 @@ pub struct ViewState {
|
||||
|
||||
impl Default for ViewState {
|
||||
fn default() -> Self {
|
||||
// Registry order for `order`; Ip + DEFAULT_VISIBLE are shown. Default
|
||||
// sort is by IP ascending.
|
||||
let order: Vec<Column> = ALL_COLUMNS.to_vec();
|
||||
// Display order = Ip, then DEFAULT_VISIBLE in its own order, then every
|
||||
// remaining metric (so the initial columns match the UI-SPEC order rather
|
||||
// than the ALL_COLUMNS registry order). Default sort is by IP ascending.
|
||||
let mut order: Vec<Column> = Vec::with_capacity(ALL_COLUMNS.len());
|
||||
order.push(Column::Ip);
|
||||
order.extend(DEFAULT_VISIBLE);
|
||||
for c in ALL_COLUMNS {
|
||||
if !order.contains(&c) {
|
||||
order.push(c);
|
||||
}
|
||||
}
|
||||
let mut visible: HashSet<Column> = DEFAULT_VISIBLE.iter().copied().collect();
|
||||
visible.insert(Column::Ip);
|
||||
ViewState { order, visible, sort: Some((Column::Ip, true)), filters: HashMap::new() }
|
||||
@@ -1145,9 +1210,12 @@ mod tests {
|
||||
fn reorder_with_hidden_column_keeps_all_columns() {
|
||||
let mut view = ViewState::default();
|
||||
view.visible.remove(&Column::Power);
|
||||
// display now: Ip(0), Hashrate(1), ChipTemp(2), ... - swap Hashrate/ChipTemp
|
||||
// Swap Hashrate and ChipTemp in the visible display order (order-agnostic:
|
||||
// find them by identity rather than by a fixed index).
|
||||
let mut vis = view.display_columns();
|
||||
vis.swap(1, 2);
|
||||
let hr0 = vis.iter().position(|c| *c == Column::Hashrate).unwrap();
|
||||
let ct0 = vis.iter().position(|c| *c == Column::ChipTemp).unwrap();
|
||||
vis.swap(hr0, ct0);
|
||||
view.apply_visible_reorder(&vis);
|
||||
assert!(view.order.contains(&Column::Power), "hidden column dropped!");
|
||||
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
||||
|
||||
@@ -46,6 +46,38 @@ fn is_antminer(make: &str) -> bool {
|
||||
make.trim().eq_ignore_ascii_case("antminer")
|
||||
}
|
||||
|
||||
/// Split asic-rs's firmware family string into the family shown in the Firmware
|
||||
/// column and an optional vendor prefix that moves into the FW Version column
|
||||
/// (round 11 #6). asic-rs reports stock firmware as "AntMiner Stock" /
|
||||
/// "WhatsMiner Stock"; the Firmware column should read just "Stock" (so it
|
||||
/// colours as the neutral/default family), and the vendor word belongs with the
|
||||
/// version. Aftermarket families ("VNish", "Braiins", ...) carry no vendor
|
||||
/// prefix and pass through unchanged.
|
||||
pub fn firmware_family(raw: &str) -> (String, Option<String>) {
|
||||
let trimmed = raw.trim();
|
||||
// Vendor prefixes asic-rs prepends on stock-firmware family strings, matched
|
||||
// case-insensitively.
|
||||
for vendor in ["AntMiner", "WhatsMiner"] {
|
||||
if trimmed.len() > vendor.len() && trimmed[..vendor.len()].eq_ignore_ascii_case(vendor) {
|
||||
let rest = trimmed[vendor.len()..].trim();
|
||||
if !rest.is_empty() {
|
||||
return (rest.to_string(), Some(vendor.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
(trimmed.to_string(), None)
|
||||
}
|
||||
|
||||
/// Whether a miner is liquid-cooled (hydro / water / immersion) rather than
|
||||
/// air-cooled, inferred from the model name (round 11 #17). asic-rs exposes no
|
||||
/// cooling-type field, so this is a best-effort model-string heuristic: it
|
||||
/// decides whether a reported "fluid" temperature is a real coolant reading or
|
||||
/// (for air-cooled units) the ambient/environment temperature.
|
||||
pub fn is_liquid_cooled(model: &str) -> bool {
|
||||
let m = model.to_ascii_lowercase();
|
||||
m.contains("hydro") || m.contains("immers") || m.contains("water")
|
||||
}
|
||||
|
||||
/// The human model name for the Model column: brand dropped (it has its own
|
||||
/// column), family-letter suffix lowercased, word suffixes spaced, "+"/"++" for
|
||||
/// Plus/PlusPlus, and (WhatsMiner) the trailing version block moved to Submodel.
|
||||
@@ -354,4 +386,28 @@ mod tests {
|
||||
assert_eq!(control_board_cpu("Antminer", "Unknown: FOO", "S19"), "Unknown: FOO");
|
||||
assert_eq!(control_board_board("Antminer", "Unknown: FOO", "S19"), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn firmware_family_splits_vendor_prefix() {
|
||||
// Stock firmware: vendor word moves out of the family word (round 11 #6).
|
||||
assert_eq!(firmware_family("AntMiner Stock"), ("Stock".to_string(), Some("AntMiner".to_string())));
|
||||
assert_eq!(
|
||||
firmware_family("WhatsMiner Stock"),
|
||||
("Stock".to_string(), Some("WhatsMiner".to_string()))
|
||||
);
|
||||
// Aftermarket families pass through with no vendor prefix.
|
||||
assert_eq!(firmware_family("VNish"), ("VNish".to_string(), None));
|
||||
assert_eq!(firmware_family("Braiins"), ("Braiins".to_string(), None));
|
||||
// A bare vendor word with nothing after it is left as-is (not emptied).
|
||||
assert_eq!(firmware_family("AntMiner"), ("AntMiner".to_string(), None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn liquid_cooling_detection() {
|
||||
assert!(is_liquid_cooled("S21 XP Hydro"));
|
||||
assert!(is_liquid_cooled("Antminer S19 Hydro"));
|
||||
assert!(is_liquid_cooled("M53 immersion"));
|
||||
assert!(!is_liquid_cooled("S21 Pro"));
|
||||
assert!(!is_liquid_cooled("M30S++"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,17 +25,28 @@ pub struct SshCreds {
|
||||
pub pass: String,
|
||||
}
|
||||
|
||||
/// Which I2C bus to probe, chosen from the control-board family. AMLogic uses
|
||||
/// i2c-1, BeagleBone uses i2c-0; for anything else (Xilinx/CVITek/unknown) we
|
||||
/// try both. The wiki confirms the AML/BB buses; Zynx/CVITek are unconfirmed.
|
||||
/// I2C buses to probe for the hashboard MCU/LM75 at 0x48, most-likely first,
|
||||
/// chosen from the control-board family. `probe_pic` tries them in order and
|
||||
/// stops at the first bus that classifies definitively, so extra fallbacks only
|
||||
/// cost an SSH round-trip when earlier buses are absent/indeterminate.
|
||||
///
|
||||
/// Confirmed live (2026-09-19): a VNish CVITek S19k Pro exposes the hashboard
|
||||
/// MCU on i2c-3 (i2c-4 is the second, usually empty); its buses are i2c-3/i2c-4,
|
||||
/// NOT i2c-0/i2c-1 -- the earlier CVITek -> [1,0] guess never found the MCU,
|
||||
/// which is why PIC detection appeared not to work. AMLogic=i2c-1 and
|
||||
/// BeagleBone=i2c-0 are from the wiki; buses vary across firmware, so each family
|
||||
/// also lists the others as fallbacks.
|
||||
pub fn bus_candidates(control_board: &str) -> Vec<u8> {
|
||||
let cb = control_board.to_lowercase();
|
||||
if cb.contains("amlogic") || cb.contains("aml") {
|
||||
vec![1]
|
||||
if cb.contains("cvi") {
|
||||
vec![3, 4, 1, 0]
|
||||
} else if cb.contains("amlogic") || cb.contains("aml") {
|
||||
vec![1, 3, 4, 0]
|
||||
} else if cb.contains("beaglebone") || cb.contains("bb") {
|
||||
vec![0]
|
||||
vec![0, 1, 3, 4]
|
||||
} else {
|
||||
vec![1, 0]
|
||||
// Xilinx / unknown: try the common buses.
|
||||
vec![1, 0, 3, 4]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,9 +226,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bus_from_control_board() {
|
||||
assert_eq!(bus_candidates("AMLogic"), vec![1]);
|
||||
assert_eq!(bus_candidates("BeagleBone Black"), vec![0]);
|
||||
assert_eq!(bus_candidates("Xilinx"), vec![1, 0]);
|
||||
assert_eq!(bus_candidates(""), vec![1, 0]);
|
||||
// Most-likely bus first, then fallbacks. CVITek's i2c-3 first is the live
|
||||
// fix; AMLogic i2c-1 and BeagleBone i2c-0 keep their wiki-confirmed lead.
|
||||
assert_eq!(bus_candidates("CVI (C88)"), vec![3, 4, 1, 0]);
|
||||
assert_eq!(bus_candidates("CVITek"), vec![3, 4, 1, 0]);
|
||||
assert_eq!(bus_candidates("AMLogic")[0], 1);
|
||||
assert_eq!(bus_candidates("BeagleBone Black")[0], 0);
|
||||
assert_eq!(bus_candidates("Xilinx")[0], 1);
|
||||
assert_eq!(bus_candidates("")[0], 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,20 +11,20 @@ use crate::scan::config_path;
|
||||
|
||||
pub const PRESETS_FILE: &str = "presets.json";
|
||||
|
||||
/// The built-in default profile's visible columns, in display order (Ip first).
|
||||
const DEFAULT_PROFILE: [Column; 12] = [
|
||||
/// The built-in default profile's visible columns, in display order (Ip first):
|
||||
/// IP, model, errors, hashrate, power, chip temp, firmware, CPU, boards
|
||||
/// (hashboard health), access.
|
||||
const DEFAULT_PROFILE: [Column; 10] = [
|
||||
Column::Ip,
|
||||
Column::Model,
|
||||
Column::Error,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Firmware,
|
||||
Column::FwVersion,
|
||||
Column::Cpu,
|
||||
Column::BoardCode,
|
||||
Column::Pic,
|
||||
Column::Error,
|
||||
Column::Status,
|
||||
Column::Hashboards,
|
||||
Column::Locked,
|
||||
];
|
||||
|
||||
/// A serializable snapshot of a `ViewState` (Vec-based so JSON has no map keys
|
||||
@@ -126,10 +126,13 @@ mod tests {
|
||||
let view = p.view.to_view();
|
||||
// IP first + the requested default columns visible.
|
||||
assert!(view.visible.contains(&Column::Ip));
|
||||
assert!(view.visible.contains(&Column::Model));
|
||||
assert!(view.visible.contains(&Column::Error));
|
||||
assert!(view.visible.contains(&Column::Cpu));
|
||||
assert!(view.visible.contains(&Column::BoardCode));
|
||||
assert!(view.visible.contains(&Column::Pic));
|
||||
assert!(view.visible.contains(&Column::Status));
|
||||
assert!(view.visible.contains(&Column::Hashboards));
|
||||
assert!(view.visible.contains(&Column::Locked));
|
||||
// Columns dropped from the default profile in round 11.
|
||||
assert!(!view.visible.contains(&Column::BoardCode), "not in the default profile");
|
||||
assert!(!view.visible.contains(&Column::Cooling), "not in the default profile");
|
||||
// to_view covers every column in `order`.
|
||||
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
||||
|
||||
@@ -449,15 +449,19 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
.as_ref()
|
||||
.map(|t| t.as_celsius())
|
||||
.unwrap_or(0.0);
|
||||
// Per-hashboard chip temperature (hottest chip per board, falling back to
|
||||
// the board/PCB temp), for the "77 / 64 / 74" Chip-temp cell.
|
||||
// Per-hashboard temperature for the "77 / 64 / 74" Chip-temp cell. Prefer the
|
||||
// board/PCB temperature over the hottest-chip (outlet) reading: WhatsMiner's
|
||||
// outlet_chip is the max chip temp (~100C on the hottest board), which read
|
||||
// alarmingly high and didn't match the temperature the miner itself reports;
|
||||
// the board temperature (~60-79C) is the figure the miner's own UI shows
|
||||
// (round 12 #3). Falls back to the chip temp when no board temp is reported.
|
||||
let board_temps: Vec<f64> = data
|
||||
.hashboards
|
||||
.iter()
|
||||
.filter_map(|b| {
|
||||
b.outlet_chip_temperature
|
||||
b.board_temperature
|
||||
.as_ref()
|
||||
.or(b.board_temperature.as_ref())
|
||||
.or(b.outlet_chip_temperature.as_ref())
|
||||
.map(|t| t.as_celsius())
|
||||
})
|
||||
.filter(|&t| t > 0.0)
|
||||
@@ -496,9 +500,16 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// Firmware family (coloured column) and version go in separate columns now.
|
||||
let firmware = data.device_info.firmware.clone();
|
||||
let fw_version = data.firmware_version.clone().unwrap_or_default();
|
||||
// Firmware family (coloured column) and version go in separate columns. Strip
|
||||
// the vendor word asic-rs prepends on stock firmware ("AntMiner Stock" ->
|
||||
// "Stock") and carry it into the version instead (round 11 #6).
|
||||
let (firmware, fw_vendor) = crate::naming::firmware_family(&data.device_info.firmware);
|
||||
let raw_fw_version = data.firmware_version.clone().unwrap_or_default();
|
||||
let fw_version = match (fw_vendor, raw_fw_version.is_empty()) {
|
||||
(Some(vendor), false) => format!("{vendor} {raw_fw_version}"),
|
||||
(Some(vendor), true) => vendor,
|
||||
(None, _) => raw_fw_version,
|
||||
};
|
||||
// Split asic-rs's compact make/model identifiers into the human-facing
|
||||
// Brand / Model / Submodel the table shows (see crate::naming). asic-rs hands
|
||||
// us "Antminer"/"S19KPro"; we render brand "Antminer", model "S19k Pro".
|
||||
@@ -511,7 +522,16 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
let control_board = crate::naming::control_board_code(&make, &raw_board, &model);
|
||||
let cpu = crate::naming::control_board_cpu(&make, &raw_board, &model);
|
||||
let board_code = crate::naming::control_board_board(&make, &raw_board, &model);
|
||||
let fluid_temp_c = data.fluid_temperature.as_ref().map(|t| t.as_celsius()).unwrap_or(0.0);
|
||||
// asic-rs has no cooling-type field and reports air-cooled miners' ambient
|
||||
// reading in `fluid_temperature` (the WhatsMiner backends read the "Env
|
||||
// Temp"/"environment-temperature" key). Route it to the Env-temp column for
|
||||
// air-cooled models so it isn't mislabelled as a coolant temp (round 11 #17).
|
||||
let reported_fluid = data.fluid_temperature.as_ref().map(|t| t.as_celsius()).unwrap_or(0.0);
|
||||
let (fluid_temp_c, env_temp_c) = if crate::naming::is_liquid_cooled(&model) {
|
||||
(reported_fluid, 0.0)
|
||||
} else {
|
||||
(0.0, reported_fluid)
|
||||
};
|
||||
let outlet_temp_c = data
|
||||
.outlet_fluid_temperature
|
||||
.as_ref()
|
||||
@@ -548,9 +568,42 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
// on-board SSH/I2C probe -- a separate feature).
|
||||
let pic_present = if model.to_lowercase().contains("nopic") { Some(false) } else { None };
|
||||
// Access: locked/view-only when the miner exposes no writable control at
|
||||
// all, otherwise unlocked. Inferred from capabilities (asic-rs has no direct
|
||||
// lock-state field).
|
||||
let write_locked = Some(!caps.any_control());
|
||||
// all, otherwise unlocked. Inferred from asic-rs capabilities (there is no
|
||||
// direct lock-state field). WhatsMiner is the exception: it is controllable
|
||||
// over its :4028 token API regardless of which commands the matched asic-rs
|
||||
// backend implements, so this heuristic falsely marks older units "locked".
|
||||
// Leave it unknown and let the real access probe (the :4028 token check)
|
||||
// decide (round 12 #8b).
|
||||
let write_locked = if brand.eq_ignore_ascii_case("whatsminer") {
|
||||
None
|
||||
} else {
|
||||
Some(!caps.any_control())
|
||||
};
|
||||
// Per-hashboard health for the Boards status dots (round 11 #10): green =
|
||||
// present & hashing, red = present but idle/faulty, grey = expected but not
|
||||
// detected. Boards keep asic-rs's reported order (board 1 first); any boards
|
||||
// expected beyond those reported are padded as Missing.
|
||||
let mut board_status: Vec<crate::model::BoardHealth> = data
|
||||
.hashboards
|
||||
.iter()
|
||||
.map(|b| {
|
||||
let ok = match (b.active, b.working_chips) {
|
||||
(Some(a), _) => a,
|
||||
(None, Some(c)) => c > 0,
|
||||
(None, None) => true,
|
||||
};
|
||||
if ok {
|
||||
crate::model::BoardHealth::Ok
|
||||
} else {
|
||||
crate::model::BoardHealth::Fault
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
if let Some(exp) = data.expected_hashboards {
|
||||
while board_status.len() < exp as usize {
|
||||
board_status.push(crate::model::BoardHealth::Missing);
|
||||
}
|
||||
}
|
||||
let errors = summarize_messages(&data.messages);
|
||||
MinerRow {
|
||||
ip: data.ip.to_string(),
|
||||
@@ -565,7 +618,22 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
submodel,
|
||||
mac: data.mac.map(|m| m.to_string()).unwrap_or_default(),
|
||||
hostname: data.hostname.clone().unwrap_or_default(),
|
||||
serial: data.serial_number.clone().unwrap_or_default(),
|
||||
serial: {
|
||||
// Some miners report a placeholder serial ("N/A", "none", ...); show
|
||||
// those as an empty cell rather than the literal placeholder (round 12).
|
||||
let s = data.serial_number.clone().unwrap_or_default();
|
||||
let t = s.trim();
|
||||
if t.is_empty()
|
||||
|| t.eq_ignore_ascii_case("n/a")
|
||||
|| t.eq_ignore_ascii_case("na")
|
||||
|| t.eq_ignore_ascii_case("none")
|
||||
|| t.eq_ignore_ascii_case("null")
|
||||
{
|
||||
String::new()
|
||||
} else {
|
||||
s
|
||||
}
|
||||
},
|
||||
firmware,
|
||||
fw_version,
|
||||
api_version: data.api_version.clone().unwrap_or_default(),
|
||||
@@ -580,6 +648,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
chip_temp_c,
|
||||
board_temps,
|
||||
fluid_temp_c,
|
||||
env_temp_c,
|
||||
outlet_temp_c,
|
||||
fan_rpms,
|
||||
psu_fan_rpm,
|
||||
@@ -589,6 +658,7 @@ async fn to_row(miner: &dyn Miner) -> MinerRow {
|
||||
expected_chips: data.expected_chips.map(|v| v as u32),
|
||||
hashboards: (!data.hashboards.is_empty()).then_some(data.hashboards.len() as u32),
|
||||
expected_hashboards: data.expected_hashboards.map(|v| v as u32),
|
||||
board_status,
|
||||
worker,
|
||||
pool_url,
|
||||
pools,
|
||||
@@ -1084,11 +1154,11 @@ pub fn start_access_probe(
|
||||
let thread_cancel = cancel.clone();
|
||||
let err_tx = tx.clone();
|
||||
let res = std::thread::Builder::new().name("access-probe".into()).spawn(move || {
|
||||
for (ip, fw) in targets {
|
||||
for (ip, make) in targets {
|
||||
if thread_cancel.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
let (locked, error) = match crate::access_probe::probe_access(&ip, &fw, &user, &pass) {
|
||||
let (locked, error) = match crate::access_probe::probe_access(&ip, &make, &user, &pass) {
|
||||
Ok(v) => (v, None),
|
||||
Err(e) => (None, Some(e)),
|
||||
};
|
||||
|
||||
@@ -72,12 +72,22 @@ const ID_FLASH_CANCEL: i32 = 745;
|
||||
const ID_CREDS_SAVE: i32 = 746;
|
||||
const ID_CREDS_CLEAR: i32 = 747;
|
||||
const ID_CREDS_CANCEL: i32 = 748;
|
||||
// Per-firmware default-credentials editor (round 12 #13), opened from the scan
|
||||
// credentials dialog.
|
||||
const ID_FWCREDS_OPEN: i32 = 749;
|
||||
const ID_FWCREDS_SAVE: i32 = 750;
|
||||
const ID_FWCREDS_RESET: i32 = 751;
|
||||
const ID_FWCREDS_CANCEL: i32 = 752;
|
||||
// Column-header right-click menu (Excel-style).
|
||||
const ID_HDR_SORT_ASC: i32 = 760;
|
||||
const ID_HDR_SORT_DESC: i32 = 761;
|
||||
const ID_HDR_HIDE: i32 = 762;
|
||||
const ID_HDR_AUTOSIZE: i32 = 763;
|
||||
const ID_HDR_COLUMNS: i32 = 764;
|
||||
// Relative-hashrate (actual/expected) sort, offered on the Hashrate header only
|
||||
// (round 11 #16).
|
||||
const ID_HDR_SORT_REL_ASC: i32 = 765;
|
||||
const ID_HDR_SORT_REL_DESC: i32 = 766;
|
||||
// Ticks (~seconds) to keep an action's result on the status bar before the
|
||||
// idle/countdown status takes over again.
|
||||
const ACTION_RESULT_TICKS: u8 = 8;
|
||||
@@ -232,6 +242,162 @@ fn encode_flag_cell(plain: &str, color: Option<(u8, u8, u8)>) -> String {
|
||||
encode_segments(&[(color, plain.to_string())])
|
||||
}
|
||||
|
||||
/// Shape-sentinel strings the SegmentRenderer draws as small vector icons rather
|
||||
/// than text (round 11 #10/#13). These byte values MUST match the SHAPE_* set in
|
||||
/// widgets_bridge.cpp. They are control characters, never emoji/pictographs.
|
||||
const SHAPE_DOT: &str = "\u{0007}";
|
||||
const SHAPE_LOCK: &str = "\u{0002}";
|
||||
const SHAPE_UNLOCK: &str = "\u{0003}";
|
||||
// Status-column KPI icons (round 12 #11): one sentinel per status, each drawn
|
||||
// from the same SVG as its dashboard KPI card. Registered with the bridge in
|
||||
// `register_cell_icons` at startup.
|
||||
const SHAPE_HASHING: &str = "\u{0004}";
|
||||
const SHAPE_SLOW: &str = "\u{0005}";
|
||||
const SHAPE_NOTHASHING: &str = "\u{0006}";
|
||||
const SHAPE_PAUSED: &str = "\u{0008}";
|
||||
/// Locate-light dot that fades in and out (round 12 #6); distinct from the static
|
||||
/// `SHAPE_DOT` so only the flashing light pulses, not the hashboard health dots.
|
||||
const SHAPE_PULSE_DOT: &str = "\u{000B}";
|
||||
|
||||
/// Register every SVG-backed table-cell icon with the bridge (round 12 #9/#11):
|
||||
/// the access padlocks and the four status KPI icons. Called once at startup;
|
||||
/// the renderer recolours each per cell. The sentinel code points MUST match the
|
||||
/// `\u{..}` constants above and the SHAPE_* set in widgets_bridge.cpp.
|
||||
fn register_cell_icons() {
|
||||
// (sentinel first char, svg) pairs; the bridge reads the viewBox dims we pass
|
||||
// to keep each icon's aspect ratio when it rasterises at the cell height.
|
||||
let icons: [(&str, &str); 6] = [
|
||||
(SHAPE_LOCK, SVG_LOCK),
|
||||
(SHAPE_UNLOCK, SVG_UNLOCK),
|
||||
(SHAPE_HASHING, SVG_RABBIT),
|
||||
(SHAPE_SLOW, SVG_TURTLE),
|
||||
(SHAPE_NOTHASHING, SVG_WINE_CRACK),
|
||||
(SHAPE_PAUSED, SVG_OTTER),
|
||||
];
|
||||
for (sentinel, svg) in icons {
|
||||
let cp = sentinel.chars().next().map(|c| c as u32).unwrap_or(0);
|
||||
let (vbw, vbh) = svg_viewbox(svg);
|
||||
wx_rs::register_shape_svg(cp, svg, vbw, vbh);
|
||||
}
|
||||
}
|
||||
|
||||
/// Parse an SVG's viewBox width/height (round 12 #9/#11), defaulting to a square
|
||||
/// when absent so the bridge can preserve the icon aspect at any cell height.
|
||||
fn svg_viewbox(svg: &str) -> (i32, i32) {
|
||||
svg.split("viewBox=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('"').next())
|
||||
.and_then(|vb| {
|
||||
let n: Vec<f64> = vb.split_whitespace().filter_map(|x| x.parse().ok()).collect();
|
||||
(n.len() == 4 && n[2] > 0.0 && n[3] > 0.0).then(|| (n[2].round() as i32, n[3].round() as i32))
|
||||
})
|
||||
.unwrap_or((1, 1))
|
||||
}
|
||||
|
||||
/// Boards column: one status dot per hashboard (round 11 #10). Board 1 is the
|
||||
/// rightmost dot, so boards render high-position-first (left to right). green =
|
||||
/// present and hashing, red = present but idle/faulty, grey = not detected.
|
||||
fn encode_board_dots(pal: &Palette, status: &[crate::model::BoardHealth]) -> String {
|
||||
use crate::model::BoardHealth;
|
||||
if status.is_empty() {
|
||||
return encode_segments(&[(None, String::new())]);
|
||||
}
|
||||
let segs: Vec<(Option<(u8, u8, u8)>, String)> = status
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|h| {
|
||||
let color = match h {
|
||||
BoardHealth::Ok => pal.green,
|
||||
BoardHealth::Fault => pal.red,
|
||||
BoardHealth::Missing => pal.label,
|
||||
};
|
||||
(Some(color), SHAPE_DOT.to_string())
|
||||
})
|
||||
.collect();
|
||||
encode_segments(&segs)
|
||||
}
|
||||
|
||||
/// Access column: a green open padlock (writable) or red closed padlock
|
||||
/// (view-only); blank when the lock state is unknown (round 11 #13).
|
||||
fn encode_access_icon(pal: &Palette, write_locked: Option<bool>) -> String {
|
||||
match write_locked {
|
||||
Some(true) => encode_segments(&[(Some(pal.red), SHAPE_LOCK.to_string())]),
|
||||
Some(false) => encode_segments(&[(Some(pal.green), SHAPE_UNLOCK.to_string())]),
|
||||
None => encode_segments(&[(None, String::new())]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Light column: a yellow dot while the miner's locate light is flashing, else
|
||||
/// blank (round 11 #10). The dot fades in and out (round 12 #6) via the pulsing
|
||||
/// sentinel, so a flashing light reads as a live pulse rather than a static dot.
|
||||
fn encode_light_dot(pal: &Palette, flashing: Option<bool>) -> String {
|
||||
match flashing {
|
||||
Some(true) => encode_segments(&[(Some(pal.amber), SHAPE_PULSE_DOT.to_string())]),
|
||||
_ => encode_segments(&[(None, String::new())]),
|
||||
}
|
||||
}
|
||||
|
||||
/// Status column: the status rendered as its KPI icon in the status colour
|
||||
/// (round 12 #11) -- rabbit=hashing, turtle=slow, cracked wine glass=not
|
||||
/// hashing, otter=paused. An unrecognised status falls back to coloured text.
|
||||
fn encode_status_icon(pal: &Palette, status: &str) -> String {
|
||||
let shape = match status {
|
||||
"hashing" => SHAPE_HASHING,
|
||||
"slow" => SHAPE_SLOW,
|
||||
"not hashing" => SHAPE_NOTHASHING,
|
||||
"paused" => SHAPE_PAUSED,
|
||||
_ => return encode_segments(&[(Some(status_kind_color(pal, status)), status.to_string())]),
|
||||
};
|
||||
encode_segments(&[(Some(status_kind_color(pal, status)), shape.to_string())])
|
||||
}
|
||||
|
||||
// KPI card icons (round 11 #15). The animal/wine-glass SVGs are Font Awesome Pro
|
||||
// (operator-supplied); bolt/hive are matching in-repo SVGs. All use
|
||||
// fill="currentColor", recoloured per card at render time.
|
||||
const SVG_RABBIT: &str = include_str!("../assets/icons/rabbit.svg");
|
||||
const SVG_TURTLE: &str = include_str!("../assets/icons/turtle.svg");
|
||||
const SVG_WINE_CRACK: &str = include_str!("../assets/icons/wine-glass-crack.svg");
|
||||
const SVG_OTTER: &str = include_str!("../assets/icons/otter.svg");
|
||||
const SVG_HIVE: &str = include_str!("../assets/icons/hive.svg");
|
||||
const SVG_BOLT: &str = include_str!("../assets/icons/bolt.svg");
|
||||
// Access-column padlocks (round 12 #9): operator-supplied Font Awesome padlocks
|
||||
// that replace the hand-drawn vector padlocks in the table.
|
||||
const SVG_LOCK: &str = include_str!("../assets/icons/lock.svg");
|
||||
const SVG_UNLOCK: &str = include_str!("../assets/icons/unlock.svg");
|
||||
|
||||
/// KPI card minimum widths. The count cards (Total/Hashing/...) are narrow; the
|
||||
/// two wide cards (SHA-256 Hashrate, Est. power) need more room so their
|
||||
/// icon + units-bearing value never clips (round 12 #2). The wide floor fits the
|
||||
/// widest realistic value the card can show -- a ~20px icon + 5px gap + a value
|
||||
/// text up to "118.0 PH" (~127px at 19pt bold) + the card's 16px side inset --
|
||||
/// so the units ("kW"/"PH"/...) stay visible instead of being squeezed off; the
|
||||
/// row collapses the wide cards entirely (see `on_resize`) rather than shrink
|
||||
/// them below this and clip.
|
||||
const KPI_MIN: i32 = 116;
|
||||
const KPI_WIDE_MIN: i32 = 176;
|
||||
|
||||
/// Recolour an SVG to the KPI card's colour (round 11 #15). Some Font Awesome
|
||||
/// exports use fill="currentColor" (replaced here); others omit fill entirely and
|
||||
/// default to black, so a root `fill` is also injected for shapes to inherit.
|
||||
fn svg_recolored(svg: &str, color: (u8, u8, u8)) -> String {
|
||||
let hex = format!("#{:02X}{:02X}{:02X}", color.0, color.1, color.2);
|
||||
let s = svg.replace("currentColor", &hex);
|
||||
s.replacen("<svg ", &format!("<svg fill=\"{hex}\" "), 1)
|
||||
}
|
||||
|
||||
/// Width to render an SVG at, preserving its viewBox aspect ratio at height `h`.
|
||||
fn svg_width_for_height(svg: &str, h: i32) -> i32 {
|
||||
svg.split("viewBox=\"")
|
||||
.nth(1)
|
||||
.and_then(|s| s.split('"').next())
|
||||
.and_then(|vb| {
|
||||
let n: Vec<f64> = vb.split_whitespace().filter_map(|x| x.parse().ok()).collect();
|
||||
(n.len() == 4 && n[3] > 0.0).then(|| ((h as f64) * n[2] / n[3]).round() as i32)
|
||||
})
|
||||
.unwrap_or(h)
|
||||
.max(1)
|
||||
}
|
||||
|
||||
/// Build the segment-encoded cell text for the Cooling column: each fan's RPM
|
||||
/// gets its own grey-to-blue colour by speed, and the "/" separators between
|
||||
/// them stay in the default text colour.
|
||||
@@ -363,6 +529,12 @@ pub struct App {
|
||||
// so both can be repainted when the system light/dark theme changes.
|
||||
pal: Palette,
|
||||
kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)>,
|
||||
/// The main content panel and the KPI card row sizer, plus whether the two
|
||||
/// wide KPI cards (Hashrate, Est. power) are currently collapsed because the
|
||||
/// window is too narrow to fit all seven cards (round 11 #2).
|
||||
panel: Widget,
|
||||
kpi_row: Widget,
|
||||
kpi_collapsed: bool,
|
||||
// The 4 status KPI cards that double as quick-filters: (status text, its
|
||||
// ButtonClicked id, card panel, value text, label text). The three widgets
|
||||
// are all painted for the active-filter highlight (so the whole box tints,
|
||||
@@ -407,6 +579,10 @@ pub struct App {
|
||||
creds_dialog: Widget,
|
||||
creds_user_input: Widget,
|
||||
creds_pass_input: Widget,
|
||||
// Per-firmware default-credentials editor (round 12 #13): the dialog plus one
|
||||
// (firmware name, user field, pass field) per registry firmware.
|
||||
fwcreds_dialog: Widget,
|
||||
fwcreds_rows: Vec<(String, Widget, Widget)>,
|
||||
// Background access (lock-state) probe.
|
||||
access_probe: Option<scan::AccessProbeHandle>,
|
||||
// Background SSH PIC probe + its credentials dialog.
|
||||
@@ -428,6 +604,11 @@ pub struct App {
|
||||
ranges_auto: Widget,
|
||||
columns_dialog: Widget,
|
||||
columns_list: Widget,
|
||||
/// The columns-dialog "hide empty columns" checkbox, read at Apply.
|
||||
columns_hide_empty_cb: Widget,
|
||||
/// When set, columns with no scanned value in any row are hidden from the
|
||||
/// table (non-destructively -- clearing it restores them) (round 11 #9).
|
||||
auto_hide_empty: bool,
|
||||
// Filter dialog (Excel-style, one column at a time via a dropdown).
|
||||
filter_dialog: Widget,
|
||||
filter_col_choice: Widget, // which column to filter
|
||||
@@ -447,6 +628,9 @@ pub struct App {
|
||||
|
||||
pub fn build(frame: Widget) -> App {
|
||||
let pal = palette();
|
||||
// Register the SVG-backed table-cell icons once (access padlocks + status KPI
|
||||
// icons, round 12 #9/#11) before any row is rendered.
|
||||
register_cell_icons();
|
||||
let panel = Widget::panel(frame);
|
||||
let root = Widget::box_sizer(true);
|
||||
|
||||
@@ -458,18 +642,23 @@ pub fn build(frame: Widget) -> App {
|
||||
// min size floors them at their largest content's width.
|
||||
let kpi_row = Widget::box_sizer(false);
|
||||
let mut kpi_cards: Vec<(Widget, Widget, Widget, ColorKind)> = Vec::new();
|
||||
let mut mk_card = |label: &str, kind: ColorKind| -> (Widget, Widget) {
|
||||
let mut mk_card = |label: &str, kind: ColorKind, icon: Option<&'static str>| -> (Widget, Widget) {
|
||||
let vc = kind_color(&pal, kind);
|
||||
let card = Widget::panel(panel);
|
||||
card.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||
// Min-content floor (the widest label/value); cards grow equally past
|
||||
// this to fill the window (proportion 1 + EXPAND on add).
|
||||
card.set_min_size(116, 62);
|
||||
card.set_min_size(KPI_MIN, 62);
|
||||
let cs = Widget::box_sizer(true);
|
||||
let value = Widget::static_text(card, "0");
|
||||
value.set_font_size(19);
|
||||
value.set_bold();
|
||||
value.set_fg(vc.0, vc.1, vc.2);
|
||||
// Neutral cards (Total, Est. power) keep the default text colour so they
|
||||
// dim with the rest of the dashboard when the window loses focus; only
|
||||
// the semantically-coloured cards force a foreground (round-10 #2).
|
||||
if !matches!(kind, ColorKind::Neutral) {
|
||||
value.set_fg(vc.0, vc.1, vc.2);
|
||||
}
|
||||
value.set_bg(pal.card_bg.0, pal.card_bg.1, pal.card_bg.2);
|
||||
let lbl = Widget::static_text(card, label);
|
||||
lbl.set_font_size(9);
|
||||
@@ -484,8 +673,26 @@ pub fn build(frame: Widget) -> App {
|
||||
row.add_stretch(1);
|
||||
row
|
||||
};
|
||||
// The value row optionally leads with a small drawn KPI icon (round 11
|
||||
// #15). Neutral cards (Est. power) colour the icon amber for pop since
|
||||
// their value text stays the default (dimming) colour.
|
||||
let value_row = {
|
||||
let row = Widget::box_sizer(false);
|
||||
row.add_stretch(1);
|
||||
if let Some(svg) = icon {
|
||||
// Icon takes the card's value colour, so each icon matches its KPI
|
||||
// text (otter = paused colour, bolt = est-power colour, etc.).
|
||||
let icol = vc;
|
||||
let h = 20;
|
||||
let ic = Widget::svg_icon(card, &svg_recolored(svg, icol), svg_width_for_height(svg, h), h);
|
||||
row.add(ic, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_RIGHT, 5);
|
||||
}
|
||||
row.add(value, 0, sf::ALIGN_CENTRE_VERTICAL, 0);
|
||||
row.add_stretch(1);
|
||||
row
|
||||
};
|
||||
cs.add_stretch(1);
|
||||
cs.add_sizer(centre(value), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 8);
|
||||
cs.add_sizer(value_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_TOP | sf::BORDER_RIGHT, 8);
|
||||
cs.add_sizer(centre(lbl), 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_BOTTOM | sf::BORDER_RIGHT, 8);
|
||||
cs.add_stretch(1);
|
||||
cs.set_sizer_on(card);
|
||||
@@ -493,14 +700,23 @@ pub fn build(frame: Widget) -> App {
|
||||
kpi_cards.push((card, value, lbl, kind));
|
||||
(card, value)
|
||||
};
|
||||
let (_card_total, kpi_total) = mk_card("Total", ColorKind::Neutral);
|
||||
let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green);
|
||||
let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber);
|
||||
let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red);
|
||||
let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue);
|
||||
let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Accent);
|
||||
let (_card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral);
|
||||
// Icons (round 11 #15): rabbit=hashing, turtle=slow, cracked wine glass=not
|
||||
// hashing, otter=paused, hive=hashrate, lightning=power; Total has none.
|
||||
let (_card_total, kpi_total) = mk_card("Total", ColorKind::Neutral, None);
|
||||
let (card_hashing, kpi_hashing) = mk_card("Hashing", ColorKind::Green, Some(SVG_RABBIT));
|
||||
let (card_slow, kpi_slow) = mk_card("Slow", ColorKind::Amber, Some(SVG_TURTLE));
|
||||
let (card_not, kpi_not) = mk_card("Not hashing", ColorKind::Red, Some(SVG_WINE_CRACK));
|
||||
let (card_paused, kpi_paused) = mk_card("Paused", ColorKind::Blue, Some(SVG_OTTER));
|
||||
// Total-hashrate value renders in the default (black) text colour, not accent
|
||||
// (round 12 #1); it still dims with focus like the other neutral cards.
|
||||
let (card_hashrate, kpi_hashrate) = mk_card("SHA-256 Hashrate", ColorKind::Neutral, Some(SVG_HIVE));
|
||||
let (card_power, kpi_power) = mk_card("Est. power", ColorKind::Neutral, Some(SVG_BOLT));
|
||||
drop(mk_card);
|
||||
// The two wide cards carry a units-bearing value (icon + e.g. "685 TH" /
|
||||
// "21.3 kW"); give them a larger min width so the value never clips, and
|
||||
// collapse them before the row would squeeze them below it (round 12 #2).
|
||||
card_hashrate.set_min_size(KPI_WIDE_MIN, 62);
|
||||
card_power.set_min_size(KPI_WIDE_MIN, 62);
|
||||
let _ = (card_hashing, card_slow, card_not, card_paused);
|
||||
// The hashrate card is kpi_cards[5] in build order (Total, Hashing, Slow,
|
||||
// Not, Paused, Hashrate, Power); its caption is retitled per algorithm.
|
||||
@@ -567,6 +783,9 @@ pub fn build(frame: Widget) -> App {
|
||||
let table_parent = panel;
|
||||
|
||||
root.set_sizer_on(panel);
|
||||
// Collapse the two wide KPI cards when the window is too narrow to fit all
|
||||
// seven (round 11 #2): listen for panel resizes.
|
||||
panel.bind_size();
|
||||
let frame_sizer = Widget::box_sizer(true);
|
||||
frame_sizer.add(panel, 1, sf::EXPAND, 0);
|
||||
frame_sizer.set_sizer_on(frame);
|
||||
@@ -611,6 +830,9 @@ pub fn build(frame: Widget) -> App {
|
||||
selected_ips: HashSet::new(),
|
||||
pal,
|
||||
kpi_cards,
|
||||
panel,
|
||||
kpi_row,
|
||||
kpi_collapsed: false,
|
||||
kpi_filter_cards,
|
||||
active_kpi_filter: None,
|
||||
pending_popup: None,
|
||||
@@ -632,6 +854,8 @@ pub fn build(frame: Widget) -> App {
|
||||
creds_dialog: frame,
|
||||
creds_user_input: frame,
|
||||
creds_pass_input: frame,
|
||||
fwcreds_dialog: frame,
|
||||
fwcreds_rows: Vec::new(),
|
||||
access_probe: None,
|
||||
pic_probe: None,
|
||||
pending_pic_targets: Vec::new(),
|
||||
@@ -649,6 +873,8 @@ pub fn build(frame: Widget) -> App {
|
||||
ranges_auto: frame,
|
||||
columns_dialog: frame,
|
||||
columns_list: frame,
|
||||
columns_hide_empty_cb: frame,
|
||||
auto_hide_empty: false,
|
||||
filter_dialog: frame,
|
||||
filter_col_choice: frame,
|
||||
filter_controls: frame,
|
||||
@@ -674,6 +900,61 @@ pub fn build(frame: Widget) -> App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Whether `c` has no scanned value in any current row (round 11 #9). IP is
|
||||
/// never empty. With no rows loaded, nothing is considered empty (so the
|
||||
/// table isn't blanked before the first scan).
|
||||
fn column_is_empty(&self, c: Column) -> bool {
|
||||
c != Column::Ip
|
||||
&& !self.rows.is_empty()
|
||||
&& self.rows.iter().all(|r| c.cell(r).trim().is_empty())
|
||||
}
|
||||
|
||||
/// The columns the table actually shows: the view's display columns, minus
|
||||
/// any that are empty across all rows when the "hide empty columns" option is
|
||||
/// on (round 11 #9). Every table-path caller uses this (not
|
||||
/// `view.display_columns()` directly) so header/sort/reorder indices agree
|
||||
/// with what is rendered.
|
||||
fn table_columns(&self) -> Vec<Column> {
|
||||
let mut cols = self.view.display_columns();
|
||||
if self.auto_hide_empty {
|
||||
cols.retain(|c| !self.column_is_empty(*c));
|
||||
}
|
||||
cols
|
||||
}
|
||||
|
||||
/// Collapse or restore the two wide KPI cards (Hashrate, Est. power) as the
|
||||
/// window is resized (round 11 #2). When the panel is too narrow to fit all
|
||||
/// seven cards at their minimum width, the two wide cards are hidden so the
|
||||
/// five miner-count cards fill the row; they return when there is room again.
|
||||
fn on_resize(&mut self, width: i32) {
|
||||
// Each card occupies its min width + BORDER_ALL*2 (8px); the row itself is
|
||||
// inset by the root border (~12px). Collapse the two wide cards below the
|
||||
// width where all seven fit at their mins, so the wide cards' units-bearing
|
||||
// value never gets squeezed/clipped (round 12 #2) -- they drop out cleanly
|
||||
// instead.
|
||||
let need_all = 5 * (KPI_MIN + 8) + 2 * (KPI_WIDE_MIN + 8) + 12;
|
||||
let want_collapsed = width < need_all;
|
||||
if want_collapsed != self.kpi_collapsed {
|
||||
self.kpi_collapsed = want_collapsed;
|
||||
let show = !want_collapsed;
|
||||
// kpi_cards[5] = Hashrate card, [6] = Est. power card (build order).
|
||||
let hashrate_card = self.kpi_cards[5].0;
|
||||
let power_card = self.kpi_cards[6].0;
|
||||
self.kpi_row.sizer_show(hashrate_card, show);
|
||||
self.kpi_row.sizer_show(power_card, show);
|
||||
self.panel.layout();
|
||||
}
|
||||
// A nested wxPanel does not re-run its own sizer when the parent resizes
|
||||
// it, so the value/label centring spacers keep the slot sizes they were
|
||||
// given at the previous width. Re-layout each card here so the value
|
||||
// (which may carry a units suffix like "kW"/"PH") stays centred and its
|
||||
// full text is allocated -- otherwise the suffix reads as clipped when
|
||||
// the row is squeezed (round 12 #2).
|
||||
for (card, _, _, _) in &self.kpi_cards {
|
||||
card.layout();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rebuild_table(&mut self) {
|
||||
// Detach the old table from the sizer before destroying it, so the
|
||||
// sizer never holds a dangling item, then drop it.
|
||||
@@ -690,7 +971,7 @@ impl App {
|
||||
// an ASCII direction marker in its header ("^" asc, "v" desc) -- wx's
|
||||
// native SetSortOrder re-sorts the store lexically and would fight our
|
||||
// numeric sort, so we mark the header text instead.
|
||||
for c in self.view.display_columns() {
|
||||
for c in self.table_columns() {
|
||||
let fixed = self.view.is_fixed(c);
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
@@ -698,7 +979,7 @@ impl App {
|
||||
Some((sc, false)) if sc == c => title.push_str(" v"),
|
||||
_ => {}
|
||||
}
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status | Column::Firmware) {
|
||||
if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Light | Column::Error | Column::Status | Column::Firmware) {
|
||||
// These columns show two-tone / multi-tone text (actual vs.
|
||||
// expected, or one colour per fan) via a custom renderer that
|
||||
// parses the segment-encoded cell value fill_rows writes.
|
||||
@@ -723,7 +1004,7 @@ impl App {
|
||||
let top = t.dvlc_get_top_row();
|
||||
t.dvlc_clear();
|
||||
self.view_idx = self.view.view(&self.rows);
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
for &ri in &self.view_idx {
|
||||
let r = &self.rows[ri];
|
||||
let cells: Vec<String> = cols.iter().map(|c| c.cell(r)).collect();
|
||||
@@ -751,17 +1032,8 @@ impl App {
|
||||
.flatten();
|
||||
encode_combined_cell(&self.pal, actual, expected, "/", ratio)
|
||||
}
|
||||
Column::Hashboards => {
|
||||
let actual = r.hashboards.map(|v| v.to_string());
|
||||
let expected = r.expected_hashboards.map(|v| v.to_string());
|
||||
let ratio = r.hashboards.and_then(|a| {
|
||||
actual_expected_ratio(
|
||||
a as f64,
|
||||
r.expected_hashboards.map(|v| v as f64).unwrap_or(0.0),
|
||||
)
|
||||
});
|
||||
encode_combined_cell(&self.pal, actual, expected, " / ", ratio)
|
||||
}
|
||||
// Boards column: per-hashboard health dots (round 11 #10).
|
||||
Column::Hashboards => encode_board_dots(&self.pal, &r.board_status),
|
||||
Column::TotalChips => {
|
||||
let actual = r.total_chips.map(|v| v.to_string());
|
||||
let expected = r.expected_chips.map(|v| v.to_string());
|
||||
@@ -775,24 +1047,20 @@ impl App {
|
||||
}
|
||||
Column::ChipTemp => encode_board_temps_cell(&self.pal, &r.board_temps, r.chip_temp_c),
|
||||
Column::Cooling => encode_cooling_cell(&self.pal, &r.fan_rpms),
|
||||
Column::Locked => {
|
||||
// green = unlocked/writable, red = locked/view-only.
|
||||
let color = match r.write_locked {
|
||||
Some(true) => Some(self.pal.red),
|
||||
Some(false) => Some(self.pal.green),
|
||||
None => None,
|
||||
};
|
||||
encode_flag_cell(&c.cell(r), color)
|
||||
}
|
||||
// Access column: a padlock icon, green open (writable) / red
|
||||
// closed (view-only) (round 11 #13).
|
||||
Column::Locked => encode_access_icon(&self.pal, r.write_locked),
|
||||
// Light column: a yellow locate dot while flashing (round 11 #10).
|
||||
Column::Light => encode_light_dot(&self.pal, r.light_flashing),
|
||||
Column::Error => {
|
||||
let color = (!r.errors.is_empty()).then_some(self.pal.red);
|
||||
encode_flag_cell(&c.cell(r), color)
|
||||
}
|
||||
Column::Firmware => encode_flag_cell(&c.cell(r), firmware_color(&r.firmware)),
|
||||
Column::Status => {
|
||||
// Status keeps its status colour on its own cell (the
|
||||
// row is no longer tinted wholesale).
|
||||
encode_flag_cell(&c.cell(r), Some(status_kind_color(&self.pal, r.status())))
|
||||
// The status reads as its KPI icon (round 12 #11), drawn
|
||||
// in the status colour so it matches the dashboard card.
|
||||
encode_status_icon(&self.pal, r.status())
|
||||
}
|
||||
_ => continue,
|
||||
};
|
||||
@@ -817,6 +1085,14 @@ impl App {
|
||||
if !sel.is_empty() {
|
||||
t.dvlc_select_rows(&sel);
|
||||
}
|
||||
// Run the locate-light fade timer only while a visible row's light is
|
||||
// actually flashing (round 12 #6), so the table isn't repainted on a timer
|
||||
// when there is nothing to animate.
|
||||
let any_flashing = self
|
||||
.view_idx
|
||||
.iter()
|
||||
.any(|&ri| self.rows[ri].light_flashing == Some(true));
|
||||
wx_rs::set_light_pulse(any_flashing);
|
||||
self.refresh_kpis();
|
||||
}
|
||||
|
||||
@@ -875,7 +1151,10 @@ impl App {
|
||||
let vc = kind_color(&self.pal, *kind);
|
||||
card.set_bg(self.pal.card_bg.0, self.pal.card_bg.1, self.pal.card_bg.2);
|
||||
value.set_bg(self.pal.card_bg.0, self.pal.card_bg.1, self.pal.card_bg.2);
|
||||
value.set_fg(vc.0, vc.1, vc.2);
|
||||
// Neutral cards keep the default (dimming) text colour -- see mk_card.
|
||||
if !matches!(kind, ColorKind::Neutral) {
|
||||
value.set_fg(vc.0, vc.1, vc.2);
|
||||
}
|
||||
caption.set_bg(self.pal.card_bg.0, self.pal.card_bg.1, self.pal.card_bg.2);
|
||||
caption.set_fg(self.pal.label.0, self.pal.label.1, self.pal.label.2);
|
||||
}
|
||||
@@ -1176,10 +1455,13 @@ impl App {
|
||||
wx_rs::set_status_text("an access check is already running");
|
||||
return;
|
||||
}
|
||||
// Pass the brand (make), not the firmware family: the access probe picks
|
||||
// its strategy by make (WhatsMiner :4028 token vs Antminer web digest),
|
||||
// and "Stock" alone can't tell them apart (round 12 #8b).
|
||||
let targets: Vec<(String, String)> = self
|
||||
.selected_rows()
|
||||
.iter()
|
||||
.map(|r| (r.ip.clone(), r.firmware.clone()))
|
||||
.map(|r| (r.ip.clone(), r.brand.clone()))
|
||||
.collect();
|
||||
if targets.is_empty() {
|
||||
return;
|
||||
@@ -1296,9 +1578,8 @@ impl App {
|
||||
/// actions (power limit / tuning %) return a prompt dialog to show modally.
|
||||
fn on_menu_item(&mut self, id: i32) -> Option<Widget> {
|
||||
match id {
|
||||
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => {
|
||||
return self.on_header_menu(id)
|
||||
}
|
||||
ID_HDR_SORT_ASC | ID_HDR_SORT_DESC | ID_HDR_SORT_REL_ASC | ID_HDR_SORT_REL_DESC
|
||||
| ID_HDR_HIDE | ID_HDR_AUTOSIZE | ID_HDR_COLUMNS => return self.on_header_menu(id),
|
||||
ID_CTX_OPEN => {
|
||||
for ip in self.selected_ip_list() {
|
||||
wx_rs::launch_browser(&format!("http://{ip}"));
|
||||
@@ -1560,6 +1841,19 @@ impl App {
|
||||
pass_input.set_min_size(200, -1);
|
||||
pass_row.add(pass_input, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
root.add_sizer(pass_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
// The single credential above is applied to every firmware that has no
|
||||
// per-firmware override; the button below edits those per-firmware default
|
||||
// logins (round 12 #13).
|
||||
let fwrow = Widget::box_sizer(false);
|
||||
fwrow.add(
|
||||
Widget::static_text(dlg, "Or set a login per firmware:"),
|
||||
0,
|
||||
sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL,
|
||||
6,
|
||||
);
|
||||
fwrow.add_stretch(1);
|
||||
fwrow.add(Widget::button(dlg, "Per-firmware defaults...", ID_FWCREDS_OPEN), 0, sf::BORDER_ALL, 6);
|
||||
root.add_sizer(fwrow, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, 6);
|
||||
let btns = Widget::box_sizer(false);
|
||||
btns.add_stretch(1);
|
||||
btns.add(Widget::button(dlg, "Save", ID_CREDS_SAVE), 0, sf::BORDER_ALL, 6);
|
||||
@@ -1567,7 +1861,7 @@ impl App {
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_CREDS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
root.set_sizer_on(dlg);
|
||||
dlg.set_min_size(360, 190);
|
||||
dlg.set_min_size(460, 220);
|
||||
dlg.fit(dlg);
|
||||
self.creds_dialog = dlg;
|
||||
self.creds_user_input = user_input;
|
||||
@@ -1575,6 +1869,113 @@ impl App {
|
||||
dlg
|
||||
}
|
||||
|
||||
/// Build (but do not show) the per-firmware default-credentials editor
|
||||
/// (round 12 #13): one row per firmware in the asic-rs registry, each with a
|
||||
/// username and password field prefilled from the saved override or, failing
|
||||
/// that, the firmware's shipped default. Editing a field away from the default
|
||||
/// makes it an override; setting it back to the default clears the override.
|
||||
fn build_firmware_creds_dialog(&mut self) -> Widget {
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Per-firmware default logins");
|
||||
let root = Widget::box_sizer(true);
|
||||
root.add(
|
||||
Widget::static_text(
|
||||
dlg,
|
||||
"Default login used when auto-discovering each firmware. Blank fields mean no login.\nValues left at the firmware's shipped default are not saved as overrides.",
|
||||
),
|
||||
0,
|
||||
sf::BORDER_ALL,
|
||||
8,
|
||||
);
|
||||
// Column headers.
|
||||
let head = Widget::box_sizer(false);
|
||||
let h_fw = Widget::static_text(dlg, "Firmware");
|
||||
h_fw.set_min_size(150, -1);
|
||||
head.add(h_fw, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let h_user = Widget::static_text(dlg, "Username");
|
||||
h_user.set_min_size(150, -1);
|
||||
head.add(h_user, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
head.add(Widget::static_text(dlg, "Password"), 0, sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
root.add_sizer(head, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, 6);
|
||||
|
||||
let saved = credentials::load_firmware_credentials();
|
||||
let mut rows: Vec<(String, Widget, Widget)> = Vec::new();
|
||||
for fw in asic_rs::factory::default_firmware_registry() {
|
||||
let name = fw.to_string();
|
||||
let (def_user, def_pass) = credentials::firmware_default_for(&name);
|
||||
let (user, pass) = saved
|
||||
.get(&name)
|
||||
.cloned()
|
||||
.unwrap_or((def_user, def_pass));
|
||||
let row = Widget::box_sizer(false);
|
||||
let label = Widget::static_text(dlg, &name);
|
||||
label.set_min_size(150, -1);
|
||||
row.add(label, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let user_ctrl = Widget::text_ctrl(dlg, false);
|
||||
user_ctrl.set_min_size(150, -1);
|
||||
user_ctrl.set_value(&user);
|
||||
row.add(user_ctrl, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let pass_ctrl = Widget::text_ctrl(dlg, false);
|
||||
pass_ctrl.set_min_size(150, -1);
|
||||
pass_ctrl.set_value(&pass);
|
||||
row.add(pass_ctrl, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
root.add_sizer(row, 0, sf::EXPAND | sf::BORDER_TOP, 4);
|
||||
rows.push((name, user_ctrl, pass_ctrl));
|
||||
}
|
||||
|
||||
let btns = Widget::box_sizer(false);
|
||||
btns.add_stretch(1);
|
||||
btns.add(Widget::button(dlg, "Save", ID_FWCREDS_SAVE), 0, sf::BORDER_ALL, 6);
|
||||
btns.add(Widget::button(dlg, "Reset to defaults", ID_FWCREDS_RESET), 0, sf::BORDER_ALL, 6);
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_FWCREDS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
root.add_sizer(btns, 0, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
root.set_sizer_on(dlg);
|
||||
dlg.set_min_size(520, 200);
|
||||
dlg.fit(dlg);
|
||||
self.fwcreds_dialog = dlg;
|
||||
self.fwcreds_rows = rows;
|
||||
dlg
|
||||
}
|
||||
|
||||
/// Persist the per-firmware editor: a row that differs from the firmware's
|
||||
/// shipped default becomes an override; a row equal to the default clears it.
|
||||
fn apply_firmware_creds_save(&mut self) {
|
||||
let mut map: std::collections::HashMap<String, (String, String)> = std::collections::HashMap::new();
|
||||
for (name, user_ctrl, pass_ctrl) in &self.fwcreds_rows {
|
||||
let user = user_ctrl.get_value();
|
||||
let pass = pass_ctrl.get_value();
|
||||
let default = credentials::firmware_default_for(name);
|
||||
if (user.clone(), pass.clone()) != default {
|
||||
map.insert(name.clone(), (user, pass));
|
||||
}
|
||||
}
|
||||
match credentials::save_firmware_credentials(&map) {
|
||||
Ok(()) => {
|
||||
self.fwcreds_dialog.close(1);
|
||||
let n = map.len();
|
||||
wx_rs::set_status_text(&format!(
|
||||
"per-firmware logins saved ({n} override{})",
|
||||
if n == 1 { "" } else { "s" }
|
||||
));
|
||||
}
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to save per-firmware logins: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Reset every editor row to the firmware's shipped default and clear the
|
||||
/// saved overrides.
|
||||
fn apply_firmware_creds_reset(&mut self) {
|
||||
for (name, user_ctrl, pass_ctrl) in &self.fwcreds_rows {
|
||||
let (user, pass) = credentials::firmware_default_for(name);
|
||||
user_ctrl.set_value(&user);
|
||||
pass_ctrl.set_value(&pass);
|
||||
}
|
||||
match credentials::clear_firmware_credentials() {
|
||||
Ok(()) => wx_rs::set_status_text("per-firmware logins reset to defaults"),
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to clear per-firmware logins: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_creds_save(&mut self) {
|
||||
let user = self.creds_user_input.get_value();
|
||||
let mut pass = self.creds_pass_input.get_value();
|
||||
@@ -1917,15 +2318,28 @@ impl App {
|
||||
// Columns are appended in display order; map the clicked creation index
|
||||
// back to a model column through display_columns() (hidden columns don't
|
||||
// shift the mapping). Every column, including IP at index 0, is sortable.
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
if creation_idx >= cols.len() {
|
||||
return;
|
||||
}
|
||||
let col = cols[creation_idx];
|
||||
self.view.sort = match self.view.sort {
|
||||
Some((c, true)) if c == col => Some((col, false)),
|
||||
Some((c, false)) if c == col => None,
|
||||
_ => Some((col, true)),
|
||||
self.view.sort = if col == Column::Hashrate {
|
||||
// The Hashrate header cycles through four modes: absolute asc, absolute
|
||||
// desc, relative (actual/expected) asc, relative desc, then unsorted
|
||||
// (round 11 #16).
|
||||
match self.view.sort {
|
||||
Some((Column::Hashrate, true)) => Some((Column::Hashrate, false)),
|
||||
Some((Column::Hashrate, false)) => Some((Column::HashrateRel, true)),
|
||||
Some((Column::HashrateRel, true)) => Some((Column::HashrateRel, false)),
|
||||
Some((Column::HashrateRel, false)) => None,
|
||||
_ => Some((Column::Hashrate, true)),
|
||||
}
|
||||
} else {
|
||||
match self.view.sort {
|
||||
Some((c, true)) if c == col => Some((col, false)),
|
||||
Some((c, false)) if c == col => None,
|
||||
_ => Some((col, true)),
|
||||
}
|
||||
};
|
||||
// Update the header marker in place + re-sort rows. Avoids destroying and
|
||||
// recreating the whole control on every sort click (janky on big fleets).
|
||||
@@ -1937,12 +2351,18 @@ impl App {
|
||||
/// auto-size, and open the full column picker).
|
||||
fn header_context_menu(&mut self, creation_idx: usize) {
|
||||
let Some(t) = self.table else { return };
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
let Some(&col) = cols.get(creation_idx) else { return };
|
||||
self.header_menu_col = Some(col);
|
||||
let menu = Widget::menu_new();
|
||||
menu.menu_append(ID_HDR_SORT_ASC, &format!("Sort {} ascending", col.title()));
|
||||
menu.menu_append(ID_HDR_SORT_DESC, &format!("Sort {} descending", col.title()));
|
||||
// The Hashrate column also offers a relative (actual/expected) sort
|
||||
// (round 11 #16).
|
||||
if col == Column::Hashrate {
|
||||
menu.menu_append(ID_HDR_SORT_REL_ASC, "Sort relative hashrate ascending");
|
||||
menu.menu_append(ID_HDR_SORT_REL_DESC, "Sort relative hashrate descending");
|
||||
}
|
||||
menu.menu_append_separator();
|
||||
menu.menu_append(ID_HDR_AUTOSIZE, "Auto-size this column");
|
||||
// The fixed IP column can't be hidden.
|
||||
@@ -1968,13 +2388,23 @@ impl App {
|
||||
self.update_headers();
|
||||
self.fill_rows();
|
||||
}
|
||||
ID_HDR_SORT_REL_ASC => {
|
||||
self.view.sort = Some((Column::HashrateRel, true));
|
||||
self.update_headers();
|
||||
self.fill_rows();
|
||||
}
|
||||
ID_HDR_SORT_REL_DESC => {
|
||||
self.view.sort = Some((Column::HashrateRel, false));
|
||||
self.update_headers();
|
||||
self.fill_rows();
|
||||
}
|
||||
ID_HDR_HIDE if !self.view.is_fixed(col) => {
|
||||
self.view.visible.remove(&col);
|
||||
self.rebuild_table();
|
||||
}
|
||||
ID_HDR_AUTOSIZE => {
|
||||
if let (Some(t), Some(pos)) =
|
||||
(self.table, self.view.display_columns().iter().position(|c| *c == col))
|
||||
(self.table, self.table_columns().iter().position(|c| *c == col))
|
||||
{
|
||||
t.dvlc_autosize_col(pos);
|
||||
}
|
||||
@@ -1989,11 +2419,16 @@ impl App {
|
||||
/// place, without recreating the table.
|
||||
fn update_headers(&self) {
|
||||
let Some(t) = self.table else { return };
|
||||
for (i, c) in self.view.display_columns().iter().enumerate() {
|
||||
for (i, c) in self.table_columns().iter().enumerate() {
|
||||
let mut title = c.title().to_string();
|
||||
match self.view.sort {
|
||||
Some((sc, true)) if sc == *c => title.push_str(" ^"),
|
||||
Some((sc, false)) if sc == *c => title.push_str(" v"),
|
||||
// The relative-hashrate sort is a pseudo-column; mark it on the
|
||||
// Hashrate header with a "%" so the mode is visible (round 11 #16).
|
||||
Some((Column::HashrateRel, asc)) if *c == Column::Hashrate => {
|
||||
title.push_str(if asc { " %^" } else { " %v" })
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
t.dvlc_set_col_title(i, &title);
|
||||
@@ -2006,7 +2441,7 @@ impl App {
|
||||
// model column via display_columns(). Read the new visible order from
|
||||
// the drag result and hand it to the model, which splices it back into
|
||||
// the full column order while leaving hidden columns in place.
|
||||
let disp = self.view.display_columns();
|
||||
let disp = self.table_columns();
|
||||
let n = t.dvlc_col_count();
|
||||
let mut new_visible = Vec::with_capacity(n);
|
||||
for pos in 0..n {
|
||||
@@ -2211,7 +2646,7 @@ impl App {
|
||||
let root = Widget::box_sizer(true);
|
||||
let hint = Widget::static_text(
|
||||
dlg,
|
||||
"Check to show a metric; drag or use the arrows to reorder (IP is always first).",
|
||||
"Check to show a metric; drag rows to reorder (IP is always first). Shift/Ctrl-click or drag to select several.",
|
||||
);
|
||||
root.add(hint, 0, sf::BORDER_ALL, 6);
|
||||
// Base list is registry order; the wx order array lists items in the
|
||||
@@ -2226,8 +2661,13 @@ impl App {
|
||||
order.push(if self.view.visible.contains(c) { idx } else { !idx });
|
||||
}
|
||||
}
|
||||
let list = Widget::rearrange_list(dlg, &order, &titles);
|
||||
let list = Widget::reorder_list(dlg, &order, &titles);
|
||||
root.add(list, 1, sf::EXPAND | sf::BORDER_ALL, 6);
|
||||
// Option: hide columns with no scanned value in any row (round 11 #9).
|
||||
let hide_empty = Widget::check_box(dlg, "Hide columns with no scanned values");
|
||||
hide_empty.set_checked(self.auto_hide_empty);
|
||||
root.add(hide_empty, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_BOTTOM, 6);
|
||||
self.columns_hide_empty_cb = hide_empty;
|
||||
let btns = Widget::box_sizer(false);
|
||||
btns.add(Widget::button(dlg, "OK", ID_COLUMNS_OK), 0, sf::BORDER_ALL, 6);
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_COLUMNS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
@@ -2240,8 +2680,11 @@ impl App {
|
||||
}
|
||||
|
||||
fn apply_columns(&mut self) {
|
||||
// Persist the "hide empty columns" option (round 11 #9); table_columns()
|
||||
// applies it non-destructively when the table is (re)built below.
|
||||
self.auto_hide_empty = self.columns_hide_empty_cb.is_checked();
|
||||
let base = Self::selectable_columns();
|
||||
let order = self.columns_list.rearrange_get_order();
|
||||
let order = self.columns_list.reorder_get_order();
|
||||
let mut new_order: Vec<Column> = vec![Column::Ip];
|
||||
let mut visible: HashSet<Column> = HashSet::from([Column::Ip]);
|
||||
for entry in order {
|
||||
@@ -2619,6 +3062,10 @@ impl App {
|
||||
ID_CREDS_SAVE => self.apply_creds_save(),
|
||||
ID_CREDS_CLEAR => self.apply_creds_clear(),
|
||||
ID_CREDS_CANCEL => self.creds_dialog.close(0),
|
||||
ID_FWCREDS_OPEN => return Some(self.build_firmware_creds_dialog()),
|
||||
ID_FWCREDS_SAVE => self.apply_firmware_creds_save(),
|
||||
ID_FWCREDS_RESET => self.apply_firmware_creds_reset(),
|
||||
ID_FWCREDS_CANCEL => self.fwcreds_dialog.close(0),
|
||||
ID_KPI_HASHING => self.toggle_kpi_filter("hashing"),
|
||||
ID_KPI_SLOW => self.toggle_kpi_filter("slow"),
|
||||
ID_KPI_NOT => self.toggle_kpi_filter("not hashing"),
|
||||
@@ -2664,6 +3111,7 @@ impl App {
|
||||
WxEventKind::MenuItem => return self.on_menu_item(ev.p1 as i32),
|
||||
WxEventKind::ChoiceChanged => self.on_choice_changed(ev.p1 as i32, ev.p2 as i32),
|
||||
WxEventKind::SysColour => self.repaint_theme(),
|
||||
WxEventKind::Sized => self.on_resize(ev.p1 as i32),
|
||||
WxEventKind::Deferred => self.on_deferred(ev.p1 as i32),
|
||||
WxEventKind::TimerTick if ev.p1 as i32 == TIMER_SCAN => self.tick(),
|
||||
_ => {}
|
||||
@@ -2707,7 +3155,7 @@ impl App {
|
||||
check("table exists", false, "no table widget".into());
|
||||
return false;
|
||||
};
|
||||
let cols = self.view.display_columns();
|
||||
let cols = self.table_columns();
|
||||
|
||||
// 2. Row count in the store matches the (unfiltered) fixture count.
|
||||
let want_rows = self.view_idx.len();
|
||||
@@ -2723,9 +3171,15 @@ impl App {
|
||||
for (disp_row, &ri) in self.view_idx.iter().enumerate() {
|
||||
let r = &self.rows[ri];
|
||||
for (j, c) in cols.iter().enumerate() {
|
||||
// Icon/dot columns (round 11 #10/#13) render shape sentinels, not
|
||||
// text, so they don't round-trip to c.cell(r); they're verified
|
||||
// structurally in the icon-column spot-check below.
|
||||
if matches!(c, Column::Hashboards | Column::Locked | Column::Light | Column::Status) {
|
||||
continue;
|
||||
}
|
||||
let want = c.cell(r);
|
||||
let raw = t.dvlc_get_cell(disp_row, j).unwrap_or_default();
|
||||
let got = if matches!(c, Column::Hashrate | Column::Hashboards | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Locked | Column::Error | Column::Status | Column::Firmware) {
|
||||
let got = if matches!(c, Column::Hashrate | Column::TotalChips | Column::ChipTemp | Column::Cooling | Column::Error | Column::Firmware) {
|
||||
decode_segments_plain(&raw)
|
||||
} else {
|
||||
raw
|
||||
@@ -2743,7 +3197,6 @@ impl App {
|
||||
|
||||
// 4. Independent spot-checks by IP against the known hardware output.
|
||||
let ip_col = cols.iter().position(|c| *c == Column::Ip);
|
||||
let status_col = cols.iter().position(|c| *c == Column::Status);
|
||||
let hr_col = cols.iter().position(|c| *c == Column::Hashrate);
|
||||
let find = |ip: &str| -> Option<usize> {
|
||||
self.view_idx.iter().position(|&ri| self.rows[ri].ip == ip)
|
||||
@@ -2756,9 +3209,27 @@ impl App {
|
||||
None => String::new(),
|
||||
}
|
||||
};
|
||||
if let (Some(row), Some(_)) = (find("10.255.1.149"), status_col) {
|
||||
check("S21 Pro (.149) is slow", cell(row, status_col) == "slow",
|
||||
format!("status=\"{}\"", cell(row, status_col)));
|
||||
// Status is a model property; the Status column is not in the default
|
||||
// view (round 11 #12), so verify it straight from the row rather than a
|
||||
// displayed cell.
|
||||
let status_of = |row: usize| -> &'static str { self.rows[self.view_idx[row]].status() };
|
||||
// Icon columns (round 11 #10/#13): the store carries shape sentinels
|
||||
// (dots / padlock), not text -- verify they are present.
|
||||
let boards_col = cols.iter().position(|c| *c == Column::Hashboards);
|
||||
let access_col = cols.iter().position(|c| *c == Column::Locked);
|
||||
if let (Some(bc), Some(row)) = (boards_col, find("10.255.1.166")) {
|
||||
let raw = t.dvlc_get_cell(row, bc).unwrap_or_default();
|
||||
check("Boards column renders dot sentinels for a mining miner",
|
||||
raw.contains('\u{0007}'), format!("cell={raw:?}"));
|
||||
}
|
||||
if let (Some(ac), Some(row)) = (access_col, find("10.255.1.112")) {
|
||||
let raw = t.dvlc_get_cell(row, ac).unwrap_or_default();
|
||||
check("Access column renders a closed-padlock sentinel for a locked miner",
|
||||
raw.contains('\u{0002}'), format!("cell={raw:?}"));
|
||||
}
|
||||
if let Some(row) = find("10.255.1.149") {
|
||||
check("S21 Pro (.149) is slow", status_of(row) == "slow",
|
||||
format!("status=\"{}\"", status_of(row)));
|
||||
check("S21 Pro (.149) hashrate == 60.0T/200T",
|
||||
cell(row, hr_col) == "60.0T/200T",
|
||||
format!("hashrate=\"{}\"", cell(row, hr_col)));
|
||||
@@ -2766,16 +3237,16 @@ impl App {
|
||||
check("S21 Pro (.149) present", false, "row not found".into());
|
||||
}
|
||||
if let Some(row) = find("10.255.1.112") {
|
||||
check("S17 (.112) is not hashing", cell(row, status_col) == "not hashing",
|
||||
format!("status=\"{}\"", cell(row, status_col)));
|
||||
check("S17 (.112) is not hashing", status_of(row) == "not hashing",
|
||||
format!("status=\"{}\"", status_of(row)));
|
||||
check("S17 (.112) blank hashrate", cell(row, hr_col).is_empty(),
|
||||
format!("hashrate=\"{}\"", cell(row, hr_col)));
|
||||
} else {
|
||||
check("S17 (.112) present", false, "row not found".into());
|
||||
}
|
||||
if let Some(row) = find("10.255.1.115") {
|
||||
check("WardenOS-dev (.115) is paused", cell(row, status_col) == "paused",
|
||||
format!("status=\"{}\"", cell(row, status_col)));
|
||||
check("WardenOS-dev (.115) is paused", status_of(row) == "paused",
|
||||
format!("status=\"{}\"", status_of(row)));
|
||||
} else {
|
||||
check("WardenOS-dev (.115) present", false, "row not found".into());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
Subject: [PATCH 0003] antminer: recognise VNish short control-board platforms (CV, XIL)
|
||||
|
||||
Round-11 #5 -- VNish reports the control board in short form via /api/v1/info
|
||||
"platform": "cv" (CVITek), "xil" (Xilinx), "aml" (AMLogic). asic-rs's
|
||||
AntMinerControlBoard::parse matched the full names (CVITEK, XILINX) but not the
|
||||
short "CV"/"XIL", so VNish CVITek and Xilinx boards showed a blank control board
|
||||
(the "can't scan XIL or CVITek boards" bug). Add the short forms. Verified live:
|
||||
S19k Pro platform "cv" -> CVITek, S19 platform "xil" -> Xilinx.
|
||||
|
||||
diff --git a/vendor/asic-rs-makes-antminer/src/hardware.rs b/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
index 41a73240..aa0923c8 100644
|
||||
--- a/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
+++ b/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
@@ -268,11 +268,13 @@ impl AntMinerControlBoard {
|
||||
.collect::<String>();
|
||||
|
||||
match compact.as_str() {
|
||||
- "XILINX" => Some(Self::Xilinx),
|
||||
+ // "XIL" is VNish's short platform form for a Xilinx control board.
|
||||
+ "XILINX" | "XIL" => Some(Self::Xilinx),
|
||||
"BBB" | "BBCTRL" | "BB" | "BEAGLEBONE" | "BEAGLEBONEBLACK" => {
|
||||
Some(Self::BeagleBoneBlack)
|
||||
}
|
||||
- "CVITEK" | "CVCTRL" => Some(Self::CVITek),
|
||||
+ // "CV" is VNish's short platform form for a CVITek control board.
|
||||
+ "CVITEK" | "CVCTRL" | "CV" => Some(Self::CVITek),
|
||||
"AMLOGIC" | "AML" => Some(Self::AMLogic),
|
||||
"AMCB07" => Some(Self::Xilinx), // Mara FW
|
||||
"ZYNQ7007" => Some(Self::Xilinx),
|
||||
@@ -0,0 +1,65 @@
|
||||
Subject: [PATCH 0004] whatsminer v1: control-board fallback + optional ALLWINNER_ prefix
|
||||
|
||||
Round-11 #5 -- older M30S firmware (< 2022.7.29, the v1 backend) often omits
|
||||
"CB Platform" from the summary RPC, and its parse mandatorily stripped an
|
||||
"ALLWINNER_" prefix (strip_prefix(..)? -> None when absent), so those units
|
||||
showed a blank control board. Add get_version /Msg/platform (the source v2 uses)
|
||||
as a fallback location, and make the ALLWINNER_ strip optional. Verified live:
|
||||
M30S+ VE40 (fw 20220422, v1) blank -> H6OS.
|
||||
|
||||
diff --git a/vendor/asic-rs-firmwares-whatsminer/src/backends/v1/mod.rs b/vendor/asic-rs-firmwares-whatsminer/src/backends/v1/mod.rs
|
||||
index b4a27db8..f95a22ae 100644
|
||||
--- a/vendor/asic-rs-firmwares-whatsminer/src/backends/v1/mod.rs
|
||||
+++ b/vendor/asic-rs-firmwares-whatsminer/src/backends/v1/mod.rs
|
||||
@@ -131,14 +131,28 @@ impl GetDataLocations for WhatsMinerV1 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
- DataField::ControlBoardVersion => vec![(
|
||||
- RPC_SUMMARY,
|
||||
- DataExtractor {
|
||||
- func: get_by_pointer,
|
||||
- key: Some("/SUMMARY/0/CB Platform"),
|
||||
- tag: None,
|
||||
- },
|
||||
- )],
|
||||
+ DataField::ControlBoardVersion => vec![
|
||||
+ (
|
||||
+ RPC_SUMMARY,
|
||||
+ DataExtractor {
|
||||
+ func: get_by_pointer,
|
||||
+ key: Some("/SUMMARY/0/CB Platform"),
|
||||
+ tag: None,
|
||||
+ },
|
||||
+ ),
|
||||
+ // Older M30S firmware (< 2022.7.29, so this v1 backend) often omits
|
||||
+ // "CB Platform" from summary but still reports the board under
|
||||
+ // get_version /Msg/platform (the source v2 uses). Fall back to it so
|
||||
+ // those units don't show a blank control board.
|
||||
+ (
|
||||
+ RPC_GET_VERSION,
|
||||
+ DataExtractor {
|
||||
+ func: get_by_pointer,
|
||||
+ key: Some("/Msg/platform"),
|
||||
+ tag: None,
|
||||
+ },
|
||||
+ ),
|
||||
+ ],
|
||||
DataField::TuningTarget => vec![(
|
||||
RPC_SUMMARY,
|
||||
DataExtractor {
|
||||
@@ -285,8 +299,12 @@ impl GetControlBoardVersion for WhatsMinerV1 {
|
||||
) -> Option<MinerControlBoard> {
|
||||
data.extract::<String>(DataField::ControlBoardVersion)
|
||||
.and_then(|s| {
|
||||
- WhatsMinerControlBoard::parse(s.to_uppercase().strip_prefix("ALLWINNER_")?)
|
||||
- .map(|cb| cb.into())
|
||||
+ // The "ALLWINNER_" prefix is optional: summary's CB Platform carries
|
||||
+ // it (e.g. "ALLWINNER_H6"), but the get_version /Msg/platform fallback
|
||||
+ // does not (e.g. "H6OS"). Strip it only when present.
|
||||
+ let up = s.to_uppercase();
|
||||
+ let board = up.strip_prefix("ALLWINNER_").unwrap_or(&up);
|
||||
+ WhatsMinerControlBoard::parse(board).map(|cb| cb.into())
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
Subject: [PATCH 0005] vnish: surface the partner build name in the firmware version
|
||||
|
||||
Round-11 #6b/#11 -- VNish /api/v1/info carries a partner/reseller "build_name"
|
||||
("WildRose", "vnishreturn", ...) alongside "fw_version"; it is shown in the
|
||||
Hashcore toolkit but asic-rs did not expose it. Point the FirmwareVersion
|
||||
extractor at /build_name and combine it with the /fw_version number (still on
|
||||
ApiVersion) in parse_firmware_version, so firmware_version reads "<build>
|
||||
<version>", e.g. "WildRose 1.2.7". Applies to both the v1_2_0 and v1_3_0
|
||||
backends. Verified live: S19j Pro -> "WildRose 1.2.7", S19k Pro -> "vnishreturn 1.3.5".
|
||||
|
||||
diff --git a/vendor/asic-rs-firmwares-vnish/src/backends/v1_2_0/mod.rs b/vendor/asic-rs-firmwares-vnish/src/backends/v1_2_0/mod.rs
|
||||
index 4cc1434a..e734a03e 100644
|
||||
--- a/vendor/asic-rs-firmwares-vnish/src/backends/v1_2_0/mod.rs
|
||||
+++ b/vendor/asic-rs-firmwares-vnish/src/backends/v1_2_0/mod.rs
|
||||
@@ -179,11 +179,15 @@ impl GetDataLocations for VnishV120 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
+ // The partner/reseller build name ("WildRose", "vnishreturn", ...) --
|
||||
+ // combined with the version number in parse_firmware_version so the FW
|
||||
+ // Version column shows e.g. "WildRose 1.3.5". ApiVersion still carries
|
||||
+ // the bare /fw_version.
|
||||
DataField::FirmwareVersion => vec![(
|
||||
WEB_INFO,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
- key: Some("/fw_version"),
|
||||
+ key: Some("/build_name"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
@@ -415,7 +419,20 @@ impl GetApiVersion for VnishV120 {
|
||||
|
||||
impl GetFirmwareVersion for VnishV120 {
|
||||
fn parse_firmware_version(&self, data: &HashMap<DataField, Value>) -> Option<String> {
|
||||
- data.extract::<String>(DataField::FirmwareVersion)
|
||||
+ // FirmwareVersion carries /build_name (the partner build), ApiVersion the
|
||||
+ // /fw_version number; show "<build> <version>" when both are present, else
|
||||
+ // whichever is available.
|
||||
+ let build = data
|
||||
+ .extract::<String>(DataField::FirmwareVersion)
|
||||
+ .filter(|b| !b.is_empty());
|
||||
+ let version = data
|
||||
+ .extract::<String>(DataField::ApiVersion)
|
||||
+ .filter(|v| !v.is_empty());
|
||||
+ match (build, version) {
|
||||
+ (Some(b), Some(v)) => Some(format!("{b} {v}")),
|
||||
+ (Some(b), None) => Some(b),
|
||||
+ (None, v) => v,
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/vendor/asic-rs-firmwares-vnish/src/backends/v1_3_0/mod.rs b/vendor/asic-rs-firmwares-vnish/src/backends/v1_3_0/mod.rs
|
||||
index 6975d9e5..0a5d694e 100644
|
||||
--- a/vendor/asic-rs-firmwares-vnish/src/backends/v1_3_0/mod.rs
|
||||
+++ b/vendor/asic-rs-firmwares-vnish/src/backends/v1_3_0/mod.rs
|
||||
@@ -179,11 +179,13 @@ impl GetDataLocations for VnishV130 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
+ // Partner/reseller build name; combined with the version number in
|
||||
+ // parse_firmware_version (FW Version shows e.g. "WildRose 1.3.5").
|
||||
DataField::FirmwareVersion => vec![(
|
||||
WEB_INFO,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
- key: Some("/fw_version"),
|
||||
+ key: Some("/build_name"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
@@ -423,7 +425,19 @@ impl GetApiVersion for VnishV130 {
|
||||
|
||||
impl GetFirmwareVersion for VnishV130 {
|
||||
fn parse_firmware_version(&self, data: &HashMap<DataField, Value>) -> Option<String> {
|
||||
- data.extract::<String>(DataField::FirmwareVersion)
|
||||
+ // FirmwareVersion carries /build_name (partner build), ApiVersion the
|
||||
+ // /fw_version number; show "<build> <version>" when both are present.
|
||||
+ let build = data
|
||||
+ .extract::<String>(DataField::FirmwareVersion)
|
||||
+ .filter(|b| !b.is_empty());
|
||||
+ let version = data
|
||||
+ .extract::<String>(DataField::ApiVersion)
|
||||
+ .filter(|v| !v.is_empty());
|
||||
+ match (build, version) {
|
||||
+ (Some(b), Some(v)) => Some(format!("{b} {v}")),
|
||||
+ (Some(b), None) => Some(b),
|
||||
+ (None, v) => v,
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
Subject: [PATCH 0006] antminer: route old models to the right backend + read the Z15 control board
|
||||
|
||||
Round-12 #10. Three fixes for stock Antminer Z15/Z15J (fw 2020), all verified
|
||||
live on 10.5.1.x:
|
||||
|
||||
1. Backend routing: the version detector only read summary.cgi, which older
|
||||
models (Z15) do not serve (404) -> version None -> AntMiner::new defaulted to
|
||||
the newest backend, which mis-parsed the miner (empty control board, no
|
||||
expected hashrate/wattage/fans). Fall back to the cgminer :4028 `version`
|
||||
RPC's CompileTime so the Z15 (2020) routes to the v2020 backend.
|
||||
|
||||
2. Control board "read, not guess": the Z15 has no miner_type.cgi, so its
|
||||
control-board subtype is unreadable there. Read the kernel build string from
|
||||
get_system_info.cgi instead ("Linux 4.6.0-xilinx-..." -> Xilinx); the
|
||||
ControlBoardVersion field now carries both the subtype and the kernel, and the
|
||||
parser prefers the subtype and falls back to the kernel marker.
|
||||
|
||||
3. Malformed cgminer stats: the Z15 emits a stats array whose objects are not
|
||||
comma-separated (`...}{"STATS":0...`), invalid JSON that serde rejected,
|
||||
dropping the whole stats command and every stats-derived field. Insert the
|
||||
missing separators before parsing (a no-op on well-formed responses); this
|
||||
restores expected hashrate, fans, hashboards and uptime. The expected
|
||||
hashrate also gets the same Equihash Sol/s reinterpretation as the realtime
|
||||
rate, so both read on one scale (e.g. 144k / 320k) instead of the expected
|
||||
reading ~1e6x larger.
|
||||
|
||||
diff --git a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
index 5b9f77b3..a02bdf9d 100644
|
||||
--- a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
+++ b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
@@ -434,14 +434,29 @@ impl GetDataLocations for AntMinerV2020 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
- DataField::ControlBoardVersion => vec![(
|
||||
- WEB_MINER_TYPE,
|
||||
- DataExtractor {
|
||||
- func: get_by_pointer,
|
||||
- key: Some("/subtype"),
|
||||
- tag: None,
|
||||
- },
|
||||
- )],
|
||||
+ // Prefer the explicit control-board subtype from miner_type.cgi, but
|
||||
+ // carry the kernel build string from get_system_info.cgi too: older
|
||||
+ // models (e.g. Z15/Z15J) have no miner_type.cgi, and their kernel
|
||||
+ // string ("...-xilinx-...") names the control board we can actually
|
||||
+ // read instead of guessing from the model (round 12 #10).
|
||||
+ DataField::ControlBoardVersion => vec![
|
||||
+ (
|
||||
+ WEB_MINER_TYPE,
|
||||
+ DataExtractor {
|
||||
+ func: get_by_pointer,
|
||||
+ key: Some("/subtype"),
|
||||
+ tag: Some("subtype"),
|
||||
+ },
|
||||
+ ),
|
||||
+ (
|
||||
+ WEB_SYSTEM_INFO,
|
||||
+ DataExtractor {
|
||||
+ func: get_by_pointer,
|
||||
+ key: Some("/system_kernel_version"),
|
||||
+ tag: Some("kernel"),
|
||||
+ },
|
||||
+ ),
|
||||
+ ],
|
||||
// cgminer names its summary keys after the unit they are in —
|
||||
// `GHS 5s` on SHA-256 models, `MHS 5s` on Scrypt ones — so keep
|
||||
// the whole entry and let the parse pick the key that is present.
|
||||
@@ -748,16 +763,33 @@ impl GetExpectedHashrate for AntMinerV2020 {
|
||||
let value = field?
|
||||
.pointer("/hashrate")
|
||||
.and_then(Self::parse_f64_field)?;
|
||||
+ // Equihash miners (Z15/Z15J) report `total_rateideal` as a Sol/s count in
|
||||
+ // the same (mislabelled) scale as the realtime "GHS" rate, so reinterpret
|
||||
+ // it as the base Hash unit -- matching parse_hashrate. Without this,
|
||||
+ // expected reads ~1e6x larger than realtime and the realtime figure looks
|
||||
+ // absent next to it (round 12 #10).
|
||||
+ let is_equihash = self.device_info.algo == HashAlgorithm::Equihash
|
||||
+ || self
|
||||
+ .device_info
|
||||
+ .model
|
||||
+ .to_string()
|
||||
+ .to_ascii_uppercase()
|
||||
+ .contains("Z15");
|
||||
+ let unit = if is_equihash {
|
||||
+ HashRateUnit::Hash
|
||||
+ } else {
|
||||
+ // `total_rateideal` does not name its own scale, so take it from
|
||||
+ // STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||
+ field
|
||||
+ .and_then(|v| v.pointer("/unit"))
|
||||
+ .and_then(|v| v.as_str())
|
||||
+ .and_then(|s| HashRateUnit::from_str(s).ok())
|
||||
+ .unwrap_or(HashRateUnit::GigaHash)
|
||||
+ };
|
||||
Some(
|
||||
HashRate {
|
||||
value,
|
||||
- // `total_rateideal` does not name its own scale, so take it
|
||||
- // from STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||
- unit: field
|
||||
- .and_then(|v| v.pointer("/unit"))
|
||||
- .and_then(|v| v.as_str())
|
||||
- .and_then(|s| HashRateUnit::from_str(s).ok())
|
||||
- .unwrap_or(HashRateUnit::GigaHash),
|
||||
+ unit,
|
||||
algo: self.device_info.algo,
|
||||
}
|
||||
.as_unit(HashRateUnit::default()),
|
||||
@@ -888,11 +920,34 @@ impl GetControlBoardVersion for AntMinerV2020 {
|
||||
&self,
|
||||
data: &HashMap<DataField, Value>,
|
||||
) -> Option<MinerControlBoard> {
|
||||
- let cb_type = data.extract::<String>(DataField::ControlBoardVersion)?;
|
||||
- match cb_type.as_str() {
|
||||
- s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||
- _ => AntMinerControlBoard::parse(cb_type.split("_").collect::<Vec<&str>>()[0])
|
||||
- .map(|cb| cb.into()),
|
||||
+ let field = data.get(&DataField::ControlBoardVersion)?;
|
||||
+ // Explicit control-board subtype (miner_type.cgi) wins when present.
|
||||
+ let subtype = field
|
||||
+ .pointer("/subtype")
|
||||
+ .and_then(|v| v.as_str())
|
||||
+ .unwrap_or("");
|
||||
+ if !subtype.is_empty() {
|
||||
+ return match subtype {
|
||||
+ s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||
+ _ => AntMinerControlBoard::parse(subtype.split('_').next().unwrap_or(subtype))
|
||||
+ .map(|cb| cb.into()),
|
||||
+ };
|
||||
+ }
|
||||
+ // No subtype (older models): read the control board from the kernel build
|
||||
+ // string instead of guessing from the model (round 12 #10). Bitmain names
|
||||
+ // the SoC in the kernel version, e.g. "Linux 4.6.0-xilinx-..." (Z15) or an
|
||||
+ // AMLogic/Meson kernel on newer AMLogic boards.
|
||||
+ let kernel = field
|
||||
+ .pointer("/kernel")
|
||||
+ .and_then(|v| v.as_str())
|
||||
+ .unwrap_or("")
|
||||
+ .to_ascii_lowercase();
|
||||
+ if kernel.contains("xilinx") || kernel.contains("zynq") {
|
||||
+ Some(AntMinerControlBoard::Xilinx.into())
|
||||
+ } else if kernel.contains("aml") || kernel.contains("meson") {
|
||||
+ Some(AntMinerControlBoard::AMLogic.into())
|
||||
+ } else {
|
||||
+ None
|
||||
}
|
||||
}
|
||||
}
|
||||
diff --git a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||
index 23962f35..52232c1f 100644
|
||||
--- a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||
+++ b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/rpc.rs
|
||||
@@ -71,7 +71,17 @@ impl AntMinerRPCAPI {
|
||||
read_stream_response(&mut stream, DEFAULT_RPC_TIMEOUT).await
|
||||
};
|
||||
let response = response?;
|
||||
- self.parse_rpc_result(&response)
|
||||
+ self.parse_rpc_result(&Self::sanitize_cgminer(&response))
|
||||
+ }
|
||||
+
|
||||
+ /// Antminer's cgminer `stats` sometimes emits an array whose objects are not
|
||||
+ /// comma-separated (`...}{"STATS":0,...` on the Z15/Z15J), which is invalid
|
||||
+ /// JSON that serde rejects -- dropping the whole stats command and with it
|
||||
+ /// every stats-derived field (expected hashrate, wattage, fans, hashboards,
|
||||
+ /// uptime). Insert the missing separators. Well-formed JSON never contains an
|
||||
+ /// unseparated `}{`, so this is a no-op on valid responses (round 12 #10).
|
||||
+ fn sanitize_cgminer(response: &str) -> String {
|
||||
+ response.replace("}{", "},{")
|
||||
}
|
||||
|
||||
fn parse_rpc_result(&self, response: &str) -> anyhow::Result<Value> {
|
||||
diff --git a/vendor/asic-rs-firmwares-antminer/src/firmware.rs b/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||
index fce5e8ff..46abbc9d 100644
|
||||
--- a/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||
+++ b/vendor/asic-rs-firmwares-antminer/src/firmware.rs
|
||||
@@ -142,18 +142,9 @@ async fn get_model_with_auth(
|
||||
}
|
||||
}
|
||||
|
||||
-/// Fetch the firmware version from a miner using digest auth.
|
||||
-async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||
- let client = build_discovery_client().ok()?;
|
||||
- let data: Response = client
|
||||
- .get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||
- .send_digest_auth((auth.username(), auth.password()))
|
||||
- .await
|
||||
- .ok()?;
|
||||
-
|
||||
- let json_data = data.json::<serde_json::Value>().await.ok()?;
|
||||
- let fw_version = json_data["INFO"]["CompileTime"].as_str().unwrap_or("");
|
||||
-
|
||||
+/// Parse an Antminer cgminer `CompileTime` string ("Mon Dec 14 18:01:42 CST
|
||||
+/// 2020") into a date-based semver (year.month.day) used to pick the backend.
|
||||
+fn parse_antminer_compile_time(fw_version: &str) -> Option<semver::Version> {
|
||||
let cleaned: String = {
|
||||
let mut parts: Vec<&str> = fw_version.split_whitespace().collect();
|
||||
if parts.len() > 4 {
|
||||
@@ -161,9 +152,7 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||
}
|
||||
parts.join(" ")
|
||||
};
|
||||
-
|
||||
let dt = NaiveDateTime::parse_from_str(&cleaned, "%a %b %e %H:%M:%S %Y").ok()?;
|
||||
-
|
||||
Some(semver::Version::new(
|
||||
dt.year() as u64,
|
||||
dt.month() as u64,
|
||||
@@ -171,6 +160,34 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||
))
|
||||
}
|
||||
|
||||
+/// Fetch the firmware version (as a date-based semver) to pick the backend.
|
||||
+async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||
+ // Newer Antminers expose the firmware CompileTime via summary.cgi.
|
||||
+ if let Ok(client) = build_discovery_client()
|
||||
+ && let Ok(data) = client
|
||||
+ .get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||
+ .send_digest_auth((auth.username(), auth.password()))
|
||||
+ .await
|
||||
+ && let Ok(json_data) = data.json::<serde_json::Value>().await
|
||||
+ && let Some(v) =
|
||||
+ parse_antminer_compile_time(json_data["INFO"]["CompileTime"].as_str().unwrap_or(""))
|
||||
+ {
|
||||
+ return Some(v);
|
||||
+ }
|
||||
+
|
||||
+ // Older models (e.g. Z15/Z15J) have no summary.cgi, so summary-based version
|
||||
+ // detection returns nothing and the miner would default to the newest
|
||||
+ // backend and be mis-parsed. Fall back to the cgminer :4028 `version` RPC,
|
||||
+ // which still reports the CompileTime, so the right (older) backend is picked
|
||||
+ // (round 12 #10).
|
||||
+ let rpc = asic_rs_core::util::send_rpc_command(&ip, "version").await?;
|
||||
+ parse_antminer_compile_time(
|
||||
+ rpc.pointer("/VERSION/0/CompileTime")
|
||||
+ .and_then(|v| v.as_str())
|
||||
+ .unwrap_or(""),
|
||||
+ )
|
||||
+}
|
||||
+
|
||||
#[async_trait]
|
||||
impl MinerFirmware for AntMinerStockFirmware {
|
||||
/// Uses default credentials. For custom credentials, use `build_miner`
|
||||
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,745 @@
|
||||
@@ -0,0 +1,814 @@
|
||||
+// widgets.rs — alkane-toolkit extension: Rust bindings for the widget bridge
|
||||
+// in cpp_src/widgets_bridge.cpp. Handles are opaque pointers owned by the
|
||||
+// wxWidgets object tree (parents own children; nothing to free in Rust).
|
||||
@@ -36,6 +36,8 @@
|
||||
+ pub fn wxbr_set_sizer(win: *mut c_void, sizer: *mut c_void);
|
||||
+ pub fn wxbr_layout(win: *mut c_void);
|
||||
+ pub fn wxbr_sizer_detach(sizer: *mut c_void, win: *mut c_void);
|
||||
+ pub fn wxbr_sizer_show(sizer: *mut c_void, win: *mut c_void, show: c_int);
|
||||
+ pub fn wxbr_bind_size(win: *mut c_void);
|
||||
+ pub fn wxbr_fit(win: *mut c_void);
|
||||
+ pub fn wxbr_set_min_size(win: *mut c_void, w: c_int, h: c_int);
|
||||
+ pub fn wxbr_static_text(parent: *mut c_void, label: *const c_char) -> *mut c_void;
|
||||
@@ -90,6 +92,8 @@
|
||||
+ pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
+ pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
+ pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_reorder_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
+ pub fn wxbr_reorder_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
+ pub fn wxbr_menu_new() -> *mut c_void;
|
||||
+ pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
+ pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
@@ -112,6 +116,9 @@
|
||||
+ pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int;
|
||||
+ pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
|
||||
+ pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void;
|
||||
+ pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int);
|
||||
+ pub fn wxbr_set_light_pulse(on: c_int);
|
||||
+ pub fn wxbr_bind_sys_colour(win: *mut c_void);
|
||||
+ pub fn wxbr_destroy(win: *mut c_void);
|
||||
+ pub fn wxbr_destroy_children(win: *mut c_void);
|
||||
@@ -154,6 +161,8 @@
|
||||
+ SysColour,
|
||||
+ Deferred,
|
||||
+ DvlcHeaderRightClick,
|
||||
+ /// Window resized; p1 = new client width, p2 = new client height.
|
||||
+ Sized,
|
||||
+}
|
||||
+
|
||||
+impl WxEventKind {
|
||||
@@ -173,6 +182,7 @@
|
||||
+ 13 => WxEventKind::SysColour,
|
||||
+ 14 => WxEventKind::Deferred,
|
||||
+ 15 => WxEventKind::DvlcHeaderRightClick,
|
||||
+ 16 => WxEventKind::Sized,
|
||||
+ _ => return None,
|
||||
+ })
|
||||
+ }
|
||||
@@ -205,6 +215,24 @@
|
||||
+ unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) }
|
||||
+}
|
||||
+
|
||||
+/// Register a raw SVG for a table-cell shape sentinel (a control-char code point)
|
||||
+/// so the segment renderer can draw it recoloured to each cell's segment colour.
|
||||
+/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect
|
||||
+/// ratio when it is rasterised at the cell height (round 12 #9/#11).
|
||||
+pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) {
|
||||
+ let c = CString::new(svg).unwrap_or_default();
|
||||
+ unsafe {
|
||||
+ notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh as c_int)
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+/// Start (or stop) the locate-light dot fade animation. Call with `true` while at
|
||||
+/// least one miner's locate light is flashing so the table repaint timer only
|
||||
+/// runs when there is a pulsing dot to animate (round 12 #6).
|
||||
+pub fn set_light_pulse(on: bool) {
|
||||
+ unsafe { notsafe::wxbr_set_light_pulse(on as c_int) }
|
||||
+}
|
||||
+
|
||||
+/// Open a URL in the system default browser. Returns true on success.
|
||||
+pub fn launch_browser(url: &str) -> bool {
|
||||
+ let c = CString::new(url).unwrap_or_default();
|
||||
@@ -321,6 +349,18 @@
|
||||
+ unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
|
||||
+ }
|
||||
+
|
||||
+ /// Show or hide a child window in this sizer (self = a sizer), reclaiming or
|
||||
+ /// restoring its space on the next `layout()`.
|
||||
+ pub fn sizer_show(&self, win: Widget, show: bool) {
|
||||
+ unsafe { notsafe::wxbr_sizer_show(self.0, win.0, show as c_int) }
|
||||
+ }
|
||||
+
|
||||
+ /// Emit `WxEventKind::Sized` (p1 = width, p2 = height) whenever this window
|
||||
+ /// is resized.
|
||||
+ pub fn bind_size(&self) {
|
||||
+ unsafe { notsafe::wxbr_bind_size(self.0) }
|
||||
+ }
|
||||
+
|
||||
+ pub fn fit(&self, win: Widget) {
|
||||
+ unsafe { notsafe::wxbr_fit(win.0) }
|
||||
+ }
|
||||
@@ -626,6 +666,27 @@
|
||||
+ buf.into_iter().take(n.max(0) as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ /// A checkable, multi-select, drag-reorderable column list (round 11 #4):
|
||||
+ /// like `rearrange_list` but with no up/down buttons -- rows are reordered by
|
||||
+ /// dragging, and selected with shift/ctrl-click or a rubber-band drag. Same
|
||||
+ /// `[idx | !idx]` order encoding.
|
||||
+ pub fn reorder_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
+ let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
+ let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
+ Widget(unsafe {
|
||||
+ notsafe::wxbr_reorder_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
+ /// Read back the current order from a `reorder_list` (same encoding).
|
||||
+ pub fn reorder_get_order(&self) -> Vec<i32> {
|
||||
+ let mut buf = vec![0i32; 4096];
|
||||
+ let n = unsafe {
|
||||
+ notsafe::wxbr_reorder_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
+ };
|
||||
+ buf.into_iter().take(n.max(0) as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ // ---- popup menu ----
|
||||
+
|
||||
+ pub fn menu_new() -> Widget {
|
||||
@@ -740,6 +801,14 @@
|
||||
+ })
|
||||
+ }
|
||||
+
|
||||
+ /// Render an SVG string (recolour it first -- its fill must be an explicit
|
||||
+ /// colour, not "currentColor") into a static-bitmap icon at `w`x`h` px
|
||||
+ /// (round 11 #15).
|
||||
+ pub fn svg_icon(parent: Widget, svg: &str, w: i32, h: i32) -> Widget {
|
||||
+ let c = CString::new(svg).unwrap_or_default();
|
||||
+ Widget(unsafe { notsafe::wxbr_svg_icon(parent.0, c.as_ptr(), w as c_int, h as c_int) })
|
||||
+ }
|
||||
+
|
||||
+ /// Listen for OS light/dark theme changes on this window (emits `SysColour`).
|
||||
+ pub fn bind_sys_colour(&self) {
|
||||
+ unsafe { notsafe::wxbr_bind_sys_colour(self.0) }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,1133 @@
|
||||
@@ -0,0 +1,1622 @@
|
||||
+// widgets_bridge.cpp — alkane-toolkit extension to wx-rs
|
||||
+// Adds the widget/event surface the toolkit UI needs on top of the upstream
|
||||
+// render-callback bridge (which is kept untouched).
|
||||
@@ -22,10 +22,12 @@
|
||||
+#include <wx/utils.h>
|
||||
+#include <wx/app.h>
|
||||
+#include <wx/rearrangectrl.h>
|
||||
+#include <wx/listctrl.h>
|
||||
+#include <wx/menu.h>
|
||||
+#include <wx/choice.h>
|
||||
+#include <wx/bmpbuttn.h>
|
||||
+#include <wx/bitmap.h>
|
||||
+#include <wx/bmpbndl.h>
|
||||
+#include <wx/image.h>
|
||||
+#include <wx/dcmemory.h>
|
||||
+#include <wx/dcgraph.h>
|
||||
@@ -35,6 +37,7 @@
|
||||
+#include <wx/statusbr.h>
|
||||
+#include <cstring>
|
||||
+#include <cstdio>
|
||||
+#include <cmath>
|
||||
+#include <map>
|
||||
+#include <vector>
|
||||
+#ifdef __WXGTK__
|
||||
@@ -69,6 +72,7 @@
|
||||
+ WxEV_SYS_COLOUR = 13,
|
||||
+ WxEV_DEFERRED = 14,
|
||||
+ WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||
+ WxEV_SIZE = 16, // p1 = new client width, p2 = new client height
|
||||
+};
|
||||
+
|
||||
+// A list store that carries an optional per-row foreground colour plus an
|
||||
@@ -149,6 +153,185 @@
|
||||
+ return segs;
|
||||
+}
|
||||
+
|
||||
+// Shape sentinels a segment's text may carry instead of glyphs (round 11
|
||||
+// #10/#13): a single control char selects a small vector icon drawn in the
|
||||
+// segment's colour. These are control characters (never emoji/pictographs) so
|
||||
+// they are safe in source and independent of the font's glyph coverage.
|
||||
+const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light)
|
||||
+const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only)
|
||||
+const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable)
|
||||
+// Status-column KPI icons (round 12 #11): each renders the same Font Awesome
|
||||
+// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side
|
||||
+// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell
|
||||
+// is simply blank.
|
||||
+const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing)
|
||||
+const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow)
|
||||
+const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing)
|
||||
+const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused)
|
||||
+const wxUniChar SHAPE_PULSE_DOT = 0x0B; // locate-light dot that fades in/out (round 12 #6)
|
||||
+const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
|
||||
+
|
||||
+// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a
|
||||
+// wxTimer while any such dot is on screen; the treeview it repaints is tracked so
|
||||
+// the timer can invalidate exactly it.
|
||||
+double g_pulse_phase = 0.0;
|
||||
+wxDataViewCtrl* g_pulse_target = nullptr;
|
||||
+
|
||||
+bool IsShapeSentinel(const wxString& s, wxUniChar& out) {
|
||||
+ if (s.length() != 1) return false;
|
||||
+ wxUniChar c = s[0];
|
||||
+ if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK ||
|
||||
+ c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING ||
|
||||
+ c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT) {
|
||||
+ out = c;
|
||||
+ return true;
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
+// Blend `fg` toward `bg` by alpha (1.0 = fully fg), used to fade the locate dot.
|
||||
+wxColour BlendColour(const wxColour& bg, const wxColour& fg, double a) {
|
||||
+ auto mix = [a](unsigned char b, unsigned char f) {
|
||||
+ double v = (double)b * (1.0 - a) + (double)f * a + 0.5;
|
||||
+ if (v < 0) v = 0;
|
||||
+ if (v > 255) v = 255;
|
||||
+ return (unsigned char)v;
|
||||
+ };
|
||||
+ return wxColour(mix(bg.Red(), fg.Red()), mix(bg.Green(), fg.Green()), mix(bg.Blue(), fg.Blue()));
|
||||
+}
|
||||
+
|
||||
+// Drives the locate-light dot's fade (round 12 #6): while running it advances the
|
||||
+// phase and repaints the treeview so the SHAPE_PULSE_DOT cells re-render at the
|
||||
+// new opacity. Runs only while at least one locate light is flashing.
|
||||
+class PulseTimer : public wxTimer {
|
||||
+ public:
|
||||
+ void Notify() override {
|
||||
+ g_pulse_phase += 0.4; // ~1.6 s cycle at the 100 ms tick below
|
||||
+ if (!g_pulse_target) return;
|
||||
+ // A plain Refresh() does not re-invoke the custom cell renderer under wxGTK
|
||||
+ // (GtkTreeView caches rendered cells); emitting a row change does, so the
|
||||
+ // SHAPE_PULSE_DOT cells re-render at the new phase. The timer only runs while
|
||||
+ // a light is flashing, so touching every row here is cheap.
|
||||
+ AttrListStore* store = dynamic_cast<AttrListStore*>(g_pulse_target->GetModel());
|
||||
+ if (store) {
|
||||
+ unsigned int n = store->GetItemCount();
|
||||
+ for (unsigned int r = 0; r < n; r++) store->RowChanged(r);
|
||||
+ } else {
|
||||
+ g_pulse_target->Refresh();
|
||||
+ }
|
||||
+ }
|
||||
+};
|
||||
+PulseTimer* g_pulse_timer = nullptr;
|
||||
+
|
||||
+void SetLightPulse(bool on) {
|
||||
+ if (!g_pulse_timer) g_pulse_timer = new PulseTimer();
|
||||
+ if (on) {
|
||||
+ if (!g_pulse_timer->IsRunning()) g_pulse_timer->Start(100);
|
||||
+ } else {
|
||||
+ g_pulse_timer->Stop();
|
||||
+ if (g_pulse_target) g_pulse_target->Refresh();
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status
|
||||
+// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect)
|
||||
+// per sentinel; DrawShape recolours it to the segment colour, rasterises once
|
||||
+// per (sentinel, colour, height), caches the bitmap, and draws it. The access
|
||||
+// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered.
|
||||
+struct ShapeSvg {
|
||||
+ wxString svg;
|
||||
+ int vbw;
|
||||
+ int vbh;
|
||||
+};
|
||||
+std::map<int, ShapeSvg> g_shape_svgs;
|
||||
+std::map<uint64_t, wxBitmap> g_shape_bmp_cache;
|
||||
+
|
||||
+const ShapeSvg* LookupShapeSvg(wxUniChar shape) {
|
||||
+ auto it = g_shape_svgs.find((int)shape.GetValue());
|
||||
+ return it == g_shape_svgs.end() ? nullptr : &it->second;
|
||||
+}
|
||||
+
|
||||
+// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace
|
||||
+// fill="currentColor" and inject a root fill so shapes that omit a fill inherit
|
||||
+// the colour too (e.g. the Font Awesome Free otter).
|
||||
+wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) {
|
||||
+ wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue());
|
||||
+ wxString s = svg;
|
||||
+ s.Replace("currentColor", hex);
|
||||
+ int pos = s.Find("<svg ");
|
||||
+ if (pos != wxNOT_FOUND) s.insert((size_t)pos + 5, wxString("fill=\"") + hex + "\" ");
|
||||
+ return s;
|
||||
+}
|
||||
+
|
||||
+const wxBitmap& ShapeBitmap(wxUniChar shape, const ShapeSvg& sv, const wxColour& col,
|
||||
+ int w, int h) {
|
||||
+ uint64_t rgb = ((uint64_t)col.Red() << 16) | ((uint64_t)col.Green() << 8) | (uint64_t)col.Blue();
|
||||
+ uint64_t key = ((uint64_t)(unsigned)shape.GetValue() << 40) | (rgb << 8) | (uint64_t)(h & 0xFF);
|
||||
+ auto it = g_shape_bmp_cache.find(key);
|
||||
+ if (it != g_shape_bmp_cache.end()) return it->second;
|
||||
+ wxString colored = RecolorShapeSvg(sv.svg, col);
|
||||
+ wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h));
|
||||
+ wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
|
||||
+ return g_shape_bmp_cache.emplace(key, bmp).first->second;
|
||||
+}
|
||||
+
|
||||
+// Draw one shape sentinel centred at x; returns the horizontal space it used
|
||||
+// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon).
|
||||
+// `bg` is the cell background the shape sits on, used to fade the pulsing dot.
|
||||
+int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell,
|
||||
+ const wxColour& colour, const wxColour& bg) {
|
||||
+ int cy = cell.y + cell.height / 2;
|
||||
+ // SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the
|
||||
+ // segment colour, rasterise (cached), and draw centred in its slot.
|
||||
+ if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
|
||||
+ int h = cell.height - 4;
|
||||
+ if (h > 15) h = 15;
|
||||
+ if (h < 8) h = 8;
|
||||
+ int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h;
|
||||
+ if (w < 1) w = 1;
|
||||
+ const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h);
|
||||
+ if (bmp.IsOk()) {
|
||||
+ int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE;
|
||||
+ dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true);
|
||||
+ return slot;
|
||||
+ }
|
||||
+ }
|
||||
+ int cx = x + SHAPE_ADVANCE / 2;
|
||||
+ if (shape == SHAPE_DOT || shape == SHAPE_PULSE_DOT) {
|
||||
+ wxColour fill = colour;
|
||||
+ if (shape == SHAPE_PULSE_DOT) {
|
||||
+ // Fade between ~0.3 and 1.0 opacity over a ~1.6 s cycle (round 12 #6).
|
||||
+ double a = 0.3 + 0.7 * (0.5 + 0.5 * std::sin(g_pulse_phase));
|
||||
+ fill = BlendColour(bg, colour, a);
|
||||
+ }
|
||||
+ dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
+ dc->SetBrush(wxBrush(fill));
|
||||
+ dc->DrawCircle(cx, cy, 4);
|
||||
+ return SHAPE_ADVANCE;
|
||||
+ }
|
||||
+ // Padlock: a filled body with a staple shackle above. The colour carries the
|
||||
+ // state (green = unlocked, red = locked); the shackle is drawn ajar when open.
|
||||
+ bool open = (shape == SHAPE_UNLOCK);
|
||||
+ int bw = 9, bh = 7;
|
||||
+ int bx = cx - bw / 2;
|
||||
+ int by = cy - bh / 2 + 1;
|
||||
+ dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
+ dc->SetBrush(wxBrush(colour));
|
||||
+ dc->DrawRoundedRectangle(bx, by, bw, bh, 1.5);
|
||||
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
+ dc->SetPen(wxPen(colour, 2));
|
||||
+ int sr = 3;
|
||||
+ int legTop = by - sr - 1;
|
||||
+ int lx = cx - sr, rx = cx + sr;
|
||||
+ dc->DrawLine(lx, by, lx, legTop); // left leg
|
||||
+ dc->DrawLine(lx, legTop, rx, legTop); // top bar
|
||||
+ if (open)
|
||||
+ dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted
|
||||
+ else
|
||||
+ dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body
|
||||
+ return SHAPE_ADVANCE;
|
||||
+}
|
||||
+
|
||||
+} // namespace
|
||||
+
|
||||
+class SegmentRenderer : public wxDataViewCustomRenderer {
|
||||
@@ -168,12 +351,71 @@
|
||||
+
|
||||
+ bool Render(wxRect cell, wxDC* dc, int state) override {
|
||||
+ bool selected = (state & wxDATAVIEW_CELL_SELECTED) != 0;
|
||||
+ // wxGTK does NOT paint a custom renderer's cell background, so the per-row
|
||||
+ // (zebra) background set via GetAttrByRow shows on the native columns but
|
||||
+ // not here -- the zebra looked inconsistent across columns. Paint it here so
|
||||
+ // every column stripes the same (skip when the row is selected: the control
|
||||
+ // already drew the selection highlight).
|
||||
+ if (!selected && GetAttr().HasBackgroundColour()) {
|
||||
+ dc->SetBrush(wxBrush(GetAttr().GetBackgroundColour()));
|
||||
+ dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
+ // The `cell` rect wx hands a custom renderer is shrunk to the content
|
||||
+ // (text/shape) size in BOTH dimensions by the alignment logic, so filling
|
||||
+ // it alone left the zebra covering only a content-sized band -- and since
|
||||
+ // shape cells (dots) and text cells have different content heights, the
|
||||
+ // stripes ended up unequal across columns. Fill an over-sized rect (full
|
||||
+ // column width, and well beyond the row vertically); wxGTK clips the cell
|
||||
+ // DC to the real cell background area, so this lands exactly on the full
|
||||
+ // row height of this cell without bleeding into neighbours (round 11 #1/#3).
|
||||
+ wxRect bg = cell;
|
||||
+ if (wxDataViewColumn* owner = const_cast<SegmentRenderer*>(this)->GetOwner()) {
|
||||
+ int cw = owner->GetWidth();
|
||||
+ if (cw > bg.width) bg.width = cw;
|
||||
+ }
|
||||
+ bg.y -= 40;
|
||||
+ bg.height += 80;
|
||||
+ dc->DrawRectangle(bg);
|
||||
+ }
|
||||
+ wxColour highlight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
|
||||
+ wxColour plain = GetAttr().HasColour()
|
||||
+ ? GetAttr().GetColour()
|
||||
+ : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
+ // An uncoloured (default) segment -- the "/" in a combined cell, a "Stock"
|
||||
+ // firmware family, etc. -- must dim exactly like the native columns when the
|
||||
+ // top-level window is backdropped. wxGTK dims a native cell's text via the
|
||||
+ // widget's themed state colour, but a custom renderer's DC keeps the normal
|
||||
+ // WINDOWTEXT, so ask the tree widget for its themed text colour AT ITS
|
||||
+ // CURRENT STATE (which carries GTK_STATE_FLAG_BACKDROP while unfocused) and
|
||||
+ // use that; off-GTK (or if the widget isn't reachable) fall back to the DC
|
||||
+ // then the system colour (round 11 #1/#7).
|
||||
+ wxColour plain;
|
||||
+ if (GetAttr().HasColour()) {
|
||||
+ plain = GetAttr().GetColour();
|
||||
+ } else {
|
||||
+ plain = ThemedTextColour();
|
||||
+ }
|
||||
+ if (!plain.IsOk()) {
|
||||
+ plain = dc->GetTextForeground();
|
||||
+ }
|
||||
+ if (!plain.IsOk()) {
|
||||
+ plain = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
+ }
|
||||
+ wxCoord x = cell.x;
|
||||
+ for (const ColorSegment& seg : ParseColorSegments(m_value)) {
|
||||
+ // Shape segments (status dots, access padlock) keep their own semantic
|
||||
+ // colour even on a selected row, so the green/red reading survives the
|
||||
+ // selection highlight (round 11 #10/#13).
|
||||
+ wxUniChar shape;
|
||||
+ if (IsShapeSentinel(seg.text, shape)) {
|
||||
+ // Background the shape sits on, so the pulsing locate dot fades toward it.
|
||||
+ wxColour cellbg;
|
||||
+ if (selected) {
|
||||
+ cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
|
||||
+ } else if (GetAttr().HasBackgroundColour()) {
|
||||
+ cellbg = GetAttr().GetBackgroundColour();
|
||||
+ } else {
|
||||
+ cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
+ }
|
||||
+ x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain, cellbg);
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (seg.text.IsEmpty()) continue;
|
||||
+ dc->SetTextForeground(selected ? highlight : (seg.has_colour ? seg.colour : plain));
|
||||
+ wxSize extent = dc->GetTextExtent(seg.text);
|
||||
@@ -185,14 +427,66 @@
|
||||
+ }
|
||||
+
|
||||
+ wxSize GetSize() const override {
|
||||
+ wxString plain;
|
||||
+ for (const ColorSegment& seg : ParseColorSegments(m_value)) plain += seg.text;
|
||||
+ wxSize sz = GetTextExtent(plain);
|
||||
+ if (sz.GetWidth() < 1) sz.SetWidth(1);
|
||||
+ return sz;
|
||||
+ int w = 0, h = 0;
|
||||
+ for (const ColorSegment& seg : ParseColorSegments(m_value)) {
|
||||
+ wxUniChar shape;
|
||||
+ if (IsShapeSentinel(seg.text, shape)) {
|
||||
+ int adv = SHAPE_ADVANCE;
|
||||
+ if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
|
||||
+ int hh = 15;
|
||||
+ int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh;
|
||||
+ if (ww > adv) adv = ww;
|
||||
+ }
|
||||
+ w += adv;
|
||||
+ if (h < 12) h = 12;
|
||||
+ continue;
|
||||
+ }
|
||||
+ wxSize e = GetTextExtent(seg.text);
|
||||
+ w += e.GetWidth();
|
||||
+ if (e.GetHeight() > h) h = e.GetHeight();
|
||||
+ }
|
||||
+ if (w < 1) w = 1;
|
||||
+ if (h < 1) h = 1;
|
||||
+ return wxSize(w, h);
|
||||
+ }
|
||||
+
|
||||
+ private:
|
||||
+ // The owning tree widget's themed text colour at its current GTK state, so
|
||||
+ // uncoloured segments dim on window-backdrop like the native columns
|
||||
+ // (round 11 #1/#7). Returns an invalid colour off wxGTK or when the widget is
|
||||
+ // unreachable, so the caller falls back to the DC / system colour.
|
||||
+ wxColour ThemedTextColour() const {
|
||||
+#ifdef __WXGTK__
|
||||
+ wxDataViewColumn* col = const_cast<SegmentRenderer*>(this)->GetOwner();
|
||||
+ if (col && col->GetOwner()) {
|
||||
+ GtkWidget* tv = col->GetOwner()->GtkGetTreeView();
|
||||
+ if (tv && GTK_IS_WIDGET(tv)) {
|
||||
+ // The treeview's own state flags do NOT reliably carry
|
||||
+ // GTK_STATE_FLAG_BACKDROP (that lives on the toplevel), so query the
|
||||
+ // toplevel window's active state directly and force BACKDROP onto the
|
||||
+ // style-context state when it is inactive. Then the themed cell text
|
||||
+ // colour matches what GTK paints on the native columns when the window
|
||||
+ // loses focus (round 11 #1/#7).
|
||||
+ GtkWidget* top = gtk_widget_get_toplevel(tv);
|
||||
+ bool active = GTK_IS_WINDOW(top) && gtk_window_is_active(GTK_WINDOW(top));
|
||||
+ GtkStyleContext* ctx = gtk_widget_get_style_context(tv);
|
||||
+ GtkStateFlags st = gtk_widget_get_state_flags(tv);
|
||||
+ st = active ? (GtkStateFlags)(st & ~GTK_STATE_FLAG_BACKDROP)
|
||||
+ : (GtkStateFlags)(st | GTK_STATE_FLAG_BACKDROP);
|
||||
+ GdkRGBA c;
|
||||
+ gtk_style_context_save(ctx);
|
||||
+ gtk_style_context_set_state(ctx, st);
|
||||
+ gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &c);
|
||||
+ gtk_style_context_restore(ctx);
|
||||
+ return wxColour((unsigned char)(c.red * 255.0 + 0.5),
|
||||
+ (unsigned char)(c.green * 255.0 + 0.5),
|
||||
+ (unsigned char)(c.blue * 255.0 + 0.5));
|
||||
+ }
|
||||
+ }
|
||||
+#endif
|
||||
+ return wxColour();
|
||||
+ }
|
||||
+
|
||||
+ wxString m_value;
|
||||
+};
|
||||
+
|
||||
@@ -274,6 +568,23 @@
|
||||
+ ((wxSizer*)sizer)->Detach((wxWindow*)win);
|
||||
+}
|
||||
+
|
||||
+// Show or hide a sizer-managed child window AND reclaim (or restore) its space
|
||||
+// on the next Layout(). Used to collapse the wide KPI cards when the window is
|
||||
+// too narrow (round 11 #2).
|
||||
+void wxbr_sizer_show(void* sizer, void* win, int show) {
|
||||
+ ((wxSizer*)sizer)->Show((wxWindow*)win, show != 0);
|
||||
+}
|
||||
+
|
||||
+// Emit WxEV_SIZE (p1 = new client width, p2 = height) whenever this window is
|
||||
+// resized. e.Skip() keeps the normal sizer layout running (round 11 #2).
|
||||
+void wxbr_bind_size(void* win) {
|
||||
+ ((wxWindow*)win)->Bind(wxEVT_SIZE, [](wxSizeEvent& e) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_SIZE, (long)e.GetSize().GetWidth(),
|
||||
+ (long)e.GetSize().GetHeight());
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+}
|
||||
+
|
||||
+void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
|
||||
+
|
||||
+void wxbr_set_min_size(void* win, int w, int h) {
|
||||
@@ -384,12 +695,31 @@
|
||||
+// ---- check list box ---------------------------------------------------------
|
||||
+
|
||||
+void* wxbr_check_list_box(void* parent) {
|
||||
+ // wxLB_EXTENDED so several rows can be selected at once (ctrl/shift-click and
|
||||
+ // rubber-band drag, native to wxListBox); a checkbox toggle on any selected
|
||||
+ // row then applies to every selected row (see the handler below). This is the
|
||||
+ // Excel-style batch-check the filter menu needs (round 12 #7).
|
||||
+ wxCheckListBox* clb = new wxCheckListBox((wxWindow*)parent, wxID_ANY,
|
||||
+ wxDefaultPosition, wxSize(-1, -1),
|
||||
+ 0, NULL, wxLB_SINGLE | wxLB_NEEDED_SB);
|
||||
+ 0, NULL, wxLB_EXTENDED | wxLB_NEEDED_SB);
|
||||
+ clb->Bind(wxEVT_CHECKLISTBOX, [clb](wxCommandEvent& e) {
|
||||
+ int idx = e.GetInt();
|
||||
+ // Batch toggle: if the clicked row is part of a multi-row selection, give
|
||||
+ // every selected row the clicked row's new state. Check() does not itself
|
||||
+ // fire wxEVT_CHECKLISTBOX, so there is no recursion.
|
||||
+ wxArrayInt sel;
|
||||
+ clb->GetSelections(sel);
|
||||
+ if (sel.GetCount() > 1) {
|
||||
+ bool inSel = false;
|
||||
+ for (size_t i = 0; i < sel.GetCount(); i++)
|
||||
+ if (sel[i] == idx) { inSel = true; break; }
|
||||
+ if (inSel) {
|
||||
+ bool state = clb->IsChecked(idx);
|
||||
+ for (size_t i = 0; i < sel.GetCount(); i++) clb->Check(sel[i], state);
|
||||
+ }
|
||||
+ }
|
||||
+ if (g_widget_event)
|
||||
+ g_widget_event(WxEV_CLB_TOGGLED, (long)(intptr_t)clb, e.GetInt());
|
||||
+ g_widget_event(WxEV_CLB_TOGGLED, (long)(intptr_t)clb, idx);
|
||||
+ });
|
||||
+ return (void*)clb;
|
||||
+}
|
||||
@@ -507,6 +837,7 @@
|
||||
+ AttrListStore* store = new AttrListStore();
|
||||
+ dv->AssociateModel(store);
|
||||
+ store->DecRef(); // the control owns a reference now
|
||||
+ g_pulse_target = dv; // the locate-dot pulse timer repaints this control
|
||||
+ dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
|
||||
+ if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
+ });
|
||||
@@ -962,6 +1293,137 @@
|
||||
+ return n < cap ? n : cap;
|
||||
+}
|
||||
+
|
||||
+// ---- reorder list: a checkable, multi-select, drag-reorderable column list
|
||||
+// for the Columns dialog (round 11 #4). Replaces wxRearrangeCtrl (which had
|
||||
+// up/down buttons and no drag / multi-select). It is a single-column headerless
|
||||
+// wxListCtrl with native checkboxes; rows carry their base model index as item
|
||||
+// data, and the check state + row order encode the same [idx | ~idx] contract
|
||||
+// as wxbr_rearrange_get_order. Selection (shift/ctrl-click, rubber-band drag) is
|
||||
+// native to wxListCtrl. Drag-reorder: on begin-drag we record the selected rows'
|
||||
+// base indices, and on the following mouse-up we move that group to the row
|
||||
+// under the cursor (we never start a real DnD loop, so the mouse-up still
|
||||
+// arrives).
|
||||
+static wxVector<long> g_reorder_drag;
|
||||
+static wxListCtrl* g_reorder_list = nullptr;
|
||||
+
|
||||
+void* wxbr_reorder_list(void* parent, int n, const int* order, const char** items) {
|
||||
+ wxListCtrl* lc = new wxListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
+ wxSize(-1, 240), wxLC_REPORT | wxLC_NO_HEADER);
|
||||
+ lc->EnableCheckBoxes(true);
|
||||
+ lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 260);
|
||||
+ for (int i = 0; i < n; i++) {
|
||||
+ int enc = order[i];
|
||||
+ int idx = enc < 0 ? ~enc : enc;
|
||||
+ long row = lc->InsertItem(i, wxString::FromUTF8(items[idx]));
|
||||
+ lc->SetItemData(row, (long)idx);
|
||||
+ lc->CheckItem(row, enc >= 0);
|
||||
+ }
|
||||
+ // Batch checkbox toggle: checking/unchecking a row that is part of a
|
||||
+ // multi-row selection applies the same state to every selected row, so the
|
||||
+ // user can ctrl/shift-click several columns and show/hide them together
|
||||
+ // (round 12 #7). CheckItem() re-enters this handler, so guard against it.
|
||||
+ auto batchCheck = [lc](long item, bool state) {
|
||||
+ static bool busy = false;
|
||||
+ if (busy) return;
|
||||
+ if (!(lc->GetItemState(item, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED))
|
||||
+ return;
|
||||
+ wxVector<long> sel;
|
||||
+ long it = -1;
|
||||
+ for (;;) {
|
||||
+ it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
+ if (it == -1) break;
|
||||
+ sel.push_back(it);
|
||||
+ }
|
||||
+ if (sel.size() <= 1) return;
|
||||
+ busy = true;
|
||||
+ for (size_t i = 0; i < sel.size(); i++)
|
||||
+ if (sel[i] != item) lc->CheckItem(sel[i], state);
|
||||
+ busy = false;
|
||||
+ };
|
||||
+ lc->Bind(wxEVT_LIST_ITEM_CHECKED, [batchCheck](wxListEvent& e) {
|
||||
+ batchCheck(e.GetIndex(), true);
|
||||
+ });
|
||||
+ lc->Bind(wxEVT_LIST_ITEM_UNCHECKED, [batchCheck](wxListEvent& e) {
|
||||
+ batchCheck(e.GetIndex(), false);
|
||||
+ });
|
||||
+ lc->Bind(wxEVT_LIST_BEGIN_DRAG, [lc](wxListEvent&) {
|
||||
+ g_reorder_drag.clear();
|
||||
+ g_reorder_list = lc;
|
||||
+ long it = -1;
|
||||
+ for (;;) {
|
||||
+ it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
+ if (it == -1) break;
|
||||
+ g_reorder_drag.push_back(lc->GetItemData(it));
|
||||
+ }
|
||||
+ });
|
||||
+ lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
|
||||
+ e.Skip();
|
||||
+ if (g_reorder_list != lc || g_reorder_drag.empty()) return;
|
||||
+ struct Row {
|
||||
+ long data;
|
||||
+ bool checked;
|
||||
+ wxString text;
|
||||
+ };
|
||||
+ int count = lc->GetItemCount();
|
||||
+ wxVector<Row> rows;
|
||||
+ for (int i = 0; i < count; i++) {
|
||||
+ Row r;
|
||||
+ r.data = lc->GetItemData(i);
|
||||
+ r.checked = lc->IsItemChecked(i);
|
||||
+ r.text = lc->GetItemText(i);
|
||||
+ rows.push_back(r);
|
||||
+ }
|
||||
+ auto isDragged = [](long d) {
|
||||
+ for (size_t i = 0; i < g_reorder_drag.size(); i++)
|
||||
+ if (g_reorder_drag[i] == d) return true;
|
||||
+ return false;
|
||||
+ };
|
||||
+ int flags = 0;
|
||||
+ long targetRow = lc->HitTest(e.GetPosition(), flags);
|
||||
+ long anchor = (targetRow >= 0 && targetRow < count) ? rows[targetRow].data : -1;
|
||||
+ if (anchor >= 0 && isDragged(anchor)) anchor = -1;
|
||||
+ wxVector<Row> remaining, moved;
|
||||
+ for (size_t i = 0; i < rows.size(); i++) {
|
||||
+ if (isDragged(rows[i].data))
|
||||
+ moved.push_back(rows[i]);
|
||||
+ else
|
||||
+ remaining.push_back(rows[i]);
|
||||
+ }
|
||||
+ int insertAt = (int)remaining.size();
|
||||
+ if (anchor >= 0) {
|
||||
+ for (size_t i = 0; i < remaining.size(); i++)
|
||||
+ if (remaining[i].data == anchor) {
|
||||
+ insertAt = (int)i;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ wxVector<Row> result;
|
||||
+ for (int i = 0; i < insertAt; i++) result.push_back(remaining[i]);
|
||||
+ for (size_t i = 0; i < moved.size(); i++) result.push_back(moved[i]);
|
||||
+ for (int i = insertAt; i < (int)remaining.size(); i++) result.push_back(remaining[i]);
|
||||
+ lc->DeleteAllItems();
|
||||
+ for (size_t i = 0; i < result.size(); i++) {
|
||||
+ long row = lc->InsertItem((long)i, result[i].text);
|
||||
+ lc->SetItemData(row, result[i].data);
|
||||
+ lc->CheckItem(row, result[i].checked);
|
||||
+ }
|
||||
+ g_reorder_drag.clear();
|
||||
+ g_reorder_list = nullptr;
|
||||
+ });
|
||||
+ return (void*)lc;
|
||||
+}
|
||||
+
|
||||
+int wxbr_reorder_get_order(void* win, int* buf, int cap) {
|
||||
+ wxListCtrl* lc = (wxListCtrl*)win;
|
||||
+ int count = lc->GetItemCount();
|
||||
+ int n = 0;
|
||||
+ for (int i = 0; i < count && n < cap; i++) {
|
||||
+ int idx = (int)lc->GetItemData(i);
|
||||
+ buf[n++] = lc->IsItemChecked(i) ? idx : ~idx;
|
||||
+ }
|
||||
+ return n;
|
||||
+}
|
||||
+
|
||||
+// ---- popup menu (right-click context menu) ----------------------------------
|
||||
+
|
||||
+void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
@@ -1054,6 +1516,33 @@
|
||||
+ return (void*)btn;
|
||||
+}
|
||||
+
|
||||
+// Render an SVG (already recoloured on the Rust side -- its fill is an explicit
|
||||
+// #RRGGBB) into a wxStaticBitmap for the KPI cards (round 11 #15). The caller
|
||||
+// passes the target pixel size (w chosen from the SVG aspect ratio, h fixed).
|
||||
+void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) {
|
||||
+ wxBitmapBundle bundle = wxBitmapBundle::FromSVG(svg, wxSize(w, h));
|
||||
+ wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
|
||||
+ return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
|
||||
+}
|
||||
+
|
||||
+// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell
|
||||
+// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's
|
||||
+// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces
|
||||
+// any prior registration for that sentinel and invalidates the bitmap cache.
|
||||
+void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) {
|
||||
+ ShapeSvg s;
|
||||
+ s.svg = wxString::FromUTF8(svg);
|
||||
+ s.vbw = vbw;
|
||||
+ s.vbh = vbh;
|
||||
+ g_shape_svgs[sentinel] = s;
|
||||
+ g_shape_bmp_cache.clear();
|
||||
+}
|
||||
+
|
||||
+// Start/stop the locate-light dot fade animation (round 12 #6). The Rust side
|
||||
+// calls this after each refresh with whether any miner's locate light is
|
||||
+// flashing, so the repaint timer only runs when there is a dot to animate.
|
||||
+void wxbr_set_light_pulse(int on) { SetLightPulse(on != 0); }
|
||||
+
|
||||
+// ---- live theme changes -----------------------------------------------------
|
||||
+
|
||||
+// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
#include <wx/utils.h>
|
||||
#include <wx/app.h>
|
||||
#include <wx/rearrangectrl.h>
|
||||
#include <wx/listctrl.h>
|
||||
#include <wx/menu.h>
|
||||
#include <wx/choice.h>
|
||||
#include <wx/bmpbuttn.h>
|
||||
#include <wx/bitmap.h>
|
||||
#include <wx/bmpbndl.h>
|
||||
#include <wx/image.h>
|
||||
#include <wx/dcmemory.h>
|
||||
#include <wx/dcgraph.h>
|
||||
@@ -32,6 +34,7 @@
|
||||
#include <wx/statusbr.h>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#ifdef __WXGTK__
|
||||
@@ -66,6 +69,7 @@ enum WxWidgetEventKind {
|
||||
WxEV_SYS_COLOUR = 13,
|
||||
WxEV_DEFERRED = 14,
|
||||
WxEV_DVLC_HEADER_RIGHT_CLICK = 15,
|
||||
WxEV_SIZE = 16, // p1 = new client width, p2 = new client height
|
||||
};
|
||||
|
||||
// A list store that carries an optional per-row foreground colour plus an
|
||||
@@ -146,6 +150,185 @@ std::vector<ColorSegment> ParseColorSegments(const wxString& value) {
|
||||
return segs;
|
||||
}
|
||||
|
||||
// Shape sentinels a segment's text may carry instead of glyphs (round 11
|
||||
// #10/#13): a single control char selects a small vector icon drawn in the
|
||||
// segment's colour. These are control characters (never emoji/pictographs) so
|
||||
// they are safe in source and independent of the font's glyph coverage.
|
||||
const wxUniChar SHAPE_DOT = 0x07; // filled status dot (hashboards, locate light)
|
||||
const wxUniChar SHAPE_LOCK = 0x02; // closed padlock (locked / view-only)
|
||||
const wxUniChar SHAPE_UNLOCK = 0x03; // open padlock (unlocked / writable)
|
||||
// Status-column KPI icons (round 12 #11): each renders the same Font Awesome
|
||||
// glyph as its dashboard KPI card, drawn from an SVG registered by the Rust side
|
||||
// (see wxbr_register_shape_svg). No vector fallback -- if unregistered the cell
|
||||
// is simply blank.
|
||||
const wxUniChar SHAPE_HASHING = 0x04; // rabbit (hashing)
|
||||
const wxUniChar SHAPE_SLOW = 0x05; // turtle (slow)
|
||||
const wxUniChar SHAPE_NOTHASHING = 0x06; // cracked wine glass (not hashing)
|
||||
const wxUniChar SHAPE_PAUSED = 0x08; // otter (paused)
|
||||
const wxUniChar SHAPE_PULSE_DOT = 0x0B; // locate-light dot that fades in/out (round 12 #6)
|
||||
const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
|
||||
|
||||
// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a
|
||||
// wxTimer while any such dot is on screen; the treeview it repaints is tracked so
|
||||
// the timer can invalidate exactly it.
|
||||
double g_pulse_phase = 0.0;
|
||||
wxDataViewCtrl* g_pulse_target = nullptr;
|
||||
|
||||
bool IsShapeSentinel(const wxString& s, wxUniChar& out) {
|
||||
if (s.length() != 1) return false;
|
||||
wxUniChar c = s[0];
|
||||
if (c == SHAPE_DOT || c == SHAPE_LOCK || c == SHAPE_UNLOCK ||
|
||||
c == SHAPE_HASHING || c == SHAPE_SLOW || c == SHAPE_NOTHASHING ||
|
||||
c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT) {
|
||||
out = c;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Blend `fg` toward `bg` by alpha (1.0 = fully fg), used to fade the locate dot.
|
||||
wxColour BlendColour(const wxColour& bg, const wxColour& fg, double a) {
|
||||
auto mix = [a](unsigned char b, unsigned char f) {
|
||||
double v = (double)b * (1.0 - a) + (double)f * a + 0.5;
|
||||
if (v < 0) v = 0;
|
||||
if (v > 255) v = 255;
|
||||
return (unsigned char)v;
|
||||
};
|
||||
return wxColour(mix(bg.Red(), fg.Red()), mix(bg.Green(), fg.Green()), mix(bg.Blue(), fg.Blue()));
|
||||
}
|
||||
|
||||
// Drives the locate-light dot's fade (round 12 #6): while running it advances the
|
||||
// phase and repaints the treeview so the SHAPE_PULSE_DOT cells re-render at the
|
||||
// new opacity. Runs only while at least one locate light is flashing.
|
||||
class PulseTimer : public wxTimer {
|
||||
public:
|
||||
void Notify() override {
|
||||
g_pulse_phase += 0.4; // ~1.6 s cycle at the 100 ms tick below
|
||||
if (!g_pulse_target) return;
|
||||
// A plain Refresh() does not re-invoke the custom cell renderer under wxGTK
|
||||
// (GtkTreeView caches rendered cells); emitting a row change does, so the
|
||||
// SHAPE_PULSE_DOT cells re-render at the new phase. The timer only runs while
|
||||
// a light is flashing, so touching every row here is cheap.
|
||||
AttrListStore* store = dynamic_cast<AttrListStore*>(g_pulse_target->GetModel());
|
||||
if (store) {
|
||||
unsigned int n = store->GetItemCount();
|
||||
for (unsigned int r = 0; r < n; r++) store->RowChanged(r);
|
||||
} else {
|
||||
g_pulse_target->Refresh();
|
||||
}
|
||||
}
|
||||
};
|
||||
PulseTimer* g_pulse_timer = nullptr;
|
||||
|
||||
void SetLightPulse(bool on) {
|
||||
if (!g_pulse_timer) g_pulse_timer = new PulseTimer();
|
||||
if (on) {
|
||||
if (!g_pulse_timer->IsRunning()) g_pulse_timer->Start(100);
|
||||
} else {
|
||||
g_pulse_timer->Stop();
|
||||
if (g_pulse_target) g_pulse_target->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
// Registry of SVG-backed shape icons (round 12 #9 access padlocks, #11 status
|
||||
// icons). The Rust side registers a raw SVG (with its viewBox dims for aspect)
|
||||
// per sentinel; DrawShape recolours it to the segment colour, rasterises once
|
||||
// per (sentinel, colour, height), caches the bitmap, and draws it. The access
|
||||
// padlocks (0x02/0x03) fall back to a hand-drawn vector when unregistered.
|
||||
struct ShapeSvg {
|
||||
wxString svg;
|
||||
int vbw;
|
||||
int vbh;
|
||||
};
|
||||
std::map<int, ShapeSvg> g_shape_svgs;
|
||||
std::map<uint64_t, wxBitmap> g_shape_bmp_cache;
|
||||
|
||||
const ShapeSvg* LookupShapeSvg(wxUniChar shape) {
|
||||
auto it = g_shape_svgs.find((int)shape.GetValue());
|
||||
return it == g_shape_svgs.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
// Recolour an SVG to `c`, matching the Rust svg_recolored(): replace
|
||||
// fill="currentColor" and inject a root fill so shapes that omit a fill inherit
|
||||
// the colour too (e.g. the Font Awesome Free otter).
|
||||
wxString RecolorShapeSvg(const wxString& svg, const wxColour& c) {
|
||||
wxString hex = wxString::Format("#%02X%02X%02X", (int)c.Red(), (int)c.Green(), (int)c.Blue());
|
||||
wxString s = svg;
|
||||
s.Replace("currentColor", hex);
|
||||
int pos = s.Find("<svg ");
|
||||
if (pos != wxNOT_FOUND) s.insert((size_t)pos + 5, wxString("fill=\"") + hex + "\" ");
|
||||
return s;
|
||||
}
|
||||
|
||||
const wxBitmap& ShapeBitmap(wxUniChar shape, const ShapeSvg& sv, const wxColour& col,
|
||||
int w, int h) {
|
||||
uint64_t rgb = ((uint64_t)col.Red() << 16) | ((uint64_t)col.Green() << 8) | (uint64_t)col.Blue();
|
||||
uint64_t key = ((uint64_t)(unsigned)shape.GetValue() << 40) | (rgb << 8) | (uint64_t)(h & 0xFF);
|
||||
auto it = g_shape_bmp_cache.find(key);
|
||||
if (it != g_shape_bmp_cache.end()) return it->second;
|
||||
wxString colored = RecolorShapeSvg(sv.svg, col);
|
||||
wxBitmapBundle bundle = wxBitmapBundle::FromSVG(colored.ToUTF8().data(), wxSize(w, h));
|
||||
wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
|
||||
return g_shape_bmp_cache.emplace(key, bmp).first->second;
|
||||
}
|
||||
|
||||
// Draw one shape sentinel centred at x; returns the horizontal space it used
|
||||
// (SHAPE_ADVANCE for the vector shapes, the icon width for a wider SVG icon).
|
||||
// `bg` is the cell background the shape sits on, used to fade the pulsing dot.
|
||||
int DrawShape(wxDC* dc, wxUniChar shape, wxCoord x, const wxRect& cell,
|
||||
const wxColour& colour, const wxColour& bg) {
|
||||
int cy = cell.y + cell.height / 2;
|
||||
// SVG-backed icon (access padlocks #9, status KPI icons #11): recolour to the
|
||||
// segment colour, rasterise (cached), and draw centred in its slot.
|
||||
if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
|
||||
int h = cell.height - 4;
|
||||
if (h > 15) h = 15;
|
||||
if (h < 8) h = 8;
|
||||
int w = (sv->vbh > 0) ? (int)((double)h * sv->vbw / sv->vbh + 0.5) : h;
|
||||
if (w < 1) w = 1;
|
||||
const wxBitmap& bmp = ShapeBitmap(shape, *sv, colour, w, h);
|
||||
if (bmp.IsOk()) {
|
||||
int slot = (w > SHAPE_ADVANCE) ? w : SHAPE_ADVANCE;
|
||||
dc->DrawBitmap(bmp, x + (slot - w) / 2, cy - h / 2, true);
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
int cx = x + SHAPE_ADVANCE / 2;
|
||||
if (shape == SHAPE_DOT || shape == SHAPE_PULSE_DOT) {
|
||||
wxColour fill = colour;
|
||||
if (shape == SHAPE_PULSE_DOT) {
|
||||
// Fade between ~0.3 and 1.0 opacity over a ~1.6 s cycle (round 12 #6).
|
||||
double a = 0.3 + 0.7 * (0.5 + 0.5 * std::sin(g_pulse_phase));
|
||||
fill = BlendColour(bg, colour, a);
|
||||
}
|
||||
dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
dc->SetBrush(wxBrush(fill));
|
||||
dc->DrawCircle(cx, cy, 4);
|
||||
return SHAPE_ADVANCE;
|
||||
}
|
||||
// Padlock: a filled body with a staple shackle above. The colour carries the
|
||||
// state (green = unlocked, red = locked); the shackle is drawn ajar when open.
|
||||
bool open = (shape == SHAPE_UNLOCK);
|
||||
int bw = 9, bh = 7;
|
||||
int bx = cx - bw / 2;
|
||||
int by = cy - bh / 2 + 1;
|
||||
dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
dc->SetBrush(wxBrush(colour));
|
||||
dc->DrawRoundedRectangle(bx, by, bw, bh, 1.5);
|
||||
dc->SetBrush(*wxTRANSPARENT_BRUSH);
|
||||
dc->SetPen(wxPen(colour, 2));
|
||||
int sr = 3;
|
||||
int legTop = by - sr - 1;
|
||||
int lx = cx - sr, rx = cx + sr;
|
||||
dc->DrawLine(lx, by, lx, legTop); // left leg
|
||||
dc->DrawLine(lx, legTop, rx, legTop); // top bar
|
||||
if (open)
|
||||
dc->DrawLine(rx, legTop, rx, legTop + sr); // ajar: right leg lifted
|
||||
else
|
||||
dc->DrawLine(rx, legTop, rx, by); // closed: right leg to body
|
||||
return SHAPE_ADVANCE;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class SegmentRenderer : public wxDataViewCustomRenderer {
|
||||
@@ -165,12 +348,71 @@ class SegmentRenderer : public wxDataViewCustomRenderer {
|
||||
|
||||
bool Render(wxRect cell, wxDC* dc, int state) override {
|
||||
bool selected = (state & wxDATAVIEW_CELL_SELECTED) != 0;
|
||||
// wxGTK does NOT paint a custom renderer's cell background, so the per-row
|
||||
// (zebra) background set via GetAttrByRow shows on the native columns but
|
||||
// not here -- the zebra looked inconsistent across columns. Paint it here so
|
||||
// every column stripes the same (skip when the row is selected: the control
|
||||
// already drew the selection highlight).
|
||||
if (!selected && GetAttr().HasBackgroundColour()) {
|
||||
dc->SetBrush(wxBrush(GetAttr().GetBackgroundColour()));
|
||||
dc->SetPen(*wxTRANSPARENT_PEN);
|
||||
// The `cell` rect wx hands a custom renderer is shrunk to the content
|
||||
// (text/shape) size in BOTH dimensions by the alignment logic, so filling
|
||||
// it alone left the zebra covering only a content-sized band -- and since
|
||||
// shape cells (dots) and text cells have different content heights, the
|
||||
// stripes ended up unequal across columns. Fill an over-sized rect (full
|
||||
// column width, and well beyond the row vertically); wxGTK clips the cell
|
||||
// DC to the real cell background area, so this lands exactly on the full
|
||||
// row height of this cell without bleeding into neighbours (round 11 #1/#3).
|
||||
wxRect bg = cell;
|
||||
if (wxDataViewColumn* owner = const_cast<SegmentRenderer*>(this)->GetOwner()) {
|
||||
int cw = owner->GetWidth();
|
||||
if (cw > bg.width) bg.width = cw;
|
||||
}
|
||||
bg.y -= 40;
|
||||
bg.height += 80;
|
||||
dc->DrawRectangle(bg);
|
||||
}
|
||||
wxColour highlight = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
|
||||
wxColour plain = GetAttr().HasColour()
|
||||
? GetAttr().GetColour()
|
||||
: wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
// An uncoloured (default) segment -- the "/" in a combined cell, a "Stock"
|
||||
// firmware family, etc. -- must dim exactly like the native columns when the
|
||||
// top-level window is backdropped. wxGTK dims a native cell's text via the
|
||||
// widget's themed state colour, but a custom renderer's DC keeps the normal
|
||||
// WINDOWTEXT, so ask the tree widget for its themed text colour AT ITS
|
||||
// CURRENT STATE (which carries GTK_STATE_FLAG_BACKDROP while unfocused) and
|
||||
// use that; off-GTK (or if the widget isn't reachable) fall back to the DC
|
||||
// then the system colour (round 11 #1/#7).
|
||||
wxColour plain;
|
||||
if (GetAttr().HasColour()) {
|
||||
plain = GetAttr().GetColour();
|
||||
} else {
|
||||
plain = ThemedTextColour();
|
||||
}
|
||||
if (!plain.IsOk()) {
|
||||
plain = dc->GetTextForeground();
|
||||
}
|
||||
if (!plain.IsOk()) {
|
||||
plain = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
}
|
||||
wxCoord x = cell.x;
|
||||
for (const ColorSegment& seg : ParseColorSegments(m_value)) {
|
||||
// Shape segments (status dots, access padlock) keep their own semantic
|
||||
// colour even on a selected row, so the green/red reading survives the
|
||||
// selection highlight (round 11 #10/#13).
|
||||
wxUniChar shape;
|
||||
if (IsShapeSentinel(seg.text, shape)) {
|
||||
// Background the shape sits on, so the pulsing locate dot fades toward it.
|
||||
wxColour cellbg;
|
||||
if (selected) {
|
||||
cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
|
||||
} else if (GetAttr().HasBackgroundColour()) {
|
||||
cellbg = GetAttr().GetBackgroundColour();
|
||||
} else {
|
||||
cellbg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
}
|
||||
x += DrawShape(dc, shape, x, cell, seg.has_colour ? seg.colour : plain, cellbg);
|
||||
continue;
|
||||
}
|
||||
if (seg.text.IsEmpty()) continue;
|
||||
dc->SetTextForeground(selected ? highlight : (seg.has_colour ? seg.colour : plain));
|
||||
wxSize extent = dc->GetTextExtent(seg.text);
|
||||
@@ -182,14 +424,66 @@ class SegmentRenderer : public wxDataViewCustomRenderer {
|
||||
}
|
||||
|
||||
wxSize GetSize() const override {
|
||||
wxString plain;
|
||||
for (const ColorSegment& seg : ParseColorSegments(m_value)) plain += seg.text;
|
||||
wxSize sz = GetTextExtent(plain);
|
||||
if (sz.GetWidth() < 1) sz.SetWidth(1);
|
||||
return sz;
|
||||
int w = 0, h = 0;
|
||||
for (const ColorSegment& seg : ParseColorSegments(m_value)) {
|
||||
wxUniChar shape;
|
||||
if (IsShapeSentinel(seg.text, shape)) {
|
||||
int adv = SHAPE_ADVANCE;
|
||||
if (const ShapeSvg* sv = LookupShapeSvg(shape)) {
|
||||
int hh = 15;
|
||||
int ww = (sv->vbh > 0) ? (int)((double)hh * sv->vbw / sv->vbh + 0.5) : hh;
|
||||
if (ww > adv) adv = ww;
|
||||
}
|
||||
w += adv;
|
||||
if (h < 12) h = 12;
|
||||
continue;
|
||||
}
|
||||
wxSize e = GetTextExtent(seg.text);
|
||||
w += e.GetWidth();
|
||||
if (e.GetHeight() > h) h = e.GetHeight();
|
||||
}
|
||||
if (w < 1) w = 1;
|
||||
if (h < 1) h = 1;
|
||||
return wxSize(w, h);
|
||||
}
|
||||
|
||||
private:
|
||||
// The owning tree widget's themed text colour at its current GTK state, so
|
||||
// uncoloured segments dim on window-backdrop like the native columns
|
||||
// (round 11 #1/#7). Returns an invalid colour off wxGTK or when the widget is
|
||||
// unreachable, so the caller falls back to the DC / system colour.
|
||||
wxColour ThemedTextColour() const {
|
||||
#ifdef __WXGTK__
|
||||
wxDataViewColumn* col = const_cast<SegmentRenderer*>(this)->GetOwner();
|
||||
if (col && col->GetOwner()) {
|
||||
GtkWidget* tv = col->GetOwner()->GtkGetTreeView();
|
||||
if (tv && GTK_IS_WIDGET(tv)) {
|
||||
// The treeview's own state flags do NOT reliably carry
|
||||
// GTK_STATE_FLAG_BACKDROP (that lives on the toplevel), so query the
|
||||
// toplevel window's active state directly and force BACKDROP onto the
|
||||
// style-context state when it is inactive. Then the themed cell text
|
||||
// colour matches what GTK paints on the native columns when the window
|
||||
// loses focus (round 11 #1/#7).
|
||||
GtkWidget* top = gtk_widget_get_toplevel(tv);
|
||||
bool active = GTK_IS_WINDOW(top) && gtk_window_is_active(GTK_WINDOW(top));
|
||||
GtkStyleContext* ctx = gtk_widget_get_style_context(tv);
|
||||
GtkStateFlags st = gtk_widget_get_state_flags(tv);
|
||||
st = active ? (GtkStateFlags)(st & ~GTK_STATE_FLAG_BACKDROP)
|
||||
: (GtkStateFlags)(st | GTK_STATE_FLAG_BACKDROP);
|
||||
GdkRGBA c;
|
||||
gtk_style_context_save(ctx);
|
||||
gtk_style_context_set_state(ctx, st);
|
||||
gtk_style_context_get_color(ctx, gtk_style_context_get_state(ctx), &c);
|
||||
gtk_style_context_restore(ctx);
|
||||
return wxColour((unsigned char)(c.red * 255.0 + 0.5),
|
||||
(unsigned char)(c.green * 255.0 + 0.5),
|
||||
(unsigned char)(c.blue * 255.0 + 0.5));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return wxColour();
|
||||
}
|
||||
|
||||
wxString m_value;
|
||||
};
|
||||
|
||||
@@ -271,6 +565,23 @@ void wxbr_sizer_detach(void* sizer, void* win) {
|
||||
((wxSizer*)sizer)->Detach((wxWindow*)win);
|
||||
}
|
||||
|
||||
// Show or hide a sizer-managed child window AND reclaim (or restore) its space
|
||||
// on the next Layout(). Used to collapse the wide KPI cards when the window is
|
||||
// too narrow (round 11 #2).
|
||||
void wxbr_sizer_show(void* sizer, void* win, int show) {
|
||||
((wxSizer*)sizer)->Show((wxWindow*)win, show != 0);
|
||||
}
|
||||
|
||||
// Emit WxEV_SIZE (p1 = new client width, p2 = height) whenever this window is
|
||||
// resized. e.Skip() keeps the normal sizer layout running (round 11 #2).
|
||||
void wxbr_bind_size(void* win) {
|
||||
((wxWindow*)win)->Bind(wxEVT_SIZE, [](wxSizeEvent& e) {
|
||||
if (g_widget_event) g_widget_event(WxEV_SIZE, (long)e.GetSize().GetWidth(),
|
||||
(long)e.GetSize().GetHeight());
|
||||
e.Skip();
|
||||
});
|
||||
}
|
||||
|
||||
void wxbr_fit(void* win) { ((wxWindow*)win)->Fit(); }
|
||||
|
||||
void wxbr_set_min_size(void* win, int w, int h) {
|
||||
@@ -381,12 +692,31 @@ void wxbr_check_box_set(void* win, int v) {
|
||||
// ---- check list box ---------------------------------------------------------
|
||||
|
||||
void* wxbr_check_list_box(void* parent) {
|
||||
// wxLB_EXTENDED so several rows can be selected at once (ctrl/shift-click and
|
||||
// rubber-band drag, native to wxListBox); a checkbox toggle on any selected
|
||||
// row then applies to every selected row (see the handler below). This is the
|
||||
// Excel-style batch-check the filter menu needs (round 12 #7).
|
||||
wxCheckListBox* clb = new wxCheckListBox((wxWindow*)parent, wxID_ANY,
|
||||
wxDefaultPosition, wxSize(-1, -1),
|
||||
0, NULL, wxLB_SINGLE | wxLB_NEEDED_SB);
|
||||
0, NULL, wxLB_EXTENDED | wxLB_NEEDED_SB);
|
||||
clb->Bind(wxEVT_CHECKLISTBOX, [clb](wxCommandEvent& e) {
|
||||
int idx = e.GetInt();
|
||||
// Batch toggle: if the clicked row is part of a multi-row selection, give
|
||||
// every selected row the clicked row's new state. Check() does not itself
|
||||
// fire wxEVT_CHECKLISTBOX, so there is no recursion.
|
||||
wxArrayInt sel;
|
||||
clb->GetSelections(sel);
|
||||
if (sel.GetCount() > 1) {
|
||||
bool inSel = false;
|
||||
for (size_t i = 0; i < sel.GetCount(); i++)
|
||||
if (sel[i] == idx) { inSel = true; break; }
|
||||
if (inSel) {
|
||||
bool state = clb->IsChecked(idx);
|
||||
for (size_t i = 0; i < sel.GetCount(); i++) clb->Check(sel[i], state);
|
||||
}
|
||||
}
|
||||
if (g_widget_event)
|
||||
g_widget_event(WxEV_CLB_TOGGLED, (long)(intptr_t)clb, e.GetInt());
|
||||
g_widget_event(WxEV_CLB_TOGGLED, (long)(intptr_t)clb, idx);
|
||||
});
|
||||
return (void*)clb;
|
||||
}
|
||||
@@ -504,6 +834,7 @@ void* wxbr_dvlc(void* parent) {
|
||||
AttrListStore* store = new AttrListStore();
|
||||
dv->AssociateModel(store);
|
||||
store->DecRef(); // the control owns a reference now
|
||||
g_pulse_target = dv; // the locate-dot pulse timer repaints this control
|
||||
dv->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxDataViewEvent&) {
|
||||
if (g_widget_event) g_widget_event(WxEV_DVLC_SELECTION_CHANGED, 0, 0);
|
||||
});
|
||||
@@ -959,6 +1290,137 @@ int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
|
||||
return n < cap ? n : cap;
|
||||
}
|
||||
|
||||
// ---- reorder list: a checkable, multi-select, drag-reorderable column list
|
||||
// for the Columns dialog (round 11 #4). Replaces wxRearrangeCtrl (which had
|
||||
// up/down buttons and no drag / multi-select). It is a single-column headerless
|
||||
// wxListCtrl with native checkboxes; rows carry their base model index as item
|
||||
// data, and the check state + row order encode the same [idx | ~idx] contract
|
||||
// as wxbr_rearrange_get_order. Selection (shift/ctrl-click, rubber-band drag) is
|
||||
// native to wxListCtrl. Drag-reorder: on begin-drag we record the selected rows'
|
||||
// base indices, and on the following mouse-up we move that group to the row
|
||||
// under the cursor (we never start a real DnD loop, so the mouse-up still
|
||||
// arrives).
|
||||
static wxVector<long> g_reorder_drag;
|
||||
static wxListCtrl* g_reorder_list = nullptr;
|
||||
|
||||
void* wxbr_reorder_list(void* parent, int n, const int* order, const char** items) {
|
||||
wxListCtrl* lc = new wxListCtrl((wxWindow*)parent, wxID_ANY, wxDefaultPosition,
|
||||
wxSize(-1, 240), wxLC_REPORT | wxLC_NO_HEADER);
|
||||
lc->EnableCheckBoxes(true);
|
||||
lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 260);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int enc = order[i];
|
||||
int idx = enc < 0 ? ~enc : enc;
|
||||
long row = lc->InsertItem(i, wxString::FromUTF8(items[idx]));
|
||||
lc->SetItemData(row, (long)idx);
|
||||
lc->CheckItem(row, enc >= 0);
|
||||
}
|
||||
// Batch checkbox toggle: checking/unchecking a row that is part of a
|
||||
// multi-row selection applies the same state to every selected row, so the
|
||||
// user can ctrl/shift-click several columns and show/hide them together
|
||||
// (round 12 #7). CheckItem() re-enters this handler, so guard against it.
|
||||
auto batchCheck = [lc](long item, bool state) {
|
||||
static bool busy = false;
|
||||
if (busy) return;
|
||||
if (!(lc->GetItemState(item, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED))
|
||||
return;
|
||||
wxVector<long> sel;
|
||||
long it = -1;
|
||||
for (;;) {
|
||||
it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
if (it == -1) break;
|
||||
sel.push_back(it);
|
||||
}
|
||||
if (sel.size() <= 1) return;
|
||||
busy = true;
|
||||
for (size_t i = 0; i < sel.size(); i++)
|
||||
if (sel[i] != item) lc->CheckItem(sel[i], state);
|
||||
busy = false;
|
||||
};
|
||||
lc->Bind(wxEVT_LIST_ITEM_CHECKED, [batchCheck](wxListEvent& e) {
|
||||
batchCheck(e.GetIndex(), true);
|
||||
});
|
||||
lc->Bind(wxEVT_LIST_ITEM_UNCHECKED, [batchCheck](wxListEvent& e) {
|
||||
batchCheck(e.GetIndex(), false);
|
||||
});
|
||||
lc->Bind(wxEVT_LIST_BEGIN_DRAG, [lc](wxListEvent&) {
|
||||
g_reorder_drag.clear();
|
||||
g_reorder_list = lc;
|
||||
long it = -1;
|
||||
for (;;) {
|
||||
it = lc->GetNextItem(it, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
if (it == -1) break;
|
||||
g_reorder_drag.push_back(lc->GetItemData(it));
|
||||
}
|
||||
});
|
||||
lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
|
||||
e.Skip();
|
||||
if (g_reorder_list != lc || g_reorder_drag.empty()) return;
|
||||
struct Row {
|
||||
long data;
|
||||
bool checked;
|
||||
wxString text;
|
||||
};
|
||||
int count = lc->GetItemCount();
|
||||
wxVector<Row> rows;
|
||||
for (int i = 0; i < count; i++) {
|
||||
Row r;
|
||||
r.data = lc->GetItemData(i);
|
||||
r.checked = lc->IsItemChecked(i);
|
||||
r.text = lc->GetItemText(i);
|
||||
rows.push_back(r);
|
||||
}
|
||||
auto isDragged = [](long d) {
|
||||
for (size_t i = 0; i < g_reorder_drag.size(); i++)
|
||||
if (g_reorder_drag[i] == d) return true;
|
||||
return false;
|
||||
};
|
||||
int flags = 0;
|
||||
long targetRow = lc->HitTest(e.GetPosition(), flags);
|
||||
long anchor = (targetRow >= 0 && targetRow < count) ? rows[targetRow].data : -1;
|
||||
if (anchor >= 0 && isDragged(anchor)) anchor = -1;
|
||||
wxVector<Row> remaining, moved;
|
||||
for (size_t i = 0; i < rows.size(); i++) {
|
||||
if (isDragged(rows[i].data))
|
||||
moved.push_back(rows[i]);
|
||||
else
|
||||
remaining.push_back(rows[i]);
|
||||
}
|
||||
int insertAt = (int)remaining.size();
|
||||
if (anchor >= 0) {
|
||||
for (size_t i = 0; i < remaining.size(); i++)
|
||||
if (remaining[i].data == anchor) {
|
||||
insertAt = (int)i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
wxVector<Row> result;
|
||||
for (int i = 0; i < insertAt; i++) result.push_back(remaining[i]);
|
||||
for (size_t i = 0; i < moved.size(); i++) result.push_back(moved[i]);
|
||||
for (int i = insertAt; i < (int)remaining.size(); i++) result.push_back(remaining[i]);
|
||||
lc->DeleteAllItems();
|
||||
for (size_t i = 0; i < result.size(); i++) {
|
||||
long row = lc->InsertItem((long)i, result[i].text);
|
||||
lc->SetItemData(row, result[i].data);
|
||||
lc->CheckItem(row, result[i].checked);
|
||||
}
|
||||
g_reorder_drag.clear();
|
||||
g_reorder_list = nullptr;
|
||||
});
|
||||
return (void*)lc;
|
||||
}
|
||||
|
||||
int wxbr_reorder_get_order(void* win, int* buf, int cap) {
|
||||
wxListCtrl* lc = (wxListCtrl*)win;
|
||||
int count = lc->GetItemCount();
|
||||
int n = 0;
|
||||
for (int i = 0; i < count && n < cap; i++) {
|
||||
int idx = (int)lc->GetItemData(i);
|
||||
buf[n++] = lc->IsItemChecked(i) ? idx : ~idx;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// ---- popup menu (right-click context menu) ----------------------------------
|
||||
|
||||
void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
@@ -1051,6 +1513,33 @@ void* wxbr_media_button(void* parent, int id, int kind, int r, int g, int b) {
|
||||
return (void*)btn;
|
||||
}
|
||||
|
||||
// Render an SVG (already recoloured on the Rust side -- its fill is an explicit
|
||||
// #RRGGBB) into a wxStaticBitmap for the KPI cards (round 11 #15). The caller
|
||||
// passes the target pixel size (w chosen from the SVG aspect ratio, h fixed).
|
||||
void* wxbr_svg_icon(void* parent, const char* svg, int w, int h) {
|
||||
wxBitmapBundle bundle = wxBitmapBundle::FromSVG(svg, wxSize(w, h));
|
||||
wxBitmap bmp = bundle.GetBitmap(wxSize(w, h));
|
||||
return (void*)new wxStaticBitmap((wxWindow*)parent, wxID_ANY, bmp);
|
||||
}
|
||||
|
||||
// Register a raw SVG (with its viewBox width/height for aspect) for a table-cell
|
||||
// shape sentinel, so the SegmentRenderer can draw it recoloured to the cell's
|
||||
// segment colour (round 12 #9 access padlocks, #11 status KPI icons). Replaces
|
||||
// any prior registration for that sentinel and invalidates the bitmap cache.
|
||||
void wxbr_register_shape_svg(int sentinel, const char* svg, int vbw, int vbh) {
|
||||
ShapeSvg s;
|
||||
s.svg = wxString::FromUTF8(svg);
|
||||
s.vbw = vbw;
|
||||
s.vbh = vbh;
|
||||
g_shape_svgs[sentinel] = s;
|
||||
g_shape_bmp_cache.clear();
|
||||
}
|
||||
|
||||
// Start/stop the locate-light dot fade animation (round 12 #6). The Rust side
|
||||
// calls this after each refresh with whether any miner's locate light is
|
||||
// flashing, so the repaint timer only runs when there is a dot to animate.
|
||||
void wxbr_set_light_pulse(int on) { SetLightPulse(on != 0); }
|
||||
|
||||
// ---- live theme changes -----------------------------------------------------
|
||||
|
||||
// Emit WxEV_SYS_COLOUR when the OS light/dark theme changes so the app can
|
||||
|
||||
@@ -23,6 +23,8 @@ mod notsafe {
|
||||
pub fn wxbr_set_sizer(win: *mut c_void, sizer: *mut c_void);
|
||||
pub fn wxbr_layout(win: *mut c_void);
|
||||
pub fn wxbr_sizer_detach(sizer: *mut c_void, win: *mut c_void);
|
||||
pub fn wxbr_sizer_show(sizer: *mut c_void, win: *mut c_void, show: c_int);
|
||||
pub fn wxbr_bind_size(win: *mut c_void);
|
||||
pub fn wxbr_fit(win: *mut c_void);
|
||||
pub fn wxbr_set_min_size(win: *mut c_void, w: c_int, h: c_int);
|
||||
pub fn wxbr_static_text(parent: *mut c_void, label: *const c_char) -> *mut c_void;
|
||||
@@ -77,6 +79,8 @@ mod notsafe {
|
||||
pub fn wxbr_apply_zebra_css(r: c_int, g: c_int, b: c_int);
|
||||
pub fn wxbr_rearrange_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
pub fn wxbr_rearrange_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
pub fn wxbr_reorder_list(parent: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char) -> *mut c_void;
|
||||
pub fn wxbr_reorder_get_order(win: *mut c_void, buf: *mut c_int, cap: c_int) -> c_int;
|
||||
pub fn wxbr_menu_new() -> *mut c_void;
|
||||
pub fn wxbr_menu_append(menu: *mut c_void, id: c_int, label: *const c_char);
|
||||
pub fn wxbr_menu_append_separator(menu: *mut c_void);
|
||||
@@ -99,6 +103,9 @@ mod notsafe {
|
||||
pub fn wxbr_choice_get_selection(win: *mut c_void) -> c_int;
|
||||
pub fn wxbr_choice_set_selection(win: *mut c_void, i: c_int);
|
||||
pub fn wxbr_media_button(parent: *mut c_void, id: c_int, kind: c_int, r: c_int, g: c_int, b: c_int) -> *mut c_void;
|
||||
pub fn wxbr_svg_icon(parent: *mut c_void, svg: *const c_char, w: c_int, h: c_int) -> *mut c_void;
|
||||
pub fn wxbr_register_shape_svg(sentinel: c_int, svg: *const c_char, vbw: c_int, vbh: c_int);
|
||||
pub fn wxbr_set_light_pulse(on: c_int);
|
||||
pub fn wxbr_bind_sys_colour(win: *mut c_void);
|
||||
pub fn wxbr_destroy(win: *mut c_void);
|
||||
pub fn wxbr_destroy_children(win: *mut c_void);
|
||||
@@ -141,6 +148,8 @@ pub enum WxEventKind {
|
||||
SysColour,
|
||||
Deferred,
|
||||
DvlcHeaderRightClick,
|
||||
/// Window resized; p1 = new client width, p2 = new client height.
|
||||
Sized,
|
||||
}
|
||||
|
||||
impl WxEventKind {
|
||||
@@ -160,6 +169,7 @@ impl WxEventKind {
|
||||
13 => WxEventKind::SysColour,
|
||||
14 => WxEventKind::Deferred,
|
||||
15 => WxEventKind::DvlcHeaderRightClick,
|
||||
16 => WxEventKind::Sized,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -192,6 +202,24 @@ pub fn status_indicator_set(text: &str, r: u8, g: u8, b: u8) {
|
||||
unsafe { notsafe::wxbr_status_indicator_set(c.as_ptr(), r as c_int, g as c_int, b as c_int) }
|
||||
}
|
||||
|
||||
/// Register a raw SVG for a table-cell shape sentinel (a control-char code point)
|
||||
/// so the segment renderer can draw it recoloured to each cell's segment colour.
|
||||
/// `vbw`/`vbh` are the SVG viewBox dimensions, used to keep the icon's aspect
|
||||
/// ratio when it is rasterised at the cell height (round 12 #9/#11).
|
||||
pub fn register_shape_svg(sentinel: u32, svg: &str, vbw: i32, vbh: i32) {
|
||||
let c = CString::new(svg).unwrap_or_default();
|
||||
unsafe {
|
||||
notsafe::wxbr_register_shape_svg(sentinel as c_int, c.as_ptr(), vbw as c_int, vbh as c_int)
|
||||
}
|
||||
}
|
||||
|
||||
/// Start (or stop) the locate-light dot fade animation. Call with `true` while at
|
||||
/// least one miner's locate light is flashing so the table repaint timer only
|
||||
/// runs when there is a pulsing dot to animate (round 12 #6).
|
||||
pub fn set_light_pulse(on: bool) {
|
||||
unsafe { notsafe::wxbr_set_light_pulse(on as c_int) }
|
||||
}
|
||||
|
||||
/// Open a URL in the system default browser. Returns true on success.
|
||||
pub fn launch_browser(url: &str) -> bool {
|
||||
let c = CString::new(url).unwrap_or_default();
|
||||
@@ -308,6 +336,18 @@ impl Widget {
|
||||
unsafe { notsafe::wxbr_sizer_detach(self.0, win.0) }
|
||||
}
|
||||
|
||||
/// Show or hide a child window in this sizer (self = a sizer), reclaiming or
|
||||
/// restoring its space on the next `layout()`.
|
||||
pub fn sizer_show(&self, win: Widget, show: bool) {
|
||||
unsafe { notsafe::wxbr_sizer_show(self.0, win.0, show as c_int) }
|
||||
}
|
||||
|
||||
/// Emit `WxEventKind::Sized` (p1 = width, p2 = height) whenever this window
|
||||
/// is resized.
|
||||
pub fn bind_size(&self) {
|
||||
unsafe { notsafe::wxbr_bind_size(self.0) }
|
||||
}
|
||||
|
||||
pub fn fit(&self, win: Widget) {
|
||||
unsafe { notsafe::wxbr_fit(win.0) }
|
||||
}
|
||||
@@ -613,6 +653,27 @@ impl Widget {
|
||||
buf.into_iter().take(n.max(0) as usize).collect()
|
||||
}
|
||||
|
||||
/// A checkable, multi-select, drag-reorderable column list (round 11 #4):
|
||||
/// like `rearrange_list` but with no up/down buttons -- rows are reordered by
|
||||
/// dragging, and selected with shift/ctrl-click or a rubber-band drag. Same
|
||||
/// `[idx | !idx]` order encoding.
|
||||
pub fn reorder_list(parent: Widget, order: &[i32], items: &[&str]) -> Widget {
|
||||
let cs: Vec<CString> = items.iter().map(|s| CString::new(*s).unwrap_or_default()).collect();
|
||||
let ptrs: Vec<*const c_char> = cs.iter().map(|c| c.as_ptr()).collect();
|
||||
Widget(unsafe {
|
||||
notsafe::wxbr_reorder_list(parent.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
})
|
||||
}
|
||||
|
||||
/// Read back the current order from a `reorder_list` (same encoding).
|
||||
pub fn reorder_get_order(&self) -> Vec<i32> {
|
||||
let mut buf = vec![0i32; 4096];
|
||||
let n = unsafe {
|
||||
notsafe::wxbr_reorder_get_order(self.0, buf.as_mut_ptr(), buf.len() as c_int)
|
||||
};
|
||||
buf.into_iter().take(n.max(0) as usize).collect()
|
||||
}
|
||||
|
||||
// ---- popup menu ----
|
||||
|
||||
pub fn menu_new() -> Widget {
|
||||
@@ -727,6 +788,14 @@ impl Widget {
|
||||
})
|
||||
}
|
||||
|
||||
/// Render an SVG string (recolour it first -- its fill must be an explicit
|
||||
/// colour, not "currentColor") into a static-bitmap icon at `w`x`h` px
|
||||
/// (round 11 #15).
|
||||
pub fn svg_icon(parent: Widget, svg: &str, w: i32, h: i32) -> Widget {
|
||||
let c = CString::new(svg).unwrap_or_default();
|
||||
Widget(unsafe { notsafe::wxbr_svg_icon(parent.0, c.as_ptr(), w as c_int, h as c_int) })
|
||||
}
|
||||
|
||||
/// Listen for OS light/dark theme changes on this window (emits `SysColour`).
|
||||
pub fn bind_sys_colour(&self) {
|
||||
unsafe { notsafe::wxbr_bind_sys_colour(self.0) }
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"6e42d50107b1a43fd7cf4a4c4f538468a337ed219ad8d6b23bd9abdabd123bd5","Cargo.lock":"7f984c7231c91f2def8f3e2e923a85c2e0b3239492f5ce23400881ea4de1aa16","Cargo.toml":"8a447efc18cd97d019a9771fb258b06f694499500561564eec75480e46bcc554","Cargo.toml.orig":"6c9e7b86804255debe03545c6358eb975d3d470810a19e6c40c680299a686b1f","src/backends/mod.rs":"65cdc60cdf38968f5a7e197338f4cf6173406ce69a4f0aaa96a9e29f4f581b6e","src/backends/v2020/firmware.rs":"5a41bfb8f42f17523e68f8702e87d75bcdb268bd4950bb66227f6966ef3576a9","src/backends/v2020/mod.rs":"f1972769a1b4811d5772e96b2e6c45b461cdcb4175355dba2b586b9df776fc1d","src/backends/v2020/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2020/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/backends/v2023_07/firmware.rs":"c07668e351d48dab3e24511b1aa9ab5e408bbcb5a438fdb0542a1377f94b9bbb","src/backends/v2023_07/mod.rs":"278e4dd04a753858e12df96ead3522aef0616ebf6f27b3da4f1a12b064c19ee6","src/backends/v2023_07/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2023_07/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/firmware.rs":"55d5b722632c0a5cfcf1f8c8252a88c5a1ece887173bb513cca0b22b874d628f","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"a3ef4d6805bb4f8ea087e3a9b875e5a1664580e1ff3e3cd2015bb0c5c18ae7bb","src/test/json/v2020/devs.json":"df17cdfc9522e23450702b93f70ff701892db54c6ce6d986300453ad5e0d22db","src/test/json/v2020/mod.rs":"4c2512d36af834d400a865a94c2e8b1919f9d8dcbf54ab2530c73861c51af67d","src/test/json/v2020/pools.json":"4c4d19ad3ef0de84bfb18daaa48428b5f7917d23287c0196eacf3a6e389e7634","src/test/json/v2020/stats.json":"6d3cb463abb7539ae77aa44ef38e62a5dc0db54670aeacf3bbd01e83f49aa1fd","src/test/json/v2020/summary.json":"2f18c81f989b7c5f70dcb0ddac0520e56ec98b6da25c24e59354a6126c965dae","src/test/json/v2020/system_info.json":"51d1ce922e39a254518a24be56ca86ef1b5843582fb26c1ff0ec4ff6f8f91ccf","src/test/json/v2020/version.json":"ae898c4c9ea3462c3e79f9de755f1fccb4ef122b94a4a512e61aa74491c1a8e9","src/test/json/v2023_07/l11_stats.json":"2eab324f253ced9a0ea4e46466691e0e71fc6fde7558fec86bd5acf6bb9c717d","src/test/json/v2023_07/l11_summary.json":"1e0fdb61b968005d0ec5393d9dc889b09efb1398ffa427629bcc0a98d1b67c22","src/test/json/v2023_07/l11_version.json":"d116921a71731c6e492aed109731c39561e34a24c7df2a88d11ac52b80f6100a","src/test/json/v2023_07/l9_stats.json":"731ee545f16dafd356d22703248b91a37f74585ad73cc27441eb3461ce53dca0","src/test/json/v2023_07/l9_summary.json":"b32b5131ad46859b270d2dbb6bdba3c4e5d7301298daee4ce56332c98faaf81d","src/test/json/v2023_07/l9_version.json":"82f03ca6ea8873f12c4d9455f21b98c547801b58fbff1dcd83c837c0f337a129","src/test/json/v2023_07/mod.rs":"1360a8b155b120f2e755ede0736bcc0d76a9d1d693b984a1b51a16e6c0413791","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"0c06e3ecbf95ae3fe5e30aacae55cf6e7ad3d965f4a93b2f85c7b64f61fc75e2"}
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"6e42d50107b1a43fd7cf4a4c4f538468a337ed219ad8d6b23bd9abdabd123bd5","Cargo.lock":"7f984c7231c91f2def8f3e2e923a85c2e0b3239492f5ce23400881ea4de1aa16","Cargo.toml":"8a447efc18cd97d019a9771fb258b06f694499500561564eec75480e46bcc554","Cargo.toml.orig":"6c9e7b86804255debe03545c6358eb975d3d470810a19e6c40c680299a686b1f","src/backends/mod.rs":"65cdc60cdf38968f5a7e197338f4cf6173406ce69a4f0aaa96a9e29f4f581b6e","src/backends/v2020/firmware.rs":"5a41bfb8f42f17523e68f8702e87d75bcdb268bd4950bb66227f6966ef3576a9","src/backends/v2020/mod.rs":"4018fbe6d907231746b1eb44c8027688b64e9cdb4ba722e0d54c2467786b9afd","src/backends/v2020/rpc.rs":"b517f88b9125fe1d8a20d5167f5d0d105b1339fce3d1a9fad5592e00470f46fb","src/backends/v2020/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/backends/v2023_07/firmware.rs":"c07668e351d48dab3e24511b1aa9ab5e408bbcb5a438fdb0542a1377f94b9bbb","src/backends/v2023_07/mod.rs":"278e4dd04a753858e12df96ead3522aef0616ebf6f27b3da4f1a12b064c19ee6","src/backends/v2023_07/rpc.rs":"2b24bbb432b302dd15f7a354054fc96c6a75cac2c8e75b8bcc11da37255a05a3","src/backends/v2023_07/web.rs":"d39b67ed83781b2c4fa84a445b9ffe785ae3001941f800ad9860e050c61c6506","src/firmware.rs":"e75c21d63218204b61bfab067599402e5c0b20452beaf0b16bfa79bf8afb6b35","src/lib.rs":"53f7acddeff8f7d82f80d09e0a9f91962011f9ccf2e441c4ca05cd7fc4eb292e","src/test/json/mod.rs":"a3ef4d6805bb4f8ea087e3a9b875e5a1664580e1ff3e3cd2015bb0c5c18ae7bb","src/test/json/v2020/devs.json":"df17cdfc9522e23450702b93f70ff701892db54c6ce6d986300453ad5e0d22db","src/test/json/v2020/mod.rs":"4c2512d36af834d400a865a94c2e8b1919f9d8dcbf54ab2530c73861c51af67d","src/test/json/v2020/pools.json":"4c4d19ad3ef0de84bfb18daaa48428b5f7917d23287c0196eacf3a6e389e7634","src/test/json/v2020/stats.json":"6d3cb463abb7539ae77aa44ef38e62a5dc0db54670aeacf3bbd01e83f49aa1fd","src/test/json/v2020/summary.json":"2f18c81f989b7c5f70dcb0ddac0520e56ec98b6da25c24e59354a6126c965dae","src/test/json/v2020/system_info.json":"51d1ce922e39a254518a24be56ca86ef1b5843582fb26c1ff0ec4ff6f8f91ccf","src/test/json/v2020/version.json":"ae898c4c9ea3462c3e79f9de755f1fccb4ef122b94a4a512e61aa74491c1a8e9","src/test/json/v2023_07/l11_stats.json":"2eab324f253ced9a0ea4e46466691e0e71fc6fde7558fec86bd5acf6bb9c717d","src/test/json/v2023_07/l11_summary.json":"1e0fdb61b968005d0ec5393d9dc889b09efb1398ffa427629bcc0a98d1b67c22","src/test/json/v2023_07/l11_version.json":"d116921a71731c6e492aed109731c39561e34a24c7df2a88d11ac52b80f6100a","src/test/json/v2023_07/l9_stats.json":"731ee545f16dafd356d22703248b91a37f74585ad73cc27441eb3461ce53dca0","src/test/json/v2023_07/l9_summary.json":"b32b5131ad46859b270d2dbb6bdba3c4e5d7301298daee4ce56332c98faaf81d","src/test/json/v2023_07/l9_version.json":"82f03ca6ea8873f12c4d9455f21b98c547801b58fbff1dcd83c837c0f337a129","src/test/json/v2023_07/mod.rs":"1360a8b155b120f2e755ede0736bcc0d76a9d1d693b984a1b51a16e6c0413791","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"0c06e3ecbf95ae3fe5e30aacae55cf6e7ad3d965f4a93b2f85c7b64f61fc75e2"}
|
||||
@@ -434,14 +434,29 @@ impl GetDataLocations for AntMinerV2020 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
DataField::ControlBoardVersion => vec![(
|
||||
WEB_MINER_TYPE,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/subtype"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
// Prefer the explicit control-board subtype from miner_type.cgi, but
|
||||
// carry the kernel build string from get_system_info.cgi too: older
|
||||
// models (e.g. Z15/Z15J) have no miner_type.cgi, and their kernel
|
||||
// string ("...-xilinx-...") names the control board we can actually
|
||||
// read instead of guessing from the model (round 12 #10).
|
||||
DataField::ControlBoardVersion => vec![
|
||||
(
|
||||
WEB_MINER_TYPE,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/subtype"),
|
||||
tag: Some("subtype"),
|
||||
},
|
||||
),
|
||||
(
|
||||
WEB_SYSTEM_INFO,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/system_kernel_version"),
|
||||
tag: Some("kernel"),
|
||||
},
|
||||
),
|
||||
],
|
||||
// cgminer names its summary keys after the unit they are in —
|
||||
// `GHS 5s` on SHA-256 models, `MHS 5s` on Scrypt ones — so keep
|
||||
// the whole entry and let the parse pick the key that is present.
|
||||
@@ -748,16 +763,33 @@ impl GetExpectedHashrate for AntMinerV2020 {
|
||||
let value = field?
|
||||
.pointer("/hashrate")
|
||||
.and_then(Self::parse_f64_field)?;
|
||||
// Equihash miners (Z15/Z15J) report `total_rateideal` as a Sol/s count in
|
||||
// the same (mislabelled) scale as the realtime "GHS" rate, so reinterpret
|
||||
// it as the base Hash unit -- matching parse_hashrate. Without this,
|
||||
// expected reads ~1e6x larger than realtime and the realtime figure looks
|
||||
// absent next to it (round 12 #10).
|
||||
let is_equihash = self.device_info.algo == HashAlgorithm::Equihash
|
||||
|| self
|
||||
.device_info
|
||||
.model
|
||||
.to_string()
|
||||
.to_ascii_uppercase()
|
||||
.contains("Z15");
|
||||
let unit = if is_equihash {
|
||||
HashRateUnit::Hash
|
||||
} else {
|
||||
// `total_rateideal` does not name its own scale, so take it from
|
||||
// STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||
field
|
||||
.and_then(|v| v.pointer("/unit"))
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|s| HashRateUnit::from_str(s).ok())
|
||||
.unwrap_or(HashRateUnit::GigaHash)
|
||||
};
|
||||
Some(
|
||||
HashRate {
|
||||
value,
|
||||
// `total_rateideal` does not name its own scale, so take it
|
||||
// from STATS' `rate_unit` (`"GH"` / `"MH"`).
|
||||
unit: field
|
||||
.and_then(|v| v.pointer("/unit"))
|
||||
.and_then(|v| v.as_str())
|
||||
.and_then(|s| HashRateUnit::from_str(s).ok())
|
||||
.unwrap_or(HashRateUnit::GigaHash),
|
||||
unit,
|
||||
algo: self.device_info.algo,
|
||||
}
|
||||
.as_unit(HashRateUnit::default()),
|
||||
@@ -888,11 +920,34 @@ impl GetControlBoardVersion for AntMinerV2020 {
|
||||
&self,
|
||||
data: &HashMap<DataField, Value>,
|
||||
) -> Option<MinerControlBoard> {
|
||||
let cb_type = data.extract::<String>(DataField::ControlBoardVersion)?;
|
||||
match cb_type.as_str() {
|
||||
s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||
_ => AntMinerControlBoard::parse(cb_type.split("_").collect::<Vec<&str>>()[0])
|
||||
.map(|cb| cb.into()),
|
||||
let field = data.get(&DataField::ControlBoardVersion)?;
|
||||
// Explicit control-board subtype (miner_type.cgi) wins when present.
|
||||
let subtype = field
|
||||
.pointer("/subtype")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("");
|
||||
if !subtype.is_empty() {
|
||||
return match subtype {
|
||||
s if s.to_uppercase().contains("AML") => Some(AntMinerControlBoard::AMLogic.into()),
|
||||
_ => AntMinerControlBoard::parse(subtype.split('_').next().unwrap_or(subtype))
|
||||
.map(|cb| cb.into()),
|
||||
};
|
||||
}
|
||||
// No subtype (older models): read the control board from the kernel build
|
||||
// string instead of guessing from the model (round 12 #10). Bitmain names
|
||||
// the SoC in the kernel version, e.g. "Linux 4.6.0-xilinx-..." (Z15) or an
|
||||
// AMLogic/Meson kernel on newer AMLogic boards.
|
||||
let kernel = field
|
||||
.pointer("/kernel")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("")
|
||||
.to_ascii_lowercase();
|
||||
if kernel.contains("xilinx") || kernel.contains("zynq") {
|
||||
Some(AntMinerControlBoard::Xilinx.into())
|
||||
} else if kernel.contains("aml") || kernel.contains("meson") {
|
||||
Some(AntMinerControlBoard::AMLogic.into())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,17 @@ impl AntMinerRPCAPI {
|
||||
read_stream_response(&mut stream, DEFAULT_RPC_TIMEOUT).await
|
||||
};
|
||||
let response = response?;
|
||||
self.parse_rpc_result(&response)
|
||||
self.parse_rpc_result(&Self::sanitize_cgminer(&response))
|
||||
}
|
||||
|
||||
/// Antminer's cgminer `stats` sometimes emits an array whose objects are not
|
||||
/// comma-separated (`...}{"STATS":0,...` on the Z15/Z15J), which is invalid
|
||||
/// JSON that serde rejects -- dropping the whole stats command and with it
|
||||
/// every stats-derived field (expected hashrate, wattage, fans, hashboards,
|
||||
/// uptime). Insert the missing separators. Well-formed JSON never contains an
|
||||
/// unseparated `}{`, so this is a no-op on valid responses (round 12 #10).
|
||||
fn sanitize_cgminer(response: &str) -> String {
|
||||
response.replace("}{", "},{")
|
||||
}
|
||||
|
||||
fn parse_rpc_result(&self, response: &str) -> anyhow::Result<Value> {
|
||||
|
||||
@@ -142,18 +142,9 @@ async fn get_model_with_auth(
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch the firmware version from a miner using digest auth.
|
||||
async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||
let client = build_discovery_client().ok()?;
|
||||
let data: Response = client
|
||||
.get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||
.send_digest_auth((auth.username(), auth.password()))
|
||||
.await
|
||||
.ok()?;
|
||||
|
||||
let json_data = data.json::<serde_json::Value>().await.ok()?;
|
||||
let fw_version = json_data["INFO"]["CompileTime"].as_str().unwrap_or("");
|
||||
|
||||
/// Parse an Antminer cgminer `CompileTime` string ("Mon Dec 14 18:01:42 CST
|
||||
/// 2020") into a date-based semver (year.month.day) used to pick the backend.
|
||||
fn parse_antminer_compile_time(fw_version: &str) -> Option<semver::Version> {
|
||||
let cleaned: String = {
|
||||
let mut parts: Vec<&str> = fw_version.split_whitespace().collect();
|
||||
if parts.len() > 4 {
|
||||
@@ -161,9 +152,7 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||
}
|
||||
parts.join(" ")
|
||||
};
|
||||
|
||||
let dt = NaiveDateTime::parse_from_str(&cleaned, "%a %b %e %H:%M:%S %Y").ok()?;
|
||||
|
||||
Some(semver::Version::new(
|
||||
dt.year() as u64,
|
||||
dt.month() as u64,
|
||||
@@ -171,6 +160,34 @@ async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::V
|
||||
))
|
||||
}
|
||||
|
||||
/// Fetch the firmware version (as a date-based semver) to pick the backend.
|
||||
async fn get_version_with_auth(ip: IpAddr, auth: &MinerAuth) -> Option<semver::Version> {
|
||||
// Newer Antminers expose the firmware CompileTime via summary.cgi.
|
||||
if let Ok(client) = build_discovery_client()
|
||||
&& let Ok(data) = client
|
||||
.get(format!("http://{ip}/cgi-bin/summary.cgi"))
|
||||
.send_digest_auth((auth.username(), auth.password()))
|
||||
.await
|
||||
&& let Ok(json_data) = data.json::<serde_json::Value>().await
|
||||
&& let Some(v) =
|
||||
parse_antminer_compile_time(json_data["INFO"]["CompileTime"].as_str().unwrap_or(""))
|
||||
{
|
||||
return Some(v);
|
||||
}
|
||||
|
||||
// Older models (e.g. Z15/Z15J) have no summary.cgi, so summary-based version
|
||||
// detection returns nothing and the miner would default to the newest
|
||||
// backend and be mis-parsed. Fall back to the cgminer :4028 `version` RPC,
|
||||
// which still reports the CompileTime, so the right (older) backend is picked
|
||||
// (round 12 #10).
|
||||
let rpc = asic_rs_core::util::send_rpc_command(&ip, "version").await?;
|
||||
parse_antminer_compile_time(
|
||||
rpc.pointer("/VERSION/0/CompileTime")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or(""),
|
||||
)
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl MinerFirmware for AntMinerStockFirmware {
|
||||
/// Uses default credentials. For custom credentials, use `build_miner`
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"de321c89f62a60690ba07d6bb145ac688c6141c458638e68b3ed36b50b8de1f1","Cargo.lock":"5942ec7c9cf5c201bd32442d65020dc3ae72e33cb5aaf374b2a26501571a1487","Cargo.toml":"cb9ee00cbb415fa66a71a7d4822839bb3552336ec9ab975ae7b1137c711449cb","Cargo.toml.orig":"08409c395e4d502015da62e97efdc9c5bc6e3076031144f3f5aa35c900c7c735","src/backends/mod.rs":"26591e67688f8d015242295dde5050c4b34986e9980018a855346291a0472206","src/backends/v1_2_0/mod.rs":"c87949458cf3c73ef957b319abc1a39c4755d709d7e3cf5ea9b9b326eb054605","src/backends/v1_2_0/web.rs":"ac89f16bf623f7d85590d34b45c99b0e522d9d434b4c22af7fa8a8a653e09d2e","src/backends/v1_3_0/mod.rs":"722301b45abe8177269cc008a528ae5c5b122f4d0ced28aaa5bee6b5b9f0c062","src/backends/v1_3_0/web.rs":"1ec4cbe6bdc26f165d9e54e9bf2aac4c3706357ce4677dc21113710d4a26c3c1","src/firmware.rs":"168eeffaef90cb1525bb2e126e73905b5205d49215437263813e30323f6b7a05","src/lib.rs":"16ea1c0007fa6d6c86c1f83d3ac9cdf065cd9936cd52f35ef89c227397bbc54a","src/timezone.rs":"309bf23de1bdc9126bde5db8dabff0d2c0fea797dbf2630a772a18539838a05e"},"package":"1cb662e56f104c0fe45c8ccdac13f60cbcaad45ac228f939c6ac46ff40335052"}
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"de321c89f62a60690ba07d6bb145ac688c6141c458638e68b3ed36b50b8de1f1","Cargo.lock":"5942ec7c9cf5c201bd32442d65020dc3ae72e33cb5aaf374b2a26501571a1487","Cargo.toml":"cb9ee00cbb415fa66a71a7d4822839bb3552336ec9ab975ae7b1137c711449cb","Cargo.toml.orig":"08409c395e4d502015da62e97efdc9c5bc6e3076031144f3f5aa35c900c7c735","src/backends/mod.rs":"26591e67688f8d015242295dde5050c4b34986e9980018a855346291a0472206","src/backends/v1_2_0/mod.rs":"fc68a12769890e18231255c6a53cb2c68e4706a887d91f49113c6192684340d2","src/backends/v1_2_0/web.rs":"ac89f16bf623f7d85590d34b45c99b0e522d9d434b4c22af7fa8a8a653e09d2e","src/backends/v1_3_0/mod.rs":"0bba1bf94e7a86d763dbedda3bb5d68cf760e17f744204b0bbc0de4e3754f795","src/backends/v1_3_0/web.rs":"1ec4cbe6bdc26f165d9e54e9bf2aac4c3706357ce4677dc21113710d4a26c3c1","src/firmware.rs":"168eeffaef90cb1525bb2e126e73905b5205d49215437263813e30323f6b7a05","src/lib.rs":"16ea1c0007fa6d6c86c1f83d3ac9cdf065cd9936cd52f35ef89c227397bbc54a","src/timezone.rs":"309bf23de1bdc9126bde5db8dabff0d2c0fea797dbf2630a772a18539838a05e"},"package":"1cb662e56f104c0fe45c8ccdac13f60cbcaad45ac228f939c6ac46ff40335052"}
|
||||
@@ -179,11 +179,15 @@ impl GetDataLocations for VnishV120 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
// The partner/reseller build name ("WildRose", "vnishreturn", ...) --
|
||||
// combined with the version number in parse_firmware_version so the FW
|
||||
// Version column shows e.g. "WildRose 1.3.5". ApiVersion still carries
|
||||
// the bare /fw_version.
|
||||
DataField::FirmwareVersion => vec![(
|
||||
WEB_INFO,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/fw_version"),
|
||||
key: Some("/build_name"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
@@ -415,7 +419,20 @@ impl GetApiVersion for VnishV120 {
|
||||
|
||||
impl GetFirmwareVersion for VnishV120 {
|
||||
fn parse_firmware_version(&self, data: &HashMap<DataField, Value>) -> Option<String> {
|
||||
data.extract::<String>(DataField::FirmwareVersion)
|
||||
// FirmwareVersion carries /build_name (the partner build), ApiVersion the
|
||||
// /fw_version number; show "<build> <version>" when both are present, else
|
||||
// whichever is available.
|
||||
let build = data
|
||||
.extract::<String>(DataField::FirmwareVersion)
|
||||
.filter(|b| !b.is_empty());
|
||||
let version = data
|
||||
.extract::<String>(DataField::ApiVersion)
|
||||
.filter(|v| !v.is_empty());
|
||||
match (build, version) {
|
||||
(Some(b), Some(v)) => Some(format!("{b} {v}")),
|
||||
(Some(b), None) => Some(b),
|
||||
(None, v) => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,11 +179,13 @@ impl GetDataLocations for VnishV130 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
// Partner/reseller build name; combined with the version number in
|
||||
// parse_firmware_version (FW Version shows e.g. "WildRose 1.3.5").
|
||||
DataField::FirmwareVersion => vec![(
|
||||
WEB_INFO,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/fw_version"),
|
||||
key: Some("/build_name"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
@@ -423,7 +425,19 @@ impl GetApiVersion for VnishV130 {
|
||||
|
||||
impl GetFirmwareVersion for VnishV130 {
|
||||
fn parse_firmware_version(&self, data: &HashMap<DataField, Value>) -> Option<String> {
|
||||
data.extract::<String>(DataField::FirmwareVersion)
|
||||
// FirmwareVersion carries /build_name (partner build), ApiVersion the
|
||||
// /fw_version number; show "<build> <version>" when both are present.
|
||||
let build = data
|
||||
.extract::<String>(DataField::FirmwareVersion)
|
||||
.filter(|b| !b.is_empty());
|
||||
let version = data
|
||||
.extract::<String>(DataField::ApiVersion)
|
||||
.filter(|v| !v.is_empty());
|
||||
match (build, version) {
|
||||
(Some(b), Some(v)) => Some(format!("{b} {v}")),
|
||||
(Some(b), None) => Some(b),
|
||||
(None, v) => v,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"30f09ad063df45fdf223aff235fe2da15cb1a7e79e86d7012074153b91662fc4","Cargo.lock":"9d0886791db53421d3218ab72d964145b86cfbe9738eaf09aac5d3c89a1c0190","Cargo.toml":"8c2e9938436850f2e250e8268ed7b385fce903e2077923b207a0560ca3e3242c","Cargo.toml.orig":"891fcfa45e79d6bc4d838c4f3075618f791bd013c99231da48e752b987f409d5","src/backends/mod.rs":"0f5a0ae31d5443d0d0f41a2540def806196238c92d22761b3ad9843cb2e77f45","src/backends/v1/mod.rs":"80f3915f1e87c6f7483e9bd0e5b1fb5552f8d017634c82eea6150fe5134b171f","src/backends/v1/rpc.rs":"4cee9caeb9bc291c4efec04f4b7fc2b8eaead904a1f2d0f30e13236476d9aac5","src/backends/v2/mod.rs":"68fd8c1762b424a7785174fdb3ae4fede1d599632657808d4b7c76bcfbfb202c","src/backends/v2/rpc.rs":"b7afc5357d24de42350d4ec15a6b5a37698e4fd77b2c2cc8071f303ee62e957c","src/backends/v3/mod.rs":"f19e673c47c2cc366e2ff7782bca93daf750563d62221a12a043b3ee79a15251","src/backends/v3/rpc.rs":"7a5f80aec4af1bcaa0d36e67345aa9acbbd8ead73c0be474f06305358b38e81b","src/error_codes.rs":"de85845f52b1d4e1a0bff73462cef00962b60fad8a3ed71c7bb083c02df3a413","src/firmware.rs":"6d002e481ce0a897c0485b9393b0382fcb25811164e893eb8eb67b2ff392ca0d","src/lib.rs":"710b46c9d934f26f900e1366ca1df5f872896e7d8da03569c0f159859e899cc9","src/test/json/mod.rs":"99760925ccfefc40d2455d3567fb1ecfc99e9e55e70478190ef372a954825909","src/test/json/v1/devs.json":"b4fd010f0bae3584efde93387cf2dab5933b499cc30a2dd7635fdc994b56c3b8","src/test/json/v1/get_psu.json":"8c11b6495e0bd5da496dd5c10ca53ec53b2d8fe9a3737f470ec9ce2c1aaf9d99","src/test/json/v1/get_version.json":"c43e947e654792ab191210d50c6f793ee0dd7af41e8cb59f0722b70f32a203bc","src/test/json/v1/mod.rs":"e79509eee78a1fef63735afe385299813726822c8259a02d1dcf5e8b4db9d04e","src/test/json/v1/pools.json":"b570808a3428a0773d7d2ee322150d8fd0794a33804af970300a7fef128a8a01","src/test/json/v1/status.json":"00ec38dd9f980b7ac0ffd6f815374afdbbed98d601bd8ef18bcf0f76ae0aa853","src/test/json/v1/summary.json":"d6e3e75654eb4019e1f479b3d9cf3097130f1afb85dd3338682c094fd4ab498a","src/test/json/v1/summary_with_errors.json":"1ba682f6ad5c43e41ae22a4069d0f52f04da3f07a18031bf4c07e07b3c59cc97","src/test/json/v2/devs.json":"2d203e41ef6ef337c0c81456b73d08730882c3167403c557c3c9776022a972d1","src/test/json/v2/get_error_code.json":"e90b702fd97bceb4f62dcb8228f75ff5ce930290355dca94eefd7192f7f57009","src/test/json/v2/get_error_code_with_errors.json":"6cb6038366eb3835684421c41be0b2b30ae8ce79a7ed51a85f4f52f70da9df16","src/test/json/v2/get_miner_info.json":"55d2af984833a692f502188ae4df4e41bdc10386b47f921c896a452ef1de9062","src/test/json/v2/get_psu.json":"b43086b65897061521d1f6611e200ef372a1724f9ea1876e347c03d5fb19b8f2","src/test/json/v2/get_version.json":"b17e3a81603b43186b2e15745e6822b6c82b3c6f5928b22f84e683d7728dbfcd","src/test/json/v2/mod.rs":"c847205d076323bbd9698e393d241b08f3cf75d32aae86f7058cf8748266b935","src/test/json/v2/pools.json":"926d34e8dae774473ebfec83d4a38e77ca73231708f07683763e212be7af0580","src/test/json/v2/status.json":"fc268cd23864ef99e84813dbf8eb916b2e6f339351a0ee5dab217cbe02569fc3","src/test/json/v2/summary.json":"4e4c01b986e2960893f58d0f1ea4dce23b8ef88db4985348f7f0183eb4818478","src/test/json/v3/get_device_info.json":"83ac22ea9a11adbceb4c963db80aa62d9a2aa50d019a372394dece817d924cda","src/test/json/v3/get_device_info_with_errors.json":"24cee4b7840e87e12147cbfddf6c361f3b378a15bb85330b339d3be9e17cdbd5","src/test/json/v3/get_miner_status_edevs.json":"2d831c06113f555e0988df994c2e602a053a4aea603dded0db8f0f80e191ca5a","src/test/json/v3/get_miner_status_pools.json":"cd65c2efd3a5ce80b57aae46c420298a34ca06df7ac7f8c36fd556217703d242","src/test/json/v3/get_miner_status_summary.json":"799a94ba13ef54aed0f81a3d041d6c1fa263d4183754b384c69ca12d85a8d3ba","src/test/json/v3/mod.rs":"7ea3a8ff1b81c7a5b0f44f7c12dda880a9aeac5b0e6b56ac4fff4f4a7cbfe451","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"c85da6325b62f061327dc5f7605dd3721c823a9e8a2cfd6a356363dfbc84d66e"}
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"30f09ad063df45fdf223aff235fe2da15cb1a7e79e86d7012074153b91662fc4","Cargo.lock":"9d0886791db53421d3218ab72d964145b86cfbe9738eaf09aac5d3c89a1c0190","Cargo.toml":"8c2e9938436850f2e250e8268ed7b385fce903e2077923b207a0560ca3e3242c","Cargo.toml.orig":"891fcfa45e79d6bc4d838c4f3075618f791bd013c99231da48e752b987f409d5","src/backends/mod.rs":"0f5a0ae31d5443d0d0f41a2540def806196238c92d22761b3ad9843cb2e77f45","src/backends/v1/mod.rs":"b96cd7679b575335d716b114a3986167b2696b9e94a1a06a4696757aef08c7d1","src/backends/v1/rpc.rs":"4cee9caeb9bc291c4efec04f4b7fc2b8eaead904a1f2d0f30e13236476d9aac5","src/backends/v2/mod.rs":"68fd8c1762b424a7785174fdb3ae4fede1d599632657808d4b7c76bcfbfb202c","src/backends/v2/rpc.rs":"b7afc5357d24de42350d4ec15a6b5a37698e4fd77b2c2cc8071f303ee62e957c","src/backends/v3/mod.rs":"f19e673c47c2cc366e2ff7782bca93daf750563d62221a12a043b3ee79a15251","src/backends/v3/rpc.rs":"7a5f80aec4af1bcaa0d36e67345aa9acbbd8ead73c0be474f06305358b38e81b","src/error_codes.rs":"de85845f52b1d4e1a0bff73462cef00962b60fad8a3ed71c7bb083c02df3a413","src/firmware.rs":"6d002e481ce0a897c0485b9393b0382fcb25811164e893eb8eb67b2ff392ca0d","src/lib.rs":"710b46c9d934f26f900e1366ca1df5f872896e7d8da03569c0f159859e899cc9","src/test/json/mod.rs":"99760925ccfefc40d2455d3567fb1ecfc99e9e55e70478190ef372a954825909","src/test/json/v1/devs.json":"b4fd010f0bae3584efde93387cf2dab5933b499cc30a2dd7635fdc994b56c3b8","src/test/json/v1/get_psu.json":"8c11b6495e0bd5da496dd5c10ca53ec53b2d8fe9a3737f470ec9ce2c1aaf9d99","src/test/json/v1/get_version.json":"c43e947e654792ab191210d50c6f793ee0dd7af41e8cb59f0722b70f32a203bc","src/test/json/v1/mod.rs":"e79509eee78a1fef63735afe385299813726822c8259a02d1dcf5e8b4db9d04e","src/test/json/v1/pools.json":"b570808a3428a0773d7d2ee322150d8fd0794a33804af970300a7fef128a8a01","src/test/json/v1/status.json":"00ec38dd9f980b7ac0ffd6f815374afdbbed98d601bd8ef18bcf0f76ae0aa853","src/test/json/v1/summary.json":"d6e3e75654eb4019e1f479b3d9cf3097130f1afb85dd3338682c094fd4ab498a","src/test/json/v1/summary_with_errors.json":"1ba682f6ad5c43e41ae22a4069d0f52f04da3f07a18031bf4c07e07b3c59cc97","src/test/json/v2/devs.json":"2d203e41ef6ef337c0c81456b73d08730882c3167403c557c3c9776022a972d1","src/test/json/v2/get_error_code.json":"e90b702fd97bceb4f62dcb8228f75ff5ce930290355dca94eefd7192f7f57009","src/test/json/v2/get_error_code_with_errors.json":"6cb6038366eb3835684421c41be0b2b30ae8ce79a7ed51a85f4f52f70da9df16","src/test/json/v2/get_miner_info.json":"55d2af984833a692f502188ae4df4e41bdc10386b47f921c896a452ef1de9062","src/test/json/v2/get_psu.json":"b43086b65897061521d1f6611e200ef372a1724f9ea1876e347c03d5fb19b8f2","src/test/json/v2/get_version.json":"b17e3a81603b43186b2e15745e6822b6c82b3c6f5928b22f84e683d7728dbfcd","src/test/json/v2/mod.rs":"c847205d076323bbd9698e393d241b08f3cf75d32aae86f7058cf8748266b935","src/test/json/v2/pools.json":"926d34e8dae774473ebfec83d4a38e77ca73231708f07683763e212be7af0580","src/test/json/v2/status.json":"fc268cd23864ef99e84813dbf8eb916b2e6f339351a0ee5dab217cbe02569fc3","src/test/json/v2/summary.json":"4e4c01b986e2960893f58d0f1ea4dce23b8ef88db4985348f7f0183eb4818478","src/test/json/v3/get_device_info.json":"83ac22ea9a11adbceb4c963db80aa62d9a2aa50d019a372394dece817d924cda","src/test/json/v3/get_device_info_with_errors.json":"24cee4b7840e87e12147cbfddf6c361f3b378a15bb85330b339d3be9e17cdbd5","src/test/json/v3/get_miner_status_edevs.json":"2d831c06113f555e0988df994c2e602a053a4aea603dded0db8f0f80e191ca5a","src/test/json/v3/get_miner_status_pools.json":"cd65c2efd3a5ce80b57aae46c420298a34ca06df7ac7f8c36fd556217703d242","src/test/json/v3/get_miner_status_summary.json":"799a94ba13ef54aed0f81a3d041d6c1fa263d4183754b384c69ca12d85a8d3ba","src/test/json/v3/mod.rs":"7ea3a8ff1b81c7a5b0f44f7c12dda880a9aeac5b0e6b56ac4fff4f4a7cbfe451","src/test/mod.rs":"ed52c3d613eabc4a0346bb38bcfdf7a94933d61e368d3c9094821edeab92f81b"},"package":"c85da6325b62f061327dc5f7605dd3721c823a9e8a2cfd6a356363dfbc84d66e"}
|
||||
@@ -131,14 +131,28 @@ impl GetDataLocations for WhatsMinerV1 {
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
DataField::ControlBoardVersion => vec![(
|
||||
RPC_SUMMARY,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/SUMMARY/0/CB Platform"),
|
||||
tag: None,
|
||||
},
|
||||
)],
|
||||
DataField::ControlBoardVersion => vec![
|
||||
(
|
||||
RPC_SUMMARY,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/SUMMARY/0/CB Platform"),
|
||||
tag: None,
|
||||
},
|
||||
),
|
||||
// Older M30S firmware (< 2022.7.29, so this v1 backend) often omits
|
||||
// "CB Platform" from summary but still reports the board under
|
||||
// get_version /Msg/platform (the source v2 uses). Fall back to it so
|
||||
// those units don't show a blank control board.
|
||||
(
|
||||
RPC_GET_VERSION,
|
||||
DataExtractor {
|
||||
func: get_by_pointer,
|
||||
key: Some("/Msg/platform"),
|
||||
tag: None,
|
||||
},
|
||||
),
|
||||
],
|
||||
DataField::TuningTarget => vec![(
|
||||
RPC_SUMMARY,
|
||||
DataExtractor {
|
||||
@@ -285,8 +299,12 @@ impl GetControlBoardVersion for WhatsMinerV1 {
|
||||
) -> Option<MinerControlBoard> {
|
||||
data.extract::<String>(DataField::ControlBoardVersion)
|
||||
.and_then(|s| {
|
||||
WhatsMinerControlBoard::parse(s.to_uppercase().strip_prefix("ALLWINNER_")?)
|
||||
.map(|cb| cb.into())
|
||||
// The "ALLWINNER_" prefix is optional: summary's CB Platform carries
|
||||
// it (e.g. "ALLWINNER_H6"), but the get_version /Msg/platform fallback
|
||||
// does not (e.g. "H6OS"). Strip it only when present.
|
||||
let up = s.to_uppercase();
|
||||
let board = up.strip_prefix("ALLWINNER_").unwrap_or(&up);
|
||||
WhatsMinerControlBoard::parse(board).map(|cb| cb.into())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"aaaa0f14e3aff2543d3d09a4515efa5ab439f0651a36b582e87b9843d0475752","Cargo.lock":"58da2f3399ff680bf7d619204897b4edf5c03d336a8c3cceb54c9aba280bfed1","Cargo.toml":"57f92bf3808fa6f468dbabf43763a808d9ead128eef83b748f940ef3b219a80e","Cargo.toml.orig":"cbfb99fc843dd61ad2025dcfc16bd435afd2b6d43c2c983867af08af415916f1","src/hardware.rs":"77612b4f39e9c15355172b0582693d86b2fe44a305f5b01eef592e5a34b37188","src/lib.rs":"b2f55767a7f3fdacb1e898c5cb961c2dec8481823f94386ee67628960e91bf7d","src/make.rs":"e968e4dbd745d485fc9ad4c5a4c081d679eddce11f66e572f81f2dbe37ede3f0","src/models.rs":"da72a570d8cbb2c843c04047c3d879ca9709455f9bd6a02c3f2ab739e1b5be60"},"package":"67cca6e6bf4ac14562084ce7534521ffa7cd313fa39e2392f98ff98a047a4353"}
|
||||
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"aaaa0f14e3aff2543d3d09a4515efa5ab439f0651a36b582e87b9843d0475752","Cargo.lock":"58da2f3399ff680bf7d619204897b4edf5c03d336a8c3cceb54c9aba280bfed1","Cargo.toml":"57f92bf3808fa6f468dbabf43763a808d9ead128eef83b748f940ef3b219a80e","Cargo.toml.orig":"cbfb99fc843dd61ad2025dcfc16bd435afd2b6d43c2c983867af08af415916f1","src/hardware.rs":"c3edc06f2404efd473bcc4ab16d66bb647369f2d43c0a10cb77bbc12cb98bf43","src/lib.rs":"b2f55767a7f3fdacb1e898c5cb961c2dec8481823f94386ee67628960e91bf7d","src/make.rs":"e968e4dbd745d485fc9ad4c5a4c081d679eddce11f66e572f81f2dbe37ede3f0","src/models.rs":"da72a570d8cbb2c843c04047c3d879ca9709455f9bd6a02c3f2ab739e1b5be60"},"package":"67cca6e6bf4ac14562084ce7534521ffa7cd313fa39e2392f98ff98a047a4353"}
|
||||
@@ -268,11 +268,13 @@ impl AntMinerControlBoard {
|
||||
.collect::<String>();
|
||||
|
||||
match compact.as_str() {
|
||||
"XILINX" => Some(Self::Xilinx),
|
||||
// "XIL" is VNish's short platform form for a Xilinx control board.
|
||||
"XILINX" | "XIL" => Some(Self::Xilinx),
|
||||
"BBB" | "BBCTRL" | "BB" | "BEAGLEBONE" | "BEAGLEBONEBLACK" => {
|
||||
Some(Self::BeagleBoneBlack)
|
||||
}
|
||||
"CVITEK" | "CVCTRL" => Some(Self::CVITek),
|
||||
// "CV" is VNish's short platform form for a CVITek control board.
|
||||
"CVITEK" | "CVCTRL" | "CV" => Some(Self::CVITek),
|
||||
"AMLOGIC" | "AML" => Some(Self::AMLogic),
|
||||
"AMCB07" => Some(Self::Xilinx), // Mara FW
|
||||
"ZYNQ7007" => Some(Self::Xilinx),
|
||||
|
||||