public AdminShell.Property GenerateDefault() { var res = new AdminShell.Property(); this.InitSme(res); if (this.presetValue != null) { res.value = this.presetValue; } return(res); }
public static bool operation_checkCollection(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property checkType: isEmpty, isNotEmpty; // inputVariable reference collection proposal if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 2 && op.outputVariable.Count != 0) { return(false); } AdminShell.Property checkType = null; AdminShell.SubmodelElementCollection refCollection = null; foreach (var input in op.inputVariable) { var inputRef = input.value.submodelElement; if (inputRef is AdminShell.Property) { checkType = (inputRef as AdminShell.Property); continue; } if (!(inputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((inputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.SubmodelElementCollection) { refCollection = refElement as AdminShell.SubmodelElementCollection; } } int count = refCollection.value.Count; switch (checkType.idShort) { case "isEmpty": return(count == 0); case "isNotEmpty": return(count != 0); } return(false); }
public FormInstanceProperty( FormInstanceListOfSame parentInstance, FormDescProperty parentDesc, AdminShell.SubmodelElement source = null, bool deepCopy = false) { // way back to description this.parentInstance = parentInstance; this.desc = parentDesc; // initialize Referable var p = new AdminShell.Property(); this.sme = p; InitReferable(parentDesc, source); // check, if a source is present this.sourceSme = source; var pSource = this.sourceSme as AdminShell.Property; if (pSource != null) { // take over p.valueType = pSource.valueType; p.value = pSource.value; } else { // some more preferences if (parentDesc.allowedValueTypes != null && parentDesc.allowedValueTypes.Length >= 1) { p.valueType = parentDesc.allowedValueTypes[0]; } if (parentDesc.presetValue != null && parentDesc.presetValue.Length > 0) { p.value = parentDesc.presetValue; // immediately set touched in order to have this value saved this.Touch(); } } // create user control this.subControl = new FormSubControlProperty(); this.subControl.DataContext = this; }
public static bool operation_sendFrame(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property protocol: memory, connect // inputVariable reference frame proposal: collection // inputVariable reference submodel // outputVariable reference property sendFrameJSON if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 3 && op.outputVariable.Count != 1) { return(false); } AdminShell.Property protocol = null; AdminShell.SubmodelElementCollection refFrame = null; AdminShell.Submodel refSubmodel = null; AdminShell.Property sendFrameJSON = null; foreach (var input in op.inputVariable) { var inputRef = input.value.submodelElement; if (inputRef is AdminShell.Property) { protocol = (inputRef as AdminShell.Property); continue; } if (!(inputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((inputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.SubmodelElementCollection) { refFrame = refElement as AdminShell.SubmodelElementCollection; } if (refElement is AdminShell.Submodel) { refSubmodel = refElement as AdminShell.Submodel; } } foreach (var output in op.outputVariable) { var outputRef = output.value.submodelElement; if (!(outputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((outputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.Property) { sendFrameJSON = refElement as AdminShell.Property; } } if (protocol.value != "memory" && protocol.value != "connect") { return(false); } int frameCount = refFrame.value.Count; string frame = "{ \"frame\": { "; foreach (var smew in refFrame.value) { var sme = smew.submodelElement; if (sme.idShort == "_insert_submodel_into_frame") { frame += "\"" + "submodel" + "\" : "; var smJson = JsonConvert.SerializeObject(refSubmodel, Newtonsoft.Json.Formatting.Indented); frame += smJson; } else { frame += "\"" + sme.idShort + "\" : "; if (sme is AdminShell.Property) { frame += "\"" + (sme as AdminShell.Property).value + "\""; } else { frame += "\"\""; } } if (frameCount-- != 1) { frame += ","; } } frame += " } }"; sendFrameJSON.value = frame; Console.WriteLine(frame); if (auto.name == "automatonServiceRequester") { switch (protocol.value) { case "memory": receivedFrameJSONProvider.Add(frame); break; case "connect": sendFrameJSONRequester.Add(frame); break; } } if (auto.name == "automatonServiceProvider") { switch (protocol.value) { case "memory": receivedFrameJSONRequester.Add(frame); break; case "connect": sendFrameJSONProvider.Add(frame); break; } } return(true); }
public static bool operation_receiveProposals(AdminShell.Operation op, i40LanguageAutomaton auto) { // inputVariable property protocol: memory, connect // inputVariable reference frame proposal: collection // inputVariable reference submodel // outputVariable reference collected proposals: collection // outputVariable reference collected not understood proposals: collection // outputVariable reference collected refused proposals: collection // outputVariable reference property receivedFrameJSON if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } if (op.inputVariable.Count != 3 && op.outputVariable.Count != 4) { return(false); } AdminShell.Submodel refSubmodel = null; AdminShell.Property protocol = null; AdminShell.Property receivedFrameJSON = null; foreach (var input in op.inputVariable) { var inputRef = input.value.submodelElement; if (inputRef is AdminShell.Property) { protocol = (inputRef as AdminShell.Property); continue; } if (!(inputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((inputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.Submodel) { refSubmodel = refElement as AdminShell.Submodel; } } foreach (var output in op.outputVariable) { var outputRef = output.value.submodelElement; if (!(outputRef is AdminShell.ReferenceElement)) { return(false); } var refElement = Program.env[0].AasEnv.FindReferableByReference((outputRef as AdminShell.ReferenceElement).value); if (refElement is AdminShell.Property) { receivedFrameJSON = refElement as AdminShell.Property; } } var out1 = op.outputVariable.First(); var r2 = out1.value.submodelElement; if (!(r2 is AdminShell.ReferenceElement)) { return(false); } var ref2 = Program.env[0].AasEnv.FindReferableByReference((r2 as AdminShell.ReferenceElement).value); if (!(ref2 is AdminShell.SubmodelElementCollection)) { return(false); } var smc2 = ref2 as AdminShell.SubmodelElementCollection; if (protocol.value != "memory" && protocol.value != "connect") { return(false); } while ((auto.name == "automatonServiceRequester" && receivedFrameJSONRequester.Count != 0) || (auto.name == "automatonServiceProvider" && receivedFrameJSONProvider.Count != 0)) { string receivedFrame = ""; if (auto.name == "automatonServiceRequester") { // receivedFrame = sendFrameJSONProvider; // sendFrameJSONProvider = ""; if (receivedFrameJSONRequester.Count != 0) { receivedFrame = receivedFrameJSONRequester[0]; receivedFrameJSONRequester.RemoveAt(0); } } if (auto.name == "automatonServiceProvider") { // receivedFrame = sendFrameJSONRequester; // sendFrameJSONRequester = ""; if (receivedFrameJSONProvider.Count != 0) { receivedFrame = receivedFrameJSONProvider[0]; receivedFrameJSONProvider.RemoveAt(0); } } receivedFrameJSON.value = receivedFrame; AdminShell.Submodel submodel = null; if (receivedFrame != "") { try { if (auto.name == debugAutomaton) { int i = 0; // set breakpoint here to debug specific automaton } JObject parsed = JObject.Parse(receivedFrame); foreach (JProperty jp1 in (JToken)parsed) { if (jp1.Name == "frame") { foreach (JProperty jp2 in jp1.Value) { if (jp2.Name == "submodel") { string text = jp2.Value.ToString(); submodel = JsonConvert.DeserializeObject <AdminShell.Submodel>(text, new AdminShellConverters.JsonAasxConverter("modelType", "name")); } } } } } catch { } } if (submodel != null) { AdminShell.SubmodelElementCollection smcSubmodel = new AdminShell.SubmodelElementCollection(); smcSubmodel.idShort = submodel.idShort; foreach (var sme in submodel.submodelElements) { smcSubmodel.Add(sme.submodelElement); } smc2.Add(smcSubmodel); } } return(true); }
public void Animate( AdminShell.Property prop, Action <AdminShell.Property, AdminShell.IAasDiaryEntry> emitEvent) { // prop needs to exists and have qualifiers var q = prop.HasQualifierOfType("Animate.Args"); var args = Parse(q.value); if (args == null) { return; } // get state var state = GetState(prop, createIfNeeded: true); if (state == null) { return; } // how long till last time var deltaSecs = (DateTime.UtcNow - state.LastTime).TotalSeconds; if (deltaSecs < 0.001 * Math.Max(100, args.timer)) { return; } // save new lastTime, phase state.LastTime = DateTime.UtcNow; var phase = state.Phase; state.Phase = (state.Phase + deltaSecs * args.freq) % 2.0; // function? double?res = null; switch (args.type) { case AnimateArgs.TypeDef.Saw: res = args.ofs + args.scale * Math.Sin(-1.0 + phase); phase = phase % 2.0; break; case AnimateArgs.TypeDef.Sin: res = args.ofs + args.scale * Math.Sin(phase * 2 * Math.PI); break; case AnimateArgs.TypeDef.Cos: res = args.ofs + args.scale * Math.Cos(phase * 2 * Math.PI); break; case AnimateArgs.TypeDef.Square: res = args.ofs + ((phase < 1.0) ? -1.0 : 1.0); phase = phase % 2.0; break; } // use result? if (res.HasValue) { // set value prop.value = res.Value.ToString(CultureInfo.InvariantCulture); // send event if (emitEvent != null) { // create var evi = new AasPayloadUpdateValueItem( path: (prop as AdminShell.IGetReference)?.GetReference()?.Keys, value: prop.ValueAsText()); evi.ValueId = prop.valueId; evi.FoundReferable = prop; // add AdminShell.DiaryDataDef.AddAndSetTimestamps(prop, evi, isCreate: false); // kick lambda emitEvent.Invoke(prop, evi); } } }