Module AxisNetcam::Camera::Info
In: lib/axis-netcam/camera.rb

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

Methods

Public Instance methods

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}

[Source]

# File lib/axis-netcam/camera.rb, line 388
      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

Returns the camera‘s model name.

[Source]

# File lib/axis-netcam/camera.rb, line 457
      def model
        extract_value_pairs_from_server_report(['prodshortname'])['prodshortname']
      end

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.

[Source]

# File lib/axis-netcam/camera.rb, line 441
      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()

Alias for status_code

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).

[Source]

# File lib/axis-netcam/camera.rb, line 472
      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

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.

[Source]

# File lib/axis-netcam/camera.rb, line 497
      def status_message
        if @status_message
          @status_message
        else
          status_code
          @status_message
        end
      end

[Validate]