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_os_adapter.h"
16#include "tuya_base_utilities.h"
18#include "tuya_error_code.h"
19
20#if defined(WIFI_GW) && (WIFI_GW==1)
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define SERIAL_NO_STR_LEN 32 // max string length of sn
29#define GET_ACCESS_TOKEN_INTERVAL (300 * 1000) //5min
30
34typedef struct {
36 CHAR_T uuid[GW_UUID_LEN + 1];
38 CHAR_T psk_key[PSK_KEY_LEN + 1];
40 CHAR_T auth_key[AUTH_KEY_LEN + 1];
41
42#if defined(WIFI_GW) && (WIFI_GW==1)
44 CHAR_T ap_ssid[WIFI_SSID_LEN + 1];
46 CHAR_T ap_passwd[WIFI_PASSWD_LEN + 1];
47
48#endif
49#if (defined(WIFI_GW) && (WIFI_GW==1)) || (defined(GW_SUPPORT_COUNTRY_CODE) && (GW_SUPPORT_COUNTRY_CODE==1))
51 CHAR_T country_code[COUNTRY_CODE_LEN];
52#endif
53#if defined(GPRS_GW) && (GPRS_GW==1)
55 CHAR_T imei[TUYA_IMEI_LEN + 1];
57 CHAR_T sn[TUYA_SN_LEN + 1];
58#endif
60 BOOL_T prod_test;
61#if defined(TY_BT_MOD) && TY_BT_MOD == 1
63 CHAR_T bt_mac[BT_MAC_LEN + 1];
65 CHAR_T bt_hid[BT_HID_LEN + 1];
66#endif
68 CHAR_T fac_pin[20 + 1];
70
71// gw register status
72typedef BYTE_T GW_WORK_STAT_T;
73#define UNREGISTERED 0 // unregistered
74#define REGISTERED 1 // registered & activate start
75#define ACTIVATED 2 // already active
76#define BLE_ACTIVING (3)//start ble active
77#define BLE_ACTIVATED (4) // ble actived
78
82typedef struct {
83#if defined(WIFI_GW) && (WIFI_GW==1)
85 GW_WF_NWC_STAT_T nc_tp;
87 GW_WF_MD_T md;
89 CHAR_T ssid[WIFI_SSID_LEN + 1];
91 CHAR_T passwd[WIFI_PASSWD_LEN + 1];
92#endif
94 TY_DNS_PRIO_T dns_prio; // not saved in kv to save flash life-cycle
96 GW_WORK_STAT_T stat;
98 CHAR_T token[TOKEN_LEN + 1];
100 CHAR_T region[REGION_LEN + 1];
102 CHAR_T regist_key[REGIST_KEY_LEN + 1];
104
108typedef struct {
110 GW_ABI abi;
112 CHAR_T id[GW_ID_LEN + 1];
114 CHAR_T sw_ver[SW_VER_LEN + 1];
116 CHAR_T bs_ver[SW_VER_LEN + 1];
118 CHAR_T prtl_ver[SW_VER_LEN + 1];
120 CHAR_T lan_prtl_ver[SW_VER_LEN + 1];
122 CHAR_T cad_ver[SW_VER_LEN + 1];
124 CHAR_T cd_ver[SW_VER_LEN + 1];
126 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
128 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
129
131 CHAR_T dev_sw_ver[SW_VER_LEN + 1];
133 CHAR_T schema_id[SCHEMA_ID_LEN + 1];
135 DEV_TYPE_T tp;
136
138 BYTE_T attr_num;
140 GW_ATTACH_ATTR_T attr[GW_ATTACH_ATTR_LMT];
141
143 BOOL_T sync;
145
149typedef struct {
151 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
153 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
155
159typedef struct {
161 CHAR_T key[SEC_KEY_LEN + 1];
163 CHAR_T local_key[LOCAL_KEY_LEN + 1];
165 CHAR_T psk21_key[TUYA_PSK21_LEN + 1];
167 CHAR_T http_url[HTTP_URL_LMT + 1];
169 CHAR_T http_ip[HTTP_URL_LMT + 1];
171 CHAR_T https_url[HTTP_URL_LMT + 1];
173 CHAR_T https_ip[HTTP_URL_LMT + 1];
175 CHAR_T httpsPSK_url[HTTP_URL_LMT + 1];
177 CHAR_T httpsPSK_ip[HTTP_URL_LMT + 1];
178
180 CHAR_T mq_psk_url[MQ_URL_LMT + 1];
182 CHAR_T mq_psk_ip[MQ_URL_LMT + 1];
184 CHAR_T mq_tls_url[MQ_URL_LMT + 1];
186 CHAR_T mq_tls_ip[MQ_URL_LMT + 1];
188 CHAR_T mq_proto_url[MQ_URL_LMT + 1];
190 CHAR_T mq_proto_ip[MQ_URL_LMT + 1];
192 CHAR_T ai_speech_url[HTTP_URL_LMT + 1];
194 CHAR_T ai_speech_ip[HTTP_URL_LMT + 1];
196 CHAR_T lowpower_url[MQ_URL_LMT + 1];
198 CHAR_T lowpower_ip[MQ_URL_LMT + 1];
199
201 CHAR_T time_zone[TIME_ZONE_LEN + 1];
203 CHAR_T summer_time_zone[SUMMER_TM_ZONE_LEN + 1];
204
206 CHAR_T wx_app_id[WXAPPID_LEN + 1];
208 CHAR_T wx_uuid[WXUUID_LEN + 1];
211
215
219#define CLOUD_CAPABILITY_WIFI 0 // wifi
220#define CLOUD_CAPABILITY_CABLE 1 // cable
221#define CLOUD_CAPABILITY_GPRS 2 // gprs
222#define CLOUD_CAPABILITY_NBIOT 3 // nb-iot
223#define CLOUD_CAPABILITY_BLUETOOTH 10 // bt
224#define CLOUD_CAPABILITY_BLEMESH 11 // blemesh
225#define CLOUD_CAPABILITY_ZIGBEE 12 // zigbee
226#define CLOUD_CAPABILITY_INFRARED 13 // infrared
227#define CLOUD_CAPABILITY_SUBPIECES 14 // subpieces
228#define CLOUD_CAPABILITY_SIGMESH 15 // sigmesh
229#define CLOUD_CAPABILITY_MCU 16 // mcu
230
234typedef BYTE_T DP_PV_STAT_E;
235#define INVALID 0 // dp is invalid
236#define VALID_LC 1 // dp is valid in local
237#define VALID_ULING 2 // dp is uploading to cloud
238#define VALID_CLOUD 3 // dp is synced with cloud
239
243typedef BYTE_T DP_ID_REPT_TYPE_E;
244#define DP_ID_REPT_RULE_ROUTE (0x1) //dp report rule from route
245
249typedef struct {
250 UINT_T period; // long filter period
251 UINT_T limit; // dpcount limit in long filter period
252 UINT_T rept_cnt; // report counter
253 TIME_S fir_rept_timestamp;//the first report success timestamp
255
259typedef struct {
260 DP_REPT_FLOW_CTRL_UNIT filter_short;//flow control rules for short period
261 DP_REPT_FLOW_CTRL_UNIT filter_long;//flow control rules for long period
263
264#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
268typedef struct {
270 TIME_S cur_set_time;
272 UINT_T cur_set_rept_num;
273} DP_CUR_SET_REPT_CNTL_S;
274#endif
275
279typedef struct {
286 BYTE_T uling_cnt;
289#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
291 TIME_S rept_new_time;
293 DP_PROP_VALUE_U cur_set;
295 DP_CUR_SET_REPT_CNTL_S cur_set_rept;
297 BYTE_T is_set_flag;//是否要检查当前下发的值与实际状态是否一样
298#endif
299} DP_CNTL_S;
300
301
305typedef struct {
309
310
311#define GRP_LMT 64 // group limit
312#define SCENE_LMT 64 // scene limit
313#define LOG_PHAT_MAX_LEN 64
314
318typedef struct {
320 CHAR_T gid[GRP_ID_LEN + 1];
321} GRP_REC_S;
322
326typedef struct {
328 CHAR_T s_id[SCENE_ID_LEN + 1];
330 CHAR_T g_id[GRP_ID_LEN + 1];
332
336typedef struct {
338 GRP_REC_S g_rec[GRP_LMT];
340 BYTE_T cnt;
341} GRP_MAG_S;
342
346typedef struct {
348 SCENE_REC_S s_rec[SCENE_LMT];
350 BYTE_T cnt;
352
357typedef struct {
363
367typedef struct dev_cntl_n_s {
369 CHAR_T id[DEV_ID_LEN + 1];
372#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
374 BYTE_T reliable_transfer_flag;//1表示要可靠性检测
375#endif
376
378 MUTEX_HANDLE dp_mutex;//dp本地缓存互斥锁
380 BYTE_T dp_num;
384
392typedef DEV_CNTL_N_S * (*subdev_dev_cntl_get_cb)(IN CHAR_T *id);
393
397typedef struct {
399 CHAR_T *serial_no;
403 GW_EXT_STAT_T ext_stat;
404
406 BOOL_T is_oem;
408 BOOL_T is_init;
410 BOOL_T is_stride;
413
422
425
428
433} GW_CNTL_S;
434
435typedef BYTE_T GW_RESET_TP_T;
436#define GRT_LOCAL 0 // reset is triggerd by device itself
437#define GRT_REMOTE 1 // reset is triggerd by cloud/app
438
442typedef struct {
444 GW_RESET_TP_T gw_rst_tp;
446 BOOL_T lazy;
447} GW_RESET_S;
448
452typedef struct {
454 GW_RESET_TP_T tp;
456 CHAR_T dev_id[DEV_ID_LEN + 1];
458
462typedef enum {
472
479
486
495
504DP_CNTL_S *get_dev_dp_cntl(IN CHAR_T *id, IN CONST BYTE_T dpid);
505
512
524CHAR_T *tuya_get_schema(VOID);
525
537OPERATE_RET tuya_get_dp_info(IN CONST CHAR_T *dev_id, INT_T* dp_num, DP_CNTL_S** dp_info);
538
547OPERATE_RET gw_get_gpd_type(IN CONST UINT_T type, OUT GW_PERMIT_DEV_TP_T *gpd);
548
556OPERATE_RET gw_set_ext_attribute(UINT_T attr);
557
564
574OPERATE_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);
575
583OPERATE_RET gw_destroy_dev_cntl(IN DEV_CNTL_N_S *dev_cnt);
584
593OPERATE_RET gw_dup_dev_cntl(IN DEV_CNTL_N_S *dev_cnt_src, OUT DEV_CNTL_N_S **dev_cnt_out);
594
603
609OPERATE_RET gw_fast_unactive(IN CONST GW_RESET_S *rst_t);
610
618OPERATE_RET gw_unregister(IN CONST GW_RESET_S *rst_t);
619
627OPERATE_RET gw_unactive(IN CONST GW_RESET_S *rst_t);
628
636OPERATE_RET gw_get_last_reset_region(INOUT CONST CHAR_T *region);
637
638#ifdef __cplusplus
639}
640#endif
641
642#include "tuya_devos_utils.h"
643
644#endif
645
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:462
@ TY_COUNTRY_CODE_JP
Definition: gw_intf.h:468
@ TY_COUNTRY_CODE_US
Definition: gw_intf.h:466
@ TY_COUNTRY_CODE_EU
Definition: gw_intf.h:470
@ TY_COUNTRY_CODE_CN
Definition: gw_intf.h:464
BYTE_T DP_PV_STAT_E
Definiton of DP status
Definition: gw_intf.h:234
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:392
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
OPERATE_RET gw_get_last_reset_region(INOUT CONST CHAR_T *region)
Get last reset region
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:243
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:357
BOOL_T preprocess
Definition: gw_intf.h:361
BOOL_T attach_dp_if
Definition: gw_intf.h:359
Definition of sub-device reset info
Definition: gw_intf.h:452
GW_RESET_TP_T tp
Definition: gw_intf.h:454
Definition of dp control
Definition: gw_intf.h:279
DP_DESC_IF_S dp_desc
Definition: gw_intf.h:281
DP_PROP_VALUE_U prop
Definition: gw_intf.h:283
DP_PV_STAT_E pv_stat
Definition: gw_intf.h:285
DP_REPT_FLOW_CTRL rept_flow_ctrl
Definition: gw_intf.h:288
Definition of dp description
Definition: tuya_cloud_com_defs.h:390
Definition of dp report flow control unit
Definition: gw_intf.h:249
Definition of dp report flow control
Definition: gw_intf.h:259
Definition of group management
Definition: gw_intf.h:336
BYTE_T cnt
Definition: gw_intf.h:340
Definition of group info
Definition: gw_intf.h:318
Definition of active info
Definition: gw_intf.h:159
BYTE_T dynamic_tls_mode
Definition: gw_intf.h:213
INT_T cloud_capability
Definition: gw_intf.h:210
Definition of attach moudule attribute
Definition: tuya_cloud_com_defs.h:175
Definition gw BASE information
Definition: gw_intf.h:34
BOOL_T prod_test
Definition: gw_intf.h:60
Definition of core device management
Definition: gw_intf.h:397
BOOL_T is_init
Definition: gw_intf.h:408
UINT_T ext_attribute
Definition: gw_intf.h:401
GW_BASE_IF_S gw_base
Definition: gw_intf.h:415
BOOL_T is_oem
Definition: gw_intf.h:406
CHAR_T * serial_no
Definition: gw_intf.h:399
subdev_dev_cntl_get_cb subdev_dev_get_cb
Definition: gw_intf.h:432
GW_DESC_IF_S gw_if
Definition: gw_intf.h:419
GW_EXT_STAT_T ext_stat
Definition: gw_intf.h:403
DEV_CNTL_N_S * dev_cntl
Definition: gw_intf.h:424
TY_IOT_CBS_S cbs
Definition: gw_intf.h:427
GW_WORK_STAT_MAG_S gw_wsm
Definition: gw_intf.h:417
GW_ACTV_IF_S gw_actv
Definition: gw_intf.h:421
BOOL_T is_need_recovery
Definition: gw_intf.h:412
BOOL_T is_stride
Definition: gw_intf.h:410
TIME_S data_update_time
Definition: gw_intf.h:430
Definition of device description info
Definition: gw_intf.h:108
BYTE_T attr_num
Definition: gw_intf.h:138
BOOL_T sync
Definition: gw_intf.h:143
GW_ABI abi
Definition: gw_intf.h:110
DEV_TYPE_T tp
Definition: gw_intf.h:135
Definition of gateway device reset info
Definition: gw_intf.h:442
BOOL_T lazy
Definition: gw_intf.h:446
GW_RESET_TP_T gw_rst_tp
Definition: gw_intf.h:444
Definition of stride update info
Definition: gw_intf.h:149
Definition of device work state
Definition: gw_intf.h:82
GW_WORK_STAT_T stat
Definition: gw_intf.h:96
TY_DNS_PRIO_T dns_prio
Definition: gw_intf.h:94
Definition of scene management
Definition: gw_intf.h:346
BYTE_T cnt
Definition: gw_intf.h:350
Definition of scene info
Definition: gw_intf.h:326
Definition of schema other attribute
Definition: gw_intf.h:305
BOOL_T preprocess
Definition: gw_intf.h:307
Definition of gateway callback funtions
Definition: tuya_cloud_com_defs.h:726
Definition of device control info
Definition: gw_intf.h:367
DP_CNTL_S dp[0]
Definition: gw_intf.h:382
MUTEX_HANDLE dp_mutex
Definition: gw_intf.h:378
BYTE_T dp_num
Definition: gw_intf.h:380
DEV_ACTV_ATTR_S attr
Definition: gw_intf.h:371
tuya utilities module
Common definitions of TUYA cloud
Utilities of DevOS
Common process - Initialization
UINT_T TY_DNS_PRIO_T
DNS priority
Definition: uni_network.h:85
Definition of dp prop value
Definition: tuya_cloud_com_defs.h:342