78 lines
3.4 KiB
C#
78 lines
3.4 KiB
C#
using System;
|
|
|
|
namespace BenchtopParser {
|
|
public class I28 {
|
|
public static Dictionary<String, ProgramConfig> Load_ProgramConfig(String program_config_value) {
|
|
Dictionary<String, ProgramConfig> programConfigs = new Dictionary<String, ProgramConfig>();
|
|
ProgramConfig? current = null;
|
|
|
|
foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
|
var configLine = line.Split("\t").ToList();
|
|
if (configLine.Count() < 2) {
|
|
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
|
|
}
|
|
configLine.RemoveAt(0); // Remove random hex value
|
|
configLine.RemoveAt(0); // Remove L column
|
|
if (configLine[0].StartsWith("Start,")) {
|
|
// initialize programconfig
|
|
current = new ProgramConfig();
|
|
continue;
|
|
}
|
|
if (configLine[0].StartsWith("Stop,")) {
|
|
// Short circuit early when stop comes.
|
|
if (current != null && current.ProgramNumber != null) {
|
|
programConfigs.Add(current.ProgramNumber, current);
|
|
}
|
|
current = null;
|
|
// TODO: What if multiple configs how to handle start and stop?
|
|
break;
|
|
}
|
|
var config = configLine[0].Split(",", 2).ToList();
|
|
if (configLine.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('\\'); // snake case as its three values
|
|
var data = programnumber_group_data[2];
|
|
if (data.StartsWith("=")) { continue; /* comment line */ }
|
|
|
|
var lineConfig = new Configuration();
|
|
lineConfig.unit = configLine[1];
|
|
lineConfig.type = configLine[2]; //a, c, f, i
|
|
var nameValue = data.Split("=");
|
|
lineConfig.name = nameValue[0];
|
|
lineConfig.value = nameValue[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);
|
|
} else {
|
|
throw new Exception("Config list is null, something broke");
|
|
}
|
|
}
|
|
// TODO: What if multiple configs how to handle start and stop?
|
|
|
|
return programConfigs;
|
|
}
|
|
|
|
public static TransducerVerify Load_TransducerVerify(String transducer_verify_value) {
|
|
TransducerVerify tv = new TransducerVerify(transducer_verify_value);
|
|
return tv;
|
|
}
|
|
}
|
|
}
|
|
|
|
// TODO: normalize snake or pascal case |