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.



306
307
308
309
310
311
312
313
314
315
316
317
# File 'app/models/extface/driver/datecs/fp550.rb', line 306

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

#bccObject (readonly)

Returns the value of attribute bcc.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def bcc
  @bcc
end

#cmdObject (readonly)

Returns the value of attribute cmd.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def cmd
  @cmd
end

#dataObject (readonly)

Returns the value of attribute data.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def data
  @data
end

#frameObject (readonly)

Returns the value of attribute frame.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def frame
  @frame
end

#lenObject (readonly)

Returns the value of attribute len.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def len
  @len
end

#seqObject (readonly)

Returns the value of attribute seq.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def seq
  @seq
end

#statusObject (readonly)

Returns the value of attribute status.



300
301
302
# File 'app/models/extface/driver/datecs/fp550.rb', line 300

def status
  @status
end

Class Method Details

.bcc(buffer) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
# File 'app/models/extface/driver/datecs/fp550.rb', line 343

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)


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

def ack?; !!@ack; end

#nak?Boolean

should retry command with same seq

Returns:

  • (Boolean)


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

def nak?; !!@nak; end