Liu Song’s Projects


~/Projects/Tasmota

git clone https://code.lsong.org/Tasmota

Commit

Commit
fe0423c6cdd77e589367b7cfeb58e4adf2e3b337
Author
s-hadinger <49731213+[email protected]>
Date
2023-09-03 21:49:35 +0200 +0200
Diffstat
 lib/libesp32/berry_tasmota/src/be_udp_lib.c | 43 ++++++++++----
 tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino | 25 --------

Berry cleaned udp class (#19449)


diff --git a/lib/libesp32/berry_tasmota/src/be_udp_lib.c b/lib/libesp32/berry_tasmota/src/be_udp_lib.c
index 9c58315cf09889ad91c361b50ea8b0cf8cc2f019..e49dc5e48a6f03788d0f445b35004b522ceea5d6 100644
--- a/lib/libesp32/berry_tasmota/src/be_udp_lib.c
+++ b/lib/libesp32/berry_tasmota/src/be_udp_lib.c
@@ -5,23 +5,39 @@  * To use: `d = udp()`
  *
  *******************************************************************/
 #include "be_constobj.h"
+#include "be_mapping.h"
 
 #ifdef USE_WEBCLIENT
 
+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 int be_udp_init(struct bvm *vm);
-/********************************************************************
+ * To use: `d = udp()`
-/********************************************************************
+
+ * To use: `d = udp()`
 /********************************************************************
-/********************************************************************
+ * To use: `d = udp()`
  * UDP lib
-/********************************************************************
+
+ * To use: `d = udp()`
  *
-/********************************************************************
+ * To use: `d = udp()`
  * To use: `d = udp()`
-/********************************************************************
+
+ * To use: `d = udp()`
  *******************************************************************/
-/********************************************************************
+ * To use: `d = udp()`
 #include "be_constobj.h"
+
+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"
@@ -32,19 +48,18 @@ class be_class_udp (scope: global, name: udp) {
     .p, var
     remote_ip, var
     remote_port, var
- * UDP lib
  * To use: `d = udp()`
+extern int be_udp_init(struct bvm *vm);
- * UDP lib
  *******************************************************************/
 
-    send, func(be_udp_send)
+    send, ctype_func(be_udp_send_ntv)
+ *******************************************************************/
  * UDP lib
-
 
-    begin, func(be_udp_begin)
+    begin, ctype_func(be_udp_begin_ntv)
-    begin_multicast, func(be_udp_begin_mcast)
+    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 bf103d1a75453dc64c9934459d694ce40c0afa8c..d71ada444c9711b90be04d70fa41648f4abf07d1 100644
--- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino
+++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino
@@ -40,16 +40,9 @@
   // init()
   WiFiUDP *be_udp_init_ntv(void) {
 
-
 /*
 
-  xdrv_52_3_berry_udp.ino - Berry scripting language, UDP client
 
-
-  }
-  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()
@@ -57,9 +50,6 @@   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) {
@@ -69,18 +59,12 @@     if(host && (*host != 0) && !WifiHostByName(host, addr)){
         return 0;
     }
     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) {
@@ -89,9 +73,6 @@     if(!WifiHostByName(host, addr)){
         return 0;
     }
     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
@@ -107,9 +88,6 @@     if (!bw) { return 0; }
     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) {
@@ -118,9 +96,6 @@     int bw = udp->write(buf, len);
     if (!bw) { return 0; }
     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