Commit 6f4472f1 authored by 潘栩锋's avatar 潘栩锋 🚴

删除 dynarea 内的 ToBytes

parent b272c7aa
......@@ -11,64 +11,17 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
{
#region Pack
public class Pack_GetADPos : IPack
public class Pack_GetADPos
{
public int thick;
public int position;
public int boltIndex;
public int ad;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(thick));
buf.AddRange(BitConverter.GetBytes(position));
buf.AddRange(BitConverter.GetBytes(boltIndex));
buf.AddRange(BitConverter.GetBytes(ad));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
int idx = 0;
thick = BitConverter.ToInt32(value,idx);
idx += 4;
position = BitConverter.ToInt32(value, idx);
idx += 4;
boltIndex = BitConverter.ToInt32(value, idx);
idx += 4;
ad = BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
#endregion
}
public class Pack_Position2 : IPack
public class Pack_Position2
{
public int position;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(position));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
position = BitConverter.ToInt32(value, 0);
return true;
}
#endregion
}
public class Pack_GetScanInfo
{
......@@ -105,7 +58,7 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
/// </summary>
public double velocity;
}
public class Pack_GetControllerState : IPack
public class Pack_GetControllerState
{
/// <summary>
/// 运行状态
......@@ -115,210 +68,84 @@ namespace FLY.Thick.Base.OBJ_INTERFACE
/// 自动扫描时间累积
/// </summary>
public int autoscan_counter;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes((Int32)controller_state));
buf.AddRange(BitConverter.GetBytes(autoscan_counter));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
if (value.Length < 8)
return false;
int idx = 0;
controller_state = (CTRL_STATE)BitConverter.ToInt32(value, idx);
idx += 4;
autoscan_counter = BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
#endregion
}
public class Pack_GetIO : IPack
public class Pack_GetIO
{
public UInt16 iStatus;
public UInt16 oStatus;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(iStatus));
buf.AddRange(BitConverter.GetBytes(oStatus));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
iStatus = BitConverter.ToUInt16(value, 0);
oStatus = BitConverter.ToUInt16(value, 2);
return true;
}
#endregion
}
public class Pack_GetSystem : IPack
{
public bool isConnect;//FLYAD 连接状态
public bool secuteLock;//锁
public int hrs;//系统剩余小时
public string version;//版本
public GAGE_TYPE gagetype;//设备类型
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(isConnect));
buf.AddRange(BitConverter.GetBytes(secuteLock));
buf.AddRange(BitConverter.GetBytes(hrs));
byte[] version_buf = Converter.StringToBytes(version);
buf.AddRange(BitConverter.GetBytes(version_buf.Length));
buf.AddRange(version_buf);
buf.AddRange(BitConverter.GetBytes((int)gagetype));
return buf.ToArray();
}
public bool TryParse(byte[] value)
public class Pack_GetSystem
{
int cnt = 1 + 1 + 4 + 4 + 4;
if (value.Length < cnt)
return false;
int index = 0;
isConnect = BitConverter.ToBoolean(value, index);
index++;
secuteLock = BitConverter.ToBoolean(value, index);
index++;
hrs = BitConverter.ToInt32(value, index);
index += 4;
int len = BitConverter.ToInt32(value, index);
index += 4;
cnt += len;
if (value.Length < cnt)
return false;
byte[] version_buf = new byte[len];
Array.Copy(value, index, version_buf, 0, len);
index += len;
version = Converter.BytesToString(version_buf);
gagetype = (GAGE_TYPE)BitConverter.ToInt32(value, index);
index += 4;
return true;
}
#endregion
/// <summary>
/// FLYAD 连接状态
/// </summary>
public bool isConnect;
/// <summary>
/// 锁
/// </summary>
public bool secuteLock;
/// <summary>
/// 系统剩余小时
/// </summary>
public int hrs;
/// <summary>
/// 版本
/// </summary>
public string version;
/// <summary>
/// 设备类型
/// </summary>
public GAGE_TYPE gagetype;
}
public class Pack_GetProfile : IPack
public class Pack_GetProfile
{
public string ProductName;//产品名称
public int Target;//目标值
public int Alarm;//报警值
public int DataBoltNoBegin;//数据开始分区号
public int DataBoltNoEnd;//数据结束分区号
/// <summary>
/// 产品名称
/// </summary>
public string ProductName;
/// <summary>
/// 目标值
/// </summary>
public int Target;
/// <summary>
/// 报警值
/// </summary>
public int Alarm;
/// <summary>
/// 数据开始分区号
/// </summary>
public int DataBoltNoBegin;
/// <summary>
/// 数据结束分区号
/// </summary>
public int DataBoltNoEnd;
/// <summary>
/// 扫描范围开始分区号
/// </summary>
public int ScanBoltNoBegin;
/// <summary>
/// 扫描范围结束分区号
/// </summary>
public int ScanBoltNoEnd;
/// <summary>
/// 斜率补差
/// </summary>
public double Comp;
/// <summary>
/// 平移补差
/// </summary>
public int Shift;
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(Target));
buf.AddRange(BitConverter.GetBytes(Alarm));
buf.AddRange(BitConverter.GetBytes(DataBoltNoBegin));
buf.AddRange(BitConverter.GetBytes(DataBoltNoEnd));
buf.AddRange(BitConverter.GetBytes(ScanBoltNoBegin));
buf.AddRange(BitConverter.GetBytes(ScanBoltNoEnd));
buf.AddRange(BitConverter.GetBytes(Comp));
buf.AddRange(BitConverter.GetBytes(Shift));
byte[] name_bytes = Converter.StringToBytes(ProductName);
buf.AddRange(BitConverter.GetBytes((int)name_bytes.Length));
buf.AddRange(name_bytes);
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
int index = 0;
Target = BitConverter.ToInt32(value, index);
index += 4;
Alarm = BitConverter.ToInt32(value, index);
index += 4;
DataBoltNoBegin = BitConverter.ToInt32(value, index);//数据开始分区号
index += 4;
DataBoltNoEnd = BitConverter.ToInt32(value, index);//数据结束分区号
index += 4;
ScanBoltNoBegin = BitConverter.ToInt32(value, index);//数据开始分区号
index += 4;
ScanBoltNoEnd = BitConverter.ToInt32(value, index);//数据结束分区号
index += 4;
Comp = BitConverter.ToDouble(value, index);
index += 8;
Shift = BitConverter.ToInt32(value, index);
index += 4;
int name_bytes_length = BitConverter.ToInt32(value, index);
index += 4;
byte[] name_bytes = new byte[name_bytes_length];
Array.Copy(value, index, name_bytes, 0, name_bytes_length);
index += name_bytes_length;
ProductName = Converter.BytesToString(name_bytes);
return true;
}
#endregion
}
public class Pack_GetBoltmap : IPack
public class Pack_GetBoltmap
{
public int NBolts;//总分区数
public int FirstBoltNo;//开始分区号
#region IPack 成员
public byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(BitConverter.GetBytes(NBolts));
buf.AddRange(BitConverter.GetBytes(FirstBoltNo));
return buf.ToArray();
}
public bool TryParse(byte[] value)
{
NBolts = BitConverter.ToInt32(value, 0);
FirstBoltNo = BitConverter.ToInt32(value, 4);
return true;
}
#endregion
/// <summary>
/// 总分区数
/// </summary>
public int NBolts;
/// <summary>
/// 开始分区号
/// </summary>
public int FirstBoltNo;
}
#endregion
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment