| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | '''Write incomming packet(s) to file(s)''' |
|---|
| 4 | |
|---|
| 5 | import wx #needed for display stuff |
|---|
| 6 | from omniORB import CORBA #use this for the CORBA orb stuff (pushing packets) |
|---|
| 7 | import sys #for system commands (e.g., argv and argc stuff) |
|---|
| 8 | import CosNaming #narrowing naming context stuff |
|---|
| 9 | import CF, CF__POA #core framework stuff |
|---|
| 10 | import standardInterfaces__POA |
|---|
| 11 | from wx.lib.anchors import LayoutAnchors #used by splitter window |
|---|
| 12 | # import wx.lib.buttons as buttons #for special wx buttons |
|---|
| 13 | |
|---|
| 14 | class display_short(standardInterfaces__POA.complexShort): |
|---|
| 15 | '''Writes I and Q data to 2 files''' |
|---|
| 16 | |
|---|
| 17 | def __init__(self, orb, gui): |
|---|
| 18 | self.orb = orb |
|---|
| 19 | self.gui = gui #usually parent |
|---|
| 20 | self.delimiter = ',' |
|---|
| 21 | |
|---|
| 22 | def pushPacket(self, I_data, Q_data): |
|---|
| 23 | '''Store the data to be written to file when the Write Packet button is bushed''' |
|---|
| 24 | self.gui.I_data = I_data |
|---|
| 25 | self.gui.Q_data = Q_data |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | def create(parent,namespace, interface, ns_name, port_name): |
|---|
| 30 | #return MainFrame(parent, -1, namespace, interface, ns_name, port_name) |
|---|
| 31 | return MainFrame(parent, -1, "Don't know what this should be", namespace, interface, ns_name, port_name) |
|---|
| 32 | |
|---|
| 33 | #generate wx ids for my wx controls |
|---|
| 34 | [wxID_MAINFRAME, wxID_SPLITTERWINDOW1] = [wx.NewId() for _init_ctrls in range(2)] |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | class MainFrame(wx.Frame): |
|---|
| 38 | def __init__(self, parent, id, title, namespace, interface, component_name, port_name): |
|---|
| 39 | |
|---|
| 40 | self._init_ctrls(parent) |
|---|
| 41 | |
|---|
| 42 | self.I_data = [] |
|---|
| 43 | self.Q_data = [] |
|---|
| 44 | |
|---|
| 45 | self.parent = parent |
|---|
| 46 | self.namespace = namespace |
|---|
| 47 | self.interface = interface |
|---|
| 48 | self.my_local_controls = None |
|---|
| 49 | self.component_name = component_name |
|---|
| 50 | self.port_name = port_name |
|---|
| 51 | self.setup_graphics() |
|---|
| 52 | |
|---|
| 53 | # Now Create the menu bar and items |
|---|
| 54 | self.mainmenu = wx.MenuBar() |
|---|
| 55 | |
|---|
| 56 | menu = wx.Menu() |
|---|
| 57 | menu.Append(205, 'E&xit', 'Enough of this already!') |
|---|
| 58 | self.Bind(wx.EVT_MENU, self.OnFileExit, id=205) |
|---|
| 59 | self.mainmenu.Append(menu, '&File') |
|---|
| 60 | |
|---|
| 61 | menu = wx.Menu() |
|---|
| 62 | menu.Append(300, '&About', 'About this thing...') |
|---|
| 63 | self.Bind(wx.EVT_MENU, self.OnHelpAbout, id=300) |
|---|
| 64 | self.mainmenu.Append(menu, '&Help') |
|---|
| 65 | |
|---|
| 66 | self.SetMenuBar(self.mainmenu) |
|---|
| 67 | |
|---|
| 68 | # Bind the close event so we can disconnect the ports |
|---|
| 69 | self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) |
|---|
| 70 | |
|---|
| 71 | self.Show(True) |
|---|
| 72 | |
|---|
| 73 | self.iFileNameEditor.write('i_out.dat') |
|---|
| 74 | self.qFileNameEditor.write('q_out.dat') |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | def _init_ctrls(self, prnt): |
|---|
| 78 | wx.Frame.__init__(self, id=wxID_MAINFRAME, name='', parent=prnt, |
|---|
| 79 | pos=wx.Point(530, 680), size=wx.Size(520, 270), |
|---|
| 80 | style=wx.DEFAULT_FRAME_STYLE, title='Write to File Tool') |
|---|
| 81 | |
|---|
| 82 | self.splitterWindow1 = wx.SplitterWindow(id=wxID_SPLITTERWINDOW1, |
|---|
| 83 | name='splitterWindow1', parent=self, point=wx.Point(1, 1), |
|---|
| 84 | size=wx.Size(570, 270), style=wx.SP_3D) |
|---|
| 85 | self.splitterWindow1.SetConstraints(LayoutAnchors(self.splitterWindow1, |
|---|
| 86 | True, True, True, True)) |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | def OnFileExit(self, event): |
|---|
| 92 | '''This is what will happen when you select File -> Exit in the menu bar''' |
|---|
| 93 | self.Close() #close the frame |
|---|
| 94 | |
|---|
| 95 | def OnHelpAbout(self, event): |
|---|
| 96 | '''Stuff that gets displayed when you select Help -> About in the menu bar''' |
|---|
| 97 | from wx.lib.dialogs import ScrolledMessageDialog |
|---|
| 98 | about = ScrolledMessageDialog(self, "Write to file tool.\nA product of Wireless@VT.", "About...") |
|---|
| 99 | about.ShowModal() |
|---|
| 100 | |
|---|
| 101 | def setup_graphics(self): |
|---|
| 102 | self.CORBA_being_used = False |
|---|
| 103 | |
|---|
| 104 | if True: |
|---|
| 105 | self.CORBA_being_used = True |
|---|
| 106 | self.orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) |
|---|
| 107 | obj = self.orb.resolve_initial_references("NameService") |
|---|
| 108 | rootContext = obj._narrow(CosNaming.NamingContext) |
|---|
| 109 | if rootContext is None: |
|---|
| 110 | print "Failed to narrow the root naming context" |
|---|
| 111 | sys.exit(1) |
|---|
| 112 | name = [CosNaming.NameComponent(self.component_name[0],""), |
|---|
| 113 | CosNaming.NameComponent(self.component_name[1],""), |
|---|
| 114 | CosNaming.NameComponent(self.component_name[2],"")] |
|---|
| 115 | |
|---|
| 116 | try: |
|---|
| 117 | ResourceRef = rootContext.resolve(name) |
|---|
| 118 | |
|---|
| 119 | except: |
|---|
| 120 | print "Required resource not found" |
|---|
| 121 | sys.exit(1) |
|---|
| 122 | |
|---|
| 123 | ResourceHandle = ResourceRef._narrow(CF.Resource) |
|---|
| 124 | PortReference = ResourceHandle.getPort(self.port_name) |
|---|
| 125 | if PortReference is None: |
|---|
| 126 | print "Failed to get Port reference" |
|---|
| 127 | self.PortHandle = PortReference._narrow(CF.Port) |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | #create the class instance of the display class |
|---|
| 131 | self.my_file_writer = display_short(self.orb, self) |
|---|
| 132 | |
|---|
| 133 | obj_poa = self.orb.resolve_initial_references("RootPOA") |
|---|
| 134 | poaManager = obj_poa._get_the_POAManager() |
|---|
| 135 | poaManager.activate() |
|---|
| 136 | obj_poa.activate_object(self.my_file_writer) |
|---|
| 137 | self.PortHandle.connectPort(self.my_file_writer._this(), "thisismyconnectionid_disp") |
|---|
| 138 | #orb.run() |
|---|
| 139 | |
|---|
| 140 | def OnCloseWindow(self,event): |
|---|
| 141 | if hasattr(self.parent, 'removeToolFrame'): |
|---|
| 142 | self.parent.removeToolFrame(self) |
|---|
| 143 | self = None |
|---|
| 144 | event.Skip() |
|---|
| 145 | |
|---|
| 146 | def __del__(self): |
|---|
| 147 | if self.CORBA_being_used: |
|---|
| 148 | self.PortHandle.disconnectPort("thisismyconnectionid_disp") |
|---|
| 149 | while (_time.time() - self.my_local_plot.end_time) < 1.5: |
|---|
| 150 | #print (time.time() - self.my_local_plot.end_time) |
|---|
| 151 | pass |
|---|
| 152 | #_time.sleep(1) |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | |
|---|