Class: Interlnk::Protocol
- Inherits:
-
Object
- Object
- Interlnk::Protocol
- Defined in:
- lib/interlnk/protocol.rb
Instance Attribute Summary collapse
-
#init_info ⇒ Object
readonly
Returns the value of attribute init_info.
-
#server_info ⇒ Object
readonly
Returns the value of attribute server_info.
Instance Method Summary collapse
- #debug=(debug_state) ⇒ Object
- #do_init ⇒ Object
- #get_bpb(drive_nbr) ⇒ Object
- #get_drive_info(drive_nbr) ⇒ Object
- #get_sectors(unit_nbr: nil, start_sector: nil, nbr_sectors: nil) ⇒ Object
- #get_server_info ⇒ Object
- #idle ⇒ Object
-
#initialize(channel:) ⇒ Protocol
constructor
A new instance of Protocol.
Constructor Details
#initialize(channel:) ⇒ Protocol
Returns a new instance of Protocol.
9 10 11 12 13 14 15 |
# File 'lib/interlnk/protocol.rb', line 9 def initialize(channel:) @channel = channel @channel.connect @channel.baud = 115200 @server_info = get_server_info @init_info = do_init end |
Instance Attribute Details
#init_info ⇒ Object (readonly)
Returns the value of attribute init_info.
7 8 9 |
# File 'lib/interlnk/protocol.rb', line 7 def init_info @init_info end |
#server_info ⇒ Object (readonly)
Returns the value of attribute server_info.
7 8 9 |
# File 'lib/interlnk/protocol.rb', line 7 def server_info @server_info end |
Instance Method Details
#debug=(debug_state) ⇒ Object
17 18 19 |
# File 'lib/interlnk/protocol.rb', line 17 def debug=(debug_state) @channel.debug = debug_state end |
#do_init ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/interlnk/protocol.rb', line 32 def do_init @channel.channel_turnaround_to_send initr = Packet::InitRequest.new @channel.send_packet initr.bytes @channel.channel_turnaround_to_recv # TODO: do something with the mappings received @channel.receive_packet(type: Packet::InitAnswer) end |
#get_bpb(drive_nbr) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/interlnk/protocol.rb', line 50 def get_bpb(drive_nbr) @channel.channel_turnaround_to_send bpbr = Packet::BpbRequest.new(unit_nbr: drive_nbr) @channel.send_packet bpbr.bytes @channel.channel_turnaround_to_recv @channel.receive_packet(type: Packet::BpbAnswer).bpb end |
#get_drive_info(drive_nbr) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/interlnk/protocol.rb', line 42 def get_drive_info(drive_nbr) @channel.channel_turnaround_to_send # TODO: convert this to a proper request packet type @channel.send_packet([0x1C, drive_nbr]) # packet type: drive_info_request @channel.channel_turnaround_to_recv @channel.receive_packet(type: Packet::DriveInfoAnswer) end |
#get_sectors(unit_nbr: nil, start_sector: nil, nbr_sectors: nil) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/interlnk/protocol.rb', line 58 def get_sectors(unit_nbr: nil, start_sector: nil, nbr_sectors: nil) @channel.channel_turnaround_to_send readr = Packet::ReadRequest.new(unit_nbr: unit_nbr, start_sector: start_sector, nbr_sectors: nbr_sectors) @channel.send_packet readr.bytes @channel.channel_turnaround_to_recv # TODO: look at the answering status to make sure it worked @channel.receive_packet(type: Packet::IoAnswer) @channel.request_more_data # get the actual sector data @channel.receive_packet end |
#get_server_info ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/interlnk/protocol.rb', line 21 def get_server_info sir = Packet::ServerInfoRequest.new @channel.send_packet([0x00, 0x00]) # packet type: server_info_request @channel.send_packet(sir.bytes) # now we need to get ready to receive the SIR data @channel.channel_turnaround_to_recv @channel.receive_packet(type: Packet::ServerInfoAnswer) end |
#idle ⇒ Object
71 72 73 |
# File 'lib/interlnk/protocol.rb', line 71 def idle @channel.perform_idle end |