/* Note: this function is executed on TCP thread and should return as soon as possible.  */
void websocket_cb(struct tcp_pcb *pcb, uint8_t *data, u16_t data_len, uint8_t mode)
/* Note: this function is executed on TCP thread and should return as soon as possible.  */
void websocket_cb(struct tcp_pcb *pcb, uint8_t *data, u16_t data_len, uint8_t mode)
{
    printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char*) data);
    uint8_t response[2];
    uint16_t val;
    switch (data[0]) {
        case 'A':
            val = sdk_system_adc_read();
            break;
        case 'D':
            gpio_write(LED_PIN, true);
            val = 0xDEAD;
            break;
        case 'E':
            gpio_write(LED_PIN, false);
            val = 0xBEEF;
            break;
        default:
            printf("Unknown command\n");
            val = 0;
            break;
    }
    response[1] = (uint8_t) val;
    response[0] = val >> 8;
    websocket_write(pcb, response, 2, WS_BIN_MODE);
}