Fix write's topic error

- Function tests all passed without removing function code.
This commit is contained in:
gc87
2022-02-09 15:01:19 +08:00
committed by Parker Liu
parent 80becc2b9c
commit ecd8d846fc
3 changed files with 24 additions and 7 deletions
+1 -1
View File
@@ -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
+4 -2
View File
@@ -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);
+19 -4
View File
@@ -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: {