Skip to content

Commit

Permalink
Merge pull request #611 from jean-roland/fix_issues
Browse files Browse the repository at this point in the history
Fix merge-related issues
  • Loading branch information
milyin authored Aug 29, 2024
2 parents a79ad74 + de2d2cb commit c8f795e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
3 changes: 2 additions & 1 deletion include/zenoh-pico/api/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@
z_owned_reply_t : z_reply_clone, \
z_owned_hello_t : z_hello_clone, \
z_owned_string_t : z_string_clone, \
z_owned_string_array_t : z_string_array_clone \
z_owned_string_array_t : z_string_array_clone, \
z_owned_config_t : z_config_clone \
)(&x, y)

/**
Expand Down
22 changes: 16 additions & 6 deletions src/link/multicast/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,29 @@
int8_t _z_endpoint_bt_valid(_z_endpoint_t *ep) {
int8_t ret = _Z_RES_OK;

if (_z_str_eq(ep->_locator._protocol, BT_SCHEMA) != true) {
_z_string_t bt_str = _z_string_alias_str(BT_SCHEMA);
if (!_z_string_equals(&ep->_locator._protocol, &bt_str)) {
ret = _Z_ERR_CONFIG_LOCATOR_INVALID;
}

if (ret == _Z_RES_OK) {
if (strlen(ep->_locator._address) == (size_t)0) {
if (_z_string_len(&ep->_locator._address) == (size_t)0) {
ret = _Z_ERR_CONFIG_LOCATOR_INVALID;
}
}

return ret;
}

static char *__z_convert_address_bt(_z_string_t *address) {
char *ret = NULL;
ret = (char *)z_malloc(_z_string_len(address) + 1);
if (ret != NULL) {
_z_str_n_copy(ret, _z_string_data(address), _z_string_len(address) + 1);
}
return ret;
}

int8_t _z_f_link_open_bt(_z_link_t *self) {
int8_t ret = _Z_RES_OK;

Expand All @@ -54,8 +64,8 @@ int8_t _z_f_link_open_bt(_z_link_t *self) {
tout = (uint32_t)strtoul(tout_as_str, NULL, 10);
}

self->_socket._bt._gname = self->_endpoint._locator._address;
ret = _z_open_bt(&self->_socket._bt._sock, self->_endpoint._locator._address, mode, profile, tout);
self->_socket._bt._gname = __z_convert_address_bt(&self->_endpoint._locator._address);
ret = _z_open_bt(&self->_socket._bt._sock, self->_socket._bt._gname, mode, profile, tout);

return ret;
}
Expand All @@ -73,8 +83,8 @@ int8_t _z_f_link_listen_bt(_z_link_t *self) {
tout = (uint32_t)strtoul(tout_as_str, NULL, 10);
}

self->_socket._bt._gname = self->_endpoint._locator._address;
ret = _z_listen_bt(&self->_socket._bt._sock, self->_endpoint._locator._address, mode, profile, tout);
self->_socket._bt._gname = __z_convert_address_bt(&self->_endpoint._locator._address);
ret = _z_listen_bt(&self->_socket._bt._sock, self->_socket._bt._gname, mode, profile, tout);

return ret;
}
Expand Down
36 changes: 25 additions & 11 deletions src/link/unicast/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,36 @@
int8_t _z_endpoint_serial_valid(_z_endpoint_t *endpoint) {
int8_t ret = _Z_RES_OK;

if (_z_str_eq(endpoint->_locator._protocol, SERIAL_SCHEMA) != true) {
_z_string_t ser_str = _z_string_alias_str(SERIAL_SCHEMA);
if (!_z_string_equals(&endpoint->_locator._protocol, &ser_str)) {
ret = _Z_ERR_CONFIG_LOCATOR_INVALID;
}

if (ret == _Z_RES_OK) {
char *p_dot = strchr(endpoint->_locator._address, '.');
size_t addr_len = _z_string_len(&endpoint->_locator._address);
const char *p_start = _z_string_data(&endpoint->_locator._address);
const char *p_dot = (char *)memchr(p_start, (int)'.', addr_len);
if (p_dot != NULL) {
if ((endpoint->_locator._address == p_dot) ||
(strlen(p_dot) == (size_t)1)) { // If dot is the first or last character
size_t dot_loc = _z_ptr_char_diff(p_dot, p_start);
// Check if dot is first or last character
if ((dot_loc == 0) || (dot_loc == addr_len)) {
ret = _Z_ERR_CONFIG_LOCATOR_INVALID;
}
} else {
if (strlen(endpoint->_locator._address) == (size_t)0) {
if (_z_string_len(&endpoint->_locator._address) == (size_t)0) {
ret = _Z_ERR_CONFIG_LOCATOR_INVALID;
}
}
}
return ret;
}

static char *__z_convert_address_serial(_z_string_t *address) {
char *ret = NULL;
ret = (char *)z_malloc(_z_string_len(address) + 1);
if (ret != NULL) {
_z_str_n_copy(ret, _z_string_data(address), _z_string_len(address) + 1);
}
return ret;
}

Expand All @@ -56,15 +68,16 @@ int8_t _z_f_link_open_serial(_z_link_t *self) {

const char *baudrate_str = _z_str_intmap_get(&self->_endpoint._config, SERIAL_CONFIG_BAUDRATE_KEY);
uint32_t baudrate = (uint32_t)strtoul(baudrate_str, NULL, 10);
char *address = __z_convert_address_serial(&self->_endpoint._locator._address);
char *p_dot = strchr(address, '.');

char *p_dot = strchr(self->_endpoint._locator._address, '.');
if (p_dot != NULL) {
uint32_t txpin = (uint32_t)strtoul(self->_endpoint._locator._address, &p_dot, 10);
uint32_t txpin = (uint32_t)strtoul(address, &p_dot, 10);
p_dot = _z_ptr_char_offset(p_dot, 1);
uint32_t rxpin = (uint32_t)strtoul(p_dot, NULL, 10);
ret = _z_open_serial_from_pins(&self->_socket._serial._sock, txpin, rxpin, baudrate);
} else {
ret = _z_open_serial_from_dev(&self->_socket._serial._sock, self->_endpoint._locator._address, baudrate);
ret = _z_open_serial_from_dev(&self->_socket._serial._sock, address, baudrate);
}

return ret;
Expand All @@ -75,15 +88,16 @@ int8_t _z_f_link_listen_serial(_z_link_t *self) {

const char *baudrate_str = _z_str_intmap_get(&self->_endpoint._config, SERIAL_CONFIG_BAUDRATE_KEY);
uint32_t baudrate = (uint32_t)strtoul(baudrate_str, NULL, 10);
char *address = __z_convert_address_serial(&self->_endpoint._locator._address);
char *p_dot = strchr(address, '.');

char *p_dot = strchr(self->_endpoint._locator._address, '.');
if (p_dot != NULL) {
uint32_t txpin = (uint32_t)strtoul(self->_endpoint._locator._address, &p_dot, 10);
uint32_t txpin = (uint32_t)strtoul(address, &p_dot, 10);
p_dot = _z_ptr_char_offset(p_dot, 1);
uint32_t rxpin = (uint32_t)strtoul(p_dot, NULL, 10);
ret = _z_listen_serial_from_pins(&self->_socket._serial._sock, txpin, rxpin, baudrate);
} else {
ret = _z_listen_serial_from_dev(&self->_socket._serial._sock, self->_endpoint._locator._address, baudrate);
ret = _z_listen_serial_from_dev(&self->_socket._serial._sock, address, baudrate);
}

return ret;
Expand Down
10 changes: 6 additions & 4 deletions tests/z_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ void query_handler(const z_loaned_query_t *query, void *arg) {
snprintf(res, 64, "%s%u", uri, *(unsigned int *)arg);
printf(">> Received query: %s\t(%u/%u)\n", res, queries, total);

z_view_string_t k_str;
z_view_string_t k_str, res_str;
z_keyexpr_as_view_string(z_query_keyexpr(query), &k_str);
assert(_z_str_eq(z_string_data(z_loan(k_str)), res) == true);
z_view_string_from_str(&res_str, res);
assert(_z_string_equals(z_loan(k_str), z_loan(res_str)));

z_view_string_t pred;
z_query_parameters(query, &pred);
Expand All @@ -78,13 +79,14 @@ void reply_handler(const z_loaned_reply_t *reply, void *arg) {
const z_loaned_sample_t *sample = z_reply_ok(reply);
printf(">> Received reply data: %s\t(%u/%u)\n", res, replies, total);

z_view_string_t k_str;
z_view_string_t k_str, res_str;
z_keyexpr_as_view_string(z_sample_keyexpr(sample), &k_str);
z_owned_string_t value;
z_bytes_deserialize_into_string(z_sample_payload(sample), &value);
assert(z_string_len(z_loan(value)) == strlen(res));
assert(strncmp(res, z_string_data(z_loan(value)), strlen(res)) == 0);
assert(_z_str_eq(z_string_data(z_loan(k_str)), res) == true);
z_view_string_from_str(&res_str, res);
assert(_z_string_equals(z_loan(k_str), z_loan(res_str)));

replies++;
z_drop(z_move(value));
Expand Down

0 comments on commit c8f795e

Please sign in to comment.