| 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 | import standardInterfaces__POA |
|---|
| 27 | import CF__POA |
|---|
| 28 | import threading |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | #------------------------------------------------------------------ |
|---|
| 32 | # dataIn_realChar_metadata_i class definition |
|---|
| 33 | #------------------------------------------------------------------ |
|---|
| 34 | # from radio |
|---|
| 35 | class dataIn_realChar_metadata_i(standardInterfaces__POA.realChar): |
|---|
| 36 | def __init__(self, parent, name): |
|---|
| 37 | self.parent = parent |
|---|
| 38 | self.name = name |
|---|
| 39 | |
|---|
| 40 | def pushPacket(self, data): |
|---|
| 41 | print "WARNING! rc2007_gui::pushPacket() not supported without meta data" |
|---|
| 42 | #self.parent.rx_work_mod.AddMetaData(data) |
|---|
| 43 | |
|---|
| 44 | def pushPacketMetaData(self, data, metadata): |
|---|
| 45 | #print "rx packet " + str(metadata.packet_id) + \ |
|---|
| 46 | # ", len = " + str(len(data)) + \ |
|---|
| 47 | # " voice? " + str(metadata.eom) |
|---|
| 48 | self.parent.rx_work_mod.AddMetaData(data, metadata) |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | #------------------------------------------------------------------ |
|---|
| 53 | # dataOut_realChar_metadata_i class definition |
|---|
| 54 | #------------------------------------------------------------------ |
|---|
| 55 | # to radio |
|---|
| 56 | class dataOut_realChar_metadata_i(CF__POA.Port): |
|---|
| 57 | def __init__(self, parent, name): |
|---|
| 58 | self.parent = parent |
|---|
| 59 | self.outPorts = {} |
|---|
| 60 | self.name = name |
|---|
| 61 | |
|---|
| 62 | self.data_buffer = [] |
|---|
| 63 | self.data_event = threading.Event() |
|---|
| 64 | self.data_buffer_lock = threading.Lock() |
|---|
| 65 | |
|---|
| 66 | self.is_running = True |
|---|
| 67 | self.process_thread = threading.Thread(target = self.Process) |
|---|
| 68 | self.process_thread.start() |
|---|
| 69 | |
|---|
| 70 | def connectPort(self, connection, connectionId): |
|---|
| 71 | port = connection._narrow(standardInterfaces__POA.realChar) |
|---|
| 72 | self.outPorts[str(connectionId)] = port |
|---|
| 73 | self.parent.to_radio_port_active = True |
|---|
| 74 | |
|---|
| 75 | def disconnectPort(self, connectionId): |
|---|
| 76 | self.outPorts.pop(str(connectionId)) |
|---|
| 77 | if len(self.outPorts)==0: |
|---|
| 78 | self.parent.to_radio_port_active = False |
|---|
| 79 | |
|---|
| 80 | def releasePort(self): |
|---|
| 81 | # shut down the Process thread |
|---|
| 82 | self.is_running = False |
|---|
| 83 | self.data_event.set() |
|---|
| 84 | |
|---|
| 85 | def send_data(self, data, metadata): |
|---|
| 86 | self.data_buffer_lock.acquire() |
|---|
| 87 | self.data_buffer.insert(0, (data, metadata)) |
|---|
| 88 | self.data_buffer_lock.release() |
|---|
| 89 | self.data_event.set() |
|---|
| 90 | |
|---|
| 91 | def Process(self): |
|---|
| 92 | while self.is_running: |
|---|
| 93 | |
|---|
| 94 | self.data_event.wait() |
|---|
| 95 | |
|---|
| 96 | while len(self.data_buffer) > 0: |
|---|
| 97 | self.data_buffer_lock.acquire() |
|---|
| 98 | # get data and metadata from the stack |
|---|
| 99 | (data, metadata) = self.data_buffer.pop() |
|---|
| 100 | self.data_buffer_lock.release() |
|---|
| 101 | #print "this is my data: " + str(data) + "\n\n" |
|---|
| 102 | #print "this is my meta data: " + str(metadata) + "\n\n" |
|---|
| 103 | |
|---|
| 104 | # send the data to all outPort connections |
|---|
| 105 | for port in self.outPorts.values(): |
|---|
| 106 | #print "tx packet " + str(metadata.packet_id) + \ |
|---|
| 107 | # ", len = " + str(len(data)) + \ |
|---|
| 108 | # " voice? " + str(metadata.eom) |
|---|
| 109 | port.pushPacketMetaData(data, metadata) |
|---|
| 110 | |
|---|
| 111 | self.data_event.clear() |
|---|
| 112 | |
|---|
| 113 | |
|---|