/
SADXls.cs
409 lines (332 loc) · 14.8 KB
/
SADXls.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace SAD806x
{
// EEC Analyser / Binary Editor XLS/XLSX Format
public class XlsConfigParameter
{
public string Parameter { get; set; }
public string Value { get; set; }
}
public class XlsRevision
{
public string Revision { get; set; }
public string Comments { get; set; }
}
public class XlsLevel
{
public string Value { get; set; } // Is Key
public string Label { get; set; } // Level Label
}
public class XlsQHorse
{
public string Address { get; set; }
public string Data { get; set; }
public string Parameter { get; set; }
public string Value { get; set; }
}
public class XlsTwEECer
{
public string Address { get; set; }
public string Data { get; set; }
public string Parameter { get; set; }
public string Value { get; set; }
}
public class XlsPayLoad
{
public int AddressInt { get; set; } // Is Key and Address in Header
public string Label { get; set; } // TAG in header
public string Description { get; set; }
public string Comments { get; set; }
public int Bytes { get; set; }
public bool Signed { get; set; }
public string Equation { get; set; }
public int Digits { get; set; }
public string Units { get; set; }
public List<string> BitsArray { get; set; } // BITX in header, X is 0 to 7, Value is the label
public string Address { get { return string.Format("0x{0:x4}", AddressInt); } }
public void Import(S6xRegister s6xRegister)
{
AddressInt = s6xRegister.AddressInt;
Label = s6xRegister.Label;
Description = s6xRegister.Comments;
Bytes = s6xRegister.SizeStatus == "Word" ? 2 : 1;
Signed = s6xRegister.SignedStatus == "Signed" ? true : false;
Equation = s6xRegister.ScaleExpression;
Digits = s6xRegister.ScalePrecision;
Units = s6xRegister.Units;
if (s6xRegister.isBitFlags)
{
if (BitsArray == null) BitsArray = new List<string>() { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
foreach (S6xBitFlag s6xBF in s6xRegister.BitFlags)
{
if (s6xBF.Position > 7) continue;
BitsArray[s6xBF.Position] = s6xBF.Label;
}
}
}
}
public class XlsScalar
{
public int AddressInt { get; set; } // Is Key and Address in Header
public string Key { get; set; } // Unique
public string PID { get; set; } // Short Label
public string Parameter { get; set; } // Label
public string Units { get; set; }
public string Comments { get; set; }
public int Bytes { get; set; }
public bool Signed { get; set; }
public int Digits { get; set; } // DecimalPl in Header
public string Equation { get; set; }
public string EnumName { get; set; }
public string EnumVal { get; set; }
public string Min { get; set; }
public string Max { get; set; }
public string ParentPID { get; set; }
public string ParentVal { get; set; }
public XlsLevel Level { get; set; }
public XlsLevel Level2 { get; set; }
public string Address { get { return string.Format("0x{0:x6}", AddressInt); } }
public void Import(S6xScalar s6xScalar, int xlsBaseOffset, SortedList<string, XlsLevel> xlsLevels)
{
PID = s6xScalar.ShortLabel;
Key = s6xScalar.DuplicateNum == 0 ? Key : Key + "_" + s6xScalar.DuplicateNum.ToString();
Parameter = s6xScalar.Label;
Comments = s6xScalar.Comments;
if (s6xScalar.Category != null && s6xScalar.Category != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xScalar.Category.ToUpper())
{
Level = xlsLevel;
break;
}
}
}
if (s6xScalar.Category2 != null && s6xScalar.Category2 != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xScalar.Category2.ToUpper())
{
Level2 = xlsLevel;
break;
}
}
}
AddressInt = Tools.xlsAddressFromBinAddress(s6xScalar.AddressBinInt, xlsBaseOffset);
Units = s6xScalar.Units;
Bytes = s6xScalar.Byte ? 1 : 2;
Signed = s6xScalar.Signed;
Equation = s6xScalar.ScaleExpression;
Digits = s6xScalar.ScalePrecision;
Min = Tools.getValidMinMax(s6xScalar.Min);
Max = Tools.getValidMinMax(s6xScalar.Max);
}
}
public class XlsFunction
{
public int AddressInt { get; set; } // Is Key and Address in Header
public string Key { get; set; } // Unique
public string PID { get; set; } // Short Label
public string Title { get; set; } // Label
public string Comments { get; set; }
public int Rows { get; set; }
public int Bytes { get; set; }
public bool XSigned { get; set; }
public int XDigits { get; set; } // DecimalPl in Header
public string XEquation { get; set; }
public string XUnits { get; set; }
public string XMin { get; set; }
public string XMax { get; set; }
public XlsPayLoad XPayLoad { get; set; } // Based on XPayloadTag in Header
public bool YSigned { get; set; }
public int YDigits { get; set; } // DecimalPl in Header
public string YEquation { get; set; }
public string YUnits { get; set; }
public string YMin { get; set; }
public string YMax { get; set; }
public XlsPayLoad YPayLoad { get; set; } // Based on YPayloadTag in Header
public string ParentPID { get; set; }
public string ParentVal { get; set; }
public XlsLevel Level { get; set; }
public XlsLevel Level2 { get; set; }
public string Address { get { return string.Format("0x{0:x6}", AddressInt); } }
public void Import(S6xFunction s6xFunction, int xlsBaseOffset, SortedList<string, XlsLevel> xlsLevels)
{
PID = s6xFunction.ShortLabel;
Key = s6xFunction.DuplicateNum == 0 ? Key : Key + "_" + s6xFunction.DuplicateNum.ToString();
Title = s6xFunction.Label;
Comments = s6xFunction.Comments;
if (s6xFunction.Category != null && s6xFunction.Category != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xFunction.Category.ToUpper())
{
Level = xlsLevel;
break;
}
}
}
if (s6xFunction.Category2 != null && s6xFunction.Category2 != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xFunction.Category2.ToUpper())
{
Level2 = xlsLevel;
break;
}
}
}
AddressInt = Tools.xlsAddressFromBinAddress(s6xFunction.AddressBinInt, xlsBaseOffset);
Bytes = s6xFunction.ByteInput ? 1 : 2;
Rows = s6xFunction.RowsNumber;
XSigned = s6xFunction.SignedInput;
XUnits = s6xFunction.InputUnits;
XEquation = s6xFunction.InputScaleExpression.Trim();
XDigits = s6xFunction.InputScalePrecision;
XMin = Tools.getValidMinMax(s6xFunction.InputMin);
XMax = Tools.getValidMinMax(s6xFunction.InputMax);
YSigned = s6xFunction.SignedOutput;
YUnits = s6xFunction.OutputUnits;
YEquation = s6xFunction.OutputScaleExpression.Trim();
YDigits = s6xFunction.OutputScalePrecision;
YMin = Tools.getValidMinMax(s6xFunction.OutputMin);
YMax = Tools.getValidMinMax(s6xFunction.OutputMax);
}
}
public class XlsTable
{
public int AddressInt { get; set; } // Key and Address in Header
public string Key { get; set; } // Unique
public string PID { get; set; } // Short Label
public string Title { get; set; } // Label
public string Comments { get; set; }
public int Rows { get; set; }
public int Cols { get; set; }
public int Bytes { get; set; }
public bool Signed { get; set; }
public int Digits { get; set; } // DecimalPl in Header
public string Equation { get; set; } // ZEquation in Header
public string Units { get; set; } // ZUnits in Header
public string Min { get; set; }
public string Max { get; set; }
public XlsFunction XFunction { get; set; } // Based on XLabelLink in Header
public string XLabels { get; set; } // Default Labels when no Function is known
public string XUnits { get; set; }
public XlsPayLoad XPayLoad { get; set; } // Based on XPayloadTag in Header
public XlsFunction YFunction { get; set; } // Based on YLabelLink in Header
public string YLabels { get; set; } // Default Labels when no Function is known
public string YUnits { get; set; }
public XlsPayLoad YPayLoad { get; set; } // Based on YPayloadTag in Header
public string ParentPID { get; set; }
public string ParentVal { get; set; }
public string LevelXlsKey { get; set; }
public string Level2XlsKey { get; set; }
public XlsLevel Level { get; set; }
public XlsLevel Level2 { get; set; }
public string Address { get { return string.Format("0x{0:x6}", AddressInt); } }
public void Import(S6xTable s6xTable, int xlsBaseOffset, SortedList<string, XlsLevel> xlsLevels)
{
PID = s6xTable.ShortLabel;
Key = s6xTable.DuplicateNum == 0 ? Key : Key + "_" + s6xTable.DuplicateNum.ToString();
Title = s6xTable.Label;
Comments = s6xTable.Comments;
if (s6xTable.Category != null && s6xTable.Category != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xTable.Category.ToUpper())
{
Level = xlsLevel;
break;
}
}
}
if (s6xTable.Category2 != null && s6xTable.Category2 != string.Empty)
{
foreach (XlsLevel xlsLevel in xlsLevels.Values)
{
if (xlsLevel.Label.ToUpper() == s6xTable.Category2.ToUpper())
{
Level2 = xlsLevel;
break;
}
}
}
AddressInt = Tools.xlsAddressFromBinAddress(s6xTable.AddressBinInt, xlsBaseOffset);
Cols = s6xTable.ColsNumber;
Rows = s6xTable.RowsNumber;
Bytes = s6xTable.WordOutput ? 2 : 1;
Signed = s6xTable.SignedOutput;
Equation = s6xTable.CellsScaleExpression;
Digits = s6xTable.CellsScalePrecision;
Units = s6xTable.CellsUnits;
Min = Tools.getValidMinMax(s6xTable.CellsMin);
Max = Tools.getValidMinMax(s6xTable.CellsMax);
XUnits = s6xTable.ColsUnits;
if ((XUnits == null || XUnits == string.Empty) && XFunction != null) XUnits = XFunction.XUnits;
YUnits = s6xTable.RowsUnits;
if ((YUnits == null || YUnits == string.Empty) && YFunction != null) YUnits = YFunction.XUnits;
}
}
public class XlsFile
{
public List<XlsConfigParameter> ConfigParameters = null;
public List<XlsRevision> Revisions = null;
public SortedList<string, XlsLevel> Levels = null;
public List<XlsQHorse> QHorses = null;
public List<XlsTwEECer> TwEECers = null;
public SortedList<int, XlsPayLoad> PayLoads = null;
public SortedList<string, XlsScalar> Scalars = null;
public SortedList<string, XlsFunction> Functions = null;
public SortedList<string, XlsTable> Tables = null;
private bool valid = false;
public bool Valid { get { return valid; } }
private string filePath = string.Empty;
public string FilePath { get { return filePath; } }
private string fileName = string.Empty;
public string FileName { get { return fileName; } }
public void Create(string xlsFilePath, ref SADBin sadBin)
{
filePath = xlsFilePath;
fileName = Path.GetFileName(xlsFilePath);
valid = true;
ConfigParameters = new List<XlsConfigParameter>();
Revisions = new List<XlsRevision>();
Levels = new SortedList<string, XlsLevel>();
QHorses = new List<XlsQHorse>();
TwEECers = new List<XlsTwEECer>();
PayLoads = new SortedList<int, XlsPayLoad>();
Scalars = new SortedList<string, XlsScalar>();
Functions = new SortedList<string, XlsFunction>();
Tables = new SortedList<string, XlsTable>();
// To be checked
// Some Minimum records on Config or Revisions could be required
}
public void Load(string xlsFilePath, bool forceXlsAlt)
{
XlsFile refXlsFile = this;
valid = ToolsXls.ReadXlsFile(ref refXlsFile, xlsFilePath, forceXlsAlt, true);
refXlsFile = null;
if (valid)
{
filePath = xlsFilePath;
fileName = Path.GetFileName(xlsFilePath);
}
}
public bool Save(string saveFilePath, ref List<string> lstErrors)
{
XlsFile refXlsFile = this;
bool bResult = ToolsXls.WriteXlsFile(ref refXlsFile, saveFilePath, ref lstErrors);
refXlsFile = null;
return bResult;
}
}
}