UpstreamData / pyasic

A simplified and standardized interface for Bitcoin ASICs.
https://docs.pyasic.org
Apache License 2.0
100 stars 54 forks source link

feat: Add update firmware for Whatsminer #158

Closed 1e9abhi1e10 closed 5 months ago

1e9abhi1e10 commented 5 months ago

This PR aims to add update firmware functionality for Whatsminer.

b-rowan commented 5 months ago

This needs to be in BTMiner.py, and also the actually sending of the file should be handled by pyasic.rpc.btminer.BTMinerRPCAPI.upgrade_firmware, as documented in their API docs.

b-rowan commented 5 months ago

Heres the function that should be implemented in the BTMinerRPCAPI class, then you can call this from the upper levels.

    async def update_firmware(self, firmware: bytes):  # noqa - static
        """Upgrade the firmware running on the miner.
        <details>
            <summary>Expand</summary>

        Upgrade the firmware on the miner using the firmware passed in bytes.

        Returns:
            A reply informing of the firmware upgrade as a boolean.
        </details>
        """
        ready = await self.send_privileged_command("update_firmware")
        if not ready.get("Msg") == "ready":
            raise APIError(f"Not ready for firmware update: {self}")
        file_size = struct.pack("<I", len(firmware))
        await self._send_bytes(file_size + firmware)
        return True