History

(1) GSF.EMAX: Corrected issues with loading analog definitions, scalars and UTC time adjustments. (2) Added Nuget packages for PQDIF, EMAX, COMTRADE, SEL event parser and phasor protocol libraries.

ritchiecarroll committed 11 years ago

Commit 31c8cf61 parent 033d3a419 files · +422 −103Browse files

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

Unified · Split

Source/Libraries/GSF.EMAX/ControlFile.cs+62−22
@@ -38,7 +38,6 @@ namespace GSF.EMAX · 37 unmodified lines
3838 // Fields
3939 public string FileName;
4040 public DataSize DataSize;
41− public int ConfiguredAnalogChannels;
4241 public CTL_HEADER Header;
4342 public CTL_FILE_STRUCT[] FileStructures;
4443 public SYSTEM_PARAMETERS SystemParameters;
@@ -47,8 +46,9 @@ namespace GSF.EMAX · 2 unmodified lines
4746 public EVENT_GROUP EventGroup;
4847 public A_E_RSLTS AnalogEventResults;
4948 public IDENTSTRING IdentityString;
50− public ANLG_CHNL_NEW AnalogChannelSettings;
51− public EVNT_CHNL_NEW EventChannelSettings;
49+ public Dictionary<int, ANLG_CHNL_NEW> AnalogChannelSettings;
50+ public Dictionary<int, EVNT_CHNL_NEW> EventChannelSettings;
51+ public Dictionary<int, double> ScalingFactors;
5252 public EVENT_DISPLAY EventDisplay;
5353 public SENS_RSLTS SensorResults;
5454 public TPwrRcd PowerRecord;
@@ -62,6 +62,7 @@ namespace GSF.EMAX · 7 unmodified lines
6262 public SEQUENCE_CHANNELS SequenceChannels;
6363 public BREAKER_TRIP_TIMES BreakerTripTimes;
6464
65+ private int m_configuredAnalogChannels;
6566 private readonly List<StructureType> m_parsedSuccesses;
6667 private readonly List<Tuple<StructureType, Exception>> m_parsedFailures;
6768 private StructureType m_currentType;
@@ -94,6 +95,28 @@ namespace GSF.EMAX · 26 unmodified lines
9495
9596 #region [ Properties ]
9697
98+ /// <summary>
99+ /// Gets configured analog channels.
100+ /// </summary>
101+ public int ConfiguredAnalogChannels
102+ {
103+ get
104+ {
105+ return m_configuredAnalogChannels;
106+ }
107+ }
108+
109+ /// <summary>
110+ /// Gets the digital channel count for the <see cref="ControlFile"/>.
111+ /// </summary>
112+ public int ConfiguredDigitalChannels
113+ {
114+ get
115+ {
116+ return EventGroupCount * 8;
117+ }
118+ }
119+
97120 /// <summary>
98121 /// Gets the analog channel count for the <see cref="ControlFile"/>.
99122 /// </summary>
@@ -102,7 +125,7 @@ namespace GSF.EMAX · 2 unmodified lines
102125 get
103126 {
104127 ushort samplesPerSecond = SystemParameters.samples_per_second;
105− return ConfiguredAnalogChannels * (samplesPerSecond > 5760 ? samplesPerSecond / 5760 : 1);
128+ return m_configuredAnalogChannels * (samplesPerSecond > 5760 ? samplesPerSecond / 5760 : 1);
106129 }
107130 }
108131
@@ -116,7 +139,7 @@ namespace GSF.EMAX · 7 unmodified lines
116139 if (SystemParameters.samples_per_second > 5760)
117140 return 4;
118141
119− return 4 * (ConfiguredAnalogChannels > 32 ? 2 : 1);
142+ return 4 * (m_configuredAnalogChannels > 32 ? 2 : 1);
120143 }
121144 }
122145
@@ -181,37 +204,32 @@ namespace GSF.EMAX · 58 unmodified lines
181204 // Read in header and file structure definitions
182205 using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))
183206 {
207+ // Read control header
208+ Header = reader.ReadStructure<CTL_HEADER>();
209+
184210 // Read byte that defines number of analog channels
185− ConfiguredAnalogChannels = BinaryCodedDecimal.Decode((ushort)reader.ReadByte());
211+ m_configuredAnalogChannels = BinaryCodedDecimal.Decode(Header.id.LowByte());
186212
187213 // Read byte that defines data size (i.e., 12 or 16 bits)
188− byteValue = reader.ReadByte();
214+ byteValue = Header.id.HighByte();
189215
190216 if (!Enum.IsDefined(typeof(DataSize), byteValue))
191217 throw new InvalidOperationException("Invalid EMAX data size code encountered: 0x" + byteValue.ToString("X").PadLeft(2, '0'));
192218
193219 DataSize = (DataSize)byteValue;
194220
195− // Read control header
196− Header = new CTL_HEADER(reader);
197−
198221 // Create array of file structures
199222 List<CTL_FILE_STRUCT> fileStructures = new List<CTL_FILE_STRUCT>();
200− CTL_FILE_STRUCT fileStructure = new CTL_FILE_STRUCT
201− {
202− type = StructureType.SYSTEM_PARAMETERS,
203− offset = Header.sp_offset
204− };
223+ CTL_FILE_STRUCT fileStructure = new CTL_FILE_STRUCT(reader);
205224
206225 // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
207− do
226+ while (fileStructure.type != StructureType.EndOfStructures)
208227 {
209228 if (fileStructure.type != StructureType.Unknown)
210229 fileStructures.Add(fileStructure);
211230
212231 fileStructure = new CTL_FILE_STRUCT(reader);
213232 }
214− while (fileStructure.type != StructureType.EndOfStructures);
215233
216234 FileStructures = fileStructures.ToArray();
217235 }
@@ -240,19 +258,41 @@ namespace GSF.EMAX · 22 unmodified lines
240258 AttemptParse(() => SystemSettings = reader.ReadStructure<SYS_SETTINGS>());
241259 break;
242260 case StructureType.A_E_RSLTS:
243− AttemptParse(() => AnalogEventResults = new A_E_RSLTS(reader, ConfiguredAnalogChannels, SystemParameters.analog_groups));
261+ AttemptParse(() => AnalogEventResults = new A_E_RSLTS(reader, m_configuredAnalogChannels, SystemParameters.analog_groups));
244262 break;
245263 case StructureType.ANALOG_GROUP:
246− AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, ConfiguredAnalogChannels));
264+ AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, m_configuredAnalogChannels));
247265 break;
248266 case StructureType.EVENT_GROUP:
249267 AttemptParse(() => EventGroup = reader.ReadStructure<EVENT_GROUP>());
250268 break;
251269 case StructureType.ANLG_CHNL_NEW:
252− AttemptParse(() => AnalogChannelSettings = reader.ReadStructure<ANLG_CHNL_NEW>());
270+ AttemptParse(() =>
271+ {
272+ AnalogChannelSettings = new Dictionary<int, ANLG_CHNL_NEW>();
273+ ScalingFactors = new Dictionary<int, double>();
274+ ANLG_CHNL_NEW settings;
275+
276+ for (int i = 0; i < ConfiguredAnalogChannels; i++)
277+ {
278+ settings = reader.ReadStructure<ANLG_CHNL_NEW>();
279+ AnalogChannelSettings.Add(settings.ChannelNumber, settings);
280+ ScalingFactors.Add(settings.ChannelNumber, settings.ScalingFactor);
281+ }
282+ });
253283 break;
254284 case StructureType.EVNT_CHNL_NEW:
255− AttemptParse(() => EventChannelSettings = reader.ReadStructure<EVNT_CHNL_NEW>());
285+ AttemptParse(() =>
286+ {
287+ EventChannelSettings = new Dictionary<int, EVNT_CHNL_NEW>();
288+ EVNT_CHNL_NEW settings;
289+
290+ for (int i = 0; i < ConfiguredDigitalChannels; i++)
291+ {
292+ settings = reader.ReadStructure<EVNT_CHNL_NEW>();
293+ EventChannelSettings.Add(settings.EventNumber, settings);
294+ }
295+ });
256296 break;
257297 case StructureType.ANLG_CHNLS:
258298 // TODO: Add decoder once structure definition is known...
@@ -307,7 +347,7 @@ namespace GSF.EMAX · 48 unmodified lines
307347 AttemptParse(() => BoardAnalogEventChannels = reader.ReadStructure<BoardAnalogEventChannels>());
308348 break;
309349 case StructureType.BREAKER_TRIP_TIMES:
310− AttemptParse(() => BreakerTripTimes = new BREAKER_TRIP_TIMES(reader, ConfiguredAnalogChannels, SystemParameters.analog_groups));
350+ AttemptParse(() => BreakerTripTimes = new BREAKER_TRIP_TIMES(reader, m_configuredAnalogChannels, SystemParameters.analog_groups));
311351 break;
312352 default:
313353 throw new ArgumentOutOfRangeException();

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