root/experimental/components/rc2007_gui/WorkModules.py @ 4874

Revision 4874, 3.2 KB (checked in by DrewCormier, 6 years ago)

starting to add a rx work module in addition to the existing tx work module

Line 
1#! /usr/bin/env python
2
3'''
4/****************************************************************************
5
6Copyright 2007 Virginia Polytechnic Institute and State University
7
8This file is part of the OSSIE USRP_Commander_GUI.
9
10OSSIE USRP_Commander_GUI is free software; you can redistribute it and/or modify
11it under the terms of the GNU General Public License as published by
12the Free Software Foundation; either version 2 of the License, or
13(at your option) any later version.
14
15OSSIE USRP_Commander_GUI is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with OSSIE USRP_Commander_GUI; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24****************************************************************************/
25
26'''
27
28#!/usr/bin/env python
29import threading
30
31class WorkClass:
32    """This class provides a place for the main processing of the
33    component to reside."""
34
35    def __init__(self, rc2007_gui_ref):
36        '''Initialization.  Sets a reference to parent. 
37        Initializes the buffer.  Starts the Process data
38        thread, which waits for data to be added to the buffer'''
39
40        self.rc2007_gui_ref = rc2007_gui_ref
41       
42        self.voice_data_queue = []
43        self.voice_data_queue_lock = threading.Lock()
44        self.voice_data_signal = threading.Event()
45
46        self.is_running = True
47
48        self.process_thread = threading.Thread(target=self.Process)
49        self.process_thread.start()
50       
51    def __del__(self):
52        '''Destructor'''
53        pass
54       
55    def AddVoiceData(self, data):
56        '''Generally called by parent.  Adds data to a buffer.
57        The Process() method will wait for this buffer to be set.
58        '''
59        self.voice_data_queue_lock.acquire()
60        self.voice_data_queue.insert(0, data)
61        self.voice_data_queue_lock.release()
62        self.voice_data_signal.set()
63   
64    def SendTextData(self,text):
65        # TODO: pack/depack
66        # TODO: add meta data
67        # TODO: text should be data in send_data method
68        self.rc2007_gui_ref.to_radio_port_servant.send_data(text)
69       
70    def Release(self):
71        self.is_running = False
72        self.voice_data_signal.set()
73               
74    def Process(self):
75        while self.is_running:
76            self.voice_data_signal.wait()  # wait for data to be aded to the
77                                     # buffer in self.AddVoiceData()
78            while len(self.voice_data_queue) > 0:
79                # get the data from the buffer:
80                self.voice_data_queue_lock.acquire()
81                new_data = self.voice_data_queue.pop()
82                self.voice_data_queue_lock.release()
83                               
84                # forwarding voice data:
85                if self.rc2007_gui_ref.talk_flag:
86                    if self.rc2007_gui_ref.to_radio_port_active:
87                        # TODO: send voice metadata
88                        self.rc2007_gui_ref.to_radio_port_servant.send_data(data)   
89
90            self.voice_data_signal.clear()  # done reading the buffer
91                               
92
Note: See TracBrowser for help on using the browser.