Commit e15fb33e authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

extmod/modwebrepl: Add GET_VER operation to query MicroPython version.

parent cbef0dba
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "py/mphal.h" #include "py/mphal.h"
#endif #endif
#include "extmod/modwebsocket.h" #include "extmod/modwebsocket.h"
#include "genhdr/mpversion.h"
#if MICROPY_PY_WEBREPL #if MICROPY_PY_WEBREPL
...@@ -57,7 +58,7 @@ struct webrepl_file { ...@@ -57,7 +58,7 @@ struct webrepl_file {
char fname[64]; char fname[64];
} __attribute__((packed)); } __attribute__((packed));
enum { PUT_FILE = 1, GET_FILE, LIST_DIR }; enum { PUT_FILE = 1, GET_FILE, GET_VER };
enum { STATE_PASSWD, STATE_NORMAL }; enum { STATE_PASSWD, STATE_NORMAL };
typedef struct _mp_obj_webrepl_t { typedef struct _mp_obj_webrepl_t {
...@@ -128,6 +129,20 @@ STATIC int write_file_chunk(mp_obj_webrepl_t *self) { ...@@ -128,6 +129,20 @@ STATIC int write_file_chunk(mp_obj_webrepl_t *self) {
} }
STATIC void handle_op(mp_obj_webrepl_t *self) { STATIC void handle_op(mp_obj_webrepl_t *self) {
// Handle operations not requiring opened file
switch (self->hdr.type) {
case GET_VER: {
static char ver[] = {MICROPY_VERSION_MAJOR, MICROPY_VERSION_MINOR, MICROPY_VERSION_MICRO};
write_webrepl(self->sock, ver, sizeof(ver));
self->hdr_to_recv = sizeof(struct webrepl_file);
return;
}
}
// Handle operations requiring opened file
mp_obj_t open_args[2] = { mp_obj_t open_args[2] = {
mp_obj_new_str(self->hdr.fname, strlen(self->hdr.fname), false), mp_obj_new_str(self->hdr.fname, strlen(self->hdr.fname), false),
MP_OBJ_NEW_QSTR(MP_QSTR_rb) MP_OBJ_NEW_QSTR(MP_QSTR_rb)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment