From ecd8d846fc900ed73604d2cf82fa715986542a18 Mon Sep 17 00:00:00 2001 From: gc87 Date: Wed, 9 Feb 2022 15:01:19 +0800 Subject: [PATCH] Fix write's topic error - Function tests all passed without removing function code. --- ft/common.resource | 2 +- plugins/mqtt/command/command.c | 6 ++++-- plugins/mqtt/plugin_mqtt.c | 23 +++++++++++++++++++---- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ft/common.resource b/ft/common.resource index 17634a72..e283e6ed 100644 --- a/ft/common.resource +++ b/ft/common.resource @@ -96,7 +96,7 @@ ${TOPIC_TAGS_REQ} neuron/${MQTT_CLIENTID}/tags/req ${TOPIC_PLUGIN_REQ} neuron/${MQTT_CLIENTID}/plugin/req ${TOPIC_SUBSCRIBE_REQ} neuron/${MQTT_CLIENTID}/subscribe/req ${TOPIC_READ_REQ} neuron/${MQTT_CLIENTID}/read/req -${TOPIC_WRITE_REQ} neuron/${MQTT_CLIENTID}/write/req" +${TOPIC_WRITE_REQ} neuron/${MQTT_CLIENTID}/write/req ${TOPIC_TTYS_REQ} neuron/${MQTT_CLIENTID}/ttys/req ${TOPIC_SCHEMA_REQ} neuron/${MQTT_CLIENTID}/schema/plugin/req ${TOPIC_SETTING_REQ} neuron/${MQTT_CLIENTID}/node/setting/req diff --git a/plugins/mqtt/command/command.c b/plugins/mqtt/command/command.c index 4285e5a1..445e5aa7 100644 --- a/plugins/mqtt/command/command.c +++ b/plugins/mqtt/command/command.c @@ -473,7 +473,8 @@ void command_response_handle1(mqtt_response_t *response) if (0 == rc) { uint32_t req_id = neu_plugin_get_event_id(plugin); if (0 < req_id) { - response->context_add(plugin, req_id, mqtt, NULL, NULL, false); + response->context_add(plugin, req_id, mqtt, NULL, + response->topic_pair, false); } command_read_once_request(plugin, mqtt, req, req_id); @@ -489,7 +490,8 @@ void command_response_handle1(mqtt_response_t *response) if (0 == rc) { uint32_t req_id = neu_plugin_get_event_id(plugin); if (0 < req_id) { - response->context_add(plugin, req_id, mqtt, NULL, NULL, false); + response->context_add(plugin, req_id, mqtt, NULL, + response->topic_pair, false); } command_write_request(plugin, mqtt, req, req_id); diff --git a/plugins/mqtt/plugin_mqtt.c b/plugins/mqtt/plugin_mqtt.c index efc01db0..bcc06b56 100644 --- a/plugins/mqtt/plugin_mqtt.c +++ b/plugins/mqtt/plugin_mqtt.c @@ -250,6 +250,20 @@ static struct topic_pair *topic_list_find(neu_list *list, const char *topic) return NULL; } +static struct topic_pair *topic_list_find_by_type(neu_list *list, + const int type) +{ + struct topic_pair *item = NULL; + NEU_LIST_FOREACH(list, item) + { + if (item->type == type) { + return item; + } + } + + return NULL; +} + static void topic_list_cleanup(neu_list *list) { while (!neu_list_empty(list)) { @@ -653,10 +667,11 @@ static int mqtt_plugin_request(neu_plugin_t *plugin, neu_request_t *req) case NEU_REQRESP_TRANS_DATA: { neu_reqresp_data_t *neu_data = NULL; neu_data = (neu_reqresp_data_t *) req->buf; - - char *json_str = - command_read_cycle_response(plugin, neu_data->data_val); - mqtt_context_add(plugin, 0, NULL, json_str, NULL, true); + struct topic_pair *pair = NULL; + char * json_str = NULL; + pair = topic_list_find_by_type(&plugin->topic_list, TOPIC_TYPE_READ); + json_str = command_read_cycle_response(plugin, neu_data->data_val); + mqtt_context_add(plugin, 0, NULL, json_str, pair, true); break; } case NEU_REQRESP_WRITE_DATA: {