Class: SpheroRequest

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(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

#checksumObject

Returns the value of attribute checksum.



510
511
512
# File 'lib/rubysphero.rb', line 510

def checksum
  @checksum
end

#cidObject

Returns the value of attribute cid.



507
508
509
# File 'lib/rubysphero.rb', line 507

def cid
  @cid
end

#didObject

Returns the value of attribute did.



506
507
508
# File 'lib/rubysphero.rb', line 506

def did
  @did
end

#dlenObject

Returns the value of attribute dlen.



508
509
510
# File 'lib/rubysphero.rb', line 508

def dlen
  @dlen
end

#seqObject

Returns the value of attribute seq.



509
510
511
# File 'lib/rubysphero.rb', line 509

def seq
  @seq
end

#sequenceObject

Returns the value of attribute sequence.



511
512
513
# File 'lib/rubysphero.rb', line 511

def sequence
  @sequence
end

#sop1Object

Returns the value of attribute sop1.



504
505
506
# File 'lib/rubysphero.rb', line 504

def sop1
  @sop1
end

#sop2Object

Returns the value of attribute sop2.



505
506
507
# File 'lib/rubysphero.rb', line 505

def sop2
  @sop2
end

Instance Method Details

#build_packetObject

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

#lengthObject

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