mirror of
https://github.com/cedricve/go-onvif.git
synced 2025-10-04 00:06:25 +08:00
Add method to fetch device information
This commit is contained in:
50
device.go
50
device.go
@@ -1,10 +1,46 @@
|
|||||||
package onvif
|
package onvif
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
)
|
||||||
|
|
||||||
var deviceXMLNs = []string{
|
var deviceXMLNs = []string{
|
||||||
`xmlns:tds="http://www.onvif.org/ver10/device/wsdl"`,
|
`xmlns:tds="http://www.onvif.org/ver10/device/wsdl"`,
|
||||||
`xmlns:tt="http://www.onvif.org/ver10/schema"`,
|
`xmlns:tt="http://www.onvif.org/ver10/schema"`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDeviceInformation fetch information of ONVIF camera
|
||||||
|
func (device Device) GetDeviceInformation() (DeviceInformation, error) {
|
||||||
|
// Create initial result
|
||||||
|
result := DeviceInformation{}
|
||||||
|
|
||||||
|
// Create SOAP
|
||||||
|
soap := SOAP{
|
||||||
|
Body: "<tds:GetDeviceInformation/>",
|
||||||
|
XMLNs: deviceXMLNs,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send SOAP request
|
||||||
|
response, err := soap.SendRequest(device.XAddr)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse response to interface
|
||||||
|
deviceInfo, err := response.ValueForPath("Envelope.Body.GetDeviceInformationResponse")
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse interface to struct
|
||||||
|
err = device.interfaceToStruct(&deviceInfo, &result)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetSystemDateAndTime fetch date and time from ONVIF camera
|
// GetSystemDateAndTime fetch date and time from ONVIF camera
|
||||||
func (device Device) GetSystemDateAndTime() (string, error) {
|
func (device Device) GetSystemDateAndTime() (string, error) {
|
||||||
// Create SOAP
|
// Create SOAP
|
||||||
@@ -23,3 +59,17 @@ func (device Device) GetSystemDateAndTime() (string, error) {
|
|||||||
dateTime, _ := response.ValueForPathString("Envelope.Body.GetSystemDateAndTimeResponse.SystemDateAndTime")
|
dateTime, _ := response.ValueForPathString("Envelope.Body.GetSystemDateAndTimeResponse.SystemDateAndTime")
|
||||||
return dateTime, nil
|
return dateTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (device Device) interfaceToStruct(src, dst interface{}) error {
|
||||||
|
bt, err := json.Marshal(&src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(bt, &dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
9
model.go
9
model.go
@@ -8,3 +8,12 @@ type Device struct {
|
|||||||
User string
|
User string
|
||||||
Password string
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeviceInformation contains information of ONVIF camera
|
||||||
|
type DeviceInformation struct {
|
||||||
|
FirmwareVersion string
|
||||||
|
HardwareID string
|
||||||
|
Manufacturer string
|
||||||
|
Model string
|
||||||
|
SerialNumber string
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user