summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/modesp.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-25 17:41:06 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-01-25 17:41:06 +0200
commit5fb775a0c059d187366525ff66be1c892a7b3302 (patch)
treeb2766b5af109538ec069878a91f47826cee3149c /esp8266/modesp.c
parent6ec650b41fd340a1f5787a86ce3388b2d1ff5311 (diff)
downloadmicropython-5fb775a0c059d187366525ff66be1c892a7b3302.tar.gz
micropython-5fb775a0c059d187366525ff66be1c892a7b3302.zip
esp8266: Handle exceptions in callback.
Diffstat (limited to 'esp8266/modesp.c')
-rw-r--r--esp8266/modesp.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/esp8266/modesp.c b/esp8266/modesp.c
index 1bc1b710f3..70df5ba360 100644
--- a/esp8266/modesp.c
+++ b/esp8266/modesp.c
@@ -32,12 +32,25 @@
#include "py/obj.h"
#include "py/gc.h"
#include "py/runtime.h"
+#include "py/pfenv.h"
#include MICROPY_HAL_H
#include "queue.h"
#include "user_interface.h"
+// Singleton instance of scan callback, meaning that there can be only
+// one concurrent AP scan.
STATIC mp_obj_t scan_cb_obj;
+mp_obj_t call_function_1_protected(mp_obj_t fun, mp_obj_t arg) {
+ nlr_buf_t nlr;
+ if (nlr_push(&nlr) == 0) {
+ return mp_call_function_1(fun, arg);
+ } else {
+ mp_obj_print_exception(printf_wrapper, NULL, (mp_obj_t)nlr.ret_val);
+ return (mp_obj_t)nlr.ret_val;
+ }
+}
+
STATIC void esp_scan_cb(scaninfo *si, STATUS status) {
//printf("in pyb_scan_cb: %d, si=%p, si->pbss=%p\n", status, si, si->pbss);
struct bss_info *bs;
@@ -50,7 +63,7 @@ STATIC void esp_scan_cb(scaninfo *si, STATUS status) {
t->items[3] = MP_OBJ_NEW_SMALL_INT(bs->rssi);
t->items[4] = MP_OBJ_NEW_SMALL_INT(bs->authmode);
t->items[5] = MP_OBJ_NEW_SMALL_INT(bs->is_hidden);
- mp_call_function_1(scan_cb_obj, t);
+ call_function_1_protected(scan_cb_obj, t);
}
}
}