Class: C0f::CANPacketStat
- Inherits:
-
Object
- Object
- C0f::CANPacketStat
- Defined in:
- lib/c0f/can_packet_stat.rb
Instance Attribute Summary collapse
-
#dynamic ⇒ Object
readonly
Returns the value of attribute dynamic.
-
#pkt_count ⇒ Object
readonly
Returns the value of attribute pkt_count.
-
#pkts ⇒ Object
readonly
Returns the value of attribute pkts.
Instance Method Summary collapse
-
#add(pkt) ⇒ Object
Adds a CANPacket to the stats.
-
#initialize ⇒ CANPacketStat
constructor
A new instance of CANPacketStat.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CANPacketStat
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
#dynamic ⇒ Object (readonly)
Returns the value of attribute dynamic.
3 4 5 |
# File 'lib/c0f/can_packet_stat.rb', line 3 def dynamic @dynamic end |
#pkt_count ⇒ Object (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 |
#pkts ⇒ Object (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
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_s ⇒ Object
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 |