feat: add legacy router and models
This commit is contained in:
parent
7cc69bc977
commit
e04e311ff4
33
api/legacy/models.go
Normal file
33
api/legacy/models.go
Normal file
@ -0,0 +1,33 @@
|
||||
package legacy
|
||||
|
||||
// FingerPoseRequest 手指姿态设置请求
|
||||
type FingerPoseRequest struct {
|
||||
Interface string `json:"interface,omitempty"`
|
||||
Pose []byte `json:"pose" binding:"required,len=6"`
|
||||
HandType string `json:"handType,omitempty"` // 新增:手型类型
|
||||
HandId uint32 `json:"handId,omitempty"` // 新增:CAN ID
|
||||
}
|
||||
|
||||
// PalmPoseRequest 掌部姿态设置请求
|
||||
type PalmPoseRequest struct {
|
||||
Interface string `json:"interface,omitempty"`
|
||||
Pose []byte `json:"pose" binding:"required,len=4"`
|
||||
HandType string `json:"handType,omitempty"` // 新增:手型类型
|
||||
HandId uint32 `json:"handId,omitempty"` // 新增:CAN ID
|
||||
}
|
||||
|
||||
// AnimationRequest 动画控制请求
|
||||
type AnimationRequest struct {
|
||||
Interface string `json:"interface,omitempty"`
|
||||
Type string `json:"type" binding:"required,oneof=wave sway stop"`
|
||||
Speed int `json:"speed" binding:"min=0,max=2000"`
|
||||
HandType string `json:"handType,omitempty"` // 新增:手型类型
|
||||
HandId uint32 `json:"handId,omitempty"` // 新增:CAN ID
|
||||
}
|
||||
|
||||
// HandTypeRequest 手型设置请求
|
||||
type HandTypeRequest struct {
|
||||
Interface string `json:"interface" binding:"required"`
|
||||
HandType string `json:"handType" binding:"required,oneof=left right"`
|
||||
HandId uint32 `json:"handId" binding:"required"`
|
||||
}
|
64
api/legacy/router.go
Normal file
64
api/legacy/router.go
Normal file
@ -0,0 +1,64 @@
|
||||
package legacy
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"hands/device"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type LegacyServer struct {
|
||||
mapper *InterfaceDeviceMapper
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
// NewLegacyServer 创建新的兼容层 API 服务器实例
|
||||
func NewLegacyServer(deviceManager *device.DeviceManager) (*LegacyServer, error) {
|
||||
mapper, err := NewInterfaceDeviceMapper(deviceManager)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &LegacyServer{
|
||||
mapper: mapper,
|
||||
startTime: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetupRoutes 设置兼容层 API 路由
|
||||
func (s *LegacyServer) SetupRoutes(r *gin.Engine) {
|
||||
// 兼容层 API 路由组
|
||||
legacy := r.Group("/api/legacy")
|
||||
{
|
||||
// 手型设置 API
|
||||
legacy.POST("/hand-type", s.handleHandType)
|
||||
|
||||
// 手指姿态 API
|
||||
legacy.POST("/fingers", s.handleFingers)
|
||||
|
||||
// 掌部姿态 API
|
||||
legacy.POST("/palm", s.handlePalm)
|
||||
|
||||
// 预设姿势 API
|
||||
legacy.POST("/preset/:pose", s.handlePreset)
|
||||
|
||||
// 动画控制 API
|
||||
legacy.POST("/animation", s.handleAnimation)
|
||||
|
||||
// 获取传感器数据 API
|
||||
legacy.GET("/sensors", s.handleSensors)
|
||||
|
||||
// 系统状态 API
|
||||
legacy.GET("/status", s.handleStatus)
|
||||
|
||||
// 获取可用接口列表 API
|
||||
legacy.GET("/interfaces", s.handleInterfaces)
|
||||
|
||||
// 获取手型配置 API
|
||||
legacy.GET("/hand-configs", s.handleHandConfigs)
|
||||
|
||||
// 健康检查端点
|
||||
legacy.GET("/health", s.handleHealth)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user