public byte[] Execute(CustomActionContext context) { var model = new Models.Settings.CorrectSetting(); model.GasTemp = context.IO.GetGasTempCorrectionSettings(); model.RedTemp = context.IO.GetRedTempCorrectionSettings(); model.GasPress = context.IO.GetGasPressCorrectionSettings(); this.Result = model; return(null); }
public byte[] Execute(CustomActionContext context) { var tt = context.IO.SendAndRead(InstructionSet.MAPCalibrationParamsPart1, InstructionSet.MAPCalibrationParamsPart2_2DGasCurve); var gasCurve2D = tt.PacketData(2) .Select(m => m * 0.1f).ToArray(); var petrolCurve2D = context.IO.SendAndRead(InstructionSet.MAPCalibrationParamsPart1, InstructionSet.MAPCalibrationParamsPart2_2DPetrolCurve).PacketData(2) .Select(m => m * 0.1f).ToArray(); context.Job.Content.Context = new Models.Feedback.Tiji2DCurve() { PetrolCurve2D = petrolCurve2D, GasCurve2D = gasCurve2D }; return(null); }
public byte[] Execute(CustomActionContext context) { var petrolCurve = InstructionSet.MAPCalibrationParamsPart2_PetrolCurve.Select(m => context.IO.SendAndRead(InstructionSet.MAPCalibrationParamsPart1, m).PacketData(2) .Select(m2 => ValueConvert.MapTableInjectionFrom(m2)).ToArray()).ToArray(); var gasCurve = InstructionSet.MAPCalibrationParamsPart2_GasCurve.Select(m => context.IO.SendAndRead(InstructionSet.MAPCalibrationParamsPart1, m).PacketData(2) .Select(m2 => ValueConvert.MapTableInjectionFrom(m2)).ToArray()).ToArray(); context.Job.Content.Context = new Models.Feedback.Tiji3DCurve() { PetrolCurve = petrolCurve, GasCurve = gasCurve }; return(null); }
public byte[] Execute(CustomActionContext context) { var data1 = context.IO.SendAndRead(InstructionSet.GetEmergencyStartInfo).PacketData(1).ToArray(); //var data2 = context.IO.SendAndRead(InstructionSet.GetMaintainInfo).PacketData(1).ToArray(); this.Result = new Models.Settings.AdditionalSettings(); if (data1[0] == 0x00)//LDC删除 { this.Result.EmergencyStartAllowed = false; } else { this.Result.EmergencyStartAllowed = true; } this.Result.EmergencyStatsPerformed = data1[1]; //this.Result.MaintainRemind = ValueConvert.MaintainRemindTypesFrom(data2[0]); //this.Result.MaintainTime = ValueConvert.MaintainTimeFrom(data2[1], data2[2]); return(null); }
private int ParseSelf(CompilationContext compilationContext, List<Token> tokens, int index, ref IActionNode currentParent) { Token currentToken = tokens[++index]; if (currentToken.Type == TokenType.ReferenceAction) { // Create an action ActionBinding action = compilationContext.TypeBindingTable.GetActionByName(currentToken.Value, compilationContext .ScriptOwnerType); ICustomActionNode node = action.CreateActionNode(); List<Expression> expressions; int skip = ParseActionParameters(index + 1, tokens, compilationContext, out expressions); if (action.NumParameters != expressions.Count) throw new GossipScriptParameterException(String.Format("Invalid number of parameters for action:{0} found:{1} expected:{2}", action.Name,expressions.Count, action.NumParameters)); var customActionContext = new CustomActionContext(expressions); currentParent.Next = new ExecuteCustomActionNode(node, customActionContext); currentParent = currentParent.Next; index += (skip + 1); currentToken = tokens[index]; return index; } if (currentToken.Type == TokenType.ReferencePropertySet) { Token operand = currentToken; Expression expression; currentToken = tokens[++index]; AssertExpectedTokenType(currentToken, TokenType.Assignment, "Unexpected token"); currentToken = tokens[++index]; int skip = ParseExpression(index, tokens, compilationContext, out expression); index += skip; currentToken = tokens[index]; if ( !m_Engine.HostBridge.TypeBindingTable.SetPropertyExists(operand.Value, compilationContext.ScriptOwnerType)) throw new GossipScriptException(String.Format("Property {0} not found or is read only.", operand.Value)); PropertySetBinding setter = m_Engine.HostBridge.TypeBindingTable.GetPropertySetByName(operand.Value, compilationContext .ScriptOwnerType); if (setter.ParameterType != expression.ReturnType) throw new GossipScriptException("Incompatile property set parameter"); currentParent.Next = new AssignReferenceProperty(-1, setter.Id, expression); currentParent = currentParent.Next; return index; } // Parse Action { // First check if we are going to encounter an assignment Int32 enounterAssignmentIndex = 0; if (EncounterAssignment(index, tokens, ref enounterAssignmentIndex)) { return ParsePropertySet(compilationContext, index - 1, tokens, ref currentParent, enounterAssignmentIndex); } Expression expression; int skip = ParseExpression(index - 1, tokens, compilationContext, out expression); index += (skip); currentToken = tokens[index - 1]; if (currentToken.Type == TokenType.ReferenceAction) { // Create an action ActionBinding action = compilationContext.TypeBindingTable.GetActionByName(currentToken.Value, expression.HostReturnType); ICustomActionNode node = action.CreateActionNode(); List<Expression> expressions; skip = ParseActionParameters(index, tokens, compilationContext, out expressions); if (action.NumParameters != expressions.Count) throw new GossipScriptParameterException( String.Format("Invalid number of parameters for action:{0} found:{1} expected:{2}", action.Name, expressions.Count, action.NumParameters)); var customActionContext = new CustomActionContext(expressions, expression); currentParent.Next = new ExecuteCustomActionNode(node, customActionContext); currentParent = currentParent.Next; index += (skip + 1); currentToken = tokens[index]; return index; } } throw new Exception("Unexpected token"); }
private int ParseReferenceObjectAccess(CompilationContext compilationContext, Token currentToken, List<Token> tokens, int index, ref IActionNode currentParent) { int varIndex = currentToken.GetAccessIndex(m_Engine.HostBridge.EnumDefineTable); // Map enums to their index counterparts if (currentToken.Type == TokenType.ReferenceObjectAccessEnum) currentToken.Type = TokenType.ReferenceObjectAccess; currentToken = tokens[++index]; // Assignment or Property set or Action only Token operand = currentToken; Expression expression; if (currentToken.Type == TokenType.ReferencePropertySet) { currentToken = tokens[++index]; AssertExpectedTokenType(currentToken, TokenType.Assignment, "Unexpected token"); currentToken = tokens[++index]; int skip = ParseExpression(index, tokens, compilationContext, out expression); index += skip; currentToken = tokens[index]; ReferenceAssignment assignment = compilationContext.ReferenceAssignmentTable.GetAssignment(varIndex); if (!m_Engine.HostBridge.TypeBindingTable.SetPropertyExists(operand.Value, assignment.Type)) throw new GossipScriptException(String.Format("Property {0} not found or is read only.", operand.Value)); PropertySetBinding setter = m_Engine.HostBridge.TypeBindingTable.GetPropertySetByName(operand.Value, assignment.Type); if (setter.ParameterType != expression.ReturnType) throw new GossipScriptException("Incompatile property set parameter"); currentParent.Next = new AssignReferenceProperty(varIndex, setter.Id, expression); currentParent = currentParent.Next; return index; } if (currentToken.Type == TokenType.Assignment) { currentToken = tokens[++index]; int skip = ParseExpression(index, tokens, compilationContext, out expression); index += skip; currentToken = tokens[index]; compilationContext.ReferenceAssignmentTable.TrackReference(varIndex, expression.HostReturnType); if (expression.ReturnType != GossipType.ReferenceObject) throw new GossipScriptException("Expected return type reference object"); // Create the assignment command currentParent.Next = new AssignReference(varIndex, expression); currentParent = currentParent.Next; return index; } // Parse Action { int skip = ParseExpression(index - 1, tokens, compilationContext, out expression); index += (skip); currentToken = tokens[index - 1]; if (currentToken.Type == TokenType.ReferenceAction) { // Create an action ReferenceAssignment actionType = compilationContext.ReferenceAssignmentTable.GetAssignment(varIndex); ActionBinding action = compilationContext.TypeBindingTable.GetActionByName(currentToken.Value, actionType.Type); ICustomActionNode node = action.CreateActionNode(); int refIndex = varIndex; // Unless the expression result is List<Expression> expressions; skip = ParseActionParameters(index, tokens, compilationContext, out expressions); if (action.NumParameters != expressions.Count) throw new GossipScriptParameterException( String.Format("Invalid number of parameters for action:{0} found:{1} expected:{2}", action.Name, expressions.Count, action.NumParameters)); var customActionContext = new CustomActionContext(expressions, refIndex); currentParent.Next = new ExecuteCustomActionNode(node, customActionContext); currentParent = currentParent.Next; index += (skip + 1); currentToken = tokens[index]; return index; } } throw new GossipScriptException("Unhandled operand"); }
private int ParseApiCalls(CompilationContext compilationContext, string currentTokenValue, int index, List<Token> tokens, Token currentToken, ref IActionNode currentParent) { bool match = false; foreach (ActionInfo function in m_Engine.GlobalActions.Values) { if (currentTokenValue == function.TokenName) { List<Expression> parametersAsExpressions; int skip = ParseFunctionParameterExpressions(index, tokens, compilationContext,out parametersAsExpressions); currentParent.Next = new ExecuteAction(function, parametersAsExpressions) {Next = new ActionNode()}; currentParent = currentParent.Next; match = true; index += skip; currentToken = tokens[index]; break; } } if (match == false) { foreach (HostCall function in m_Engine.HostBridge.HostCallTable.Values) { if (function.ReturnType == GossipType.ReferenceObject) { // First check if we are going to encounter an assignment Int32 enounterAssignmentIndex = 0; if (EncounterAssignment(index, tokens, ref enounterAssignmentIndex)) { return ParsePropertySet(compilationContext, index, tokens, ref currentParent, enounterAssignmentIndex); } Expression expression; int skip = ParseExpression(index, tokens, compilationContext, out expression); if (tokens[index + skip].Type == TokenType.ReferenceAction) { index = index + skip; currentToken = tokens[index]; // Create Action ActionBinding action = compilationContext.TypeBindingTable.GetActionByName(currentToken.Value, expression.HostReturnType); ICustomActionNode node = action.CreateActionNode(); List<Expression> expressions; skip = ParseActionParameters(index + 1, tokens, compilationContext, out expressions); if (action.NumParameters != expressions.Count) throw new GossipScriptParameterException( String.Format("Invalid number of parameters for action:{0} found:{1} expected:{2}", action.Name, expressions.Count, action.NumParameters)); var customActionContext = new CustomActionContext(expressions, expression); currentParent.Next = new ExecuteCustomActionNode(node, customActionContext); currentParent = currentParent.Next; index += (skip + 1); currentToken = tokens[index]; return index; } throw new NotImplementedException( "TODO anything that returns a reference might want to be invoked"); } } } if (match == false) throw new GossipScriptException("Encountered Unknown Token", currentToken); return index; }
public byte[] Execute(CustomActionContext context) { this.Result = context.IO.GetECUCorrectionParams(); return(null); }
public byte[] Execute(CustomActionContext context) { this.Result = context.IO.GetMAPCalibrationParams(); return(null); }
public byte[] Execute(CustomActionContext context) { this.Result = context.IO.GetSettingFormPLC(); return(null); }
byte[] ICustomTask.Execute(CustomActionContext context) { this.Result = context.IO.GetInjectorCorrectionSetting(); return(null); }
protected void ExecueJob(Job4Agent job) { var result = new AgentTaskResult(job.Identity); result.Action = job.Content.Action; try { switch (job.Content.Action) { case "Send": this.IOAgent.Send(job.Content.SendPacket); result.Successed = true; break; case "Read": result.ExecuteResult = this.IOAgent.Read(job.Content.ReadFilter, 0x00); result.Successed = true; break; case "SendAndRead": result.ExecuteResult = this.IOAgent.SendAndRead(job.Content.SendPacket, job.Content.ReadFilter); result.Successed = true; break; default: if (CustomActionExecute != null) { CustomActionContext caContext = new CustomActionContext(); caContext.Agent = this; caContext.IO = this.IOAgent; caContext.Job = job; result.ExecuteResult = CustomActionExecute(caContext); result.Successed = true; } else { result.Exception = new ArgumentException("未能识别的Action"); result.Successed = false; } break; } } catch (Exception e) { System.Diagnostics.Debug.Write("Exception Catch On AgentAsync.ExecueJob"); System.Diagnostics.Debug.WriteLine(String.Format("{0}:{1}", e.GetType(), e.Message)); System.Diagnostics.Debug.WriteLine(e.StackTrace); result.Exception = e; result.Successed = false; } result.Context = job.Content.Context; if (Scheduler.ScheduleState != ScheduleStates.Running) { return; } ResultGot(result); if (EnableResultQueue) { ResultQueue.Enqueue(result); } }
/// <summary> /// 任务实际执行方法 /// </summary> /// <param name="context">上下文</param> /// <returns>下位机返回的原始数据</returns> protected abstract byte[] ExecuteInner(CustomActionContext context);
/// <summary> /// 执行此自定义任务 /// 欲定义任务执行方法,请重写 ExecuteInner /// </summary> /// <param name="context">上下文</param> /// <returns>下位机返回的原始数据</returns> public byte[] Execute(CustomActionContext context) { this.Device.ResultGot4Custom += device_ResultGot4Custom; return(ExecuteInner(context)); }