TuyaOS
lan_rpc.h
浏览该文件的文档.
1
11#ifndef __LAN_RPC_H__
12#define __LAN_RPC_H__
13
14
15#include "tuya_cloud_com_defs.h"
16#include "tuya_cloud_types.h"
17#include "tuya_hal_network.h"
18#include "svc_rpc.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24
25#define LAN_RPC_ID_LEN (GW_ID_LEN)
26#define LAN_RPC_KEY_LEN (LOCAL_KEY_LEN)
27#define LAN_RPC_NODE_TIMEOUT 20
28
29#define LAN_RPC_NODE_ADD 0
30#define LAN_RPC_NODE_DEL 1
31#define LAN_RPC_NODE_REJOIN 2
32
33
34typedef enum {
35 LAN_RPC_SLAVER,
36 LAN_RPC_MASTER,
37} LAN_RPC_TYPE;
38
39typedef struct {
40 UINT_T ip;
41 INT_T seqno;
42 USHORT_T cap;
43 UINT8_T id[LAN_RPC_ID_LEN + 1];
44 UINT8_T key[LAN_RPC_KEY_LEN + 1]; //key是非字符串的
46
47typedef struct {
48 UINT8_T owner;
49 UINT8_T stat;
50 LAN_RPC_NODE_S node;
52
53typedef OPERATE_RET(*LAN_RPC_MASTER_GET_CB)(LAN_RPC_MASTER_S *master);
54typedef OPERATE_RET(*LAN_RPC_NODE_STAT_CB)(UINT8_T stat, LAN_RPC_NODE_S *node);
55typedef VOID (*LAN_RPC_NODE_OUTPUT_CB)(LAN_RPC_NODE_S *node, UINT16_T num, VOID *arg);
56typedef rpc_async_cb RPC_RET_CB;
57typedef rpc_method_cb RPC_METHOD_CB;
58
59typedef struct {
60 UINT8_T type;
61 LAN_RPC_NODE_STAT_CB node_stat_cb;
62 LAN_RPC_MASTER_GET_CB master_get_cb;
64
70INT_T lan_rpc_fd_get(VOID);
71
77
86
87VOID lan_rpc_node_fresh(CHAR_T *dev_id);
88
89VOID lan_rpc_node_timeout_set(UINT_T timeout_s);
90
99BOOL_T lan_rpc_node_find_by_ip(UINT_T ip, LAN_RPC_NODE_S *node);
100
109BOOL_T lan_rpc_node_find_ip_by_id(UINT8_T *id, UINT_T *ip);
110
119OPERATE_RET lan_rpc_node_key_set(UINT8_T *id, UINT8_T *key);
120
129OPERATE_RET lan_rpc_node_output(LAN_RPC_NODE_OUTPUT_CB node_output_cb, VOID *arg);
130
138OPERATE_RET lan_rpc_session_key_set(UINT8_T *session_key);
139
147OPERATE_RET lan_rpc_init(LAN_RPC_CFG_S *cfg);
148
158OPERATE_RET lan_rpc_slave_call_sync(JRPC_MSG_S *requset, JRPC_MSG_S *result, UINT_T timeout);
170OPERATE_RET lan_rpc_call_async(UINT8_T *id, JRPC_MSG_S *requset, RPC_RET_CB cb, VOID *cb_param, UINT_T timeout);
171
177OPERATE_RET lan_rpc_recv(VOID);
178
188OPERATE_RET lan_rpc_method_register(CHAR_T *name, RPC_METHOD_CB cb, VOID *arg);
189
197OPERATE_RET lan_rpc_get_peer_ip(OUT UNW_IP_ADDR_T *peer_ip);
198
199#ifdef __cplusplus
200}
201#endif
202#endif
OPERATE_RET lan_rpc_slave_call_sync(JRPC_MSG_S *requset, JRPC_MSG_S *result, UINT_T timeout)
slave rpc sync
OPERATE_RET lan_rpc_init(LAN_RPC_CFG_S *cfg)
rpc init
OPERATE_RET lan_rpc_session_key_set(UINT8_T *session_key)
set session key
INT_T lan_rpc_fd_get(VOID)
get fd
OPERATE_RET lan_rpc_call_async(UINT8_T *id, JRPC_MSG_S *requset, RPC_RET_CB cb, VOID *cb_param, UINT_T timeout)
rpc sync
BOOL_T lan_rpc_node_find_ip_by_id(UINT8_T *id, UINT_T *ip)
found ip by id
OPERATE_RET lan_rpc_node_add(LAN_RPC_NODE_S *node)
node add
OPERATE_RET lan_rpc_node_key_set(UINT8_T *id, UINT8_T *key)
node key set
OPERATE_RET lan_rpc_recv(VOID)
rpc receive
BOOL_T lan_rpc_node_find_by_ip(UINT_T ip, LAN_RPC_NODE_S *node)
found node by ip
OPERATE_RET lan_rpc_method_register(CHAR_T *name, RPC_METHOD_CB cb, VOID *arg)
lan rpc method register
VOID lan_rpc_node_timeout_check(VOID)
check timeout
OPERATE_RET lan_rpc_node_output(LAN_RPC_NODE_OUTPUT_CB node_output_cb, VOID *arg)
node output
OPERATE_RET lan_rpc_get_peer_ip(OUT UNW_IP_ADDR_T *peer_ip)
lan rpc get peer ip
Definition: lan_rpc.h:59
Definition: lan_rpc.h:47
Definition: lan_rpc.h:39
Definition: json_rpc.h:42
rcp relate
void(* rpc_method_cb)(jrpc_msg_t *request, void *arg, jrpc_msg_t *reply)
rpc method callback
Definition: svc_rpc.h:73
void(* rpc_async_cb)(jrpc_msg_t *result, void *arg)
rpc async callback
Definition: svc_rpc.h:91
Common process - Initialization