diff --git a/core/app-framework/app-native-shared/attr_container.c b/core/app-framework/app-native-shared/attr_container.c index e8c120196..e1e9f4e35 100644 --- a/core/app-framework/app-native-shared/attr_container.c +++ b/core/app-framework/app-native-shared/attr_container.c @@ -7,11 +7,14 @@ typedef union jvalue { bool z; - int8_t b; - uint16_t c; - int16_t s; - int32_t i; - int64_t j; + int8_t i8; + uint8_t u8; + int16_t i16; + uint16_t u16; + int32_t i32; + uint32_t u32; + int64_t i64; + uint64_t u64; float f; double d; } jvalue; @@ -27,7 +30,9 @@ get_int16(const char *buf) static inline uint16_t get_uint16(const char *buf) { - return get_int16(buf); + uint16_t ret; + bh_memcpy_s(&ret, sizeof(uint16_t), buf, sizeof(uint16_t)); + return ret; } static inline int32_t @@ -41,7 +46,9 @@ get_int32(const char *buf) static inline uint32_t get_uint32(const char *buf) { - return get_int32(buf); + uint32_t ret; + bh_memcpy_s(&ret, sizeof(uint32_t), buf, sizeof(uint32_t)); + return ret; } static inline int64_t @@ -55,7 +62,9 @@ get_int64(const char *buf) static inline uint64_t get_uint64(const char *buf) { - return get_int64(buf); + uint64_t ret; + bh_memcpy_s(&ret, sizeof(uint64_t), buf, sizeof(uint64_t)); + return ret; } static inline void @@ -145,8 +154,8 @@ attr_container_get_attr_next(const char *curr_attr) p += sizeof(uint16_t) + get_uint16(p); type = *p++; - /* Short type to Boolean type */ - if (type >= ATTR_TYPE_SHORT && type <= ATTR_TYPE_BOOLEAN) { + /* Byte type to Boolean type */ + if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) { p += 1 << (type & 3); return p; } @@ -342,7 +351,7 @@ attr_container_set_attr(attr_container_t **p_attr_cont, const char *key, /* key len + key + '\0' + type */ attr_len = sizeof(uint16_t) + strlen(key) + 1 + 1; - if (type >= ATTR_TYPE_SHORT && type <= ATTR_TYPE_BOOLEAN) + if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) attr_len += 1 << (type & 3); else if (type == ATTR_TYPE_STRING) attr_len += sizeof(uint16_t) + value_length; @@ -362,7 +371,7 @@ attr_container_set_attr(attr_container_t **p_attr_cont, const char *key, p += str_len; *p++ = type; - if (type >= ATTR_TYPE_SHORT && type <= ATTR_TYPE_BOOLEAN) + if (type >= ATTR_TYPE_BYTE && type <= ATTR_TYPE_BOOLEAN) bh_memcpy_s(p, 1 << (type & 3), value, 1 << (type & 3)); else if (type == ATTR_TYPE_STRING) { set_uint16(p, value_length); @@ -460,6 +469,14 @@ attr_container_set_short(attr_container_t **p_attr_cont, const char *key, 2); } +bool +attr_container_set_int16(attr_container_t **p_attr_cont, const char *key, + int16_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT16, &value, + 2); +} + bool attr_container_set_int(attr_container_t **p_attr_cont, const char *key, int value) @@ -467,6 +484,22 @@ attr_container_set_int(attr_container_t **p_attr_cont, const char *key, return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT, &value, 4); } +bool +attr_container_set_int32(attr_container_t **p_attr_cont, const char *key, + int32_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT32, &value, + 4); +} + +bool +attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key, + uint32_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT32, &value, + 4); +} + bool attr_container_set_int64(attr_container_t **p_attr_cont, const char *key, int64_t value) @@ -475,6 +508,14 @@ attr_container_set_int64(attr_container_t **p_attr_cont, const char *key, 8); } +bool +attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key, + uint64_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT64, &value, + 8); +} + bool attr_container_set_byte(attr_container_t **p_attr_cont, const char *key, int8_t value) @@ -482,6 +523,21 @@ attr_container_set_byte(attr_container_t **p_attr_cont, const char *key, return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_BYTE, &value, 1); } +bool +attr_container_set_int8(attr_container_t **p_attr_cont, const char *key, + int8_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_INT8, &value, 1); +} + +bool +attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key, + uint8_t value) +{ + return attr_container_set_attr(p_attr_cont, key, ATTR_TYPE_UINT8, &value, + 1); +} + bool attr_container_set_uint16(attr_container_t **p_attr_cont, const char *key, uint16_t value) @@ -552,7 +608,7 @@ attr_container_get_attr(const attr_container_t *attr_cont, const char *key) if (!(attr_addr = attr_container_find_attr(attr_cont, key))) { attr_container_printf("Get attribute failed: lookup key failed.\r\n"); - return false; + return NULL; } /* key len + key + '\0' */ @@ -566,14 +622,17 @@ attr_container_get_attr(const attr_container_t *attr_cont, const char *key) uint8_t type; \ if (!addr) \ return 0; \ - val.j = 0; \ + val.i64 = 0; \ type = *(uint8_t *)addr++; \ switch (type) { \ - case ATTR_TYPE_SHORT: \ - case ATTR_TYPE_INT: \ + case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ \ + case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ \ + case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ \ case ATTR_TYPE_INT64: \ - case ATTR_TYPE_BYTE: \ + case ATTR_TYPE_UINT8: \ case ATTR_TYPE_UINT16: \ + case ATTR_TYPE_UINT32: \ + case ATTR_TYPE_UINT64: \ case ATTR_TYPE_FLOAT: \ case ATTR_TYPE_DOUBLE: \ case ATTR_TYPE_BOOLEAN: \ @@ -608,31 +667,67 @@ attr_container_get_attr(const attr_container_t *attr_cont, const char *key) short attr_container_get_as_short(const attr_container_t *attr_cont, const char *key) { - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, s); + TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i16); +} + +int16_t +attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key) +{ + return (int16_t)attr_container_get_as_short(attr_cont, key); } int attr_container_get_as_int(const attr_container_t *attr_cont, const char *key) { - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i); + TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i32); +} + +int32_t +attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key) +{ + return (int32_t)attr_container_get_as_int(attr_cont, key); +} + +uint32_t +attr_container_get_as_uint32(const attr_container_t *attr_cont, const char *key) +{ + return (uint32_t)attr_container_get_as_int(attr_cont, key); } int64_t attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key) { - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, j); + TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i64); +} + +uint64_t +attr_container_get_as_uint64(const attr_container_t *attr_cont, const char *key) +{ + return (uint64_t)attr_container_get_as_int64(attr_cont, key); } int8_t attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key) { - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, b); + TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, i8); +} + +int8_t +attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key) +{ + return attr_container_get_as_byte(attr_cont, key); +} + +uint8_t +attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key) +{ + return (uint8_t)attr_container_get_as_byte(attr_cont, key); } uint16_t attr_container_get_as_uint16(const attr_container_t *attr_cont, const char *key) { - TEMPLATE_ATTR_BUF_TO_VALUE(attr_cont, key, s); + return (uint16_t)attr_container_get_as_short(attr_cont, key); } float @@ -671,11 +766,14 @@ attr_container_get_as_bytearray(const attr_container_t *attr_cont, type = *(uint8_t *)addr++; switch (type) { - case ATTR_TYPE_SHORT: - case ATTR_TYPE_INT: + case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ + case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ + case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ case ATTR_TYPE_INT64: - case ATTR_TYPE_BYTE: + case ATTR_TYPE_UINT8: case ATTR_TYPE_UINT16: + case ATTR_TYPE_UINT32: + case ATTR_TYPE_UINT64: case ATTR_TYPE_FLOAT: case ATTR_TYPE_DOUBLE: case ATTR_TYPE_BOOLEAN: @@ -807,34 +905,52 @@ attr_container_dump(const attr_container_t *attr_cont) attr_container_printf(" key: %s", key); switch (type) { - case ATTR_TYPE_SHORT: - bh_memcpy_s(&value.s, sizeof(int16_t), p, sizeof(int16_t)); + case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ + bh_memcpy_s(&value.i8, 1, p, 1); + attr_container_printf(", type: byte, value: 0x%x\n", + value.i8 & 0xFF); + p++; + break; + case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ + bh_memcpy_s(&value.i16, sizeof(int16_t), p, sizeof(int16_t)); attr_container_printf(", type: short, value: 0x%x\n", - value.s & 0xFFFF); + value.i16 & 0xFFFF); p += 2; break; - case ATTR_TYPE_INT: - bh_memcpy_s(&value.i, sizeof(int32_t), p, sizeof(int32_t)); - attr_container_printf(", type: int, value: 0x%x\n", value.i); + case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ + bh_memcpy_s(&value.i32, sizeof(int32_t), p, sizeof(int32_t)); + attr_container_printf(", type: int, value: 0x%x\n", value.i32); p += 4; break; case ATTR_TYPE_INT64: - bh_memcpy_s(&value.j, sizeof(uint64_t), p, sizeof(uint64_t)); + bh_memcpy_s(&value.i64, sizeof(int64_t), p, sizeof(int64_t)); attr_container_printf(", type: int64, value: 0x%llx\n", - (long long unsigned int)(value.j)); + (long long unsigned int)(value.i64)); p += 8; break; - case ATTR_TYPE_BYTE: - bh_memcpy_s(&value.b, 1, p, 1); - attr_container_printf(", type: byte, value: 0x%x\n", - value.b & 0xFF); + case ATTR_TYPE_UINT8: + bh_memcpy_s(&value.u8, 1, p, 1); + attr_container_printf(", type: uint8, value: 0x%x\n", value.u8); p++; break; case ATTR_TYPE_UINT16: - bh_memcpy_s(&value.c, sizeof(uint16_t), p, sizeof(uint16_t)); - attr_container_printf(", type: uint16, value: 0x%x\n", value.c); + bh_memcpy_s(&value.u16, sizeof(uint16_t), p, sizeof(uint16_t)); + attr_container_printf(", type: uint16, value: 0x%x\n", + value.u16); p += 2; break; + case ATTR_TYPE_UINT32: + bh_memcpy_s(&value.u32, sizeof(uint32_t), p, sizeof(uint32_t)); + attr_container_printf(", type: uint32, value: 0x%x\n", + value.u32); + p += 4; + break; + case ATTR_TYPE_UINT64: + bh_memcpy_s(&value.u64, sizeof(uint64_t), p, sizeof(uint64_t)); + attr_container_printf(", type: int64, value: 0x%llx\n", + (long long unsigned int)(value.u64)); + p += 8; + break; case ATTR_TYPE_FLOAT: bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float)); attr_container_printf(", type: float, value: %f\n", value.f); diff --git a/core/app-framework/app-native-shared/bi-inc/attr_container.h b/core/app-framework/app-native-shared/bi-inc/attr_container.h index 3b7be8062..f5d8759b8 100644 --- a/core/app-framework/app-native-shared/bi-inc/attr_container.h +++ b/core/app-framework/app-native-shared/bi-inc/attr_container.h @@ -20,13 +20,27 @@ extern "C" { /* Attribute type */ enum { - ATTR_TYPE_BEGIN = 1, - ATTR_TYPE_SHORT = ATTR_TYPE_BEGIN, + ATTR_TYPE_BEGIN = 0, + ATTR_TYPE_BYTE = ATTR_TYPE_BEGIN, + ATTR_TYPE_INT8 = ATTR_TYPE_BYTE, + ATTR_TYPE_SHORT, + ATTR_TYPE_INT16 = ATTR_TYPE_SHORT, ATTR_TYPE_INT, + ATTR_TYPE_INT32 = ATTR_TYPE_INT, ATTR_TYPE_INT64, - ATTR_TYPE_BYTE, + ATTR_TYPE_UINT8, ATTR_TYPE_UINT16, - ATTR_TYPE_FLOAT, + ATTR_TYPE_UINT32, + ATTR_TYPE_UINT64, + /** + * Why ATTR_TYPE_FLOAT = 10? + * We determine the number of bytes that should be copied through 1<<(type & + * 3). ATTR_TYPE_BYTE = 0, so the number of bytes is 1 << 0 = 1. + * ATTR_TYPE_UINT64 = 7, so the number of bytes is 1 << 3 = 8. + * Since the float type takes up 4 bytes, ATTR_TYPE_FLOAT should be 10. + * Calculation: (1 << (10&3)) = (1 << 2) = 4 + */ + ATTR_TYPE_FLOAT = 10, ATTR_TYPE_DOUBLE, ATTR_TYPE_BOOLEAN, ATTR_TYPE_STRING, @@ -89,6 +103,20 @@ bool attr_container_set_short(attr_container_t **p_attr_cont, const char *key, short value); +/** + * Set int16 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_int16(attr_container_t **p_attr_cont, const char *key, + int16_t value); + /** * Set int attribute in attribute container * @@ -103,6 +131,34 @@ bool attr_container_set_int(attr_container_t **p_attr_cont, const char *key, int value); +/** + * Set int32 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_int32(attr_container_t **p_attr_cont, const char *key, + int32_t value); + +/** + * Set uint32 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_uint32(attr_container_t **p_attr_cont, const char *key, + uint32_t value); + /** * Set int64 attribute in attribute container * @@ -117,6 +173,20 @@ bool attr_container_set_int64(attr_container_t **p_attr_cont, const char *key, int64_t value); +/** + * Set uint64 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_uint64(attr_container_t **p_attr_cont, const char *key, + uint64_t value); + /** * Set byte attribute in attribute container * @@ -131,6 +201,34 @@ bool attr_container_set_byte(attr_container_t **p_attr_cont, const char *key, int8_t value); +/** + * Set int8 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_int8(attr_container_t **p_attr_cont, const char *key, + int8_t value); + +/** + * Set uint8 attribute in attribute container + * + * @param p_attr_cont pointer to attribute container to set attribute, and + * return the new attribute container if it is re-created + * @param key the attribute key + * @param value the attribute value + * + * @return true if success, false otherwise + */ +bool +attr_container_set_uint8(attr_container_t **p_attr_cont, const char *key, + uint8_t value); + /** * Set uint16 attribute in attribute container * @@ -259,6 +357,18 @@ attr_container_contain_key(const attr_container_t *attr_cont, const char *key); short attr_container_get_as_short(const attr_container_t *attr_cont, const char *key); +/** + * Get attribute from attribute container and return it as int16 value, + * return 0 if attribute isn't found in message. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the short value of the attribute, 0 if key isn't found + */ +int16_t +attr_container_get_as_int16(const attr_container_t *attr_cont, const char *key); + /** * Get attribute from attribute container and return it as int value, * return 0 if attribute isn't found in message. @@ -271,6 +381,31 @@ attr_container_get_as_short(const attr_container_t *attr_cont, const char *key); int attr_container_get_as_int(const attr_container_t *attr_cont, const char *key); +/** + * Get attribute from attribute container and return it as int32 value, + * return 0 if attribute isn't found in message. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the int value of the attribute, 0 if key isn't found + */ +int32_t +attr_container_get_as_int32(const attr_container_t *attr_cont, const char *key); + +/** + * Get attribute from attribute container and return it as uint32 value, + * return 0 if attribute isn't found in message. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the unsigned int value of the attribute, 0 if key isn't found + */ +uint32_t +attr_container_get_as_uint32(const attr_container_t *attr_cont, + const char *key); + /** * Get attribute from attribute container and return it as int64 value, * return 0 if attribute isn't found in attribute container. @@ -283,6 +418,19 @@ attr_container_get_as_int(const attr_container_t *attr_cont, const char *key); int64_t attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key); +/** + * Get attribute from attribute container and return it as uint64 value, + * return 0 if attribute isn't found in attribute container. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the unsigned long value of the attribute, 0 if key isn't found + */ +uint64_t +attr_container_get_as_uint64(const attr_container_t *attr_cont, + const char *key); + /** * Get attribute from attribute container and return it as byte value, * return 0 if attribute isn't found in attribute container. @@ -295,6 +443,30 @@ attr_container_get_as_int64(const attr_container_t *attr_cont, const char *key); int8_t attr_container_get_as_byte(const attr_container_t *attr_cont, const char *key); +/** + * Get attribute from attribute container and return it as int8 value, + * return 0 if attribute isn't found in attribute container. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the byte value of the attribute, 0 if key isn't found + */ +int8_t +attr_container_get_as_int8(const attr_container_t *attr_cont, const char *key); + +/** + * Get attribute from attribute container and return it as uint8 value, + * return 0 if attribute isn't found in attribute container. + * + * @param attr_cont the attribute container + * @param key the attribute key + * + * @return the uint8 value of the attribute, 0 if key isn't found + */ +uint8_t +attr_container_get_as_uint8(const attr_container_t *attr_cont, const char *key); + /** * Get attribute from attribute container and return it as uint16 value, * return 0 if attribute isn't found in attribute container. diff --git a/samples/gui/wasm-apps/increase/Makefile b/samples/gui/wasm-apps/increase/Makefile index 2c150332a..5f250d6ef 100644 --- a/samples/gui/wasm-apps/increase/Makefile +++ b/samples/gui/wasm-apps/increase/Makefile @@ -25,9 +25,9 @@ SRCS += $(APP_FRAMEWORK_DIR)/wgl/app/src/*.c all: @$(CC) $(CFLAGS) $(SRCS) \ - --target=wasm32 -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ - -Wl,--allow-undefined \ - -Wl,--strip-all,--no-entry -nostdlib \ + --target=wasm32-wasi -O3 -z stack-size=2048 -Wl,--initial-memory=65536 \ + -nostdlib -Wl,--allow-undefined \ + -Wl,--strip-all,--no-entry \ -Wl,--export=on_init -Wl,--export=on_timer_callback \ -Wl,--export=on_widget_event \ -Wl,--export=__heap_base,--export=__data_end \ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html index 9e9d63c9a..4ad7427ba 100755 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html +++ b/test-tools/IoT-APP-Store-Demo/wasm_django/devices/templates/help.html @@ -33,7 +33,7 @@

1. Download a simple runtime (build for ubuntu 20.04 64 bits, other platforms please build - from the source code) + from the source code)

2. In the terminal: cd ~/Download && ./simple -a 82.156.57.236 @@ -44,7 +44,7 @@

Notes:
We also have a UI-enabled runtime, please download here and enjoy. It may require + href="../static/upload/wasm_runtime_wgl">download here and enjoy. It may require a few more setups.

Before running the UI-enabled runtime, please install some required softwares:

sudo apt-get install libsdl2-2.0-0:i386

diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py b/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py index 5edeb90aa..970ec6f60 100755 --- a/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py +++ b/test-tools/IoT-APP-Store-Demo/wasm_django/server/wasm_server.py @@ -16,14 +16,18 @@ import logging import os attr_type_list = [ - "ATTR_NONE", - "ATTR_TYPE_SHORT", - "ATTR_TYPE_INT", + "ATTR_TYPE_BYTE", # = ATTR_TYPE_INT8 + "ATTR_TYPE_SHORT",# = ATTR_TYPE_INT16 + "ATTR_TYPE_INT", # = ATTR_TYPE_INT32 "ATTR_TYPE_INT64", - "ATTR_TYPE_BYTE", + "ATTR_TYPE_UINT8", "ATTR_TYPE_UINT16", + "ATTR_TYPE_UINT32", + "ATTR_TYPE_UINT64", "ATTR_TYPE_FLOAT", "ATTR_TYPE_DOUBLE", + "ATTR_NONE", + "ATTR_NONE", "ATTR_TYPE_BOOLEAN", "ATTR_TYPE_STRING", "ATTR_TYPE_BYTEARRAY" @@ -140,26 +144,38 @@ def decode_attr_container(msg): attr_type = attr_type_list[int(type_index[0])] buf = buf[1 : ] - if attr_type == "ATTR_TYPE_SHORT": + if attr_type == "ATTR_TYPE_BYTE": # = ATTR_TYPE_INT8 + (attr_value, ) = struct.unpack('@c', buf[0 : 1]) + buf = buf[1 : ] + # continue + elif attr_type == "ATTR_TYPE_SHORT": # = ATTR_TYPE_INT16 (attr_value, ) = struct.unpack('@h', buf[0 : 2]) buf = buf[2 : ] # continue - elif attr_type == "ATTR_TYPE_INT": - (attr_value, ) = struct.unpack('@I', buf[0 : 4]) + elif attr_type == "ATTR_TYPE_INT": # = ATTR_TYPE_INT32 + (attr_value, ) = struct.unpack('@i', buf[0 : 4]) buf = buf[4 : ] # continue elif attr_type == "ATTR_TYPE_INT64": (attr_value, ) = struct.unpack('@q', buf[0 : 8]) buf = buf[8 : ] # continue - elif attr_type == "ATTR_TYPE_BYTE": - (attr_value, ) = struct.unpack('@c', buf[0 : 1]) + elif attr_type == "ATTR_TYPE_UINT8": + (attr_value, ) = struct.unpack('@B', buf[0 : 1]) buf = buf[1 : ] # continue elif attr_type == "ATTR_TYPE_UINT16": (attr_value, ) = struct.unpack('@H', buf[0 : 2]) buf = buf[2 : ] # continue + elif attr_type == "ATTR_TYPE_UINT32": + (attr_value, ) = struct.unpack('@I', buf[0 : 4]) + buf = buf[4 : ] + # continue + elif attr_type == "ATTR_TYPE_UINT64": + (attr_value, ) = struct.unpack('@Q', buf[0 : 8]) + buf = buf[8 : ] + # continue elif attr_type == "ATTR_TYPE_FLOAT": (attr_value, ) = struct.unpack('@f', buf[0 : 4]) buf = buf[4 : ] diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm index 2a2e79dc7..936e80cf6 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/connection.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm index 4cf911099..31dc1018f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_publisher.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm index 1766c2565..1dce622f4 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/event_subscriber.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm index 1da74dbe7..85959790f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_handler.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm index f7c9b994e..ce9a6f6e8 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/request_sender.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm index eb51ec8ee..f24bd1009 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sensor.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple index da9c485ed..478a0f85f 100755 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/simple differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm index 2a2e79dc7..936e80cf6 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/connection.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm index 4cf911099..31dc1018f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_publisher.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm index 1766c2565..1dce622f4 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/event_subscriber.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm index 1da74dbe7..85959790f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_handler.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm index f7c9b994e..ce9a6f6e8 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/request_sender.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm index bcd4c8fa4..0bb3c920f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/sys/timer.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm index bcd4c8fa4..0bb3c920f 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/timer.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm index ddda9e2d3..1182ca291 100644 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/ui_app.wasm differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/vgl_wasm_runtime b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/vgl_wasm_runtime deleted file mode 100755 index fa68f3a2d..000000000 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/vgl_wasm_runtime and /dev/null differ diff --git a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl index eb7b42b82..30f8e92e2 100755 Binary files a/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl and b/test-tools/IoT-APP-Store-Demo/wasm_django/static/upload/wasm_runtime_wgl differ diff --git a/test-tools/host-tool/src/host_tool_utils.c b/test-tools/host-tool/src/host_tool_utils.c index 2b9051bbf..9ea3d6ca9 100644 --- a/test-tools/host-tool/src/host_tool_utils.c +++ b/test-tools/host-tool/src/host_tool_utils.c @@ -15,11 +15,14 @@ typedef union jvalue { bool z; - int8_t b; - uint16_t c; - int16_t s; - int32_t i; - int64_t j; + int8_t i8; + uint8_t u8; + int16_t i16; + uint16_t u16; + int32_t i32; + uint32_t u32; + int64_t i64; + uint64_t u64; float f; double d; } jvalue; @@ -90,43 +93,64 @@ attr2json(const attr_container_t *attr_cont) type = *p++; switch (type) { - case ATTR_TYPE_SHORT: - bh_memcpy_s(&value.s, sizeof(int16_t), p, sizeof(int16_t)); - if (NULL == (obj = cJSON_CreateNumber(value.s))) + case ATTR_TYPE_BYTE: /* = ATTR_TYPE_INT8 */ + bh_memcpy_s(&value.i8, 1, p, 1); + if (NULL == (obj = cJSON_CreateNumber(value.i8))) + goto fail; + cJSON_AddItemToObject(root, key, obj); + p++; + break; + case ATTR_TYPE_SHORT: /* = ATTR_TYPE_INT16 */ + bh_memcpy_s(&value.i16, sizeof(int16_t), p, sizeof(int16_t)); + if (NULL == (obj = cJSON_CreateNumber(value.i16))) goto fail; cJSON_AddItemToObject(root, key, obj); /* another approach: cJSON_AddNumberToObject(root, key, value.s) */ p += 2; break; - case ATTR_TYPE_INT: - bh_memcpy_s(&value.i, sizeof(int32_t), p, sizeof(int32_t)); - if (NULL == (obj = cJSON_CreateNumber(value.i))) + case ATTR_TYPE_INT: /* = ATTR_TYPE_INT32 */ + bh_memcpy_s(&value.i32, sizeof(int32_t), p, sizeof(int32_t)); + if (NULL == (obj = cJSON_CreateNumber(value.i32))) goto fail; cJSON_AddItemToObject(root, key, obj); p += 4; break; case ATTR_TYPE_INT64: - bh_memcpy_s(&value.j, sizeof(uint64_t), p, sizeof(uint64_t)); - if (NULL == (obj = cJSON_CreateNumber(value.j))) + bh_memcpy_s(&value.i64, sizeof(int64_t), p, sizeof(int64_t)); + if (NULL == (obj = cJSON_CreateNumber(value.i64))) goto fail; cJSON_AddItemToObject(root, key, obj); p += 8; break; - case ATTR_TYPE_BYTE: - bh_memcpy_s(&value.b, 1, p, 1); - if (NULL == (obj = cJSON_CreateNumber(value.b))) + case ATTR_TYPE_UINT8: + bh_memcpy_s(&value.u8, 1, p, 1); + if (NULL == (obj = cJSON_CreateNumber(value.u8))) goto fail; cJSON_AddItemToObject(root, key, obj); p++; break; case ATTR_TYPE_UINT16: - bh_memcpy_s(&value.c, sizeof(uint16_t), p, sizeof(uint16_t)); - if (NULL == (obj = cJSON_CreateNumber(value.c))) + bh_memcpy_s(&value.u16, sizeof(uint16_t), p, sizeof(uint16_t)); + if (NULL == (obj = cJSON_CreateNumber(value.u16))) goto fail; cJSON_AddItemToObject(root, key, obj); p += 2; break; + case ATTR_TYPE_UINT32: + bh_memcpy_s(&value.u32, sizeof(uint32_t), p, sizeof(uint32_t)); + if (NULL == (obj = cJSON_CreateNumber(value.u32))) + goto fail; + cJSON_AddItemToObject(root, key, obj); + p += 4; + break; + case ATTR_TYPE_UINT64: + bh_memcpy_s(&value.u64, sizeof(uint64_t), p, sizeof(uint64_t)); + if (NULL == (obj = cJSON_CreateNumber(value.u64))) + goto fail; + cJSON_AddItemToObject(root, key, obj); + p += 8; + break; case ATTR_TYPE_FLOAT: bh_memcpy_s(&value.f, sizeof(float), p, sizeof(float)); if (NULL == (obj = cJSON_CreateNumber(value.f)))