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 UCHAR_T pin[10];
84
85// gw register status
86typedef BYTE_T GW_WORK_STAT_T;
87#define UNREGISTERED 0 // unregistered
88#define REGISTERED 1 // registered & activate start
89#define ACTIVATED 2 // already active
90#define PROXY_ACTIVING (3)//start ble active
91#define PROXY_ACTIVATED (4) // ble actived
92
96typedef struct {
97#if defined(ENABLE_WIFI_SERVICE) && (ENABLE_WIFI_SERVICE==1)
99 GW_WF_NWC_STAT_T nc_tp;
101 GW_WF_MD_T md;
103 CHAR_T ssid[WIFI_SSID_LEN + 1];
105 CHAR_T passwd[WIFI_PASSWD_LEN + 1];
106#endif
108 TY_DNS_PRIO_T dns_prio; // not saved in kv to save flash life-cycle
110 GW_WORK_STAT_T stat;
112 CHAR_T token[TOKEN_LEN + 1];
114 CHAR_T region[REGION_LEN + 1];
116 CHAR_T regist_key[REGIST_KEY_LEN + 1];
120
124typedef struct {
126 GW_ABI abi;
128 CHAR_T id[GW_ID_LEN + 1];
130 CHAR_T sw_ver[SW_VER_LEN + 1];
132 CHAR_T bs_ver[SW_VER_LEN + 1];
134 CHAR_T prtl_ver[SW_VER_LEN + 1];
136 CHAR_T lan_prtl_ver[SW_VER_LEN + 1];
138 CHAR_T cad_ver[SW_VER_LEN + 1];
140 CHAR_T cd_ver[SW_VER_LEN + 1];
142 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
144 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
145
147 CHAR_T dev_sw_ver[SW_VER_LEN + 1];
149 CHAR_T schema_id[SCHEMA_ID_LEN + 1];
151 DEV_TYPE_T tp;
152
154 BYTE_T attr_num;
156 GW_ATTACH_ATTR_T attr[GW_ATTACH_ATTR_LMT];
157
159 BOOL_T sync;
161
165typedef struct {
167 CHAR_T product_key[PRODUCT_KEY_LEN + 1];
169 CHAR_T firmware_key[PRODUCT_KEY_LEN + 1];
171
175typedef struct {
177 CHAR_T key[SEC_KEY_LEN + 1];
179 CHAR_T local_key[LOCAL_KEY_LEN + 1];
181 CHAR_T http_url[HTTP_URL_LMT + 1];
183 CHAR_T http_ip[HTTP_URL_LMT + 1];
185 CHAR_T https_url[HTTP_URL_LMT + 1];
187 CHAR_T https_ip[HTTP_URL_LMT + 1];
189 CHAR_T httpsPSK_url[HTTP_URL_LMT + 1];
191 CHAR_T httpsPSK_ip[HTTP_URL_LMT + 1];
192
194 CHAR_T mq_psk_url[MQ_URL_LMT + 1];
196 CHAR_T mq_psk_ip[MQ_URL_LMT + 1];
198 CHAR_T mq_tls_url[MQ_URL_LMT + 1];
200 CHAR_T mq_tls_ip[MQ_URL_LMT + 1];
202 CHAR_T mq_proto_url[MQ_URL_LMT + 1];
204 CHAR_T mq_proto_ip[MQ_URL_LMT + 1];
206 CHAR_T ai_speech_url[HTTP_URL_LMT + 1];
208 CHAR_T ai_speech_ip[HTTP_URL_LMT + 1];
210 CHAR_T lowpower_url[MQ_URL_LMT + 1];
212 CHAR_T lowpower_ip[MQ_URL_LMT + 1];
213
215 CHAR_T time_zone[TIME_ZONE_LEN + 1];
217 CHAR_T summer_time_zone[SUMMER_TM_ZONE_LEN + 1];
218
220 CHAR_T wx_app_id[WXAPPID_LEN + 1];
222 CHAR_T wx_uuid[WXUUID_LEN + 1];
225
229
233#define CLOUD_CAPABILITY_WIFI 0 // wifi
234#define CLOUD_CAPABILITY_CABLE 1 // cable
235#define CLOUD_CAPABILITY_GPRS 2 // gprs
236#define CLOUD_CAPABILITY_NBIOT 3 // nb-iot
237#define CLOUD_CAPABILITY_BLUETOOTH 10 // bt
238#define CLOUD_CAPABILITY_BLEMESH 11 // blemesh
239#define CLOUD_CAPABILITY_ZIGBEE 12 // zigbee
240#define CLOUD_CAPABILITY_INFRARED 13 // infrared
241#define CLOUD_CAPABILITY_SUBPIECES 14 // subpieces
242#define CLOUD_CAPABILITY_SIGMESH 15 // sigmesh
243#define CLOUD_CAPABILITY_MCU 16 // mcu
244
248typedef BYTE_T DP_PV_STAT_E;
249#define INVALID 0 // dp is invalid
250#define VALID_LC 1 // dp is valid in local
251#define VALID_ULING 2 // dp is uploading to cloud
252#define VALID_CLOUD 3 // dp is synced with cloud
253
257typedef BYTE_T DP_ID_REPT_TYPE_E;
258#define DP_ID_REPT_RULE_ROUTE (0x1) //dp report rule from route
259
263typedef struct {
264 UINT_T period; // long filter period
265 UINT_T limit; // dpcount limit in long filter period
266 UINT_T rept_cnt; // report counter
267 TIME_S fir_rept_timestamp;//the first report success timestamp
269
273typedef struct {
274 DP_REPT_FLOW_CTRL_UNIT filter_short;//flow control rules for short period
275 DP_REPT_FLOW_CTRL_UNIT filter_long;//flow control rules for long period
277
278#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
282typedef struct {
284 TIME_S cur_set_time;
286 UINT_T cur_set_rept_num;
287} DP_CUR_SET_REPT_CNTL_S;
288#endif
289
293typedef struct {
300 BYTE_T uling_cnt;
307#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
309 TIME_S rept_new_time;
311 DP_PROP_VALUE_U cur_set;
313 DP_CUR_SET_REPT_CNTL_S cur_set_rept;
315 BYTE_T is_set_flag;//是否要检查当前下发的值与实际状态是否一样
316#endif
317} DP_CNTL_S;
318
319
323typedef struct {
327
328
329#define GRP_LMT 64 // group limit
330#define SCENE_LMT 64 // scene limit
331#define LOG_PHAT_MAX_LEN 64
332
336typedef struct {
338 CHAR_T gid[GRP_ID_LEN + 1];
339} GRP_REC_S;
340
344typedef struct {
346 CHAR_T s_id[SCENE_ID_LEN + 1];
348 CHAR_T g_id[GRP_ID_LEN + 1];
350
354typedef struct {
356 GRP_REC_S g_rec[GRP_LMT];
358 BYTE_T cnt;
359} GRP_MAG_S;
360
364typedef struct {
366 SCENE_REC_S s_rec[SCENE_LMT];
368 BYTE_T cnt;
370
375typedef struct {
381
385typedef struct dev_cntl_n_s {
387 CHAR_T id[DEV_ID_LEN + 1];
390#if defined(RELIABLE_TRANSFER) && (RELIABLE_TRANSFER==1)
392 BYTE_T reliable_transfer_flag;//1表示要可靠性检测
393#endif
394
396 MUTEX_HANDLE dp_mutex;//dp本地缓存互斥锁
398 BYTE_T dp_num;
402
410typedef DEV_CNTL_N_S * (*subdev_dev_cntl_get_cb)(IN CHAR_T *id);
411
415typedef struct {
417 CHAR_T *serial_no;
421 GW_EXT_STAT_T ext_stat;
422
424 BOOL_T is_oem;
426 BOOL_T is_init;
428 BOOL_T is_stride;
431
440
443
446
451} GW_CNTL_S;
452
453typedef BYTE_T GW_RESET_TP_T;
454#define GRT_LOCAL 0 // reset is triggerd by device itself
455#define GRT_REMOTE 1 // reset is triggerd by cloud/app
456
460typedef struct {
462 GW_RESET_TP_T gw_rst_tp;
464 BOOL_T lazy;
465} GW_RESET_S;
466
470typedef struct {
472 GW_RESET_TP_T tp;
474 CHAR_T dev_id[DEV_ID_LEN + 1];
476
480typedef enum {
490
497
504
513
522DP_CNTL_S *get_dev_dp_cntl(IN CHAR_T *id, IN CONST BYTE_T dpid);
523
530
542CHAR_T *tuya_get_schema(VOID);
543
555OPERATE_RET tuya_get_dp_info(IN CONST CHAR_T *dev_id, INT_T* dp_num, DP_CNTL_S** dp_info);
556
565OPERATE_RET gw_get_gpd_type(IN CONST UINT_T type, OUT GW_PERMIT_DEV_TP_T *gpd);
566
574OPERATE_RET gw_set_ext_attribute(UINT_T attr);
575
582
592OPERATE_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);
593
601OPERATE_RET gw_destroy_dev_cntl(IN DEV_CNTL_N_S *dev_cnt);
602
611OPERATE_RET gw_dup_dev_cntl(IN DEV_CNTL_N_S *dev_cnt_src, OUT DEV_CNTL_N_S **dev_cnt_out);
612
621
627OPERATE_RET gw_fast_unactive(IN CONST GW_RESET_S *rst_t);
628
636OPERATE_RET gw_unregister(IN CONST GW_RESET_S *rst_t);
637
645OPERATE_RET gw_unactive(IN CONST GW_RESET_S *rst_t);
646
654VOID_T tuya_devos_enable_hot_reset(BOOL_T flag);
655
664
665#ifdef __cplusplus
666}
667#endif
668
669#include "tuya_devos_utils.h"
670
671#endif
672
VOID_T tuya_devos_enable_hot_reset(BOOL_T flag)
Enable hot reset
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:480
@ TY_COUNTRY_CODE_JP
Definition: gw_intf.h:486
@ TY_COUNTRY_CODE_US
Definition: gw_intf.h:484
@ TY_COUNTRY_CODE_EU
Definition: gw_intf.h:488
@ TY_COUNTRY_CODE_CN
Definition: gw_intf.h:482
BYTE_T DP_PV_STAT_E
Definiton of DP status
Definition: gw_intf.h:248
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:410
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:257
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
BOOL_T tuya_devos_is_hot_reset(VOID_T)
Check devos is support hot reset
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:375
BOOL_T preprocess
Definition: gw_intf.h:379
BOOL_T attach_dp_if
Definition: gw_intf.h:377
Definition of sub-device reset info
Definition: gw_intf.h:470
GW_RESET_TP_T tp
Definition: gw_intf.h:472
Definition of dp control
Definition: gw_intf.h:293
DP_DESC_IF_S dp_desc
Definition: gw_intf.h:295
UINT_T ble_send_sn
Definition: gw_intf.h:306
DP_PROP_VALUE_U prop
Definition: gw_intf.h:297
DP_PV_STAT_E pv_stat
Definition: gw_intf.h:299
DP_REPT_FLOW_CTRL rept_flow_ctrl
Definition: gw_intf.h:302
UINT_T time_stamp
Definition: gw_intf.h:304
Definition of dp description
Definition: tuya_cloud_com_defs.h:392
Definition of dp report flow control unit
Definition: gw_intf.h:263
Definition of dp report flow control
Definition: gw_intf.h:273
Definition of group management
Definition: gw_intf.h:354
BYTE_T cnt
Definition: gw_intf.h:358
Definition of group info
Definition: gw_intf.h:336
Definition of active info
Definition: gw_intf.h:175
BYTE_T dynamic_tls_mode
Definition: gw_intf.h:227
INT_T cloud_capability
Definition: gw_intf.h:224
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:415
BOOL_T is_init
Definition: gw_intf.h:426
UINT_T ext_attribute
Definition: gw_intf.h:419
GW_BASE_IF_S gw_base
Definition: gw_intf.h:433
BOOL_T is_oem
Definition: gw_intf.h:424
CHAR_T * serial_no
Definition: gw_intf.h:417
subdev_dev_cntl_get_cb subdev_dev_get_cb
Definition: gw_intf.h:450
GW_DESC_IF_S gw_if
Definition: gw_intf.h:437
TIME_MS data_update_time
Definition: gw_intf.h:448
GW_EXT_STAT_T ext_stat
Definition: gw_intf.h:421
DEV_CNTL_N_S * dev_cntl
Definition: gw_intf.h:442
TY_IOT_CBS_S cbs
Definition: gw_intf.h:445
GW_WORK_STAT_MAG_S gw_wsm
Definition: gw_intf.h:435
GW_ACTV_IF_S gw_actv
Definition: gw_intf.h:439
BOOL_T is_need_recovery
Definition: gw_intf.h:430
BOOL_T is_stride
Definition: gw_intf.h:428
Definition of device description info
Definition: gw_intf.h:124
BYTE_T attr_num
Definition: gw_intf.h:154
BOOL_T sync
Definition: gw_intf.h:159
GW_ABI abi
Definition: gw_intf.h:126
DEV_TYPE_T tp
Definition: gw_intf.h:151
Definition of gateway device reset info
Definition: gw_intf.h:460
BOOL_T lazy
Definition: gw_intf.h:464
GW_RESET_TP_T gw_rst_tp
Definition: gw_intf.h:462
Definition of stride update info
Definition: gw_intf.h:165
Definition of device work state
Definition: gw_intf.h:96
GW_WORK_STAT_T stat
Definition: gw_intf.h:110
TY_DNS_PRIO_T dns_prio
Definition: gw_intf.h:108
BOOL_T is_psk30_cfg
Definition: gw_intf.h:118
Definition of scene management
Definition: gw_intf.h:364
BYTE_T cnt
Definition: gw_intf.h:368
Definition of scene info
Definition: gw_intf.h:344
Definition of schema other attribute
Definition: gw_intf.h:323
BOOL_T preprocess
Definition: gw_intf.h:325
auth info for ext module
Definition: gw_intf.h:35
Definition of gateway callback funtions
Definition: tuya_cloud_com_defs.h:807
Definition of device control info
Definition: gw_intf.h:385
DP_CNTL_S dp[0]
Definition: gw_intf.h:400
MUTEX_HANDLE dp_mutex
Definition: gw_intf.h:396
BYTE_T dp_num
Definition: gw_intf.h:398
DEV_ACTV_ATTR_S attr
Definition: gw_intf.h:389
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