public static bool Validate(string expr, Settings settings) { bool valid; Parse(expr, true, out valid, null, null, settings); return valid; }
private void DisplayPriority(Settings.PayloadClass.Priority priority) { if (priority != null) { var ps = priority.PriorityOrder .Where(w => w.Second == Settings.PayloadClass.Priority.PriorityState.Used) .Select(w => settings.Payload.Buttons[w.First].Name + " (" + settings.Payload.Buttons[w.First].PinID + ")"); Invoke((MethodInvoker)delegate { lstPriorities.Items.Clear(); foreach (var s in ps) lstPriorities.Items.Add(s); }); } else Invoke((MethodInvoker)delegate { lstPriorities.Items.Clear(); lstPriorities.Items.Add("(no priorities)"); }); }
private void SetupInitialHysteresis(float[] oldAI, ref float oldTemp, ref float oldRH, Settings settings) { for (int i = 0; i < 8; ++i) { oldAI[i] = LJ.ReadAnalogInput(i); if (settings.Payload.HysteresisAI.ContainsKey(i)) { if (oldAI[i] < settings.Payload.HysteresisAI[i].From) LJ.SetDigitalOutput(settings.Payload.HysteresisAI[i].PinID, true, 1); } } LJ.ReadTemperatureHumidity(out oldTemp, out oldRH); if (settings.Payload.Hysteresis.ContainsKey(Settings.PayloadClass.HysteresisKind.Humidity)) { if (oldRH < settings.Payload.Hysteresis[Settings.PayloadClass.HysteresisKind.Humidity].From) LJ.SetDigitalOutput(settings.Payload.Hysteresis[Settings.PayloadClass.HysteresisKind.Humidity].PinID, true, 1); } if (settings.Payload.Hysteresis.ContainsKey(Settings.PayloadClass.HysteresisKind.Temperature)) { if (oldTemp < settings.Payload.Hysteresis[Settings.PayloadClass.HysteresisKind.Temperature].From) LJ.SetDigitalOutput(settings.Payload.Hysteresis[Settings.PayloadClass.HysteresisKind.Temperature].PinID, true, 1); } }
public frmEditTestSet(Settings settings, Settings.PayloadClass.TestSet testset) { this.settings = settings; this.testset = testset; InitializeComponent(); }
private static bool? Parse(string expr, bool validateOnly, out bool valid, int[] dstate, double[] astate, Settings settings) { // foreach (var redefinition in AutoCompleteExpressionBox.GetRedefitionions(settings)) // { // string key = "[" + redefinition.Value + "]"; // expr = ReplaceAll(expr, key, " " + redefinition.Key + " "); // } expr += " "; valid = true; bool? result = null; OperandType ot = OperandType.First; int index = 0; // handle doorup/down/still string strdu = "(a1>" + settings.Payload.ZeroToleranceHigh + ")", strdd = "(a1<" + settings.Payload.ZeroToleranceLow + ")", strds = "(a1>=" + settings.Payload.ZeroToleranceLow + " and a1<=" + settings.Payload.ZeroToleranceHigh + ")"; // expr = ReplaceAll(ReplaceAll(ReplaceAll(expr, "doorup", strdu), "doordown", strdd), "doorstill", strds); expr = PreProcess(expr, AutoCompleteExpressionBox.GetRedefitionions(settings), strdu, strdd, strds); while (true) { // eat space while (index < expr.Length && char.IsWhiteSpace(expr[index])) ++index; if (index >= expr.Length) break; // (...) and (...) or (...) if (expr[index] == '(') { if (ot == OperandType.NotFirst) { valid = false; return null; } // find the end of the subexpression int balance = 1, ending; for (ending = index + 1; ending < expr.Length && balance != 0; ++ending) if (expr[ending] == '(') ++balance; else if (expr[ending] == ')') --balance; if (balance != 0) { valid = false; return null; } bool? res = Parse(expr.Substring(index + 1, ending - index - 2), validateOnly, out valid, dstate, astate, settings); index = ending; if (!valid) return null; if (ot == OperandType.First) { if (!validateOnly) result = res; } else if (ot == OperandType.And) { if (!validateOnly) result &= res; } else if (ot == OperandType.Or) { if (!validateOnly) result |= res; } ot = OperandType.NotFirst; } else if (string.Compare("and", 0, expr, index, 3, true) == 0 || string.Compare("or", 0, expr, index, 2, true) == 0) { // and // or if (ot != OperandType.NotFirst) { valid = false; return null; } if (expr[index] == 'a' || expr[index] == 'A') { ot = OperandType.And; index += 3; } else { ot = OperandType.Or; index += 2; } } else { // channel comparison number // channel:==a[1..1]|d[1..16] if (ot == OperandType.NotFirst) { valid = false; return null; } int ending = index + 1; if (expr[index] == 'a' || expr[index] == 'A' || expr[index] == 'd' || expr[index] == 'D') { while (ending < expr.Length && char.IsNumber(expr[ending])) ++ending; if (ending == index + 1) { valid = false; return null; } // further tests } else { valid = false; return null; } string channel = expr.Substring(index, ending - index); index = ending; // eat space while (index < expr.Length && char.IsWhiteSpace(expr[index])) ++index; if (index >= expr.Length) { valid = false; return null; } // comparison ending = index; if (expr[index] == '<' || expr[index] == '>' || expr[index] == '=' || expr[index] == '!') if (index + 1 < expr.Length) if (expr[index + 1] == '=') ++ending; string comparison = expr.Substring(index, ending - index + 1); index = ending + 1; // eat space while (index < expr.Length && char.IsWhiteSpace(expr[index])) ++index; if (index >= expr.Length) { valid = false; return null; } // number for (ending = index; ending < expr.Length && !char.IsWhiteSpace(expr[ending]); ++ending) ; if (channel[0] == 'a' || channel[0] == 'A') { double number; if (!double.TryParse(expr.Substring(index, ending - index + 1), out number)) { valid = false; return null; } if (!validateOnly) { bool res; try { int cn = int.Parse(channel.Substring(1)); double cv = astate[cn - 1]; switch (comparison) { case "<": res = cv < number; break; case ">": res = cv > number; break; case "=": res = cv == number; break; case "==": res = cv == number; break; case "<=": res = cv <= number; break; case ">=": res = cv >= number; break; default: valid = false; return null; } } catch { valid = false; return null; } if (ot == OperandType.First) { if (!validateOnly) result = res; } else if (ot == OperandType.And) { if (!validateOnly) result &= res; } else if (ot == OperandType.Or) { if (!validateOnly) result |= res; } } ot = OperandType.NotFirst; // eat the number index = ending; } else { int number; if (!int.TryParse(expr.Substring(index, ending - index + 1), out number)) { valid = false; return null; } if (!validateOnly) { bool res; try { int cn = int.Parse(channel.Substring(1)); int cv = dstate[cn - 1]; switch (comparison) { case "<": res = cv < number; break; case ">": res = cv > number; break; case "=": res = cv == number; break; case "==": res = cv == number; break; case "<=": res = cv <= number; break; case ">=": res = cv >= number; break; default: valid = false; return null; } } catch { valid = false; return null; } if (ot == OperandType.First) { if (!validateOnly) result = res; } else if (ot == OperandType.And) { if (!validateOnly) result &= res; } else if (ot == OperandType.Or) { if (!validateOnly) result |= res; } } ot = OperandType.NotFirst; // eat the number index = ending; } } } return validateOnly ? result : result ?? true; }
public bool Validate(Settings settings) { return Validate(Expression, settings); }
public bool Evaluate(int[] dstate, double[] astate, Settings settings) { bool valid; return Parse(Expression, false, out valid, dstate, astate, settings).Value; }
public frmEdit(Settings settings) { InitializeComponent(); this.settings = settings; }
public static Dictionary<string, string> GetRedefitionions(Settings settings) { Dictionary<string, string> suggestions = new Dictionary<string, string>(); // first read the settings for the default buttons foreach (var button in settings.Payload.Buttons) { string key = "D" + button.PinID; if (!suggestions.Keys.Contains(key)) suggestions.Add(key, button.Name); } // let the user redefine as he sees fit foreach (var redefinition in settings.Payload.DigitalNameOverrides) { string key = "D" + redefinition.Key; if (suggestions.Keys.Contains(key)) suggestions[key] = redefinition.Value; else suggestions.Add(key, redefinition.Value); } return suggestions; }
public frmEditPriority(Settings settings, Settings.PayloadClass.Priority priority) { this.settings = settings; this.priority = priority; InitializeComponent(); }
public AutoCompleteExpressionBoxCustomization(Settings settings) { this.settings = settings; InitializeComponent(); }
public frmEditLink(Settings settings) { InitializeComponent(); this.settings = settings; OrigFrom = From; }
public frmOptions(Settings settings) { this.settings = settings; InitializeComponent(); }