Skip to content

Commit eb481a5

Browse files
Add new flow to ethernet/ip protocol
1 parent 35be174 commit eb481a5

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

Dockerfile

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ FROM alpine:3.10.3 AS builder
44
ARG LIBELL_VERSION=0.18
55
ARG JSONC_VERSION=0.14-20200419
66
ARG RABBITMQC_VERSION=v0.10.0
7-
ARG KNOT_CLOUD_SDK_VERSION=bdc4130
8-
ARG KNOT_PROTOCOL_VERSION=5f4e9c6
7+
ARG KNOT_CLOUD_SDK_VERSION=KNoTU-v3.2.0-rc05
8+
ARG KNOT_PROTOCOL_VERSION=KNoTU-v3.2.0-rc05
99
ARG LIBMODBUS_VERSION=3.1.4
10-
ARG LIBPLCTAG_VERSION=v2.5.0
11-
ARG LIBOPEN62541_VERSION=23c8586
10+
ARG LIBPLCTAG_VERSION=v2.5.4
11+
ARG LIBOPEN62541_VERSION=v1.3.4
1212

1313
WORKDIR /usr/local
1414

@@ -47,7 +47,7 @@ RUN cd libmodbus && ./configure --prefix=/usr -q && make install
4747

4848
# Install open62541 dependency. While the fix for checking StatusCode is not approved, it is necessary to use a specific branch of IOTechSystems.
4949
RUN mkdir -p /usr/local/libplctag
50-
RUN git clone https://github.com/IOTechSystems/open62541.git /usr/local/open62541
50+
RUN git clone https://github.com/open62541/open62541.git /usr/local/open62541
5151
RUN cd open62541 && git checkout $LIBOPEN62541_VERSION && git submodule update --init --recursive && mkdir -p build
5252
RUN cd open62541/build && cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib DLIB_INSTALL_DIR=lib -DCMAKE_BUILD_TYPE=Release -DUA_NAMESPACE_ZERO=FULL -DUA_ENABLE_ENCRYPTION=OPENSSL -DUA_ARCH_REMOVE_FLAGS="-Werror" ..
5353
RUN cd open62541/build && make install

src/iface-ethernet-ip.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static iface_ethernet_ip_disconnected_cb_t disconn_cb;
3232
static struct l_timeout *connect_to;
3333
struct knot_thing thing_ethernet_ip;
3434
static struct l_io *ethernet_op_io;
35+
static int status_ethernet_ip;
3536

3637
union ethernet_ip_types {
3738
float val_float;
@@ -113,12 +114,6 @@ static int connect_ethernet_ip(struct knot_data_item *data_item)
113114
{
114115
int rc = 0;
115116

116-
/* Check and destroy if an IO is already allocated */
117-
if (ethernet_op_io) {
118-
l_io_destroy(ethernet_op_io);
119-
ethernet_op_io = NULL;
120-
}
121-
122117
plc_tag_destroy(data_item->tag);
123118
data_item->tag = plc_tag_create(data_item->string_tag_path,
124119
DATA_TIMEOUT);
@@ -131,20 +126,6 @@ static int connect_ethernet_ip(struct knot_data_item *data_item)
131126
return -EINVAL;
132127
}
133128

134-
ethernet_op_io = l_io_new(plc_tag_status(data_item->tag));
135-
if (!ethernet_op_io) {
136-
l_error("Error setting up tag internal state. %s",
137-
plc_tag_decode_error(
138-
data_item->tag));
139-
return -EIO;
140-
}
141-
142-
if (!l_io_set_disconnect_handler(ethernet_op_io, on_disconnected, NULL,
143-
NULL)) {
144-
l_error("Couldn't set Ethernet/IP disconnect handler");
145-
return -EINVAL;
146-
}
147-
148129
return rc;
149130
}
150131

@@ -188,21 +169,40 @@ static void attempt_connect(struct l_timeout *to, void *user_data)
188169

189170
l_debug("Trying to connect to Ethernet/Ip");
190171

172+
/* Check and destroy if an IO is already allocated */
173+
if (ethernet_op_io) {
174+
l_io_destroy(ethernet_op_io);
175+
ethernet_op_io = NULL;
176+
}
177+
191178
l_hashmap_foreach(thing_ethernet_ip.data_items,
192179
foreach_data_item_ethernet_ip, &rc);
193180
if (rc) {
194181
l_error("error connecting to Ethernet/Ip");
195182
goto retry;
196183
}
197184

185+
ethernet_op_io = l_io_new(status_ethernet_ip);
186+
if (!ethernet_op_io) {
187+
l_error("Error setting up tag internal state.");
188+
goto io_destroy;
189+
}
190+
191+
if (!l_io_set_disconnect_handler(ethernet_op_io, on_disconnected, NULL,
192+
NULL)) {
193+
l_error("Couldn't set Ethernet/IP disconnect handler");
194+
goto io_destroy;
195+
}
196+
198197
if (conn_cb)
199198
conn_cb(user_data);
200199

201200
return;
202201

203-
retry:
202+
io_destroy:
204203
l_io_destroy(ethernet_op_io);
205204
ethernet_op_io = NULL;
205+
retry:
206206
l_timeout_modify(to, RECONNECT_TIMEOUT);
207207
}
208208

0 commit comments

Comments
 (0)