Class: SpheroResponse

Inherits:
SpheroBase show all
Includes:
SpheroUtilities
Defined in:
lib/rubysphero.rb

Overview

class

Instance Attribute Summary collapse

Attributes inherited from SpheroBase

#debug

Instance Method Summary collapse

Methods included from SpheroUtilities

#add_checksum, #do_checksum, #print_format_bytes

Methods inherited from SpheroBase

#logd

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_checksumObject

Returns the value of attribute calculated_checksum.



433
434
435
# File 'lib/rubysphero.rb', line 433

def calculated_checksum
  @calculated_checksum
end

#dataObject

Returns the value of attribute data.



437
438
439
# File 'lib/rubysphero.rb', line 437

def data
  @data
end

#echoed_seqObject

Returns the value of attribute echoed_seq.



435
436
437
# File 'lib/rubysphero.rb', line 435

def echoed_seq
  @echoed_seq
end

#raw_checksumObject

Returns the value of attribute raw_checksum.



434
435
436
# File 'lib/rubysphero.rb', line 434

def raw_checksum
  @raw_checksum
end

#raw_dataObject

Returns the value of attribute raw_data.



436
437
438
# File 'lib/rubysphero.rb', line 436

def raw_data
  @raw_data
end

#sop1Object

Returns the value of attribute sop1.



439
440
441
# File 'lib/rubysphero.rb', line 439

def sop1
  @sop1
end

#sop2Object

Returns the value of attribute sop2.



440
441
442
# File 'lib/rubysphero.rb', line 440

def sop2
  @sop2
end

#validObject

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_lengthObject

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

Returns:

  • (Boolean)


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