Module: Meshtastic::TCP
- Defined in:
- lib/meshtastic/tcp.rb
Constant Summary collapse
- DEFAULT_PORT =
4403
Class Method Summary collapse
- .authors ⇒ Object
- .connect(opts = {}) ⇒ Object
- .disconnect(opts = {}) ⇒ Object
- .drain_from_radio(opts = {}) ⇒ Object
- .help ⇒ Object
- .recv_from_radio(opts = {}) ⇒ Object
- .send_data(opts = {}) ⇒ Object
- .send_text(opts = {}) ⇒ Object
- .send_to_radio(opts = {}) ⇒ Object
- .subscribe(opts = {}) ⇒ Object
- .wait_for_config(opts = {}) ⇒ Object
Class Method Details
.authors ⇒ Object
85 86 87 |
# File 'lib/meshtastic/tcp.rb', line 85 public_class_method def self. "AUTHOR(S):\n 0day Inc. <[email protected]>\n " end |
.connect(opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/meshtastic/tcp.rb', line 11 public_class_method def self.connect(opts = {}) host = opts[:host] ||= '127.0.0.1' port = opts[:port] ||= DEFAULT_PORT tcp_obj = nil socket = opts[:socket] || TCPSocket.new(host, port) socket.binmode tcp_obj = { serial_conn: socket, tcp_socket: socket, block_dev: "#{host}:#{port}", host: host, port: port, tx_mutex: Mutex.new, my_info: nil, my_node_num: nil, metadata: nil } tcp_obj[:rx_thread] = Meshtastic::Serial.send( :init_rx_thread, serial_conn: socket, serial_obj: tcp_obj, debug_out: opts[:debug_out] ) Meshtastic::Serial.wake_up_device(serial_obj: tcp_obj) if opts.fetch(:want_config, true) mesh = Meshtastic::MeshInterface.new bytes = mesh.start_config tcp_obj[:config_id] = mesh.config_id Meshtastic::Serial.send_to_radio(serial_obj: tcp_obj, to_radio: bytes) end tcp_obj rescue StandardError disconnect(tcp_obj: tcp_obj) if tcp_obj raise end |
.disconnect(opts = {}) ⇒ Object
81 82 83 |
# File 'lib/meshtastic/tcp.rb', line 81 public_class_method def self.disconnect(opts = {}) Meshtastic::Serial.disconnect(serial_obj: opts[:tcp_obj] || opts[:serial_obj]) end |
.drain_from_radio(opts = {}) ⇒ Object
68 69 70 |
# File 'lib/meshtastic/tcp.rb', line 68 public_class_method def self.drain_from_radio(opts = {}) Meshtastic::Serial.drain_from_radio(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |
.help ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/meshtastic/tcp.rb', line 89 public_class_method def self.help puts " USAGE: # Run the connect class method for this module. #{self}.connect( host: 'optional - value for host passed into connect', port: 'optional - value for port passed into connect', socket: 'optional - value for socket passed into connect', debug_out: 'optional - value for debug_out passed into connect' ) # Run the wait_for_config class method for this module. #{self}.wait_for_config( tcp_obj: 'optional - value for tcp_obj passed into wait_for_config', serial_obj: 'optional - value for serial_obj passed into wait_for_config' ) # Run the send_to_radio class method for this module. #{self}.send_to_radio( tcp_obj: 'optional - value for tcp_obj passed into send_to_radio', serial_obj: 'optional - value for serial_obj passed into send_to_radio' ) # Run the send_text class method for this module. #{self}.send_text( tcp_obj: 'optional - value for tcp_obj passed into send_text', serial_obj: 'optional - value for serial_obj passed into send_text' ) # Run the send_data class method for this module. #{self}.send_data( tcp_obj: 'optional - value for tcp_obj passed into send_data', serial_obj: 'optional - value for serial_obj passed into send_data' ) # Run the recv_from_radio class method for this module. #{self}.recv_from_radio( tcp_obj: 'optional - value for tcp_obj passed into recv_from_radio', serial_obj: 'optional - value for serial_obj passed into recv_from_radio' ) # Run the drain_from_radio class method for this module. #{self}.drain_from_radio( tcp_obj: 'optional - value for tcp_obj passed into drain_from_radio', serial_obj: 'optional - value for serial_obj passed into drain_from_radio' ) # Run the subscribe class method for this module. #{self}.subscribe( tcp_obj: 'optional - value for tcp_obj passed into subscribe', serial_obj: 'optional - value for serial_obj passed into subscribe' ) # Run the disconnect class method for this module. #{self}.disconnect( tcp_obj: 'optional - value for tcp_obj passed into disconnect', serial_obj: 'optional - value for serial_obj passed into disconnect' ) # Run the authors class method for this module. #{self}.authors " end |
.recv_from_radio(opts = {}) ⇒ Object
64 65 66 |
# File 'lib/meshtastic/tcp.rb', line 64 public_class_method def self.recv_from_radio(opts = {}) Meshtastic::Serial.recv_from_radio(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |
.send_data(opts = {}) ⇒ Object
60 61 62 |
# File 'lib/meshtastic/tcp.rb', line 60 public_class_method def self.send_data(opts = {}) Meshtastic::Serial.send_data(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |
.send_text(opts = {}) ⇒ Object
56 57 58 |
# File 'lib/meshtastic/tcp.rb', line 56 public_class_method def self.send_text(opts = {}) Meshtastic::Serial.send_text(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |
.send_to_radio(opts = {}) ⇒ Object
52 53 54 |
# File 'lib/meshtastic/tcp.rb', line 52 public_class_method def self.send_to_radio(opts = {}) Meshtastic::Serial.send_to_radio(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |
.subscribe(opts = {}) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/meshtastic/tcp.rb', line 72 public_class_method def self.subscribe(opts = {}) merged = opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj]) if block_given? Meshtastic::Serial.subscribe(merged) { |msg| yield msg } # rubocop:disable Style/ExplicitBlockArgument else Meshtastic::Serial.subscribe(merged) end end |
.wait_for_config(opts = {}) ⇒ Object
48 49 50 |
# File 'lib/meshtastic/tcp.rb', line 48 public_class_method def self.wait_for_config(opts = {}) Meshtastic::Serial.wait_for_config(opts.merge(serial_obj: opts[:tcp_obj] || opts[:serial_obj])) end |