Class: SpheroRequest
- Inherits:
-
SpheroBase
- Object
- SpheroBase
- SpheroRequest
- Includes:
- SpheroUtilities
- Defined in:
- lib/rubysphero.rb
Overview
class
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#cid ⇒ Object
Returns the value of attribute cid.
-
#did ⇒ Object
Returns the value of attribute did.
-
#dlen ⇒ Object
Returns the value of attribute dlen.
-
#seq ⇒ Object
Returns the value of attribute seq.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#sop1 ⇒ Object
Returns the value of attribute sop1.
-
#sop2 ⇒ Object
Returns the value of attribute sop2.
Attributes inherited from SpheroBase
Instance Method Summary collapse
-
#build_packet ⇒ Object
def.
-
#initialize(type = :synchronous, debugval) ⇒ SpheroRequest
constructor
A new instance of SpheroRequest.
-
#length ⇒ Object
def.
-
#push_data(data_input, length = :a8bit) ⇒ Object
def.
Methods included from SpheroUtilities
#add_checksum, #do_checksum, #print_format_bytes
Methods inherited from SpheroBase
Constructor Details
#initialize(type = :synchronous, debugval) ⇒ SpheroRequest
Returns a new instance of SpheroRequest.
514 515 516 517 518 519 520 521 522 |
# File 'lib/rubysphero.rb', line 514 def initialize(type=:synchronous, debugval) if type==:synchronous @sop1=0xFF @sop2=0xFF end # if @debug=debugval @packet_data=Array.new @payload_data=Array.new end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
510 511 512 |
# File 'lib/rubysphero.rb', line 510 def checksum @checksum end |
#cid ⇒ Object
Returns the value of attribute cid.
507 508 509 |
# File 'lib/rubysphero.rb', line 507 def cid @cid end |
#did ⇒ Object
Returns the value of attribute did.
506 507 508 |
# File 'lib/rubysphero.rb', line 506 def did @did end |
#dlen ⇒ Object
Returns the value of attribute dlen.
508 509 510 |
# File 'lib/rubysphero.rb', line 508 def dlen @dlen end |
#seq ⇒ Object
Returns the value of attribute seq.
509 510 511 |
# File 'lib/rubysphero.rb', line 509 def seq @seq end |
#sequence ⇒ Object
Returns the value of attribute sequence.
511 512 513 |
# File 'lib/rubysphero.rb', line 511 def sequence @sequence end |
#sop1 ⇒ Object
Returns the value of attribute sop1.
504 505 506 |
# File 'lib/rubysphero.rb', line 504 def sop1 @sop1 end |
#sop2 ⇒ Object
Returns the value of attribute sop2.
505 506 507 |
# File 'lib/rubysphero.rb', line 505 def sop2 @sop2 end |
Instance Method Details
#build_packet ⇒ Object
def
528 529 530 531 532 533 534 535 536 537 |
# File 'lib/rubysphero.rb', line 528 def build_packet packet_no_checksum=[@sop1, @sop2, @did, @cid, @seq, @dlen] packet_no_checksum.concat @payload_data packet_with_checksum=add_checksum(packet_no_checksum) packet_packed=packet_with_checksum.pack("C*") logd(print_format_bytes(packet_with_checksum)) @packet_data=packet_packed return @packet_data end |
#length ⇒ Object
def
524 525 526 |
# File 'lib/rubysphero.rb', line 524 def length return @packet_data.length end |
#push_data(data_input, length = :a8bit) ⇒ Object
def
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/rubysphero.rb', line 539 def push_data(data_input, length=:a8bit) # 8bit and 16bit numbers if data_input > 0xFF then logd("Greater than 255, splitting into MSB and LSB)}") logd("Masked: #{(data_input & 0b0000000100000000 ).to_s(2)}") data_input_msb = (data_input & 0b0000000100000000) >> 8 data_input_lsb = data_input & 0b0000000011111111 logd("data_input MSB #{data_input_msb.to_s(2)}") logd("data_input LSB #{data_input_lsb.to_s(2)}") @payload_data.push data_input_msb @payload_data.push data_input_lsb else if length==:a16bit @payload_data.push 0x00 end #if @payload_data.push data_input end # else end |