diff --git a/CMakeLists.txt b/CMakeLists.txt index dcb0dc0..639eede 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ #set(BUILD_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/install CACHE STRING "install destination for 3rd party libs and plugins") set(BUILD_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/install CACHE STRING "") set(WALLET_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE STRING "") +if ((${CMAKE_BUILD_TYPE} MATCHES "Debug")) + SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") + SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +endif() include(cmake/solc.cmake) if(BUILD_XCOMPILE) diff --git a/examples/wallet/app/main.c b/examples/wallet/app/main.c index 7088895..a3dab6b 100644 --- a/examples/wallet/app/main.c +++ b/examples/wallet/app/main.c @@ -6,13 +6,13 @@ /* system includes */ #include -#include #include #include #include /* local includes */ #include "zephyr-wallet/wallet.h" +#include "zephyr-wallet/shell_modules.h" #include "zephyr-wallet/lwm2m_client.h" /* 1000 msec = 1 sec */ @@ -54,11 +54,12 @@ void main(void) { int cnt = 0; struct device *dev = init_led(); - lwm2m_init(); +/* lwm2m_init();*/ privkey_t pk; memcpy(&pk.k, g_zephyr_private_key, 32); wallet_set_global_privkey(&pk); + wallet_register_shell_modules(); while (1) { /* Set pin to HIGH/LOW every 1 second */ diff --git a/prj.conf b/prj.conf index 2aeb91f..cbdf1e2 100644 --- a/prj.conf +++ b/prj.conf @@ -11,6 +11,7 @@ CONFIG_HTTP_PARSER_URL=y CONFIG_NETWORKING=y CONFIG_NET_TCP=y +CONFIG_NET_UDP=y CONFIG_NET_IPV6=y CONFIG_NET_IPV4=y CONFIG_NET_CONFIG_SETTINGS=y @@ -40,3 +41,5 @@ CONFIG_DHT_NAME="DHT11" CONFIG_DHT_GPIO_DEV_NAME="GPIO_1" CONFIG_DHT_GPIO_PIN_NUM=10 CONFIG_SENSOR=y +CONFIG_SNTP=y +CONFIG_POSIX_API=y diff --git a/prj_qemu_x86.conf b/prj_qemu_x86.conf index 7da3a30..2f9e5a2 100644 --- a/prj_qemu_x86.conf +++ b/prj_qemu_x86.conf @@ -35,3 +35,5 @@ CONFIG_LWM2M_IPSO_SUPPORT=y CONFIG_LWM2M_IPSO_TEMP_SENSOR=y CONFIG_POSIX_API=y + +CONFIG_SNTP=y diff --git a/zephyr-wallet/erc20_shell.c b/zephyr-wallet/erc20_shell.c index e4c257b..49d2add 100644 --- a/zephyr-wallet/erc20_shell.c +++ b/zephyr-wallet/erc20_shell.c @@ -305,3 +305,6 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_erc20) { SHELL_SUBCMD_SET_END }; SHELL_CMD_REGISTER(erc20, &sub_erc20, "erc20 utils", NULL); + +void erc20_shell_register() +{} diff --git a/zephyr-wallet/erc20_shell.h b/zephyr-wallet/erc20_shell.h index 59342a2..f52c980 100644 --- a/zephyr-wallet/erc20_shell.h +++ b/zephyr-wallet/erc20_shell.h @@ -7,6 +7,7 @@ #ifdef __cplusplus extern "C" { #endif +void erc20_shell_register(); #ifdef __cplusplus } diff --git a/zephyr-wallet/http_service.c b/zephyr-wallet/http_service.c index a37da05..8037906 100644 --- a/zephyr-wallet/http_service.c +++ b/zephyr-wallet/http_service.c @@ -6,6 +6,7 @@ */ /* system includes */ +#define LOG_MODULE_NAME http_service #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wignored-qualifiers" @@ -54,18 +55,15 @@ static int on_headers_complete(struct http_parser *parser) if ((ctx->http.req.method == HTTP_HEAD || ctx->http.req.method == HTTP_OPTIONS) && ctx->http.rsp.content_length > 0) { - NET_DBG("No body expected"); return 1; } if ((ctx->http.req.method == HTTP_PUT || ctx->http.req.method == HTTP_POST) && ctx->http.rsp.content_length == 0) { - NET_DBG("No body expected"); return 1; } - NET_DBG("Headers complete"); return 0; } diff --git a/zephyr-wallet/sensor_service.c b/zephyr-wallet/sensor_service.c index fb6b2ae..10edfca 100644 --- a/zephyr-wallet/sensor_service.c +++ b/zephyr-wallet/sensor_service.c @@ -80,3 +80,6 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_sensor) { SHELL_SUBCMD_SET_END }; SHELL_CMD_REGISTER(sensor, &sub_sensor, "temperature sensor", NULL); + +void sensor_shell_register() +{} diff --git a/zephyr-wallet/sensor_service.h b/zephyr-wallet/sensor_service.h index 3dbd126..74c2d70 100644 --- a/zephyr-wallet/sensor_service.h +++ b/zephyr-wallet/sensor_service.h @@ -1,6 +1,7 @@ #ifndef _SENSOR_SERVICE_H_ #define _SENSOR_SERVICE_H_ /* system includes */ +#include /* local includes */ @@ -8,6 +9,7 @@ extern "C" { #endif +void sensor_shell_register(); int get_sensor_data(int32_t *temperature, int32_t *humidity); #ifdef __cplusplus diff --git a/zephyr-wallet/shell_modules.c b/zephyr-wallet/shell_modules.c new file mode 100644 index 0000000..58d0ecc --- /dev/null +++ b/zephyr-wallet/shell_modules.c @@ -0,0 +1,25 @@ +/** +* @brief +* @file shell_modules.c +* @author J.H. +* @date 2018-11-29 +*/ + +/* system includes */ + +/* local includes */ +#include "shell_modules.h" +#include "web3_shell.h" +#include "sensor_service.h" +#include "upload.h" +#include "erc20_shell.h" +#include "sntp_shell.h" + +void wallet_register_shell_modules() +{ + web3_shell_register(); + sensor_shell_register(); + upload_shell_register(); + erc20_shell_register(); + sntp_shell_register(); +} diff --git a/zephyr-wallet/shell_modules.h b/zephyr-wallet/shell_modules.h new file mode 100644 index 0000000..94a7410 --- /dev/null +++ b/zephyr-wallet/shell_modules.h @@ -0,0 +1,18 @@ +#ifndef _SHELL_MODULES_H_ +#define _SHELL_MODULES_H_ +/* system includes */ +/* local includes */ + + +#ifdef __cplusplus +extern "C" { +#endif + +void wallet_register_shell_modules(); + +#ifdef __cplusplus +} +#endif + +#endif /* _SHELL_MODULES_H_ */ + diff --git a/zephyr-wallet/sntp_shell.c b/zephyr-wallet/sntp_shell.c new file mode 100644 index 0000000..d26a44b --- /dev/null +++ b/zephyr-wallet/sntp_shell.c @@ -0,0 +1,80 @@ +/** +* @brief +* @file sntp_shell.c +* @author J.H. +* @date 2018-11-29 +*/ + +/* system includes */ +#define LOG_MODULE_NAME sntp_shell +#include +#include +#include + +/* local includes */ + +#define SNTP_PORT 123 + + +#include +void resp_callback(struct sntp_ctx *ctx, + int status, + u64_t epoch_time, + void *user_data) +{ + struct timespec ts = { + .tv_sec = epoch_time, + .tv_nsec = 0 + }; + clock_settime(CLOCK_REALTIME, &ts); + struct k_sem *sync_sem = (struct k_sem *)user_data; + k_sem_give(sync_sem); +} + +static int shell_sntp_sync(const struct shell *shell, size_t argc, char *argv[]) +{ + struct sntp_ctx ctx; + int rv; + // semaphore to keep the app alive until the reply is received or timeouts + struct k_sem sync_sem; + k_sem_init(&sync_sem, 0, 1); + + /* ipv4 */ + rv = sntp_init(&ctx, + CONFIG_NET_CONFIG_PEER_IPV4_ADDR, + SNTP_PORT, + K_FOREVER); + if (rv < 0) { + shell_error(shell, "Failed to init sntp ctx: %d\n", rv); + goto end; + } + rv = sntp_request(&ctx, K_FOREVER, resp_callback, &sync_sem); + if (rv < 0) { + shell_warn(shell, "Failed to send sntp request: %d\n", rv); + goto end; + } + k_sem_take(&sync_sem, K_FOREVER); +end: + sntp_close(&ctx); + return 0; +} + +static int shell_sntp_time(const struct shell *shell, size_t argc, char *argv[]) +{ + ARG_UNUSED(argv); + ARG_UNUSED(argc); + struct timeval tv; + gettimeofday(&tv, NULL); + shell_print(shell, "%ld", tv.tv_sec); + return 0; +} + +SHELL_CREATE_STATIC_SUBCMD_SET(sub_sntp) { + SHELL_CMD(sync, NULL, "sync", shell_sntp_sync), + SHELL_CMD(time, NULL, "time", shell_sntp_time), + SHELL_SUBCMD_SET_END +}; +SHELL_CMD_REGISTER(sntp, &sub_sntp, "sntp utils", NULL); + +void sntp_shell_register() +{} diff --git a/zephyr-wallet/sntp_shell.h b/zephyr-wallet/sntp_shell.h new file mode 100644 index 0000000..293fb63 --- /dev/null +++ b/zephyr-wallet/sntp_shell.h @@ -0,0 +1,17 @@ +#ifndef _SNTP_SHELL_H_ +#define _SNTP_SHELL_H_ +/* system includes */ +/* local includes */ + + +#ifdef __cplusplus +extern "C" { +#endif +void sntp_shell_register(); + +#ifdef __cplusplus +} +#endif + +#endif /* _SNTP_SHELL_H_ */ + diff --git a/zephyr-wallet/upload.c b/zephyr-wallet/upload.c index 3d4a080..9772024 100644 --- a/zephyr-wallet/upload.c +++ b/zephyr-wallet/upload.c @@ -144,3 +144,5 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_upload) { SHELL_SUBCMD_SET_END }; SHELL_CMD_REGISTER(upload, &sub_upload, "http upload service", NULL); + +void upload_shell_register() {} diff --git a/zephyr-wallet/upload.h b/zephyr-wallet/upload.h index 0018176..31933d0 100644 --- a/zephyr-wallet/upload.h +++ b/zephyr-wallet/upload.h @@ -7,6 +7,7 @@ #ifdef __cplusplus extern "C" { #endif +void upload_shell_register(); #ifdef __cplusplus } diff --git a/zephyr-wallet/wallet.c b/zephyr-wallet/wallet.c index 5ccd6e2..1968833 100644 --- a/zephyr-wallet/wallet.c +++ b/zephyr-wallet/wallet.c @@ -9,14 +9,14 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-parameter" #include -#include -#include -#include #include #pragma GCC diagnostic pop +#include +#include /* local includes */ #include "wallet.h" +#include "helpers/hextobin.h" #include "zephyr-wallet/utils.h" #include "zephyr-wallet/web3_rpc.h" @@ -234,4 +234,3 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_wallet) { SHELL_SUBCMD_SET_END }; SHELL_CMD_REGISTER(wallet, &sub_wallet, "crypto eth", NULL); - diff --git a/zephyr-wallet/web3_shell.c b/zephyr-wallet/web3_shell.c index a07f8cd..1c22504 100644 --- a/zephyr-wallet/web3_shell.c +++ b/zephyr-wallet/web3_shell.c @@ -136,4 +136,6 @@ SHELL_CREATE_STATIC_SUBCMD_SET(sub_web3) { SHELL_CMD(eth_sendRawTransaction, NULL, "send a raw transaction", web3_shell_sendRawTransaction), SHELL_SUBCMD_SET_END }; -SHELL_CMD_REGISTER(web3, &sub_web3, "http upload service", NULL); +SHELL_CMD_REGISTER(web3, &sub_web3, "web3 utils", NULL); + +void web3_shell_register() {} diff --git a/zephyr-wallet/web3_shell.h b/zephyr-wallet/web3_shell.h index fde2f5c..ce4f9bf 100644 --- a/zephyr-wallet/web3_shell.h +++ b/zephyr-wallet/web3_shell.h @@ -7,6 +7,7 @@ #ifdef __cplusplus extern "C" { #endif +void web3_shell_register(); #ifdef __cplusplus }