Skip to content

Commit

Permalink
Merge pull request #54 from VIP-LES/52-refactor-position-decode-function
Browse files Browse the repository at this point in the history
Refactored decode position and made position test
  • Loading branch information
aryanbattula authored Apr 12, 2023
2 parents fafb05e + 17a7a08 commit 69d995a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
4 changes: 2 additions & 2 deletions EosLib/format/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def set_validity(self):
self.valid = True

@staticmethod
def decode_position(gps_packet: Packet):
def decode_position(gps_packet: Packet | bytes):
new_position = Position()

if isinstance(gps_packet, Packet):
if new_position.gps_packet.data_header.data_type != Type.POSITION:
if gps_packet.data_header.data_type != Type.POSITION:
raise ValueError("Packet is not a position")
packet_body = gps_packet.body
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import find_packages

setup(name='EosLib',
version='2.0.0',
version='2.0.1',
description='Library of shared code between EosPayload and EosGround',
author='Lightning From The Edge of Space',
author_email='[email protected]',
Expand Down
66 changes: 66 additions & 0 deletions tests/format/test_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from datetime import datetime
from EosLib.packet.packet import Packet
import EosLib.packet.transmit_header
import EosLib.packet.data_header
from EosLib.format.position import Position, FlightState

import EosLib
from EosLib.packet import data_header, transmit_header
from EosLib.device import Device
from EosLib.packet import Packet
from EosLib.packet.definitions import Type

def test_position_bytes():
"""Tests encode and decode functions
:returns: If encode and decode work
:rtype: boolean
"""
current_time = datetime.now()
new_data = Position()

# new_data.set_validity()
time = current_time
encoded_new_data = new_data.encode_position(time.timestamp(), 23.0, 24.0, 25.0, 26.0, 5,
FlightState.NOT_SET)

decoded_new_data = Position.decode_position(encoded_new_data)

assert time == decoded_new_data.timestamp
assert 23.0 == decoded_new_data.latitude
assert 24.0 == decoded_new_data.longitude
assert 25.0 == decoded_new_data.altitude
assert 26.0 == decoded_new_data.speed
assert 5 == decoded_new_data.number_of_satellites
assert FlightState.NOT_SET == decoded_new_data.flight_state
assert decoded_new_data.valid


def test_position_packet():
"""Tests encode and decode functions for packet input
:returns: If encode and decode work
:rtype: boolean
"""

position_data_header = EosLib.packet.data_header.DataHeader(Device.O3, Type.POSITION)
position_transmit_header = EosLib.packet.transmit_header.TransmitHeader(2)

current_time = datetime.now()
new_data = Position()

encoded_new_data = new_data.encode_position(current_time.timestamp(), 24.0, 25.0, 26.0, 27.0, 5,
FlightState.NOT_SET)
packet = Packet(encoded_new_data, position_data_header, position_transmit_header)

decoded_new_data = Position.decode_position(packet)

assert current_time == decoded_new_data.timestamp
assert 24.0 == decoded_new_data.latitude
assert 25.0 == decoded_new_data.longitude
assert 26.0 == decoded_new_data.altitude
assert 27.0 == decoded_new_data.speed
assert 5 == decoded_new_data.number_of_satellites
assert FlightState.NOT_SET == decoded_new_data.flight_state
assert decoded_new_data.valid

0 comments on commit 69d995a

Please sign in to comment.