Different types of units. Writing values, relay unit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user