feat(sense): establish M1 offline intake skeleton
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
// Package onvif defines the ONVIF boundary used by Sense.
|
||||
package onvif
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Target struct {
|
||||
// EndpointRef identifies a device endpoint but must not contain credentials.
|
||||
EndpointRef string
|
||||
// CredentialRef is an opaque secret-store reference, never a password.
|
||||
CredentialRef string
|
||||
}
|
||||
|
||||
type Profile struct {
|
||||
Token string `json:"token"`
|
||||
Name string `json:"name"`
|
||||
VideoEncoder bool `json:"video_encoder"`
|
||||
}
|
||||
|
||||
type ProbeResult struct {
|
||||
Manufacturer string `json:"manufacturer"`
|
||||
Model string `json:"model"`
|
||||
FirmwareVersion string `json:"firmware_version"`
|
||||
SerialNumber string `json:"serial_number"`
|
||||
Profiles []Profile `json:"profiles"`
|
||||
StreamURI string `json:"stream_uri"`
|
||||
}
|
||||
|
||||
type Adapter interface {
|
||||
Probe(ctx context.Context, target Target) (ProbeResult, error)
|
||||
SetSystemDateAndTime(ctx context.Context, target Target, value time.Time) error
|
||||
}
|
||||
|
||||
type ErrorCode string
|
||||
|
||||
const (
|
||||
ErrorAuthentication ErrorCode = "authentication_failed"
|
||||
ErrorTimeout ErrorCode = "timeout"
|
||||
ErrorUnavailable ErrorCode = "unavailable"
|
||||
ErrorInvalidReply ErrorCode = "invalid_response"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Code ErrorCode
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *Error) Error() string {
|
||||
if e.Err == nil {
|
||||
return string(e.Code)
|
||||
}
|
||||
return fmt.Sprintf("%s: %v", e.Code, e.Err)
|
||||
}
|
||||
|
||||
func (e *Error) Unwrap() error { return e.Err }
|
||||
|
||||
func CodeOf(err error) ErrorCode {
|
||||
var onvifError *Error
|
||||
if errors.As(err, &onvifError) {
|
||||
return onvifError.Code
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return ErrorTimeout
|
||||
}
|
||||
return ErrorUnavailable
|
||||
}
|
||||
Reference in New Issue
Block a user