Skip to content

Commit

Permalink
Merge branch 'serial_timeout' into serial_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets authored Mar 27, 2024
2 parents f3c4ae5 + 22bf428 commit c6ee2cc
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino_esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
mkdir -p $ARDUINO_BASE
cd $ARDUINO_BASE
platformio init -b esp32thing_plus --project-option="build_flags=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC"
platformio init -b esp32thing_plus -O "build_flags=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC" -O "lib_ldf_mode=deep+"
cd $ARDUINO_BASE/lib
ln -s $ZENOH_PICO_BASE
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,15 @@ The simplest way to run some of the example is to get a Docker image of the **ze
### 3.1. Starting the Zenoh Router
Assuming you've pulled the Docker image of the **zenoh** router on a Linux host (to leverage UDP multicast scouting as explained [here](https://zenoh.io/docs/getting-started/quick-test/#run-zenoh-router-in-a-docker-container), then simply do:
```bash
$ docker run --init --net host eclipse/zenoh:master
$ docker run --init --net host eclipse/zenoh:main
```

To see the zenoh manual page, simply do:
```bash
$ docker run --init --net host eclipse/zenoh:master --help
$ docker run --init --net host eclipse/zenoh:main --help
```

:warning: **Please notice that the `--net host` option in Docker is restricted to Linux only.**
:warning: **Please notice that the `--net host` option in Docker is restricted to Linux only.**
The cause is that Docker doesn't support UDP multicast between a container and its host (see cases [moby/moby#23659](https://github.com/moby/moby/issues/23659), [moby/libnetwork#2397](https://github.com/moby/libnetwork/issues/2397) or [moby/libnetwork#552](https://github.com/moby/libnetwork/issues/552)). The only known way to make it work is to use the `--net host` option that is [only supported on Linux hosts](https://docs.docker.com/network/host/).

### 3.2. Basic Pub/Sub Example
Expand Down Expand Up @@ -385,7 +385,7 @@ where `lo0` is the network interface you want to use for multicast communication
### 3.4. Basic Pub/Sub Example - Mixing Client and P2P communication
To allow Zenoh-Pico unicast clients to talk to Zenoh-Pico multicast peers, as well as with any other Zenoh client/peer, you need to start a Zenoh Router that listens on both multicast and unicast:
```bash
$ docker run --init --net host eclipse/zenoh:master -l udp/224.0.0.123:7447#iface=lo0 -l tcp/127.0.0.1:7447
$ docker run --init --net host eclipse/zenoh:main -l udp/224.0.0.123:7447#iface=lo0 -l tcp/127.0.0.1:7447
```

Assuming that (1) you are running the **zenoh** router as indicated above, and (2) you are under the build directory, do:
Expand Down
19 changes: 10 additions & 9 deletions include/zenoh-pico/collections/refcount.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@
#define _ZP_RC_CNT_TYPE _z_atomic(unsigned int)
#define _ZP_RC_OP_INIT_CNT _z_atomic_store_explicit(&p.in->_cnt, (unsigned int)1, _z_memory_order_relaxed);
#define _ZP_RC_OP_INCR_CNT _z_atomic_fetch_add_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_relaxed);
#define _ZP_RC_OP_DECR_AND_CMP _z_atomic_fetch_sub_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_release) > 1
#define _ZP_RC_OP_DECR_AND_CMP \
_z_atomic_fetch_sub_explicit(&p->in->_cnt, (unsigned int)1, _z_memory_order_release) > (unsigned int)1
#define _ZP_RC_OP_SYNC atomic_thread_fence(_z_memory_order_acquire);

#else // ZENOH_C_STANDARD == 99
#ifdef ZENOH_COMPILER_GCC

// c99 gcc sync builtin variant
#define _ZP_RC_CNT_TYPE unsigned int
#define _ZP_RC_OP_INIT_CNT \
__sync_fetch_and_and(&p.in->_cnt, 0); \
__sync_fetch_and_add(&p.in->_cnt, 1);
#define _ZP_RC_OP_INCR_CNT __sync_fetch_and_add(&p->in->_cnt, 1);
#define _ZP_RC_OP_DECR_AND_CMP __sync_fetch_and_sub(&p->in->_cnt, 1) > 1
#define _ZP_RC_OP_INIT_CNT \
__sync_fetch_and_and(&p.in->_cnt, (unsigned int)0); \
__sync_fetch_and_add(&p.in->_cnt, (unsigned int)1);
#define _ZP_RC_OP_INCR_CNT __sync_fetch_and_add(&p->in->_cnt, (unsigned int)1);
#define _ZP_RC_OP_DECR_AND_CMP __sync_fetch_and_sub(&p->in->_cnt, (unsigned int)1) > (unsigned int)1
#define _ZP_RC_OP_SYNC __sync_synchronize();

#else // !ZENOH_COMPILER_GCC
Expand All @@ -76,9 +77,9 @@

// Single thread variant
#define _ZP_RC_CNT_TYPE unsigned int
#define _ZP_RC_OP_INIT_CNT p.in->_cnt = 1;
#define _ZP_RC_OP_INCR_CNT p->in->_cnt += 1;
#define _ZP_RC_OP_DECR_AND_CMP p->in->_cnt-- > 1
#define _ZP_RC_OP_INIT_CNT p.in->_cnt = (unsigned int)1;
#define _ZP_RC_OP_INCR_CNT p->in->_cnt += (unsigned int)1;
#define _ZP_RC_OP_DECR_AND_CMP p->in->_cnt-- > (unsigned int)1
#define _ZP_RC_OP_SYNC

#endif // Z_FEATURE_MULTI_THREAD == 1
Expand Down
16 changes: 8 additions & 8 deletions include/zenoh-pico/link/config/bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
#define BT_CONFIG_TOUT_KEY 0x03
#define BT_CONFIG_TOUT_STR "tout"

#define BT_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[BT_CONFIG_ARGC]; \
args[0]._key = BT_CONFIG_MODE_KEY; \
args[0]._str = BT_CONFIG_MODE_STR; \
args[1]._key = BT_CONFIG_PROFILE_KEY; \
args[1]._str = BT_CONFIG_PROFILE_STR; \
args[2]._key = BT_CONFIG_TOUT_KEY; \
args[2]._str = BT_CONFIG_TOUT_STR;
#define BT_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[BT_CONFIG_ARGC]; \
args[0]._key = BT_CONFIG_MODE_KEY; \
args[0]._str = (char *)BT_CONFIG_MODE_STR; \
args[1]._key = BT_CONFIG_PROFILE_KEY; \
args[1]._str = (char *)BT_CONFIG_PROFILE_STR; \
args[2]._key = BT_CONFIG_TOUT_KEY; \
args[2]._str = (char *)BT_CONFIG_TOUT_STR;

size_t _z_bt_config_strlen(const _z_str_intmap_t *s);

Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/link/config/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define SERIAL_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[SERIAL_CONFIG_ARGC]; \
args[0]._key = SERIAL_CONFIG_BAUDRATE_KEY; \
args[0]._str = SERIAL_CONFIG_BAUDRATE_STR;
args[0]._str = (char *)SERIAL_CONFIG_BAUDRATE_STR;
// args[1]._key = SERIAL_CONFIG_DATABITS_KEY;
// args[1]._str = SERIAL_CONFIG_DATABITS_STR;
// args[2]._key = SERIAL_CONFIG_FLOWCONTROL_KEY;
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/link/config/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define TCP_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[TCP_CONFIG_ARGC]; \
args[0]._key = TCP_CONFIG_TOUT_KEY; \
args[0]._str = TCP_CONFIG_TOUT_STR;
args[0]._str = (char *)TCP_CONFIG_TOUT_STR;

size_t _z_tcp_config_strlen(const _z_str_intmap_t *s);

Expand Down
16 changes: 8 additions & 8 deletions include/zenoh-pico/link/config/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
#define UDP_CONFIG_JOIN_STR "join"

#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1
#define UDP_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[UDP_CONFIG_ARGC]; \
args[0]._key = UDP_CONFIG_IFACE_KEY; \
args[0]._str = UDP_CONFIG_IFACE_STR; \
args[1]._key = UDP_CONFIG_TOUT_KEY; \
args[1]._str = UDP_CONFIG_TOUT_STR; \
args[2]._key = UDP_CONFIG_JOIN_KEY; \
args[2]._str = UDP_CONFIG_JOIN_STR;
#define UDP_CONFIG_MAPPING_BUILD \
_z_str_intmapping_t args[UDP_CONFIG_ARGC]; \
args[0]._key = UDP_CONFIG_IFACE_KEY; \
args[0]._str = (char *)UDP_CONFIG_IFACE_STR; \
args[1]._key = UDP_CONFIG_TOUT_KEY; \
args[1]._str = (char *)UDP_CONFIG_TOUT_STR; \
args[2]._key = UDP_CONFIG_JOIN_KEY; \
args[2]._str = (char *)UDP_CONFIG_JOIN_STR;

size_t _z_udp_config_strlen(const _z_str_intmap_t *s);

Expand Down
6 changes: 3 additions & 3 deletions src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,19 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb

char *opt_as_str = _z_config_get(config->_value, Z_CONFIG_SCOUTING_WHAT_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_SCOUTING_WHAT_DEFAULT;
opt_as_str = (char *)Z_CONFIG_SCOUTING_WHAT_DEFAULT;
}
z_what_t what = strtol(opt_as_str, NULL, 10);

opt_as_str = _z_config_get(config->_value, Z_CONFIG_MULTICAST_LOCATOR_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_MULTICAST_LOCATOR_DEFAULT;
opt_as_str = (char *)Z_CONFIG_MULTICAST_LOCATOR_DEFAULT;
}
char *mcast_locator = opt_as_str;

opt_as_str = _z_config_get(config->_value, Z_CONFIG_SCOUTING_TIMEOUT_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT;
opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT;
}
uint32_t timeout = strtoul(opt_as_str, NULL, 10);

Expand Down
6 changes: 3 additions & 3 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) {
if (connect == NULL && listen == NULL) { // Scout if peer is not configured
opt_as_str = _z_config_get(config, Z_CONFIG_SCOUTING_WHAT_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_SCOUTING_WHAT_DEFAULT;
opt_as_str = (char *)Z_CONFIG_SCOUTING_WHAT_DEFAULT;
}
z_what_t what = strtol(opt_as_str, NULL, 10);

opt_as_str = _z_config_get(config, Z_CONFIG_MULTICAST_LOCATOR_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_MULTICAST_LOCATOR_DEFAULT;
opt_as_str = (char *)Z_CONFIG_MULTICAST_LOCATOR_DEFAULT;
}
char *mcast_locator = opt_as_str;

opt_as_str = _z_config_get(config, Z_CONFIG_SCOUTING_TIMEOUT_KEY);
if (opt_as_str == NULL) {
opt_as_str = Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT;
opt_as_str = (char *)Z_CONFIG_SCOUTING_TIMEOUT_DEFAULT;
}
uint32_t timeout = strtoul(opt_as_str, NULL, 10);

Expand Down

0 comments on commit c6ee2cc

Please sign in to comment.