36 lines
666 B
C#
36 lines
666 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ESPServer
|
|
{
|
|
class RelayUnit : Unit
|
|
{
|
|
public override byte[] GetWriteCommand(int address, float value)
|
|
{
|
|
foreach (var v in values)
|
|
{
|
|
if (v.Value.name == "r" && v.Value.addressOffset + baseAddress == address)
|
|
{
|
|
return GetWritePayload(value);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private byte[] GetWritePayload(float value)
|
|
{
|
|
string t = "r_write\x01";
|
|
if (MathF.Abs(value) < 1e-4) t += "0";
|
|
else t += "1";
|
|
t += "\x01";
|
|
return Encoding.ASCII.GetBytes(t);
|
|
}
|
|
|
|
public override bool IsValueWritable(UnitValue v)
|
|
{
|
|
return v.name == "r";
|
|
}
|
|
}
|
|
}
|