-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from pcppcp/sntp
Add sntp sync shell command
- Loading branch information
Showing
18 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ CONFIG_LWM2M_IPSO_SUPPORT=y | |
CONFIG_LWM2M_IPSO_TEMP_SENSOR=y | ||
|
||
CONFIG_POSIX_API=y | ||
|
||
CONFIG_SNTP=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
void erc20_shell_register(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <net/sntp.h> | ||
#include <shell/shell.h> | ||
#include <posix/time.h> | ||
|
||
/* local includes */ | ||
|
||
#define SNTP_PORT 123 | ||
|
||
|
||
#include <misc/printk.h> | ||
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() | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
void upload_shell_register(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
void web3_shell_register(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
|