saas-smartAi通信协议标准库
gongshangguo
2022-03-02 6c31643efa07274245b6fe4ef95f39c1460f4b70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
syntax = "proto3";
 
package aiot;
 
// 协议格式:
// |  int32  | | enum int32 | |    int32   | |                      []byte                     | |  enum int32  | |  enum int32  | |        []byte        | |  []byte   |
// ----------- -------------- -------------- --------------------------------------------------- ---------------- ---------------- ------------------------ --------------
//   length      receiver        senderId                        deviceProto                           msgType          reqType            msgIdProto            data
//  数据包长度     接受者身份        发送者ID                           设备信息                             消息类型           请求类型               消息ID             消息体
//    4byte
//                                          {|    string    | |     string     | |    string   |}                                 {|  string  | | string  |}
//                                           ---------------- ------------------ ---------------                                   ------------ -----------
//                                               clusterId       masterDeviceId      DeviceIds                                         msgId     PreMsgId
//                                                 集群ID        集群Master设备ID    消息指向的设备ID                                       消息ID     原始消息ID
// 消息接收者
enum RECEIVER {
    // 发送给saas
    TO_SAAS = 0;
    // 发送给集群master
    TO_MASTER = 1;
    // 发送给集群全部成员
    TO_CLUSTER = 2;
    // 发送给集群某一个节点
    TO_NODE = 3;
    // 发送给集群中部分节点
    TO_NODE_LIST = 4;
}
 
// 消息类型
enum MSG_TYPE {
    // 心跳
    HEART_BEAT = 0;
    // 注册
    REGISTER = 1;
    // 数据上报
    DATA_REPORT = 2;
    // 设备控制
    CONTROL = 3;
    // 业务消息
    BUSINESS = 9;
}
 
// 请求类型
enum REQ_TYPE {
    // 收到请求
    REQUEST = 0;
    // 收到应答
    RESPONSE = 1;
}
 
// 设备信息组成
message DeviceProto {
    // 集群ID
    string clusterId = 1;
    // 主节点ID
    string masterDeviceId = 2;
    // 消息接收者
    repeated string deviceIds = 3;
}
 
// 消息ID
message MsgIdProto {
    string msgId = 1;
    string preMsgId = 2;
}
 
// 消息体
message BusinessProto {
    string topic = 1;
    bytes request = 2;
    string authorization = 3;
}
 
// 消息体组成
message Protocol {
    RECEIVER receiver = 1;
    string senderId = 2;
    DeviceProto deviceProto = 3;
    MSG_TYPE msgType = 4;
    REQ_TYPE reqType = 5;
    MsgIdProto msgProto = 6;
    bytes data = 7;
}
 
// 心跳包
message HeartBeatProto {}
 
// 注册节点ID
message DeviceNode {
    string deviceId = 1;
}
 
// 设备注册包
message DeviceRegister {
    // 设备ID
    string deviceId = 1;
    //设备名称
    string serverName = 2;
    // 集群ID
    string clusterId = 3;
    // 集群名称
    string clusterName = 4;
    // 漂移IP
    string virtualIp = 5;
    // 集群节点列表
    repeated DeviceNode deviceList = 6;
}
 
// 数据上报
message DataReport {
    string dataKey = 1;
    bytes data = 2;
}