-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion_detection.go
71 lines (64 loc) · 1.93 KB
/
motion_detection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package axisevents simplifies the configuration of events such as record video to sd-card when the device detects motion detection
package axisevents
// Device holds the connection info for the device
type Device struct {
Username string
Password string
Address string // Address must be in format of http://ip/ or http://hostname/ or if the device is configured for ssl https://ip/
}
// NewMotionDetectionHandler creates a new MotionDetectionHandler which is used
// to define what happens when a device detects motion.
//
// Supported versions:
// 2,3,4 defaults to version 2
// Supported actions:
// Record video to the device SD-card.
func NewMotionDetectionHandler(
name string,
enabled bool,
version int,
) *MotionDetectionHandler {
var topicExpression string
switch version {
case 2:
topicExpression = "tns1:RuleEngine/tnsaxis:VideoMotionDetection/motion"
case 3:
topicExpression = ""
case 4:
topicExpression = "tnsaxis:CameraApplicationPlatform/VMD/Camera1ProfileANY"
default:
topicExpression = "tns1:RuleEngine/tnsaxis:VideoMotionDetection/motion"
}
collector := collector{
name: name,
enabled: enabled,
version: version,
topicExpression: topicExpression,
messageContent: `boolean(//SimpleItem[@Name="active" and @Value="1"])`,
properties: make(map[string]interface{}),
}
return &MotionDetectionHandler{
collector: collector,
}
}
type MotionDetectionHandler struct {
collector collector
}
// HttpNotification sends http notifications when motion is detected.
func (h *MotionDetectionHandler) HttpNotification() *HttpNotificationHandler {
return &HttpNotificationHandler{
collector: h.collector,
}
}
// Record motion.
func (h *MotionDetectionHandler) Record() RecordVideoHandler {
return &recordVideoHandler{
collector: h.collector,
}
}
// Send video clip.
func (h *MotionDetectionHandler) VideoClip() *SendVideoClipper {
return &SendVideoClipper{
collector: h.collector,
}
}