meshtastic 0.0.116 → 0.0.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e1db876551e7f78c1b28f5dbd0d066346890aa31ea7e5969165b8c9142d84b
4
- data.tar.gz: fb7c1b7ee22e0cb7b86cdcaaefc5c89d49fcd7c36f2dbcc9ac5185424bc81276
3
+ metadata.gz: bf595fe9b5fdde913869bac28839cfeab6df0c358f8cde8d895154cf1b03a4a9
4
+ data.tar.gz: 2277431855a0478c85e122f4bdf7f822b808c1d2b88a4f620d4e9d9b4655f045
5
5
  SHA512:
6
- metadata.gz: ffb5a5731c4d63e46816eec4de5538aa8b28637d00c79159811bea652757aa9260f3587bd8c9db7fed2842766e28fd17943a5bfe917d6d684ada85b4bef50592
7
- data.tar.gz: 4145d728651ca25dfaffc8f99d2cfdc3ebd17904be545c5c395a1839287207a3fbd05696f90be8755982ca574be405f77f7377577bb0d6e8ab278c8f127e1601
6
+ metadata.gz: d7a7fb5995c15ef99ed1efa643e3a0119a0a29b2f5e739db05729b3912e308e10e2b4b0207bbc73abebaa05b0a39ee4173131249ccd22478b0ea76c3aeab5569
7
+ data.tar.gz: 8e6dcfcb7575a1d335d5a8c9618b61dde2875a2dd420a14264b3a8c230abb4155b8e212781e614d5fb6065e13390437b77b2de810722ef40dbbd5ce7b3144536
@@ -13,10 +13,39 @@ module Meshtastic
13
13
  module Serial
14
14
  @session_data = []
15
15
 
16
+ # Supported Method Parameters::
17
+ # session_thread = init_session_thread(
18
+ # serial_conn: 'required - SerialPort.new object'
19
+ # )
20
+
21
+ private_class_method def self.init_session_thread(opts = {})
22
+ serial_conn = opts[:serial_conn]
23
+
24
+ # Spin up a serial_obj session_thread
25
+ Thread.new do
26
+ # serial_conn.read_timeout = -1
27
+ serial_conn.flush
28
+
29
+ loop do
30
+ serial_conn.wait_readable
31
+ # Read raw chars into @session_data,
32
+ # convert to readable bytes if need-be
33
+ # later.
34
+ @session_data << serial_conn.readchar.force_encoding('UTF-8')
35
+ end
36
+ end
37
+ rescue StandardError => e
38
+ session_thread&.terminate
39
+ serial_conn&.close
40
+ serial_conn = nil
41
+
42
+ raise e
43
+ end
44
+
16
45
  # Supported Method Parameters::
17
46
  # serial_obj = Meshtastic::Serial.connect(
18
47
  # block_dev: 'optional - serial block device path (defaults to /dev/ttyUSB0)',
19
- # baud: 'optional - (defaults to 9600)',
48
+ # baud: 'optional - (defaults to 115200)',
20
49
  # data_bits: 'optional - (defaults to 8)',
21
50
  # stop_bits: 'optional - (defaults to 1)',
22
51
  # parity: 'optional - :even|:mark|:odd|:space|:none (defaults to :none)'
@@ -26,7 +55,7 @@ module Meshtastic
26
55
  block_dev = opts[:block_dev] ||= '/dev/ttyUSB0'
27
56
  raise "Invalid block device: #{block_dev}" unless File.exist?(block_dev)
28
57
 
29
- baud = opts[:baud] ||= 9_600
58
+ baud = opts[:baud] ||= 115_200
30
59
  data_bits = opts[:data_bits] ||= 8
31
60
  stop_bits = opts[:stop_bits] ||= 1
32
61
  parity = opts[:parity] ||= :none
@@ -62,6 +91,63 @@ module Meshtastic
62
91
  raise e
63
92
  end
64
93
 
94
+ # Supported Method Parameters::
95
+ # session_data = PWN::Plugins::Serial.dump_session_data
96
+
97
+ public_class_method def self.dump_session_data
98
+ if block_given?
99
+ @session_data.join.split("\n").each do |data|
100
+ yield data
101
+ end
102
+ else
103
+ @session_data.join
104
+ end
105
+ rescue StandardError => e
106
+ raise e
107
+ end
108
+
109
+ # Supported Method Parameters::
110
+ # session_data = PWN::Plugins::Serial.flush_session_data
111
+
112
+ public_class_method def self.flush_session_data
113
+ @session_data.clear
114
+ rescue StandardError => e
115
+ raise e
116
+ end
117
+
118
+ # Supported Method Parameters::
119
+ # session_data = PWN::Plugins::Serial.monitor(
120
+ # duration: 'optional - duration to monitor (default: 3)',
121
+ # include: 'optional - comma-delimited string(s) to include in message (default: nil)',
122
+ # exclude: 'optional - comma-delimited string(s) to exclude in message (default: nil)'
123
+ # )
124
+
125
+ public_class_method def self.monitor(opts = {})
126
+ duration = opts[:duration] ||= 3
127
+ include = opts[:include]
128
+ exclude = opts[:exclude]
129
+
130
+ loop do
131
+ exclude_arr = exclude.to_s.split(',').map(&:strip)
132
+ include_arr = include.to_s.split(',').map(&:strip)
133
+
134
+ dump_session_data do |data|
135
+ disp = false
136
+ disp = true if exclude_arr.none? { |exclude| data.include?(exclude) } && (
137
+ include_arr.empty? ||
138
+ include_arr.all? { |include| data.include?(include) }
139
+ )
140
+ puts data if disp
141
+ flush_session_data
142
+ end
143
+ sleep duration
144
+ end
145
+ rescue Interrupt
146
+ puts "\nCTRL+C detected. Breaking out of monitor mode..."
147
+ rescue StandardError => e
148
+ raise e
149
+ end
150
+
65
151
  # Supported Method Parameters::
66
152
  # Meshtastic::Serial.subscribe(
67
153
  # serial_obj: 'required - serial_obj returned from #connect method'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.116'
4
+ VERSION = '0.0.117'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meshtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.116
4
+ version: 0.0.117
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.