benchtopparser/BenchtopParser/I28.cs

78 lines
3.5 KiB
C#
Raw Normal View History

2022-07-25 04:10:26 +00:00
namespace BenchtopParser {
public class I28 {
public static Dictionary<String, ProgramConfig> Load_ProgramConfig(String program_config_value) {
Dictionary<String, ProgramConfig> program_configs = new Dictionary<String, ProgramConfig>();
ProgramConfig? current = null;
foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
2022-07-25 04:10:26 +00:00
var config_line = line.Split("\t").ToList();
2022-07-25 04:16:15 +00:00
if (config_line.Count() < 2) {
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
}
2022-07-25 04:10:26 +00:00
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 ProgramConfig();
2022-07-25 04:10:26 +00:00
continue;
}
if (config_line[0].StartsWith("Stop,")) {
// Short circuit early when stop comes.
if (current != null && current.ProgramNumber != null) {
program_configs.Add(current.ProgramNumber, current);
}
current = null;
// TODO: What if multiple configs how to handle start and stop?
2022-07-25 04:10:26 +00:00
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 Configuration();
2022-07-25 04:10:26 +00:00
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 Dictionary<String, Configuration> { { lineConfig.name, lineConfig } });
} else if (current != null) {
current.Group[group].Add(lineConfig.name, lineConfig);
2022-07-25 04:10:26 +00:00
} else {
throw new Exception("Config list is null, something broke");
}
}
// TODO: What if multiple configs how to handle start and stop?
return program_configs;
}
public static Dictionary<String, TransducerVerify> Load_TransducerVerify(String transducer_verify_value) {
foreach (var line in transducer_verify_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
}
return null;
}
2022-07-25 04:10:26 +00:00
}
}