2022-07-25 04:10:26 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-07-26 05:23:41 +00:00
|
|
|
|
using System.Dynamic;
|
2022-07-25 04:10:26 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BenchtopParser {
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public class Program {
|
|
|
|
|
public String? ProgramNumber { get; set; }
|
2022-07-25 04:10:26 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
// Config Groups. TODO: rename to w/e the heck they are.
|
2022-07-26 05:52:37 +00:00
|
|
|
|
public Dictionary<String, Configuration> A = new();
|
|
|
|
|
public Dictionary<String, Configuration> I = new();
|
|
|
|
|
public Dictionary<String, Configuration> M = new();
|
|
|
|
|
public Dictionary<String, Configuration> O = new();
|
|
|
|
|
public Dictionary<String, Configuration> P = new();
|
|
|
|
|
public Dictionary<String, Configuration> R = new();
|
|
|
|
|
public Dictionary<String, Configuration> S = new();
|
|
|
|
|
public Dictionary<String, Configuration> T = new();
|
|
|
|
|
public Dictionary<String, Configuration> U = new();
|
|
|
|
|
public Dictionary<String, Configuration> X = new();
|
2022-07-26 05:17:53 +00:00
|
|
|
|
|
2022-07-26 05:48:18 +00:00
|
|
|
|
public string Name() {
|
|
|
|
|
if (M != null && M["Name"] != null && M["Name"].value != null) {
|
|
|
|
|
return M["Name"].value;
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public void AddToGroup(String group, Configuration config) {
|
|
|
|
|
// UGLY - but helpful later.
|
|
|
|
|
// TODO: Find out what the config names are and MAKE A MAP
|
|
|
|
|
var name = config.name;
|
|
|
|
|
if (name == null) {
|
|
|
|
|
throw new Exception("Name is null, adding before Config has set name");
|
2022-07-25 04:10:26 +00:00
|
|
|
|
}
|
2022-07-26 05:17:53 +00:00
|
|
|
|
|
|
|
|
|
switch (group.ToUpper()) {
|
|
|
|
|
case "A": this.A.Add(name, config); break;
|
|
|
|
|
case "I": this.I.Add(name, config); break;
|
|
|
|
|
case "M": this.M.Add(name, config); break;
|
|
|
|
|
case "O": this.O.Add(name, config); break;
|
|
|
|
|
case "P": this.P.Add(name, config); break;
|
|
|
|
|
case "R": this.R.Add(name, config); break;
|
|
|
|
|
case "S": this.S.Add(name, config); break;
|
|
|
|
|
case "T": this.T.Add(name, config); break;
|
|
|
|
|
case "U": this.U.Add(name, config); break;
|
|
|
|
|
case "X": this.X.Add(name, config); break;
|
2022-07-26 05:48:18 +00:00
|
|
|
|
default: throw new Exception($"No group {group} configured. Please fix configuration");
|
2022-07-26 04:59:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 05:17:53 +00:00
|
|
|
|
}
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public class Configuration {
|
2022-07-26 05:48:18 +00:00
|
|
|
|
public String name { get; set; }
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public String? value { get; set; }
|
|
|
|
|
public String? unit { get; set; }
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:30:36 +00:00
|
|
|
|
public String? type { get; set; } //possible values are: a, c, f, i. Which I presume are Array, Characters, Float, Integer
|
|
|
|
|
|
2022-07-26 05:48:18 +00:00
|
|
|
|
public Configuration(string name, string? value, string? unit, string? type) {
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.value = value;
|
|
|
|
|
this.unit = unit;
|
|
|
|
|
this.type = type;
|
|
|
|
|
}
|
2022-07-26 05:30:36 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public Configuration(List<String> config, String data) {
|
|
|
|
|
String[] nameValue = data.Split("=");
|
|
|
|
|
name = nameValue[0].Trim();
|
|
|
|
|
value = nameValue[1].Trim();
|
|
|
|
|
|
|
|
|
|
unit = config[1].Trim();
|
2022-07-26 05:30:36 +00:00
|
|
|
|
type = config[2].Trim();
|
2022-07-26 05:17:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
public class ProgramConfig {
|
2022-07-26 05:52:37 +00:00
|
|
|
|
public Dictionary<String, Program> programs = new();
|
2022-07-26 05:30:36 +00:00
|
|
|
|
public ProgramConfig(String program_config_value) {
|
2022-07-26 05:17:53 +00:00
|
|
|
|
Program? current = null;
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
|
|
|
|
List<String> configLine = line.Split("\t").ToList();
|
|
|
|
|
if (configLine.Count < 2) {
|
|
|
|
|
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove the first two items because they seem to be a checksum and an unneeded type.
|
|
|
|
|
// Then we can start at 0 like normal, not have the first important bit be at 2.
|
|
|
|
|
configLine.RemoveAt(0); // Remove random hex value
|
|
|
|
|
configLine.RemoveAt(0); // Remove L column
|
|
|
|
|
|
|
|
|
|
/* LOOP CONTROL */
|
|
|
|
|
if (configLine[0].StartsWith("Start,")) {
|
|
|
|
|
// initialize programconfig
|
|
|
|
|
current = new Program();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (configLine[0].StartsWith("Stop,")) {
|
|
|
|
|
// Short circuit early when stop comes.
|
|
|
|
|
if (current != null && current.ProgramNumber != null) {
|
|
|
|
|
programs.Add(current.ProgramNumber, current);
|
2022-07-26 04:59:04 +00:00
|
|
|
|
}
|
2022-07-26 05:17:53 +00:00
|
|
|
|
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");
|
2022-07-26 04:59:04 +00:00
|
|
|
|
}
|
2022-07-26 05:17:53 +00:00
|
|
|
|
current.ProgramNumber = config[1];
|
|
|
|
|
continue;
|
2022-07-26 04:59:04 +00:00
|
|
|
|
}
|
2022-07-26 05:17:53 +00:00
|
|
|
|
/* CREATE A CONFIGURATION */
|
2022-07-26 04:41:48 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
var value = config[1];
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
var programnumber_group_data = value.Split('\\'); // snake case as its three values
|
|
|
|
|
var data = programnumber_group_data[2];
|
|
|
|
|
if (data.StartsWith("=")) { continue; /* comment line */ }
|
|
|
|
|
|
2022-07-26 05:52:37 +00:00
|
|
|
|
Configuration lineConfig = new(configLine, data);
|
2022-07-26 05:17:53 +00:00
|
|
|
|
|
|
|
|
|
// Deal with this group logic
|
|
|
|
|
if (current != null) {
|
|
|
|
|
current.AddToGroup(programnumber_group_data[1], lineConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// TODO: What if multiple configs how to handle start and stop?
|
|
|
|
|
}
|
2022-07-26 04:59:04 +00:00
|
|
|
|
|
2022-07-26 05:17:53 +00:00
|
|
|
|
}
|
2022-07-26 05:30:36 +00:00
|
|
|
|
|
2022-07-25 04:10:26 +00:00
|
|
|
|
}
|