using System.Net;
using DotNext;
namespace Peripherals.PowerClient;
class PowerAddr
{
public const UInt32 Base = 0x10_00_00_00;
public const UInt32 PowerCtrl = Base + 7;
}
///
/// [TODO:description]
///
public class Power
{
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
readonly int timeout;
readonly int port;
readonly string address;
private IPEndPoint ep;
///
/// [TODO:description]
///
/// [TODO:parameter]
/// [TODO:parameter]
/// [TODO:parameter]
/// [TODO:return]
public Power(string address, int port, int timeout = 1000)
{
this.address = address;
this.port = port;
this.ep = new IPEndPoint(IPAddress.Parse(address), port);
this.timeout = timeout;
}
///
/// [TODO:description]
///
/// [TODO:parameter]
/// [TODO:return]
public async ValueTask> SetPowerOnOff(bool enable)
{
if (MsgBus.IsRunning)
MsgBus.UDPServer.ClearUDPData(this.address, 1);
else return new(new Exception("Message Bus not work!"));
var ret = await UDPClientPool.WriteAddr(this.ep, 1, PowerAddr.PowerCtrl, Convert.ToUInt32(enable), this.timeout);
if (!ret.IsSuccessful) return new(ret.Error);
return ret.Value;
}
}