Berry udp remote ip and port

This commit is contained in:
Stephan Hadinger 2021-12-24 09:48:40 +01:00
parent 0039f5a8c3
commit c343896760
4 changed files with 950 additions and 929 deletions

View File

@ -98,6 +98,18 @@ extern "C" {
uint8_t * buf = (uint8_t*) be_pushbuffer(vm, btr);
int32_t btr2 = udp->read(buf, btr);
be_pushbytes(vm, buf, btr2);
// set remotet ip
IPAddress remote_ip = udp->remoteIP();
be_pushstring(vm, remote_ip.toString().c_str());
be_setmember(vm, 1, "remote_ip");
be_pop(vm, 1);
// set remote port
be_pushint(vm, udp->remotePort());
be_setmember(vm, 1, "remote_port");
be_pop(vm, 1);
be_return(vm); /* return code */
} else {
be_return_nil(vm);
@ -116,6 +128,8 @@ extern "C" {
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)

View File

@ -560,6 +560,8 @@ extern const bcstring be_const_str_reapply;
extern const bcstring be_const_str_redirect;
extern const bcstring be_const_str_refr_size;
extern const bcstring be_const_str_register_obj;
extern const bcstring be_const_str_remote_ip;
extern const bcstring be_const_str_remote_port;
extern const bcstring be_const_str_remove;
extern const bcstring be_const_str_remove_cmd;
extern const bcstring be_const_str_remove_driver;

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,26 @@
#include "be_constobj.h"
static be_define_const_map_slots(be_class_udp_map) {
{ be_const_key(deinit, -1), be_const_func(be_udp_deinit) },
{ be_const_key(begin_multicast, -1), be_const_func(be_udp_begin_mcast) },
{ be_const_key(begin, -1), be_const_func(be_udp_begin) },
{ be_const_key(_X2Ep, 4), be_const_var(0) },
{ be_const_key(init, 1), be_const_func(be_udp_init) },
{ be_const_key(read, -1), be_const_func(be_udp_read) },
{ be_const_key(send_multicast, 2), be_const_func(be_udp_send_mcast) },
{ be_const_key(send_multicast, 6), be_const_func(be_udp_send_mcast) },
{ be_const_key(send, -1), be_const_func(be_udp_send) },
{ be_const_key(deinit, -1), be_const_func(be_udp_deinit) },
{ be_const_key(remote_ip, -1), be_const_var(0) },
{ be_const_key(read, -1), be_const_func(be_udp_read) },
{ be_const_key(begin_multicast, 8), be_const_func(be_udp_begin_mcast) },
{ be_const_key(begin, -1), be_const_func(be_udp_begin) },
{ be_const_key(remote_port, -1), be_const_var(1) },
{ be_const_key(init, -1), be_const_func(be_udp_init) },
{ be_const_key(_X2Ep, 4), be_const_var(2) },
};
static be_define_const_map(
be_class_udp_map,
8
10
);
BE_EXPORT_VARIABLE be_define_const_class(
be_class_udp,
1,
3,
NULL,
udp
);