public bool Execute(int canId, int hostId, List <byte> appData) { switch (WorkState) { case WorkStateEnum.Idle: InitFramesToSend(appData); WorkState = WorkStateEnum.Send; CanId = canId; HostId = hostId; if (appData.Count > 1) { SuppressResp = ((byte)0x80 & appData[1]) != 0; } else { SuppressResp = false; } return(false); case WorkStateEnum.Send: return(Send()); case WorkStateEnum.Receive: return(Receive()); default: throw new InvalidOperationException("DcmTpProtocalISO15765.Send: Unknown work " + "state -> " + WorkState.ToString()); } }
public ReceiveResult Receive(int hostId, List <byte[]> frames) { switch (WorkState) { case WorkStateEnum.Idle: return(ReceiveSFOrFF(hostId, frames)); case WorkStateEnum.SendFlowControlFrame: return(SendFlowControl()); case WorkStateEnum.ReceiveConsecutiveFrame: return(ReceiveConsecutiveFrame()); default: throw new InvalidOperationException("DcmTpProtocalISO15765Receiver: Unknown " + "Work State: " + WorkState.ToString()); } }
private bool Receive() { var result = receiver.Receive(CanId, FramesReceived); bool ret = false; switch (result) { case DcmTpProtocalISO15765Receiver.ReceiveResult.Ok: DcmTpHandleResult = DcmTpHandleResult.OK; // 解包数据 AppDataReceived = DcmTpProtocalISO15765Packer.Unpack(FramesReceived); Reset(); ret = true; break; case DcmTpProtocalISO15765Receiver.ReceiveResult.Working: ret = false; break; case DcmTpProtocalISO15765Receiver.ReceiveResult.Fail: DcmTpHandleResult = DcmTpHandleResult.FailWithReceive; Reset(); ret = true; break; default: throw new InvalidOperationException("DcmTpProtocalISO15765.Send: Unknown work " + "state -> " + WorkState.ToString()); } if (!ret) { // 检测接收超时 if (ReceiveTimeoutCheck && (stopwatch.ElapsedMilliseconds >= ReceiveTimeout)) { DcmTpHandleResult = DcmTpHandleResult.FailWithReceiveTimeout; Reset(); return(true); } } return(ret); }
private bool Send() { var result = sender.Send(CanId, FramesToSend); switch (result) { case DcmTpProtocalISO15765Sender.SendResult.Ok: return(OnSendOk()); case DcmTpProtocalISO15765Sender.SendResult.Working: return(false); case DcmTpProtocalISO15765Sender.SendResult.Fail: DcmTpHandleResult = DcmTpHandleResult.FailWithSend; Reset(); return(true); default: throw new InvalidOperationException("DcmTpProtocalISO15765.Send: Unknown work " + "state -> " + WorkState.ToString()); } }
public SendResult Send(int canId, List <byte[]> frames) { // 一次只能执行一次事务 if ((WorkState != WorkStateEnum.Odle) && (frames != Frames)) { return(SendResult.Fail); } switch (WorkState) { case WorkStateEnum.Odle: return(SendSFOrFF(canId, frames)); case WorkStateEnum.WaitFlowControlFrame: return(ReceiveFlowControlFrame()); case WorkStateEnum.SendConsecutiveFrame: return(SendConsecutiveFrame()); default: throw new ArgumentException("DcmTpProtocalISO15765Sender:Unkno" + "wn Work State: " + WorkState.ToString()); } }