Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berry cleaned udp class #19449

Merged
merged 1 commit into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions lib/libesp32/berry_tasmota/src/be_udp_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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 */

Expand Down
24 changes: 0 additions & 24 deletions tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_udp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down