1 /*
2  * Copyright (C) 2018-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef _GENIE_SERVICE_H_
6 #define _GENIE_SERVICE_H_
7 
8 #include "ulog/ulog.h"
9 
10 //#include <aos/aos.h>
11 //#include <soc.h>
12 #include <hal/hal.h>
13 #include <aos/hal/gpio.h>
14 
15 #include "core/inc/genie_event.h"
16 #include "core/inc/genie_cli.h"
17 #include "core/inc/genie_at.h"
18 #include "core/inc/genie_bin_cmds.h"
19 #include "core/inc/genie_storage.h"
20 #include "core/inc/genie_reset.h"
21 #include "core/inc/genie_triple.h"
22 #include "core/inc/genie_addr.h"
23 #include "core/inc/genie_version.h"
24 #ifdef CONFIG_GENIE_OTA
25 #include "sal/inc/genie_sal_ota.h"
26 #include "core/inc/genie_ais.h"
27 #include "core/inc/genie_ota.h" //Please keep genie_ais.h is upper of genie_ota.h because ota depend ais
28 #endif
29 #include "core/inc/genie_transport.h"
30 #include "core/inc/genie_vendor_model.h"
31 #include "core/inc/genie_provision.h"
32 #include "core/inc/genie_crypto.h"
33 
34 #ifdef CONFIG_PM_SLEEP
35 #include "core/inc/genie_lpm.h"
36 #include "genie_sal_lpm.h"
37 #endif
38 
39 #ifdef MESH_MODEL_VENDOR_TIMER
40 #include "core/inc/genie_time.h"
41 #endif
42 
43 #include "sal/inc/genie_sal_ble.h"
44 #include "sal/inc/genie_sal_uart.h"
45 
46 #include "core/inc/sig_models/sig_model.h"
47 #include "core/inc/genie_mesh.h"
48 
49 #define GENIE_SERVICE_TAG "Genie_service"
50 
51 #define GENIE_LOG_ERR(fmt, ...)  LOGE(GENIE_SERVICE_TAG, fmt, ##__VA_ARGS__)
52 #define GENIE_LOG_WARN(fmt, ...) LOGW(GENIE_SERVICE_TAG, fmt, ##__VA_ARGS__)
53 #define GENIE_LOG_INFO(fmt, ...) LOGI(GENIE_SERVICE_TAG, fmt, ##__VA_ARGS__)
54 #define GENIE_LOG_DBG(fmt, ...)  LOGD(GENIE_SERVICE_TAG, fmt, ##__VA_ARGS__)
55 
56 #define GENIE_GLP_SLEEP_TIME (1100) //unit:ms
57 #define GENIE_GLP_WAKEUP_TIME (60) //unit:ms
58 
59 #define GENIE_SERVICE_ERRCODE_USER_BASE (-0x100)
60 #define GENIE_SERVICE_ERRCODE_MESH_BASE (-0x200)
61 #define GENIE_SERVICE_ERRCODE_TRIPLE_BASE (-0x300)
62 
63 typedef enum _genie_service_errcode_s
64 {
65     GENIE_SERVICE_SUCCESS = 0,
66     GENIE_SERVICE_ERRCODE_USER_INPUT = GENIE_SERVICE_ERRCODE_USER_BASE - 1,
67     GENIE_SERVICE_ERRCODE_MESH_INIT = GENIE_SERVICE_ERRCODE_MESH_BASE - 1,
68     GENIE_SERVICE_ERRCODE_NO_TRIPLE = GENIE_SERVICE_ERRCODE_MESH_BASE - 2,
69 
70     GENIE_SERVICE_ERRCODE_TRIPLE_READ_FAIL = GENIE_SERVICE_ERRCODE_TRIPLE_BASE - 1,
71     GENIE_SERVICE_ERRCODE_TRIPLE_WRITE_FAIL = GENIE_SERVICE_ERRCODE_TRIPLE_BASE - 2,
72 } genie_service_errcode;
73 
74 typedef void (*user_event_cb)(genie_event_e event, void *p_arg);
75 
76 typedef struct _genie_service_ctx_s
77 {
78     struct bt_mesh_elem *p_mesh_elem;
79     unsigned char mesh_elem_counts;
80     user_event_cb event_cb;
81     uint32_t prov_timeout;
82 #ifdef CONFIG_PM_SLEEP
83     genie_lpm_conf_t lpm_conf;
84 #endif
85 } genie_service_ctx_t;
86 
87 /**
88  * @brief The initialization api for genie sdk. The application always
89  *        involks this api to initialize AIS/Mesh procedure for bussiness.
90  */
91 int genie_service_init(genie_service_ctx_t *p_ctx);
92 
93 genie_service_ctx_t *genie_service_get_context(void);
94 
95 #endif
96