8000 espnow: More formatting fixes for linelength > 80. · micropython/micropython@f01fd27 · GitHub
[go: up one dir, main page]

Skip to content

Commit f01fd27

Browse files
committed
espnow: More formatting fixes for linelength > 80.
1 parent c6f950e commit f01fd27

File tree

2 files changed

+31
-52
lines changed

2 files changed

+31
-52
lines changed

ports/esp32/modespnow.c

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_activ
234234
// Get or set configuration values. Supported config params:
235235
// buffer: size of buffer for rx packets (default=514 bytes)
236236
// timeout: Default read timeout (default=300,000 milliseconds)
237-
STATIC mp_obj_t espnow_config(
238-
size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
239-
237+
STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
240238
esp_espnow_obj_t *self = _get_singleton();
241239
enum { ARG_get, ARG_buffer, ARG_timeout_ms, ARG_rate };
242240
static const mp_arg_t allowed_args[] = {
@@ -258,10 +256,8 @@ STATIC mp_obj_t espnow_config(
258256
if (args[ARG_rate].u_int >= 0) {
259257
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0)
260258
esp_initialise_wifi(); // Call the wifi init code in network_wlan.c
261-
check_esp_err(esp_wifi_config_espnow_rate(
262-
ESP_IF_WIFI_STA, args[ARG_rate].u_int));
263-
check_esp_err(esp_wifi_config_espnow_rate(
264-
ESP_IF_WIFI_AP, args[ARG_rate].u_int));
259+
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_STA, args[ARG_rate].u_int));
260+
check_esp_err(esp_wifi_config_espnow_rate(ESP_IF_WIFI_AP, args[ARG_rate].u_int));
265261
#else
266262
mp_raise_ValueError(MP_ERROR_TEXT("rate option not supported"));
267263
#endif
@@ -329,8 +325,9 @@ static inline int8_t _get_rssi_from_wifi_pkt(const uint8_t *msg) {
329325
// and a espnow_frame_format_t.
330326
// Backtrack to get a pointer to the wifi_promiscuous_pkt_t.
331327
static const size_t sizeof_espnow_frame_format = 39;
332-
wifi_promiscuous_pkt_t *wifi_pkt = (wifi_promiscuous_pkt_t *)(
333-
msg - sizeof_espnow_frame_format - sizeof(wifi_promiscuous_pkt_t));
328+
wifi_promiscuous_pkt_t *wifi_pkt =
329+
(wifi_promiscuous_pkt_t *)(msg - sizeof_espnow_frame_format -
330+
sizeof(wifi_promiscuous_pkt_t));
334331

335332
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 2, 0)
336333
return wifi_pkt->rx_ctrl.rssi - 100; // Offset rssi for IDF 4.0.2
@@ -342,9 +339,7 @@ static inline int8_t _get_rssi_from_wifi_pkt(const uint8_t *msg) {
342339
// Lookup a peer in the peers table and return a reference to the item in the
343340
// peers_table. Add peer to the table if it is not found (may alloc memory).
344341
// Will not return NULL.
345-
static mp_map_elem_t *_lookup_add_peer(
346-
esp_espnow_obj_t *self, const uint8_t *peer) {
347-
342+
static mp_map_elem_t *_lookup_add_peer(esp_espnow_obj_t *self, const uint8_t *peer) {
348343
// We do not want to allocate any new memory in the case that the peer
349344
// already exists in the peers_table (which is almost all the time).
350345
// So, we use a byte string on the stack and look that up in the dict.
@@ -364,9 +359,7 @@ static mp_map_elem_t *_lookup_add_peer(
364359

365360
// Update the peers table with the new rssi value from a received pkt and
366361
// return a reference to the item in the peers_table.
367-
static mp_map_elem_t *_update_rssi(
368-
const uint8_t *peer, int8_t rssi, uint32_t time_ms) {
369-
362+
static mp_map_elem_t *_update_rssi(const uint8_t *peer, int8_t rssi, uint32_t time_ms) {
370363
esp_espnow_obj_t *self = _get_singleton_initialised();
371364
// Lookup the peer in the device table
372365
mp_map_elem_t *item = _lookup_add_peer(self, peer);
@@ -389,8 +382,7 @@ static uint8_t *_get_bytes_len_rw(mp_obj_t obj, size_t len, mp_uint_t rw) {
389382
mp_buffer_info_t bufinfo;
390383
mp_get_buffer_raise(obj, &bufinfo, rw);
391384
if (bufinfo.len != len) {
392-
mp_raise_ValueError(
393-
MP_ERROR_TEXT("ESPNow: bytes or bytearray wrong length"));
385+
mp_raise_ValueError(MP_ERROR_TEXT("ESPNow: bytes or bytearray wrong length"));
394386
}
395387
return (uint8_t *)bufinfo.buf;
396388
}
@@ -465,10 +457,10 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) {
465457
int msg_len = hdr.msg_len;
466458

467459
// Check the message packet header format and read the message data
468-
if (hdr.magic != ESPNOW_MAGIC ||
469-
msg_len > ESP_NOW_MAX_DATA_LEN ||
470-
ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0 ||
471-
ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) {
460+
if (hdr.magic != ESPNOW_MAGIC
461+
|| msg_len > ESP_NOW_MAX_DATA_LEN
462+
|| ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0
463+
|| ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) {
472464
mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recv(): buffer error"));
473465
}
474466
if (mp_obj_is_type(msg, &mp_type_bytearray)) {
@@ -550,10 +542,9 @@ STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) {
550542
int saved_failures = self->tx_failures;
551543
// Send the packet - try, try again if internal esp-now buffers are full.
552544
esp_err_t err;
553-
int64_t start = mp_hal_ticks_ms();
554-
while ((ESP_ERR_ESPNOW_NO_MEM ==
555-
(err = esp_now_send(peer, message.buf, message.len))) &&
556-
(mp_hal_ticks_ms() - start) <= DEFAULT_SEND_TIMEOUT_MS) {
545+
mp_uint_t start = mp_hal_ticks_ms();
546+
while ((ESP_ERR_ESPNOW_NO_MEM == (err = esp_now_send(peer, message.buf, message.len)))
547+
&& (mp_uint_t)(mp_hal_ticks_ms() - start) < (mp_uint_t)DEFAULT_SEND_TIMEOUT_MS) {
557548
MICROPY_EVENT_POLL_HOOK;
558549
}
559550
check_esp_err(err); // Will raise OSError if e != ESP_OK
@@ -641,16 +632,13 @@ STATIC bool _update_peer_info(
641632
{ MP_QSTR_encrypt, MP_ARG_OBJ, {.u_obj = mp_const_none} },
642633
};
643634
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
644-
mp_arg_parse_all(n_args, pos_args, kw_args,
645-
MP_ARRAY_SIZE(allowed_args), allowed_args, args);
635+
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
646636
if (args[ARG_lmk].u_obj != mp_const_none) {
647637
mp_obj_t obj = args[ARG_lmk].u_obj;
648638
peer->encrypt = mp_obj_is_true(obj);
649639
if (peer->encrypt) {
650640
// Key must be 16 bytes in length.
651-
memcpy(peer->lmk,
652-
_get_bytes_len(obj, ESP_NOW_KEY_LEN),
653-
ESP_NOW_KEY_LEN);
641+
memcpy(peer->lmk, _get_bytes_len(obj, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN);
654642
}
655643
}
656644
if (args[ARG_channel].u_obj != mp_const_none) {
@@ -692,9 +680,7 @@ STATIC void _update_peer_count() {
692680
// Raise ValueError if mac or LMK are not bytes-like objects or wrong length.
693681
// Raise TypeError if invalid keyword args or too many positional args.
694682
// Return None.
695-
STATIC mp_obj_t espnow_add_peer(
696-
size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
697-
683+
STATIC mp_obj_t espnow_add_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
698684
esp_now_peer_info_t peer = {0};
699685
memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN);
700686
_update_peer_info(&peer, n_args - 2, args + 2, kw_args);
@@ -776,9 +762,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_get_peer_obj, espnow_get_peer);
776762
// Raise ValueError if mac or LMK are not bytes-like objects or wrong length.
777763
// Raise TypeError if invalid keyword args or too many positional args.
778764
// Return None.
779-
STATIC mp_obj_t espnow_mod_peer(
780-
size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
781-
765+
STATIC mp_obj_t espnow_mod_peer(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
782766
esp_now_peer_info_t peer = {0};
783767
memcpy(peer.peer_addr, _get_peer(args[1]), ESP_NOW_ETH_ALEN);
784768
check_esp_err(esp_now_get_peer(peer.peer_addr, &peer));
@@ -845,8 +829,8 @@ STATIC MP_DEFINE_CONST_DICT(espnow_globals_dict, espnow_globals_dict_table);
845829
// ...so asyncio can poll.ipoll() on this device
846830

847831
// Support ioctl(MP_STREAM_POLL, ) for asyncio
848-
STATIC mp_uint_t espnow_stream_ioctl(mp_obj_t self_in, mp_uint_t request,
849-
uintptr_t arg, int *errcode) {
832+
STATIC mp_uint_t espnow_stream_ioctl(
833+
mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
850834
if (request != MP_STREAM_POLL) {
851835
*errcode = MP_EINVAL;
852836
return MP_STREAM_ERROR;

ports/esp8266/modespnow.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_active_obj, 1, 2, espnow_activ
200200
// Initialise the Espressif ESPNOW software stack, register callbacks and
201201
// allocate the recv data buffers.
202202
// Returns True if interface is active, else False.
203-
STATIC mp_obj_t espnow_config(
204-
size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
205-
203+
STATIC mp_obj_t espnow_config(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
206204
esp_espnow_obj_t *self = _get_singleton();
207205
enum { ARG_rxbuf, ARG_timeout_ms };
208206
static const mp_arg_t allowed_args[] = {
@@ -263,8 +261,7 @@ static uint8_t *_get_bytes_len_rw(mp_obj_t obj, size_t len, mp_uint_t rw) {
263261
mp_buffer_info_t bufinfo;
264262
mp_get_buffer_raise(obj, &bufinfo, rw);
265263
if (bufinfo.len != len) {
266-
mp_raise_ValueError(
267-
MP_ERROR_TEXT("ESPNow: bytes or bytearray wrong length"));
264+
mp_raise_ValueError(MP_ERROR_TEXT("ESPNow: bytes or bytearray wrong length"));
268265
}
269266
return (uint8_t *)bufinfo.buf;
270267
}
@@ -329,10 +326,10 @@ STATIC mp_obj_t espnow_recvinto(size_t n_args, const mp_obj_t *args) {
329326
int msg_len = hdr.msg_len;
330327

331328
// Check the message packet header format and read the message data
332-
if (hdr.magic != ESPNOW_MAGIC ||
333-
msg_len > ESP_NOW_MAX_DATA_LEN ||
334-
ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0 ||
335-
ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) {
329+
if (hdr.magic != ESPNOW_MAGIC
330+
|| msg_len > ESP_NOW_MAX_DATA_LEN
331+
|| ringbuf_get_bytes(self->recv_buffer, peer_buf, ESP_NOW_ETH_ALEN) < 0
332+
|| ringbuf_get_bytes(self->recv_buffer, msg_buf, msg_len) < 0) {
336333
mp_raise_ValueError(MP_ERROR_TEXT("ESPNow.recv(): buffer error"));
337334
}
338335
if (mp_obj_is_type(msg, &mp_type_bytearray)) {
@@ -394,9 +391,8 @@ STATIC mp_obj_t espnow_send(size_t n_args, const mp_obj_t *args) {
394391
}
395392
int saved_failures = self->tx_failures;
396393

397-
check_esp_err(esp_now_send(
398-
_get_bytes_len(args[1], ESP_NOW_ETH_ALEN),
399-
message.buf, message.len));
394+
check_esp_err(
395+
esp_now_send(_get_bytes_len(args[1], ESP_NOW_ETH_ALEN), message.buf, message.len));
400396
self->tx_packets++;
401397
if (sync) {
402398
// Wait for message to be received by peer
@@ -414,8 +410,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(espnow_send_obj, 3, 4, espnow_send);
414410
// Raise OSError if not initialised.
415411
// Raise ValueError if key is not a bytes-like object exactly 16 bytes long.
416412
STATIC mp_obj_t espnow_set_pmk(mp_obj_t _, mp_obj_t key) {
417-
check_esp_err(esp_now_set_kok(
418-
_get_bytes_len(key, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN));
413+
check_esp_err(esp_now_set_kok(_get_bytes_len(key, ESP_NOW_KEY_LEN), ESP_NOW_KEY_LEN));
419414
return mp_const_none;
420415
}
421416
STATIC MP_DEFINE_CONST_FUN_OBJ_2(espnow_set_pmk_obj, espnow_set_pmk);

0 commit comments

Comments
 (0)
0