BugID:17642035:make linkkit gateway example can be exit after certain time
@@ -357,16 +357,32 @@ void *user_dispatch_yield(void *args)
return NULL;
}
+static int max_running_seconds = 0;
int linkkit_main(void *paras)
{
-#if !defined(WIFI_PROVISION_ENABLED) || !defined(BUILD_AOS)
- set_iotx_info();
-#endif
int res = 0;
- uint64_t time_prev_sec = 0, time_now_sec = 0;
+ uint64_t time_prev_sec = 0, time_now_sec = 0, time_begin_sec = 0;
user_example_ctx_t *user_example_ctx = user_example_get_ctx();
iotx_linkkit_dev_meta_info_t master_meta_info;
+#if defined(__UBUNTU_SDK_DEMO__)
+ int argc = ((app_main_paras_t *)paras)->argc;
+ char **argv = ((app_main_paras_t *)paras)->argv;
+
+ if (argc > 1) {
+ int tmp = atoi(argv[1]);
+
+ if (tmp >= 60) {
+ max_running_seconds = tmp;
+ EXAMPLE_TRACE("set [max_running_seconds] = %d seconds\n", max_running_seconds);
+ }
+ }
+#endif
+
+#if !defined(WIFI_PROVISION_ENABLED) || !defined(BUILD_AOS)
+ set_iotx_info();
+#endif
+
memset(user_example_ctx, 0, sizeof(user_example_ctx_t));
user_example_ctx->subdev_index = -1;
@@ -423,6 +439,7 @@ int linkkit_main(void *paras)
return -1;
}
+ time_begin_sec = user_update_sec();
while (1) {
HAL_SleepMs(200);
@@ -430,6 +447,10 @@ int linkkit_main(void *paras)
if (time_prev_sec == time_now_sec) {
continue;
}
+ if (max_running_seconds && (time_now_sec - time_begin_sec > max_running_seconds)) {
+ EXAMPLE_TRACE("Example Run for Over %d Seconds, Break Loop!\n", max_running_seconds);
+ break;
+ }
/* Add subdev */
if (user_example_ctx->master_initialized && user_example_ctx->subdev_index >= 0) {
