Skip to content

Commit

Permalink
Forward port changes from v0.6 release branch
Browse files Browse the repository at this point in the history
Merge fix for C++ with newer esp-idf and new `network:sta_rssi/0`.
  • Loading branch information
bettio committed May 20, 2024
2 parents 7ed0c3a + aad2d60 commit ceedd61
Show file tree
Hide file tree
Showing 47 changed files with 303 additions and 139 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added guards `is_even` and `is_odd` to the `Integer` module
- Add a number of functions to proplists module, such as `delete/2`, `from/to_map/1`, etc...
- Add `esp:deep_sleep_enable_gpio_wakeup/2` to allow wakeup from deep sleep for ESP32C3 and ESP32C6.
- Obtain RSSI of the current connection with `network:sta_rssi/0` on ESP32.
- Pico-W support for `network:sta_rssi/0`.

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions doc/src/network-programming-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ case network:wait_for_sta(Config, 15000) of
end
```

To obtain the signal strength (in decibels) of the connection to the associated access point use [`network:sta_rssi/0`](./apidocs/erlang/eavmlib/network.md#sta_rssi0).

## AP mode

In AP mode, the ESP32 starts a WiFi network to which other devices (laptops, mobile devices, other ESP32 devices, etc) can connect. The ESP32 will create an IPv4 network, and will assign itself the address `192.168.4.1`. Devices that attach to the ESP32 in AP mode will be assigned sequential addresses in the `192.168.4.0/24` range, e.g., `192.168.4.2`, `192.168.4.3`, etc.
Expand Down
22 changes: 21 additions & 1 deletion libs/eavmlib/src/network.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

-export([
wait_for_sta/0, wait_for_sta/1, wait_for_sta/2,
wait_for_ap/0, wait_for_ap/1, wait_for_ap/2
wait_for_ap/0, wait_for_ap/1, wait_for_ap/2,
sta_rssi/0
]).
-export([start/1, start_link/1, stop/0]).
-export([
Expand Down Expand Up @@ -88,6 +89,8 @@

-type network_config() :: [sta_config() | ap_config() | sntp_config()].

-type db() :: integer().

-record(state, {
config :: network_config(),
port :: port(),
Expand Down Expand Up @@ -247,6 +250,23 @@ start_link(Config) ->
stop() ->
gen_server:stop(?SERVER).

%%-----------------------------------------------------------------------------
%% @returns {ok, Rssi} in decibels, or {error, Reason}.
%%
%% @doc Get the rssi information of AP to which the device is associated with.
%% @end
%%-----------------------------------------------------------------------------
-spec sta_rssi() -> {ok, Rssi :: db()} | {error, Reason :: term()}.
sta_rssi() ->
Port = get_port(),
Ref = make_ref(),
Port ! {self(), Ref, rssi},
receive
{Ref, {error, Reason}} -> {error, Reason};
{Ref, {rssi, Rssi}} -> {ok, Rssi};
Other -> {error, Other}
end.

%%
%% gen_server callbacks
%%
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/atom.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#ifndef _ATOM_H_
#define _ATOM_H_

#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdlib.h>

/**
* @details no-op macro: just syntax sugar for avoiding mistakes or clang-format dividing atoms in multiple
* lines. Usage: ATOM_STR("\\x5", "hello").
Expand Down
8 changes: 8 additions & 0 deletions src/libAtomVM/atom_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#include "atom.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ATOM_TABLE_NOT_FOUND -1
#define ATOM_TABLE_ALLOC_FAIL -2

Expand Down Expand Up @@ -63,4 +67,8 @@ void atom_table_write_bytes(struct AtomTable *table, atom_ref_t atom, size_t buf
void atom_table_write_cstring(
struct AtomTable *table, atom_ref_t atom, size_t buf_len, char *outbuf);

#ifdef __cplusplus
}
#endif

#endif
4 changes: 2 additions & 2 deletions src/libAtomVM/atomshashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#ifndef _ATOMSHASHTABLE_H_
#define _ATOMSHASHTABLE_H_

#include "atom.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "atom.h"

#ifndef AVM_NO_SMP
#ifndef TYPEDEF_RWLOCK
#define TYPEDEF_RWLOCK
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/avmpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
#ifndef _AVMPACK_H_
#define _AVMPACK_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"
#include "list.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define END_OF_FILE 0
#define BEAM_START_FLAG 1
#define BEAM_CODE_FLAG 2
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/bif.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
#ifndef _BIF_H_
#define _BIF_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "atom.h"
#include "context.h"
#include "exportedfunction.h"
#include "module.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_BIF_NAME_LEN 260

const struct ExportedFunction *bif_registry_get_handler(AtomString module, AtomString function, int arity);
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/bitstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
#ifndef _BITSTRING_H_
#define _BITSTRING_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "term.h"

#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __ORDER_LITTLE_ENDIAN__
#define READ_16LE_UNALIGNED(ptr) \
( (((uint8_t *)(ptr))[1] << 8) | ((uint8_t *)(ptr))[0] )
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
#ifndef _CONTEXT_H_
#define _CONTEXT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"
#include "list.h"
#include "mailbox.h"
#include "smp.h"
#include "term.h"
#include "timer_list.h"

#ifdef __cplusplus
extern "C" {
#endif

struct Module;

#ifndef TYPEDEF_MODULE
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include "context.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"

/**
* @brief Print a repreentation of the context to stderr.
*
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/defaultatoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#ifndef _DEFAULTATOMS_H_
#define _DEFAULTATOMS_H_

#include "globalcontext.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "globalcontext.h"

#define FALSE_ATOM_INDEX 0
#define TRUE_ATOM_INDEX 1

Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_

#include "list.h"
#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "list.h"
#include "term.h"

typedef enum
{
DictionaryOk,
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/erl_nif_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _ERL_NIF_PRIV_H_
#define _ERL_NIF_PRIV_H_

#include "context.h"
#include "memory.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"
#include "memory.h"

struct ErlNifEnv
{
GlobalContext *global;
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/externalterm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _EXTERNALTERM_H_
#define _EXTERNALTERM_H_

#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "term.h"

enum ExternalTermResult
{
EXTERNAL_TERM_OK = 0,
Expand Down
8 changes: 4 additions & 4 deletions src/libAtomVM/globalcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
#ifndef _GLOBALCONTEXT_H_
#define _GLOBALCONTEXT_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#include "atom.h"
Expand All @@ -45,6 +41,10 @@ extern "C" {
#include "term.h"
#include "timer_list.h"

#ifdef __cplusplus
extern "C" {
#endif

#define INVALID_PROCESS_ID 0

struct Context;
Expand Down
4 changes: 2 additions & 2 deletions src/libAtomVM/iff.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#ifndef _IFF_H_
#define _IFF_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/** UTF-8 Atoms table section */
#define AT8U 0
/** Code chunk section */
Expand Down
6 changes: 3 additions & 3 deletions src/libAtomVM/interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
#ifndef _INTEROP_H_
#define _INTEROP_H_

#include "context.h"
#include "term.h"

#ifdef __cplusplus
extern "C" {
#endif

#include "context.h"
#include "term.h"

typedef enum
{
InteropOk,
Expand Down
8 changes: 8 additions & 0 deletions src/libAtomVM/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#ifndef _LIST_H_
#define _LIST_H_

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief gets a pointer to the struct that contains a certain list head
*
Expand Down Expand Up @@ -92,4 +96,8 @@ static inline struct ListHead *list_last(struct ListHead *head)
return head->prev;
}

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions src/libAtomVM/listeners.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Add an event listener to the set of polled events.
*
Expand Down Expand Up @@ -151,3 +155,7 @@ void sys_listener_destroy(struct ListHead *item)
free(listener);
}
#endif /* DOXYGEN_SKIP_SECTION */

#ifdef __cplusplus
}
#endif
8 changes: 4 additions & 4 deletions src/libAtomVM/mailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
#ifndef _MAILBOX_H_
#define _MAILBOX_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>

#include "list.h"
Expand All @@ -50,6 +46,10 @@ extern "C" {
#define ATOMIC
#endif

#ifdef __cplusplus
extern "C" {
#endif

struct Context;

#ifndef TYPEDEF_CONTEXT
Expand Down
Loading

0 comments on commit ceedd61

Please sign in to comment.