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
38 // Fields38 // Fields
39 public string FileName;39 public string FileName;
40 public DataSize DataSize;40 public DataSize DataSize;
41 public int ConfiguredAnalogChannels;
42 public CTL_HEADER Header;41 public CTL_HEADER Header;
43 public CTL_FILE_STRUCT[] FileStructures;42 public CTL_FILE_STRUCT[] FileStructures;
44 public SYSTEM_PARAMETERS SystemParameters;43 public SYSTEM_PARAMETERS SystemParameters;
@@ -47,8 +46,9 @@ namespace GSF.EMAX · 2 unmodified lines
47 public EVENT_GROUP EventGroup;46 public EVENT_GROUP EventGroup;
48 public A_E_RSLTS AnalogEventResults;47 public A_E_RSLTS AnalogEventResults;
49 public IDENTSTRING IdentityString;48 public IDENTSTRING IdentityString;
50 public ANLG_CHNL_NEW AnalogChannelSettings;49 public Dictionary<int, ANLG_CHNL_NEW> AnalogChannelSettings;
51 public EVNT_CHNL_NEW EventChannelSettings;50 public Dictionary<int, EVNT_CHNL_NEW> EventChannelSettings;
51 public Dictionary<int, double> ScalingFactors;
52 public EVENT_DISPLAY EventDisplay;52 public EVENT_DISPLAY EventDisplay;
53 public SENS_RSLTS SensorResults;53 public SENS_RSLTS SensorResults;
54 public TPwrRcd PowerRecord;54 public TPwrRcd PowerRecord;
@@ -62,6 +62,7 @@ namespace GSF.EMAX · 7 unmodified lines
62 public SEQUENCE_CHANNELS SequenceChannels;62 public SEQUENCE_CHANNELS SequenceChannels;
63 public BREAKER_TRIP_TIMES BreakerTripTimes;63 public BREAKER_TRIP_TIMES BreakerTripTimes;
64 64
65 private int m_configuredAnalogChannels;
65 private readonly List<StructureType> m_parsedSuccesses;66 private readonly List<StructureType> m_parsedSuccesses;
66 private readonly List<Tuple<StructureType, Exception>> m_parsedFailures;67 private readonly List<Tuple<StructureType, Exception>> m_parsedFailures;
67 private StructureType m_currentType;68 private StructureType m_currentType;
@@ -94,6 +95,28 @@ namespace GSF.EMAX · 26 unmodified lines
94 95
95 #region [ Properties ]96 #region [ Properties ]
96 97
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
97 /// <summary>120 /// <summary>
98 /// Gets the analog channel count for the <see cref="ControlFile"/>.121 /// Gets the analog channel count for the <see cref="ControlFile"/>.
99 /// </summary>122 /// </summary>
@@ -102,7 +125,7 @@ namespace GSF.EMAX · 2 unmodified lines
102 get125 get
103 {126 {
104 ushort samplesPerSecond = SystemParameters.samples_per_second;127 ushort samplesPerSecond = SystemParameters.samples_per_second;
105 return ConfiguredAnalogChannels * (samplesPerSecond > 5760 ? samplesPerSecond / 5760 : 1);128 return m_configuredAnalogChannels * (samplesPerSecond > 5760 ? samplesPerSecond / 5760 : 1);
106 }129 }
107 }130 }
108 131
@@ -116,7 +139,7 @@ namespace GSF.EMAX · 7 unmodified lines
116 if (SystemParameters.samples_per_second > 5760)139 if (SystemParameters.samples_per_second > 5760)
117 return 4;140 return 4;
118 141
119 return 4 * (ConfiguredAnalogChannels > 32 ? 2 : 1);142 return 4 * (m_configuredAnalogChannels > 32 ? 2 : 1);
120 }143 }
121 }144 }
122 145
@@ -181,37 +204,32 @@ namespace GSF.EMAX · 58 unmodified lines
181 // Read in header and file structure definitions204 // Read in header and file structure definitions
182 using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))205 using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true))
183 {206 {
207 // Read control header
208 Header = reader.ReadStructure<CTL_HEADER>();
209
184 // Read byte that defines number of analog channels210 // Read byte that defines number of analog channels
185 ConfiguredAnalogChannels = BinaryCodedDecimal.Decode((ushort)reader.ReadByte());211 m_configuredAnalogChannels = BinaryCodedDecimal.Decode(Header.id.LowByte());
186 212
187 // Read byte that defines data size (i.e., 12 or 16 bits)213 // Read byte that defines data size (i.e., 12 or 16 bits)
188 byteValue = reader.ReadByte();214 byteValue = Header.id.HighByte();
189 215
190 if (!Enum.IsDefined(typeof(DataSize), byteValue))216 if (!Enum.IsDefined(typeof(DataSize), byteValue))
191 throw new InvalidOperationException("Invalid EMAX data size code encountered: 0x" + byteValue.ToString("X").PadLeft(2, '0'));217 throw new InvalidOperationException("Invalid EMAX data size code encountered: 0x" + byteValue.ToString("X").PadLeft(2, '0'));
192 218
193 DataSize = (DataSize)byteValue;219 DataSize = (DataSize)byteValue;
194 220
195 // Read control header
196 Header = new CTL_HEADER(reader);
197
198 // Create array of file structures221 // Create array of file structures
199 List<CTL_FILE_STRUCT> fileStructures = new List<CTL_FILE_STRUCT>();222 List<CTL_FILE_STRUCT> fileStructures = new List<CTL_FILE_STRUCT>();
200 CTL_FILE_STRUCT fileStructure = new CTL_FILE_STRUCT223 CTL_FILE_STRUCT fileStructure = new CTL_FILE_STRUCT(reader);
201 {
202 type = StructureType.SYSTEM_PARAMETERS,
203 offset = Header.sp_offset
204 };
205 224
206 // ReSharper disable once LoopVariableIsNeverChangedInsideLoop225 // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
207 do226 while (fileStructure.type != StructureType.EndOfStructures)
208 {227 {
209 if (fileStructure.type != StructureType.Unknown)228 if (fileStructure.type != StructureType.Unknown)
210 fileStructures.Add(fileStructure);229 fileStructures.Add(fileStructure);
211 230
212 fileStructure = new CTL_FILE_STRUCT(reader);231 fileStructure = new CTL_FILE_STRUCT(reader);
213 }232 }
214 while (fileStructure.type != StructureType.EndOfStructures);
215 233
216 FileStructures = fileStructures.ToArray();234 FileStructures = fileStructures.ToArray();
217 }235 }
@@ -240,19 +258,41 @@ namespace GSF.EMAX · 22 unmodified lines
240 AttemptParse(() => SystemSettings = reader.ReadStructure<SYS_SETTINGS>());258 AttemptParse(() => SystemSettings = reader.ReadStructure<SYS_SETTINGS>());
241 break;259 break;
242 case StructureType.A_E_RSLTS:260 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));
244 break;262 break;
245 case StructureType.ANALOG_GROUP:263 case StructureType.ANALOG_GROUP:
246 AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, ConfiguredAnalogChannels));264 AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, m_configuredAnalogChannels));
247 break;265 break;
248 case StructureType.EVENT_GROUP:266 case StructureType.EVENT_GROUP:
249 AttemptParse(() => EventGroup = reader.ReadStructure<EVENT_GROUP>());267 AttemptParse(() => EventGroup = reader.ReadStructure<EVENT_GROUP>());
250 break;268 break;
251 case StructureType.ANLG_CHNL_NEW:269 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 });
253 break;283 break;
254 case StructureType.EVNT_CHNL_NEW:284 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 });
256 break;296 break;
257 case StructureType.ANLG_CHNLS:297 case StructureType.ANLG_CHNLS:
258 // TODO: Add decoder once structure definition is known...298 // TODO: Add decoder once structure definition is known...
@@ -307,7 +347,7 @@ namespace GSF.EMAX · 48 unmodified lines
307 AttemptParse(() => BoardAnalogEventChannels = reader.ReadStructure<BoardAnalogEventChannels>());347 AttemptParse(() => BoardAnalogEventChannels = reader.ReadStructure<BoardAnalogEventChannels>());
308 break;348 break;
309 case StructureType.BREAKER_TRIP_TIMES:349 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));
311 break;351 break;
312 default:352 default:
313 throw new ArgumentOutOfRangeException();353 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