-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomtrade.h
More file actions
193 lines (149 loc) · 4.88 KB
/
comtrade.h
File metadata and controls
193 lines (149 loc) · 4.88 KB
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
/**
* @file comtrade.h
* @brief Definitions and helper function for parsing IEEE Std C37.111-1999 (R2005) files.
*
* This code was made using the following document:
* Identification: IEEE Std C37.111-1999
* Title: Common Format for Transient Data Exchange (COMTRADE) for Power Systems
* Revision: R2005
* Date: 02 Feb 2005
* URL: https://ieeexplore.ieee.org/document/798772
*
* @author Adam King
* @date 2023-04-19
*/
#pragma once
#include <string>
#include <vector>
#include "error.h"
#include "types.h"
#include "vectorMap.h"
namespace comtrade {
// See section `5. Configuration file` for configuration file information
// See section `6. Data file` for data file information
enum enmChannelType {
enmChannelAnalog,
enmChannelDigital,
enmChannelTypeCount
};
struct stcChannelInfoType {
uint32_t u32Index;
std::string strName;
char chrPhase;
std::string strCircuitId;
};
// 5.3.3 --> An, ch_id, ph, ccbm, uu, a, b, skew, min, max, primary, secondary, PS
struct stcAnalogChannelInfoType {
// generic channel info
stcChannelInfoType stcChannelInfo;
// analog-specific channel info
std::string strUnit;
float64_t f64ConvA;
float64_t f64ConvB;
// ignoring skew, min, max, primary, secondary, PS
//
// note that skew, primary, secondary, and PS would be needed if using real-world data
};
// 5.3.4 --> Dn, ch_id, ph, ccbm, y
struct stcDigitalChannelInfoType {
// generic channel info
stcChannelInfoType stcChannelInfo;
// digital-specific channel info
bool bInServiceState;
};
struct stcSamplingRateInfoType {
float64_t f64SamplesPerSec;
uint64_t u64LastSampleNumber;
};
struct stcDateTimeType {
struct stcDateType {
uint16_t u16Year;
uint8_t u8Month;
uint8_t u8Day;
} stcDate;
struct stcTimeType {
uint8_t u8Hour;
uint8_t u8Minute;
float64_t f64Second;
} stcTime;
};
enum enmDataFileFormatType {
enmDataFileFormatAscii,
enmDataFileFormatBinary,
enmDataFileFormatTypeCount
};
struct stcConfigFileType {
bool bInit = false;
std::string strCfgFileName;
std::string strDatFileName;
// 5.3.1 --> station_name, rec_dev_id, rev_year
std::string strStationName;
std::string strDeviceId;
std::uint16_t u16Version;
// 5.3.2 --> TT, ##A, ##D
std::uint32_t u32NumChannels;
std::uint32_t u32NumAnaChannels;
std::uint32_t u32NumDigChannels;
vm::clsVectorMap<std::string, stcAnalogChannelInfoType> objVmAnalogChannelInfo;
vm::clsVectorMap<std::string, stcDigitalChannelInfoType> objVmDigitalChannelInfo;
float32_t f32Frequency;
uint32_t u32NumSamplingRates;
std::vector<stcSamplingRateInfoType> vctSamplingRateInfo;
stcDateTimeType stcDateTimeStart;
stcDateTimeType stcDateTimeTrigger;
enmDataFileFormatType enmDataFileFormat;
float64_t f64TimeMult;
};
struct stcAnalogDataType {
int16_t i16DataRaw;
float64_t f64Data;
};
struct stcDigitalDataType {
uint16_t u16DataRaw;
std::vector<bool> vctData;
};
struct stcSampleDataType {
uint32_t u32SampleNumber;
float64_t f64TimestampUs;
vm::clsVectorMap<std::string, stcAnalogDataType*> objVmSampleAnaData;
vm::clsVectorMap<std::string, stcDigitalDataType*> objVmSampleDigData;
};
struct stcDataFileType {
bool bInit = false;
bool bSimpleSampling;
uint64_t u64TotalSamples;
uint32_t u32SampleSizeBytes;
uint32_t u32PrevSampleNumber;
// Storage by sample
std::vector<stcSampleDataType> vctSampleData;
// Storage by channel
vm::clsVectorMap<std::string, std::vector<stcAnalogDataType*>*> objVmChanAnaData;
vm::clsVectorMap<std::string, std::vector<stcDigitalDataType*>*> objVmChanDigData;
};
error::enmErrorType
parseConfigFile(
std::string const& strFileNamePrefix,
stcConfigFileType& stcCfgOut
);
error::enmErrorType
printConfigInfo(
stcConfigFileType const& stcCfg
);
error::enmErrorType
parseDataFile(
stcConfigFileType const& stcCfgIn,
stcDataFileType& stcDatOut
);
error::enmErrorType
printDataInfo(
stcConfigFileType const& stcCfg,
stcDataFileType const& stcDat,
uint64_t const u64SampleNumber
);
error::enmErrorType
printDataInfo(
stcConfigFileType const& stcCfg,
stcDataFileType const& stcDat,
std::string const& strChanName
);
}