Class: Driver::Datecs::Dp35::Frame
- Inherits:
-
Object
- Object
- Driver::Datecs::Dp35::Frame
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/extface/driver/datecs/dp35.rb
Instance Attribute Summary collapse
-
#bcc ⇒ Object
readonly
Returns the value of attribute bcc.
-
#cmd ⇒ Object
readonly
Returns the value of attribute cmd.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
-
#len ⇒ Object
readonly
Returns the value of attribute len.
-
#seq ⇒ Object
readonly
Returns the value of attribute seq.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#ack? ⇒ Boolean
should wait, response is yet to come.
-
#initialize(buffer) ⇒ Frame
constructor
A new instance of Frame.
-
#nak? ⇒ Boolean
should retry command with same seq.
Constructor Details
#initialize(buffer) ⇒ Frame
Returns a new instance of Frame.
320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 320 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.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def bcc @bcc end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def cmd @cmd end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def data @data end |
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def frame @frame end |
#len ⇒ Object (readonly)
Returns the value of attribute len.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def len @len end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def seq @seq end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
314 315 316 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 314 def status @status end |
Class Method Details
.bcc(buffer) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 357 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
333 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 333 def ack?; !!@ack; end |
#nak? ⇒ Boolean
should retry command with same seq
335 |
# File 'app/models/extface/driver/datecs/dp35.rb', line 335 def nak?; !!@nak; end |