Skip to content

Commit 35fdb08

Browse files
committed
Preserve original formatting from VS code automatic format on save
1 parent 20481c2 commit 35fdb08

File tree

2 files changed

+90
-120
lines changed

2 files changed

+90
-120
lines changed

divert_sim/divert_sim.cpp

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#endif
88

99
#include "Console.h"
10-
//#include "emonesp.h"
1110
#include "RapiSender.h"
1211
#include "openevse.h"
1312
#include "divert.h"
@@ -46,31 +45,19 @@ time_t parse_date(const char *dateStr)
4645
{
4746
int y = 2020, M = 1, d = 1, h = 0, m = 0, s = 0;
4847
char ampm[5];
49-
if (6 != sscanf(dateStr, "%d-%d-%dT%d:%d:%dZ", &y, &M, &d, &h, &m, &s))
50-
{
51-
if (6 != sscanf(dateStr, "%d-%d-%dT%d:%d:%d+00:00", &y, &M, &d, &h, &m, &s))
52-
{
53-
if (6 != sscanf(dateStr, "%d-%d-%d %d:%d:%d", &y, &M, &d, &h, &m, &s))
54-
{
55-
if (3 != sscanf(dateStr, "%d:%d %s", &h, &m, ampm))
56-
{
57-
if (1 == sscanf(dateStr, "%d", &s))
58-
{
48+
if(6 != sscanf(dateStr, "%d-%d-%dT%d:%d:%dZ", &y, &M, &d, &h, &m, &s)) {
49+
if(6 != sscanf(dateStr, "%d-%d-%dT%d:%d:%d+00:00", &y, &M, &d, &h, &m, &s)) {
50+
if(6 != sscanf(dateStr, "%d-%d-%d %d:%d:%d", &y, &M, &d, &h, &m, &s)) {
51+
if(3 != sscanf(dateStr, "%d:%d %s", &h, &m, ampm)) {
52+
if(1 == sscanf(dateStr, "%d", &s)) {
5953
return s;
6054
}
61-
}
62-
else
63-
{
64-
y = 2020;
65-
M = 1;
66-
d = 1;
67-
s = 0;
68-
if (12 == h)
69-
{
55+
} else {
56+
y = 2020; M = 1; d = 1; s = 0;
57+
if(12 == h) {
7058
h -= 12;
7159
}
72-
if ('P' == ampm[0])
73-
{
60+
if('P' == ampm[0]) {
7461
h += 12;
7562
}
7663
}
@@ -92,13 +79,11 @@ time_t parse_date(const char *dateStr)
9279
int get_watt(const char *val)
9380
{
9481
float number = 0.0;
95-
if (1 != sscanf(val, "%f", &number))
96-
{
82+
if(1 != sscanf(val, "%f", &number)) {
9783
throw std::invalid_argument("Not a number");
9884
}
9985

100-
if (kw)
101-
{
86+
if(kw) {
10287
number *= 1000;
10388
}
10489

@@ -110,18 +95,27 @@ time_t divertmode_get_time()
11095
return simulated_time;
11196
}
11297

113-
int main(int argc, char **argv)
98+
int main(int argc, char** argv)
11499
{
115100
int voltage_arg = -1;
116101
std::string sep = ",";
117102

118103
cxxopts::Options options(argv[0], " - example command line options");
119104
options
120-
.positional_help("[optional args]")
121-
.show_positional_help();
105+
.positional_help("[optional args]")
106+
.show_positional_help();
122107

123108
options
124-
.add_options()("help", "Print help")("d,date", "The date column", cxxopts::value<int>(date_col), "N")("s,solar", "The solar column", cxxopts::value<int>(solar_col), "N")("g,gridie", "The Grid IE column", cxxopts::value<int>(grid_ie_col), "N")("attack", "The attack factor for the smoothing", cxxopts::value<double>(divert_attack_smoothing_factor))("decay", "The decay factor for the smoothing", cxxopts::value<double>(divert_decay_smoothing_factor))("v,voltage", "The Voltage column if < 50, else the fixed voltage", cxxopts::value<int>(voltage_arg), "N")("kw", "values are KW")("sep", "Field separator", cxxopts::value<std::string>(sep));
109+
.add_options()
110+
("help", "Print help")
111+
("d,date", "The date column", cxxopts::value<int>(date_col), "N")
112+
("s,solar", "The solar column", cxxopts::value<int>(solar_col), "N")
113+
("g,gridie", "The Grid IE column", cxxopts::value<int>(grid_ie_col), "N")
114+
("attack", "The attack factor for the smoothing", cxxopts::value<double>(divert_attack_smoothing_factor))
115+
("decay", "The decay factor for the smoothing", cxxopts::value<double>(divert_decay_smoothing_factor))
116+
("v,voltage", "The Voltage column if < 50, else the fixed voltage", cxxopts::value<int>(voltage_arg), "N")
117+
("kw", "values are KW")
118+
("sep", "Field separator", cxxopts::value<std::string>(sep));
125119

126120
auto result = options.parse(argc, argv);
127121

@@ -136,14 +130,10 @@ int main(int argc, char **argv)
136130
mqtt_solar = grid_ie_col >= 0 ? "" : "yes";
137131
mqtt_grid_ie = grid_ie_col >= 0 ? "yes" : "";
138132

139-
if (voltage_arg >= 0)
140-
{
141-
if (voltage_arg < 50)
142-
{
133+
if(voltage_arg >= 0) {
134+
if(voltage_arg < 50) {
143135
voltage_col = voltage_arg;
144-
}
145-
else
146-
{
136+
} else {
147137
voltage = voltage_arg;
148138
}
149139
}
@@ -158,30 +148,23 @@ int main(int argc, char **argv)
158148
int row_number = 0;
159149

160150
std::cout << "Date,Solar,Grid IE,Pilot,Charge Power,Min Charge Power,State,Smoothed Available" << std::endl;
161-
for (auto &row : parser)
151+
for (auto& row : parser)
162152
{
163153
try
164154
{
165155
int col = 0;
166156
std::string val;
167157

168-
for (auto &field : row)
158+
for (auto& field : row)
169159
{
170160
val = field;
171-
if (date_col == col)
172-
{
161+
if(date_col == col) {
173162
simulated_time = parse_date(val.c_str());
174-
}
175-
else if (grid_ie_col == col)
176-
{
163+
} else if (grid_ie_col == col) {
177164
grid_ie = get_watt(val.c_str());
178-
}
179-
else if (solar_col == col)
180-
{
165+
} else if (solar_col == col) {
181166
solar = get_watt(val.c_str());
182-
}
183-
else if (voltage_col == col)
184-
{
167+
} else if (voltage_col == col) {
185168
voltage = stoi(field);
186169
}
187170

@@ -204,7 +187,7 @@ int main(int argc, char **argv)
204187

205188
std::cout << buffer << "," << solar << "," << grid_ie << "," << ev_pilot << "," << ev_watt << "," << min_ev_watt << "," << state << "," << smoothed << std::endl;
206189
}
207-
catch (const std::invalid_argument &e)
190+
catch(const std::invalid_argument& e)
208191
{
209192
}
210193
}

0 commit comments

Comments
 (0)