初始
This commit is contained in:
39
api/pilot/manage/login.go
Normal file
39
api/pilot/manage/login.go
Normal file
@ -0,0 +1,39 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type LOGIN struct {
|
||||
}
|
||||
type LoginReq struct {
|
||||
g.Meta `path:"login" summary:"pilot登录" method:"post" tags:"无人机遥控器"`
|
||||
|
||||
Username string `json:"username" v:"required"`
|
||||
Password string `json:"password" v:"required"`
|
||||
//Flag int `json:"flag" v:"required"`
|
||||
}
|
||||
type LoginRes struct {
|
||||
Username string `json:"username"`
|
||||
UserId string `json:"user_id"`
|
||||
WorkspaceId string `json:"workspace_id"`
|
||||
UserType int `json:"user_type"`
|
||||
MqttUsername string `json:"mqtt_username"`
|
||||
MqttPassword string `json:"mqtt_password"`
|
||||
AccessToken string `json:"access_token"`
|
||||
MqttAddr string `json:"mqtt_addr"`
|
||||
}
|
||||
|
||||
func (receiver *LOGIN) Login(ctx context.Context, req *LoginReq) (res *LoginRes, err error) {
|
||||
res = &LoginRes{}
|
||||
res.Username = "pilot"
|
||||
res.UserId = "be7c6c3d-afe9-4be4-b9eb-c55066c0914e"
|
||||
res.WorkspaceId = "e3dea0f5-37f2-4d79-ae58-490af3228069"
|
||||
res.UserType = 2
|
||||
res.MqttUsername = "pilot"
|
||||
res.MqttPassword = "pilot123"
|
||||
res.AccessToken = "abc"
|
||||
res.MqttAddr = "tcp://jl.yj-3d.com:1883"
|
||||
return
|
||||
}
|
122
api/pilot/manage/manage.go
Normal file
122
api/pilot/manage/manage.go
Normal file
@ -0,0 +1,122 @@
|
||||
package manage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type MANAGE struct {
|
||||
}
|
||||
type UsualRes struct {
|
||||
}
|
||||
type BindReq struct {
|
||||
g.Meta `path:"devices/{device_sn}/binding" summary:"绑定设备" method:"post" tags:"无人机遥控器"`
|
||||
DeviceSN string `json:"device_sn"`
|
||||
UserID string `json:"user_id"`
|
||||
WorkspaceId string `json:"workspace_id"`
|
||||
}
|
||||
|
||||
func (receiver *MANAGE) Bind(ctx context.Context, req *BindReq) (res *UsualRes, err error) {
|
||||
fmt.Println(req.DeviceSN)
|
||||
fmt.Println(req.UserID)
|
||||
fmt.Println(req.WorkspaceId)
|
||||
return
|
||||
}
|
||||
|
||||
type UserCurrentReq struct {
|
||||
g.Meta `path:"users/current" summary:"获取当前用户信息信息" method:"get" tags:"无人机遥控器"`
|
||||
}
|
||||
type UserCurrentRes struct {
|
||||
Username string `json:"username"`
|
||||
UserId string `json:"user_id"`
|
||||
WorkspaceId string `json:"workspace_id"`
|
||||
UserType int `json:"user_type"`
|
||||
MqttUsername string `json:"mqtt_username"`
|
||||
MqttPassword string `json:"mqtt_password"`
|
||||
MqttAddr string `json:"mqtt_addr"`
|
||||
}
|
||||
|
||||
func (receiver *MANAGE) UserCurrent(ctx context.Context, req *UserCurrentReq) (res *UserCurrentRes, err error) {
|
||||
res = &UserCurrentRes{}
|
||||
res.Username = "pilot"
|
||||
res.UserId = "be7c6c3d-afe9-4be4-b9eb-c55066c0914e"
|
||||
res.WorkspaceId = "e3dea0f5-37f2-4d79-ae58-490af3228069"
|
||||
res.UserType = 2
|
||||
res.MqttUsername = "pilot"
|
||||
res.MqttPassword = "pilot123"
|
||||
res.MqttAddr = "tcp://jl.yj-3d.com:1883"
|
||||
return
|
||||
}
|
||||
|
||||
type WorkSpaceCurrentReq struct {
|
||||
g.Meta `path:"workspaces/current" summary:"获取当前工作空间信息" method:"get" tags:"无人机遥控器"`
|
||||
}
|
||||
type WorkSpaceCurrentRes struct {
|
||||
WorkspaceId string `json:"workspace_id"`
|
||||
WorkspaceName string `json:"workspace_name"`
|
||||
WorkspaceDesc string `json:"workspace_desc"`
|
||||
PlatformName string `json:"platform_name"`
|
||||
BindCode string `json:"bind_code"`
|
||||
}
|
||||
|
||||
func (receiver *MANAGE) WorkSpaceCurrent(ctx context.Context, req *WorkSpaceCurrentReq) (res *WorkSpaceCurrentRes, err error) {
|
||||
res = &WorkSpaceCurrentRes{}
|
||||
res.WorkspaceName = "测试组"
|
||||
res.WorkspaceId = "e3dea0f5-37f2-4d79-ae58-490af3228069"
|
||||
res.WorkspaceDesc = "中煤科工测试云平台"
|
||||
res.PlatformName = "中煤科工光伏平台"
|
||||
res.BindCode = "qwe"
|
||||
return
|
||||
}
|
||||
|
||||
type TopologiesReq struct {
|
||||
g.Meta `path:"workspaces/{workspace_id}/devices/topologies" summary:"获取设备拓扑列表)" method:"get" tags:"无人机遥控器"`
|
||||
}
|
||||
type TopologiesRes struct {
|
||||
List []struct {
|
||||
Hosts []struct {
|
||||
Sn string `json:"sn"`
|
||||
DeviceModel struct {
|
||||
Key string `json:"key"`
|
||||
Domain string `json:"domain"`
|
||||
Type string `json:"type"`
|
||||
SubType string `json:"sub_type"`
|
||||
} `json:"device_model"`
|
||||
OnlineStatus bool `json:"online_status"`
|
||||
DeviceCallsign string `json:"device_callsign"`
|
||||
UserId string `json:"user_id"`
|
||||
UserCallsign string `json:"user_callsign"`
|
||||
IconUrls struct {
|
||||
NormalIconUrl string `json:"normal_icon_url"`
|
||||
SelectedIconUrl string `json:"selected_icon_url"`
|
||||
} `json:"icon_urls"`
|
||||
} `json:"hosts"`
|
||||
Parents []struct {
|
||||
Sn string `json:"sn"`
|
||||
OnlineStatus bool `json:"online_status"`
|
||||
DeviceModel struct {
|
||||
Key string `json:"key"`
|
||||
Domain string `json:"domain"`
|
||||
Type string `json:"type"`
|
||||
SubType string `json:"sub_type"`
|
||||
} `json:"device_model"`
|
||||
DeviceCallsign string `json:"device_callsign"`
|
||||
UserId string `json:"user_id"`
|
||||
UserCallsign string `json:"user_callsign"`
|
||||
IconUrls struct {
|
||||
NormalIconUrl string `json:"normal_icon_url"`
|
||||
SelectedIconUrl string `json:"selected_icon_url"`
|
||||
} `json:"icon_urls"`
|
||||
} `json:"parents"`
|
||||
} `json:"list"`
|
||||
}
|
||||
|
||||
func (receiver *MANAGE) Topologies(ctx context.Context, req *TopologiesReq) (res *TopologiesRes, err error) {
|
||||
workspace_id := ghttp.RequestFromCtx(ctx).Get("workspace_id")
|
||||
fmt.Println("workspace_id", workspace_id)
|
||||
res = &TopologiesRes{}
|
||||
|
||||
return
|
||||
}
|
51
api/pilot/map/map.go
Normal file
51
api/pilot/map/map.go
Normal file
@ -0,0 +1,51 @@
|
||||
package _map
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type MAP struct {
|
||||
}
|
||||
type Element_groupsReq struct {
|
||||
g.Meta `path:"workspaces/{workspace_id}/element-groups" summary:"获取元素列表" method:"get" tags:"无人机遥控器"`
|
||||
GroupId string `json:"group_id"`
|
||||
IsDistributed bool `json:"is_distributed"`
|
||||
}
|
||||
type Element_groupsRes struct {
|
||||
Id string `json:"id"`
|
||||
Type int `json:"type"`
|
||||
Name string `json:"name"`
|
||||
IsLock bool `json:"is_lock"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
Elements []struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
UpdateTime int64 `json:"update_time"`
|
||||
Resource struct {
|
||||
Type int `json:"type"`
|
||||
UserName string `json:"user_name"`
|
||||
Content struct {
|
||||
Type string `json:"type"`
|
||||
Properties struct {
|
||||
Color string `json:"color"`
|
||||
ClampToGround bool `json:"clampToGround"`
|
||||
} `json:"properties"`
|
||||
Geometry struct {
|
||||
Type string `json:"type"`
|
||||
Coordinates []interface{} `json:"coordinates"`
|
||||
} `json:"geometry"`
|
||||
} `json:"content"`
|
||||
} `json:"resource"`
|
||||
} `json:"elements"`
|
||||
}
|
||||
|
||||
func (receiver MAP) Element_groups(ctx context.Context, req *Element_groupsReq) (res *Element_groupsRes, err error) {
|
||||
workspace_id := ghttp.RequestFromCtx(ctx).Get("workspace_id")
|
||||
fmt.Println("获取元素列表workspace_id", workspace_id)
|
||||
return
|
||||
}
|
32
api/pilot/pilot.go
Normal file
32
api/pilot/pilot.go
Normal file
@ -0,0 +1,32 @@
|
||||
package pilot
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
"github.com/tiger1103/gfast/v3/api/pilot/manage"
|
||||
_map "github.com/tiger1103/gfast/v3/api/pilot/map"
|
||||
"github.com/tiger1103/gfast/v3/api/pilot/wayline"
|
||||
"github.com/tiger1103/gfast/v3/api/pilot/ws"
|
||||
)
|
||||
|
||||
func InitPlilotAPI(group *ghttp.RouterGroup) {
|
||||
group.Middleware(ghttp.MiddlewareCORS)
|
||||
group.Group("/manage", func(group *ghttp.RouterGroup) {
|
||||
group.Group("/api/v1", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(new(manage.LOGIN))
|
||||
//service.GfToken().Middleware(group)
|
||||
group.Bind(new(manage.MANAGE))
|
||||
group.Bind(new(ws.WS))
|
||||
|
||||
})
|
||||
})
|
||||
group.Group("/wayline", func(group *ghttp.RouterGroup) {
|
||||
group.Group("/api/v1", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(new(wayline.WAYLINE))
|
||||
})
|
||||
})
|
||||
group.Group("/map", func(group *ghttp.RouterGroup) {
|
||||
group.Group("/api/v1", func(group *ghttp.RouterGroup) {
|
||||
group.Bind(new(_map.MAP))
|
||||
})
|
||||
})
|
||||
}
|
48
api/pilot/wayline/wayline.go
Normal file
48
api/pilot/wayline/wayline.go
Normal file
@ -0,0 +1,48 @@
|
||||
package wayline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type WAYLINE struct {
|
||||
}
|
||||
|
||||
type WaylinesReq struct {
|
||||
g.Meta `path:"workspaces/{workspace_id}/waylines" summary:"获取航线列表" method:"get" tags:"无人机遥控器"`
|
||||
Favorited bool `json:"favorited"`
|
||||
Order_by string `json:"order_by"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
TemplateType []int `json:"template_type"`
|
||||
}
|
||||
|
||||
type Wayline struct {
|
||||
Id string `json:"id"`
|
||||
DroneModelKey string `json:"drone_model_key"`
|
||||
Favorited bool `json:"favorited"`
|
||||
Name string `json:"name"`
|
||||
PayloadModelKeys []string `json:"payload_model_keys"`
|
||||
TemplateTypes []int `json:"template_types"`
|
||||
UpdateTime int64 `json:"update_time"`
|
||||
UserName string `json:"user_name"`
|
||||
}
|
||||
type WaylinesRes struct {
|
||||
List []Wayline `json:"list"`
|
||||
Pagination struct {
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Total int `json:"total"`
|
||||
} `json:"pagination"`
|
||||
}
|
||||
|
||||
func (receiver WAYLINE) Waylines(ctx context.Context, req *WaylinesReq) (res *WaylinesRes, err error) {
|
||||
workspace_id := ghttp.RequestFromCtx(ctx).Get("workspace_id")
|
||||
fmt.Println("获取航线列表workspace_id", workspace_id)
|
||||
fmt.Println(req.Order_by, req.TemplateType, req.Page, req.PageSize, req.Favorited)
|
||||
res = &WaylinesRes{}
|
||||
res.List = []Wayline{}
|
||||
return
|
||||
}
|
32
api/pilot/ws/ws.go
Normal file
32
api/pilot/ws/ws.go
Normal file
@ -0,0 +1,32 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type WS struct {
|
||||
}
|
||||
|
||||
type WsReq struct {
|
||||
g.Meta `path:"ws2" summary:"ws2" method:"get" tags:"无人机"`
|
||||
}
|
||||
|
||||
type UsualRes struct {
|
||||
}
|
||||
|
||||
func (receiver *WS) WSConnect(ctx context.Context, req *WsReq) (res *UsualRes, err error) {
|
||||
r := ghttp.RequestFromCtx(ctx)
|
||||
ws, err := r.WebSocket()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for {
|
||||
_, _, err := ws.ReadMessage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//fmt.Println(msgType, string(msg))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user