1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 /**
5  * @file main.c
6  *
7  * This file includes the entry code of link sdk related demo
8  *
9  */
10 
11 #include <string.h>
12 #include <stdio.h>
13 #include <aos/kernel.h>
14 #include "ulog/ulog.h"
15 #include "netmgr.h"
16 #include <uservice/uservice.h>
17 #include <uservice/eventid.h>
18 
19 extern int demo_main(int argc, char *argv[]);
20 
21 static int _ip_got_finished = 0;
22 
entry_func(void * data)23 static void entry_func(void *data)
24 {
25     demo_main(0 , NULL);
26 }
wifi_event_cb(uint32_t event_id,const void * param,void * context)27 static void wifi_event_cb(uint32_t event_id, const void *param, void *context)
28 {
29     aos_task_t task;
30     aos_status_t ret;
31     if (event_id != EVENT_NETMGR_DHCP_SUCCESS)
32         return;
33 
34     if (_ip_got_finished != 0)
35         return;
36 
37     _ip_got_finished = 1;
38     ret = aos_task_create(&task, "linksdk_gateway_demo", entry_func,
39                           NULL, NULL, 6048, AOS_DEFAULT_APP_PRI, AOS_TASK_AUTORUN);
40     if (ret < 0) {
41         printf("create linksdk gateway demo task failed, ret = %ld \r\n", ret);
42     }
43 }
44 
application_start(int argc,char * argv[])45 int application_start(int argc, char *argv[])
46 {
47     aos_set_log_level(AOS_LL_DEBUG);
48     event_service_init(NULL);
49 
50     netmgr_service_init(NULL);
51     netmgr_set_auto_reconnect(NULL, true);
52     netmgr_wifi_set_auto_save_ap(true);
53 
54     event_subscribe(EVENT_NETMGR_DHCP_SUCCESS, wifi_event_cb, NULL);
55 
56     while (1)
57         aos_msleep(1000);
58 
59     return 0;
60 }
61