You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2026/10/12 10:47:10 UTC
(plc4x) 05/05: feat(plc4c): add the response codes plc4c was missing and report them from the proxy
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 3581a6fc559e57d1dddbb63458eac4476f922e67
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon Oct 12 12:46:53 2026 +0200
feat(plc4c): add the response codes plc4c was missing and report them from the proxy
plc4c had no INVALID_DATA, REMOTE_BUSY, REMOTE_ERROR, UNSUPPORTED, NOT_READY
or OUT_OF_RANGE, so the plc4x proxy driver still reported those as
INTERNAL_ERROR. They are added at the end of plc4c_response_code, keeping the
existing values' numbers, with messages, and the proxy driver now maps every
code the protocol defines onto its plc4c counterpart. Only a value the
protocol doesn't define is still INTERNAL_ERROR.
---
plc4c/api/include/plc4c/types.h | 9 ++++++++-
.../plc4x/include/plc4c/driver_plc4x_packets.h | 2 +-
plc4c/drivers/plc4x/src/driver_plc4x_packets.c | 17 +++++++++++++++--
plc4c/drivers/plc4x/test/plc4x_test.c | 22 ++++++++++++++--------
plc4c/spi/src/types.c | 18 ++++++++++++++++++
5 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/plc4c/api/include/plc4c/types.h b/plc4c/api/include/plc4c/types.h
index 50f7a74826..d78e97a823 100644
--- a/plc4c/api/include/plc4c/types.h
+++ b/plc4c/api/include/plc4c/types.h
@@ -67,7 +67,14 @@ typedef enum plc4c_response_code {
PLC4C_RESPONSE_CODE_INVALID_DATATYPE,
PLC4C_RESPONSE_CODE_INTERNAL_ERROR,
PLC4C_RESPONSE_CODE_RESPONSE_PENDING,
- PLC4C_RESPONSE_CODE_REQUEST_TIMEOUT
+ PLC4C_RESPONSE_CODE_REQUEST_TIMEOUT,
+ // Added after the others so that the values above keep their numbers.
+ PLC4C_RESPONSE_CODE_INVALID_DATA,
+ PLC4C_RESPONSE_CODE_REMOTE_BUSY,
+ PLC4C_RESPONSE_CODE_REMOTE_ERROR,
+ PLC4C_RESPONSE_CODE_UNSUPPORTED,
+ PLC4C_RESPONSE_CODE_NOT_READY,
+ PLC4C_RESPONSE_CODE_OUT_OF_RANGE
} plc4c_response_code;
/**
diff --git a/plc4c/drivers/plc4x/include/plc4c/driver_plc4x_packets.h b/plc4c/drivers/plc4x/include/plc4c/driver_plc4x_packets.h
index 70f3d6e635..d1a5d1f3e8 100644
--- a/plc4c/drivers/plc4x/include/plc4c/driver_plc4x_packets.h
+++ b/plc4c/drivers/plc4x/include/plc4c/driver_plc4x_packets.h
@@ -55,7 +55,7 @@ void plc4c_driver_plc4x_destroy_plc4x_write_request(
/**
* Translates a response code received from the proxy into the one plc4c reports for the tag.
- * Codes plc4c has no counterpart for are reported as PLC4C_RESPONSE_CODE_INTERNAL_ERROR.
+ * A value the proxy protocol doesn't define is reported as PLC4C_RESPONSE_CODE_INTERNAL_ERROR.
*
* @param response_code the code as it came over the wire.
* @return the code to report to the caller.
diff --git a/plc4c/drivers/plc4x/src/driver_plc4x_packets.c b/plc4c/drivers/plc4x/src/driver_plc4x_packets.c
index 7ebf1f143e..db6f002c64 100644
--- a/plc4c/drivers/plc4x/src/driver_plc4x_packets.c
+++ b/plc4c/drivers/plc4x/src/driver_plc4x_packets.c
@@ -343,13 +343,26 @@ plc4c_response_code plc4c_driver_plc4x_map_response_code(
return PLC4C_RESPONSE_CODE_INVALID_ADDRESS;
case plc4c_plc4x_read_write_plc4x_response_code_INVALID_DATATYPE:
return PLC4C_RESPONSE_CODE_INVALID_DATATYPE;
+ case plc4c_plc4x_read_write_plc4x_response_code_INVALID_DATA:
+ return PLC4C_RESPONSE_CODE_INVALID_DATA;
+ case plc4c_plc4x_read_write_plc4x_response_code_INTERNAL_ERROR:
+ return PLC4C_RESPONSE_CODE_INTERNAL_ERROR;
+ case plc4c_plc4x_read_write_plc4x_response_code_REMOTE_BUSY:
+ return PLC4C_RESPONSE_CODE_REMOTE_BUSY;
+ case plc4c_plc4x_read_write_plc4x_response_code_REMOTE_ERROR:
+ return PLC4C_RESPONSE_CODE_REMOTE_ERROR;
+ case plc4c_plc4x_read_write_plc4x_response_code_UNSUPPORTED:
+ return PLC4C_RESPONSE_CODE_UNSUPPORTED;
case plc4c_plc4x_read_write_plc4x_response_code_RESPONSE_PENDING:
return PLC4C_RESPONSE_CODE_RESPONSE_PENDING;
+ case plc4c_plc4x_read_write_plc4x_response_code_NOT_READY:
+ return PLC4C_RESPONSE_CODE_NOT_READY;
+ case plc4c_plc4x_read_write_plc4x_response_code_OUT_OF_RANGE:
+ return PLC4C_RESPONSE_CODE_OUT_OF_RANGE;
case plc4c_plc4x_read_write_plc4x_response_code_REQUEST_TIMEOUT:
return PLC4C_RESPONSE_CODE_REQUEST_TIMEOUT;
default:
- // INVALID_DATA, REMOTE_BUSY, REMOTE_ERROR, UNSUPPORTED, NOT_READY and OUT_OF_RANGE have no
- // plc4c counterpart (yet), and INTERNAL_ERROR maps onto itself.
+ // Not a code the proxy protocol defines.
return PLC4C_RESPONSE_CODE_INTERNAL_ERROR;
}
}
diff --git a/plc4c/drivers/plc4x/test/plc4x_test.c b/plc4c/drivers/plc4x/test/plc4x_test.c
index 52145875a0..7a5358bd29 100644
--- a/plc4c/drivers/plc4x/test/plc4x_test.c
+++ b/plc4c/drivers/plc4x/test/plc4x_test.c
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+#include <string.h>
#include <unity.h>
#include "plc4c/driver_plc4x_packets.h"
@@ -26,8 +27,7 @@ void setUp(void) {}
void tearDown(void) {}
-// Every code the proxy can put on the wire, and what a plc4c caller sees for it: the one plc4c
-// has where it has one, INTERNAL_ERROR where it doesn't.
+// Every code the proxy can put on the wire, and what a plc4c caller sees for it.
void test_plc4x_response_code_mapping(void) {
struct {
plc4c_plc4x_read_write_plc4x_response_code wire;
@@ -38,14 +38,14 @@ void test_plc4x_response_code_mapping(void) {
{plc4c_plc4x_read_write_plc4x_response_code_ACCESS_DENIED, PLC4C_RESPONSE_CODE_ACCESS_DENIED},
{plc4c_plc4x_read_write_plc4x_response_code_INVALID_ADDRESS, PLC4C_RESPONSE_CODE_INVALID_ADDRESS},
{plc4c_plc4x_read_write_plc4x_response_code_INVALID_DATATYPE, PLC4C_RESPONSE_CODE_INVALID_DATATYPE},
- {plc4c_plc4x_read_write_plc4x_response_code_INVALID_DATA, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
+ {plc4c_plc4x_read_write_plc4x_response_code_INVALID_DATA, PLC4C_RESPONSE_CODE_INVALID_DATA},
{plc4c_plc4x_read_write_plc4x_response_code_INTERNAL_ERROR, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
- {plc4c_plc4x_read_write_plc4x_response_code_REMOTE_BUSY, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
- {plc4c_plc4x_read_write_plc4x_response_code_REMOTE_ERROR, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
- {plc4c_plc4x_read_write_plc4x_response_code_UNSUPPORTED, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
+ {plc4c_plc4x_read_write_plc4x_response_code_REMOTE_BUSY, PLC4C_RESPONSE_CODE_REMOTE_BUSY},
+ {plc4c_plc4x_read_write_plc4x_response_code_REMOTE_ERROR, PLC4C_RESPONSE_CODE_REMOTE_ERROR},
+ {plc4c_plc4x_read_write_plc4x_response_code_UNSUPPORTED, PLC4C_RESPONSE_CODE_UNSUPPORTED},
{plc4c_plc4x_read_write_plc4x_response_code_RESPONSE_PENDING, PLC4C_RESPONSE_CODE_RESPONSE_PENDING},
- {plc4c_plc4x_read_write_plc4x_response_code_NOT_READY, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
- {plc4c_plc4x_read_write_plc4x_response_code_OUT_OF_RANGE, PLC4C_RESPONSE_CODE_INTERNAL_ERROR},
+ {plc4c_plc4x_read_write_plc4x_response_code_NOT_READY, PLC4C_RESPONSE_CODE_NOT_READY},
+ {plc4c_plc4x_read_write_plc4x_response_code_OUT_OF_RANGE, PLC4C_RESPONSE_CODE_OUT_OF_RANGE},
{plc4c_plc4x_read_write_plc4x_response_code_REQUEST_TIMEOUT, PLC4C_RESPONSE_CODE_REQUEST_TIMEOUT},
};
int num_cases = sizeof(cases) / sizeof(cases[0]);
@@ -56,7 +56,13 @@ void test_plc4x_response_code_mapping(void) {
TEST_ASSERT_EQUAL_INT_MESSAGE(cases[i].expected,
plc4c_driver_plc4x_map_response_code(cases[i].wire),
plc4c_response_code_to_message(cases[i].expected));
+ TEST_ASSERT_NOT_EQUAL_INT(0, strcmp("UNKNOWN RESPONSE CODE",
+ plc4c_response_code_to_message(cases[i].expected)));
}
+ // A value the protocol doesn't define can't be reported as anything in particular.
+ TEST_ASSERT_EQUAL_INT(PLC4C_RESPONSE_CODE_INTERNAL_ERROR,
+ plc4c_driver_plc4x_map_response_code(
+ (plc4c_plc4x_read_write_plc4x_response_code) 0xFF));
}
int main(void) {
diff --git a/plc4c/spi/src/types.c b/plc4c/spi/src/types.c
index d7436e6d94..f4b45957e4 100644
--- a/plc4c/spi/src/types.c
+++ b/plc4c/spi/src/types.c
@@ -102,6 +102,24 @@ char *plc4c_response_code_to_message(plc4c_response_code response_code) {
case PLC4C_RESPONSE_CODE_REQUEST_TIMEOUT: {
return "REQUEST TIMEOUT";
}
+ case PLC4C_RESPONSE_CODE_INVALID_DATA: {
+ return "INVALID DATA";
+ }
+ case PLC4C_RESPONSE_CODE_REMOTE_BUSY: {
+ return "REMOTE BUSY";
+ }
+ case PLC4C_RESPONSE_CODE_REMOTE_ERROR: {
+ return "REMOTE ERROR";
+ }
+ case PLC4C_RESPONSE_CODE_UNSUPPORTED: {
+ return "UNSUPPORTED";
+ }
+ case PLC4C_RESPONSE_CODE_NOT_READY: {
+ return "NOT READY";
+ }
+ case PLC4C_RESPONSE_CODE_OUT_OF_RANGE: {
+ return "OUT OF RANGE";
+ }
default: {
return "UNKNOWN RESPONSE CODE";
}