ME 405 Romi
Loading...
Searching...
No Matches
task_share.Queue Class Reference

A queue which is used to transfer data from one task to another. More...

Inheritance diagram for task_share.Queue:
Collaboration diagram for task_share.Queue:

Public Member Functions

 __init__ (self, type_code, size, thread_protect=False, overwrite=False, name=None)
 Initialize a queue object to carry and buffer data between tasks.
 put (self, item, in_ISR=False)
 Put an item into the queue.
 get (self, in_ISR=False)
 Read an item from the queue.
 any (self)
 Check if there are any items in the queue.
 empty (self)
 Check if the queue is empty.
 full (self)
 Check if the queue is full.
 num_in (self)
 Check how many items are in the queue.
 clear (self)
 Remove all contents from the queue.
 __repr__ (self)
 This method puts diagnostic information about the queue into a string.

Static Public Attributes

int ser_num = 0
 A counter used to give serial numbers to queues for diagnostic use.

Protected Attributes

 _size = size
 _overwrite = overwrite
str _name
 _buffer = array.array (type_code, range (size))
int _wr_idx = 0
int _num_items = self._size
# Record maximum fillage _max_full
int _rd_idx = 0

Detailed Description

A queue which is used to transfer data from one task to another.

If parameter 'thread_protect' is True when a queue is created, transfers of data will be protected from corruption in the case that one task might interrupt another due to use in a pre-emptive multithreading environment or due to one task being run as an interrupt service routine.

An example of the creation and use of a queue is as follows:

import task_share
# This queue holds unsigned short (16-bit) integers
my_queue = task_share.Queue ('H', 100, name="My Queue")
# Somewhere in one task, put data into the queue
my_queue.put (some_data)
# In another task, read data from the queue
something = my_queue.get ()
A queue which is used to transfer data from one task to another.
Definition task_share.py:90

Definition at line 90 of file task_share.py.

Constructor & Destructor Documentation

◆ __init__()

task_share.Queue.__init__ ( self,
type_code,
size,
thread_protect = False,
overwrite = False,
name = None )

Initialize a queue object to carry and buffer data between tasks.

This method sets up a queue by allocating memory for the contents and setting up the components in an empty configuration.

Each queue can only carry data of one particular type which must be chosen from the following list. The data type is specified by a one-letter type code which is given as for the Python array.array type, which can be any of the following:

b (signed char) B (unsigned char) 8 bit integers
h (signed short) H (unsigned short) 16 bit integers
i (signed int) I (unsigned int) 32 bit integers (probably)
l (signed long) L (unsigned long) 32 bit integers
q (signed long long) Q (unsigned long long) 64 bit integers
f (float) d (double-precision float)
Parameters
type_codeThe type of data items which the queue can hold
sizeThe maximum number of items which the queue can hold
thread_protectTrue if mutual exclusion protection is used
overwriteIf True, oldest data will be overwritten with new data if the queue becomes full
nameA short name for the queue, default QueueN where N is a serial number for the queue

Definition at line 120 of file task_share.py.

Member Function Documentation

◆ __repr__()

task_share.Queue.__repr__ ( self)

This method puts diagnostic information about the queue into a string.

It shows the queue's name and type as well as the maximum number of items and queue size.

Definition at line 297 of file task_share.py.

◆ any()

task_share.Queue.any ( self)

Check if there are any items in the queue.

Returns True if there are any items in the queue and False if the queue is empty.

Returns
True if items are in the queue, False if not

Definition at line 251 of file task_share.py.

◆ clear()

task_share.Queue.clear ( self)

Remove all contents from the queue.

Definition at line 286 of file task_share.py.

◆ empty()

task_share.Queue.empty ( self)

Check if the queue is empty.

Returns True if there are no items in the queue and False if there are any items therein.

Returns
True if queue is empty, False if it's not empty

Definition at line 261 of file task_share.py.

Here is the caller graph for this function:

◆ full()

task_share.Queue.full ( self)

Check if the queue is full.

This method returns True if the queue is already full and there is no room for more data without overwriting existing data.

Returns
True if the queue is full

Definition at line 271 of file task_share.py.

Here is the caller graph for this function:

◆ get()

task_share.Queue.get ( self,
in_ISR = False )

Read an item from the queue.

If there isn't anything in there, wait (blocking the calling process) until something becomes available. If non-blocking reads are needed, one should call any() to check for items before attempting to read from the queue. This is usually done in a low priority task:

def some_task ():
# Setup
while True:
if my_queue.any ():
something = my_queue.get ()
do_something_with (something)
# More loop stuff
yield 0
Parameters
in_ISRSet this to True if calling from within an ISR

Definition at line 218 of file task_share.py.

Here is the call graph for this function:

◆ num_in()

task_share.Queue.num_in ( self)

Check how many items are in the queue.

This method returns the number of items which are currently in the queue.

Returns
The number of items in the queue

Definition at line 281 of file task_share.py.

◆ put()

task_share.Queue.put ( self,
item,
in_ISR = False )

Put an item into the queue.

If there isn't room for the item, wait (blocking the calling process) until room becomes available, unless the overwrite constructor parameter was set to True to allow old data to be clobbered. If non-blocking behavior without overwriting is needed, one should call full() to ensure that the queue is not full before putting data into it:

def some_task ():
# Setup
while True:
if not my_queue.full ():
my_queue.put (create_something_to_put ())
yield 0
Parameters
itemThe item to be placed into the queue
in_ISRSet this to True if calling from within an ISR

Definition at line 168 of file task_share.py.

Here is the call graph for this function:

Member Data Documentation

◆ _buffer

task_share.Queue._buffer = array.array (type_code, range (size))
protected

Definition at line 133 of file task_share.py.

◆ _max_full

task_share.Queue._max_full
protected

Definition at line 192 of file task_share.py.

◆ _name

task_share.Queue._name
protected
Initial value:
= None \
else 'Queue' + str (Queue.ser_num)

Definition at line 127 of file task_share.py.

◆ _num_items

task_share.Queue._num_items = self._size
protected

Definition at line 191 of file task_share.py.

◆ _overwrite

task_share.Queue._overwrite = overwrite
protected

Definition at line 126 of file task_share.py.

◆ _rd_idx

int task_share.Queue._rd_idx = 0
protected

Definition at line 233 of file task_share.py.

◆ _size

task_share.Queue._size = size
protected

Definition at line 125 of file task_share.py.

◆ _wr_idx

int task_share.Queue._wr_idx = 0
protected

Definition at line 188 of file task_share.py.

◆ ser_num

int task_share.Queue.ser_num = 0
static

A counter used to give serial numbers to queues for diagnostic use.

Definition at line 93 of file task_share.py.


The documentation for this class was generated from the following file: