Class: TimexDatalinkClient::NotebookAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/timex_datalink_client/notebook_adapter.rb

Constant Summary collapse

BYTE_SLEEP_DEFAULT =
0.025
PACKET_SLEEP_DEFAULT =
0.25

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serial_device:, byte_sleep: nil, packet_sleep: nil, verbose: false) ⇒ NotebookAdapter

Create a NotebookAdapter instance.

Parameters:

  • serial_device (String)

    Path to serial device.

  • byte_sleep (Integer, nil) (defaults to: nil)

    Time to sleep after sending byte.

  • packet_sleep (Integer, nil) (defaults to: nil)

    Time to sleep after sending packet of bytes.

  • verbose (Boolean) (defaults to: false)

    Write verbose output to console.



19
20
21
22
23
24
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 19

def initialize(serial_device:, byte_sleep: nil, packet_sleep: nil, verbose: false)
  @serial_device = serial_device
  @byte_sleep = byte_sleep || BYTE_SLEEP_DEFAULT
  @packet_sleep = packet_sleep || PACKET_SLEEP_DEFAULT
  @verbose = verbose
end

Instance Attribute Details

#byte_sleepObject

Returns the value of attribute byte_sleep.



10
11
12
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 10

def byte_sleep
  @byte_sleep
end

#packet_sleepObject

Returns the value of attribute packet_sleep.



10
11
12
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 10

def packet_sleep
  @packet_sleep
end

#serial_deviceObject

Returns the value of attribute serial_device.



10
11
12
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 10

def serial_device
  @serial_device
end

#verboseObject

Returns the value of attribute verbose.



10
11
12
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 10

def verbose
  @verbose
end

Instance Method Details

#write(packets) ⇒ void

This method returns an undefined value.

Write packets of bytes to serial device.

Parameters:

  • packets (Array<Array<Integer>>)

    Two-dimensional array of integers that represent bytes.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/timex_datalink_client/notebook_adapter.rb', line 30

def write(packets)
  packets.each do |packet|
    packet.each do |byte|
      printf("%.2X ", byte) if verbose

      serial_port.write(byte.chr)

      sleep(byte_sleep)
    end

    sleep(packet_sleep)

    puts if verbose
  end
end