diff --git a/README.md b/README.md index cb1a9b9..b794f3c 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ graphical interface served on the webpage. ## Setup +[Installation and demo video](https://youtu.be/uORnxt5DLTw) + Download the webkeyboard.uf2 file from the latest [release](https://git.kkozai.com/kenji/webkeyboard/releases) and flash onto the Raspberry Pi Pico W by holding down the BOOTSEL button while plugging diff --git a/websocket.c b/websocket.c index 1980a7e..613e9c4 100644 --- a/websocket.c +++ b/websocket.c @@ -13,6 +13,9 @@ static const char WS_RESPONSE[] = "HTTP/1.1 101 Switching Protocols\r\n" \ "Connection: Upgrade\r\n" \ "Sec-WebSocket-Accept: "; +static uint8_t buf[WS_BUFFER_SIZE]; +static uint16_t buf_len=0; + static tWSHandler ws_receive_cb = NULL; static tWSOpenHandler ws_open_cb = NULL; @@ -330,30 +333,87 @@ static err_t ws_read(struct altcp_pcb *pcb, struct ws_state *wss, struct pbuf *p // successful read, reset timeout wss->retries = 0; - uint8_t mode = data[0] & 0x0F; + uint8_t fin = data[0] & 0x80; + uint8_t opcode = data[0] & 0x0F; + uint8_t masked = data[1] & 0x80; uint16_t msg_len = data[1] & 0x7F; - switch (mode) { - case 0x01: //text + uint8_t *msg; + switch (msg_len) { + case 126: // next two bytes are length + memcpy(&msg_len, &data[2], 2); + if (len >= 8) { + msg = &data[8]; + } + break; + case 127: // next four bytes are length + // lwIP's pbuf only handles 16-bit lengths, so error + return ERR_ARG; + + //memcpy(&msg_len, &data[2], 4); + //if (len >= 10) { + // msg = &data[10]; + //} + //break; + default: + if (len >= 6) { + msg = &data[6]; + } + break; + } + switch (opcode) { + case OP_CONT: + LWIP_DEBUGF(WS_DEBUG, ("ws_read: received continuation frame\n")); + case OP_TEXT: LWIP_DEBUGF(WS_DEBUG, ("ws_read: received text data\n")); - case 0x02: //binary - LWIP_DEBUGF(WS_DEBUG, ("ws_read: decoding data\n")); - if (len >= 6 && ws_receive_cb != NULL) { - uint8_t *mask = &data[2]; - uint8_t *msg = &data[6]; - - for (int i=0; i