Module: AxisNetcam::Camera::Info

Included in:
AxisNetcam::Camera
Defined in:
lib/axis-netcam/camera.rb

Overview

Functionality related to obtaining information about the camera, such as its status, model number, etc.

Instance Method Summary collapse

Instance Method Details

#get_parameters(group = nil) ⇒ Object

Returns a hash enumerating the camera’s various parameters. The group parameter limits the returned values to the given group. Note that if given, the group is removed from the parameter names.

For example:

c.get_parameters("PTZ.Limit")

Returns:

{"L1.MaxFocus"=>9999, "L1.MaxFieldAngle"=>50, "L1.MaxTilt"=>10, 
 "L1.MinFieldAngle"=>1, "L1.MaxPan"=>169, "L1.MaxIris"=>9999, 
 "L1.MaxZoom"=>19999, "L1.MinFocus"=>1, "L1.MinPan"=>-169, 
 "L1.MinIris"=>1, "L1.MinZoom"=>1, "L1.MinTilt"=>-90}

But the following:

c.get_parameters("PTZ.Limit.L1")

Returns:

{"MaxIris"=>9999, "MaxZoom"=>19999, "MaxTilt"=>10, "MaxFocus"=>9999,
 "MaxPan"=>169, "MinFieldAngle"=>1, "MinTilt"=>-90, "MinPan"=>-169, 
 "MinIris"=>1, "MinZoom"=>1, "MinFocus"=>1, "MaxFieldAngle"=>50}


382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/axis-netcam/camera.rb', line 382

def get_parameters(group = nil)
  params = {
    'action' => 'list', 
    'responseformat' => 'rfc'
  }
  params['group'] = group if group
  
  response = axis_action("admin/param.cgi", params)
  
  if response =~ /Error -1 getting param in group '.*?'!/
    raise RemoteError, "There is no parameter group '#{group}' on this camera."
  end
  
  values = {}
  response.each do |line|
    k,v = line.split("=")
    k.strip!
    
    if v.nil?
      v = nil
    else
      case v.strip
      when /^true$/
        v = true
      when /^false$/
        v = false
      when /^[-]?[0-9]+$/
        v = v.to_i
      when /^[-]?[0-9]+\.?[0-9]+$/
        v = v.to_f
      else
        v = v.strip
      end
    end
  
    key = k.gsub(group ? "root.#{group}." : "root.", "")
    
    values[key] = v
  end
  
  values
end

#modelObject

Returns the camera’s model name.



451
452
453
# File 'lib/axis-netcam/camera.rb', line 451

def model
  extract_value_pairs_from_server_report(['prodshortname'])['prodshortname']
end

#server_report(force_refresh = false) ⇒ Object

Returns the raw camera server report.

The report is a string with info about the camera’s status and parameters, and differs considerably from model to model.

If you have the Easycache Rails plugin installed, report data will be cached unless the force_refresh argument is true. This is done to help improve performance, as the server_report method is often called by other methods to retrieve various camera info.



435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/axis-netcam/camera.rb', line 435

def server_report(force_refresh = false)
  if Object.const_defined? "Easycache"
    if force_refresh
      Easycache.write("#{hostname}_server_report",
        @report = axis_action("admin/serverreport.cgi"))
    else
      @report ||= Easycache.cache("#{hostname}_server_report") do
        axis_action("admin/serverreport.cgi")
      end
    end
  else
    axis_action("admin/serverreport.cgi")
  end
end

#status_codeObject Also known as: status

Returns a code describing the camera’s current status. The codes are as follows:

:ok

Camera is responding as expected.

:down

Camera is not responding at all (connection is timing out).

:error

Camera responded with an error.

:no_server_report

Camera responded but for some reason did not return a server report.

Calling this method updates the @status_message attribute with some more detailed information about the camera’s status (for example, the full error message in case of an error).



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/axis-netcam/camera.rb', line 466

def status_code
  begin
    if self.server_report(true).empty?
      @status_message = "Server did not send report"
      :no_server_report
    else
      @status_message = "OK"
      :ok
    end
  rescue InvalidLogin => e
    @status_message = "Invalid login"
    :invalid_login
  rescue RemoteTimeout => e
    @status_message = "Timeout"
    :down
  rescue RemoteError => e
    @status_message = "Error: #{e}"
    :error
  end
end

#status_messageObject

Returns the result of the status message resulting from the last status_code call. If no status message is available, status_code will be automatically called first.



491
492
493
494
495
496
497
498
# File 'lib/axis-netcam/camera.rb', line 491

def status_message
  if @status_message
    @status_message
  else
    status_code
    @status_message
  end
end