meshtastic 0.0.169 → 0.0.171

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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.169'
4
+ VERSION = '0.0.171'
5
5
  end
@@ -3,4 +3,76 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Meshtastic::SerialInterface do
6
+ def fake_serial_obj
7
+ written = +''.b
8
+ serial_conn = Object.new
9
+ serial_conn.define_singleton_method(:write) do |b|
10
+ written << b
11
+ b.bytesize
12
+ end
13
+ serial_conn.define_singleton_method(:flush) { true }
14
+ serial_conn.define_singleton_method(:closed?) { false }
15
+ serial_conn.define_singleton_method(:close) { true }
16
+ serial_conn.define_singleton_method(:written) { written }
17
+ { serial_conn: serial_conn, written: written, my_node_num: 0xb0b }
18
+ end
19
+
20
+ describe '.send_to_radio' do
21
+ it 'frames a ToRadio with START1/START2 and big-endian length' do
22
+ serial_obj = fake_serial_obj
23
+ to_radio = Meshtastic::ToRadio.new
24
+ to_radio.want_config_id = 42
25
+ body = to_radio.to_proto
26
+
27
+ described_class.send_to_radio(serial_obj: serial_obj, to_radio: to_radio)
28
+ frame = serial_obj[:serial_conn].written
29
+
30
+ expect(frame.getbyte(0)).to eq(Meshtastic::START1)
31
+ expect(frame.getbyte(1)).to eq(Meshtastic::START2)
32
+ expect((frame.getbyte(2) << 8) + frame.getbyte(3)).to eq(body.bytesize)
33
+ expect(frame.byteslice(4, body.bytesize)).to eq(body)
34
+ end
35
+
36
+ it 'accepts a pre-serialized String body' do
37
+ serial_obj = fake_serial_obj
38
+ body = Meshtastic::ToRadio.new.tap { |t| t.want_config_id = 7 }.to_proto
39
+ described_class.send_to_radio(serial_obj: serial_obj, to_radio: body)
40
+ frame = serial_obj[:serial_conn].written
41
+ expect(frame.bytesize).to eq(4 + body.bytesize)
42
+ end
43
+ end
44
+
45
+ describe '.send_text' do
46
+ it 'writes a decoded ToRadio mesh packet for the radio to encrypt' do
47
+ serial_obj = fake_serial_obj
48
+ described_class.send_text(
49
+ serial_obj: serial_obj,
50
+ text: 'ping',
51
+ to: '!ffffffff',
52
+ channel: 0
53
+ )
54
+ frame = serial_obj[:serial_conn].written
55
+ body_len = (frame.getbyte(2) << 8) + frame.getbyte(3)
56
+ tr = Meshtastic::ToRadio.decode(frame.byteslice(4, body_len))
57
+
58
+ expect(tr.packet).not_to be_nil
59
+ expect(tr.packet.decoded).not_to be_nil
60
+ expect(tr.packet.decoded.payload).to eq('ping')
61
+ expect(tr.packet.encrypted.to_s).to eq('')
62
+ expect(tr.packet.from).to eq(0xb0b)
63
+ end
64
+ end
65
+
66
+ describe '.disconnect' do
67
+ it 'returns nil and closes the serial connection' do
68
+ serial_obj = fake_serial_obj
69
+ expect(described_class.disconnect(serial_obj: serial_obj)).to be_nil
70
+ end
71
+ end
72
+
73
+ describe '.help' do
74
+ it 'prints usage without raising' do
75
+ expect { described_class.help }.to output(/USAGE/).to_stdout
76
+ end
77
+ end
6
78
  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.169
4
+ version: 0.0.171
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
@@ -267,6 +267,7 @@ files:
267
267
  - Gemfile
268
268
  - LICENSE
269
269
  - README.md
270
+ - README.md.bak.20260709105815
270
271
  - Rakefile
271
272
  - bin/meshtastic_autoinc_version
272
273
  - build_gem.sh