Skip to content

Commit 064f6aa

Browse files
author
Jan VL
committed
fix(format): reduce line length to 90 chars and replace Unicode with ASCII
1 parent f4ebe11 commit 064f6aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1077
-683
lines changed

.clang-format

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ IndentPPDirectives: AfterHash
2020
IndentWrappedFunctionNames: false
2121

2222
# Line width
23-
ColumnLimit: 100
23+
ColumnLimit: 90
2424

2525
# Braces
2626
BreakBeforeBraces: Attach # K&R style - opening brace on same line
@@ -60,7 +60,8 @@ AlwaysBreakAfterReturnType: None
6060
AlwaysBreakBeforeMultilineStrings: false
6161
AlwaysBreakTemplateDeclarations: Yes
6262
BinPackArguments: true
63-
BinPackParameters: true
63+
BinPackParameters: false
64+
AllowAllParametersOfDeclarationOnNextLine: false
6465
BreakBeforeBinaryOperators: None
6566
BreakBeforeTernaryOperators: true
6667
BreakConstructorInitializers: BeforeColon

examples/command_handling_example.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ void scada_host_thread() {
6969

7070
cmd_result = scada.publish_node_command("Gateway01", scan_cmd);
7171
if (!cmd_result) {
72-
std::cerr << "[SCADA] Failed to send scan rate command: " << cmd_result.error() << "\n";
72+
std::cerr << "[SCADA] Failed to send scan rate command: " << cmd_result.error()
73+
<< "\n";
7374
} else {
7475
std::cout << "[SCADA] Scan rate command sent\n";
7576
}
@@ -113,7 +114,8 @@ int main() {
113114
std::cout << "[EDGE NODE] -> Changing scan rate to " << new_rate << "ms\n";
114115
scan_rate_ms = new_rate;
115116
} else if (metric.name() == "Node Control/Reboot" && metric.boolean_value()) {
116-
std::cout << "[EDGE NODE] -> REBOOT requested (not implemented in this example)\n";
117+
std::cout
118+
<< "[EDGE NODE] -> REBOOT requested (not implemented in this example)\n";
117119
}
118120
}
119121
} else if (topic.message_type == sparkplug::MessageType::DCMD) {
@@ -169,7 +171,8 @@ int main() {
169171

170172
auto device_birth_result = publisher->publish_device_birth("Motor01", device_birth);
171173
if (!device_birth_result) {
172-
std::cerr << "[EDGE NODE] Failed to publish DBIRTH: " << device_birth_result.error() << "\n";
174+
std::cerr << "[EDGE NODE] Failed to publish DBIRTH: " << device_birth_result.error()
175+
<< "\n";
173176
return 1;
174177
}
175178

@@ -191,8 +194,8 @@ int main() {
191194
if (!rebirth_result) {
192195
std::cerr << "[EDGE NODE] Rebirth failed: " << rebirth_result.error() << "\n";
193196
} else {
194-
std::cout << "[EDGE NODE] Rebirth complete (new bdSeq: " << publisher->get_bd_seq()
195-
<< ")\n";
197+
std::cout << "[EDGE NODE] Rebirth complete (new bdSeq: "
198+
<< publisher->get_bd_seq() << ")\n";
196199
}
197200
do_rebirth = false;
198201
}
@@ -205,8 +208,8 @@ int main() {
205208
if (data_result) {
206209
count++;
207210
if (count % 5 == 0) {
208-
std::cout << "[EDGE NODE] Published " << count << " NDATA messages (temp=" << temperature
209-
<< ")\n";
211+
std::cout << "[EDGE NODE] Published " << count
212+
<< " NDATA messages (temp=" << temperature << ")\n";
210213
}
211214
}
212215

examples/host_application_basic_c.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ void signal_handler(int signum) {
1313
}
1414

1515
// Callback function that gets called for each received message
16-
void on_message(const char* topic, const uint8_t* payload_data, size_t payload_len,
16+
void on_message(const char* topic,
17+
const uint8_t* payload_data,
18+
size_t payload_len,
1719
void* user_data) {
1820
(void)user_data;
1921

@@ -114,8 +116,8 @@ int main(void) {
114116
signal(SIGINT, signal_handler);
115117
signal(SIGTERM, signal_handler);
116118

117-
sparkplug_host_application_t* host =
118-
sparkplug_host_application_create("tcp://localhost:1883", "c_host_example", "SCADA01");
119+
sparkplug_host_application_t* host = sparkplug_host_application_create(
120+
"tcp://localhost:1883", "c_host_example", "SCADA01");
119121

120122
if (!host) {
121123
fprintf(stderr, "Failed to create host application\n");

examples/host_application_debug.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,33 @@ int main() {
9595
const org::eclipse::tahu::protobuf::Payload& payload) {
9696
int count = ++message_count;
9797

98-
std::cout << "\n╔════════════════════════════════════════════════════════════╗\n";
99-
std::cout << " Message #" << std::setw(3) << count << " - " << std::setw(7)
100-
<< message_type_name(topic.message_type) << std::string(39, ' ') << "\n";
101-
std::cout << "╠════════════════════════════════════════════════════════════╣\n";
98+
std::cout << "\n+============================================================+\n";
99+
std::cout << "| Message #" << std::setw(3) << count << " - " << std::setw(7)
100+
<< message_type_name(topic.message_type) << std::string(39, ' ') << "|\n";
101+
std::cout << "+============================================================+\n";
102102

103-
std::cout << " Topic: " << std::left << std::setw(51) << topic.to_string() << "\n";
104-
std::cout << " Group: " << std::setw(51) << topic.group_id << "\n";
105-
std::cout << " Edge Node: " << std::setw(47) << topic.edge_node_id << "\n";
103+
std::cout << "| Topic: " << std::left << std::setw(51) << topic.to_string() << "|\n";
104+
std::cout << "| Group: " << std::setw(51) << topic.group_id << "|\n";
105+
std::cout << "| Edge Node: " << std::setw(47) << topic.edge_node_id << "|\n";
106106

107107
if (!topic.device_id.empty()) {
108-
std::cout << " Device: " << std::setw(50) << topic.device_id << "\n";
108+
std::cout << "| Device: " << std::setw(50) << topic.device_id << "|\n";
109109
}
110110

111111
if (payload.has_timestamp()) {
112-
std::cout << "║ Payload Timestamp: " << std::setw(39) << payload.timestamp() << "\n";
112+
std::cout << "| Payload Timestamp: " << std::setw(39) << payload.timestamp()
113+
<< "|\n";
113114
}
114115

115116
if (payload.has_seq()) {
116-
std::cout << " Sequence: " << std::setw(48) << payload.seq() << "\n";
117+
std::cout << "| Sequence: " << std::setw(48) << payload.seq() << "|\n";
117118
} else {
118-
std::cout << " Sequence: " << std::setw(48) << "(none)" << "\n";
119+
std::cout << "| Sequence: " << std::setw(48) << "(none)" << "|\n";
119120
}
120121

121-
std::cout << "╠════════════════════════════════════════════════════════════╣\n";
122-
std::cout << " Metrics: " << std::setw(49) << payload.metrics_size() << "\n";
123-
std::cout << "╚════════════════════════════════════════════════════════════╝\n";
122+
std::cout << "+============================================================+\n";
123+
std::cout << "| Metrics: " << std::setw(49) << payload.metrics_size() << "|\n";
124+
std::cout << "+============================================================+\n";
124125

125126
for (const auto& metric : payload.metrics()) {
126127
print_metric(metric);
@@ -140,25 +141,25 @@ int main() {
140141

141142
sparkplug::HostApplication subscriber(std::move(config));
142143

143-
std::cout << "🔧 Debug Subscriber Starting...\n";
144+
std::cout << "[DEBUG] Debug Subscriber Starting...\n";
144145

145146
auto connect_result = subscriber.connect();
146147
if (!connect_result) {
147-
std::cerr << " Failed to connect: " << connect_result.error() << "\n";
148+
std::cerr << "[ERROR] Failed to connect: " << connect_result.error() << "\n";
148149
return 1;
149150
}
150151

151-
std::cout << " Connected to broker at tcp://localhost:1883\n";
152+
std::cout << "[OK] Connected to broker at tcp://localhost:1883\n";
152153

153154
auto subscribe_result = subscriber.subscribe_all_groups();
154155
if (!subscribe_result) {
155-
std::cerr << " Failed to subscribe: " << subscribe_result.error() << "\n";
156+
std::cerr << "[ERROR] Failed to subscribe: " << subscribe_result.error() << "\n";
156157
return 1;
157158
}
158159

159-
std::cout << " Subscribed to: spBv1.0/Energy/#\n";
160-
std::cout << " Validation: ENABLED\n";
161-
std::cout << "\n Waiting for messages...\n";
160+
std::cout << "[OK] Subscribed to: spBv1.0/Energy/#\n";
161+
std::cout << "[OK] Validation: ENABLED\n";
162+
std::cout << "\n[WAIT] Waiting for messages...\n";
162163
std::cout << " (Press Ctrl+C to exit)\n";
163164
std::cout << " (Try: kill -9 <publisher_pid> to send NDEATH)\n\n";
164165

@@ -171,22 +172,23 @@ int main() {
171172
if (current_count == last_count) {
172173
static int idle_count = 0;
173174
if (++idle_count % 10 == 0) {
174-
std::cout << "💤 Still waiting... (received " << current_count << " messages so far)\n"
175+
std::cout << "[IDLE] Still waiting... (received " << current_count
176+
<< " messages so far)\n"
175177
<< std::flush;
176178
}
177179
} else {
178180
last_count = current_count;
179181
}
180182
}
181183

182-
std::cout << "\n\n Shutting down...\n";
183-
std::cout << "📊 Total messages received: " << message_count.load() << "\n";
184+
std::cout << "\n\n[STOP] Shutting down...\n";
185+
std::cout << "[STATS] Total messages received: " << message_count.load() << "\n";
184186

185187
auto disconnect_result = subscriber.disconnect();
186188
if (!disconnect_result) {
187-
std::cerr << " Failed to disconnect: " << disconnect_result.error() << "\n";
189+
std::cerr << "[ERROR] Failed to disconnect: " << disconnect_result.error() << "\n";
188190
} else {
189-
std::cout << " Disconnected\n";
191+
std::cout << "[OK] Disconnected\n";
190192
}
191193

192194
return 0;

examples/host_application_example.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// examples/host_application_example.cpp
22
// Example of using the HostApplication class for a SCADA/Primary Application
33
/*
4-
STATE messages are a special type of Sparkplug message used by Host Applications (SCADA/Primary
5-
Applications) to declare their online/offline status. They work fundamentally differently from
6-
normal Sparkplug messages:
4+
STATE messages are a special type of Sparkplug message used by Host Applications
5+
(SCADA/Primary Applications) to declare their online/offline status. They work
6+
fundamentally differently from normal Sparkplug messages:
77
88
99
1. Who Publishes STATE Messages?
@@ -34,9 +34,9 @@
3434
How STATE Messages Work
3535
3636
1. Connect to broker (no automatic messages)
37-
2. Publish STATE birth tells Edge Nodes "I'm online and monitoring"
38-
3. Send NCMD/DCMD commands control Edge Nodes and devices
39-
4. Publish STATE death tells Edge Nodes "I'm going offline"
37+
2. Publish STATE birth -> tells Edge Nodes "I'm online and monitoring"
38+
3. Send NCMD/DCMD commands -> control Edge Nodes and devices
39+
4. Publish STATE death -> tells Edge Nodes "I'm going offline"
4040
5. Disconnect
4141
4242
*/
@@ -88,9 +88,10 @@ int main() {
8888
}
8989
std::cout << "Connected successfully\n\n";
9090

91-
auto timestamp = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
92-
std::chrono::system_clock::now().time_since_epoch())
93-
.count());
91+
auto timestamp =
92+
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
93+
std::chrono::system_clock::now().time_since_epoch())
94+
.count());
9495

9596
// Publish STATE birth (declare Host Application is online)
9697
std::cout << "Publishing STATE birth (Host Application online)...\n";
@@ -106,7 +107,8 @@ int main() {
106107
std::cout << " QoS: 1, Retained: true\n\n";
107108

108109
std::cout << "Host Application is now online and monitoring...\n";
109-
std::cout << "Waiting for edge nodes to connect (monitor with mosquitto_sub -v -t '#')\n\n";
110+
std::cout
111+
<< "Waiting for edge nodes to connect (monitor with mosquitto_sub -v -t '#')\n\n";
110112

111113
// Example: Send periodic commands (every 30 seconds)
112114
auto last_command_time = std::chrono::steady_clock::now();
@@ -139,7 +141,8 @@ int main() {
139141
sparkplug::PayloadBuilder device_cmd;
140142
device_cmd.add_metric("SetPoint", 75.0 + (command_count * 5.0));
141143

142-
result = host_app.publish_device_command("Energy", "Gateway01", "Motor01", device_cmd);
144+
result =
145+
host_app.publish_device_command("Energy", "Gateway01", "Motor01", device_cmd);
143146
if (!result) {
144147
std::cerr << " Failed to publish DCMD: " << result.error() << "\n";
145148
} else {
@@ -157,9 +160,10 @@ int main() {
157160
// Graceful shutdown
158161
std::cout << "\nShutting down...\n";
159162

160-
timestamp = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
161-
std::chrono::system_clock::now().time_since_epoch())
162-
.count());
163+
timestamp =
164+
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
165+
std::chrono::system_clock::now().time_since_epoch())
166+
.count());
163167

164168
std::cout << "Publishing STATE death (Host Application going offline)...\n";
165169
result = host_app.publish_state_death(timestamp);

examples/host_application_mimic.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ int main() {
4343
return 1;
4444
}
4545

46-
auto timestamp = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
47-
std::chrono::system_clock::now().time_since_epoch())
48-
.count());
46+
auto timestamp =
47+
static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(
48+
std::chrono::system_clock::now().time_since_epoch())
49+
.count());
4950

5051
// Publish STATE birth (declare Host Application is online)
5152
std::cout << "Publishing STATE birth (Host Application online)...\n";
@@ -113,7 +114,8 @@ int main() {
113114
sparkplug::PayloadBuilder device_cmd;
114115
device_cmd.add_metric("SetPoint", 75.0);
115116

116-
result = host_app.publish_device_command("TestGroup", "SparkplugCPP", "Sensor01", device_cmd);
117+
result = host_app.publish_device_command("TestGroup", "SparkplugCPP", "Sensor01",
118+
device_cmd);
117119
if (!result) {
118120
std::cerr << "Failed to publish DCMD: " << result.error() << "\n";
119121
} else {

examples/host_application_mimic_debug.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,33 @@ int main() {
131131
break;
132132
}
133133

134-
std::cout << "\n╔════════════════════════════════════════════════════════════╗\n";
135-
std::cout << " Message #" << std::setw(3) << count << " - " << std::setw(7)
136-
<< message_type_name(topic.message_type) << std::string(39, ' ') << "\n";
137-
std::cout << "╠════════════════════════════════════════════════════════════╣\n";
134+
std::cout << "\n+============================================================+\n";
135+
std::cout << "| Message #" << std::setw(3) << count << " - " << std::setw(7)
136+
<< message_type_name(topic.message_type) << std::string(39, ' ') << "|\n";
137+
std::cout << "+============================================================+\n";
138138

139-
std::cout << " Topic: " << std::left << std::setw(51) << topic.to_string() << "\n";
140-
std::cout << " Group: " << std::setw(51) << topic.group_id << "\n";
141-
std::cout << " Edge Node: " << std::setw(47) << topic.edge_node_id << "\n";
139+
std::cout << "| Topic: " << std::left << std::setw(51) << topic.to_string() << "|\n";
140+
std::cout << "| Group: " << std::setw(51) << topic.group_id << "|\n";
141+
std::cout << "| Edge Node: " << std::setw(47) << topic.edge_node_id << "|\n";
142142

143143
if (!topic.device_id.empty()) {
144-
std::cout << " Device: " << std::setw(50) << topic.device_id << "\n";
144+
std::cout << "| Device: " << std::setw(50) << topic.device_id << "|\n";
145145
}
146146

147147
if (payload.has_timestamp()) {
148-
std::cout << "║ Payload Timestamp: " << std::setw(39) << payload.timestamp() << "\n";
148+
std::cout << "| Payload Timestamp: " << std::setw(39) << payload.timestamp()
149+
<< "|\n";
149150
}
150151

151152
if (payload.has_seq()) {
152-
std::cout << " Sequence: " << std::setw(48) << payload.seq() << "\n";
153+
std::cout << "| Sequence: " << std::setw(48) << payload.seq() << "|\n";
153154
} else {
154-
std::cout << " Sequence: " << std::setw(48) << "(none)" << "\n";
155+
std::cout << "| Sequence: " << std::setw(48) << "(none)" << "|\n";
155156
}
156157

157-
std::cout << "╠════════════════════════════════════════════════════════════╣\n";
158-
std::cout << " Metrics: " << std::setw(49) << payload.metrics_size() << "\n";
159-
std::cout << "╚════════════════════════════════════════════════════════════╝\n";
158+
std::cout << "+============================================================+\n";
159+
std::cout << "| Metrics: " << std::setw(49) << payload.metrics_size() << "|\n";
160+
std::cout << "+============================================================+\n";
160161

161162
for (const auto& metric : payload.metrics()) {
162163
print_metric(metric);
@@ -207,8 +208,9 @@ int main() {
207208
if (current_count == last_count) {
208209
if (++idle_seconds % 10 == 0) {
209210
std::cout << "Still waiting... (received " << current_count
210-
<< " messages: " << nbirth_count.load() << " NBIRTH, " << ndata_count.load()
211-
<< " NDATA, " << ndeath_count.load() << " NDEATH)\n"
211+
<< " messages: " << nbirth_count.load() << " NBIRTH, "
212+
<< ndata_count.load() << " NDATA, " << ndeath_count.load()
213+
<< " NDEATH)\n"
212214
<< std::flush;
213215
}
214216
} else {

0 commit comments

Comments
 (0)