Skip to content

Commit

Permalink
feature: add send_config support for vnish
Browse files Browse the repository at this point in the history
  • Loading branch information
UpstreamData committed Dec 2, 2024
1 parent e12f85c commit ceab8e5
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 2 deletions.
15 changes: 14 additions & 1 deletion pyasic/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from pydantic import BaseModel, Field

from pyasic.config.fans import FanMode, FanModeConfig
from pyasic.config.fans import FanMode, FanModeConfig, FanModeNormal
from pyasic.config.mining import MiningMode, MiningModeConfig
from pyasic.config.mining.scaling import ScalingConfig
from pyasic.config.pools import PoolConfig
Expand Down Expand Up @@ -159,6 +159,19 @@ def as_luxos(self, user_suffix: str = None) -> dict:
**self.pools.as_luxos(user_suffix=user_suffix),
}

def as_vnish(self, user_suffix: str = None) -> dict:
main_cfg = {
"miner": {
**self.fan_mode.as_vnish(),
**self.temperature.as_vnish(),
**self.mining_mode.as_vnish(),
**self.pools.as_vnish(user_suffix=user_suffix),
}
}
if isinstance(self.fan_mode, FanModeNormal):
main_cfg["miner"]["cooling"]["mode"]["param"] = self.temperature.target
return main_cfg

def as_hammer(self, *args, **kwargs) -> dict:
return self.as_am_modern(*args, **kwargs)

Expand Down
27 changes: 27 additions & 0 deletions pyasic/config/fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def as_bitaxe(self) -> dict:
def as_luxos(self) -> dict:
return {"fanset": {"speed": -1, "min_fans": self.minimum_fans}}

def as_vnish(self) -> dict:
return {
"cooling": {
"fan_min_count": self.minimum_fans,
"fan_min_duty": self.minimum_speed,
"mode": {
"name": "auto",
"param": None, # Target temp, must be set later...
},
}
}


class FanModeManual(MinerConfigValue):
mode: str = Field(init=False, default="manual")
Expand Down Expand Up @@ -150,6 +162,18 @@ def as_bitaxe(self) -> dict:
def as_luxos(self) -> dict:
return {"fanset": {"speed": self.speed, "min_fans": self.minimum_fans}}

def as_vnish(self) -> dict:
return {
"cooling": {
"fan_min_count": self.minimum_fans,
"fan_min_duty": self.speed,
"mode": {
"name": "manual",
"param": self.speed, # Speed value
},
}
}


class FanModeImmersion(MinerConfigValue):
mode: str = Field(init=False, default="immersion")
Expand All @@ -175,6 +199,9 @@ def as_mara(self) -> dict:
def as_luxos(self) -> dict:
return {"fanset": {"speed": 0, "min_fans": 0}}

def as_vnish(self) -> dict:
return {"cooling": {"mode": {"name": "immers"}}}


class FanModeConfig(MinerConfigOption):
normal = FanModeNormal
Expand Down
9 changes: 9 additions & 0 deletions pyasic/config/mining/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def as_am_modern(self) -> dict:
return {"miner-mode": "0"}
return {"miner-mode": 0}

def as_vnish(self) -> dict:
return {"freq": self.freq}


class MiningModeManual(MinerConfigValue):
mode: str = field(init=False, default="manual")
Expand All @@ -378,6 +381,12 @@ def as_am_modern(self) -> dict:
return {"miner-mode": "0"}
return {"miner-mode": 0}

def as_vnish(self) -> dict:
return {
"chains": [b.as_vnish() for b in self.boards.values()],
"globals": {"freq": self.global_freq, "volt": self.global_volt},
}

@classmethod
def from_vnish(cls, web_overclock_settings: dict) -> "MiningModeManual":
# will raise KeyError if it cant find the settings, values cannot be empty
Expand Down
15 changes: 15 additions & 0 deletions pyasic/config/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ def as_boser(self) -> PoolConfiguration:
url=self.url, user=self.user, password=self.password, enabled=True
)

def as_vnish(self, user_suffix: str = None) -> dict:
if user_suffix is not None:
return {
"url": self.url,
"user": f"{self.user}{user_suffix}",
"pass": self.password,
}
return {"url": self.url, "user": self.user, "pass": self.password}

@classmethod
def from_dict(cls, dict_conf: dict | None) -> "Pool":
return cls(
Expand Down Expand Up @@ -338,6 +347,9 @@ def as_boser(self, user_suffix: str = None) -> PoolGroupConfiguration:
pools=[p.as_boser() for p in self.pools],
)

def as_vnish(self, user_suffix: str = None) -> dict:
return {"pools": [p.as_vnish(user_suffix=user_suffix) for p in self.pools]}

@classmethod
def from_dict(cls, dict_conf: dict | None) -> "PoolGroup":
cls_conf = {}
Expand Down Expand Up @@ -530,6 +542,9 @@ def as_bitaxe(self, user_suffix: str = None) -> dict:
def as_luxos(self, user_suffix: str = None) -> dict:
return {}

def as_vnish(self, user_suffix: str = None) -> dict:
return self.groups[0].as_vnish(user_suffix=user_suffix)

@classmethod
def from_api(cls, api_pools: dict) -> "PoolConfig":
try:
Expand Down
12 changes: 11 additions & 1 deletion pyasic/config/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def as_epic(self) -> dict:
def as_luxos(self) -> dict:
return {"tempctrlset": [self.target or "", self.hot or "", self.danger or ""]}

def as_vnish(self) -> dict:
return {"misc": {"restart_temp": self.danger}}

@classmethod
def from_dict(cls, dict_conf: dict | None) -> "TemperatureConfig":
return cls(
Expand Down Expand Up @@ -95,9 +98,16 @@ def from_epic(cls, web_conf: dict) -> "TemperatureConfig":

@classmethod
def from_vnish(cls, web_settings: dict) -> "TemperatureConfig":
try:
dangerous_temp = web_settings["misc"]["restart_temp"]
except KeyError:
dangerous_temp = None
try:
if web_settings["miner"]["cooling"]["mode"]["name"] == "auto":
return cls(target=web_settings["miner"]["cooling"]["mode"]["param"])
return cls(
target=web_settings["miner"]["cooling"]["mode"]["param"],
danger=dangerous_temp,
)
except KeyError:
pass
return cls()
Expand Down
5 changes: 5 additions & 0 deletions pyasic/miners/backends/vnish.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class VNish(VNishFirmware, BMMiner):

data_locations = VNISH_DATA_LOC

async def send_config(self, config: MinerConfig, user_suffix: str = None) -> None:
await self.web.post_settings(
miner_settings=config.as_vnish(user_suffix=user_suffix)
)

async def restart_backend(self) -> bool:
data = await self.web.restart_vnish()
if data:
Expand Down
3 changes: 3 additions & 0 deletions pyasic/web/vnish.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ async def autotune_presets(self) -> dict:

async def find_miner(self) -> dict:
return await self.send_command("find-miner", privileged=True)

async def post_settings(self, miner_settings: dict):
return await self.send_command("settings", post=True, **miner_settings)

0 comments on commit ceab8e5

Please sign in to comment.