Skip to content

Commit

Permalink
updating imports for priority queue class
Browse files Browse the repository at this point in the history
  • Loading branch information
tomyyyD committed Jun 5, 2024
1 parent 07d2bb0 commit c6e1fd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 47 deletions.
2 changes: 1 addition & 1 deletion applications/flight/Tasks/image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Tasks.log import LogTask as Task
import radio_utils.image_queue as iq
from radio_utils.image_queue import image_queue as iq
from pycubed import cubesat
from time import monotonic, localtime
from gc import collect
Expand Down
2 changes: 1 addition & 1 deletion applications/flight/lib/radio_utils/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pycubed import cubesat
import radio_utils
from radio_utils.transmission_queue import transmission_queue as tq
from radio_utils import image_queue as iq
from radio_utils.image_queue import image_queue as iq
from radio_utils import headers
from radio_utils.disk_buffered_message import DiskBufferedMessage
from radio_utils.memory_buffered_message import MemoryBufferedMessage
Expand Down
49 changes: 4 additions & 45 deletions applications/flight/lib/radio_utils/image_queue.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
"""The Transmission Queue is a max heap of messages to be transmitted.
"""The Image Queue is a max heap of filepaths to be transmitted.
Messages must support the `__lt__`, `__le__`, `__eq__`, `__ge__`, and `__gt__` operators.
This enables to the max heap to compare messages based on their priority.
"""
from . import priority_queue as pq
# from . import priority_queue as pq
from .priority_queue import PriorityQueue

queue = []
limit = 5

def push(msg):
"""Push a msg into the transmission queue
:param msg: The message to push
:type msg: Message | MemoryBufferedMessage | DiskBufferedMessage
"""
if len(queue) < limit:
pq.push(queue, msg)
else:
raise Exception("Queue is full")

def peek():
"""Returns the next message to be transmitted
:return: The next message to be transmitted
:rtype: Message | MemoryBufferedMessage | DiskBufferedMessage
"""
return queue[0]

def pop():
"""Returns the next message to be transmitted and removes it from the transmission queue
:return: The next message to be transmitted
:rtype: Message | MemoryBufferedMessage | DiskBufferedMessage
"""
return pq.pop(queue)

def empty():
"""Returns if the transmission queue is empty"""
return len(queue) == 0

def clear():
"""Clears the transmission queue"""
global queue
queue = []

def size():
"""Returns the number of messages in the transmission queue"""
global queue
return len(queue)
image_queue = PriorityQueue([], 5)

0 comments on commit c6e1fd4

Please sign in to comment.