Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecdb2fab9d |
@@ -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="M434.8 54.1C446.7 62.7 451.1 78.3 445.7 91.9L367.3 288L512 288C525.5 288 537.5 296.4 542.1 309.1C546.7 321.8 542.8 336 532.5 344.6L244.5 584.6C233.2 594 217.1 594.5 205.2 585.9C193.3 577.3 188.9 561.7 194.3 548.1L272.7 352L128 352C114.5 352 102.5 343.6 97.9 330.9C93.3 318.2 97.2 304 107.5 295.4L395.5 55.4C406.8 46 422.9 45.5 434.8 54.1z"/></svg>
|
||||
|
After Width: | Height: | Size: 569 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="M184 120C184 89.1 209.1 64 240 64L264 64C281.7 64 296 78.3 296 96L296 544C296 561.7 281.7 576 264 576L232 576C202.2 576 177.1 555.6 170 528C169.3 528 168.7 528 168 528C123.8 528 88 492.2 88 448C88 430 94 413.4 104 400C84.6 385.4 72 362.2 72 336C72 305.1 89.6 278.2 115.2 264.9C108.1 252.9 104 238.9 104 224C104 179.8 139.8 144 184 144L184 120zM456 120L456 144C500.2 144 536 179.8 536 224C536 239 531.9 253 524.8 264.9C550.5 278.2 568 305 568 336C568 362.2 555.4 385.4 536 400C546 413.4 552 430 552 448C552 492.2 516.2 528 472 528C471.3 528 470.7 528 470 528C462.9 555.6 437.8 576 408 576L376 576C358.3 576 344 561.7 344 544L344 96C344 78.3 358.3 64 376 64L400 64C430.9 64 456 89.1 456 120z"/></svg>
|
||||
|
After Width: | Height: | Size: 920 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="M224 208C224 128.5 288.5 64 368 64C376.8 64 384 71.2 384 80L384 232.2C399 226.9 415.2 224 432 224C511.5 224 576 288.5 576 368C576 376.8 568.8 384 560 384L407.8 384C413.1 399 416 415.2 416 432C416 511.5 351.5 576 272 576C263.2 576 256 568.8 256 560L256 407.8C241 413.1 224.8 416 208 416C128.5 416 64 351.5 64 272C64 263.2 71.2 256 80 256L232.2 256C226.9 241 224 224.8 224 208zM320 352C337.7 352 352 337.7 352 320C352 302.3 337.7 288 320 288C302.3 288 288 302.3 288 320C288 337.7 302.3 352 320 352z"/></svg>
|
||||
|
After Width: | Height: | Size: 727 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="M240 88C240 74.7 229.3 64 216 64C202.7 64 192 74.7 192 88L192 128C156.7 128 128 156.7 128 192L88 192C74.7 192 64 202.7 64 216C64 229.3 74.7 240 88 240L128 240L128 296L88 296C74.7 296 64 306.7 64 320C64 333.3 74.7 344 88 344L128 344L128 400L88 400C74.7 400 64 410.7 64 424C64 437.3 74.7 448 88 448L128 448C128 483.3 156.7 512 192 512L192 552C192 565.3 202.7 576 216 576C229.3 576 240 565.3 240 552L240 512L296 512L296 552C296 565.3 306.7 576 320 576C333.3 576 344 565.3 344 552L344 512L400 512L400 552C400 565.3 410.7 576 424 576C437.3 576 448 565.3 448 552L448 512C483.3 512 512 483.3 512 448L552 448C565.3 448 576 437.3 576 424C576 410.7 565.3 400 552 400L512 400L512 344L552 344C565.3 344 576 333.3 576 320C576 306.7 565.3 296 552 296L512 296L512 240L552 240C565.3 240 576 229.3 576 216C576 202.7 565.3 192 552 192L512 192C512 156.7 483.3 128 448 128L448 88C448 74.7 437.3 64 424 64C410.7 64 400 74.7 400 88L400 128L344 128L344 88C344 74.7 333.3 64 320 64C306.7 64 296 74.7 296 88L296 128L240 128L240 88zM224 192L416 192C433.7 192 448 206.3 448 224L448 416C448 433.7 433.7 448 416 448L224 448C206.3 448 192 433.7 192 416L192 224C192 206.3 206.3 192 224 192zM240 240L240 400L400 400L400 240L240 240z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -246,6 +246,39 @@ pub enum BoardHealth {
|
||||
Missing,
|
||||
}
|
||||
|
||||
/// One component's health for the Health icon column (round 13 #3). Rendered as a
|
||||
/// coloured icon: grey = unreachable / not detected, red = detected but not
|
||||
/// functioning, yellow = functioning sub-optimally, green = fully functioning.
|
||||
/// The `level` ordering (worst first) is also the sort order.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum CompHealth {
|
||||
Unreachable,
|
||||
Down,
|
||||
Degraded,
|
||||
Ok,
|
||||
}
|
||||
|
||||
impl CompHealth {
|
||||
/// 0 (worst) .. 3 (best), for the Health column sort keys.
|
||||
pub fn level(self) -> i32 {
|
||||
match self {
|
||||
CompHealth::Unreachable => 0,
|
||||
CompHealth::Down => 1,
|
||||
CompHealth::Degraded => 2,
|
||||
CompHealth::Ok => 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Which component the Health column is currently sorted by (round 13 #3).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum HealthFacet {
|
||||
Overall,
|
||||
Power,
|
||||
Fans,
|
||||
Boards,
|
||||
}
|
||||
|
||||
/// 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.
|
||||
@@ -364,6 +397,127 @@ impl MinerRow {
|
||||
}
|
||||
}
|
||||
|
||||
/// Power-supply health (round 13 #3). Green when the miner is drawing power,
|
||||
/// its PSU fan is spinning, or it is actively mining (all prove the PSU is
|
||||
/// live); grey (unknown) otherwise -- asic-rs has no direct PSU-fault flag, so
|
||||
/// a missing wattage reading is treated as unknown, never a false "down".
|
||||
pub fn power_health(&self) -> CompHealth {
|
||||
if self.power_w > 0.0 || self.psu_fan_rpm > 0.0 || self.is_mining {
|
||||
CompHealth::Ok
|
||||
} else {
|
||||
CompHealth::Unreachable
|
||||
}
|
||||
}
|
||||
|
||||
/// Control-board health (round 13 #3). The miner answered the scan, so its
|
||||
/// control board is reachable and running; there is no network signal for a
|
||||
/// degraded controller, so this is green for any responding miner.
|
||||
pub fn control_health(&self) -> CompHealth {
|
||||
CompHealth::Ok
|
||||
}
|
||||
|
||||
/// Per-fan health (round 13 #3), front-to-back / top-to-bottom in the order
|
||||
/// the miner reports its fans. A spinning fan is green, unless it is running
|
||||
/// well below its fastest sibling (< 50% of the max reported RPM), which is a
|
||||
/// sub-optimal fan (yellow); a reported 0 RPM is a stopped fan (red); a fan the
|
||||
/// miner expects but does not report is grey (not detected). Empty when the
|
||||
/// miner reports no fans at all.
|
||||
pub fn fan_healths(&self) -> Vec<CompHealth> {
|
||||
let expected = self.expected_fans.map(|n| n as usize).unwrap_or(0);
|
||||
let n = expected.max(self.fan_rpms.len());
|
||||
let max_rpm = self.fan_rpms.iter().cloned().fold(0.0_f64, f64::max);
|
||||
(0..n)
|
||||
.map(|i| match self.fan_rpms.get(i) {
|
||||
Some(&rpm) if rpm > 0.0 => {
|
||||
if max_rpm > 0.0 && rpm < 0.5 * max_rpm {
|
||||
CompHealth::Degraded
|
||||
} else {
|
||||
CompHealth::Ok
|
||||
}
|
||||
}
|
||||
Some(_) => CompHealth::Down,
|
||||
None => CompHealth::Unreachable,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Per-hashboard health (round 13 #3). Uses the per-board status when the
|
||||
/// miner reports it (green ok / red faulted / grey missing); otherwise falls
|
||||
/// back to the present-vs-expected board counts (present green, shortfall
|
||||
/// grey). Empty when neither is known.
|
||||
pub fn board_healths(&self) -> Vec<CompHealth> {
|
||||
if !self.board_status.is_empty() {
|
||||
// A miner that is mining but "slow" is hashing sub-optimally, so its
|
||||
// present-and-hashing boards read yellow rather than green.
|
||||
let ok = if self.slow { CompHealth::Degraded } else { CompHealth::Ok };
|
||||
return self
|
||||
.board_status
|
||||
.iter()
|
||||
.map(|h| match h {
|
||||
BoardHealth::Ok => ok,
|
||||
BoardHealth::Fault => CompHealth::Down,
|
||||
BoardHealth::Missing => CompHealth::Unreachable,
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
let present = self.hashboards.map(|n| n as usize).unwrap_or(0);
|
||||
let expected = self.expected_hashboards.map(|n| n as usize).unwrap_or(present);
|
||||
let n = present.max(expected);
|
||||
(0..n)
|
||||
.map(|i| if i < present { CompHealth::Ok } else { CompHealth::Unreachable })
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The sort key for the Health column and its facet pseudo-columns (round 13
|
||||
/// #3): higher = healthier, so an ascending sort surfaces the most-broken
|
||||
/// miners first (matching the existing Boards-column behaviour). Encoded as
|
||||
/// `worst-component-level * 1000 + sum-of-levels` so any red/grey component
|
||||
/// dominates, with the healthy-icon count as the tiebreak. A component with no
|
||||
/// data scores as healthy so unknown-but-fine miners don't masquerade as
|
||||
/// broken.
|
||||
pub fn health_score(&self, facet: HealthFacet) -> f64 {
|
||||
let score = |comps: &[CompHealth]| -> i64 {
|
||||
if comps.is_empty() {
|
||||
return CompHealth::Ok.level() as i64 * 1000 + CompHealth::Ok.level() as i64;
|
||||
}
|
||||
let min = comps.iter().map(|c| c.level()).min().unwrap_or(3) as i64;
|
||||
let sum: i64 = comps.iter().map(|c| c.level() as i64).sum();
|
||||
min * 1000 + sum
|
||||
};
|
||||
let val = match facet {
|
||||
HealthFacet::Power => score(&[self.power_health()]),
|
||||
HealthFacet::Fans => score(&self.fan_healths()),
|
||||
HealthFacet::Boards => score(&self.board_healths()),
|
||||
HealthFacet::Overall => {
|
||||
let mut all = vec![self.power_health(), self.control_health()];
|
||||
all.extend(self.fan_healths());
|
||||
all.extend(self.board_healths());
|
||||
score(&all)
|
||||
}
|
||||
};
|
||||
val as f64
|
||||
}
|
||||
|
||||
/// Compact plain-text summary of component health (round 13 #3), used as the
|
||||
/// Health column's filter/sort-fallback text and the base of its hover
|
||||
/// tooltip. e.g. "power ok, fans 3/4, boards 3/3".
|
||||
pub fn health_summary(&self) -> String {
|
||||
let ok = |comps: &[CompHealth]| comps.iter().filter(|c| **c == CompHealth::Ok).count();
|
||||
let fans = self.fan_healths();
|
||||
let boards = self.board_healths();
|
||||
let mut parts = vec![match self.power_health() {
|
||||
CompHealth::Ok => "power ok".to_string(),
|
||||
_ => "power ?".to_string(),
|
||||
}];
|
||||
if !fans.is_empty() {
|
||||
parts.push(format!("fans {}/{}", ok(&fans), fans.len()));
|
||||
}
|
||||
if !boards.is_empty() {
|
||||
parts.push(format!("boards {}/{}", ok(&boards), boards.len()));
|
||||
}
|
||||
parts.join(", ")
|
||||
}
|
||||
|
||||
/// Upsert into `rows` by ip; returns true if the row is new.
|
||||
pub fn upsert_into(self, rows: &mut Vec<MinerRow>) -> bool {
|
||||
if let Some(r) = rows.iter_mut().find(|r| r.ip == self.ip) {
|
||||
@@ -415,6 +569,18 @@ pub enum Column {
|
||||
Model,
|
||||
Brand,
|
||||
Submodel,
|
||||
/// Component-health icon column (round 13 #3): power, control board, each
|
||||
/// fan, and each hashboard drawn as a coloured icon (grey unreachable, red
|
||||
/// down, yellow sub-optimal, green healthy). Replaces the old Errors, Boards
|
||||
/// (hashboard dots) and Status columns.
|
||||
Health,
|
||||
/// Sort-only pseudo-columns (round 13 #3): the Health header left-click cycles
|
||||
/// its sort through these facets so the fleet can be ordered by whichever
|
||||
/// component matters (power, fans, hashboards) instead of overall health.
|
||||
/// Deliberately NOT in `ALL_COLUMNS`, so they never appear in the picker.
|
||||
HealthPower,
|
||||
HealthFans,
|
||||
HealthBoards,
|
||||
Status,
|
||||
Efficiency,
|
||||
FluidTemp,
|
||||
@@ -452,9 +618,10 @@ pub enum Column {
|
||||
|
||||
/// Every column, in registry order. Ip first, then the default-visible set
|
||||
/// (UI-SPEC order), then all remaining metrics.
|
||||
pub const ALL_COLUMNS: [Column; 45] = [
|
||||
pub const ALL_COLUMNS: [Column; 43] = [
|
||||
Column::Ip,
|
||||
Column::Hashrate,
|
||||
Column::Health,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Cooling,
|
||||
@@ -465,7 +632,6 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::Model,
|
||||
Column::Brand,
|
||||
Column::Submodel,
|
||||
Column::Status,
|
||||
Column::Efficiency,
|
||||
Column::FluidTemp,
|
||||
Column::EnvTemp,
|
||||
@@ -474,7 +640,6 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::FanCount,
|
||||
Column::ExpectedFans,
|
||||
Column::TotalChips,
|
||||
Column::Hashboards,
|
||||
Column::Mac,
|
||||
Column::Hostname,
|
||||
Column::Serial,
|
||||
@@ -484,7 +649,6 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
Column::Algorithm,
|
||||
Column::Pic,
|
||||
Column::Locked,
|
||||
Column::Error,
|
||||
Column::Uptime,
|
||||
Column::Light,
|
||||
Column::OperatingState,
|
||||
@@ -501,17 +665,17 @@ pub const ALL_COLUMNS: [Column; 45] = [
|
||||
];
|
||||
|
||||
/// 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] = [
|
||||
/// order: model, health (component icons), hashrate, power, chip temp, firmware,
|
||||
/// CPU, access. The Health column (round 13 #3) folds the old Errors, Boards and
|
||||
/// Status columns into one row of per-component icons.
|
||||
pub const DEFAULT_VISIBLE: [Column; 8] = [
|
||||
Column::Model,
|
||||
Column::Error,
|
||||
Column::Health,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Firmware,
|
||||
Column::Cpu,
|
||||
Column::Hashboards,
|
||||
Column::Locked,
|
||||
];
|
||||
|
||||
@@ -531,6 +695,10 @@ impl Column {
|
||||
Column::Model => "Model",
|
||||
Column::Brand => "Brand",
|
||||
Column::Submodel => "Submodel",
|
||||
Column::Health => "Health",
|
||||
Column::HealthPower => "Health (power)",
|
||||
Column::HealthFans => "Health (fans)",
|
||||
Column::HealthBoards => "Health (boards)",
|
||||
Column::Status => "Status",
|
||||
Column::Efficiency => "Efficiency (J/TH)",
|
||||
Column::FluidTemp => "Fluid temp",
|
||||
@@ -582,6 +750,10 @@ impl Column {
|
||||
Column::Model => 150,
|
||||
Column::Brand => 100,
|
||||
Column::Submodel => 100,
|
||||
// Wide enough for power + control board + several fan and hashboard
|
||||
// icons in a row (round 13 #3).
|
||||
Column::Health => 170,
|
||||
Column::HealthPower | Column::HealthFans | Column::HealthBoards => 170,
|
||||
Column::Status => 95,
|
||||
Column::Efficiency => 120,
|
||||
Column::FanCount | Column::TotalChips | Column::Hashboards => 70,
|
||||
@@ -705,6 +877,12 @@ impl Column {
|
||||
}
|
||||
// IP sorts numerically (u32 fits exactly in f64), not lexically.
|
||||
Column::Ip => SortKey::Num(ip_to_u32(&r.ip) as f64),
|
||||
// Health column + its facet pseudo-columns (round 13 #3): higher =
|
||||
// healthier, so ascending surfaces the most-broken miners.
|
||||
Column::Health => SortKey::Num(r.health_score(HealthFacet::Overall)),
|
||||
Column::HealthPower => SortKey::Num(r.health_score(HealthFacet::Power)),
|
||||
Column::HealthFans => SortKey::Num(r.health_score(HealthFacet::Fans)),
|
||||
Column::HealthBoards => SortKey::Num(r.health_score(HealthFacet::Boards)),
|
||||
_ => SortKey::Str(self.cell(r).to_lowercase()),
|
||||
}
|
||||
}
|
||||
@@ -791,6 +969,12 @@ impl Column {
|
||||
n => n.to_string(),
|
||||
},
|
||||
Column::Status => r.status().to_string(),
|
||||
// The Health column renders as component icons (see fill_rows); this
|
||||
// plain-text summary is its filter/sort-fallback text and tooltip base
|
||||
// (round 13 #3). The facet pseudo-columns are never displayed.
|
||||
Column::Health | Column::HealthPower | Column::HealthFans | Column::HealthBoards => {
|
||||
r.health_summary()
|
||||
}
|
||||
Column::Uptime => format_uptime(r.uptime_secs),
|
||||
Column::Light => match r.light_flashing {
|
||||
Some(true) => "on".to_string(),
|
||||
@@ -811,6 +995,34 @@ impl Column {
|
||||
Column::Pool3Worker => pool_worker(2),
|
||||
}
|
||||
}
|
||||
|
||||
/// The column's category, as a (sort-rank, label) pair, for the column
|
||||
/// picker's "Categories" grouping (round 13 #1). Lower rank sorts first; the
|
||||
/// label heads the group. Columns keep their registry order within a group.
|
||||
pub fn category(self) -> (u8, &'static str) {
|
||||
match self {
|
||||
Column::Ip | Column::Model | Column::Brand | Column::Submodel | Column::Mac
|
||||
| Column::Hostname | Column::Serial => (0, "Identity"),
|
||||
Column::Firmware | Column::FwVersion | Column::ApiVersion | Column::Algorithm
|
||||
| Column::Pic | Column::Cpu | Column::BoardCode => (1, "Firmware & board"),
|
||||
Column::Health | Column::HealthPower | Column::HealthFans | Column::HealthBoards
|
||||
| Column::Status | Column::Error | Column::Locked | Column::Light
|
||||
| Column::OperatingState => (2, "Health & status"),
|
||||
Column::Hashrate | Column::HashrateRel | Column::Power | Column::Efficiency
|
||||
| Column::TuningPercent | Column::BestShare | Column::SessionBestShare
|
||||
| Column::Uptime => (3, "Performance"),
|
||||
Column::ChipTemp | Column::FluidTemp | Column::EnvTemp | Column::OutletTemp => {
|
||||
(4, "Temperature")
|
||||
}
|
||||
Column::Cooling | Column::PsuFan | Column::FanCount | Column::ExpectedFans => {
|
||||
(5, "Cooling")
|
||||
}
|
||||
Column::TotalChips | Column::Hashboards => (6, "Hardware"),
|
||||
Column::Worker | Column::PoolAccount | Column::PoolUrl | Column::Pool1Url
|
||||
| Column::Pool1Worker | Column::Pool2Url | Column::Pool2Worker | Column::Pool3Url
|
||||
| Column::Pool3Worker => (7, "Pools"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum SortKey {
|
||||
@@ -1065,6 +1277,63 @@ mod tests {
|
||||
(rows, view, idx)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn component_health_maps_states_to_the_four_levels() {
|
||||
// Round 13 #3: power/control/fan/board health map to the grey/red/yellow/
|
||||
// green four-state model, and the Health column is in the default view.
|
||||
assert!(DEFAULT_VISIBLE.contains(&Column::Health));
|
||||
|
||||
// A healthy mining miner: power ok, fans all spinning near each other,
|
||||
// boards ok.
|
||||
let mut r = MinerRow {
|
||||
is_mining: true,
|
||||
power_w: 3200.0,
|
||||
fan_rpms: vec![6000.0, 6100.0, 5900.0, 6000.0],
|
||||
expected_fans: Some(4),
|
||||
board_status: vec![BoardHealth::Ok, BoardHealth::Ok, BoardHealth::Ok],
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(r.power_health(), CompHealth::Ok);
|
||||
assert_eq!(r.control_health(), CompHealth::Ok);
|
||||
assert!(r.fan_healths().iter().all(|h| *h == CompHealth::Ok));
|
||||
assert!(r.board_healths().iter().all(|h| *h == CompHealth::Ok));
|
||||
|
||||
// A stopped fan is red, a fan at <50% of its fastest sibling is yellow.
|
||||
r.fan_rpms = vec![6000.0, 0.0, 2000.0, 6000.0];
|
||||
let fans = r.fan_healths();
|
||||
assert_eq!(fans[0], CompHealth::Ok);
|
||||
assert_eq!(fans[1], CompHealth::Down); // stopped
|
||||
assert_eq!(fans[2], CompHealth::Degraded); // 2000 < 0.5 * 6000
|
||||
assert_eq!(fans[3], CompHealth::Ok);
|
||||
|
||||
// A faulted / missing board is red / grey; a slow miner's ok boards go
|
||||
// yellow.
|
||||
r.board_status = vec![BoardHealth::Ok, BoardHealth::Fault, BoardHealth::Missing];
|
||||
r.slow = true;
|
||||
let boards = r.board_healths();
|
||||
assert_eq!(boards[0], CompHealth::Degraded); // ok but the miner is slow
|
||||
assert_eq!(boards[1], CompHealth::Down);
|
||||
assert_eq!(boards[2], CompHealth::Unreachable);
|
||||
|
||||
// A silent miner (no power, no fan, not mining) reads grey for power.
|
||||
let dark = MinerRow::default();
|
||||
assert_eq!(dark.power_health(), CompHealth::Unreachable);
|
||||
|
||||
// Healthier miners score higher, so an ascending Health sort puts the
|
||||
// most-broken first.
|
||||
let broken = r.health_score(HealthFacet::Overall);
|
||||
let healthy = MinerRow {
|
||||
is_mining: true,
|
||||
power_w: 3200.0,
|
||||
fan_rpms: vec![6000.0, 6000.0],
|
||||
expected_fans: Some(2),
|
||||
board_status: vec![BoardHealth::Ok, BoardHealth::Ok],
|
||||
..Default::default()
|
||||
}
|
||||
.health_score(HealthFacet::Overall);
|
||||
assert!(broken < healthy, "broken {broken} should score below healthy {healthy}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn kpis_match_expected_hardware_output() {
|
||||
// This does not hardcode fixture counts: it independently recomputes
|
||||
|
||||
@@ -12,18 +12,18 @@ 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):
|
||||
/// IP, model, errors, hashrate, power, chip temp, firmware, CPU, boards
|
||||
/// (hashboard health), access.
|
||||
const DEFAULT_PROFILE: [Column; 10] = [
|
||||
/// IP, model, health (component icons), hashrate, power, chip temp, firmware,
|
||||
/// CPU, access. The Health column (round 13 #3) replaced the old errors, boards
|
||||
/// (hashboard dots) and status columns.
|
||||
const DEFAULT_PROFILE: [Column; 9] = [
|
||||
Column::Ip,
|
||||
Column::Model,
|
||||
Column::Error,
|
||||
Column::Health,
|
||||
Column::Hashrate,
|
||||
Column::Power,
|
||||
Column::ChipTemp,
|
||||
Column::Firmware,
|
||||
Column::Cpu,
|
||||
Column::Hashboards,
|
||||
Column::Locked,
|
||||
];
|
||||
|
||||
@@ -127,10 +127,12 @@ mod tests {
|
||||
// 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::Health));
|
||||
assert!(view.visible.contains(&Column::Cpu));
|
||||
assert!(view.visible.contains(&Column::Hashboards));
|
||||
assert!(view.visible.contains(&Column::Locked));
|
||||
// The Health column (round 13 #3) replaced these in the default profile.
|
||||
assert!(!view.visible.contains(&Column::Error));
|
||||
assert!(!view.visible.contains(&Column::Hashboards));
|
||||
// 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");
|
||||
|
||||
+249
-134
@@ -28,6 +28,9 @@ const ID_RANGES_APPLY: i32 = 201;
|
||||
const ID_RANGES_CANCEL: i32 = 202;
|
||||
const ID_COLUMNS_OK: i32 = 203;
|
||||
const ID_COLUMNS_CANCEL: i32 = 204;
|
||||
// Column-picker sort buttons (round 13 #1).
|
||||
const ID_COLS_ALPHA: i32 = 231;
|
||||
const ID_COLS_CATEGORIES: i32 = 232;
|
||||
const ID_FILTER_OK: i32 = 205;
|
||||
const ID_FILTER_CANCEL: i32 = 206;
|
||||
const ID_FILTER_RESET: i32 = 210;
|
||||
@@ -76,13 +79,8 @@ const ID_CONFIRM_CANCEL: i32 = 743;
|
||||
// Strong typed-confirmation dialog for flashing firmware.
|
||||
const ID_FLASH_OK: i32 = 744;
|
||||
const ID_FLASH_CANCEL: i32 = 745;
|
||||
// Scan-credentials dialog.
|
||||
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;
|
||||
// Credentials dialog (round 13 #2): a global "all firmwares" login plus a
|
||||
// per-firmware row for every registry firmware, all in one dialog.
|
||||
const ID_FWCREDS_SAVE: i32 = 750;
|
||||
const ID_FWCREDS_RESET: i32 = 751;
|
||||
const ID_FWCREDS_CANCEL: i32 = 752;
|
||||
@@ -279,6 +277,13 @@ 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}";
|
||||
// Component-health icons (round 13 #3): one sentinel per component kind, each
|
||||
// drawn from the operator-supplied Font Awesome SVG and recoloured per component
|
||||
// state. Registered in `register_cell_icons`.
|
||||
const SHAPE_BOLT: &str = "\u{000C}"; // power supply
|
||||
const SHAPE_BRAIN: &str = "\u{000E}"; // control board
|
||||
const SHAPE_FAN: &str = "\u{000F}"; // cooling fan
|
||||
const SHAPE_CHIP: &str = "\u{0010}"; // hashboard
|
||||
|
||||
/// 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;
|
||||
@@ -287,13 +292,17 @@ const SHAPE_PULSE_DOT: &str = "\u{000B}";
|
||||
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] = [
|
||||
let icons: [(&str, &str); 10] = [
|
||||
(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),
|
||||
(SHAPE_BOLT, SVG_BOLT_FULL),
|
||||
(SHAPE_BRAIN, SVG_BRAIN_FULL),
|
||||
(SHAPE_FAN, SVG_FAN_FULL),
|
||||
(SHAPE_CHIP, SVG_CHIP_FULL),
|
||||
];
|
||||
for (sentinel, svg) in icons {
|
||||
let cp = sentinel.chars().next().map(|c| c as u32).unwrap_or(0);
|
||||
@@ -372,6 +381,34 @@ fn encode_status_icon(pal: &Palette, status: &str) -> String {
|
||||
encode_segments(&[(Some(status_kind_color(pal, status)), shape.to_string())])
|
||||
}
|
||||
|
||||
/// The colour a component-health state renders in (round 13 #3): grey =
|
||||
/// unreachable, red = detected but down, yellow = sub-optimal, green = healthy.
|
||||
fn health_color(pal: &Palette, h: crate::model::CompHealth) -> (u8, u8, u8) {
|
||||
use crate::model::CompHealth;
|
||||
match h {
|
||||
CompHealth::Unreachable => pal.label,
|
||||
CompHealth::Down => pal.red,
|
||||
CompHealth::Degraded => pal.amber,
|
||||
CompHealth::Ok => pal.green,
|
||||
}
|
||||
}
|
||||
|
||||
/// Health column: one coloured icon per component (round 13 #3), in the order
|
||||
/// power supply, control board, each fan (front-to-back / top-to-bottom), then
|
||||
/// each hashboard. Replaces the old Errors/Boards/Status columns.
|
||||
fn encode_component_health(pal: &Palette, r: &crate::model::MinerRow) -> String {
|
||||
let mut segs: Vec<(Option<(u8, u8, u8)>, String)> = Vec::new();
|
||||
segs.push((Some(health_color(pal, r.power_health())), SHAPE_BOLT.to_string()));
|
||||
segs.push((Some(health_color(pal, r.control_health())), SHAPE_BRAIN.to_string()));
|
||||
for h in r.fan_healths() {
|
||||
segs.push((Some(health_color(pal, h)), SHAPE_FAN.to_string()));
|
||||
}
|
||||
for h in r.board_healths() {
|
||||
segs.push((Some(health_color(pal, h)), SHAPE_CHIP.to_string()));
|
||||
}
|
||||
encode_segments(&segs)
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -385,6 +422,12 @@ const SVG_BOLT: &str = include_str!("../assets/icons/bolt.svg");
|
||||
// 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");
|
||||
// Component-health icons (round 13 #3): operator-supplied Font Awesome solid
|
||||
// glyphs (no fill attribute -- the renderer injects the per-component colour).
|
||||
const SVG_BOLT_FULL: &str = include_str!("../assets/icons/bolt-solid-full.svg");
|
||||
const SVG_BRAIN_FULL: &str = include_str!("../assets/icons/brain-solid-full.svg");
|
||||
const SVG_FAN_FULL: &str = include_str!("../assets/icons/fan-solid-full.svg");
|
||||
const SVG_CHIP_FULL: &str = include_str!("../assets/icons/microchip-solid-full.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
|
||||
@@ -596,12 +639,12 @@ pub struct App {
|
||||
// The column a header right-click menu targets (remembered across the menu's
|
||||
// nested event loop until an item is chosen).
|
||||
header_menu_col: Option<Column>,
|
||||
// The "Set scan credentials..." dialog.
|
||||
creds_dialog: Widget,
|
||||
// The optional global "all firmwares" login shown at the top of the
|
||||
// Credentials dialog (round 13 #2). Empty when no global credential is set.
|
||||
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.
|
||||
// The Credentials dialog (round 13 #2): the global login above plus one
|
||||
// (firmware name, user field, pass field) row per registry firmware.
|
||||
fwcreds_dialog: Widget,
|
||||
fwcreds_rows: Vec<(String, Widget, Widget)>,
|
||||
// Background access (lock-state) probe.
|
||||
@@ -798,7 +841,7 @@ pub fn build(frame: Widget) -> App {
|
||||
ctl.add(filter_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
let columns_btn = Widget::button(panel, "Columns", ID_COLUMNS);
|
||||
ctl.add(columns_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
let creds_btn = Widget::button(panel, "Set scan credentials...", ID_SCAN_CREDS);
|
||||
let creds_btn = Widget::button(panel, "Credentials", ID_SCAN_CREDS);
|
||||
ctl.add(creds_btn, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 4);
|
||||
root.add_sizer(ctl, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 4);
|
||||
|
||||
@@ -879,7 +922,6 @@ pub fn build(frame: Widget) -> App {
|
||||
pending_flash: None,
|
||||
flashing: false,
|
||||
header_menu_col: None,
|
||||
creds_dialog: frame,
|
||||
creds_user_input: frame,
|
||||
creds_pass_input: frame,
|
||||
fwcreds_dialog: frame,
|
||||
@@ -1012,7 +1054,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::Light | Column::Error | Column::Status | Column::Firmware) {
|
||||
if matches!(c, Column::Hashrate | Column::Health | 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.
|
||||
@@ -1065,6 +1107,8 @@ impl App {
|
||||
.flatten();
|
||||
encode_combined_cell(&self.pal, actual, expected, "/", ratio)
|
||||
}
|
||||
// Health column: one coloured icon per component (round 13 #3).
|
||||
Column::Health => encode_component_health(&self.pal, r),
|
||||
// Boards column: per-hashboard health dots (round 11 #10).
|
||||
Column::Hashboards => encode_board_dots(&self.pal, &r.board_status),
|
||||
Column::TotalChips => {
|
||||
@@ -1102,6 +1146,17 @@ impl App {
|
||||
if matches!(c, Column::Error) {
|
||||
t.dvlc_set_cell_tooltip(disp, ci, &r.errors.join("\n"));
|
||||
}
|
||||
// The Health icons carry a hover tooltip: the component summary,
|
||||
// plus the full error list (which the Health column replaced) so
|
||||
// no error detail is lost (round 13 #3).
|
||||
if matches!(c, Column::Health) {
|
||||
let mut tip = r.health_summary();
|
||||
if !r.errors.is_empty() {
|
||||
tip.push('\n');
|
||||
tip.push_str(&r.errors.join("\n"));
|
||||
}
|
||||
t.dvlc_set_cell_tooltip(disp, ci, &tip);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(row) = top {
|
||||
@@ -2011,84 +2066,50 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// Build (but do not show) the "Set scan credentials..." dialog: HTTP
|
||||
/// credentials used for firmware auto-discovery on password-protected
|
||||
/// miners, prefilled from whatever is already saved on disk.
|
||||
fn build_creds_dialog(&mut self) -> Widget {
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Set scan credentials");
|
||||
let root = Widget::box_sizer(true);
|
||||
let (saved_user, saved_pass) = credentials::load_credentials().unwrap_or_default();
|
||||
// Never re-display the saved password in plaintext. Leave the field
|
||||
// blank; a blank password on Save keeps whatever is already stored (see
|
||||
// apply_creds_save), so opening this dialog to change only the username
|
||||
// does not require -- or reveal -- the password.
|
||||
let pass_hint = if saved_pass.is_empty() {
|
||||
"HTTP credentials for firmware auto-discovery on password-protected miners."
|
||||
} else {
|
||||
"HTTP credentials for firmware auto-discovery. A password is already saved; leave Password blank to keep it, or type a new one to replace it."
|
||||
};
|
||||
let hint = Widget::static_text(dlg, pass_hint);
|
||||
root.add(hint, 0, sf::BORDER_ALL, 8);
|
||||
let user_row = Widget::box_sizer(false);
|
||||
user_row.add(Widget::static_text(dlg, "Username:"), 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
let user_input = Widget::text_ctrl(dlg, false);
|
||||
user_input.set_value(&saved_user);
|
||||
user_input.set_min_size(200, -1);
|
||||
user_row.add(user_input, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
root.add_sizer(user_row, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let pass_row = Widget::box_sizer(false);
|
||||
pass_row.add(Widget::static_text(dlg, "Password:"), 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_ALL, 6);
|
||||
let pass_input = Widget::text_ctrl(dlg, false);
|
||||
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);
|
||||
btns.add(Widget::button(dlg, "Clear", ID_CREDS_CLEAR), 0, sf::BORDER_ALL, 6);
|
||||
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(460, 220);
|
||||
dlg.fit(dlg);
|
||||
self.creds_dialog = dlg;
|
||||
self.creds_user_input = user_input;
|
||||
self.creds_pass_input = pass_input;
|
||||
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.
|
||||
/// Build (but do not show) the Credentials dialog (round 13 #2): a single
|
||||
/// place for every login the scanner uses. The top row is the optional global
|
||||
/// "all firmwares" login (applied to any firmware without an override); below
|
||||
/// it is one row per firmware in the asic-rs registry, each prefilled from the
|
||||
/// saved override or the firmware's shipped default. Editing a firmware row
|
||||
/// away from its default makes it an override; setting it back clears it.
|
||||
/// (Formerly a global-login dialog with the per-firmware editor behind a
|
||||
/// sub-button.)
|
||||
fn build_firmware_creds_dialog(&mut self) -> Widget {
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Per-firmware default logins");
|
||||
let dlg = Widget::dialog(frame, "Credentials");
|
||||
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.",
|
||||
"Logins used when auto-discovering password-protected miners. The global login\napplies to every firmware without its own row below. Blank fields mean no login;\nfirmware rows left at their shipped default are not saved as overrides.",
|
||||
),
|
||||
0,
|
||||
sf::BORDER_ALL,
|
||||
8,
|
||||
);
|
||||
// Global "all firmwares" login. Never re-display the saved password in
|
||||
// plaintext: leave it blank, and a blank password on Save keeps whatever
|
||||
// is already stored (see apply_firmware_creds_save).
|
||||
let (saved_user, saved_pass) = credentials::load_credentials().unwrap_or_default();
|
||||
let g_hint = if saved_pass.is_empty() {
|
||||
"All firmwares"
|
||||
} else {
|
||||
"All firmwares (password saved; blank keeps it)"
|
||||
};
|
||||
let grow = Widget::box_sizer(false);
|
||||
let glabel = Widget::static_text(dlg, g_hint);
|
||||
glabel.set_min_size(150, -1);
|
||||
grow.add(glabel, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let user_input = Widget::text_ctrl(dlg, false);
|
||||
user_input.set_min_size(150, -1);
|
||||
user_input.set_value(&saved_user);
|
||||
grow.add(user_input, 0, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
let pass_input = Widget::text_ctrl(dlg, false);
|
||||
pass_input.set_min_size(150, -1);
|
||||
grow.add(pass_input, 1, sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT, 6);
|
||||
root.add_sizer(grow, 0, sf::EXPAND | sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_TOP, 6);
|
||||
self.creds_user_input = user_input;
|
||||
self.creds_pass_input = pass_input;
|
||||
// Column headers.
|
||||
let head = Widget::box_sizer(false);
|
||||
let h_fw = Widget::static_text(dlg, "Firmware");
|
||||
@@ -2139,9 +2160,31 @@ impl App {
|
||||
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.
|
||||
/// Persist the Credentials dialog (round 13 #2): the global "all firmwares"
|
||||
/// login (top row) plus the per-firmware overrides. A firmware row that
|
||||
/// differs from its shipped default becomes an override; a row equal to the
|
||||
/// default clears it.
|
||||
fn apply_firmware_creds_save(&mut self) {
|
||||
// Global login first. A blank password means "keep the saved password"
|
||||
// (the field is never pre-filled in plaintext); a blank user AND password
|
||||
// clears the global login entirely.
|
||||
let g_user = self.creds_user_input.get_value();
|
||||
let mut g_pass = self.creds_pass_input.get_value();
|
||||
if g_pass.is_empty() {
|
||||
if let Some((_, saved_pass)) = credentials::load_credentials() {
|
||||
g_pass = saved_pass;
|
||||
}
|
||||
}
|
||||
let global_result = if g_user.is_empty() && g_pass.is_empty() {
|
||||
credentials::clear_credentials()
|
||||
} else {
|
||||
credentials::save_credentials(&g_user, &g_pass)
|
||||
};
|
||||
if let Err(e) = global_result {
|
||||
wx_rs::set_status_text(&format!("failed to save global login: {e}"));
|
||||
return;
|
||||
}
|
||||
// Per-firmware overrides.
|
||||
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();
|
||||
@@ -2156,54 +2199,29 @@ impl App {
|
||||
self.fwcreds_dialog.close(1);
|
||||
let n = map.len();
|
||||
wx_rs::set_status_text(&format!(
|
||||
"per-firmware logins saved ({n} override{})",
|
||||
"credentials saved ({n} firmware 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();
|
||||
// A blank password field means "keep the saved password" (the dialog no
|
||||
// longer pre-fills it in plaintext), so fall back to the stored value.
|
||||
if pass.is_empty() {
|
||||
if let Some((_, saved_pass)) = credentials::load_credentials() {
|
||||
pass = saved_pass;
|
||||
}
|
||||
}
|
||||
match credentials::save_credentials(&user, &pass) {
|
||||
Ok(()) => {
|
||||
self.creds_dialog.close(1);
|
||||
wx_rs::set_status_text("scan credentials saved");
|
||||
}
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to save credentials: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_creds_clear(&mut self) {
|
||||
match credentials::clear_credentials() {
|
||||
Ok(()) => {
|
||||
self.creds_dialog.close(1);
|
||||
wx_rs::set_status_text("scan credentials cleared");
|
||||
}
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to clear credentials: {e}")),
|
||||
/// Reset every firmware row to its shipped default and clear the global login,
|
||||
/// dropping all saved overrides.
|
||||
fn apply_firmware_creds_reset(&mut self) {
|
||||
self.creds_user_input.set_value("");
|
||||
self.creds_pass_input.set_value("");
|
||||
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);
|
||||
}
|
||||
let per_fw = credentials::clear_firmware_credentials();
|
||||
let global = credentials::clear_credentials();
|
||||
match per_fw.and(global) {
|
||||
Ok(()) => wx_rs::set_status_text("credentials reset to defaults"),
|
||||
Err(e) => wx_rs::set_status_text(&format!("failed to reset credentials: {e}")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2537,6 +2555,21 @@ impl App {
|
||||
Some((Column::HashrateRel, false)) => None,
|
||||
_ => Some((Column::Hashrate, true)),
|
||||
}
|
||||
} else if col == Column::Health {
|
||||
// The Health header cycles overall health, then each component facet
|
||||
// (power, fans, hashboards), each asc then desc, then unsorted, so the
|
||||
// fleet can be ordered by whichever component matters (round 13 #3).
|
||||
match self.view.sort {
|
||||
Some((Column::Health, true)) => Some((Column::Health, false)),
|
||||
Some((Column::Health, false)) => Some((Column::HealthPower, true)),
|
||||
Some((Column::HealthPower, true)) => Some((Column::HealthPower, false)),
|
||||
Some((Column::HealthPower, false)) => Some((Column::HealthFans, true)),
|
||||
Some((Column::HealthFans, true)) => Some((Column::HealthFans, false)),
|
||||
Some((Column::HealthFans, false)) => Some((Column::HealthBoards, true)),
|
||||
Some((Column::HealthBoards, true)) => Some((Column::HealthBoards, false)),
|
||||
Some((Column::HealthBoards, false)) => None,
|
||||
_ => Some((Column::Health, true)),
|
||||
}
|
||||
} else {
|
||||
match self.view.sort {
|
||||
Some((c, true)) if c == col => Some((col, false)),
|
||||
@@ -2632,6 +2665,18 @@ impl App {
|
||||
Some((Column::HashrateRel, asc)) if *c == Column::Hashrate => {
|
||||
title.push_str(if asc { " %^" } else { " %v" })
|
||||
}
|
||||
// Health facet sorts are pseudo-columns shown on the Health header
|
||||
// (round 13 #3): a short tag names the active component (Pwr/Fan/
|
||||
// Brd) beside the chevron, since a native header can't carry an SVG.
|
||||
Some((Column::HealthPower, asc)) if *c == Column::Health => {
|
||||
title.push_str(if asc { " Pwr ^" } else { " Pwr v" })
|
||||
}
|
||||
Some((Column::HealthFans, asc)) if *c == Column::Health => {
|
||||
title.push_str(if asc { " Fan ^" } else { " Fan v" })
|
||||
}
|
||||
Some((Column::HealthBoards, asc)) if *c == Column::Health => {
|
||||
title.push_str(if asc { " Brd ^" } else { " Brd v" })
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
t.dvlc_set_col_title(i, &title);
|
||||
@@ -2847,11 +2892,25 @@ impl App {
|
||||
let frame = Widget::main_frame();
|
||||
let dlg = Widget::dialog(frame, "Choose columns");
|
||||
let root = Widget::box_sizer(true);
|
||||
// Short, two-line hint so it doesn't force the dialog wide (round 13 #1).
|
||||
let hint = Widget::static_text(
|
||||
dlg,
|
||||
"Check to show a metric; drag rows to reorder (IP is always first). Shift/Ctrl-click or drag to select several.",
|
||||
"Check to show a column; drag rows to reorder (IP stays first).\nDrag or Shift/Ctrl-click to select several; Ctrl+A selects all.",
|
||||
);
|
||||
root.add(hint, 0, sf::BORDER_ALL, 6);
|
||||
// Sort the rows in the picker (round 13 #1): Alphabetical by title, or
|
||||
// grouped into Categories. These reorder the picker only; nothing applies
|
||||
// until OK.
|
||||
let sortrow = Widget::box_sizer(false);
|
||||
sortrow.add(
|
||||
Widget::static_text(dlg, "Sort:"),
|
||||
0,
|
||||
sf::ALIGN_CENTRE_VERTICAL | sf::BORDER_LEFT | sf::BORDER_RIGHT,
|
||||
6,
|
||||
);
|
||||
sortrow.add(Widget::button(dlg, "Alphabetical", ID_COLS_ALPHA), 0, sf::BORDER_RIGHT, 6);
|
||||
sortrow.add(Widget::button(dlg, "Categories", ID_COLS_CATEGORIES), 0, sf::BORDER_RIGHT, 6);
|
||||
root.add_sizer(sortrow, 0, sf::BORDER_LEFT | sf::BORDER_RIGHT | sf::BORDER_BOTTOM, 4);
|
||||
// Base list is registry order; the wx order array lists items in the
|
||||
// current arranged order, encoding checked = visible (a negative value
|
||||
// ~idx means item idx unchecked).
|
||||
@@ -2876,12 +2935,47 @@ impl App {
|
||||
btns.add(Widget::button(dlg, "Cancel", ID_COLUMNS_CANCEL), 0, sf::BORDER_ALL, 6);
|
||||
root.add_sizer(btns, 0, sf::BORDER_ALL, 6);
|
||||
root.set_sizer_on(dlg);
|
||||
// Keep the picker compact: the row column is 190px, so ~340px is enough
|
||||
// (round 13 #1). fit() sizes to content but never below this floor.
|
||||
dlg.set_min_size(360, 480);
|
||||
dlg.fit(dlg);
|
||||
self.columns_dialog = dlg;
|
||||
self.columns_list = list;
|
||||
dlg
|
||||
}
|
||||
|
||||
/// Reorder the column picker's rows (round 13 #1) by title (Alphabetical) or
|
||||
/// by category group, preserving each row's checked state. Applies to the
|
||||
/// picker only; the view changes on OK.
|
||||
fn apply_columns_sort(&self, by_category: bool) {
|
||||
let base = Self::selectable_columns();
|
||||
let titles: Vec<&str> = base.iter().map(|c| c.title()).collect();
|
||||
let mut pairs: Vec<(usize, bool)> = self
|
||||
.columns_list
|
||||
.reorder_get_order()
|
||||
.iter()
|
||||
.map(|&e| if e < 0 { ((!e) as usize, false) } else { (e as usize, true) })
|
||||
.collect();
|
||||
if by_category {
|
||||
// Category rank, then registry order within the group (idx order).
|
||||
pairs.sort_by_key(|&(idx, _)| {
|
||||
let (rank, _) = base.get(idx).map(|c| c.category()).unwrap_or((u8::MAX, ""));
|
||||
(rank, idx)
|
||||
});
|
||||
} else {
|
||||
pairs.sort_by(|&(a, _), &(b, _)| {
|
||||
let ta = base.get(a).map(|c| c.title()).unwrap_or("");
|
||||
let tb = base.get(b).map(|c| c.title()).unwrap_or("");
|
||||
ta.to_lowercase().cmp(&tb.to_lowercase())
|
||||
});
|
||||
}
|
||||
let order: Vec<i32> = pairs
|
||||
.iter()
|
||||
.map(|&(idx, checked)| if checked { idx as i32 } else { !(idx as i32) })
|
||||
.collect();
|
||||
self.columns_list.reorder_set_order(&order, &titles);
|
||||
}
|
||||
|
||||
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.
|
||||
@@ -2905,9 +2999,12 @@ impl App {
|
||||
self.view.order = new_order;
|
||||
self.view.visible = visible;
|
||||
}
|
||||
// Drop the sort if its column was hidden (IP is always shown).
|
||||
// Drop the sort if its column was hidden (IP is always shown). A sort-only
|
||||
// pseudo-column (relative hashrate, a Health facet) maps to its display
|
||||
// column for this check so it survives as long as that column is shown.
|
||||
if let Some((c, _)) = self.view.sort {
|
||||
if c != Column::Ip && !self.view.visible.contains(&c) {
|
||||
let home = Self::sort_home_col(c);
|
||||
if home != Column::Ip && !self.view.visible.contains(&home) {
|
||||
self.view.sort = None;
|
||||
}
|
||||
}
|
||||
@@ -2915,6 +3012,16 @@ impl App {
|
||||
self.rebuild_table();
|
||||
}
|
||||
|
||||
/// Map a sort-only pseudo-column to the visible column that hosts its sort
|
||||
/// (round 11 #16 / round 13 #3); every other column maps to itself.
|
||||
fn sort_home_col(c: Column) -> Column {
|
||||
match c {
|
||||
Column::HashrateRel => Column::Hashrate,
|
||||
Column::HealthPower | Column::HealthFans | Column::HealthBoards => Column::Health,
|
||||
other => other,
|
||||
}
|
||||
}
|
||||
|
||||
/// Operator labels offered for a column, by type.
|
||||
fn filter_ops(col: Column) -> &'static [&'static str] {
|
||||
if col.is_numeric() {
|
||||
@@ -3230,6 +3337,8 @@ impl App {
|
||||
ID_COLUMNS => return Some(self.build_columns_dialog()),
|
||||
ID_COLUMNS_OK => self.apply_columns(),
|
||||
ID_COLUMNS_CANCEL => self.columns_dialog.close(0),
|
||||
ID_COLS_ALPHA => self.apply_columns_sort(false),
|
||||
ID_COLS_CATEGORIES => self.apply_columns_sort(true),
|
||||
ID_PRESETS => return Some(self.build_presets_dialog()),
|
||||
ID_PICSSH_OK => self.apply_pic_probe(),
|
||||
ID_PICSSH_CANCEL => {
|
||||
@@ -3261,11 +3370,7 @@ impl App {
|
||||
self.pending_flash = None;
|
||||
self.flash_confirm_dialog.close(0);
|
||||
}
|
||||
ID_SCAN_CREDS => return Some(self.build_creds_dialog()),
|
||||
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_SCAN_CREDS => 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),
|
||||
@@ -3383,7 +3488,7 @@ impl App {
|
||||
// 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) {
|
||||
if matches!(c, Column::Health | Column::Hashboards | Column::Locked | Column::Light | Column::Status) {
|
||||
continue;
|
||||
}
|
||||
let want = c.cell(r);
|
||||
@@ -3426,11 +3531,21 @@ impl App {
|
||||
// (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);
|
||||
let health_col = cols.iter().position(|c| *c == Column::Health);
|
||||
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:?}"));
|
||||
}
|
||||
// Health column (round 13 #3): the power (bolt) and control-board (brain)
|
||||
// icons are always emitted, plus a chip icon per hashboard for a mining
|
||||
// miner; verify the sentinels are present.
|
||||
if let (Some(hc), Some(row)) = (health_col, find("10.255.1.166")) {
|
||||
let raw = t.dvlc_get_cell(row, hc).unwrap_or_default();
|
||||
check("Health column renders the power + control-board + chip sentinels",
|
||||
raw.contains('\u{000C}') && raw.contains('\u{000E}') && raw.contains('\u{0010}'),
|
||||
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",
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
Subject: [PATCH 0008] antminer: resolve Z15J / unknown-model algorithm
|
||||
|
||||
Round-13 #4/#5. A Z15J reports its model as "ANTMINER Z15J", which asic-rs' alias
|
||||
table did not recognise, so it deserialised to AntMinerModel::Unknown and its
|
||||
hash algorithm resolved to HashAlgorithm::Unknown. That left the miner's Sol/s
|
||||
hashrate un-bucketed as "unknown hashrate" in the GUI, even though the round-10
|
||||
unit reinterpretation already read the value correctly. (The older ANTMINER Z15
|
||||
matched the table and reported Equihash; only the J revision was affected.)
|
||||
|
||||
Two layers of fix:
|
||||
- models.rs / hardware.rs: add a first-class Z15J model (Equihash, same 3-chip
|
||||
x 3-board / 2-fan chassis profile as the Z15) so it parses to a named model
|
||||
and carries the right algorithm, and shows a clean "Z15J" model name.
|
||||
- v2020 backend: when the alias table still can't place a model, infer the
|
||||
algorithm from the Antminer family letter for the lines that are
|
||||
single-algorithm end to end (Z -> Equihash, L -> Scrypt, S/T -> SHA-256), so
|
||||
other not-yet-tabled models are bucketed sensibly instead of Unknown.
|
||||
Ambiguous families (K spans Kadena/KHeavyHash/Eaglesong; DR is Blake256 while
|
||||
D is X11) are deliberately left Unknown rather than guessed wrong.
|
||||
|
||||
Live-verified on 10.5.1.{50,72,196,205}: Z15 and Z15J now both report
|
||||
algo=Equihash with their real Sol/s rates (e.g. 305k, 132k; 0 on idle units).
|
||||
The antminer crate tests pass, plus two new unit tests (z15j_parses_as_equihash,
|
||||
unknown_models_infer_algo_from_family_letter).
|
||||
|
||||
diff --git a/vendor/asic-rs-makes-antminer/src/models.rs b/vendor/asic-rs-makes-antminer/src/models.rs
|
||||
--- a/vendor/asic-rs-makes-antminer/src/models.rs
|
||||
+++ b/vendor/asic-rs-makes-antminer/src/models.rs
|
||||
@@ -78,6 +78,9 @@
|
||||
#[serde(alias = "ANTMINER Z15 PRO")]
|
||||
#[algorithm(HashAlgorithm::Equihash)]
|
||||
Z15Pro,
|
||||
+ #[serde(alias = "ANTMINER Z15J")]
|
||||
+ #[algorithm(HashAlgorithm::Equihash)]
|
||||
+ Z15J,
|
||||
#[serde(alias = "ANTMINER S17")]
|
||||
#[algorithm(HashAlgorithm::SHA256)]
|
||||
S17,
|
||||
@@ -281,12 +284,22 @@
|
||||
(AntMinerModel::E9Pro, HashAlgorithm::EtHash),
|
||||
(AntMinerModel::Z15, HashAlgorithm::Equihash),
|
||||
(AntMinerModel::Z15Pro, HashAlgorithm::Equihash),
|
||||
+ (AntMinerModel::Z15J, HashAlgorithm::Equihash),
|
||||
] {
|
||||
assert_eq!(model.hash_algorithm(), expected, "{model}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
+ fn z15j_parses_as_equihash() {
|
||||
+ // The Z15J reports "ANTMINER Z15J"; before it had an alias it fell back to
|
||||
+ // Unknown, which left its Sol/s hashrate un-bucketed (round 13 #5).
|
||||
+ let model = AntMinerModel::from_str("ANTMINER Z15J").unwrap();
|
||||
+ assert_eq!(model, AntMinerModel::Z15J);
|
||||
+ assert_eq!(model.hash_algorithm(), HashAlgorithm::Equihash);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
fn unknown_model_uses_unknown_algorithm() {
|
||||
let model = AntMinerModel::from_str("ANTMINER S99").unwrap();
|
||||
|
||||
diff --git a/vendor/asic-rs-makes-antminer/src/hardware.rs b/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
--- a/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
+++ b/vendor/asic-rs-makes-antminer/src/hardware.rs
|
||||
@@ -97,6 +97,10 @@
|
||||
AntMinerModel::Z15Pro => Self {
|
||||
fans: Some(2),
|
||||
boards: Some(vec![Some(6), Some(6), Some(6)]),
|
||||
+ },
|
||||
+ AntMinerModel::Z15J => Self {
|
||||
+ fans: Some(2),
|
||||
+ boards: Some(vec![Some(3), Some(3), Some(3)]),
|
||||
},
|
||||
AntMinerModel::S17 => Self {
|
||||
fans: Some(4),
|
||||
diff --git a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
--- a/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
+++ b/vendor/asic-rs-firmwares-antminer/src/backends/v2020/mod.rs
|
||||
@@ -201,10 +201,41 @@
|
||||
Value::Object(payload)
|
||||
}
|
||||
|
||||
+/// Infer an Antminer's hash algorithm from its model-family letter, for models
|
||||
+/// asic-rs' alias table doesn't recognise (round 13 #5). Only the families whose
|
||||
+/// entire product line shares one algorithm are inferred; anything ambiguous
|
||||
+/// (the K-series spans Kadena/KHeavyHash/Eaglesong, DR is Blake256 while D is
|
||||
+/// X11) is left Unknown rather than guessed wrong.
|
||||
+fn infer_antminer_algo(model: &str) -> HashAlgorithm {
|
||||
+ let upper = model.to_ascii_uppercase();
|
||||
+ let name = upper
|
||||
+ .strip_prefix("ANTMINER ")
|
||||
+ .unwrap_or(&upper)
|
||||
+ .trim_start();
|
||||
+ match name.chars().next() {
|
||||
+ // Z9 / Z11 / Z15 / Z15 Pro / Z15J -- the whole Z line is Equihash.
|
||||
+ Some('Z') => HashAlgorithm::Equihash,
|
||||
+ // L3+ / L7 / L9 / L11 -- the whole L line is Scrypt.
|
||||
+ Some('L') => HashAlgorithm::Scrypt,
|
||||
+ // S9..S21 and T9..T21 (and future revisions) are all SHA-256.
|
||||
+ Some('S') | Some('T') => HashAlgorithm::SHA256,
|
||||
+ _ => HashAlgorithm::Unknown,
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
impl AntMinerV2020 {
|
||||
pub fn new(ip: IpAddr, model: impl MinerModel) -> Self {
|
||||
let auth = Self::default_auth();
|
||||
- let algo = model.hash_algorithm();
|
||||
+ // asic-rs maps a model string to its algorithm through a fixed alias
|
||||
+ // table; a model that is not in the table (a Z15J, a not-yet-added
|
||||
+ // S-series, ...) resolves to HashAlgorithm::Unknown, which then leaves the
|
||||
+ // miner's hashrate un-bucketed ("unknown hashrate", round 13 #5). When the
|
||||
+ // table can't place the model, infer the algorithm from its Antminer
|
||||
+ // family letter for the lines that are single-algorithm end to end.
|
||||
+ let algo = match model.hash_algorithm() {
|
||||
+ HashAlgorithm::Unknown => infer_antminer_algo(&model.to_string()),
|
||||
+ known => known,
|
||||
+ };
|
||||
AntMinerV2020 {
|
||||
ip,
|
||||
rpc: AntMinerRPCAPI::new(ip),
|
||||
@@ -1431,6 +1462,21 @@
|
||||
};
|
||||
|
||||
#[test]
|
||||
+ fn unknown_models_infer_algo_from_family_letter() {
|
||||
+ // Round 13 #5: a model outside asic-rs' alias table must still resolve a
|
||||
+ // sensible algorithm from its Antminer family letter instead of Unknown.
|
||||
+ assert_eq!(infer_antminer_algo("ANTMINER Z15J"), HashAlgorithm::Equihash);
|
||||
+ assert_eq!(infer_antminer_algo("Z9"), HashAlgorithm::Equihash);
|
||||
+ assert_eq!(infer_antminer_algo("ANTMINER L15"), HashAlgorithm::Scrypt);
|
||||
+ assert_eq!(infer_antminer_algo("ANTMINER S23"), HashAlgorithm::SHA256);
|
||||
+ assert_eq!(infer_antminer_algo("ANTMINER T23"), HashAlgorithm::SHA256);
|
||||
+ // Ambiguous / unrelated families stay Unknown (K-series spans three
|
||||
+ // algorithms; a bare unknown string has no family).
|
||||
+ assert_eq!(infer_antminer_algo("ANTMINER KS7"), HashAlgorithm::Unknown);
|
||||
+ assert_eq!(infer_antminer_algo("WHATSMINER M30"), HashAlgorithm::Unknown);
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
fn set_miner_conf_payload_matches_cgi_contract_for_pause_resume() {
|
||||
let pre = json!({
|
||||
"pools": [
|
||||
+13
-1
@@ -10,7 +10,7 @@
|
||||
+pub use widgets::*;
|
||||
--- a/src/widgets.rs
|
||||
+++ b/src/widgets.rs
|
||||
@@ -0,0 +1,814 @@
|
||||
@@ -0,0 +1,826 @@
|
||||
+// 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).
|
||||
@@ -94,6 +94,7 @@
|
||||
+ 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_reorder_set_order(win: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char);
|
||||
+ 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);
|
||||
@@ -687,6 +688,17 @@
|
||||
+ buf.into_iter().take(n.max(0) as usize).collect()
|
||||
+ }
|
||||
+
|
||||
+ /// Repopulate a `reorder_list` in a new order (same `[idx | !idx]` encoding
|
||||
+ /// and same base-index `items` array as `reorder_list`). Used by the column
|
||||
+ /// picker's Alphabetical / Categories sort buttons.
|
||||
+ pub fn reorder_set_order(&self, order: &[i32], items: &[&str]) {
|
||||
+ 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();
|
||||
+ unsafe {
|
||||
+ notsafe::wxbr_reorder_set_order(self.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // ---- popup menu ----
|
||||
+
|
||||
+ pub fn menu_new() -> Widget {
|
||||
|
||||
+181
-66
@@ -1,6 +1,6 @@
|
||||
--- a/cpp_src/widgets_bridge.cpp
|
||||
+++ b/cpp_src/widgets_bridge.cpp
|
||||
@@ -0,0 +1,1622 @@
|
||||
@@ -0,0 +1,1737 @@
|
||||
+// 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).
|
||||
@@ -169,6 +169,13 @@
|
||||
+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)
|
||||
+// Component-health icons (round 13 #3): SVG-backed and registered from the Rust
|
||||
+// side, recoloured per component state (grey/red/yellow/green) by DrawShape's
|
||||
+// SVG path. Blank if unregistered.
|
||||
+const wxUniChar SHAPE_BOLT = 0x0C; // power supply
|
||||
+const wxUniChar SHAPE_BRAIN = 0x0E; // control board
|
||||
+const wxUniChar SHAPE_FAN = 0x0F; // cooling fan
|
||||
+const wxUniChar SHAPE_CHIP = 0x10; // hashboard
|
||||
+const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
|
||||
+
|
||||
+// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a
|
||||
@@ -182,7 +189,8 @@
|
||||
+ 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) {
|
||||
+ c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT ||
|
||||
+ c == SHAPE_BOLT || c == SHAPE_BRAIN || c == SHAPE_FAN || c == SHAPE_CHIP) {
|
||||
+ out = c;
|
||||
+ return true;
|
||||
+ }
|
||||
@@ -1298,19 +1306,88 @@
|
||||
+// 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;
|
||||
+// as wxbr_rearrange_get_order. All pointer interaction is handled explicitly
|
||||
+// (round 13 #1) so a single control supports both drag-to-reorder AND
|
||||
+// drag-to-select: a drag that starts on an already-selected row moves that group
|
||||
+// (reorder), a drag that starts on an unselected row rubber-band-selects the
|
||||
+// range it sweeps. Keyboard: Ctrl+A selects all, Ctrl/Shift+Up/Down extend the
|
||||
+// selection. (The old wxEVT_LIST_BEGIN_DRAG binding intercepted every drag as a
|
||||
+// reorder, which silently disabled rubber-band selection.)
|
||||
+static wxVector<long> g_reorder_drag; // item DATA currently being reordered
|
||||
+static wxListCtrl* g_reorder_list = nullptr;
|
||||
+static long g_press_row = -1; // row under the last left-press (-1 = none/checkbox)
|
||||
+static wxPoint g_press_pos; // position of that press
|
||||
+static bool g_press_row_selected = false;
|
||||
+static int g_reorder_mode = 0; // 0 = none, 1 = reorder, 2 = rubber-band
|
||||
+static long g_rubber_anchor = -1;
|
||||
+
|
||||
+// Set the selection to the inclusive row range [a,b] (order-independent). When
|
||||
+// `additive` (Ctrl held) the existing selection is kept and the range added.
|
||||
+static void ReorderSelectRange(wxListCtrl* lc, long a, long b, bool additive) {
|
||||
+ if (a < 0) a = 0;
|
||||
+ long lo = a < b ? a : b;
|
||||
+ long hi = a < b ? b : a;
|
||||
+ int count = lc->GetItemCount();
|
||||
+ for (int i = 0; i < count; i++) {
|
||||
+ bool inRange = (i >= lo && i <= hi);
|
||||
+ bool keep = additive && (lc->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED);
|
||||
+ lc->SetItemState(i, (inRange || keep) ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// Move the rows whose DATA is in g_reorder_drag so they land just before the row
|
||||
+// under `pos` (or at the end when dropped past the last row / onto a dragged row),
|
||||
+// preserving each row's checked state.
|
||||
+static void ReorderMoveTo(wxListCtrl* lc, const wxPoint& pos) {
|
||||
+ 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(pos, 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);
|
||||
+ if (isDragged(result[i].data))
|
||||
+ lc->SetItemState((long)i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+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);
|
||||
+ // Narrower than before so the picker dialog is not over-wide (round 13 #1).
|
||||
+ lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 190);
|
||||
+ for (int i = 0; i < n; i++) {
|
||||
+ int enc = order[i];
|
||||
+ int idx = enc < 0 ? ~enc : enc;
|
||||
@@ -1346,69 +1423,91 @@
|
||||
+ 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;
|
||||
+ };
|
||||
+ // Left-press: remember the row and whether it was already selected, so a
|
||||
+ // following drag can choose reorder vs rubber-band. A press on the checkbox
|
||||
+ // (state icon) never starts a drag, so toggling still works. Skip() so the
|
||||
+ // control still does its normal focus/selection/checkbox handling.
|
||||
+ lc->Bind(wxEVT_LEFT_DOWN, [lc](wxMouseEvent& e) {
|
||||
+ 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]);
|
||||
+ long row = lc->HitTest(e.GetPosition(), flags);
|
||||
+ g_reorder_list = lc;
|
||||
+ g_reorder_mode = 0;
|
||||
+ if (flags & wxLIST_HITTEST_ONITEMSTATEICON) {
|
||||
+ g_press_row = -1; // checkbox click: don't drag
|
||||
+ } else {
|
||||
+ g_press_row = row;
|
||||
+ g_press_pos = e.GetPosition();
|
||||
+ g_press_row_selected =
|
||||
+ (row >= 0) && (lc->GetItemState(row, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED);
|
||||
+ }
|
||||
+ 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;
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ // Motion with the left button down: once past a small threshold, start either a
|
||||
+ // reorder (press began on a selected row) or a rubber-band selection.
|
||||
+ lc->Bind(wxEVT_MOTION, [lc](wxMouseEvent& e) {
|
||||
+ if (!e.LeftIsDown() || g_reorder_list != lc || g_press_row < 0) { e.Skip(); return; }
|
||||
+ wxPoint pos = e.GetPosition();
|
||||
+ if (g_reorder_mode == 0) {
|
||||
+ long dx = pos.x - g_press_pos.x, dy = pos.y - g_press_pos.y;
|
||||
+ if (dx < 0) dx = -dx;
|
||||
+ if (dy < 0) dy = -dy;
|
||||
+ if (dx < 4 && dy < 4) { e.Skip(); return; }
|
||||
+ if (g_press_row_selected) {
|
||||
+ g_reorder_mode = 1; // reorder the current selection
|
||||
+ g_reorder_drag.clear();
|
||||
+ 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));
|
||||
+ }
|
||||
+ if (g_reorder_drag.empty()) g_reorder_mode = 0;
|
||||
+ } else {
|
||||
+ g_reorder_mode = 2; // rubber-band select from the press row
|
||||
+ g_rubber_anchor = g_press_row;
|
||||
+ }
|
||||
+ }
|
||||
+ 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);
|
||||
+ if (g_reorder_mode == 2) {
|
||||
+ int flags = 0;
|
||||
+ long cur = lc->HitTest(pos, flags);
|
||||
+ if (cur < 0) cur = (pos.y < 0) ? 0 : (lc->GetItemCount() - 1);
|
||||
+ ReorderSelectRange(lc, g_rubber_anchor, cur, e.ControlDown());
|
||||
+ return; // we own the selection during a rubber-band; don't Skip
|
||||
+ }
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ // Release: complete a reorder if one was in progress, then reset.
|
||||
+ lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
|
||||
+ if (g_reorder_list == lc && g_reorder_mode == 1 && !g_reorder_drag.empty())
|
||||
+ ReorderMoveTo(lc, e.GetPosition());
|
||||
+ g_reorder_drag.clear();
|
||||
+ g_reorder_list = nullptr;
|
||||
+ g_reorder_mode = 0;
|
||||
+ g_press_row = -1;
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ // Keyboard: Ctrl+A selects all; Ctrl/Shift+Down/Up extend the selection one row
|
||||
+ // (round 13 #1). Everything else falls through to the control.
|
||||
+ lc->Bind(wxEVT_CHAR_HOOK, [lc](wxKeyEvent& e) {
|
||||
+ int key = e.GetKeyCode();
|
||||
+ int count = lc->GetItemCount();
|
||||
+ if (e.ControlDown() && (key == 'A' || key == 'a')) {
|
||||
+ for (int i = 0; i < count; i++)
|
||||
+ lc->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
+ return; // consume
|
||||
+ }
|
||||
+ if ((key == WXK_DOWN || key == WXK_UP) && (e.ControlDown() || e.ShiftDown()) && count > 0) {
|
||||
+ long focus = lc->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
||||
+ if (focus < 0) focus = lc->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
+ if (focus < 0) focus = (key == WXK_DOWN) ? -1 : count;
|
||||
+ long next = (key == WXK_DOWN) ? focus + 1 : focus - 1;
|
||||
+ if (next < 0) next = 0;
|
||||
+ if (next > count - 1) next = count - 1;
|
||||
+ lc->SetItemState(next, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
|
||||
+ wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
|
||||
+ lc->EnsureVisible(next);
|
||||
+ return; // consume
|
||||
+ }
|
||||
+ e.Skip();
|
||||
+ });
|
||||
+ return (void*)lc;
|
||||
+}
|
||||
@@ -1424,6 +1523,22 @@
|
||||
+ return n;
|
||||
+}
|
||||
+
|
||||
+// Repopulate the list in a new order (round 13 #1: the Alphabetical / Categories
|
||||
+// sort buttons). Same [idx | ~idx] encoding as construction; `items` is the same
|
||||
+// base-index-keyed title array. The Rust side preserves each row's checked state
|
||||
+// by carrying it in the sign of the order entries.
|
||||
+void wxbr_reorder_set_order(void* win, int n, const int* order, const char** items) {
|
||||
+ wxListCtrl* lc = (wxListCtrl*)win;
|
||||
+ lc->DeleteAllItems();
|
||||
+ 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);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+// ---- popup menu (right-click context menu) ----------------------------------
|
||||
+
|
||||
+void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
|
||||
+180
-65
@@ -166,6 +166,13 @@ 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)
|
||||
// Component-health icons (round 13 #3): SVG-backed and registered from the Rust
|
||||
// side, recoloured per component state (grey/red/yellow/green) by DrawShape's
|
||||
// SVG path. Blank if unregistered.
|
||||
const wxUniChar SHAPE_BOLT = 0x0C; // power supply
|
||||
const wxUniChar SHAPE_BRAIN = 0x0E; // control board
|
||||
const wxUniChar SHAPE_FAN = 0x0F; // cooling fan
|
||||
const wxUniChar SHAPE_CHIP = 0x10; // hashboard
|
||||
const int SHAPE_ADVANCE = 15; // horizontal space one shape occupies
|
||||
|
||||
// Animation phase for the pulsing locate-light dot (round 12 #6), advanced by a
|
||||
@@ -179,7 +186,8 @@ bool IsShapeSentinel(const wxString& s, wxUniChar& out) {
|
||||
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) {
|
||||
c == SHAPE_PAUSED || c == SHAPE_PULSE_DOT ||
|
||||
c == SHAPE_BOLT || c == SHAPE_BRAIN || c == SHAPE_FAN || c == SHAPE_CHIP) {
|
||||
out = c;
|
||||
return true;
|
||||
}
|
||||
@@ -1295,19 +1303,88 @@ int wxbr_rearrange_get_order(void* win, int* buf, int cap) {
|
||||
// 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;
|
||||
// as wxbr_rearrange_get_order. All pointer interaction is handled explicitly
|
||||
// (round 13 #1) so a single control supports both drag-to-reorder AND
|
||||
// drag-to-select: a drag that starts on an already-selected row moves that group
|
||||
// (reorder), a drag that starts on an unselected row rubber-band-selects the
|
||||
// range it sweeps. Keyboard: Ctrl+A selects all, Ctrl/Shift+Up/Down extend the
|
||||
// selection. (The old wxEVT_LIST_BEGIN_DRAG binding intercepted every drag as a
|
||||
// reorder, which silently disabled rubber-band selection.)
|
||||
static wxVector<long> g_reorder_drag; // item DATA currently being reordered
|
||||
static wxListCtrl* g_reorder_list = nullptr;
|
||||
static long g_press_row = -1; // row under the last left-press (-1 = none/checkbox)
|
||||
static wxPoint g_press_pos; // position of that press
|
||||
static bool g_press_row_selected = false;
|
||||
static int g_reorder_mode = 0; // 0 = none, 1 = reorder, 2 = rubber-band
|
||||
static long g_rubber_anchor = -1;
|
||||
|
||||
// Set the selection to the inclusive row range [a,b] (order-independent). When
|
||||
// `additive` (Ctrl held) the existing selection is kept and the range added.
|
||||
static void ReorderSelectRange(wxListCtrl* lc, long a, long b, bool additive) {
|
||||
if (a < 0) a = 0;
|
||||
long lo = a < b ? a : b;
|
||||
long hi = a < b ? b : a;
|
||||
int count = lc->GetItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
bool inRange = (i >= lo && i <= hi);
|
||||
bool keep = additive && (lc->GetItemState(i, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED);
|
||||
lc->SetItemState(i, (inRange || keep) ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
// Move the rows whose DATA is in g_reorder_drag so they land just before the row
|
||||
// under `pos` (or at the end when dropped past the last row / onto a dragged row),
|
||||
// preserving each row's checked state.
|
||||
static void ReorderMoveTo(wxListCtrl* lc, const wxPoint& pos) {
|
||||
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(pos, 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);
|
||||
if (isDragged(result[i].data))
|
||||
lc->SetItemState((long)i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// Narrower than before so the picker dialog is not over-wide (round 13 #1).
|
||||
lc->InsertColumn(0, wxT("Column"), wxLIST_FORMAT_LEFT, 190);
|
||||
for (int i = 0; i < n; i++) {
|
||||
int enc = order[i];
|
||||
int idx = enc < 0 ? ~enc : enc;
|
||||
@@ -1343,69 +1420,91 @@ void* wxbr_reorder_list(void* parent, int n, const int* order, const char** item
|
||||
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;
|
||||
};
|
||||
// Left-press: remember the row and whether it was already selected, so a
|
||||
// following drag can choose reorder vs rubber-band. A press on the checkbox
|
||||
// (state icon) never starts a drag, so toggling still works. Skip() so the
|
||||
// control still does its normal focus/selection/checkbox handling.
|
||||
lc->Bind(wxEVT_LEFT_DOWN, [lc](wxMouseEvent& e) {
|
||||
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]);
|
||||
long row = lc->HitTest(e.GetPosition(), flags);
|
||||
g_reorder_list = lc;
|
||||
g_reorder_mode = 0;
|
||||
if (flags & wxLIST_HITTEST_ONITEMSTATEICON) {
|
||||
g_press_row = -1; // checkbox click: don't drag
|
||||
} else {
|
||||
g_press_row = row;
|
||||
g_press_pos = e.GetPosition();
|
||||
g_press_row_selected =
|
||||
(row >= 0) && (lc->GetItemState(row, wxLIST_STATE_SELECTED) & wxLIST_STATE_SELECTED);
|
||||
}
|
||||
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;
|
||||
e.Skip();
|
||||
});
|
||||
// Motion with the left button down: once past a small threshold, start either a
|
||||
// reorder (press began on a selected row) or a rubber-band selection.
|
||||
lc->Bind(wxEVT_MOTION, [lc](wxMouseEvent& e) {
|
||||
if (!e.LeftIsDown() || g_reorder_list != lc || g_press_row < 0) { e.Skip(); return; }
|
||||
wxPoint pos = e.GetPosition();
|
||||
if (g_reorder_mode == 0) {
|
||||
long dx = pos.x - g_press_pos.x, dy = pos.y - g_press_pos.y;
|
||||
if (dx < 0) dx = -dx;
|
||||
if (dy < 0) dy = -dy;
|
||||
if (dx < 4 && dy < 4) { e.Skip(); return; }
|
||||
if (g_press_row_selected) {
|
||||
g_reorder_mode = 1; // reorder the current selection
|
||||
g_reorder_drag.clear();
|
||||
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));
|
||||
}
|
||||
if (g_reorder_drag.empty()) g_reorder_mode = 0;
|
||||
} else {
|
||||
g_reorder_mode = 2; // rubber-band select from the press row
|
||||
g_rubber_anchor = g_press_row;
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (g_reorder_mode == 2) {
|
||||
int flags = 0;
|
||||
long cur = lc->HitTest(pos, flags);
|
||||
if (cur < 0) cur = (pos.y < 0) ? 0 : (lc->GetItemCount() - 1);
|
||||
ReorderSelectRange(lc, g_rubber_anchor, cur, e.ControlDown());
|
||||
return; // we own the selection during a rubber-band; don't Skip
|
||||
}
|
||||
e.Skip();
|
||||
});
|
||||
// Release: complete a reorder if one was in progress, then reset.
|
||||
lc->Bind(wxEVT_LEFT_UP, [lc](wxMouseEvent& e) {
|
||||
if (g_reorder_list == lc && g_reorder_mode == 1 && !g_reorder_drag.empty())
|
||||
ReorderMoveTo(lc, e.GetPosition());
|
||||
g_reorder_drag.clear();
|
||||
g_reorder_list = nullptr;
|
||||
g_reorder_mode = 0;
|
||||
g_press_row = -1;
|
||||
e.Skip();
|
||||
});
|
||||
// Keyboard: Ctrl+A selects all; Ctrl/Shift+Down/Up extend the selection one row
|
||||
// (round 13 #1). Everything else falls through to the control.
|
||||
lc->Bind(wxEVT_CHAR_HOOK, [lc](wxKeyEvent& e) {
|
||||
int key = e.GetKeyCode();
|
||||
int count = lc->GetItemCount();
|
||||
if (e.ControlDown() && (key == 'A' || key == 'a')) {
|
||||
for (int i = 0; i < count; i++)
|
||||
lc->SetItemState(i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
|
||||
return; // consume
|
||||
}
|
||||
if ((key == WXK_DOWN || key == WXK_UP) && (e.ControlDown() || e.ShiftDown()) && count > 0) {
|
||||
long focus = lc->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
|
||||
if (focus < 0) focus = lc->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
if (focus < 0) focus = (key == WXK_DOWN) ? -1 : count;
|
||||
long next = (key == WXK_DOWN) ? focus + 1 : focus - 1;
|
||||
if (next < 0) next = 0;
|
||||
if (next > count - 1) next = count - 1;
|
||||
lc->SetItemState(next, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
|
||||
wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
|
||||
lc->EnsureVisible(next);
|
||||
return; // consume
|
||||
}
|
||||
e.Skip();
|
||||
});
|
||||
return (void*)lc;
|
||||
}
|
||||
@@ -1421,6 +1520,22 @@ int wxbr_reorder_get_order(void* win, int* buf, int cap) {
|
||||
return n;
|
||||
}
|
||||
|
||||
// Repopulate the list in a new order (round 13 #1: the Alphabetical / Categories
|
||||
// sort buttons). Same [idx | ~idx] encoding as construction; `items` is the same
|
||||
// base-index-keyed title array. The Rust side preserves each row's checked state
|
||||
// by carrying it in the sign of the order entries.
|
||||
void wxbr_reorder_set_order(void* win, int n, const int* order, const char** items) {
|
||||
wxListCtrl* lc = (wxListCtrl*)win;
|
||||
lc->DeleteAllItems();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- popup menu (right-click context menu) ----------------------------------
|
||||
|
||||
void* wxbr_menu_new() { return (void*)new wxMenu(); }
|
||||
|
||||
@@ -81,6 +81,7 @@ mod notsafe {
|
||||
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_reorder_set_order(win: *mut c_void, n: c_int, order: *const c_int, items: *const *const c_char);
|
||||
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);
|
||||
@@ -674,6 +675,17 @@ impl Widget {
|
||||
buf.into_iter().take(n.max(0) as usize).collect()
|
||||
}
|
||||
|
||||
/// Repopulate a `reorder_list` in a new order (same `[idx | !idx]` encoding
|
||||
/// and same base-index `items` array as `reorder_list`). Used by the column
|
||||
/// picker's Alphabetical / Categories sort buttons.
|
||||
pub fn reorder_set_order(&self, order: &[i32], items: &[&str]) {
|
||||
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();
|
||||
unsafe {
|
||||
notsafe::wxbr_reorder_set_order(self.0, items.len() as c_int, order.as_ptr(), ptrs.as_ptr())
|
||||
}
|
||||
}
|
||||
|
||||
// ---- popup menu ----
|
||||
|
||||
pub fn menu_new() -> Widget {
|
||||
|
||||
+1
-1
@@ -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":"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"}
|
||||
{"$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":"cf1bd56ca56178968f8ef57955f06d14f4c3775f27ca3a85ac280919f19b8e50","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"}
|
||||
+47
-1
@@ -201,10 +201,41 @@ fn miner_conf_with_fan_config(miner_conf: &Value, config: FanConfig) -> Value {
|
||||
Value::Object(payload)
|
||||
}
|
||||
|
||||
/// Infer an Antminer's hash algorithm from its model-family letter, for models
|
||||
/// asic-rs' alias table doesn't recognise (round 13 #5). Only the families whose
|
||||
/// entire product line shares one algorithm are inferred; anything ambiguous
|
||||
/// (the K-series spans Kadena/KHeavyHash/Eaglesong, DR is Blake256 while D is
|
||||
/// X11) is left Unknown rather than guessed wrong.
|
||||
fn infer_antminer_algo(model: &str) -> HashAlgorithm {
|
||||
let upper = model.to_ascii_uppercase();
|
||||
let name = upper
|
||||
.strip_prefix("ANTMINER ")
|
||||
.unwrap_or(&upper)
|
||||
.trim_start();
|
||||
match name.chars().next() {
|
||||
// Z9 / Z11 / Z15 / Z15 Pro / Z15J -- the whole Z line is Equihash.
|
||||
Some('Z') => HashAlgorithm::Equihash,
|
||||
// L3+ / L7 / L9 / L11 -- the whole L line is Scrypt.
|
||||
Some('L') => HashAlgorithm::Scrypt,
|
||||
// S9..S21 and T9..T21 (and future revisions) are all SHA-256.
|
||||
Some('S') | Some('T') => HashAlgorithm::SHA256,
|
||||
_ => HashAlgorithm::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
impl AntMinerV2020 {
|
||||
pub fn new(ip: IpAddr, model: impl MinerModel) -> Self {
|
||||
let auth = Self::default_auth();
|
||||
let algo = model.hash_algorithm();
|
||||
// asic-rs maps a model string to its algorithm through a fixed alias
|
||||
// table; a model that is not in the table (a Z15J, a not-yet-added
|
||||
// S-series, ...) resolves to HashAlgorithm::Unknown, which then leaves the
|
||||
// miner's hashrate un-bucketed ("unknown hashrate", round 13 #5). When the
|
||||
// table can't place the model, infer the algorithm from its Antminer
|
||||
// family letter for the lines that are single-algorithm end to end.
|
||||
let algo = match model.hash_algorithm() {
|
||||
HashAlgorithm::Unknown => infer_antminer_algo(&model.to_string()),
|
||||
known => known,
|
||||
};
|
||||
AntMinerV2020 {
|
||||
ip,
|
||||
rpc: AntMinerRPCAPI::new(ip),
|
||||
@@ -1430,6 +1461,21 @@ mod tests {
|
||||
AM_DEVS, AM_POOLS, AM_STATS, AM_SUMMARY, AM_SYSTEM_INFO, AM_VERSION,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn unknown_models_infer_algo_from_family_letter() {
|
||||
// Round 13 #5: a model outside asic-rs' alias table must still resolve a
|
||||
// sensible algorithm from its Antminer family letter instead of Unknown.
|
||||
assert_eq!(infer_antminer_algo("ANTMINER Z15J"), HashAlgorithm::Equihash);
|
||||
assert_eq!(infer_antminer_algo("Z9"), HashAlgorithm::Equihash);
|
||||
assert_eq!(infer_antminer_algo("ANTMINER L15"), HashAlgorithm::Scrypt);
|
||||
assert_eq!(infer_antminer_algo("ANTMINER S23"), HashAlgorithm::SHA256);
|
||||
assert_eq!(infer_antminer_algo("ANTMINER T23"), HashAlgorithm::SHA256);
|
||||
// Ambiguous / unrelated families stay Unknown (K-series spans three
|
||||
// algorithms; a bare unknown string has no family).
|
||||
assert_eq!(infer_antminer_algo("ANTMINER KS7"), HashAlgorithm::Unknown);
|
||||
assert_eq!(infer_antminer_algo("WHATSMINER M30"), HashAlgorithm::Unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_miner_conf_payload_matches_cgi_contract_for_pause_resume() {
|
||||
let pre = json!({
|
||||
|
||||
+1
-1
@@ -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":"c3edc06f2404efd473bcc4ab16d66bb647369f2d43c0a10cb77bbc12cb98bf43","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":"6a52c19b38be83fe47ccf8f6c6fe3b7d9597575b79366fbc678ea3586953dd52","src/lib.rs":"b2f55767a7f3fdacb1e898c5cb961c2dec8481823f94386ee67628960e91bf7d","src/make.rs":"e968e4dbd745d485fc9ad4c5a4c081d679eddce11f66e572f81f2dbe37ede3f0","src/models.rs":"b4ea44fc627ff6c8b41bf8758d6ce6074aa690fe9f6c95a9cb3d1cdbd00e51d6"},"package":"67cca6e6bf4ac14562084ce7534521ffa7cd313fa39e2392f98ff98a047a4353"}
|
||||
@@ -98,6 +98,10 @@ impl From<AntMinerModel> for MinerHardware {
|
||||
fans: Some(2),
|
||||
boards: Some(vec![Some(6), Some(6), Some(6)]),
|
||||
},
|
||||
AntMinerModel::Z15J => Self {
|
||||
fans: Some(2),
|
||||
boards: Some(vec![Some(3), Some(3), Some(3)]),
|
||||
},
|
||||
AntMinerModel::S17 => Self {
|
||||
fans: Some(4),
|
||||
boards: Some(vec![Some(48), Some(48), Some(48)]),
|
||||
|
||||
+13
@@ -78,6 +78,9 @@ pub enum AntMinerModel {
|
||||
#[serde(alias = "ANTMINER Z15 PRO")]
|
||||
#[algorithm(HashAlgorithm::Equihash)]
|
||||
Z15Pro,
|
||||
#[serde(alias = "ANTMINER Z15J")]
|
||||
#[algorithm(HashAlgorithm::Equihash)]
|
||||
Z15J,
|
||||
#[serde(alias = "ANTMINER S17")]
|
||||
#[algorithm(HashAlgorithm::SHA256)]
|
||||
S17,
|
||||
@@ -281,11 +284,21 @@ mod tests {
|
||||
(AntMinerModel::E9Pro, HashAlgorithm::EtHash),
|
||||
(AntMinerModel::Z15, HashAlgorithm::Equihash),
|
||||
(AntMinerModel::Z15Pro, HashAlgorithm::Equihash),
|
||||
(AntMinerModel::Z15J, HashAlgorithm::Equihash),
|
||||
] {
|
||||
assert_eq!(model.hash_algorithm(), expected, "{model}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z15j_parses_as_equihash() {
|
||||
// The Z15J reports "ANTMINER Z15J"; before it had an alias it fell back to
|
||||
// Unknown, which left its Sol/s hashrate un-bucketed (round 13 #5).
|
||||
let model = AntMinerModel::from_str("ANTMINER Z15J").unwrap();
|
||||
assert_eq!(model, AntMinerModel::Z15J);
|
||||
assert_eq!(model.hash_algorithm(), HashAlgorithm::Equihash);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_model_uses_unknown_algorithm() {
|
||||
let model = AntMinerModel::from_str("ANTMINER S99").unwrap();
|
||||
|
||||
Reference in New Issue
Block a user