65 lines
2.7 KiB
C#
65 lines
2.7 KiB
C#
|
namespace BenchtopParser {
|
|||
|
public class Parser {
|
|||
|
public static List<I28.ProgramConfig> I28_ProgramConfig(String program_config) {
|
|||
|
List<I28.ProgramConfig> program_configs = new List<I28.ProgramConfig>();
|
|||
|
I28.ProgramConfig? current = null;
|
|||
|
|
|||
|
foreach (var line in program_config.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
|||
|
var config_line = line.Split("\t").ToList();
|
|||
|
config_line.RemoveAt(0); // Remove random hex value
|
|||
|
config_line.RemoveAt(0); // Remove L column
|
|||
|
if (config_line[0].StartsWith("Start,")) {
|
|||
|
// initialize programconfig
|
|||
|
current = new I28.ProgramConfig();
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (config_line[0].StartsWith("Stop,")) {
|
|||
|
// Short circuit early when stop comes.
|
|||
|
program_configs.Add(current);
|
|||
|
break;
|
|||
|
}
|
|||
|
var config = config_line[0].Split(",", 2).ToList();
|
|||
|
if (config_line.Count() == 1) {
|
|||
|
// Set Program Number
|
|||
|
if (current == null) {
|
|||
|
throw new Exception("Setting Program Number Before Start. Error In Config");
|
|||
|
}
|
|||
|
Console.WriteLine(config[1]);
|
|||
|
current.ProgramNumber = config[1];
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
// Skip numbers, keep value
|
|||
|
var value = config[1];
|
|||
|
|
|||
|
|
|||
|
var programnumber_group_data = value.Split('\\');
|
|||
|
var data = programnumber_group_data[2];
|
|||
|
if (data.StartsWith("=")) { continue; /* comment line */ }
|
|||
|
|
|||
|
var lineConfig = new I28.Configuration();
|
|||
|
lineConfig.unit = config_line[1];
|
|||
|
lineConfig.type = config_line[2]; //a, c, f, i
|
|||
|
var name_value = data.Split("=");
|
|||
|
lineConfig.name = name_value[0];
|
|||
|
lineConfig.value = name_value[1];
|
|||
|
|
|||
|
// Deal with this group logic
|
|||
|
var group = programnumber_group_data[1];
|
|||
|
if (current != null && !current.Group.ContainsKey(group)) {
|
|||
|
current.Group.Add(group, new List<I28.Configuration> { lineConfig });
|
|||
|
} else if (current != null ) {
|
|||
|
current.Group[group].Add(lineConfig);
|
|||
|
} else {
|
|||
|
throw new Exception("Config list is null, something broke");
|
|||
|
}
|
|||
|
}
|
|||
|
// TODO: What if multiple configs how to handle start and stop?
|
|||
|
|
|||
|
return program_configs;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|