diff --git a/picomap.cpp b/picomap.cpp index f6dcab4..16f73f3 100644 --- a/picomap.cpp +++ b/picomap.cpp @@ -57,37 +57,39 @@ int main() { while (true) { tud_task(); - if (!tud_cdc_available()) continue; + while (tud_cdc_available()) { + uint8_t byte; + if (tud_cdc_read(&byte, 1) != 1) break; - uint8_t byte; - if (tud_cdc_read(&byte, 1) != 1) continue; + rx_buf.push_back(byte); - rx_buf.push_back(byte); + auto msg = try_decode(rx_buf); + if (!msg) { + if (rx_buf.full()) rx_buf.clear(); + continue; + } - auto msg = try_decode(rx_buf); - if (!msg) { - if (rx_buf.full()) rx_buf.clear(); - continue; + rx_buf.clear(); + + switch (msg->type_id) { + case RequestPICOBOOT::ext_id: + send_bytes(encode_response(msg->message_id, ResponsePICOBOOT{})); + sleep_ms(100); + reset_usb_boot(0, 1); + break; + case RequestInfo::ext_id: { + ResponseInfo resp; + pico_unique_board_id_t uid; + pico_get_unique_board_id(&uid); + std::copy(uid.id, uid.id + 8, resp.board_id.begin()); + auto ninfo = w6300::get_net_info(); + resp.mac = ninfo.mac; + send_bytes(encode_response(msg->message_id, resp)); + break; + } + } } - rx_buf.clear(); - - switch (msg->type_id) { - case RequestPICOBOOT::ext_id: - send_bytes(encode_response(msg->message_id, ResponsePICOBOOT{})); - sleep_ms(100); - reset_usb_boot(0, 1); - break; - case RequestInfo::ext_id: { - ResponseInfo resp; - pico_unique_board_id_t uid; - pico_get_unique_board_id(&uid); - std::copy(uid.id, uid.id + 8, resp.board_id.begin()); - auto ninfo = w6300::get_net_info(); - resp.mac = ninfo.mac; - send_bytes(encode_response(msg->message_id, resp)); - break; - } - } + __wfi(); } }