TuyaOS
gw_intf.h
浏览该文件的文档.
1
10#ifndef _GW_INTF_H
11#define _GW_INTF_H
12
13#include "tuya_cloud_types.h"
14#include "tuya_cloud_com_defs.h"
15#include "tuya_base_utilities.h"
17#include "tuya_error_code.h"
18#include "tal_mutex.h"
19
20#if defined(ENABLE_WIFI_SERVICE) && (ENABLE_WIFI_SERVICE==1)
22#include "tal_wifi.h"
23#endif
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#define SERIAL_NO_STR_LEN 32 // max string length of sn
30#define GET_ACCESS_TOKEN_INTERVAL (300 * 1000) //5min
31
35typedef struct {
36 CHAR_T uuid[GW_UUID_LEN + 1]; //uuid
37 CHAR_T auth_key[AUTH_KEY_LEN + 1];
38 CHAR_T psk_key[PSK_KEY_LEN + 1];
40
44typedef struct {
46 CHAR_T uuid[GW_UUID_LEN + 1];
48 CHAR_T psk_key[PSK_KEY_LEN + 1];
50 CHAR_T auth_key[AUTH_KEY_LEN + 1];
51
52#if defined(ENABLE_WIFI_SERVICE) && (ENABLE_WIFI_SERVICE==1)
54 CHAR_T ap_ssid[WIFI_SSID_LEN + 1];
56 CHAR_T ap_passwd[WIFI_PASSWD_LEN + 1];
57
58#endif
59#if (defined(ENABLE_WIFI_SERVICE) && (ENABLE_WIFI_SERVICE==1)) || (defined(GW_SUPPORT_COUNTRY_CODE) && (GW_SUPPORT_COUNTRY_CODE==1))
61 CHAR_T country_code[COUNTRY_CODE_LEN];
62#endif
63#if defined(GPRS_GW) && (GPRS_GW==1)
65 CHAR_T imei[TUYA_IMEI_LEN + 1];
67 CHAR_T sn[TUYA_SN_LEN + 1];
68#endif
70 BOOL_T prod_test;
71#if defined(ENABLE_BT_SERVICE) && (ENABLE_BT_SERVICE == 1)
73 CHAR_T bt_mac[BT_MAC_LEN + 1];
75 CHAR_T bt_hid[BT_HID_LEN + 1];
76#endif
78 CHAR_T fac_pin[20 + 1];
80 CHAR_T psk30_key[PSK_KEY_LEN + 1];
82
83// gw register status
84typedef BYTE_T GW_WORK_STAT_T;
85#define UNREGISTERED 0 // unregistered
86#define REGISTERED 1 // registered & activate start
87#define ACTIVATED 2 // already active
88#define PROXY_ACTIVING (3)//start ble active
89#define PROXY_ACTIVATED (4) // ble actived
90
94typedef struct {
95#if defined(ENABLE_WIFI_SERVICE) && (ENABLE_WIFI_SERVICE==1)
97 GW_WF_NWC_STAT_T nc_tp;
99 GW_WF_MD_T md;
101 CHAR_T ssid[WIFI_SSID_LEN + 1];
103 CHAR_T passwd[WIFI_PASSWD_LEN + 1];
104#endif
106 TY_DNS_PRIO_T dns_prio; // not saved in kv to save flash life-cycle
108 GW_WORK_STAT_T stat;
110 CHAR_T token[TOKEN_LEN + 1];
112 CHAR_T region[REGION_LEN + 1];
114 CHAR_T regist_key[REGIST_KEY_LEN + 1];
118
122typedef struct {
124 GW_ABI abi;
126 CHAR_T id[GW_ID_LEN + 1];
128 CHAR_T sw_ver[SW_VER_LEN + 1];
130 CHAR_T bs_ver[SW_VER_LEN + 1];
132 CHAR_T prtl_ver[SW_VER_LEN + 1];
134 CHAR_T lan_prtl_ver[SW_VER_LEN + 1];
136 CHAR_T cad_ver[SW_VER_LEN + 1];
138 CHAR_T cd_ver[SW_VER_LEN + 1];
140 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
142 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
143
145 CHAR_T dev_sw_ver[SW_VER_LEN + 1];
147 CHAR_T schema_id[SCHEMA_ID_LEN + 1];
149 DEV_TYPE_T tp;
150
152 BYTE_T attr_num;
154 GW_ATTACH_ATTR_T attr[GW_ATTACH_ATTR_LMT];
155
157 BOOL_T sync;
159
163typedef struct {
165 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
167 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
169
173typedef struct {
175 CHAR_T key[SEC_KEY_LEN + 1];
177 CHAR_T local_key[LOCAL_KEY_LEN + 1];
179 CHAR_T http_url[HTTP_URL_LMT + 1];
181 CHAR_T http_ip[HTTP_URL_LMT + 1];
183 CHAR_T https_url[HTTP_URL_LMT + 1];
185 CHAR_T https_ip[HTTP_URL_LMT + 1];
187 CHAR_T httpsPSK_url[HTTP_URL_LMT + 1];
189 CHAR_T httpsPSK_ip[HTTP_URL_LMT + 1];
190
192 CHAR_T mq_psk_url[MQ_URL_LMT + 1];
194 CHAR_T mq_psk_ip[MQ_URL_LMT + 1];
196 CHAR_T mq_tls_url[MQ_URL_LMT + 1];
198 CHAR_T mq_tls_ip[MQ_URL_LMT + 1];
200 CHAR_T mq_proto_url[MQ_URL_LMT + 1];
202 CHAR_T mq_proto_ip[MQ_URL_LMT + 1];
204 CHAR_T ai_speech_url[HTTP_URL_LMT + 1];
206 CHAR_T ai_speech_ip[HTTP_URL_LMT + 1];
208 CHAR_T lowpower_url[MQ_URL_LMT + 1];
210 CHAR_T lowpower_ip[MQ_URL_LMT + 1];
211
213 CHAR_T time_zone[TIME_ZONE_LEN + 1];
215 CHAR_T summer_time_zone[SUMMER_TM_ZONE_LEN + 1];
216
218 CHAR_T wx_app_id[WXAPPID_LEN + 1];
220 CHAR_T wx_uuid[WXUUID_LEN + 1];
223
227
231#define CLOUD_CAPABILITY_WIFI 0 // wifi
232#define CLOUD_CAPABILITY_CABLE 1 // cable
233#define CLOUD_CAPABILITY_GPRS 2 // gprs
234#define CLOUD_CAPABILITY_NBIOT 3 // nb-iot
235#define CLOUD_CAPABILITY_BLUETOOTH 10 // bt
236#define CLOUD_CAPABILITY_BLEMESH 11 // blemesh
237#define CLOUD_CAPABILITY_ZIGBEE 12 // zigbee
238#define CLOUD_CAPABILITY_INFRARED 13 // infrared
239#define CLOUD_CAPABILITY_SUBPIECES 14 // subpieces
240#define CLOUD_CAPABILITY_SIGMESH 15 // sigmesh
241#define CLOUD_CAPABILITY_MCU 16 // mcu
242
246typedef BYTE_T DP_PV_STAT_E;
247#define INVALID 0 // dp is invalid
248#define VALID_LC 1 // dp is valid in local
249#define VALID_ULING 2 // dp is uploading to cloud
250#define VALID_CLOUD 3 // dp is synced with cloud
251
255typedef BYTE_T DP_ID_REPT_TYPE_E;
256#define DP_ID_REPT_RULE_ROUTE (0x1) //dp report rule from route
257
261typedef struct {
262 UINT_T period; // long filter period
263 UINT_T limit; // dpcount limit in long filter period
264 UINT_T rept_cnt; // report counter
265 TIME_S fir_rept_timestamp;//the first report success timestamp
267
271typedef struct {
272 DP_REPT_FLOW_CTRL_UNIT filter_short;//flow control rules for short period
273 DP_REPT_FLOW_CTRL_UNIT filter_long;//flow control rules for long period
275
276#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
280typedef struct {
282 TIME_S cur_set_time;
284 UINT_T cur_set_rept_num;
285} DP_CUR_SET_REPT_CNTL_S;
286#endif
287
291typedef struct {
298 BYTE_T uling_cnt;
305#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
307 TIME_S rept_new_time;
309 DP_PROP_VALUE_U cur_set;
311 DP_CUR_SET_REPT_CNTL_S cur_set_rept;
313 BYTE_T is_set_flag;//是否要检查当前下发的值与实际状态是否一样
314#endif
315} DP_CNTL_S;
316
317
321typedef struct {
325
326
327#define GRP_LMT 64 // group limit
328#define SCENE_LMT 64 // scene limit
329#define LOG_PHAT_MAX_LEN 64
330
334typedef struct {
336 CHAR_T gid[GRP_ID_LEN + 1];
337} GRP_REC_S;
338
342typedef struct {
344 CHAR_T s_id[SCENE_ID_LEN + 1];
346 CHAR_T g_id[GRP_ID_LEN + 1];
348
352typedef struct {
354 GRP_REC_S g_rec[GRP_LMT];
356 BYTE_T cnt;
357} GRP_MAG_S;
358
362typedef struct {
364 SCENE_REC_S s_rec[SCENE_LMT];
366 BYTE_T cnt;
368
373typedef struct {
379
383typedef struct dev_cntl_n_s {
385 CHAR_T id[DEV_ID_LEN + 1];
388#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
390 BYTE_T reliable_transfer_flag;//1表示要可靠性检测
391#endif
392
394 MUTEX_HANDLE dp_mutex;//dp本地缓存互斥锁
396 BYTE_T dp_num;
400
408typedef DEV_CNTL_N_S * (*subdev_dev_cntl_get_cb)(IN CHAR_T *id);
409
413typedef struct {
415 CHAR_T *serial_no;
419 GW_EXT_STAT_T ext_stat;
420
422 BOOL_T is_oem;
424 BOOL_T is_init;
426 BOOL_T is_stride;
429
438
441
444
449} GW_CNTL_S;
450
451typedef BYTE_T GW_RESET_TP_T;
452#define GRT_LOCAL 0 // reset is triggerd by device itself
453#define GRT_REMOTE 1 // reset is triggerd by cloud/app
454
458typedef struct {
460 GW_RESET_TP_T gw_rst_tp;
462 BOOL_T lazy;
463} GW_RESET_S;
464
468typedef struct {
470 GW_RESET_TP_T tp;
472 CHAR_T dev_id[DEV_ID_LEN + 1];
474
478typedef enum {
488
495
502
511
520DP_CNTL_S *get_dev_dp_cntl(IN CHAR_T *id, IN CONST BYTE_T dpid);
521
528
540CHAR_T *tuya_get_schema(VOID);
541
553OPERATE_RET tuya_get_dp_info(IN CONST CHAR_T *dev_id, INT_T* dp_num, DP_CNTL_S** dp_info);
554
563OPERATE_RET gw_get_gpd_type(IN CONST UINT_T type, OUT GW_PERMIT_DEV_TP_T *gpd);
564
572OPERATE_RET gw_set_ext_attribute(UINT_T attr);
573
580
590OPERATE_RET gw_create_dev_cntl(IN CONST CHAR_T * dev_id, IN CONST CHAR_T * sch_json, OUT DEV_CNTL_N_S **dev_cnt_out);
591
599OPERATE_RET gw_destroy_dev_cntl(IN DEV_CNTL_N_S *dev_cnt);
600
609OPERATE_RET gw_dup_dev_cntl(IN DEV_CNTL_N_S *dev_cnt_src, OUT DEV_CNTL_N_S **dev_cnt_out);
610
619
625OPERATE_RET gw_fast_unactive(IN CONST GW_RESET_S *rst_t);
626
634OPERATE_RET gw_unregister(IN CONST GW_RESET_S *rst_t);
635
643OPERATE_RET gw_unactive(IN CONST GW_RESET_S *rst_t);
644
645#ifdef __cplusplus
646}
647#endif
648
649#include "tuya_devos_utils.h"
650
651#endif
652
OPERATE_RET gw_unregister(IN CONST GW_RESET_S *rst_t)
Reset device to unregister state
OPERATE_RET gw_dup_dev_cntl(IN DEV_CNTL_N_S *dev_cnt_src, OUT DEV_CNTL_N_S **dev_cnt_out)
Duplicate device cntl
OPERATE_RET gw_destroy_dev_cntl(IN DEV_CNTL_N_S *dev_cnt)
Destroy device cntl instance
DEV_CNTL_N_S * get_dev_cntl(IN CHAR_T *id)
Get device cntl
OPERATE_RET gw_create_dev_cntl(IN CONST CHAR_T *dev_id, IN CONST CHAR_T *sch_json, OUT DEV_CNTL_N_S **dev_cnt_out)
Create device cntl instance
TUYA_COUNTRY_CODE_E
Definition Wi-Fi country code
Definition: gw_intf.h:478
@ TY_COUNTRY_CODE_JP
Definition: gw_intf.h:484
@ TY_COUNTRY_CODE_US
Definition: gw_intf.h:482
@ TY_COUNTRY_CODE_EU
Definition: gw_intf.h:486
@ TY_COUNTRY_CODE_CN
Definition: gw_intf.h:480
BYTE_T DP_PV_STAT_E
Definiton of DP status
Definition: gw_intf.h:246
CHAR_T * tuya_get_schema(VOID)
Get device schema info
GW_DESC_IF_S * get_gw_dev_if(VOID)
Get gateway description
OPERATE_RET gw_unactive(IN CONST GW_RESET_S *rst_t)
Reset device to register state
DEV_CNTL_N_S *(* subdev_dev_cntl_get_cb)(IN CHAR_T *id)
Handler to get sub-device control info
Definition: gw_intf.h:408
OPERATE_RET gw_subdev_dev_cntl_get_register_cb(IN subdev_dev_cntl_get_cb cb)
Register handler to get sub-device cntl
UINT_T gw_get_ext_attribute(VOID)
Get device extension attribute
OPERATE_RET gw_fast_unactive(IN CONST GW_RESET_S *rst_t)
Faset reset device to register state
OPERATE_RET gw_get_gpd_type(IN CONST UINT_T type, OUT GW_PERMIT_DEV_TP_T *gpd)
Get device ota channel
DP_CNTL_S * get_dev_dp_cntl(IN CHAR_T *id, IN CONST BYTE_T dpid)
Get DP cntl
BYTE_T DP_ID_REPT_TYPE_E
Definition of dp id report rule
Definition: gw_intf.h:255
OPERATE_RET gw_set_ext_attribute(UINT_T attr)
Set device extension attribute
DEV_CNTL_N_S * get_gw_dev_cntl(VOID)
Get gateway device cntl
struct dev_cntl_n_s DEV_CNTL_N_S
Definition of device control info
OPERATE_RET tuya_get_dp_info(IN CONST CHAR_T *dev_id, INT_T *dp_num, DP_CNTL_S **dp_info)
Get device dp info
GW_CNTL_S * get_gw_cntl(VOID)
Get gateway cntl
CHAR_T * http_url(VOID)
Retrieve active HTTP url of TUYA cloud
Definition of device actv attribute
Definition: gw_intf.h:373
BOOL_T preprocess
Definition: gw_intf.h:377
BOOL_T attach_dp_if
Definition: gw_intf.h:375
Definition of sub-device reset info
Definition: gw_intf.h:468
GW_RESET_TP_T tp
Definition: gw_intf.h:470
Definition of dp control
Definition: gw_intf.h:291
DP_DESC_IF_S dp_desc
Definition: gw_intf.h:293
UINT_T ble_send_sn
Definition: gw_intf.h:304
DP_PROP_VALUE_U prop
Definition: gw_intf.h:295
DP_PV_STAT_E pv_stat
Definition: gw_intf.h:297
DP_REPT_FLOW_CTRL rept_flow_ctrl
Definition: gw_intf.h:300
UINT_T time_stamp
Definition: gw_intf.h:302
Definition of dp description
Definition: tuya_cloud_com_defs.h:392
Definition of dp report flow control unit
Definition: gw_intf.h:261
Definition of dp report flow control
Definition: gw_intf.h:271
Definition of group management
Definition: gw_intf.h:352
BYTE_T cnt
Definition: gw_intf.h:356
Definition of group info
Definition: gw_intf.h:334
Definition of active info
Definition: gw_intf.h:173
BYTE_T dynamic_tls_mode
Definition: gw_intf.h:225
INT_T cloud_capability
Definition: gw_intf.h:222
Definition of attach moudule attribute
Definition: tuya_cloud_com_defs.h:175
Definition gw BASE information
Definition: gw_intf.h:44
BOOL_T prod_test
Definition: gw_intf.h:70
Definition of core device management
Definition: gw_intf.h:413
BOOL_T is_init
Definition: gw_intf.h:424
UINT_T ext_attribute
Definition: gw_intf.h:417
GW_BASE_IF_S gw_base
Definition: gw_intf.h:431
BOOL_T is_oem
Definition: gw_intf.h:422
CHAR_T * serial_no
Definition: gw_intf.h:415
subdev_dev_cntl_get_cb subdev_dev_get_cb
Definition: gw_intf.h:448
GW_DESC_IF_S gw_if
Definition: gw_intf.h:435
TIME_MS data_update_time
Definition: gw_intf.h:446
GW_EXT_STAT_T ext_stat
Definition: gw_intf.h:419
DEV_CNTL_N_S * dev_cntl
Definition: gw_intf.h:440
TY_IOT_CBS_S cbs
Definition: gw_intf.h:443
GW_WORK_STAT_MAG_S gw_wsm
Definition: gw_intf.h:433
GW_ACTV_IF_S gw_actv
Definition: gw_intf.h:437
BOOL_T is_need_recovery
Definition: gw_intf.h:428
BOOL_T is_stride
Definition: gw_intf.h:426
Definition of device description info
Definition: gw_intf.h:122
BYTE_T attr_num
Definition: gw_intf.h:152
BOOL_T sync
Definition: gw_intf.h:157
GW_ABI abi
Definition: gw_intf.h:124
DEV_TYPE_T tp
Definition: gw_intf.h:149
Definition of gateway device reset info
Definition: gw_intf.h:458
BOOL_T lazy
Definition: gw_intf.h:462
GW_RESET_TP_T gw_rst_tp
Definition: gw_intf.h:460
Definition of stride update info
Definition: gw_intf.h:163
Definition of device work state
Definition: gw_intf.h:94
GW_WORK_STAT_T stat
Definition: gw_intf.h:108
TY_DNS_PRIO_T dns_prio
Definition: gw_intf.h:106
BOOL_T is_psk30_cfg
Definition: gw_intf.h:116
Definition of scene management
Definition: gw_intf.h:362
BYTE_T cnt
Definition: gw_intf.h:366
Definition of scene info
Definition: gw_intf.h:342
Definition of schema other attribute
Definition: gw_intf.h:321
BOOL_T preprocess
Definition: gw_intf.h:323
auth info for ext module
Definition: gw_intf.h:35
Definition of gateway callback funtions
Definition: tuya_cloud_com_defs.h:763
Definition of device control info
Definition: gw_intf.h:383
DP_CNTL_S dp[0]
Definition: gw_intf.h:398
MUTEX_HANDLE dp_mutex
Definition: gw_intf.h:394
BYTE_T dp_num
Definition: gw_intf.h:396
DEV_ACTV_ATTR_S attr
Definition: gw_intf.h:387
Common process - adapter the mutex api provide by OS
Common process
tuya utilities module
Common definitions of TUYA cloud
Utilities of DevOS
UINT_T TY_DNS_PRIO_T
DNS priority
Definition: uni_network.h:48
Definition of dp prop value
Definition: tuya_cloud_com_defs.h:344