Skip to content

Commit 7f73667

Browse files
committed
libs2: Lint applications/zpc
Origin: #136 Signed-off-by: Philippe Coval <[email protected]>
1 parent 35f8ac6 commit 7f73667

File tree

220 files changed

+13046
-9888
lines changed

Some content is hidden

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

220 files changed

+13046
-9888
lines changed

applications/zpc/applications/zpc_database_tool/include/zpc_database_updater.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "attribute.hpp"
2525
#include <vector>
2626

27-
namespace zpc_database_updater {
27+
namespace zpc_database_updater
28+
{
2829

2930
/**
3031
* @brief Update the datastore to the target version

applications/zpc/applications/zpc_database_tool/src/zpc_database_helper.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,17 @@ std::vector<attribute> endpoint_id_list()
3838
return endpoint_list;
3939
}
4040

41-
std::vector<attribute> get_attribute_list(attribute_store_type_t attribute_type) {
41+
std::vector<attribute> get_attribute_list(attribute_store_type_t attribute_type)
42+
{
4243
std::vector<attribute> attribute_list;
4344

4445
auto endpoint_list = endpoint_id_list();
4546

46-
for(auto endpoint: endpoint_list) {
47+
for (auto endpoint: endpoint_list) {
4748
auto attributes = endpoint.children(attribute_type);
48-
attribute_list.insert(attribute_list.end(), attributes.begin(), attributes.end());
49+
attribute_list.insert(attribute_list.end(),
50+
attributes.begin(),
51+
attributes.end());
4952
}
5053

5154
return attribute_list;

applications/zpc/applications/zpc_database_tool/src/zpc_database_updater.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "zpc_datastore_fixt.h"
1717
#include "attribute_store_defined_attribute_types.h"
1818

19-
// Interface
19+
// Interface
2020
#include "zpc_database_helper.hpp"
2121

2222
// Unify components
@@ -25,13 +25,14 @@
2525
#include "attribute_store_type_registration.h"
2626
#include "sl_log.h"
2727

28-
// Datastore
28+
// Datastore
2929
#include "datastore.h"
3030

3131
using namespace attribute_store;
3232
constexpr const char *LOG_TAG = "zpc_database_updater";
3333

34-
namespace zpc_database_updater {
34+
namespace zpc_database_updater
35+
{
3536
///////////////////////////////////////////////////////////////////////////////
3637
// Helper function
3738
///////////////////////////////////////////////////////////////////////////////
@@ -49,17 +50,16 @@ bool update_bitmask_attribute(attribute attribute_to_update)
4950
std::vector<uint8_t> current_value
5051
= attribute_to_update.reported<std::vector<uint8_t>>();
5152

52-
auto bitmask_length = current_value.size();
53+
auto bitmask_length = current_value.size();
5354
uint32_t new_bitmask = 0;
5455

5556
// Since we are using uint32_t we can't have more that 4 bit mask
56-
if (bitmask_length > 4 || bitmask_length == 0) {
57+
if (bitmask_length > 4 || bitmask_length == 0) {
5758
return false;
5859
}
5960

6061
for (int i = bitmask_length - 1; i >= 0; i--) {
61-
new_bitmask
62-
= (new_bitmask << 8) | current_value[i];
62+
new_bitmask = (new_bitmask << 8) | current_value[i];
6363
}
6464

6565
attribute_to_update.set_reported<uint32_t>(new_bitmask);
@@ -76,7 +76,8 @@ bool update_bitmask_attribute(attribute attribute_to_update)
7676
void helper_convert_bitmask_to_new_format(attribute_store_type_t attribute_type)
7777
{
7878
auto attribute_list = get_attribute_list(attribute_type);
79-
const std::string attribute_name = attribute_store_get_type_name(attribute_type);
79+
const std::string attribute_name
80+
= attribute_store_get_type_name(attribute_type);
8081

8182
if (attribute_list.size() == 0) {
8283
sl_log_info(LOG_TAG,
@@ -103,9 +104,6 @@ void helper_convert_bitmask_to_new_format(attribute_store_type_t attribute_type)
103104
}
104105
}
105106

106-
107-
108-
109107
///////////////////////////////////////////////////////////////////////////////
110108
// Conversion functions
111109
///////////////////////////////////////////////////////////////////////////////
@@ -210,7 +208,8 @@ sl_status_t convert_v1_datastore_to_v2()
210208
}
211209

212210
// See zpc_datastore_version for details on the versioning
213-
sl_status_t convert_v2_datastore_to_v3() {
211+
sl_status_t convert_v2_datastore_to_v3()
212+
{
214213
// Update ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SUPPORTED_MODES
215214
helper_convert_bitmask_to_new_format(
216215
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SUPPORTED_MODES);
@@ -234,8 +233,7 @@ sl_status_t convert_v2_datastore_to_v3() {
234233
"Updating attribute(s) ID under %s...",
235234
attribute_name.c_str());
236235

237-
238-
// WARNING : Do not use defined type value here. We need those specific ID's from
236+
// WARNING : Do not use defined type value here. We need those specific ID's from
239237
// the v2 database and form the v3 database.
240238
// Specify ID's for the setpoint types since they have changed since v2
241239
constexpr attribute_store_type_t OLD_MIN_VALUE_TYPE = 0x4306;
@@ -253,18 +251,20 @@ sl_status_t convert_v2_datastore_to_v3() {
253251
// Default precision (keep same behavior as before)
254252
constexpr uint8_t DEFAULT_PRECISION = 3;
255253

256-
for(auto current_setpoint: setpoint_types_list) {
254+
for (auto current_setpoint: setpoint_types_list) {
257255
// Update the scale for value (same ID)
258256
uint32_t old_value_scale
259257
= current_setpoint
260-
.child_by_type(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_SCALE)
258+
.child_by_type(
259+
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_SCALE)
261260
.reported<uint32_t>();
262261
// Those cases should NOT happen
263262
if (old_value_scale > 255) {
264263
sl_log_warning(LOG_TAG, "Value scale is too high. Setting it to 255.");
265264
old_value_scale = 255;
266265
}
267-
current_setpoint.child_by_type(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_SCALE)
266+
current_setpoint
267+
.child_by_type(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_SCALE)
268268
.set_reported<uint8_t>(old_value_scale);
269269

270270
// First get old values
@@ -283,12 +283,12 @@ sl_status_t convert_v2_datastore_to_v3() {
283283
if (old_min_value_scale > 255) {
284284
sl_log_warning(LOG_TAG,
285285
"Min value scale is too high. Setting it to 255.");
286-
old_min_value_scale = 255;
286+
old_min_value_scale = 255;
287287
}
288288
if (old_max_value_scale > 255) {
289289
sl_log_warning(LOG_TAG,
290290
"Max value scale is too high. Setting it to 255.");
291-
old_max_value_scale = 255;
291+
old_max_value_scale = 255;
292292
}
293293

294294
// Then update current attribute tree
@@ -304,23 +304,21 @@ sl_status_t convert_v2_datastore_to_v3() {
304304
// Create the missing ones
305305
current_setpoint.emplace_node<int32_t>(NEW_MAX_VALUE_TYPE, old_max_value);
306306
current_setpoint.emplace_node<uint8_t>(NEW_MAX_VALUE_SCALE_TYPE,
307-
old_max_value_scale);
307+
old_max_value_scale);
308308
current_setpoint.emplace_node<uint8_t>(NEW_MAX_VALUE_PRECISION_TYPE, 3);
309309
}
310310

311311
sl_log_info(LOG_TAG, "Done.");
312312
}
313-
313+
314314
sl_log_info(LOG_TAG, "Successfully converted from version 2 to version 3.\n");
315315
return datastore_store_int("version", DATASTORE_VERSION_V3);
316316
}
317317

318-
319318
///////////////////////////////////////////////////////////////////////////////
320319
// Exposed functions
321320
///////////////////////////////////////////////////////////////////////////////
322-
sl_status_t update_datastore(int64_t datastore_version,
323-
int64_t target_version)
321+
sl_status_t update_datastore(int64_t datastore_version, int64_t target_version)
324322
{
325323
while (datastore_version < target_version) {
326324
switch (datastore_version) {

applications/zpc/applications/zpc_database_tool/test/zpc_database_upgrade_tool_test.cpp

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,26 @@ void suiteSetUp()
7979
/// Teardown the test suite (called once after all test_xxx functions are called)
8080
int suiteTearDown(int num_failures)
8181
{
82-
return num_failures;
82+
return num_failures;
8383
}
8484

8585
/// Called before each and every test
86-
void setUp()
87-
{
88-
89-
}
86+
void setUp() {}
9087

9188
/// Called after each and every test
92-
void tearDown() {
93-
}
89+
void tearDown() {}
9490

9591
// WARNING : This test is here to cover the v1 to v2 function.
9692
// No test was done by the time, so we don't have a v1 database to test.
9793
// We simulate a v1 empty database and check if the migration is successful.
9894
void test_migration_v1_v2_test()
9995
{
10096
// Current database version
101-
constexpr int64_t BASE_VERSION = 1;
97+
constexpr int64_t BASE_VERSION = 1;
10298
// New version
10399
constexpr int64_t DESTINATION_VERSION = 2;
104100

105-
// This test is here to
101+
// This test is here to
106102
helper_setup_database(":memory:", 1);
107103

108104
// Migrate the datastore
@@ -116,13 +112,12 @@ void test_migration_v1_v2_test()
116112
void test_migration_v2_v3()
117113
{
118114
// Current database version
119-
constexpr int64_t BASE_VERSION = 2;
115+
constexpr int64_t BASE_VERSION = 2;
120116
// New version
121117
constexpr int64_t DESTINATION_VERSION = 3;
122118

123119
helper_setup_database(TEST_DB_V2_BASE_NAME, BASE_VERSION);
124120

125-
126121
attribute_store_log();
127122

128123
// Migrate the datastore
@@ -142,40 +137,41 @@ void test_migration_v2_v3()
142137

143138
// Test new attributes
144139

145-
// First of all get the correct endpoint
146-
// attribute_store_log() extract :
140+
// First of all get the correct endpoint
141+
// attribute_store_log() extract :
147142
//
148143
// 59: 2024-Jul-09 14:20:25.685584 <d> [attribute_store] ID: 1 - Root node - Reported (hex): []
149144
// 59: 2024-Jul-09 14:20:25.685690 <d> [attribute_store] ID: 55 - HomeID - Reported (hex): [DF AF 03 F7]
150145
// 59: 2024-Jul-09 14:20:25.685750 <d> [attribute_store] ID: 56 - NodeID - Reported (hex): [01 00]
151146
// 59: 2024-Jul-09 14:20:25.687162 <d> [attribute_store] ID: 73 - NodeID - Reported (hex): [02 00]
152147
// 59: 2024-Jul-09 14:20:25.687233 <d> [attribute_store] ID: 74 - Endpoint ID - Reported (hex): [00]
153-
// 59: 2024-Jul-09 14:29:39.847599 <d> [attribute_store] ID: 75 - Unknown 0xFD020001 - Reported (hex): [00 00 00 00]
154-
// 59: 2024-Jul-09 14:29:39.847676 <d> [attribute_store] ID: 76 - Inclusion protocol - Reported (hex): [00 00 00 00]
155-
// 59: 2024-Jul-09 14:29:39.847755 <d> [attribute_store] ID: 79 - Granted keys - Reported (hex): [00]
156-
// 59: 2024-Jul-09 14:29:39.847828 <d> [attribute_store] ID: 80 - KEX Fail type - Reported (hex): [00 00 00 00]
157-
// 59: 2024-Jul-09 14:29:39.847905 <d> [attribute_store] ID: 81 - NIF: Protocol Listening byte - Reported (hex): [53]
158-
// 59: 2024-Jul-09 14:29:39.847978 <d> [attribute_store] ID: 82 - NIF: Optional Protocol byte - Reported (hex): [DC]
159-
// 59: 2024-Jul-09 14:29:39.848061 <d> [attribute_store] ID: 85 - Version CC is supported - Reported (hex): [01]
160-
// 59: 2024-Jul-09 14:29:39.848135 <d> [attribute_store] ID: 111 - Last Rx/Tx timestamp - Reported (hex): [AF 56 00 00 00 00 00 00]
148+
// 59: 2024-Jul-09 14:29:39.847599 <d> [attribute_store] ID: 75 - Unknown 0xFD020001 - Reported (hex): [00 00 00 00]
149+
// 59: 2024-Jul-09 14:29:39.847676 <d> [attribute_store] ID: 76 - Inclusion protocol - Reported (hex): [00 00 00 00]
150+
// 59: 2024-Jul-09 14:29:39.847755 <d> [attribute_store] ID: 79 - Granted keys - Reported (hex): [00]
151+
// 59: 2024-Jul-09 14:29:39.847828 <d> [attribute_store] ID: 80 - KEX Fail type - Reported (hex): [00 00 00 00]
152+
// 59: 2024-Jul-09 14:29:39.847905 <d> [attribute_store] ID: 81 - NIF: Protocol Listening byte - Reported (hex): [53]
153+
// 59: 2024-Jul-09 14:29:39.847978 <d> [attribute_store] ID: 82 - NIF: Optional Protocol byte - Reported (hex): [DC]
154+
// 59: 2024-Jul-09 14:29:39.848061 <d> [attribute_store] ID: 85 - Version CC is supported - Reported (hex): [01]
155+
// 59: 2024-Jul-09 14:29:39.848135 <d> [attribute_store] ID: 111 - Last Rx/Tx timestamp - Reported (hex): [AF 56 00 00 00 00 00 00]
161156
// 59: 2024-Jul-09 14:20:25.696159 <d> [attribute_store] ID: 175 - Endpoint ID - Reported (hex): [01] << We want him
162-
auto root_node = attribute_store_get_root();
157+
auto root_node = attribute_store_get_root();
163158
auto home_id_node = attribute_store_get_node_child(root_node, 0);
164159
auto node_id_node = attribute_store_get_node_child(home_id_node, 1);
165160
const zwave_endpoint_id_t endpoint_id = 1;
166161
// Need to specify the endpoint ID here
167-
auto endpoint_id_node = attribute_store_get_node_child_by_value(node_id_node,
168-
ATTRIBUTE_ENDPOINT_ID,
169-
REPORTED_ATTRIBUTE,
170-
&endpoint_id,
171-
sizeof(endpoint_id),
172-
0);
162+
auto endpoint_id_node
163+
= attribute_store_get_node_child_by_value(node_id_node,
164+
ATTRIBUTE_ENDPOINT_ID,
165+
REPORTED_ATTRIBUTE,
166+
&endpoint_id,
167+
sizeof(endpoint_id),
168+
0);
173169

174170
// Test new bitmask values
175-
const std::map<attribute_store_type_t, uint32_t> bitmask_attributes = {
176-
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SUPPORTED_MODES, 0x180F },
177-
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_SUPPORTED_SETPOINT_TYPES, 0x0186 }
178-
};
171+
const std::map<attribute_store_type_t, uint32_t> bitmask_attributes
172+
= {{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SUPPORTED_MODES, 0x180F},
173+
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_SUPPORTED_SETPOINT_TYPES,
174+
0x0186}};
179175

180176
for (const auto &[attribute_type, expected_value]: bitmask_attributes) {
181177
printf("Testing attribute %s\n",
@@ -196,8 +192,6 @@ void test_migration_v2_v3()
196192
"New bitmask value mismatch.");
197193
}
198194

199-
200-
201195
// Test new attribute ID values
202196
struct setpoint_value {
203197
int32_t value;
@@ -206,7 +200,8 @@ void test_migration_v2_v3()
206200
};
207201

208202
// Expected value in each fields
209-
const std::map<uint8_t, std::vector<setpoint_value>> expected_setpoint_attributes
203+
const std::map<uint8_t, std::vector<setpoint_value>>
204+
expected_setpoint_attributes
210205
= {{0x01, {{73000, 1, 3}, {-10000, 0, 3}, {100000, 0, 3}}},
211206
{0x02, {{73000, 1, 3}, {-10000, 0, 3}, {100000, 0, 3}}},
212207
{0x0B, {{62000, 1, 3}, {-10000, 0, 3}, {100000, 0, 3}}},
@@ -225,7 +220,8 @@ void test_migration_v2_v3()
225220
// MAX_VALUE_PRECISION_TYPE : 0x430C
226221
const attribute_store_type_t START_VALUE_TYPE = 0x4304;
227222

228-
for (const auto &[setpoint_type, expected_values]: expected_setpoint_attributes) {
223+
for (const auto &[setpoint_type, expected_values]:
224+
expected_setpoint_attributes) {
229225
printf("Testing setpoint type %d\n", setpoint_type);
230226

231227
auto setpoint_type_node = attribute_store_get_node_child_by_value(
@@ -262,14 +258,13 @@ void test_migration_v2_v3()
262258
reported_values.value,
263259
"New setpoint value mismatch.");
264260

265-
266261
// Get scale
267262
// TODO : use defined offset in thermostat setpoint header when available
268-
status
269-
= attribute_store_get_child_reported(setpoint_type_node,
270-
START_VALUE_TYPE + CURRENT_OFFSET + 1,
271-
&reported_values.scale,
272-
sizeof(reported_values.scale));
263+
status = attribute_store_get_child_reported(
264+
setpoint_type_node,
265+
START_VALUE_TYPE + CURRENT_OFFSET + 1,
266+
&reported_values.scale,
267+
sizeof(reported_values.scale));
273268
TEST_ASSERT_EQUAL_MESSAGE(SL_STATUS_OK,
274269
status,
275270
"Failed to get new setpoint scale.");
@@ -279,11 +274,11 @@ void test_migration_v2_v3()
279274
"New setpoint scale mismatch.");
280275

281276
// Get precision
282-
status
283-
= attribute_store_get_child_reported(setpoint_type_node,
284-
START_VALUE_TYPE + CURRENT_OFFSET + 2,
285-
&reported_values.precision,
286-
sizeof(reported_values.precision));
277+
status = attribute_store_get_child_reported(
278+
setpoint_type_node,
279+
START_VALUE_TYPE + CURRENT_OFFSET + 2,
280+
&reported_values.precision,
281+
sizeof(reported_values.precision));
287282
TEST_ASSERT_EQUAL_MESSAGE(SL_STATUS_OK,
288283
status,
289284
"Failed to get new setpoint precision.");
@@ -295,6 +290,4 @@ void test_migration_v2_v3()
295290
}
296291
}
297292

298-
299-
300-
} // extern "C"
293+
} // extern "C"

applications/zpc/applications/zpc_database_tool/zpc_database_tool.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ static void import_data_store(attribute &parent, nlohmann::json &jsn)
146146
sl_log_error("zpc_database_tool", "Missing type attribute in json");
147147
return;
148148
}
149-
std::string type_str = jsn["type"].get<std::string>();
150-
attribute_store_type_t type = attribute_store_get_type_by_name(type_str.c_str());
149+
std::string type_str = jsn["type"].get<std::string>();
150+
attribute_store_type_t type
151+
= attribute_store_get_type_by_name(type_str.c_str());
151152
attribute node;
152153

153154
if (type == ATTRIBUTE_TREE_ROOT) {

applications/zpc/components/dotdot_mapper/src/basic_cluster_mapper.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ static void network_status_attribute_update(attribute_store_node_t updated_node,
118118
if (change != ATTRIBUTE_UPDATED) {
119119
return;
120120
}
121-
NodeStateNetworkStatus network_status = ZCL_NODE_STATE_NETWORK_STATUS_UNAVAILABLE;
121+
NodeStateNetworkStatus network_status
122+
= ZCL_NODE_STATE_NETWORK_STATUS_UNAVAILABLE;
122123
attribute_store_get_reported(updated_node,
123124
&network_status,
124125
sizeof(network_status));

0 commit comments

Comments
 (0)