History

GSF.EMAX: Added base data file parser.

ritchiecarroll committed 12 years ago

Commit c03ac011 parent 77806c17 files · +615 −46Browse files

Showing the changes to Source/Libraries/GSF.EMAX/ControlFileStructures.cs (1 of 7 files). Show all

Unified · Split

Source/Libraries/GSF.EMAX/ControlFileStructures.cs+46−38
@@ -73,17 +73,25 @@ namespace GSF.EMAX · 72 unmodified lines
73 {73 {
74 public UInt24 id; // System ID74 public UInt24 id; // System ID
75 public uint time; // Time of CTL file creation75 public uint time; // Time of CTL file creation
76 public ushort num_of_structs; // Number of Structures in CTL file (not really)76 public int num_of_structs; // Number of Structures in CTL file (not really)
77 77
78 public CTL_HEADER(BinaryReader reader)78 public CTL_HEADER(BinaryReader reader)
79 {79 {
80 id = BigEndian.ToUInt24(reader.ReadBytes(3), 0);80 id = BigEndian.ToUInt24(reader.ReadBytes(3), 0);
81 time = BigEndian.ToUInt32(reader.ReadBytes(4), 0);81 time = BigEndian.ToUInt32(reader.ReadBytes(4), 0);
82 num_of_structs = BigEndian.ToUInt16(reader.ReadBytes(2), 0);82 num_of_structs = (int)BinaryCodedDecimal.Decode((uint)BigEndian.ToUInt16(reader.ReadBytes(2), 0));
83 83
84 // Skip padding84 // Skip padding
85 reader.ReadBytes(2);85 reader.ReadBytes(2);
86 }86 }
87
88 public DateTime Timestamp
89 {
90 get
91 {
92 return (new UnixTimeTag(time)).ToDateTime();
93 }
94 }
87 }95 }
88 96
89 public struct CTL_FILE_STRUCT97 public struct CTL_FILE_STRUCT
@@ -469,49 +477,49 @@ namespace GSF.EMAX · 379 unmodified lines
469 private const int PEAK_CAL_LEN = 4;477 private const int PEAK_CAL_LEN = 4;
470 478
471 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CHANLNUM_LEN + 1)]479 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CHANLNUM_LEN + 1)]
472 string chanlnum;480 public string chanlnum;
473 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TITLE_LEN + 1)]481 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TITLE_LEN + 1)]
474 string title;482 public string title;
475 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TYPE_LEN + 1)]483 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = TYPE_LEN + 1)]
476 string type;484 public string type;
477 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = PRIMARY_LEN + 1)]485 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = PRIMARY_LEN + 1)]
478 string primary;486 public string primary;
479 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SECONDARY_LEN + 1)]487 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SECONDARY_LEN + 1)]
480 string secondary;488 public string secondary;
481 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CAL_LEN + 1)]489 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CAL_LEN + 1)]
482 string cal_in;490 public string cal_in;
483 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CAL_LEN + 1)]491 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CAL_LEN + 1)]
484 string cal_ref;492 public string cal_ref;
485 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SHUNT_LEN + 1)]493 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SHUNT_LEN + 1)]
486 string shunt;494 public string shunt;
487 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ZERO_LINE_LEN + 1)]495 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ZERO_LINE_LEN + 1)]
488 string display_location;496 public string display_location;
489 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SCALE_FACTOR_LEN + 1)]497 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SCALE_FACTOR_LEN + 1)]
490 string display_scale;498 public string display_scale;
491 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = LIMIT_SET_LEN + 1)]499 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = LIMIT_SET_LEN + 1)]
492 string limit_set;500 public string limit_set;
493 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]501 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]
494 string limit_on_off;502 public string limit_on_off;
495 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]503 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]
496 string over_set;504 public string over_set;
497 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]505 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]
498 string over_on_off;506 public string over_on_off;
499 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]507 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]
500 string under_set;508 public string under_set;
501 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]509 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]
502 string under_on_off;510 public string under_on_off;
503 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]511 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = SET_LEN + 1)]
504 string rate_set;512 public string rate_set;
505 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]513 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ON_OFF_LEN + 1)]
506 string rate_on_off;514 public string rate_on_off;
507 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MULT_FACT_LEN + 1)]515 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MULT_FACT_LEN + 1)]
508 string mult_factor;516 public string mult_factor;
509 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CT_RATIO_LEN + 1)]517 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = CT_RATIO_LEN + 1)]
510 string ct_ratio;518 public string ct_ratio;
511 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = PEAK_CAL_LEN + 1)]519 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = PEAK_CAL_LEN + 1)]
512 string peak_cal;520 public string peak_cal;
513 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]521 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
514 string cr_lf;522 public string cr_lf;
515 }523 }
516 524
517 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]525 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
@@ -523,17 +531,17 @@ namespace GSF.EMAX · 5 unmodified lines
523 private const int E_ON_OFF_LEN = 3;531 private const int E_ON_OFF_LEN = 3;
524 532
525 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = EVENTNUM_LEN + 1)]533 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = EVENTNUM_LEN + 1)]
526 string eventnum;534 public string eventnum;
527 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_TITLE_LEN + 1)]535 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_TITLE_LEN + 1)]
528 string e_title;536 public string e_title;
529 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NC_NO_LEN + 1)]537 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = NC_NO_LEN + 1)]
530 string nc_no;538 public string nc_no;
531 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_ON_OFF_LEN + 1)]539 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_ON_OFF_LEN + 1)]
532 string alarm_on_off;540 public string alarm_on_off;
533 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_ON_OFF_LEN + 1)]541 [MarshalAs(UnmanagedType.ByValTStr, SizeConst = E_ON_OFF_LEN + 1)]
534 string rtn_on_off;542 public string rtn_on_off;
535 [MarshalAs(UnmanagedType.I2)]543 [MarshalAs(UnmanagedType.I2)]
536 ushort eveentdebouncems;544 public ushort eveentdebouncems;
537 }545 }
538 546
539 // Since this structure includes dynamically sized arrays, we manually parse structure547 // Since this structure includes dynamically sized arrays, we manually parse structure
@@ -691,12 +699,12 @@ namespace GSF.EMAX · 151 unmodified lines
691 public struct A_SELECTION699 public struct A_SELECTION
692 {700 {
693 public short size;701 public short size;
694 public string value;702 public byte[] value;
695 703
696 public A_SELECTION(BinaryReader reader)704 public A_SELECTION(BinaryReader reader)
697 {705 {
698 size = reader.ReadInt16();706 size = reader.ReadInt16();
699 value = Encoding.ASCII.GetString(reader.ReadBytes(size));707 value = reader.ReadBytes(size);
700 }708 }
701 }709 }
702 710
@@ -862,9 +870,9 @@ namespace GSF.EMAX · 159 unmodified lines
862 public struct FAULT_LOCATION870 public struct FAULT_LOCATION
863 {871 {
864 [MarshalAs(UnmanagedType.I2)]872 [MarshalAs(UnmanagedType.I2)]
865 short type;873 public short type;
866 [MarshalAs(UnmanagedType.R4)]874 [MarshalAs(UnmanagedType.R4)]
867 float k;875 public float k;
868 };876 };
869 877
870 // Since this structure includes a dynamically sized array, we manually parse structure878 // Since this structure includes a dynamically sized array, we manually parse structure
@@ -896,16 +904,16 @@ namespace GSF.EMAX · 25 unmodified lines
896 public struct SEQUENCE_CHANNELS904 public struct SEQUENCE_CHANNELS
897 {905 {
898 public short length;906 public short length;
899 public SEQUENCE_CHANNEL[] groups;907 public SEQUENCE_CHANNEL[] channels;
900 908
901 public SEQUENCE_CHANNELS(BinaryReader reader)909 public SEQUENCE_CHANNELS(BinaryReader reader)
902 {910 {
903 length = reader.ReadInt16();911 length = reader.ReadInt16();
904 groups = new SEQUENCE_CHANNEL[length / Marshal.SizeOf(typeof(SEQUENCE_CHANNEL))];912 channels = new SEQUENCE_CHANNEL[length / Marshal.SizeOf(typeof(SEQUENCE_CHANNEL))];
905 913
906 for (int i = 0; i < groups.Length; i++)914 for (int i = 0; i < channels.Length; i++)
907 {915 {
908 groups[i] = reader.ReadStructure<SEQUENCE_CHANNEL>();916 channels[i] = reader.ReadStructure<SEQUENCE_CHANNEL>();
909 }917 }
910 }918 }
911 }919 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t