Class: Driver::Datecs::Dp25::Frame
- Inherits:
-
Object
- Object
- Driver::Datecs::Dp25::Frame
- Includes:
- ActiveModel::Validations
- Defined in:
- app/models/extface/driver/datecs/dp25.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.
306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'app/models/extface/driver/datecs/dp25.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
#bcc ⇒ Object (readonly)
Returns the value of attribute bcc.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def bcc @bcc end |
#cmd ⇒ Object (readonly)
Returns the value of attribute cmd.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def cmd @cmd end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def data @data end |
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def frame @frame end |
#len ⇒ Object (readonly)
Returns the value of attribute len.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def len @len end |
#seq ⇒ Object (readonly)
Returns the value of attribute seq.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 300 def seq @seq end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
300 301 302 |
# File 'app/models/extface/driver/datecs/dp25.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/dp25.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
319 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 319 def ack?; !!@ack; end |
#nak? ⇒ Boolean
should retry command with same seq
321 |
# File 'app/models/extface/driver/datecs/dp25.rb', line 321 def nak?; !!@nak; end |