| 1 | ''' |
|---|
| 2 | /**************************************************************************** |
|---|
| 3 | |
|---|
| 4 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 5 | |
|---|
| 6 | This file is part of the OSSIE USRP_Commander_GUI. |
|---|
| 7 | |
|---|
| 8 | OSSIE USRP_Commander_GUI is free software; you can redistribute it and/or modify |
|---|
| 9 | it under the terms of the GNU General Public License as published by |
|---|
| 10 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | (at your option) any later version. |
|---|
| 12 | |
|---|
| 13 | OSSIE USRP_Commander_GUI is distributed in the hope that it will be useful, |
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | GNU General Public License for more details. |
|---|
| 17 | |
|---|
| 18 | You should have received a copy of the GNU General Public License |
|---|
| 19 | along with OSSIE USRP_Commander_GUI; if not, write to the Free Software |
|---|
| 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | |
|---|
| 22 | ****************************************************************************/ |
|---|
| 23 | |
|---|
| 24 | ''' |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | import standardInterfaces__POA |
|---|
| 28 | import CF__POA |
|---|
| 29 | import threading |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | #------------------------------------------------------------------ |
|---|
| 33 | # dataIn_realChar_metadata_i class definition |
|---|
| 34 | #------------------------------------------------------------------ |
|---|
| 35 | # from radio |
|---|
| 36 | class dataIn_realChar_metadata_i(standardInterfaces__POA.realChar): |
|---|
| 37 | def __init__(self, parent, name): |
|---|
| 38 | self.parent = parent |
|---|
| 39 | self.name = name |
|---|
| 40 | |
|---|
| 41 | def pushPacket(self, data, metadata): |
|---|
| 42 | self.parent.rx_work_mod.AddMetaData(data, metadata) |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | #------------------------------------------------------------------ |
|---|
| 47 | # dataOut_realChar_metadata_i class definition |
|---|
| 48 | #------------------------------------------------------------------ |
|---|
| 49 | # to radio |
|---|
| 50 | class dataOut_realChar_metadata_i(CF__POA.Port): |
|---|
| 51 | def __init__(self, parent, name): |
|---|
| 52 | self.parent = parent |
|---|
| 53 | self.outPorts = {} |
|---|
| 54 | self.name = name |
|---|
| 55 | |
|---|
| 56 | self.data_buffer = [] |
|---|
| 57 | self.data_event = threading.Event() |
|---|
| 58 | self.data_buffer_lock = threading.Lock() |
|---|
| 59 | |
|---|
| 60 | self.is_running = True |
|---|
| 61 | self.process_thread = threading.Thread(target = self.Process) |
|---|
| 62 | self.process_thread.start() |
|---|
| 63 | |
|---|
| 64 | def connectPort(self, connection, connectionId): |
|---|
| 65 | port = connection._narrow(standardInterfaces__POA.realChar) |
|---|
| 66 | self.outPorts[str(connectionId)] = port |
|---|
| 67 | self.parent.to_radio_port_active = True |
|---|
| 68 | |
|---|
| 69 | def disconnectPort(self, connectionId): |
|---|
| 70 | self.outPorts.pop(str(connectionId)) |
|---|
| 71 | if len(self.outPorts)==0: |
|---|
| 72 | self.parent.to_radio_port_active = False |
|---|
| 73 | |
|---|
| 74 | def releasePort(self): |
|---|
| 75 | # shut down the Process thread |
|---|
| 76 | self.is_running = False |
|---|
| 77 | self.data_event.set() |
|---|
| 78 | |
|---|
| 79 | def send_data(self, data, metadata): |
|---|
| 80 | self.data_buffer_lock.acquire() |
|---|
| 81 | self.data_buffer.insert(0, data, metadata) |
|---|
| 82 | self.data_buffer_lock.release() |
|---|
| 83 | self.data_event.set() |
|---|
| 84 | |
|---|
| 85 | def Process(self): |
|---|
| 86 | while self.is_running: |
|---|
| 87 | |
|---|
| 88 | self.data_event.wait() |
|---|
| 89 | |
|---|
| 90 | while len(self.data_buffer) > 0: |
|---|
| 91 | self.data_buffer_lock.acquire() |
|---|
| 92 | # get data and metadata from the stack |
|---|
| 93 | (data, metadata) = self.data_buffer.pop() |
|---|
| 94 | self.data_buffer_lock.release() |
|---|
| 95 | |
|---|
| 96 | # send the data to all outPort connections |
|---|
| 97 | for port in self.outPorts.values(): |
|---|
| 98 | port.pushPacket(data, metadata) |
|---|
| 99 | |
|---|
| 100 | self.data_event.clear() |
|---|
| 101 | |
|---|
| 102 | |
|---|