-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install fix and discover command (#14)
* fixes install process, adds prefix to commands and adds new discovery command * adds new command to Makefile
- Loading branch information
Showing
11 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jessevdk/go-flags" | ||
"github.com/path-variable/onvif-cam-poll/pkg/model" | ||
"github.com/path-variable/onvif-cam-poll/pkg/utils" | ||
"github.com/use-go/onvif" | ||
"os" | ||
"strings" | ||
"time" | ||
) | ||
|
||
const commandName = "onvif-discover-all" | ||
|
||
func main() { | ||
var opts discoverAllOptions | ||
_, err := flags.ParseArgs(&opts, os.Args) | ||
|
||
if err != nil { | ||
fmt.Printf(utils.ArgParseError, err) | ||
return | ||
} | ||
|
||
for { | ||
fmt.Printf(utils.CommandSend, commandName) | ||
res, err := onvif.GetAvailableDevicesAtSpecificEthernetInterface(opts.Interface) | ||
if err != nil { | ||
fmt.Printf(utils.CommandError, commandName, err) | ||
return | ||
} | ||
|
||
fmt.Printf("Discovered %d devices on interface %s\n", len(res), opts.Interface) | ||
|
||
for i := 0; i < len(res); i++ { | ||
dev := res[i] | ||
fmt.Printf("Device at %s\n", getAddressFromServices(dev)) | ||
} | ||
|
||
fmt.Printf(utils.SleepTemplate, opts.CooldownTimer) | ||
time.Sleep(time.Duration(opts.CooldownTimer) * time.Second) | ||
} | ||
|
||
} | ||
|
||
func getAddressFromServices(device onvif.Device) string { | ||
val, found := device.GetServices()["device"] | ||
if found { | ||
return getAddressFromUrl(val) | ||
} | ||
return "" | ||
} | ||
|
||
func getAddressFromUrl(url string) string { | ||
return strings.Split(url, ":")[1][2:] | ||
} | ||
|
||
type discoverAllOptions struct { | ||
model.CooldownParameters | ||
model.InterfaceParameters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.