Class: C0f::CANPacketStat

Inherits:
Object
  • Object
show all
Defined in:
lib/c0f/can_packet_stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCANPacketStat

Returns a new instance of CANPacketStat.



4
5
6
7
8
# File 'lib/c0f/can_packet_stat.rb', line 4

def initialize
  @pkts = Hash.new
  @pkt_count = 0  # Sample size
  @dynamic = false
end

Instance Attribute Details

#dynamicObject (readonly)

Returns the value of attribute dynamic.



3
4
5
# File 'lib/c0f/can_packet_stat.rb', line 3

def dynamic
  @dynamic
end

#pkt_countObject (readonly)

Returns the value of attribute pkt_count.



3
4
5
# File 'lib/c0f/can_packet_stat.rb', line 3

def pkt_count
  @pkt_count
end

#pktsObject (readonly)

Returns the value of attribute pkts.



3
4
5
# File 'lib/c0f/can_packet_stat.rb', line 3

def pkts
  @pkts
end

Instance Method Details

#add(pkt) ⇒ Object

Adds a CANPacket to the stats

Parameters:



12
13
14
15
16
17
18
19
20
# File 'lib/c0f/can_packet_stat.rb', line 12

def add(pkt)
  if @pkts.has_key? pkt.id then
    @pkts[pkt.id].update pkt
  else
    @pkts[pkt.id] = pkt
  end
  @pkt_count += 1
  @dynamic = true if pkt.dlc < 8
end

#to_sObject



22
23
24
25
26
27
28
29
30
# File 'lib/c0f/can_packet_stat.rb', line 22

def to_s
  s = "Packet Count (Sample Size): #{@pkt_count}\n"
  s += "Dynamic bus: #{@dynamic}\n"
  s += "[Packet Stats]\n"
  @pkts.each_value do |pkt|
    s += " #{pkt.id} [#{pkt.dlc}] interval #{pkt.avg_delta} count #{pkt.count}\n"
  end
  s
end