From 93025882dd567f8d096ba1282c5cf7c302d101c2 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 3 Sep 2023 21:45:39 +0200 Subject: [PATCH] Berry cleaned udp class --- lib/libesp32/berry_tasmota/src/be_udp_lib.c | 43 +++++++++++++------ .../xdrv_52_3_berry_udp.ino | 24 ----------- 2 files changed, 29 insertions(+), 38 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_udp_lib.c b/lib/libesp32/berry_tasmota/src/be_udp_lib.c index 9c58315cf098..e49dc5e48a6f 100644 --- a/lib/libesp32/berry_tasmota/src/be_udp_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_udp_lib.c @@ -5,18 +5,33 @@ * *******************************************************************/ #include "be_constobj.h" +#include "be_mapping.h" #ifdef USE_WEBCLIENT -extern int be_udp_init(struct bvm *vm); -extern int be_udp_deinit(struct bvm *vm); -extern int be_udp_begin(struct bvm *vm); -extern int be_udp_stop(struct bvm *vm); -extern int be_udp_begin_mcast(struct bvm *vm); -extern int be_udp_send(struct bvm *vm); -extern int be_udp_send_mcast(struct bvm *vm); extern int be_udp_read(struct bvm *vm); +extern void *be_udp_init_ntv(void); +BE_FUNC_CTYPE_DECLARE(be_udp_init_ntv, "+.p", "") + +extern void *be_udp_deinit_ntv(void *udp); +BE_FUNC_CTYPE_DECLARE(be_udp_deinit_ntv, "=.p", "") + +extern int32_t be_udp_begin_ntv(void *udp, const char *host, int32_t port); +BE_FUNC_CTYPE_DECLARE(be_udp_begin_ntv, "b", ".si") + +extern void be_udp_stop_ntv(void *udp); +BE_FUNC_CTYPE_DECLARE(be_udp_stop_ntv, "", ".") + +extern int32_t be_udp_begin_mcast_ntv(void *udp, const char *host, int32_t port); +BE_FUNC_CTYPE_DECLARE(be_udp_begin_mcast_ntv, "b", ".si") + +extern int32_t be_udp_send_ntv(void *udp, const char *host, int32_t port, const uint8_t* buf, int32_t len); +BE_FUNC_CTYPE_DECLARE(be_udp_send_ntv, "b", ".si(bytes)~") + +extern int32_t be_udp_send_mcast_ntv(void *udp, const uint8_t* buf, int32_t len); +BE_FUNC_CTYPE_DECLARE(be_udp_send_mcast_ntv, "b", ".(bytes)~") + #include "be_mapping.h" #include "be_fixed_be_class_udp.h" @@ -26,16 +41,16 @@ class be_class_udp (scope: global, name: udp) { .p, var remote_ip, var remote_port, var - init, func(be_udp_init) - deinit, func(be_udp_deinit) + init, ctype_func(be_udp_init_ntv) + deinit, ctype_func(be_udp_deinit_ntv) - send, func(be_udp_send) - send_multicast, func(be_udp_send_mcast) + send, ctype_func(be_udp_send_ntv) + send_multicast, ctype_func(be_udp_send_mcast_ntv) - begin, func(be_udp_begin) - begin_multicast, func(be_udp_begin_mcast) + begin, ctype_func(be_udp_begin_ntv) + begin_multicast, ctype_func(be_udp_begin_mcast_ntv) read, func(be_udp_read) - close, func(be_udp_stop) + close, ctype_func(be_udp_stop_ntv) } @const_object_info_end */ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino index bf103d1a7545..d71ada444c97 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino @@ -39,24 +39,15 @@ extern "C" { // init() WiFiUDP *be_udp_init_ntv(void) { -AddLog(LOG_LEVEL_INFO, "be_udp_init_ntv start"); WiFiUDP *udp = new WiFiUDP(); -AddLog(LOG_LEVEL_INFO, "be_udp_init_ntv udp=%p", udp); return udp; } - int32_t be_udp_init(struct bvm *vm) { -AddLog(LOG_LEVEL_INFO, "be_udp_init start"); - return be_call_c_func(vm, (void*) &be_udp_init_ntv, "+.p", ""); - } // deinit() void *be_udp_deinit_ntv(WiFiUDP *udp) { if (udp != nullptr) { delete udp; } return nullptr; } - int32_t be_udp_deinit(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_deinit_ntv, "=.p", ""); - } // udp.begin(interface:string, port:int) -> bool int32_t be_udp_begin_ntv(WiFiUDP *udp, const char *host, int32_t port) { @@ -67,17 +58,11 @@ AddLog(LOG_LEVEL_INFO, "be_udp_init start"); } return udp->begin(addr, port); } - int32_t be_udp_begin(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_begin_ntv, "b", ".si"); - } // udp.stop() -> nil void be_udp_stop_ntv(WiFiUDP *udp) { udp->stop(); } - int32_t be_udp_stop(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_stop_ntv, "b", "."); - } // udp.begin_multicast(address:string, port:int) -> nil int32_t be_udp_begin_mcast_ntv(WiFiUDP *udp, const char *host, int32_t port) { @@ -87,9 +72,6 @@ AddLog(LOG_LEVEL_INFO, "be_udp_init start"); } return udp->WiFiUDP::beginMulticast(addr, port); } - int32_t be_udp_begin_mcast(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_begin_mcast_ntv, "b", ".si"); - } // udp.send(address:string, port:int, payload:bytes) -> bool int32_t be_udp_send_ntv(WiFiUDP *udp, const char *host, int32_t port, const uint8_t* buf, int32_t len) { @@ -104,9 +86,6 @@ AddLog(LOG_LEVEL_INFO, "be_udp_init start"); if (!udp->endPacket()) { return 0; } return btrue; } - int32_t be_udp_send(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_send_ntv, "b", ".si(bytes)~"); - } // udp.send_multicast(payload:bytes) -> bool int32_t be_udp_send_mcast_ntv(WiFiUDP *udp, const uint8_t* buf, int32_t len) { @@ -116,9 +95,6 @@ AddLog(LOG_LEVEL_INFO, "be_udp_init start"); if (!udp->endPacket()) { return 0; } return btrue; } - int32_t be_udp_send_mcast(struct bvm *vm) { - return be_call_c_func(vm, (void*) &be_udp_send_mcast_ntv, "b", ".(bytes)~"); - } // udp.read() -> bytes or nil int32_t be_udp_read(struct bvm *vm) {