From f7b4a33f5ea87e0d7eb11f3b95efb1a12bc8a6ce Mon Sep 17 00:00:00 2001 From: nasseeder1 Date: Sun, 8 Oct 2017 07:20:38 +0000 Subject: [PATCH] 49_SSCam: V3.2.3, new optimizeParams command to set cam properties git-svn-id: https://svn.fhem.de/fhem/trunk@15212 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 1 + fhem/FHEM/49_SSCam.pm | 209 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 185 insertions(+), 25 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 3e8e626fe..3acbc0fc6 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,6 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 49_SSCam: V3.2.3, new optimizeParams command to set cam properties - bugfix: 72_FB_CALLMONITOR: fix wrong reverse-search of emergency call (110/112/...), fix missing deletion of phonebook on reread. - change: 93_DbRep: V5.6.4, use new Blocking.pm abortArg diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index 89db49dc7..5b4e2f953 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -27,6 +27,7 @@ ######################################################################################################################### # Versions History: # +# 3.2.3 08.10.2017 set optimizeParams, get caminfo (simple), minor bugfix, commandref revised # 3.2.2 03.10.2017 make functions ready to use "SYNO.SurveillanceStation.PTZ" version 5, minor fixes, commandref # revised # 3.2.1 02.10.2017 change some "SYNO.SurveillanceStation.Camera" methods to version 9 @@ -204,7 +205,7 @@ use Time::HiRes; use HttpUtils; # no if $] >= 5.017011, warnings => 'experimental'; -my $SSCamVersion = "3.2.2"; +my $SSCamVersion = "3.2.3"; # Aufbau Errorcode-Hashes (siehe Surveillance Station Web API) my %SSCam_errauthlist = ( @@ -552,6 +553,7 @@ sub SSCam_Set { "createSnapGallery:noArg ". "enable ". "disable ". + "optimizeParams ". "runView:live_fw,live_link,live_open,lastrec_fw,lastrec_open,lastsnap_fw ". "stopView:noArg ". ((ReadingsVal("$name", "CapPTZPan", "false") ne "false") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : ""). @@ -698,6 +700,15 @@ sub SSCam_Set { $hash->{HELPER}{PTZACTION} = "gopreset"; doptzaction($hash); + } elsif ($opt eq "optimizeParams" && IsModelCam($hash)) { + if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} + + my %cpcl = (ntp => 1, mirror => 2, flip => 4, rotate => 8); + extoptpar($hash,$prop,\%cpcl) if($prop); + extoptpar($hash,$prop1,\%cpcl) if($prop1); + extoptpar($hash,$prop2,\%cpcl) if($prop2); + setoptpar($hash); + } elsif ($opt eq "runPatrol" && IsModelCam($hash)) { if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} if (!$prop) {return "Function \"runPatrol\" needs a \"Patrolname\" as an argument";} @@ -840,6 +851,7 @@ sub SSCam_Get { # selist für Cams $getlist = "Unknown argument $opt, choose one of ". "caminfoall:noArg ". + "caminfo:noArg ". ((AttrVal($name,"snapGalleryNumber",undef) || AttrVal($name,"snapGalleryBoost",0)) ?"snapGallery:noArg ":"snapGallery:$SSCAM_snum "). "snapinfo:noArg ". @@ -864,7 +876,12 @@ sub SSCam_Get { return if(IsDisabled($name)); - if ($opt eq "caminfoall") { + if ($opt eq "caminfo") { + # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine + if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} + getcaminfo($hash); + + } elsif ($opt eq "caminfoall") { # "1" ist Statusbit für manuelle Abfrage, kein Einstieg in Pollingroutine if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} getcaminfoall($hash,1); @@ -1947,6 +1964,32 @@ sub sethomemode ($) { } } +########################################################################### +# Optimierparameter setzen +########################################################################### +sub setoptpar ($) { + my ($hash) = @_; + my $camname = $hash->{CAMNAME}; + my $name = $hash->{NAME}; + + return if(IsDisabled($name)); + + if ($hash->{HELPER}{ACTIVE} eq "off") { + $hash->{OPMODE} = "setoptpar"; + $hash->{HELPER}{ACTIVE} = "on"; + $hash->{HELPER}{LOGINRETRIES} = 0; + + if ($attr{$name}{debugactivetoken}) { + Log3($name, 3, "$name - Active-Token was set by OPMODE: $hash->{OPMODE}"); + } + sscam_getapisites($hash); + + } else { + RemoveInternalTimer($hash, "setoptpar"); + InternalTimer(gettimeofday()+0.6, "setoptpar", $hash, 0); + } +} + ########################################################################### # HomeMode Status abfragen ########################################################################### @@ -2492,6 +2535,20 @@ sub sscam_getapisites_parse ($) { $actvs .= ($vl[2] =~ /\d/)?$vl[2]."xxxx":$vl[2]; $actvs .= "-simu"; } + + # Downgrades für nicht kompatible API-Versionen + # hier nur nutzen wenn API zentral downgraded werden soll + # In den neueren API-Upgrades werden nur einzelne Funktionen auf eine höhere API-Version gezogen + # -> diese Steuerung erfolgt in den einzelnen Funktionsaufrufen in sscam_camop + Log3($name, 4, "$name - ------- Begin of adaption section -------"); + + #$apiptzmaxver = 4; + #Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver"); + #$apicammaxver = 8; + #Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver"); + + Log3($name, 4, "$name - ------- End of adaption section -------"); + # Simulation anderer SVS-Versionen Log3($name, 4, "$name - ------- Begin of simulation section -------"); @@ -2531,17 +2588,7 @@ sub sscam_getapisites_parse ($) { Log3($name, 4, "$name - no simulations done !"); } Log3($name, 4, "$name - ------- End of simulation section -------"); - - # Downgrades für nicht kompatible API-Versionen - Log3($name, 4, "$name - ------- Begin of adaption section -------"); - - #$apiptzmaxver = 4; - #Log3($name, 4, "$name - MaxVersion of $apiptz adapted to: $apiptzmaxver"); - # $apicammaxver = 8; - # Log3($name, 4, "$name - MaxVersion of $apicam adapted to: $apicammaxver"); - - Log3($name, 4, "$name - ------- End of adaption section -------"); - + # ermittelte Werte in $hash einfügen $hash->{HELPER}{APIAUTHPATH} = $apiauthpath; $hash->{HELPER}{APIAUTHMAXVER} = $apiauthmaxver; @@ -2848,7 +2895,8 @@ sub sscam_camop ($) { Log3($name, 4, "$name - --- Begin Function $OpMode nonblocking ---"); - $httptimeout = $attr{$name}{httptimeout} ? $attr{$name}{httptimeout} : "4"; + $httptimeout = AttrVal($name, "httptimeout", 4); + $httptimeout = $httptimeout+90 if($OpMode eq "setoptpar"); # setzen der Optimierungsparameter dauert lange ! Log3($name, 5, "$name - HTTP-Call will be done with httptimeout-Value: $httptimeout s"); @@ -2929,7 +2977,7 @@ sub sscam_camop ($) { my $sev = $hash->{HELPER}{LISTLOGSEVERITY}?$hash->{HELPER}{LISTLOGSEVERITY}:""; my $lim = $hash->{HELPER}{LISTLOGLIMIT}?$hash->{HELPER}{LISTLOGLIMIT}:0; my $mco = $hash->{HELPER}{LISTLOGMATCH}?$hash->{HELPER}{LISTLOGMATCH}:""; - my $mco = IsModelCam($hash)?$hash->{CAMNAME}:$mco; + $mco = IsModelCam($hash)?$hash->{CAMNAME}:$mco; $lim = 1 if(!$hash->{HELPER}{CL}{1}); # Datenabruf im Hintergrund $sev = (lc($sev) =~ /error/)?3:(lc($sev) =~ /warning/)?2:(lc($sev) =~ /info/)?1:""; @@ -2946,6 +2994,15 @@ sub sscam_camop ($) { } elsif ($OpMode eq "getsvsinfo") { $url = "http://$serveraddr:$serverport/webapi/$apisvsinfopath?api=\"$apisvsinfo\"&version=\"$apisvsinfomaxver\"&method=\"GetInfo\"&_sid=\"$sid\""; + } elsif ($OpMode eq "setoptpar") { + my $mirr = $hash->{HELPER}{MIRROR}?$hash->{HELPER}{MIRROR}:ReadingsVal("$name","CamVideoMirror",""); + my $flip = $hash->{HELPER}{FLIP}?$hash->{HELPER}{FLIP}:ReadingsVal("$name","CamVideoFlip",""); + my $rot = $hash->{HELPER}{ROTATE}?$hash->{HELPER}{ROTATE}:ReadingsVal("$name","CamVideoRotate",""); + my $ntp = $hash->{HELPER}{NTPSERV}?$hash->{HELPER}{NTPSERV}:ReadingsVal("$name","CamNTPServer",""); + my $clst = $hash->{HELPER}{CHKLIST}?$hash->{HELPER}{CHKLIST}:""; + $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver; + $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"SaveOptimizeParam\"&vdoMirror=$mirr&vdoRotation=$rot&vdoFlip=$flip&timeServer=\"$ntp\"&camParamChkList=$clst&cameraIds=\"$camid\"&_sid=\"$sid\""; + } elsif ($OpMode eq "Getcaminfo") { $apicammaxver = ($apicammaxver >= 9)?8:$apicammaxver; $url = "http://$serveraddr:$serverport/webapi/$apicampath?api=\"$apicam\"&version=\"$apicammaxver\"&method=\"GetInfo\"&cameraIds=\"$camid\"&deviceOutCap=\"true\"&streamInfo=\"true\"&ptz=\"true\"&basic=\"true\"&camAppInfo=\"true\"&optimize=\"true\"&fisheye=\"true\"&eventDetection=\"true\"&_sid=\"$sid\""; @@ -3315,6 +3372,26 @@ sub sscam_camop_parse ($) { asyncOutput($hash->{HELPER}{CL}{1},"$log"); delete($hash->{HELPER}{CL}); + } elsif ($OpMode eq "setoptpar") { + my $rid = $data->{'data'}{'id'}; # Cam ID return wenn i.O. + my $ropt = $rid == $hash->{CAMID}?"none":"error in operation"; + + delete($hash->{HELPER}{NTPSERV}); + delete($hash->{HELPER}{MIRROR}); + delete($hash->{HELPER}{FLIP}); + delete($hash->{HELPER}{ROTATE}); + delete($hash->{HELPER}{CHKLIST}); + + readingsBeginUpdate($hash); + readingsBulkUpdate($hash,"Errorcode","none"); + readingsBulkUpdate($hash,"Error",$ropt); + readingsEndUpdate($hash, 1); + + # Token freigeben vor Abruf caminfo + $hash->{HELPER}{ACTIVE} = "off"; + RemoveInternalTimer($hash, "getcaminfo"); + InternalTimer(gettimeofday()+0.5, "getcaminfo", $hash, 0); + } elsif ($OpMode eq "MotDetSc") { readingsBeginUpdate($hash); @@ -3753,6 +3830,9 @@ sub sscam_camop_parse ($) { } else { $recStatus = "Stop"; } + + my $rotate = $data->{'data'}->{'cameras'}->[0]->{'video_rotation'}; + $rotate = $rotate == 1?"true":"false"; $exposuremode = $data->{'data'}->{'cameras'}->[0]->{'exposure_mode'}; if ($exposuremode == 0) { @@ -3803,6 +3883,7 @@ sub sscam_camop_parse ($) { readingsBulkUpdate($hash,"CamRecShare",$data->{'data'}->{'cameras'}->[0]->{'camRecShare'}); readingsBulkUpdate($hash,"CamRecVolume",$data->{'data'}->{'cameras'}->[0]->{'camRecVolume'}); readingsBulkUpdate($hash,"CamIP",$data->{'data'}->{'cameras'}->[0]->{'host'}); + readingsBulkUpdate($hash,"CamNTPServer",$data->{'data'}->{'cameras'}->[0]->{'time_server'}) if($data->{'data'}->{'cameras'}->[0]->{'time_server'}); readingsBulkUpdate($hash,"CamVendor",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camVendor'}); readingsBulkUpdate($hash,"CamPreRecTime",$data->{'data'}->{'cameras'}->[0]->{'detailInfo'}{'camPreRecTime'}); readingsBulkUpdate($hash,"CamPort",$data->{'data'}->{'cameras'}->[0]->{'port'}); @@ -3810,6 +3891,7 @@ sub sscam_camop_parse ($) { readingsBulkUpdate($hash,"CamblPresetSpeed",$data->{'data'}->{'cameras'}->[0]->{'blPresetSpeed'}); readingsBulkUpdate($hash,"CamVideoMirror",$data->{'data'}->{'cameras'}->[0]->{'video_mirror'}); readingsBulkUpdate($hash,"CamVideoFlip",$data->{'data'}->{'cameras'}->[0]->{'video_flip'}); + readingsBulkUpdate($hash,"CamVideoRotate",$rotate); readingsBulkUpdate($hash,"Availability",$camStatus); readingsBulkUpdate($hash,"DeviceType",$deviceType); readingsBulkUpdate($hash,"LastUpdateTime",$update_time); @@ -4436,6 +4518,25 @@ sub extlogargs ($$) { return; } +############################################################################### +# Helper für optimizeParams-Argumente extrahieren +############################################################################### +sub extoptpar ($$$) { + my ($hash,$a,$cpcl) = @_; + + $hash->{HELPER}{MIRROR} = (split("mirror:",$a))[1] if(lc($a) =~ m/^mirror:.*/); + $hash->{HELPER}{FLIP} = (split("flip:",$a))[1] if(lc($a) =~ m/^flip:.*/); + $hash->{HELPER}{ROTATE} = (split("rotate:",$a))[1] if(lc($a) =~ m/^rotate:.*/); + $hash->{HELPER}{NTPSERV} = (split("ntp:",$a))[1] if(lc($a) =~ m/^ntp:.*/); + + $hash->{HELPER}{CHKLIST} = ($hash->{HELPER}{NTPSERV}?$cpcl->{ntp}:0)+ + ($hash->{HELPER}{MIRROR}?$cpcl->{mirror}:0)+ + ($hash->{HELPER}{FLIP}?$cpcl->{flip}:0)+ + ($hash->{HELPER}{ROTATE}?$cpcl->{rotate}:0); + +return; +} + ############################################################################### # Clienthash übernehmen oder zusammenstellen # Identifikation ob über FHEMWEB ausgelöst oder nicht -> erstellen $hash->CL @@ -4790,7 +4891,7 @@ sub experror {
  • set ... snapGallery session: ServeillanceStation - observer
  • set ... stopView -
  • set ... credentials -
  • -
  • get ... caminfoall session: ServeillanceStation - observer
  • +
  • get ... caminfo[all] session: ServeillanceStation - observer
  • get ... eventlist session: ServeillanceStation - observer
  • get ... listLog session: ServeillanceStation - observer
  • get ... scanVirgin session: ServeillanceStation - observer
  • @@ -4963,7 +5064,7 @@ sub experror {



    + +