Showing the changes to Source/Libraries/GSF.EMAX/ControlFile.cs (1 of 19 files). Show all
Unified · Split
| @@ -38,7 +38,6 @@ namespace GSF.EMAX · 37 unmodified lines | ||
| 38 | 38 | // Fields |
| 39 | 39 | public string FileName; |
| 40 | 40 | public DataSize DataSize; |
| 41 | − public int ConfiguredAnalogChannels; | |
| 42 | 41 | public CTL_HEADER Header; |
| 43 | 42 | public CTL_FILE_STRUCT[] FileStructures; |
| 44 | 43 | public SYSTEM_PARAMETERS SystemParameters; |
| @@ -47,8 +46,9 @@ namespace GSF.EMAX · 2 unmodified lines | ||
| 47 | 46 | public EVENT_GROUP EventGroup; |
| 48 | 47 | public A_E_RSLTS AnalogEventResults; |
| 49 | 48 | 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; | |
| 52 | 52 | public EVENT_DISPLAY EventDisplay; |
| 53 | 53 | public SENS_RSLTS SensorResults; |
| 54 | 54 | public TPwrRcd PowerRecord; |
| @@ -62,6 +62,7 @@ namespace GSF.EMAX · 7 unmodified lines | ||
| 62 | 62 | public SEQUENCE_CHANNELS SequenceChannels; |
| 63 | 63 | public BREAKER_TRIP_TIMES BreakerTripTimes; |
| 64 | 64 | |
| 65 | + private int m_configuredAnalogChannels; | |
| 65 | 66 | private readonly List<StructureType> m_parsedSuccesses; |
| 66 | 67 | private readonly List<Tuple<StructureType, Exception>> m_parsedFailures; |
| 67 | 68 | private StructureType m_currentType; |
| @@ -94,6 +95,28 @@ namespace GSF.EMAX · 26 unmodified lines | ||
| 94 | 95 | |
| 95 | 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 | 120 | /// <summary> |
| 98 | 121 | /// Gets the analog channel count for the <see cref="ControlFile"/>. |
| 99 | 122 | /// </summary> |
| @@ -102,7 +125,7 @@ namespace GSF.EMAX · 2 unmodified lines | ||
| 102 | 125 | get |
| 103 | 126 | { |
| 104 | 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 | 139 | if (SystemParameters.samples_per_second > 5760) |
| 117 | 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 | 204 | // Read in header and file structure definitions |
| 182 | 205 | using (BinaryReader reader = new BinaryReader(stream, Encoding.ASCII, true)) |
| 183 | 206 | { |
| 207 | + // Read control header | |
| 208 | + Header = reader.ReadStructure<CTL_HEADER>(); | |
| 209 | + | |
| 184 | 210 | // 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 | 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 | 216 | if (!Enum.IsDefined(typeof(DataSize), byteValue)) |
| 191 | 217 | throw new InvalidOperationException("Invalid EMAX data size code encountered: 0x" + byteValue.ToString("X").PadLeft(2, '0')); |
| 192 | 218 | |
| 193 | 219 | DataSize = (DataSize)byteValue; |
| 194 | 220 | |
| 195 | − // Read control header | |
| 196 | − Header = new CTL_HEADER(reader); | |
| 197 | − | |
| 198 | 221 | // Create array of file structures |
| 199 | 222 | 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); | |
| 205 | 224 | |
| 206 | 225 | // ReSharper disable once LoopVariableIsNeverChangedInsideLoop |
| 207 | − do | |
| 226 | + while (fileStructure.type != StructureType.EndOfStructures) | |
| 208 | 227 | { |
| 209 | 228 | if (fileStructure.type != StructureType.Unknown) |
| 210 | 229 | fileStructures.Add(fileStructure); |
| 211 | 230 | |
| 212 | 231 | fileStructure = new CTL_FILE_STRUCT(reader); |
| 213 | 232 | } |
| 214 | − while (fileStructure.type != StructureType.EndOfStructures); | |
| 215 | 233 | |
| 216 | 234 | FileStructures = fileStructures.ToArray(); |
| 217 | 235 | } |
| @@ -240,19 +258,41 @@ namespace GSF.EMAX · 22 unmodified lines | ||
| 240 | 258 | AttemptParse(() => SystemSettings = reader.ReadStructure<SYS_SETTINGS>()); |
| 241 | 259 | break; |
| 242 | 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 | 262 | break; |
| 245 | 263 | case StructureType.ANALOG_GROUP: |
| 246 | − AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, ConfiguredAnalogChannels)); | |
| 264 | + AttemptParse(() => AnalogGroup = new ANALOG_GROUP(reader, m_configuredAnalogChannels)); | |
| 247 | 265 | break; |
| 248 | 266 | case StructureType.EVENT_GROUP: |
| 249 | 267 | AttemptParse(() => EventGroup = reader.ReadStructure<EVENT_GROUP>()); |
| 250 | 268 | break; |
| 251 | 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 | 283 | break; |
| 254 | 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 | 296 | break; |
| 257 | 297 | case StructureType.ANLG_CHNLS: |
| 258 | 298 | // TODO: Add decoder once structure definition is known... |
| @@ -307,7 +347,7 @@ namespace GSF.EMAX · 48 unmodified lines | ||
| 307 | 347 | AttemptParse(() => BoardAnalogEventChannels = reader.ReadStructure<BoardAnalogEventChannels>()); |
| 308 | 348 | break; |
| 309 | 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 | 351 | break; |
| 312 | 352 | default: |
| 313 | 353 | throw new ArgumentOutOfRangeException(); |