Skip to content

Commit

Permalink
Merge pull request #94 from CarletonURocketry/main
Browse files Browse the repository at this point in the history
update branch
  • Loading branch information
Juan-789 authored Apr 5, 2024
2 parents 61db2ec + e8d6fa4 commit a49f137
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
5 changes: 3 additions & 2 deletions modules/telemetry/telemetry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def parse_radio_block(pkt_version: int, block_header: BlockHeader, hex_block_con

return ParsedBlock(block_name, block_header, dict(block_contents)) # type: ignore

except ValueError:
logger.error("Invalid data block subtype")

except NotImplementedError:
logger.warning(
f"Block parsing for type {block_header.message_type}, with subtype {block_header.message_subtype} not \
implemented!"
)
except ValueError:
logger.error("Invalid data block subtype")


def parse_rn2483_transmission(data: str, config: Config) -> Optional[ParsedTransmission]:
Expand Down
71 changes: 69 additions & 2 deletions tests/parsing/test_full_telemetry_parsing.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,76 @@
import pytest
from modules.telemetry.telemetry_utils import is_valid_packet_header
from modules.telemetry.v1.block import PacketHeader
from modules.telemetry.v1.block import PacketHeader, BlockHeader, InvalidHeaderFieldValueError
from modules.telemetry.telemetry_utils import parse_radio_block, is_valid_packet_header
from modules.misc.config import load_config


@pytest.fixture
def pkt_version() -> int:
"""
returns the packet version as an integer:
"""
return 192


@pytest.fixture
def block_header() -> BlockHeader:
"""
returns a blockheader
"""
return BlockHeader.from_hex("02000200")


@pytest.fixture
def hex_block_contents() -> str:
"""
returns the contents
"""
return "00000000f0c30000"


def test_radio_block(pkt_version: int, block_header: BlockHeader, hex_block_contents: str) -> None:
"""
test a proper line on parse_radio_block
"""
prb = parse_radio_block(pkt_version, block_header, hex_block_contents)
assert prb is not None
if prb is not None:
assert prb.block_header.length == 12
assert prb.block_header.message_type == 0
assert prb.block_header.message_subtype == 2
assert prb.block_header.destination == 0
assert prb.block_name == "temperature"
assert prb.block_contents["mission_time"] == 0


# fixtures


@pytest.fixture
def not_implemented_datablock_subtype() -> BlockHeader:
return BlockHeader.from_hex("02000400")


def test_invalid_datablock_subtype(pkt_version: int, hex_block_contents: str):
"""
test for random subtype ValueError
"""
# subtype is 154, thus non-existent
with pytest.raises(
InvalidHeaderFieldValueError, match="Invalid BlockHeader field: 154 is not a valid value for DataBlockSubtype"
):
parse_radio_block(pkt_version, BlockHeader.from_hex("02009A00"), hex_block_contents)


def test_not_implemented_error(
pkt_version: int, not_implemented_datablock_subtype: BlockHeader, hex_block_contents: str
) -> None:
"""
test for a subtye that exists but is not implemented
"""
assert parse_radio_block(pkt_version, not_implemented_datablock_subtype, hex_block_contents) is None


config = load_config("config.json")

# Fixtures
Expand Down

0 comments on commit a49f137

Please sign in to comment.