Class: Driver::Datecs::Fp550::Frame

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/extface/driver/datecs/fp550.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer) ⇒ Frame

Returns a new instance of Frame.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/extface/driver/datecs/fp550.rb', line 78

def initialize(buffer)
  if match = buffer.match(/\x01(.{1})(.{1})(.{1})(.*)\x04(.{6})\x05(.{4})\x03/nm)
    @frame = match.to_a.first
    @len, @seq, @cmd, @data, @status, @bcc = match.captures
  else
    if buffer[/^\x16+$/] # only ACKs
      @ack = true
    elsif buffer.index("\x15")
      @nak = true
    end
  end
end

Instance Attribute Details

#bcc ⇒ Object (readonly)

Returns the value of attribute bcc.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def bcc
  @bcc
end

#cmd ⇒ Object (readonly)

Returns the value of attribute cmd.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def cmd
  @cmd
end

#data ⇒ Object (readonly)

Returns the value of attribute data.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def data
  @data
end

#frame ⇒ Object (readonly)

Returns the value of attribute frame.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def frame
  @frame
end

#len ⇒ Object (readonly)

Returns the value of attribute len.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def len
  @len
end

#seq ⇒ Object (readonly)

Returns the value of attribute seq.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def seq
  @seq
end

#status ⇒ Object (readonly)

Returns the value of attribute status.



72
73
74
# File 'app/models/extface/driver/datecs/fp550.rb', line 72

def status
  @status
end

Class Method Details

.bcc(buffer) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/extface/driver/datecs/fp550.rb', line 114

def bcc(buffer)
  sum = 0
  buffer.each_byte do |byte|
    sum += byte
  end
  "".tap() do |bcc|
    4.times do |halfbyte|
      bcc.insert 0, (0x30 + ((sum >> (halfbyte*4)) & 0x0f)).chr
    end
  end
end

Instance Method Details

#ack? ⇒ Boolean

should wait, response is yet to come

Returns:

  • (Boolean)


91
# File 'app/models/extface/driver/datecs/fp550.rb', line 91

def ack?; !!@ack; end

#nak? ⇒ Boolean

should retry command with same seq

Returns:

  • (Boolean)


93
# File 'app/models/extface/driver/datecs/fp550.rb', line 93

def nak?; !!@nak; end