mirror of
https://github.com/kerberos-io/onvif.git
synced 2025-10-08 01:00:13 +08:00
xml processing
This commit is contained in:
@@ -7,11 +7,12 @@ import (
|
|||||||
"github.com/beevik/etree"
|
"github.com/beevik/etree"
|
||||||
"github.com/yakovlevdmv/gosoap"
|
"github.com/yakovlevdmv/gosoap"
|
||||||
"strconv"
|
"strconv"
|
||||||
"github.com/yakovlevdmv/WS-Discovery"
|
|
||||||
"github.com/yakovlevdmv/goonvif/Networking"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/yakovlevdmv/goonvif/Device"
|
"github.com/yakovlevdmv/goonvif/Device"
|
||||||
|
"github.com/yakovlevdmv/goonvif/networking"
|
||||||
|
"github.com/yakovlevdmv/WS-Discovery"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var xlmns = map[string]string {
|
var xlmns = map[string]string {
|
||||||
@@ -170,6 +171,10 @@ func (dev device) CallMethod(method interface{}) (string, error) {
|
|||||||
case "PTZ": endpoint = dev.endpoints["PTZ"]
|
case "PTZ": endpoint = dev.endpoints["PTZ"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(endpoint) == 0 {
|
||||||
|
return "", errors.New("Requested service is not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Get endpoint automatically
|
//TODO: Get endpoint automatically
|
||||||
if dev.login != "" && dev.password != "" {
|
if dev.login != "" && dev.password != "" {
|
||||||
return dev.CallAuthorizedMethod(endpoint, method)
|
return dev.CallAuthorizedMethod(endpoint, method)
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package PTZ
|
package PTZ
|
||||||
|
|
||||||
import "github.com/yakovlevdmv/goonvif/xsd"
|
import (
|
||||||
import "github.com/yakovlevdmv/goonvif/xsd/onvif"
|
"github.com/yakovlevdmv/goonvif/xsd"
|
||||||
|
"github.com/yakovlevdmv/goonvif/xsd/onvif"
|
||||||
|
)
|
||||||
|
|
||||||
type Capabilities struct {
|
type Capabilities struct {
|
||||||
EFlip xsd.Boolean `xml:"EFlip,attr"`
|
EFlip xsd.Boolean `xml:"EFlip,attr"`
|
||||||
|
77
api/api.go
77
api/api.go
@@ -1,37 +1,66 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
|
||||||
"github.com/yakovlevdmv/goonvif"
|
"github.com/yakovlevdmv/goonvif"
|
||||||
"github.com/yakovlevdmv/goonvif/Device"
|
"github.com/yakovlevdmv/goonvif/Device"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunApi () {
|
//func RunApi () {
|
||||||
router := gin.Default()
|
// router := gin.Default()
|
||||||
|
//
|
||||||
|
// router.POST("/:service/:method", func(c *gin.Context) {
|
||||||
|
// serviceName := c.Param("service")
|
||||||
|
// methodName := c.Param("method")
|
||||||
|
// message := callNecessaryMethod(&serviceName, &methodName, "192.168.13.12")
|
||||||
|
// c.XML(http.StatusOK, message)
|
||||||
|
// })
|
||||||
|
// router.Run()
|
||||||
|
//}
|
||||||
|
|
||||||
device := goonvif.NewDevice()
|
func soapHandling(tp interface{}, tags* map[string]string) {
|
||||||
data, err := device.CallMethod("http://192.168.13.12/onvif/device_service", Device.GetCapabilities{Category:"All"})
|
ifaceValue := reflect.ValueOf(tp).Elem()
|
||||||
//_=data
|
typeOfStruct := ifaceValue.Type()
|
||||||
|
if ifaceValue.Kind() != reflect.Struct {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < ifaceValue.NumField(); i++ {
|
||||||
|
field := ifaceValue.Field(i)
|
||||||
|
tg, err := typeOfStruct.FieldByName(typeOfStruct.Field(i).Name)
|
||||||
|
if err == false {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
(*tags)[typeOfStruct.Field(i).Name] = string(tg.Tag)
|
||||||
|
|
||||||
|
subStruct := reflect.New(reflect.TypeOf( field.Interface() ))
|
||||||
|
soapHandling(subStruct.Interface(), tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func callNecessaryMethod(serviceName* string, methodName* string, deviceXaddr* string) *string {
|
||||||
|
switch *serviceName {
|
||||||
|
case "Device", "device":
|
||||||
|
return callDeviceMethods(methodName, deviceXaddr)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func callDeviceMethods(methodName* string, deviceXaddr* string) *string {
|
||||||
|
switch *methodName {
|
||||||
|
case "GetCapabilities":
|
||||||
|
return GetCapabilities(deviceXaddr)
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCapabilities(deviceXaddr* string) *string {
|
||||||
|
device := goonvif.NewDevice(*deviceXaddr)
|
||||||
|
data, err := device.CallMethod(Device.GetCapabilities{Category:"All"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
return &data
|
||||||
router.GET("/:dima", func(c *gin.Context) {
|
|
||||||
//name := c.Param("name")
|
|
||||||
c.XML(http.StatusOK, data)
|
|
||||||
})
|
|
||||||
router.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func callNecessaryMethod(serviceName, methodName string) {
|
|
||||||
switch serviceName {
|
|
||||||
case "Device", "device":
|
|
||||||
callDeviceMethonds(methodName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func callDeviceMethonds(methodName string) {
|
|
||||||
|
|
||||||
}
|
}
|
69
api/get_structs.go
Normal file
69
api/get_structs.go
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/yakovlevdmv/goonvif/PTZ"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetPTZStructByName(name string) (interface{}, error) {
|
||||||
|
switch name {
|
||||||
|
case "GetServiceCapabilities":
|
||||||
|
return &PTZ.GetServiceCapabilities{}, nil
|
||||||
|
case "GetNodes":
|
||||||
|
return &PTZ.GetNodes{}, nil
|
||||||
|
case "GetNode":
|
||||||
|
return &PTZ.GetNode{}, nil
|
||||||
|
case "GetConfiguration":
|
||||||
|
return &PTZ.GetConfiguration{}, nil
|
||||||
|
case "GetConfigurations":
|
||||||
|
return &PTZ.GetConfigurations{}, nil
|
||||||
|
case "SetConfiguration":
|
||||||
|
return &PTZ.SetConfiguration{}, nil
|
||||||
|
case "GetConfigurationOptions":
|
||||||
|
return &PTZ.GetConfigurationOptions{}, nil
|
||||||
|
case "SendAuxiliaryCommand":
|
||||||
|
return &PTZ.SendAuxiliaryCommand{}, nil
|
||||||
|
case "GetPresets":
|
||||||
|
return &PTZ.GetPresets{}, nil
|
||||||
|
case "SetPreset":
|
||||||
|
return &PTZ.SetPreset{}, nil
|
||||||
|
case "RemovePreset":
|
||||||
|
return &PTZ.RemovePreset{}, nil
|
||||||
|
case "GotoPreset":
|
||||||
|
return &PTZ.GotoPreset{}, nil
|
||||||
|
case "GotoHomePosition":
|
||||||
|
return &PTZ.GotoHomePosition{}, nil
|
||||||
|
case "SetHomePosition":
|
||||||
|
return &PTZ.SetHomePosition{}, nil
|
||||||
|
case "ContinuousMove":
|
||||||
|
return &PTZ.ContinuousMove{}, nil
|
||||||
|
case "RelativeMove":
|
||||||
|
return &PTZ.RelativeMove{}, nil
|
||||||
|
case "GetStatus":
|
||||||
|
return &PTZ.GetStatus{}, nil
|
||||||
|
case "AbsoluteMove":
|
||||||
|
return &PTZ.AbsoluteMove{}, nil
|
||||||
|
case "GeoMove":
|
||||||
|
return &PTZ.GeoMove{}, nil
|
||||||
|
case "Stop":
|
||||||
|
return &PTZ.Stop{}, nil
|
||||||
|
case "GetPresetTours":
|
||||||
|
return &PTZ.GetPresetTours{}, nil
|
||||||
|
case "GetPresetTour":
|
||||||
|
return &PTZ.GetPresetTour{}, nil
|
||||||
|
case "GetPresetTourOptions":
|
||||||
|
return &PTZ.GetPresetTourOptions{}, nil
|
||||||
|
case "CreatePresetTour":
|
||||||
|
return &PTZ.CreatePresetTour{}, nil
|
||||||
|
case "ModifyPresetTour":
|
||||||
|
return &PTZ.ModifyPresetTour{}, nil
|
||||||
|
case "OperatePresetTour":
|
||||||
|
return &PTZ.OperatePresetTour{}, nil
|
||||||
|
case "RemovePresetTour":
|
||||||
|
return &PTZ.RemovePresetTour{}, nil
|
||||||
|
case "GetCompatibleConfigurations":
|
||||||
|
return &PTZ.GetCompatibleConfigurations{}, nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("invalid structure")
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user