meta/device/device.proto

syntax = "proto3";

package jsgenerate_kb2022.meta.device;
option go_package = "gateway/protocol/meta/device";

import "google/api/annotations.proto";
import "google/api/httpbody.proto";
import "adadd52b-e7a2-4fe2-9f15-356ceddbd4f6/utils/utils.proto";
// Device 模塊用於管理掛載到區域下 受到控制的硬件設備
service Device {
    // 添加一個設備
    rpc Add (AddRequest) returns (AddResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/device"
            body: "*"
        };
    }
    // 更改設備基本屬性
    rpc Change (ChangeRequest) returns (ChangeResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/device/change/{id}"
            body: "*"
        };
    }
    // 禁用一個設備,通常是設備出了問題,將老設備禁用換上新設備
    rpc Disable (DisableRequest) returns (DisableResponse){
        option (google.api.http) = {
            delete: "/api/v1/meta/device/{id}"
        };
    }
    // 導入設備
    // 對於 http 可以請求 /api/v1/meta/device/import_file 進行檔案上傳
    // curl -X POST -F "attachment=@/tmp/somefile.txt" http://localhost/api/v1/meta/device/import_file
    rpc Import (ImportRequest) returns (ImportResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/device/import"
            body: "*"
        };
    }
    // 導出區域
    rpc Export (ExportRequest) returns (google.api.HttpBody){
        option (google.api.http) = {
            get: "/api/v1/meta/device/export"
        };
    }

    // 返回指定 id 的設備,僅用於顯示歷史數據
    rpc ID (IDRequest) returns (IDResponse){
        option (google.api.http) = {
            get: "/api/v1/meta/device/by_id"
        };
    }
    // 查詢 設備
    rpc Find (FindRequest) returns (FindResponse){
        option (google.api.http) = {
            get: "/api/v1/meta/device"
        };
    }

    // 設置設備 位置座标
    rpc SetPosition (SetPositionRequest) returns (SetPositionResponse){
        option (google.api.http) = {
            post: "/api/v1/meta/device/attribute/position/{id}"
            body: "*"
        };
    }
}
// 設備記錄
message Data{
	// 主鍵用於 緩存
	int64 id = 1;
	// 設備邏輯碼
	string logic = 2;
	// 設備物理碼
	string physical = 3;
	// 一個給人類查看的設備名稱
	string name = 4;

	// 服務端模擬器是否已經就緒
	bool emulator = 5;
	// 硬件設備是否已經連接到 服務端 模擬器
	bool connected = 6;
	// 硬件設備最後一次連接時間 unix
	int64 connectedAt = 7;
	// 更新 Emulator,Connected,ConnectedAt 使用的樂觀鎖,客户端通常可以忽略此值
	int64 locker = 8;

    // 定位信息  定位類型:latitude,longitude
    // 'GPS:123.321,456.654'
    // 空字符串代表沒有定位信息
    string position= 9;

	// 是否被停用
	bool disabled = 10;
	// 被停用的時間 unix
	int64 disabledAt = 11;
}
message AddRequest{
    // 設備邏輯碼 規則同區域邏輯碼 但 length == 20
    // 此外邏輯碼 必須以掛接的區域邏輯碼爲前綴
    string logic = 1;
    // 規則類似邏輯碼但不需要和區域邏輯碼掛鉤
    string physical =2;
    // 設備名稱
    string name = 3;
}
message AddResponse{
    // 添加成功時返回 添加的 設備 id
    int64 id = 1;
}
message ChangeRequest{
    // 要更改的設備 id
    int64 id = 1;
    // 要更改的 設備邏輯碼,用於驗證授權
    string logic  = 2;
    // 新的設備名稱
    string name = 3;
}
message ChangeResponse{
}
message DisableRequest{
    int64 id = 1;
    // 設備邏輯碼,用於驗證授權
    string logic  = 2;
}
message DisableResponse{
}
message ImportRequest{
    // 導入數據 必須是 utf8 文本
    // 一行一個設備, 邏輯碼 物理碼 設備名稱 以空格隔開
    // 如果行以 # 字符作爲開頭則表示註釋,解析器將忽略此行內容
    // 51010100000000000001 12345678901234567891 測試設備 1
    // 51010100000000000002 12345678901234567892 測試設備 2 
    // 51010200000000000001 22345678901234567891 測試設備 x
    string text = 1;
}
message ImportResponse{
    int64 changed = 1;
}
message ExportRequest{
    // 傳入一個區域碼,導出所有掛接在此區域下的設備 基礎信息
    string logic = 1;
}
message IDRequest{
    repeated int64 id = 1;
}
message IDResponse{
    repeated Data data = 1; 
}
message FindRequest{
    jsgenerate_kb2022.utils.FindLimit limit = 1;
    // id not in (...)
    repeated int64 notID = 50;
    // 設備id in 
    repeated int64 id = 2;
    // 查找 包含這些 邏輯碼 的設備
    // 比如 成都的邏輯碼是 5101,則 使用 5101 進行查詢可以找到所有掛接在成都下面的設備
    repeated string logic = 3;
    // 查找 包含這些 物理碼 的設備
    repeated string physical = 4;
    // 查找設備名稱 like
    string name = 5;
    // * -1 斷線設備
    // * 0 所有設備
    // * 1 連接設備
    int32 connected = 6;

    // * -1 啓用設備
    // * 0 所有設備
    // * 1 禁用設備
    int32 disabled = 7;
}
message FindResponse{
    jsgenerate_kb2022.utils.FindResult result = 1;
    repeated Data data = 2;
}
message SetPositionRequest{
    int64 id = 1;
    // 要更改的 設備邏輯碼,用於驗證授權
    string logic  = 2;
	// 設備 定位信息,格式爲 定位類型:latitude,longitude
	// 例如 'GPS:123.321,456.654'
	// 目前 定位類型 通常都是 GPS
    string value = 3;
}
message SetPositionResponse{
}