Created
March 17, 2018 18:56
-
-
Save febuiles/db935c5391a8283e6ebd13ee0a769bc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class TestMessageParser < ActiveSupport::TestCase | |
def test_data_decoder | |
d = MessageParser.new("PDU" => '000C640000010200000000') | |
assert_equal :data, d.packet_type | |
assert_equal "0C", d.firmware_version | |
assert_equal 100, d.power | |
assert_equal 1, d.gateway_id | |
assert_equal 2, d.num_satellites | |
end | |
def test_gps_decoder | |
d = MessageParser.new("PDU" => '010C5305AD53ED74E20113') | |
assert_equal :gps, d.packet_type | |
assert_equal "0C", d.firmware_version | |
assert_equal 83, d.power | |
assert_equal "37.3418", d.latitude | |
assert_equal "-121.8770", d.longitude | |
assert_equal 275, d.altitude | |
end | |
def test_dd_to_latlng | |
d = MessageParser.new("PDU" => '010C0105AE84ED62540093') | |
assert_equal "37.3926", d.latitude | |
assert_equal "-122.0020", d.longitude | |
end | |
def test_env_sensor_decoder | |
d = MessageParser.new("PDU" => '020641020BC01EFE001567') | |
assert_equal :sensor_bme, d.packet_type | |
assert_equal "06", d.firmware_version | |
assert_equal 2, d.satellite_id | |
assert_equal 30.08, d.temperature | |
assert_equal 79.34, d.humidity | |
assert_equal 54.79, d.pressure | |
end | |
def test_air_sensor_decoder | |
d = MessageParser.new("PDU" => '03064702013901B6000000') | |
assert_equal :sensor_iaq, d.packet_type | |
assert_equal "06", d.firmware_version | |
assert_equal 2, d.satellite_id | |
assert_equal 313, d.co2 | |
assert_equal 438, d.tvoc | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment