Class: SpheroRequest

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

Overview

class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SpheroUtilities

#add_checksum, #do_checksum, #logd, #print_format_bytes

Constructor Details

#initialize(type = :synchronous) ⇒ SpheroRequest

Returns a new instance of SpheroRequest.



292
293
294
295
296
297
298
299
300
# File 'lib/rubysphero.rb', line 292

def initialize(type=:synchronous)
	if type==:synchronous
		@sop1=0xFF
		@sop2=0xFF 
	end # if
	
	@packet_data=Array.new
	@payload_data=Array.new
end

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



288
289
290
# File 'lib/rubysphero.rb', line 288

def checksum
  @checksum
end

#cidObject

Returns the value of attribute cid.



285
286
287
# File 'lib/rubysphero.rb', line 285

def cid
  @cid
end

#didObject

Returns the value of attribute did.



284
285
286
# File 'lib/rubysphero.rb', line 284

def did
  @did
end

#dlenObject

Returns the value of attribute dlen.



286
287
288
# File 'lib/rubysphero.rb', line 286

def dlen
  @dlen
end

#seqObject

Returns the value of attribute seq.



287
288
289
# File 'lib/rubysphero.rb', line 287

def seq
  @seq
end

#sequenceObject

Returns the value of attribute sequence.



289
290
291
# File 'lib/rubysphero.rb', line 289

def sequence
  @sequence
end

#sop1Object

Returns the value of attribute sop1.



282
283
284
# File 'lib/rubysphero.rb', line 282

def sop1
  @sop1
end

#sop2Object

Returns the value of attribute sop2.



283
284
285
# File 'lib/rubysphero.rb', line 283

def sop2
  @sop2
end

Instance Method Details

#build_packetObject

def



306
307
308
309
310
311
312
313
314
315
# File 'lib/rubysphero.rb', line 306

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



302
303
304
# File 'lib/rubysphero.rb', line 302

def length
	return @packet_data.length
end

#push_data(data_input, length = :a8bit) ⇒ Object

def



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/rubysphero.rb', line 317

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