Class: SpheroResponse
- Inherits:
-
SpheroBase
- Object
- SpheroBase
- SpheroResponse
- Includes:
- SpheroUtilities
- Defined in:
- lib/rubysphero.rb
Overview
class
Instance Attribute Summary collapse
-
#calculated_checksum ⇒ Object
Returns the value of attribute calculated_checksum.
-
#data ⇒ Object
Returns the value of attribute data.
-
#echoed_seq ⇒ Object
Returns the value of attribute echoed_seq.
-
#raw_checksum ⇒ Object
Returns the value of attribute raw_checksum.
-
#raw_data ⇒ Object
Returns the value of attribute raw_data.
-
#sop1 ⇒ Object
Returns the value of attribute sop1.
-
#sop2 ⇒ Object
Returns the value of attribute sop2.
-
#valid ⇒ Object
Returns the value of attribute valid.
Attributes inherited from SpheroBase
Instance Method Summary collapse
-
#initialize(raw_data, debugval) ⇒ SpheroResponse
constructor
A new instance of SpheroResponse.
-
#process_data(bytes) ⇒ Object
def.
-
#raw_length ⇒ Object
def.
-
#synchronicity? ⇒ Boolean
def.
Methods included from SpheroUtilities
#add_checksum, #do_checksum, #print_format_bytes
Methods inherited from SpheroBase
Constructor Details
#initialize(raw_data, debugval) ⇒ SpheroResponse
Returns a new instance of SpheroResponse.
443 444 445 446 447 448 |
# File 'lib/rubysphero.rb', line 443 def initialize(raw_data, debugval) @debug=debugval @valid=false @raw_data=raw_data.dup @data=process_data(raw_data) end |
Instance Attribute Details
#calculated_checksum ⇒ Object
Returns the value of attribute calculated_checksum.
433 434 435 |
# File 'lib/rubysphero.rb', line 433 def calculated_checksum @calculated_checksum end |
#data ⇒ Object
Returns the value of attribute data.
437 438 439 |
# File 'lib/rubysphero.rb', line 437 def data @data end |
#echoed_seq ⇒ Object
Returns the value of attribute echoed_seq.
435 436 437 |
# File 'lib/rubysphero.rb', line 435 def echoed_seq @echoed_seq end |
#raw_checksum ⇒ Object
Returns the value of attribute raw_checksum.
434 435 436 |
# File 'lib/rubysphero.rb', line 434 def raw_checksum @raw_checksum end |
#raw_data ⇒ Object
Returns the value of attribute raw_data.
436 437 438 |
# File 'lib/rubysphero.rb', line 436 def raw_data @raw_data end |
#sop1 ⇒ Object
Returns the value of attribute sop1.
439 440 441 |
# File 'lib/rubysphero.rb', line 439 def sop1 @sop1 end |
#sop2 ⇒ Object
Returns the value of attribute sop2.
440 441 442 |
# File 'lib/rubysphero.rb', line 440 def sop2 @sop2 end |
#valid ⇒ Object
Returns the value of attribute valid.
438 439 440 |
# File 'lib/rubysphero.rb', line 438 def valid @valid end |
Instance Method Details
#process_data(bytes) ⇒ Object
def
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/rubysphero.rb', line 473 def process_data(bytes) if bytes.length == 0 logd "Response: None received" elsif bytes==nil logd "Response: Was nil" else logd "Response data raw: #{print_format_bytes(bytes)}" @sop1 = bytes.shift @sop2 = bytes.shift @raw_checksum=bytes.pop @calculated_checksum=do_checksum( bytes ) logd "Response checksum: #{@calculated_checksum.to_s(16)}" if @raw_checksum == @calculated_checksum then logd("Response Checksum is Valid") @valid=true logd("Response data:#{bytes}") @echoed_seq=bytes[1] @data=bytes else logd("Response Checksum is BAD") end # else end # else end |
#raw_length ⇒ Object
def
465 466 467 468 469 470 471 |
# File 'lib/rubysphero.rb', line 465 def raw_length if @data==nil return 0 else @raw_data.length end # else end |
#synchronicity? ⇒ Boolean
def
450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/rubysphero.rb', line 450 def synchronicity? logd("Synchronicity?") logd("#{@sop1}") logd("#{@sop2}") if (@sop1==0xFF) && (@sop2==0xFE) then return :asynchronous elsif (@sop1==0xFF) && (@sop2==0xFF) return :synchronous else return nil end # else end |