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 {
288#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
290 TIME_S rept_new_time;
292 DP_PROP_VALUE_U cur_set;
294 DP_CUR_SET_REPT_CNTL_S cur_set_rept;
296 BYTE_T is_set_flag;//是否要检查当前下发的值与实际状态是否一样
297#endif
298} DP_CNTL_S;
299
300
304typedef struct {
308
309
310#define GRP_LMT 64 // group limit
311#define SCENE_LMT 64 // scene limit
312#define LOG_PHAT_MAX_LEN 64
313
317typedef struct {
319 CHAR_T gid[GRP_ID_LEN + 1];
320} GRP_REC_S;
321
325typedef struct {
327 CHAR_T s_id[SCENE_ID_LEN + 1];
329 CHAR_T g_id[GRP_ID_LEN + 1];
331
335typedef struct {
337 GRP_REC_S g_rec[GRP_LMT];
339 BYTE_T cnt;
340} GRP_MAG_S;
341
345typedef struct {
347 SCENE_REC_S s_rec[SCENE_LMT];
349 BYTE_T cnt;
351
356typedef struct {
362
366typedef struct dev_cntl_n_s {
368 CHAR_T id[DEV_ID_LEN + 1];
371#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
373 BYTE_T reliable_transfer_flag;//1表示要可靠性检测
374#endif
375
377 MUTEX_HANDLE dp_mutex;//dp本地缓存互斥锁
379 BYTE_T dp_num;
383
391typedef DEV_CNTL_N_S * (*subdev_dev_cntl_get_cb)(IN CHAR_T *id);
392
396typedef struct {
398 CHAR_T *serial_no;
402 GW_EXT_STAT_T ext_stat;
403
405 BOOL_T is_oem;
407 BOOL_T is_init;
409 BOOL_T is_stride;
412
421
424
427
432} GW_CNTL_S;
433
434typedef BYTE_T GW_RESET_TP_T;
435#define GRT_LOCAL 0 // reset is triggerd by device itself
436#define GRT_REMOTE 1 // reset is triggerd by cloud/app
437
441typedef struct {
443 GW_RESET_TP_T gw_rst_tp;
445 BOOL_T lazy;
446} GW_RESET_S;
447
451typedef struct {
453 GW_RESET_TP_T tp;
455 CHAR_T dev_id[DEV_ID_LEN + 1];
457
461typedef enum {
471
478
485
494
503DP_CNTL_S *get_dev_dp_cntl(IN CHAR_T *id, IN CONST BYTE_T dpid);
504
511
523CHAR_T *tuya_get_schema(VOID);
524
536OPERATE_RET tuya_get_dp_info(IN CONST CHAR_T *dev_id, INT_T* dp_num, DP_CNTL_S** dp_info);
537
546OPERATE_RET gw_get_gpd_type(IN CONST UINT_T type, OUT GW_PERMIT_DEV_TP_T *gpd);
547
555OPERATE_RET gw_set_ext_attribute(UINT_T attr);
556
563
573OPERATE_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);
574
582OPERATE_RET gw_destroy_dev_cntl(IN DEV_CNTL_N_S *dev_cnt);
583
592OPERATE_RET gw_dup_dev_cntl(IN DEV_CNTL_N_S *dev_cnt_src, OUT DEV_CNTL_N_S **dev_cnt_out);
593
602
608OPERATE_RET gw_fast_unactive(IN CONST GW_RESET_S *rst_t);
609
617OPERATE_RET gw_unregister(IN CONST GW_RESET_S *rst_t);
618
626OPERATE_RET gw_unactive(IN CONST GW_RESET_S *rst_t);
627
628#ifdef __cplusplus
629}
630#endif
631
632#include "tuya_devos_utils.h"
633
634#endif
635
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:461
@ TY_COUNTRY_CODE_JP
Definition: gw_intf.h:467
@ TY_COUNTRY_CODE_US
Definition: gw_intf.h:465
@ TY_COUNTRY_CODE_EU
Definition: gw_intf.h:469
@ TY_COUNTRY_CODE_CN
Definition: gw_intf.h:463
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:391
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: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:356
BOOL_T preprocess
Definition: gw_intf.h:360
BOOL_T attach_dp_if
Definition: gw_intf.h:358
Definition of sub-device reset info
Definition: gw_intf.h:451
GW_RESET_TP_T tp
Definition: gw_intf.h:453
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:287
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:335
BYTE_T cnt
Definition: gw_intf.h:339
Definition of group info
Definition: gw_intf.h:317
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:396
BOOL_T is_init
Definition: gw_intf.h:407
UINT_T ext_attribute
Definition: gw_intf.h:400
GW_BASE_IF_S gw_base
Definition: gw_intf.h:414
BOOL_T is_oem
Definition: gw_intf.h:405
CHAR_T * serial_no
Definition: gw_intf.h:398
subdev_dev_cntl_get_cb subdev_dev_get_cb
Definition: gw_intf.h:431
GW_DESC_IF_S gw_if
Definition: gw_intf.h:418
GW_EXT_STAT_T ext_stat
Definition: gw_intf.h:402
DEV_CNTL_N_S * dev_cntl
Definition: gw_intf.h:423
TY_IOT_CBS_S cbs
Definition: gw_intf.h:426
GW_WORK_STAT_MAG_S gw_wsm
Definition: gw_intf.h:416
GW_ACTV_IF_S gw_actv
Definition: gw_intf.h:420
BOOL_T is_need_recovery
Definition: gw_intf.h:411
BOOL_T is_stride
Definition: gw_intf.h:409
TIME_S data_update_time
Definition: gw_intf.h:429
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:441
BOOL_T lazy
Definition: gw_intf.h:445
GW_RESET_TP_T gw_rst_tp
Definition: gw_intf.h:443
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:345
BYTE_T cnt
Definition: gw_intf.h:349
Definition of scene info
Definition: gw_intf.h:325
Definition of schema other attribute
Definition: gw_intf.h:304
BOOL_T preprocess
Definition: gw_intf.h:306
Definition of gateway callback funtions
Definition: tuya_cloud_com_defs.h:726
Definition of device control info
Definition: gw_intf.h:366
DP_CNTL_S dp[0]
Definition: gw_intf.h:381
MUTEX_HANDLE dp_mutex
Definition: gw_intf.h:377
BYTE_T dp_num
Definition: gw_intf.h:379
DEV_ACTV_ATTR_S attr
Definition: gw_intf.h:370
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