Skip to content

Commit aad5a3f

Browse files
silabs-borislrzr
authored andcommitted
UIC-3222: Indicate status of UUIC association to DevUI
1 parent d4c07f1 commit aad5a3f

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

applications/zpc/components/zcl_cluster_servers/src/user_credential_cluster_server.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,17 @@ void on_uuic_slot_update(
10421042
}
10431043
}
10441044

1045+
void on_user_credential_message(sl_log_level_t log_level,
1046+
const std::string message)
1047+
{
1048+
nlohmann::json payload;
1049+
payload["level"] = log_level;
1050+
payload["message"] = message;
1051+
1052+
std::string payload_str = payload.dump();
1053+
uic_mqtt_publish("ucl/Event", payload_str.c_str(), payload_str.length(), true);
1054+
}
1055+
10451056
///////////////////////////////////////////////////////////////////////////////
10461057
// Init and teardown functions.
10471058
//////////////////////////////////////////////////////////////////////////////
@@ -1058,6 +1069,8 @@ sl_status_t user_credential_cluster_server_init()
10581069
// Custom callbacks
10591070
zwave_command_class_user_credential_set_uuic_slot_changed_callback(
10601071
&on_uuic_slot_update);
1072+
zwave_command_class_user_credential_set_message_callback(
1073+
&on_user_credential_message);
10611074

10621075
// Command callbacks
10631076
// User

applications/zpc/components/zwave_command_classes/src/zwave_command_class_user_credential.cpp

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ zwave_frame_generator frame_generator(COMMAND_CLASS_USER_CREDENTIAL);
7575

7676
// Callbacks
7777
std::set<user_credential_slot_changed_callback_t> user_credential_slot_changed_callback;
78+
std::set<user_credential_slot_message_callback_t> user_credential_slot_message_callback;
7879
}
7980

81+
8082
/////////////////////////////////////////////////////////////////////////////
8183
// Callbacks
8284
/////////////////////////////////////////////////////////////////////////////
@@ -88,6 +90,26 @@ void zwave_command_class_user_credential_set_uuic_slot_changed_callback(
8890
}
8991
}
9092

93+
void zwave_command_class_user_credential_set_message_callback(
94+
user_credential_slot_message_callback_t callback)
95+
{
96+
if (callback != nullptr) {
97+
user_credential_slot_message_callback.insert(callback);
98+
}
99+
}
100+
101+
void send_message_to_mqtt(sl_log_level level, const std::string &message)
102+
{
103+
if (level == SL_LOG_DEBUG) {
104+
sl_log_critical(LOG_TAG, "Debug message should not be sent to MQTT");
105+
return;
106+
}
107+
sl_log(LOG_TAG, level, "%s", message.c_str());
108+
109+
for (auto &callback: user_credential_slot_message_callback) {
110+
callback(level, message);
111+
}
112+
}
91113

92114
/////////////////////////////////////////////////////////////////////////////
93115
// Version & Attribute Creation
@@ -1206,19 +1228,21 @@ sl_status_t zwave_command_class_user_credential_uuic_association_report(
12061228
// If something went wrong end device side, log the error and return
12071229
// This should handle the slot already taken case
12081230
if (association_status != USER_CREDENTIAL_ASSOCIATION_REPORT_SUCCESS) {
1209-
sl_log_error(LOG_TAG,
1210-
"User Unique Identifier Credential Association error. "
1211-
"Reported status code : %d",
1212-
association_status);
1231+
send_message_to_mqtt(SL_LOG_ERROR,
1232+
"User Unique Identifier Credential Association error. "
1233+
"Reported status code : " + std::to_string(association_status));
12131234
return SL_STATUS_OK;
12141235
}
12151236

1216-
sl_log_info(LOG_TAG,
1217-
"Moving slot %d (user %d) to slot %d (user %d)",
1218-
source_credential_slot,
1219-
source_user_id,
1220-
destination_credential_slot,
1221-
destination_user_id);
1237+
send_message_to_mqtt(
1238+
SL_LOG_INFO,
1239+
(boost::format("Credential Slot %1% for type %2% (user %3%) moved to "
1240+
"Credential slot %4% (user %5%)")
1241+
% source_credential_slot
1242+
% static_cast<unsigned int>(source_credential_type) % source_user_id
1243+
% destination_credential_slot % destination_user_id)
1244+
.str());
1245+
12221246
source_credential_slot_node.set_reported(destination_credential_slot);
12231247

12241248
// Need to move to new user
@@ -1239,13 +1263,13 @@ sl_status_t zwave_command_class_user_credential_uuic_association_report(
12391263
sl_status_t result = source_credential_slot_node.change_parent(
12401264
destination_credential_type_node);
12411265
if (result != SL_STATUS_OK) {
1242-
sl_log_error(
1243-
LOG_TAG,
1244-
"Error while moving slot %d (user %d) to slot %d (user %d)",
1245-
source_credential_slot,
1246-
source_user_id,
1247-
destination_credential_slot,
1248-
destination_user_id);
1266+
send_message_to_mqtt(
1267+
SL_LOG_ERROR,
1268+
(boost::format(
1269+
"Error while moving slot %1% (user %2%) to slot %3% (user %4%)")
1270+
% source_credential_slot % source_user_id
1271+
% destination_credential_slot % destination_user_id)
1272+
.str());
12491273
return result;
12501274
}
12511275
}

applications/zpc/components/zwave_command_classes/src/zwave_command_class_user_credential.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "attribute_store.h"
3030

3131
#ifdef __cplusplus
32+
#include <string>
33+
#include "sl_log.h"
3234
extern "C" {
3335
#endif
3436

@@ -44,7 +46,11 @@ void zwave_command_class_user_credential_set_uuic_slot_changed_callback(
4446
sl_status_t zwave_command_class_user_credential_init();
4547

4648
#ifdef __cplusplus
47-
}
49+
} // extern "C"
50+
typedef void (*user_credential_slot_message_callback_t)(
51+
sl_log_level level, const std::string message);
52+
void zwave_command_class_user_credential_set_message_callback(
53+
user_credential_slot_message_callback_t callback);
4854
#endif
4955

5056

0 commit comments

Comments
 (0)