Commit 285777f6 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 支持AD盒v1 版本 GET_STATE 与 v2 不一样,但之前不支持,全部都是v2的导致出错了

parent 909dd72a
...@@ -163,29 +163,26 @@ namespace FLYAD7_OBJ_INTERFACE ...@@ -163,29 +163,26 @@ namespace FLYAD7_OBJ_INTERFACE
} }
public class Pack_DriveState : IPack public class Pack_DriveState : IPack
{ {
//当前运行指令(1B)+当前运行状态(1B)+运行模式(1B)+ systick(4B) + 命令序列码(4B) //当前运行指令(1B)+当前运行状态(1B)+运行模式(1B)
public DRIVE_MAN_ORDER order; public DRIVE_MAN_ORDER order;
public DRIVE_MAN_STATUS status; public DRIVE_MAN_STATUS status;
public byte mode; public byte mode;
public int systick;
public Int32 marker;
#region IPack 成员 #region IPack 成员
public byte[] ToBytes() public virtual byte[] ToBytes()
{ {
List<byte> buf = new List<byte>(); List<byte> buf = new List<byte>();
buf.Add((byte)order); buf.Add((byte)order);
buf.Add((byte)status); buf.Add((byte)status);
buf.Add((byte)mode); buf.Add((byte)mode);
buf.AddRange(BitConverter.GetBytes(systick));
buf.AddRange(BitConverter.GetBytes(marker));
return buf.ToArray(); return buf.ToArray();
} }
public bool TryParse(byte[] value) public virtual bool TryParse(byte[] value)
{ {
if (value.Count() < (1 + 1 + 1 + 4 + 4)) if (value.Count() < (1 + 1 + 1))
return false; return false;
int idx = 0; int idx = 0;
order = (DRIVE_MAN_ORDER)value[idx]; order = (DRIVE_MAN_ORDER)value[idx];
...@@ -194,6 +191,36 @@ namespace FLYAD7_OBJ_INTERFACE ...@@ -194,6 +191,36 @@ namespace FLYAD7_OBJ_INTERFACE
idx++; idx++;
mode = value[idx]; mode = value[idx];
idx++; idx++;
return true;
}
#endregion
}
public class Pack_DriveState_2 : Pack_DriveState
{
//当前运行指令(1B)+当前运行状态(1B)+运行模式(1B)+ systick(4B) + 命令序列码(4B)
public int systick;
public Int32 marker;
#region IPack 成员
public override byte[] ToBytes()
{
List<byte> buf = new List<byte>();
buf.AddRange(base.ToBytes());
buf.AddRange(BitConverter.GetBytes(systick));
buf.AddRange(BitConverter.GetBytes(marker));
return buf.ToArray();
}
public override bool TryParse(byte[] value)
{
if (!base.TryParse(value))
return false;
int idx = 3;
if (value.Count() < (1 + 1 + 1 + 4 + 4))
return false;
systick = BitConverter.ToInt32(value, idx); systick = BitConverter.ToInt32(value, idx);
idx += 4; idx += 4;
marker = BitConverter.ToInt32(value, idx); marker = BitConverter.ToInt32(value, idx);
...@@ -201,6 +228,21 @@ namespace FLYAD7_OBJ_INTERFACE ...@@ -201,6 +228,21 @@ namespace FLYAD7_OBJ_INTERFACE
return true; return true;
} }
public virtual bool TryParse_version(byte[] value, out int version)
{
version = 1;
if (!base.TryParse(value))
return false;
int idx = 3;
if (value.Count() < (1 + 1 + 1 + 4 + 4))
return true;
version = 2;
systick = BitConverter.ToInt32(value, idx);
idx += 4;
marker = BitConverter.ToInt32(value, idx);
idx += 4;
return true;
}
#endregion #endregion
} }
public class Pack_SyncStatus : IPack public class Pack_SyncStatus : IPack
......
...@@ -545,14 +545,24 @@ namespace FlyADBase ...@@ -545,14 +545,24 @@ namespace FlyADBase
break; break;
case FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.GET_STATE: case FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.GET_STATE:
{ {
FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_DriveState p = new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_DriveState(); int version;
if (!p.TryParse(infodata)) FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_DriveState_2 pack = new FLYAD7_OBJ_INTERFACE.DRIVE_MAN_INTERFACE.Pack_DriveState_2();
if (!pack.TryParse_version(infodata, out version))
break; break;
DriveOrder = p.order;
DriveStatus = p.status; if (version == 1)
Marker = p.marker; {
DriveOrder = pack.order;
DriveStatus = pack.status;
}
else if (version == 2)
{
DriveOrder = pack.order;
DriveStatus = pack.status;
Marker = pack.marker;
advGetState(); advGetState();
}
isReadyGetState = true; isReadyGetState = true;
updateIsReady(); updateIsReady();
......
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