meshtastic 0.0.134 → 0.0.135

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: 2a019972ccb99e42fee81bb0b2f8a18d2c7c0223e579234a64239eb1f0d89652
4
- data.tar.gz: b8882c221fb7d8faf2b927f596b78f54f9868917a8d5c6d889d31b1ab5114990
3
+ metadata.gz: b2450abd9bb6ac40987c0cae82e08c2ca1a8fb466a510185a12cf7af2c0b1115
4
+ data.tar.gz: cc6380613f57613b0d9920ce53caaa7149afe2e67ca6da7f0abd84912d76bb1c
5
5
  SHA512:
6
- metadata.gz: 61346686f811a67bf81d68a94b3189aaf0b6232c59e0cbdbfba3cfaa6850284beec8f68616adbcbd92f3e88c8200f1134954bb40d25eed29303fb023b433b8ef
7
- data.tar.gz: 7fec0467aca8ad1ad68afdcb67ef206dc76499285282f802fee25f938335c6092cb29cb6c4720e74e8481be0235ce225fbd1616e548cba8cb0076cbd278e0698
6
+ metadata.gz: 9f00a1b9e3061dc4592495957db02af2440f15580a8b84277d1ca809af67648ed7e57fe3c72017b8f1b02eafef5a0520767b17ec959c82f7f6394d72f901f5c0
7
+ data.tar.gz: c493f51bf1efd690e035571270860e10ac7aca0a020e60e58c501b5ba9ee5d99eb447076683d0409183cf02b4b9e57ee3088ec52e7a15b23a2af5ed46cd6b362
@@ -278,29 +278,22 @@ module Meshtastic
278
278
  opts[:via] = :mqtt
279
279
 
280
280
  # TODO: Implement chunked message to deal with large messages
281
- raw_text = opts[:text].to_s
282
- max_bytes = 232
281
+ text = opts[:text].to_s
282
+ max_bytes = 233
283
283
  mui = Meshtastic::MeshInterface.new
284
284
 
285
- if raw_text.bytesize > max_bytes
286
- chunks = []
287
- current_chunk = ''
288
- raw_text.each_char do |char|
289
- if (current_chunk + char).bytesize > max_bytes
290
- chunks.push(current_chunk)
291
- current_chunk = char
292
- else
293
- current_chunk += char
294
- end
295
- end
296
- chunks.push(current_chunk) unless current_chunk.empty?
297
-
298
- total_chunks = chunks.length
299
- chunks.each_with_index do |chunk, index|
285
+ if text.bytesize > max_bytes
286
+ total_chunks = (text.bytesize.to_f / max_bytes).ceil
287
+ total_chunks.times do |i|
288
+ chunk_num = i + 1
289
+ chunk_prefix = "(#{chunk_num} of #{total_chunks})"
290
+ chunk_prefix_len = chunk_prefix.bytesize
291
+ start_index = i * (max_bytes - chunk_prefix_len)
292
+ end_index = (start_index + (max_bytes - chunk_prefix_len)) - 1
293
+ chunk = "#{chunk_prefix} #{text.byteslice(start_index..end_index)}"
300
294
  opts[:text] = chunk
301
- opts[:text] = "[#{index + 1}/#{total_chunks}] #{chunk}"
302
295
  protobuf_chunk = mui.send_text(opts)
303
- push(mqtt_obj.publish(absolute_topic, protobuf_chunk))
296
+ mqtt_obj.publish(absolute_topic, protobuf_chunk)
304
297
  end
305
298
  else
306
299
  protobuf_text = mui.send_text(opts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.134'
4
+ VERSION = '0.0.135'
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.134
4
+ version: 0.0.135
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.