Class: SpheroRequest
- Inherits:
-
Object
- Object
- 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.
Instance Method Summary collapse
-
#build_packet ⇒ Object
def.
-
#initialize(type = :synchronous) ⇒ 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, #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
#checksum ⇒ Object
Returns the value of attribute checksum.
288 289 290 |
# File 'lib/rubysphero.rb', line 288 def checksum @checksum end |
#cid ⇒ Object
Returns the value of attribute cid.
285 286 287 |
# File 'lib/rubysphero.rb', line 285 def cid @cid end |
#did ⇒ Object
Returns the value of attribute did.
284 285 286 |
# File 'lib/rubysphero.rb', line 284 def did @did end |
#dlen ⇒ Object
Returns the value of attribute dlen.
286 287 288 |
# File 'lib/rubysphero.rb', line 286 def dlen @dlen end |
#seq ⇒ Object
Returns the value of attribute seq.
287 288 289 |
# File 'lib/rubysphero.rb', line 287 def seq @seq end |
#sequence ⇒ Object
Returns the value of attribute sequence.
289 290 291 |
# File 'lib/rubysphero.rb', line 289 def sequence @sequence end |
#sop1 ⇒ Object
Returns the value of attribute sop1.
282 283 284 |
# File 'lib/rubysphero.rb', line 282 def sop1 @sop1 end |
#sop2 ⇒ Object
Returns the value of attribute sop2.
283 284 285 |
# File 'lib/rubysphero.rb', line 283 def sop2 @sop2 end |
Instance Method Details
#build_packet ⇒ Object
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 |
#length ⇒ Object
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 |