Skip to content

Commit cbe9512

Browse files
authored
Merge pull request #2741 from tannewt/fix_packetbuffer_server
Fix PacketBuffer server support
2 parents e8cffcf + 81139ae commit cbe9512

File tree

16 files changed

+96
-19
lines changed

16 files changed

+96
-19
lines changed

locale/ID.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -398,6 +398,11 @@ msgstr ""
398398
msgid "Buffer too large and unable to allocate"
399399
msgstr ""
400400

401+
#: shared-bindings/_bleio/PacketBuffer.c
402+
#, c-format
403+
msgid "Buffer too short by %d bytes"
404+
msgstr ""
405+
401406
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
402407
#: ports/nrf/common-hal/displayio/ParallelBus.c
403408
#, fuzzy, c-format

locale/circuitpython.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -394,6 +394,11 @@ msgstr ""
394394
msgid "Buffer too large and unable to allocate"
395395
msgstr ""
396396

397+
#: shared-bindings/_bleio/PacketBuffer.c
398+
#, c-format
399+
msgid "Buffer too short by %d bytes"
400+
msgstr ""
401+
397402
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
398403
#: ports/nrf/common-hal/displayio/ParallelBus.c
399404
#, c-format

locale/de_DE.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
1212
"Last-Translator: Pascal Deneaux\n"
1313
"Language-Team: Sebastian Plamauer, Pascal Deneaux\n"
@@ -398,6 +398,11 @@ msgstr "Der Puffer muss eine Mindestenslänge von 1 haben"
398398
msgid "Buffer too large and unable to allocate"
399399
msgstr ""
400400

401+
#: shared-bindings/_bleio/PacketBuffer.c
402+
#, c-format
403+
msgid "Buffer too short by %d bytes"
404+
msgstr ""
405+
401406
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
402407
#: ports/nrf/common-hal/displayio/ParallelBus.c
403408
#, c-format

locale/en_US.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
1212
"Last-Translator: \n"
1313
"Language-Team: \n"
@@ -394,6 +394,11 @@ msgstr ""
394394
msgid "Buffer too large and unable to allocate"
395395
msgstr ""
396396

397+
#: shared-bindings/_bleio/PacketBuffer.c
398+
#, c-format
399+
msgid "Buffer too short by %d bytes"
400+
msgstr ""
401+
397402
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
398403
#: ports/nrf/common-hal/displayio/ParallelBus.c
399404
#, c-format

locale/en_x_pirate.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2018-07-27 11:55-0700\n"
1212
"Last-Translator: \n"
1313
"Language-Team: @sommersoft, @MrCertainly\n"
@@ -398,6 +398,11 @@ msgstr ""
398398
msgid "Buffer too large and unable to allocate"
399399
msgstr ""
400400

401+
#: shared-bindings/_bleio/PacketBuffer.c
402+
#, c-format
403+
msgid "Buffer too short by %d bytes"
404+
msgstr ""
405+
401406
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
402407
#: ports/nrf/common-hal/displayio/ParallelBus.c
403408
#, c-format

locale/es.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2018-08-24 22:56-0500\n"
1212
"Last-Translator: \n"
1313
"Language-Team: \n"
@@ -400,6 +400,11 @@ msgstr "Buffer debe ser de longitud 1 como minimo"
400400
msgid "Buffer too large and unable to allocate"
401401
msgstr ""
402402

403+
#: shared-bindings/_bleio/PacketBuffer.c
404+
#, c-format
405+
msgid "Buffer too short by %d bytes"
406+
msgstr ""
407+
403408
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
404409
#: ports/nrf/common-hal/displayio/ParallelBus.c
405410
#, c-format

locale/fil.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2018-12-20 22:15-0800\n"
1212
"Last-Translator: Timothy <[email protected]>\n"
1313
"Language-Team: fil\n"
@@ -400,6 +400,11 @@ msgstr "Buffer dapat ay hindi baba sa 1 na haba"
400400
msgid "Buffer too large and unable to allocate"
401401
msgstr ""
402402

403+
#: shared-bindings/_bleio/PacketBuffer.c
404+
#, c-format
405+
msgid "Buffer too short by %d bytes"
406+
msgstr ""
407+
403408
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
404409
#: ports/nrf/common-hal/displayio/ParallelBus.c
405410
#, fuzzy, c-format

locale/fr.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: 0.1\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: 2019-04-14 20:05+0100\n"
1313
"Last-Translator: Pierrick Couturier <[email protected]>\n"
1414
"Language-Team: fr\n"
@@ -404,6 +404,11 @@ msgstr "Le tampon doit être de longueur au moins 1"
404404
msgid "Buffer too large and unable to allocate"
405405
msgstr ""
406406

407+
#: shared-bindings/_bleio/PacketBuffer.c
408+
#, c-format
409+
msgid "Buffer too short by %d bytes"
410+
msgstr ""
411+
407412
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
408413
#: ports/nrf/common-hal/displayio/ParallelBus.c
409414
#, fuzzy, c-format

locale/it_IT.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: 2018-10-02 16:27+0200\n"
1313
"Last-Translator: Enrico Paganin <[email protected]>\n"
1414
"Language-Team: \n"
@@ -400,6 +400,11 @@ msgstr "Il buffer deve essere lungo almeno 1"
400400
msgid "Buffer too large and unable to allocate"
401401
msgstr ""
402402

403+
#: shared-bindings/_bleio/PacketBuffer.c
404+
#, c-format
405+
msgid "Buffer too short by %d bytes"
406+
msgstr ""
407+
403408
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
404409
#: ports/nrf/common-hal/displayio/ParallelBus.c
405410
#, fuzzy, c-format

locale/ko.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: 2019-05-06 14:22-0700\n"
1313
"Last-Translator: \n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -398,6 +398,11 @@ msgstr "잘못된 크기의 버퍼. >1 여야합니다"
398398
msgid "Buffer too large and unable to allocate"
399399
msgstr ""
400400

401+
#: shared-bindings/_bleio/PacketBuffer.c
402+
#, c-format
403+
msgid "Buffer too short by %d bytes"
404+
msgstr ""
405+
401406
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
402407
#: ports/nrf/common-hal/displayio/ParallelBus.c
403408
#, c-format

locale/pl.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: \n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2019-03-19 18:37-0700\n"
1212
"Last-Translator: Radomir Dopieralski <[email protected]>\n"
1313
"Language-Team: pl\n"
@@ -397,6 +397,11 @@ msgstr "Bufor musi mieć długość 1 lub więcej"
397397
msgid "Buffer too large and unable to allocate"
398398
msgstr ""
399399

400+
#: shared-bindings/_bleio/PacketBuffer.c
401+
#, c-format
402+
msgid "Buffer too short by %d bytes"
403+
msgstr ""
404+
400405
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
401406
#: ports/nrf/common-hal/displayio/ParallelBus.c
402407
#, c-format

locale/pt_BR.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
11+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1212
"PO-Revision-Date: 2018-10-02 21:14-0000\n"
1313
"Last-Translator: \n"
1414
"Language-Team: \n"
@@ -397,6 +397,11 @@ msgstr ""
397397
msgid "Buffer too large and unable to allocate"
398398
msgstr ""
399399

400+
#: shared-bindings/_bleio/PacketBuffer.c
401+
#, c-format
402+
msgid "Buffer too short by %d bytes"
403+
msgstr ""
404+
400405
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
401406
#: ports/nrf/common-hal/displayio/ParallelBus.c
402407
#, fuzzy, c-format

locale/zh_Latn_pinyin.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ msgid ""
77
msgstr ""
88
"Project-Id-Version: circuitpython-cn\n"
99
"Report-Msgid-Bugs-To: \n"
10-
"POT-Creation-Date: 2020-03-20 17:57-0500\n"
10+
"POT-Creation-Date: 2020-03-30 17:03-0700\n"
1111
"PO-Revision-Date: 2019-04-13 10:10-0700\n"
1212
"Last-Translator: hexthat\n"
1313
"Language-Team: Chinese Hanyu Pinyin\n"
@@ -403,6 +403,11 @@ msgstr "Huǎnchōng qū bìxū zhìshǎo chángdù 1"
403403
msgid "Buffer too large and unable to allocate"
404404
msgstr "huǎn chōng qū tài dà , wú fǎ fēn pèi"
405405

406+
#: shared-bindings/_bleio/PacketBuffer.c
407+
#, c-format
408+
msgid "Buffer too short by %d bytes"
409+
msgstr ""
410+
406411
#: ports/atmel-samd/common-hal/displayio/ParallelBus.c
407412
#: ports/nrf/common-hal/displayio/ParallelBus.c
408413
#, c-format

ports/nrf/common-hal/_bleio/Connection.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
162162
self->do_bond_cccds = true;
163163
self->do_bond_cccds_request_time = supervisor_ticks_ms64();
164164
}
165-
break;
165+
// Return false so other handlers get this event as well.
166+
return false;
166167

167168
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
168169
sd_ble_gatts_sys_attr_set(self->conn_handle, NULL, 0, 0);

ports/nrf/common-hal/_bleio/PacketBuffer.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
148148
// A client wrote to this server characteristic.
149149

150150
ble_gatts_evt_write_t *evt_write = &ble_evt->evt.gatts_evt.params.write;
151+
151152
// Event handle must match the handle for my characteristic.
152153
if (evt_write->handle == self->characteristic->handle) {
153154
if (self->conn_handle == BLE_CONN_HANDLE_INVALID) {
@@ -156,8 +157,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
156157
return false;
157158
}
158159
write_to_ringbuf(self, evt_write->data, evt_write->len);
159-
} else if (evt_write->handle == self->characteristic->cccd_handle &&
160-
self->conn_handle == BLE_CONN_HANDLE_INVALID) {
160+
} else if (evt_write->handle == self->characteristic->cccd_handle) {
161161
uint16_t cccd = *((uint16_t*) evt_write->data);
162162
if (cccd & BLE_GATT_HVX_NOTIFICATION) {
163163
self->conn_handle = conn_handle;
@@ -167,6 +167,11 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) {
167167
}
168168
break;
169169
}
170+
case BLE_GAP_EVT_DISCONNECTED: {
171+
if (self->conn_handle == conn_handle) {
172+
self->conn_handle = BLE_CONN_HANDLE_INVALID;
173+
}
174+
}
170175
case BLE_GATTS_EVT_HVN_TX_COMPLETE: {
171176
queue_next_write(self);
172177
}
@@ -192,6 +197,8 @@ void common_hal_bleio_packet_buffer_construct(
192197
incoming = outgoing;
193198
outgoing = temp;
194199
self->conn_handle = bleio_connection_get_conn_handle(MP_OBJ_TO_PTR(self->characteristic->service->connection));
200+
} else {
201+
self->conn_handle = BLE_CONN_HANDLE_INVALID;
195202
}
196203

197204
if (incoming) {
@@ -255,8 +262,7 @@ int common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uin
255262
sd_nvic_critical_region_enter(&is_nested_critical_region);
256263

257264
if (packet_length > len) {
258-
// TODO: raise an exception.
259-
packet_length = len;
265+
return len - packet_length;
260266
}
261267

262268
ringbuf_get_n(&self->ringbuf, data, packet_length);

shared-bindings/_bleio/PacketBuffer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o
109109
mp_buffer_info_t bufinfo;
110110
mp_get_buffer_raise(buffer_obj, &bufinfo, MP_BUFFER_WRITE);
111111

112-
return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len));
112+
int size = common_hal_bleio_packet_buffer_readinto(self, bufinfo.buf, bufinfo.len);
113+
if (size < 0) {
114+
mp_raise_ValueError_varg(translate("Buffer too short by %d bytes"), size * -1);
115+
}
116+
117+
return MP_OBJ_NEW_SMALL_INT(size);
113118
}
114119
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto);
115120

0 commit comments

Comments
 (0)