Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
aecb8a53bd | ||
|
b204778385 | ||
|
eda1f811a1 | ||
|
baa053b8b2 | ||
|
eb03e4ba59 | ||
|
fc1f47d0d2 | ||
|
ebc765e1e0 | ||
|
3266720f15 | ||
|
078a799078 | ||
|
6fd9c4803b |
@ -57,6 +57,8 @@ typedef struct _ujson_stream_t {
|
||||
int errcode;
|
||||
mp_obj_t python_readinto[2 + 1];
|
||||
mp_obj_array_t bytearray_obj;
|
||||
size_t start;
|
||||
size_t end;
|
||||
byte cur;
|
||||
} ujson_stream_t;
|
||||
|
||||
@ -77,28 +79,44 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) {
|
||||
return s->cur;
|
||||
}
|
||||
|
||||
// We read from an object's `readinto` method in chunks larger than the json
|
||||
// parser needs to reduce the number of function calls done.
|
||||
|
||||
#define CIRCUITPY_JSON_READ_CHUNK_SIZE 64
|
||||
|
||||
STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
|
||||
(void) size; // Ignore size because we know it's always 1.
|
||||
ujson_stream_t* s = obj;
|
||||
s->bytearray_obj.items = buf;
|
||||
s->bytearray_obj.len = size;
|
||||
|
||||
if (s->start == s->end) {
|
||||
*errcode = 0;
|
||||
mp_obj_t ret = mp_call_method_n_kw(1, 0, s->python_readinto);
|
||||
if (ret == mp_const_none) {
|
||||
*errcode = MP_EAGAIN;
|
||||
return MP_STREAM_ERROR;
|
||||
}
|
||||
return mp_obj_get_int(ret);
|
||||
s->start = 0;
|
||||
s->end = mp_obj_get_int(ret);
|
||||
}
|
||||
|
||||
*((uint8_t *)buf) = ((uint8_t*) s->bytearray_obj.items)[s->start];
|
||||
s->start++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
|
||||
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, stream_obj);
|
||||
ujson_stream_t s;
|
||||
uint8_t character_buffer[CIRCUITPY_JSON_READ_CHUNK_SIZE];
|
||||
if (stream_p == NULL) {
|
||||
s.start = 0;
|
||||
s.end = 0;
|
||||
mp_load_method(stream_obj, MP_QSTR_readinto, s.python_readinto);
|
||||
s.bytearray_obj.base.type = &mp_type_bytearray;
|
||||
s.bytearray_obj.typecode = BYTEARRAY_TYPECODE;
|
||||
s.bytearray_obj.len = CIRCUITPY_JSON_READ_CHUNK_SIZE;
|
||||
s.bytearray_obj.free = 0;
|
||||
// len and items are set at read time
|
||||
s.bytearray_obj.items = character_buffer;
|
||||
s.python_readinto[2] = MP_OBJ_FROM_PTR(&s.bytearray_obj);
|
||||
s.stream_obj = &s;
|
||||
s.read = ujson_python_readinto;
|
||||
|
@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-11-04 21:18+0530\n"
|
||||
"POT-Creation-Date: 2020-12-21 23:48-0500\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@ -2861,7 +2861,7 @@ msgid "max_length must be 0-%d when fixed_length is %s"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/_bleio/Characteristic.c shared-bindings/_bleio/Descriptor.c
|
||||
msgid "max_length must be > 0"
|
||||
msgid "max_length must be >= 0"
|
||||
msgstr ""
|
||||
|
||||
#: py/runtime.c
|
||||
@ -2999,6 +2999,14 @@ msgstr ""
|
||||
msgid "non-keyword arg after keyword arg"
|
||||
msgstr ""
|
||||
|
||||
#: ports/nrf/common-hal/_bleio/Adapter.c
|
||||
msgid "non-zero timeout must be > 0.01"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/_bleio/Adapter.c
|
||||
msgid "non-zero timeout must be >= interval"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/_bleio/UUID.c
|
||||
msgid "not a 128-bit UUID"
|
||||
msgstr ""
|
||||
@ -3400,6 +3408,10 @@ msgstr ""
|
||||
msgid "timeout must be 0.0-100.0 seconds"
|
||||
msgstr ""
|
||||
|
||||
#: ports/nrf/common-hal/_bleio/Adapter.c
|
||||
msgid "timeout must be < 655.35 secs"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/_bleio/CharacteristicBuffer.c
|
||||
msgid "timeout must be >= 0.0"
|
||||
msgstr ""
|
||||
|
@ -82,7 +82,8 @@ void frequencyin_emergency_cancel_capture(uint8_t index) {
|
||||
#ifdef SAM_D5X_E5X
|
||||
NVIC_EnableIRQ(EIC_0_IRQn + self->channel);
|
||||
#endif
|
||||
mp_raise_RuntimeError(translate("Frequency captured is above capability. Capture Paused."));
|
||||
// Frequency captured is above capability. Capture paused.
|
||||
// We can't raise an error here; we're in an interrupt handler.
|
||||
}
|
||||
|
||||
void frequencyin_interrupt_handler(uint8_t index) {
|
||||
|
@ -470,7 +470,16 @@ mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, uint8_t*
|
||||
ble_drv_add_event_handler(scan_on_ble_evt, self->scan_results);
|
||||
|
||||
uint32_t nrf_timeout = SEC_TO_UNITS(timeout, UNIT_10_MS);
|
||||
if (timeout <= 0.0001) {
|
||||
if (nrf_timeout > UINT16_MAX) {
|
||||
// 0xffff / 100
|
||||
mp_raise_ValueError(translate("timeout must be < 655.35 secs"));
|
||||
}
|
||||
if (nrf_timeout == 0 && timeout > 0.0f) {
|
||||
// Make sure converted timeout is > 0 if original timeout is > 0.
|
||||
mp_raise_ValueError(translate("non-zero timeout must be > 0.01"));
|
||||
}
|
||||
|
||||
if (nrf_timeout) {
|
||||
nrf_timeout = BLE_GAP_SCAN_TIMEOUT_UNLIMITED;
|
||||
}
|
||||
|
||||
|
@ -318,3 +318,5 @@ $(BUILD)/libaxtls.a: $(TOP)/lib/axtls/README | $(OBJ_DIRS)
|
||||
$(TOP)/lib/axtls/README:
|
||||
@echo "You cloned without --recursive, fetching submodules for you."
|
||||
(cd $(TOP); git submodule update --init --recursive)
|
||||
|
||||
$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h
|
||||
|
@ -33,8 +33,8 @@
|
||||
#include "shared-bindings/_bleio/Address.h"
|
||||
#include "shared-bindings/_bleio/Adapter.h"
|
||||
|
||||
#define ADV_INTERVAL_MIN (0.0020f)
|
||||
#define ADV_INTERVAL_MIN_STRING "0.0020"
|
||||
#define ADV_INTERVAL_MIN (0.02001f)
|
||||
#define ADV_INTERVAL_MIN_STRING "0.02001"
|
||||
#define ADV_INTERVAL_MAX (10.24f)
|
||||
#define ADV_INTERVAL_MAX_STRING "10.24"
|
||||
// 20ms is recommended by Apple
|
||||
@ -307,7 +307,7 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mp_float_t timeout = 0;
|
||||
mp_float_t timeout = 0.0f;
|
||||
if (args[ARG_timeout].u_obj != mp_const_none) {
|
||||
timeout = mp_obj_get_float(args[ARG_timeout].u_obj);
|
||||
}
|
||||
@ -325,6 +325,13 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
|
||||
mp_raise_ValueError_varg(translate("interval must be in range %s-%s"), INTERVAL_MIN_STRING, INTERVAL_MAX_STRING);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wfloat-equal"
|
||||
if (timeout != 0.0f && timeout < interval) {
|
||||
mp_raise_ValueError(translate("non-zero timeout must be >= interval"));
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
const mp_float_t window = mp_obj_float_get(args[ARG_window].u_obj);
|
||||
if (window > interval) {
|
||||
mp_raise_ValueError(translate("window must be <= interval"));
|
||||
|
@ -110,8 +110,8 @@ STATIC mp_obj_t bleio_characteristic_add_to_service(size_t n_args, const mp_obj_
|
||||
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
|
||||
|
||||
const mp_int_t max_length_int = args[ARG_max_length].u_int;
|
||||
if (max_length_int <= 0) {
|
||||
mp_raise_ValueError(translate("max_length must be > 0"));
|
||||
if (max_length_int < 0) {
|
||||
mp_raise_ValueError(translate("max_length must be >= 0"));
|
||||
}
|
||||
const size_t max_length = (size_t) max_length_int;
|
||||
const bool fixed_length = args[ARG_fixed_length].u_bool;
|
||||
|
@ -101,8 +101,8 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o
|
||||
common_hal_bleio_attribute_security_mode_check_valid(write_perm);
|
||||
|
||||
const mp_int_t max_length_int = args[ARG_max_length].u_int;
|
||||
if (max_length_int <= 0) {
|
||||
mp_raise_ValueError(translate("max_length must be > 0"));
|
||||
if (max_length_int < 0) {
|
||||
mp_raise_ValueError(translate("max_length must be >= 0"));
|
||||
}
|
||||
const size_t max_length = (size_t) max_length_int;
|
||||
const bool fixed_length = args[ARG_fixed_length].u_bool;
|
||||
|
Loading…
Reference in New Issue
Block a user