Commit b2135b2b authored by 潘栩锋's avatar 潘栩锋 🚴

修复 flyad2021B2 RN包处理少了问题

parent 73a08e4b
......@@ -60,7 +60,7 @@ namespace GeneralGommunication
/// <summary>
/// 当前正在等待回复的指令
/// </summary>
COMMREQ_TransactionBase currTran;
protected COMMREQ_TransactionBase currTran;
/// <summary>
/// currTran 发送后,开始计时
/// </summary>
......
......@@ -178,7 +178,10 @@ namespace GeneralGommunication
return bytes.ToArray();
}
public override string ToString()
{
return PrefixString;
}
}
public abstract class COMMREQ_TransactionBase
......@@ -231,5 +234,10 @@ namespace GeneralGommunication
/// 回复的数据,只用于调试而已
/// </summary>
public object retData;
public override string ToString()
{
return $"{commReq.ToString()} hasRet={hasRet}";
}
}
}
......@@ -177,22 +177,7 @@ namespace FlyADBase
}
PushDataEvent?.Invoke(this, eventArgs);
}
void ParseFuncPack_PushRunResultEvent(byte[] pack)
{
PushRunResultEventArgs eventArgs = new PushRunResultEventArgs();
var retData = COMMREQ_RN.ParseFuncPack(pack, 1 + COMMREQ_RN.Prefix.Count()) as GetRunResult_Response;
eventArgs.Status = retData.result;
eventArgs.Serial = retData.serial;
//logger.Debug($"PushRunResultEvent {Newtonsoft.Json.JsonConvert.SerializeObject(retData)}");
byte systick = pack[0];
Misc.MyBase.CLEARBIT(ref systick, 7);
eventArgs.SysTick = systick;
PushRunResultEvent?.Invoke(this, eventArgs);
}
......@@ -204,15 +189,74 @@ namespace FlyADBase
{
//TODO 要处理 TimeOut / ParseFuncPack / GetSendMsg 线性同步问题
if (ParseFuncPack_RN(pack))
return;
base.ParseFuncPack(pack);
}
/// <summary>
/// 当前请求有RN
/// </summary>
/// <returns></returns>
bool IsCurrCommReqRN()
{
if (currTran == null)
return false;
if (currTran is COMMREQ_Transaction)
{
var tran = currTran as COMMREQ_Transaction;
if (tran.commReq == COMMREQ_RN)
{
return true;
}
}
else
{
var _tran = currTran as COMMREQ_TransactionMulti;
var trans = _tran.transactions.FindAll(t => !t.hasRet && t.commReq == COMMREQ_RN);
if (trans.Count() > 0)
return true;
}
return false;
}
bool ParseFuncPack_RN(byte[] pack)
{
//优先处理 PushRunResultEvent 事件
if (Is_RN_Match(pack))
if (!Is_RN_Match(pack))
return false;//收到的不是RN
//收到RN, 它可能是 RN请求 的 回复
if (IsCurrCommReqRN())
{
ParseFuncPack_PushRunResultEvent(pack);
//当前有RN请求
base.ParseFuncPack(pack);
}
base.ParseFuncPack(pack);
//最后也要作为事件推送出去
ParseFuncPack_PushRunResultEvent(pack);
return true;
}
void ParseFuncPack_PushRunResultEvent(byte[] pack)
{
PushRunResultEventArgs eventArgs = new PushRunResultEventArgs();
var retData = COMMREQ_RN.ParseFuncPack(pack, 1 + COMMREQ_RN.Prefix.Count()) as GetRunResult_Response;
eventArgs.Status = retData.result;
eventArgs.Serial = retData.serial;
//logger.Debug($"PushRunResultEvent {Newtonsoft.Json.JsonConvert.SerializeObject(retData)}");
byte systick = pack[0];
Misc.MyBase.CLEARBIT(ref systick, 7);
eventArgs.SysTick = systick;
PushRunResultEvent?.Invoke(this, eventArgs);
}
/// <summary>
/// 数据发送,输入不需要包含开头的7E; 输出会添加CRC8 和 7E
/// </summary>
......@@ -659,30 +703,11 @@ namespace FlyADBase
public void GetRunResult(CallBackHandler asyncDelegate, object asyncContext)
{
//COMMREQ_RN 作为事件,会触发一次,作为指令,也会回复一次
COMMREQ commReq = new COMMREQ()
{
Prefix = COMMREQ.ToPrefix("RN"),
ResponseLen = 5,
ParseFuncPack = (pack, dataIdx) =>
{
DRIVE_MAN_STATUS result = (DRIVE_MAN_STATUS)pack[dataIdx];
dataIdx += 1;
UInt32 serial = BitConverter.ToUInt32(pack, dataIdx);
dataIdx += 4;
return new GetRunResult_Response()
{
result = result,
serial = serial
};
}
};
//放入 交易队列
AddTran(
new COMMREQ_Transaction()
{
commReq = commReq,
commReq = COMMREQ_RN,
asyncDelegate = asyncDelegate,
asyncContext = asyncContext
});
......
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