/// <summary> /// 运行设备 /// </summary> /// <param name="key"></param> /// <param name="channel"></param> /// <param name="revData"></param> public void Run(string key, IChannel channel, byte[] revData) { //不运行设备 if (!this.IsRunDevice) { OnDeviceRuningLog("设备已经停止运行"); return; } if (revData == null) { this.UnknownIO(); if (this.DeviceDynamic.CommunicateState != CommunicateState.None) { this.DeviceDynamic.CommunicateState = CommunicateState.None; this.CommunicateStateChanged(CommunicateState.None); } } else { IRequestInfo info = new RequestInfo() { Key = key, Data = revData, Channel = channel }; //---------------------检测通讯状态----------------------// CommunicateState state = this.CheckCommunicateState(revData); if (this.DeviceDynamic.CommunicateState != state) { this.DeviceDynamic.CommunicateState = state; this.CommunicateStateChanged(state); } if (state == CommunicateState.Communicate) { this.Communicate(info); } else if (state == CommunicateState.Interrupt) { this.CommunicateInterrupt(info); } else if (state == CommunicateState.Error) { this.CommunicateError(info); } else { this.CommunicateNone(); } this.Alert(); this.Save(); this.Show(); } }
/// <summary> /// 检测通讯状态 /// </summary> /// <param name="revdata"></param> /// <returns></returns> public CommunicateState CheckCommunicateState(byte[] revdata) { CommunicateState state = CommunicateState.None; if (revdata.Length <= 0) { state = CommunicateState.Interrupt; } else { state = this.Protocol.CheckData(revdata) ? CommunicateState.Communicate : CommunicateState.Error; } return(state); }
private void InternalRun(string key, IChannel io, byte[] revdata) { #region this.ShowMonitorData(revdata, "接收"); this.SaveBytes(revdata, "接收"); //---------------------检测通讯状态----------------------// CommunicateState state = this.CheckCommunicateState(revdata); if (this.DeviceDynamic.CommunicateState != state) { this.DeviceDynamic.CommunicateState = state; this.CommunicateStateChanged(state); } IRequestInfo info = new RequestInfo() { Key = key, Data = revdata, Channel = io }; if (state == CommunicateState.Communicate) { this.Communicate(info); } else if (state == CommunicateState.Interrupt) { this.CommunicateInterrupt(info); } else if (state == CommunicateState.Error) { this.CommunicateError(info); } else { this.CommunicateNone(); } this.Alert(); this.Save(); this.Show(); #endregion }
private void InternalRun(string key, IChannel io, IRequestInfo info) { #region this.ChannelMonitorData(DataOrientation.Receive, info.Data); this.SaveOriginalBytes(DataOrientation.Receive, info.Data); //---------------------检测通讯状态----------------------// CommunicateState state = this.CheckCommunicateState(info.Data); if (this.DeviceDynamic.CommunicateState != state) { this.DeviceDynamic.CommunicateState = state; this.CommunicateStateChanged(state); } if (state == CommunicateState.Communicate) { this.Communicate(info); } else if (state == CommunicateState.Interrupt) { this.CommunicateInterrupt(info); } else if (state == CommunicateState.Error) { this.CommunicateError(info); } else { this.CommunicateNone(); } this.Alert(); this.Save(); this.Show(); #endregion }
/// <summary> /// 当通讯状态改变的时候调用此函数 /// </summary> /// <param name="comState">状态改变后的通讯状态</param> public abstract void CommunicateStateChanged(CommunicateState comState);
/// <summary> /// 运行设备 /// </summary> /// <param name="io"></param> public void Run(IChannel io) { //不运行设备 if (!this.IsRunDevice) { OnDeviceRuningLog("设备已经停止运行"); return; } if (io == null) { this.UnknownIO(); if (this.DeviceDynamic.CommunicateState != CommunicateState.None) { this.DeviceDynamic.CommunicateState = CommunicateState.None; this.CommunicateStateChanged(CommunicateState.None); } } else { //-------------------获得发送数据命令--------------------// byte[] data = this.GetSendBytes(); if (data != null && data.Length > 0) { //-------------------发送数据----------------------------// this.Send(io, data); this.ShowMonitorData(data, "发送"); this.SaveBytes(data, "发送"); } //---------------------读取数据--------------------------// byte[] revdata = this.Receive(io); this.ShowMonitorData(revdata, "接收"); this.SaveBytes(revdata, "接收"); //---------------------检测通讯状态----------------------// CommunicateState state = this.CheckCommunicateState(revdata); if (this.DeviceDynamic.CommunicateState != state) { this.DeviceDynamic.CommunicateState = state; this.CommunicateStateChanged(state); } IRequestInfo info = new RequestInfo() { Key = io.Key, Data = revdata, Channel = null }; if (state == CommunicateState.Communicate) { this.Communicate(info); } else if (state == CommunicateState.Interrupt) { this.CommunicateInterrupt(info); } else if (state == CommunicateState.Error) { this.CommunicateError(info); } else { this.CommunicateNone(); } this.Alert(); this.Save(); this.Show(); } }
public override void CommunicateStateChanged(CommunicateState comState) { //throw new NotImplementedException(); }
/// <summary> /// 通讯状态已经发生改变,包括:通讯正常、通讯中断、通讯干扰,以及通讯未知 /// </summary> /// <param name="comState"></param> public override void CommunicateStateChanged(CommunicateState comState) { }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent friend = null; float distanceToFriend = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (agent == owner) { continue; } if (data.RegistrationDate < Time.time - 0.5f || !agent.gameObject.activeSelf) { continue; } if (!agent.IsThinking || agent.IsThrow) { continue; } float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (distanceToAgent >= distanceToFriend) { continue; } /*bool recentTalk = false; * IReadOnlyCollection<DataCommunication> communications = owner.Memory.Communications.Read(); * foreach(DataCommunication com in communications){ * if(com.creature == agent.Creature && com.subject == memoryType){ * recentTalk = true; * break; * } * }*/ if (GetCreatureFilter()(agent.Creature)) { friend = agent; distanceToFriend = distanceToAgent; } } switch (communicateState) { case CommunicateState.Search: if (child.HasFailed) { AddSubgoal(new GoalSeekNest(owner)); communicateState = CommunicateState.SeekNest; } if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.SeekNest: if (child.HasFailed) { AddSubgoal(new GoalWander(owner)); communicateState = CommunicateState.Wander; } if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.Wander: if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.Share: if (child.HasFailed) { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); communicateState = CommunicateState.Search; } break; } base.ProcessSubgoals(); }