protected void SetMap(string boxName, BoardSettings settings) { var maps = IOconfFile.GetMap(); Map = maps.SingleOrDefault(x => x.BoxName == boxName); if (Map == null) { throw new Exception($"{boxName} not found in map: {string.Join(", ", maps.Select(x => x.BoxName))}"); } Map.BoardSettings = settings; }
public IOconfMap(string row, int lineNum) : base(row, lineNum, "Map") { format = "Map;SerialNo/COM1/USB1-1.1;BoxName;[NodeName];[baud rate]"; var list = ToList(); if (list[0] != "Map") { throw new Exception($"IOconfMap: wrong format: {row} {format}"); } bool isWindows = RpiVersion.IsWindows(); if (isWindows && list[1].StartsWith("COM")) { USBPort = list[1]; } else if (!isWindows && list[1].StartsWith("USB")) { USBPort = "/dev/" + list[1]; } else { SerialNumber = list[1]; } BoxName = list[2]; if (list.Count <= 3) { return; } string distributedNodeName = list.Count == 5 ? list[3] : default; var baudrate = 0; if (list.Count >= 5 && !int.TryParse(list[4], out baudrate)) { CALog.LogErrorAndConsoleLn(LogID.A, $"Failed to parse the baud rate for the board: {BoxName}. Attempting with defaults."); } else if (list.Count == 4 && int.TryParse(list[3], out baudrate)) { BaudRate = baudrate; } else { distributedNodeName = list[3]; } BaudRate = baudrate; DistributedNode = distributedNodeName != default ? IOconfFile.GetEntries <IOconfNode>().SingleOrDefault(n => n.Name == distributedNodeName) ?? throw new Exception($"Failed to find node in configuration for Map: {row}. Format: {format}") : !IOconfFile.GetEntries <IOconfNode>().Any() ? DistributedNode : throw new Exception($"The node name is not optional for distributed deployments: {row}. Format: {format}"); }
private void SetMap(string boxName, BoardSettings settings, bool skipBoardSettings) { var maps = IOconfFile.GetMap(); Map = maps.SingleOrDefault(x => x.BoxName == boxName); if (Map == null) { throw new Exception($"{boxName} not found in map: {string.Join(", ", maps.Select(x => x.BoxName))}"); } // Map.BoardSettings == BoardSettings.Default is there since some boards need separate board settings, but have multiple sensor entries. // This check means a new BoardSettings instance will be created with first entry of board, but not updated (i.e. shared) among the rest of the board entries. if (!skipBoardSettings && Map.BoardSettings == BoardSettings.Default) { Map.BoardSettings = settings; } }
public IEnumerable <IOconfInput> GetDistributedExpandedInputConf() { if (Disabled) { yield break; } //note there is no map entry for the IOconfRpiTemp as it is not an external box, but at the moment we only expose the IOconfNode through it var nodes = IOconfFile.GetEntries <IOconfNode>().ToList(); if (nodes.Count == 0) { var map = Map = new IOconfMap($"Map;RpiFakeBox;{Name}Box", LineNumber); yield return(new IOconfInput($"RPiTemp;{Name}Gpu", LineNumber, Type, false, false, BoardSettings.Default) { Map = map, Skip = true }); yield return(new IOconfInput($"RPiTemp;{Name}Cpu", LineNumber, Type, false, false, BoardSettings.Default) { Map = map, Skip = true }); yield break; } foreach (var node in nodes) { //note there is no map entry for the IOconfRpiTemp as it not an external box, but at the moment we only expose the IOconfNode through it var map = Map = new IOconfMap($"Map;RpiFakeBox;{Name}_{node.Name}Box;{node.Name}", LineNumber); yield return(new IOconfInput($"RPiTemp;{Name}_{node.Name}Gpu", LineNumber, Type, false, false, BoardSettings.Default) { Map = map, Skip = true }); yield return(new IOconfInput($"RPiTemp;{Name}_{node.Name}Cpu", LineNumber, Type, false, false, BoardSettings.Default) { Map = map, Skip = true }); } }
///<remarks> ///if the sensor is a filter, it returns the board state name of all sources of the filter. ///</remarks> private IEnumerable <string> GetBoardStateNamesForSensors(IEnumerable <string> sensors) { var targetSources = sensors.ToHashSet(); foreach (var input in IOconfFile.GetInputs()) { if (targetSources.Contains(input.Name)) { yield return(input.BoardStateSensorName); } } foreach (var filter in IOconfFile.GetFilters()) { if (!targetSources.Contains(filter.NameInVector)) { continue; } foreach (var boardState in GetBoardStateNamesForSensors(filter.SourceNames)) { yield return(boardState); } } }
public IOconfOven(string row, int lineNum) : base(row, lineNum, "Oven") { format = "Oven;Area;HeatingElement;TypeK;[ProportionalGain];[ControlPeriod];[MaxOutputPercentage]"; var list = ToList(); if (!int.TryParse(list[1], out OvenArea)) { throw new Exception($"IOconfOven: wrong OvenArea number: {row} {format}"); } if (OvenArea < 1) { throw new Exception("Oven area must be a number bigger or equal to 1"); } HeatingElement = IOconfFile.GetHeater().Single(x => x.Name == list[2]); TemperatureSensorName = list[3]; var typeks = IOconfFile.GetTypeK().Where(t => t.Name == TemperatureSensorName).ToList(); var maths = IOconfFile.GetMath().Where(m => m.Name == TemperatureSensorName).ToList(); var filters = IOconfFile.GetFilters().Where(f => f.NameInVector == TemperatureSensorName).ToList(); var foundSensor = typeks.Count > 0 || maths.Count > 0 || filters.Count > 0; if (!foundSensor) { throw new Exception($"Failed to find sensor: {TemperatureSensorName} for oven: {row}"); } BoardStateSensorNames = typeks.Select(p => p.BoardStateSensorName) .Concat(GetBoardStateNamesForSensors(maths.SelectMany(p => p.GetSources()))) .Concat(GetBoardStateNamesForSensors(filters.SelectMany(f => f.SourceNames))) .ToList() .AsReadOnly(); if (list.Count < 5) { return; } if (!list[4].TryToDouble(out var proportionalGain)) { throw new Exception($"Failed to parse the specified proportional gain: {row}"); } ProportionalGain = proportionalGain; if (list.Count < 6) { return; } if (!TimeSpan.TryParse(list[5], out var controlPeriod)) { throw new Exception($"Failed to parse the specified control period: {row}"); } ControlPeriod = controlPeriod; if (list.Count < 7) { return; } if (!int.TryParse(list[6], out var maxOutputPercentage)) { throw new Exception($"Failed to parse the specified proportional gain: {row}"); } if (maxOutputPercentage < 0 || maxOutputPercentage > 100) { throw new Exception($"Max output percentage must be a whole number between 0 and 100: {row}"); } MaxOutputPercentage = maxOutputPercentage / 100d; }