Skip to content

Commit

Permalink
Merge pull request #1376 from hxy7yx/v2.5
Browse files Browse the repository at this point in the history
delete transport_mode in modbus rtu
  • Loading branch information
yuxi311 authored Jul 5, 2023
2 parents cae5c3f + f360d34 commit 45994cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion persistence/0041_2.5.0_modbus_tmode.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FROM nodes
WHERE
settings.node_name = nodes.name
AND JSON_EXTRACT(json(setting), '$.params.transport_mode') IS NULL
AND (nodes.plugin_name='modbus-qh-tcp' OR nodes.plugin_name='modbus-plus-tcp' OR nodes.plugin_name='modbus-rtu' OR nodes.plugin_name='modbus-tcp' OR nodes.plugin_name='Modbus TCP' OR nodes.plugin_name='Modbus RTU' OR nodes.plugin_name='Modbus TCP QH');
AND (nodes.plugin_name='modbus-qh-tcp' OR nodes.plugin_name='modbus-plus-tcp' OR nodes.plugin_name='modbus-tcp' OR nodes.plugin_name='Modbus TCP' OR nodes.plugin_name='Modbus TCP QH');

UPDATE settings
SET setting = JSON_SET(json(setting), '$.params.connection_mode', 0)
Expand Down
54 changes: 22 additions & 32 deletions plugins/modbus/modbus_rtu.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
neu_json_elem_t timeout = { .name = "timeout", .t = NEU_JSON_INT };
neu_json_elem_t interval = { .name = "interval", .t = NEU_JSON_INT };

neu_json_elem_t mode = { .name = "connection_mode", .t = NEU_JSON_INT };
neu_json_elem_t tmode = { .name = "transport_mode", .t = NEU_JSON_INT };
neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR };
neu_json_elem_t port = { .name = "port", .t = NEU_JSON_INT };
neu_json_elem_t mode = { .name = "connection_mode", .t = NEU_JSON_INT };
neu_json_elem_t host = { .name = "host", .t = NEU_JSON_STR };
neu_json_elem_t port = { .name = "port", .t = NEU_JSON_INT };

neu_json_elem_t device = { .name = "device", .t = NEU_JSON_STR };
neu_json_elem_t stop = { .name = "stop", .t = NEU_JSON_INT };
Expand Down Expand Up @@ -184,8 +183,8 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
ret = neu_parse_param((char *) config, &err_param, 5, &device, &stop,
&parity, &baud, &data);
} else {
ret = neu_parse_param((char *) config, &err_param, 4, &mode, &host,
&port, &tmode);
ret = neu_parse_param((char *) config, &err_param, 3, &mode, &host,
&port);
}

if (ret != 0) {
Expand Down Expand Up @@ -223,33 +222,24 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
device.v.val_str, baud.v.val_int, data.v.val_int,
parity.v.val_int, stop.v.val_int);
} else {
if (tmode.v.val_int == 1) {
param.type = NEU_CONN_UDP;
param.params.udp.timeout = 3000;
param.params.udp.src_ip = "0.0.0.0";
param.params.udp.src_port = 0;
param.params.udp.dst_ip = host.v.val_str;
param.params.udp.dst_port = port.v.val_int;
plugin->is_server = false;
} else {
if (mode.v.val_int == 1) {
param.type = NEU_CONN_TCP_SERVER;
param.params.tcp_server.ip = host.v.val_str;
param.params.tcp_server.port = port.v.val_int;
param.params.tcp_server.start_listen = modbus_tcp_server_listen;
param.params.tcp_server.stop_listen = modbus_tcp_server_stop;
param.params.tcp_server.timeout = timeout.v.val_int;
param.params.tcp_server.max_link = 1;
plugin->is_server = true;
}
if (mode.v.val_int == 0) {
param.type = NEU_CONN_TCP_CLIENT;
param.params.tcp_client.ip = host.v.val_str;
param.params.tcp_client.port = port.v.val_int;
param.params.tcp_client.timeout = timeout.v.val_int;
plugin->is_server = false;
}
if (mode.v.val_int == 1) {
param.type = NEU_CONN_TCP_SERVER;
param.params.tcp_server.ip = host.v.val_str;
param.params.tcp_server.port = port.v.val_int;
param.params.tcp_server.start_listen = modbus_tcp_server_listen;
param.params.tcp_server.stop_listen = modbus_tcp_server_stop;
param.params.tcp_server.timeout = timeout.v.val_int;
param.params.tcp_server.max_link = 1;
plugin->is_server = true;
}
if (mode.v.val_int == 0) {
param.type = NEU_CONN_TCP_CLIENT;
param.params.tcp_client.ip = host.v.val_str;
param.params.tcp_client.port = port.v.val_int;
param.params.tcp_client.timeout = timeout.v.val_int;
plugin->is_server = false;
}

plog_notice(plugin,
"config: host: %s, port: %" PRId64 ", mode: %" PRId64 "",
host.v.val_str, port.v.val_int, mode.v.val_int);
Expand Down

0 comments on commit 45994cc

Please sign in to comment.