Module: Meshtastic::PayloadFormats
- Defined in:
- lib/meshtastic/payload_formats.rb
Overview
Stateless binary application decoders; see documentation/payload-formats.md.
Constant Summary collapse
- PORTS =
{ AUDIO_APP: 9, IP_TUNNEL_APP: 33, ZPS_APP: 68, CAYENNE_APP: 77, LORA_OTA_APP: 79 }.freeze
- LPP_TYPES =
{ 0 => [:digital_input, 1, false, 1, nil], 1 => [:digital_output, 1, false, 1, nil], 2 => [:analog_input, 2, true, 100, nil], 3 => [:analog_output, 2, true, 100, nil], 101 => [:illuminance, 2, false, 1, 'lux'], 102 => [:presence, 1, false, 1, nil], 103 => [:temperature, 2, true, 10, 'C'], 104 => [:relative_humidity, 1, false, 2, '%'], 113 => [:accelerometer, 6, true, 1000, 'g'], 115 => [:barometric_pressure, 2, false, 10, 'hPa'], 134 => [:gyrometer, 6, true, 100, 'degrees/s'], 136 => [:gps, 9, true, 1, nil] }.freeze
Class Method Summary collapse
Class Method Details
.authors ⇒ Object
232 233 234 |
# File 'lib/meshtastic/payload_formats.rb', line 232 public_class_method def self. 'Meshtastic Ruby contributors' end |
.decode(opts = {}) ⇒ Object
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/payload_formats.rb', line 24 public_class_method def self.decode(opts = {}) port = opts[:portnum] port = PORTS[port.to_sym] if port.is_a?(String) || port.is_a?(Symbol) raw = opts[:payload] raise ArgumentError, 'payload must be a binary String' unless raw.is_a?(String) raw = raw.b result = { portnum: port, raw: raw } parsed = case port when 9 then audio(payload: raw) when 33 then ip(payload: raw) when 68 then zps(payload: raw, profile: opts[:zps_profile]) when 77 then cayenne(payload: raw) when 79 then ota(payload: raw) else { status: :unsupported, format: :opaque, error: 'no verified schema for this port' } end parsed.merge!(pcm_audio(audio: parsed)) if port == 9 && opts[:pcm] && parsed[:status] == :decoded result.merge(parsed) rescue ArgumentError => e raise unless raw.is_a?(String) result.merge(status: :malformed, error: e.) end |
.help ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/meshtastic/payload_formats.rb', line 236 public_class_method def self.help puts "# Decode a binary application payload without modifying its bytes. #{self}.decode( portnum: 'required - numeric or named Meshtastic application port', payload: 'required - raw binary application payload String', pcm: 'optional - decode Codec2 to s16le audio using installed libcodec2; default false', zps_profile: 'optional - select :esp32_legacy for the experimental little-endian ZPS dialect' ) # Identify the module authors. #{self}.authors" end |