From 5240ac49054f5487e5acf9e0f1ee3795bed66274 Mon Sep 17 00:00:00 2001 From: webermarci Date: Thu, 15 Jun 2023 12:28:13 +0200 Subject: [PATCH] Add camera response duration and remove uuid and timestamp --- go.mod | 4 +--- go.sum | 2 -- hikrec.go | 17 +++++++---------- onvif.go | 13 ++++--------- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 8cd516e..d90a529 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module github.com/webermarci/hikrec -go 1.19 - -require github.com/google/uuid v1.3.0 +go 1.20 diff --git a/go.sum b/go.sum index 3dfe1c9..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/hikrec.go b/hikrec.go index 5e95465..21f5ded 100644 --- a/hikrec.go +++ b/hikrec.go @@ -1,8 +1,6 @@ package hikrec -import ( - "time" -) +import "time" type Direction string @@ -13,11 +11,10 @@ const ( ) type Recognition struct { - UUID string `json:"uuid"` - Timestamp time.Time `json:"timestamp"` - Plate string `json:"plate"` - Confidence int `json:"confidence"` - Direction Direction `json:"direction"` - Country string `json:"country"` - Nation string `json:"nation"` + Plate string `json:"plate"` + Confidence int `json:"confidence"` + Direction Direction `json:"direction"` + Country string `json:"country"` + Nation string `json:"nation"` + CameraResponseDuration time.Duration `json:"camera_response_duration"` } diff --git a/onvif.go b/onvif.go index 69883ba..c8ebb12 100644 --- a/onvif.go +++ b/onvif.go @@ -3,8 +3,6 @@ package hikrec import ( "strconv" "time" - - "github.com/google/uuid" ) type envelope struct { @@ -129,10 +127,10 @@ func (device *Device) PullRecognitions() (chan Recognition, error) { go func() { for { + start := time.Now() + messages, err := device.pullMessage(device.Url, pullAddress) if err != nil { - time.Sleep(time.Second) - res, err := device.createPullPointSubscription() for err != nil { time.Sleep(time.Second) @@ -147,10 +145,7 @@ func (device *Device) PullRecognitions() (chan Recognition, error) { } for _, message := range messages { - recognition := Recognition{ - UUID: uuid.NewString(), - Timestamp: time.Now(), - } + recognition := Recognition{} for _, item := range message.Data.Items { switch item.Name { @@ -185,9 +180,9 @@ func (device *Device) PullRecognitions() (chan Recognition, error) { continue } + recognition.CameraResponseDuration = time.Since(start) outgoing <- recognition } - } }()