use std::fmt::Display; use measurements::{Frequency, Temperature, Voltage}; #[cfg(feature = "python")] use pyo3::pyclass; use serde::{Deserialize, Serialize}; use ts_rs::TS; use super::{ hashrate::HashRate, serialize::{serialize_frequency, serialize_temperature, serialize_voltage}, }; #[cfg_attr(feature = "python", pyclass(from_py_object, module = "asic_rs"))] #[cfg_attr(feature = "python", asic_rs_pydantic::py_pydantic_model(getters))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, TS)] /// Per-chip telemetry for a hashboard. pub struct ChipData { /// The position of the chip on the board, indexed from 0 pub position: u16, /// The current hashrate of the chip pub hashrate: Option, /// The current chip temperature #[serde(serialize_with = "serialize_temperature")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub temperature: Option, /// The voltage set point for this chip #[serde(serialize_with = "serialize_voltage")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub voltage: Option, /// The frequency set point for this chip #[serde(serialize_with = "serialize_frequency")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub frequency: Option, /// Whether this chip is tuned and optimizations have completed pub tuned: Option, /// Whether this chip is working and actively mining pub working: Option, } #[cfg_attr(feature = "python", pyclass(from_py_object, module = "asic_rs"))] #[cfg_attr(feature = "python", asic_rs_pydantic::py_pydantic_model(getters))] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, TS)] /// Per-hashboard telemetry for a miner. pub struct BoardData { /// The board position in the miner, indexed from 0 pub position: u8, /// The current hashrate of the board pub hashrate: Option, /// The expected or factory hashrate of the board pub expected_hashrate: Option, /// The board temperature, also sometimes called PCB temperature #[serde(serialize_with = "serialize_temperature")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub board_temperature: Option, /// The temperature of the coolest / first-in-chain chip on the board #[serde(serialize_with = "serialize_temperature")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub inlet_chip_temperature: Option, /// The temperature of the hottest / last-in-chain chip on the board #[serde(serialize_with = "serialize_temperature")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub outlet_chip_temperature: Option, /// The expected number of chips on this board pub expected_chips: Option, /// The number of working chips on this board pub working_chips: Option, /// The serial number of this board pub serial_number: Option, /// Chip level information for this board /// May be empty, most machines do not provide this level of in depth information pub chips: Vec, /// The average voltage or voltage set point of this board #[serde(serialize_with = "serialize_voltage")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub voltage: Option, /// The average frequency or frequency set point of this board #[serde(serialize_with = "serialize_frequency")] #[serde(skip_serializing_if = "Option::is_none")] #[ts(optional, type = "number")] pub frequency: Option, /// Whether this board has been tuned and optimizations have completed pub tuned: Option, /// Whether this board is enabled and actively mining pub active: Option, /// The ASIC chip type/model on this board (e.g. "BM1370"), when reported. /// Not exposed by Antminer/LuxOS (their network API reports only the control /// board type). pub chip_type: Option, /// The hashboard model / part identifier (e.g. "A3HB70601"), when reported. pub hashboard_model: Option, } impl BoardData { /// Create a new board at the given position with the specified expected chip count. /// All other fields are left at their defaults. pub fn new(position: u8, expected_chips: Option) -> Self { Self { position, expected_chips, ..Default::default() } } /// Create a new board with tuned and active state pre-set. pub fn with_state( position: u8, expected_chips: Option, tuned: Option, active: Option, ) -> Self { Self { position, expected_chips, tuned, active, ..Default::default() } } } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TS)] #[cfg_attr( feature = "python", pyclass(from_py_object, get_all, module = "asic_rs") )] #[cfg_attr(feature = "python", asic_rs_pydantic::py_pydantic_model)] /// Control board identity reported by a miner. pub struct MinerControlBoard { /// Whether the control board name is a known board identifier. pub known: bool, /// Control board name or raw unknown identifier. pub name: String, } impl MinerControlBoard { /// Create an unknown control board identity from a raw name. pub fn unknown(name: String) -> Self { Self { known: false, name } } /// Create a known control board identity. pub fn known(name: String) -> Self { Self { known: true, name } } } impl Display for MinerControlBoard { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { if self.known { write!(f, "{}", self.name) } else { write!(f, "Unknown: {}", self.name) } } }