Subversion Repositories Projects

Rev

Rev 623 | Rev 627 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
584 FredericG 1
#!/usr/bin/env python
2
# -*- coding: iso-8859-15 -*-
3
# generated by wxGlade 0.6.3 on Thu Sep 24 15:46:36 2009
4
 
586 FredericG 5
import sys
606 FredericG 6
import os
612 FredericG 7
import time
8
import thread
9
import ConfigParser
10
 
584 FredericG 11
import wx
585 FredericG 12
import wx.lib
13
import wx.lib.plot
612 FredericG 14
import wx.lib.newevent
623 FredericG 15
import wx.lib.agw.speedmeter as speedmeter
584 FredericG 16
 
613 FredericG 17
import mkProto
18
 
19
 
20
 
21
CHANNEL_NAMES = ["GyroYaw", "GyroRoll", "GyroNick", "Pressure", "Batt", "AccTop", "AccRoll", "AccNick"]
615 FredericG 22
FS = 11111
623 FredericG 23
pi = 3.14
613 FredericG 24
 
626 FredericG 25
rootPath = ""
26
 
585 FredericG 27
# Needs Numeric or numarray or NumPy
28
try:
29
    import numpy.oldnumeric as _Numeric
30
except:
31
    try:
32
        import numarray as _Numeric  #if numarray is used it is renamed Numeric
33
    except:
34
        try:
35
            import Numeric as _Numeric
36
        except:
37
            msg= """
38
            This module requires the Numeric/numarray or NumPy module,
39
            which could not be imported.  It probably is not installed
40
            (it's not part of the standard Python distribution). See the
41
            Numeric Python site (http://numpy.scipy.org) for information on
42
            downloading source or binaries."""
43
            raise ImportError, "Numeric,numarray or NumPy not found. \n" + msg
44
 
584 FredericG 45
# begin wxGlade: extracode
46
# end wxGlade
47
 
48
 
612 FredericG 49
# This creates a new Event class and a EVT binder function
613 FredericG 50
(MeasStatusUpdateEvent, EVT_MEAS_STATUS_UPDATE) = wx.lib.newevent.NewEvent()  
51
(MeasDataEvent, EVT_MEAS_DATA) = wx.lib.newevent.NewEvent()  
584 FredericG 52
 
612 FredericG 53
class MeasureDialog(wx.Dialog):
54
    def __init__(self, *args, **kwds):
55
        # begin wxGlade: MeasureDialog.__init__
626 FredericG 56
        kwds["style"] = wx.CAPTION|wx.RESIZE_BORDER|wx.THICK_FRAME
612 FredericG 57
        wx.Dialog.__init__(self, *args, **kwds)
58
        self.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
59
        self.button = wx.Button(self, -1, "STOP")
623 FredericG 60
        self.voltageCtrl = speedmeter.SpeedMeter(self, extrastyle=speedmeter.SM_DRAW_HAND | speedmeter.SM_DRAW_PARTIAL_SECTORS |  speedmeter.SM_DRAW_MIDDLE_ICON )
61
        self.speedCtrl = speedmeter.SpeedMeter(self, extrastyle=speedmeter.SM_DRAW_HAND | speedmeter.SM_DRAW_PARTIAL_SECTORS | speedmeter.SM_DRAW_MIDDLE_TEXT | speedmeter.SM_DRAW_SECONDARY_TICKS)
626 FredericG 62
 
612 FredericG 63
        self.__set_properties()
64
        self.__do_layout()
65
 
66
        self.Bind(wx.EVT_BUTTON, self.onButton, self.button)
67
        # end wxGlade
68
 
626 FredericG 69
        self.button.SetFocus()
70
 
623 FredericG 71
        YELLOW = wx.Colour(255, 240, 0)
72
        BG = wx.Colour(0x80, 0x80, 0x80)
73
        # Configure Voltage Ctrl
74
        self.voltageCtrl.SetAngleRange(0,pi)
75
        intervals = range(0, 5)
76
        self.voltageCtrl.SetIntervals(intervals)
77
        colours = [wx.RED, wx.GREEN, wx.GREEN, YELLOW]
78
        self.voltageCtrl.SetIntervalColours(colours)
79
        ticks = ["", "", "", "", ""]
80
        self.voltageCtrl.SetTicks(ticks)
81
        self.voltageCtrl.SetTicksColour(wx.WHITE)
82
        self.voltageCtrl.SetHandColour(YELLOW)
83
 
626 FredericG 84
        icon = wx.Icon("%s/Resources/fuel.ico" % rootPath, wx.BITMAP_TYPE_ICO)
623 FredericG 85
        icon.SetWidth(24)
86
        icon.SetHeight(24)
87
 
88
        self.voltageCtrl.SetMiddleIcon(icon)        
89
        self.voltageCtrl.SetSpeedBackground(BG)        
90
        self.voltageCtrl.SetArcColour(wx.WHITE)
91
        self.voltageCtrl.SetSpeedValue(2)
92
 
93
 
94
        # Configure Speed Ctr;
95
        self.speedCtrl.SetAngleRange(0,pi)        
96
        intervals = range(0, 261, 20)
97
        self.speedCtrl.SetIntervals(intervals)
98
 
99
        colours = [BG]*(len(intervals)-1)
100
        for i in range(5,10):
101
          colours[i] = wx.GREEN
102
        self.speedCtrl.SetIntervalColours(colours)
103
        ticks = [str(interval) for interval in intervals]
104
        self.speedCtrl.SetTicks(ticks)
105
        self.speedCtrl.SetTicksColour(wx.WHITE)
106
        self.speedCtrl.SetNumberOfSecondaryTicks(1)
107
        self.speedCtrl.SetTicksFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL))
108
        self.speedCtrl.SetMiddleText("Speed")
109
        self.speedCtrl.SetMiddleTextColour(wx.WHITE)
110
        self.speedCtrl.SetMiddleTextFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD))
111
        self.speedCtrl.SetHandColour(YELLOW)
112
        self.speedCtrl.SetSpeedBackground(BG)  
113
        self.speedCtrl.SetArcColour(wx.WHITE)        
114
        self.speedCtrl.SetSpeedValue(0)
115
 
116
 
612 FredericG 117
        self.running = True
118
        self.Bind(EVT_MEAS_STATUS_UPDATE, self.OnUpdate)
613 FredericG 119
        self.Bind(EVT_MEAS_DATA, self.OnData)
120
        # The first argument that is passed to the constructor is the parent
121
        self.app = args[0].app
122
        self.error = False
623 FredericG 123
        self.firstVoltage = True
612 FredericG 124
 
623 FredericG 125
 
612 FredericG 126
    def __set_properties(self):
127
        # begin wxGlade: MeasureDialog.__set_properties
128
        self.SetTitle("Measuring Status")
129
        self.text_ctrl_1.SetMinSize((400,300))
623 FredericG 130
        self.voltageCtrl.SetMinSize((50,-1))
131
        self.speedCtrl.SetMinSize((50,-1))
612 FredericG 132
        # end wxGlade
133
 
134
    def __do_layout(self):
135
        # begin wxGlade: MeasureDialog.__do_layout
136
        sizer_1 = wx.BoxSizer(wx.HORIZONTAL)
623 FredericG 137
        sizer_4 = wx.BoxSizer(wx.VERTICAL)
612 FredericG 138
        sizer_2 = wx.BoxSizer(wx.VERTICAL)
139
        sizer_1.Add((20, 20), 0, 0, 0)
140
        sizer_2.Add((20, 20), 0, 0, 0)
141
        sizer_2.Add(self.text_ctrl_1, 1, wx.EXPAND, 0)
142
        sizer_2.Add((20, 20), 0, 0, 0)
143
        sizer_2.Add(self.button, 0, wx.ALIGN_CENTER_HORIZONTAL, 0)
144
        sizer_2.Add((20, 20), 0, 0, 0)
145
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
146
        sizer_1.Add((20, 20), 0, 0, 0)
623 FredericG 147
        sizer_4.Add(self.voltageCtrl, 1, wx.EXPAND, 0)
148
        sizer_4.Add(self.speedCtrl, 1, wx.EXPAND, 0)
149
        sizer_1.Add(sizer_4, 1, wx.EXPAND, 0)
150
        sizer_1.Add((20, 20), 0, 0, 0)
612 FredericG 151
        self.SetSizer(sizer_1)
152
        sizer_1.Fit(self)
153
        self.Layout()
154
        # end wxGlade
613 FredericG 155
 
156
    def OnData(self, evt):
157
        print "Received Data"
158
        self.app.AddTest2(evt.vibTest)
623 FredericG 159
 
612 FredericG 160
    def OnUpdate(self, evt):
613 FredericG 161
        print "Status update"
612 FredericG 162
        self.running = evt.running
613 FredericG 163
        if evt.error:
164
            self.error = True;
165
            self.text_ctrl_1.WriteText("ERROR: ")
166
            self.text_ctrl_1.SetBackgroundColour("Red")  
612 FredericG 167
        self.text_ctrl_1.WriteText("%s\n"%evt.msg)
168
        if (not self.running):
613 FredericG 169
            if (not self.error):
170
                self.text_ctrl_1.SetBackgroundColour("Green")
171
                self.text_ctrl_1.write(" ") # so that the background is redrawn
623 FredericG 172
            self.button.SetLabel("Close")
613 FredericG 173
 
623 FredericG 174
        if evt.speed != None:
175
            self.speedCtrl.SetSpeedValue(evt.speed)
176
 
177
        if evt.voltage != None:
178
            vmin,vmax,v = evt.voltage
179
            if self.firstVoltage:
180
                ticks = ["", "%.1f V"%vmin, "", "%.1f V"%vmax, ""]
181
                self.voltageCtrl.SetTicks(ticks)
182
                self.firstVoltage = False
183
            i = (v-vmin)/(vmax-vmin)  # 0..1
184
            i *= 2
185
            i = i+1
186
            i = min(max(i,0),5)
187
            self.voltageCtrl.SetSpeedValue(i)
188
 
189
 
612 FredericG 190
 
191
    def onButton(self, event): # wxGlade: MeasureDialog.<event_handler>
192
        if (not self.running):
193
            self.Destroy()
613 FredericG 194
        else:
195
            self.app.cancelMeasurement()
612 FredericG 196
 
197
# end of class MeasureDialog
198
 
199
 
607 FredericG 200
class SettingsDialog(wx.Dialog):
601 FredericG 201
    def __init__(self, *args, **kwds):
607 FredericG 202
        # begin wxGlade: SettingsDialog.__init__
203
        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
204
        wx.Dialog.__init__(self, *args, **kwds)
608 FredericG 205
        self.button_5 = wx.Button(self, wx.ID_CANCEL, "")
206
        self.button_6 = wx.Button(self, wx.ID_OK, "")
601 FredericG 207
 
208
        self.__set_properties()
209
        self.__do_layout()
611 FredericG 210
 
211
        self.Bind(wx.EVT_BUTTON, self.onOK, self.button_6)
601 FredericG 212
        # end wxGlade
213
 
608 FredericG 214
        # The first argument that is passed to the constructor is the parent
611 FredericG 215
        self.settings = args[0].app.settings
608 FredericG 216
        # Add text-boxes for all settings
611 FredericG 217
        self.tb = []
218
        self.grid_sizer_2.SetRows(len(self.settings))
219
        for setting in self.settings.iteritems():
608 FredericG 220
            lb = wx.StaticText(self, -1, setting[1].descr, style=wx.ALIGN_RIGHT)
221
            tb = wx.TextCtrl(self, -1, str(setting[1].value))
222
            self.grid_sizer_2.Add(lb, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
223
            self.grid_sizer_2.Add(tb, 0, 0, 0)
611 FredericG 224
            self.tb.append(tb)
608 FredericG 225
        self.sizer_5.Fit(self)
226
        self.Layout()
227
 
601 FredericG 228
    def __set_properties(self):
607 FredericG 229
        # begin wxGlade: SettingsDialog.__set_properties
601 FredericG 230
        self.SetTitle("Settings")
231
        # end wxGlade
232
 
233
    def __do_layout(self):
607 FredericG 234
        # begin wxGlade: SettingsDialog.__do_layout
608 FredericG 235
        sizer_5 = wx.BoxSizer(wx.VERTICAL)
236
        grid_sizer_3 = wx.GridSizer(1, 2, 0, 0)
237
        sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
238
        grid_sizer_2 = wx.GridSizer(1, 2, 4, 4)
239
        sizer_5.Add((20, 20), 0, 0, 0)
240
        sizer_6.Add((20, 20), 0, 0, 0)
241
        sizer_6.Add(grid_sizer_2, 0, 0, 0)
242
        sizer_6.Add((20, 20), 0, 0, 0)
243
        sizer_5.Add(sizer_6, 1, wx.EXPAND, 0)
244
        sizer_5.Add((20, 20), 0, 0, 0)
245
        grid_sizer_3.Add(self.button_5, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
246
        grid_sizer_3.Add(self.button_6, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0)
247
        sizer_5.Add(grid_sizer_3, 0, wx.EXPAND, 0)
248
        sizer_5.Add((20, 20), 0, 0, 0)
249
        self.SetSizer(sizer_5)
250
        sizer_5.Fit(self)
601 FredericG 251
        self.Layout()
252
        # end wxGlade
253
 
608 FredericG 254
        # Store some of the items, we will need them later
255
        self.grid_sizer_2 = grid_sizer_2  
256
        self.sizer_5 = sizer_5
257
 
258
 
611 FredericG 259
    def onOK(self, event): # wxGlade: SettingsDialog.<event_handler>
260
        print "Updating parameters"
261
        try:
262
            i=0
263
            for setting in self.settings.iteritems():
264
              print setting[0], self.tb[i].GetValue()
265
              setting[1].set(self.tb[i].GetValue())
266
              i += 1
267
            event.Skip()
268
        except:
269
            wx.MessageBox("Invalid format for \"%s\" setting." % setting[1].descr)
270
 
607 FredericG 271
# end of class SettingsDialog
272
 
273
 
274
 
584 FredericG 275
class MainFrame(wx.Frame):
276
    def __init__(self, *args, **kwds):
277
        # begin wxGlade: MainFrame.__init__
278
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
279
        wx.Frame.__init__(self, *args, **kwds)
587 FredericG 280
 
281
        # Menu Bar
282
        self.frame_1_menubar = wx.MenuBar()
283
        wxglade_tmp_menu = wx.Menu()
607 FredericG 284
        wxglade_tmp_menu.Append(101, "Settings", "", wx.ITEM_NORMAL)
616 FredericG 285
        wxglade_tmp_menu.AppendSeparator()
607 FredericG 286
        wxglade_tmp_menu.Append(150, "Exit", "", wx.ITEM_NORMAL)
587 FredericG 287
        self.frame_1_menubar.Append(wxglade_tmp_menu, "File")
288
        wxglade_tmp_menu = wx.Menu()
616 FredericG 289
        wxglade_tmp_menu.Append(301, "Clear All", "", wx.ITEM_NORMAL)
290
        wxglade_tmp_menu.Append(302, "Clear Selected", "", wx.ITEM_NORMAL)
291
        wxglade_tmp_menu.AppendSeparator()
292
        wxglade_tmp_menu.Append(303, "Load", "", wx.ITEM_NORMAL)
293
        wxglade_tmp_menu.Append(304, "Save", "", wx.ITEM_NORMAL)
587 FredericG 294
        self.frame_1_menubar.Append(wxglade_tmp_menu, "TestSet")
295
        wxglade_tmp_menu = wx.Menu()
626 FredericG 296
        wxglade_tmp_menu.Append(401, "Flash VibTest FC software", "", wx.ITEM_NORMAL)
297
        wxglade_tmp_menu.Append(402, "Restore original FC software", "", wx.ITEM_NORMAL)
587 FredericG 298
        self.frame_1_menubar.Append(wxglade_tmp_menu, "MK")
299
        wxglade_tmp_menu = wx.Menu()
626 FredericG 300
        wxglade_tmp_menu.Append(1099, "About", "", wx.ITEM_NORMAL)
587 FredericG 301
        self.frame_1_menubar.Append(wxglade_tmp_menu, "Help")
302
        self.SetMenuBar(self.frame_1_menubar)
303
        # Menu Bar end
600 FredericG 304
        self.Description = wx.StaticText(self, -1, "Description")
613 FredericG 305
        self.tcDescr = wx.TextCtrl(self, -1, "Test")
600 FredericG 306
        self.label_37 = wx.StaticText(self, -1, "Speed(s)")
613 FredericG 307
        self.tcSpeeds = wx.TextCtrl(self, -1, "100-200:10")
600 FredericG 308
        self.label_35 = wx.StaticText(self, -1, "Motor(s)")
613 FredericG 309
        self.tcMotors = wx.TextCtrl(self, -1, "1")
600 FredericG 310
        self.label_38 = wx.StaticText(self, -1, "")
626 FredericG 311
        self.panel_2 = wx.Panel(self, -1)
613 FredericG 312
        self.label_36 = wx.StaticText(self, -1, "Channel(s)")
313
        self.tcChannels = wx.TextCtrl(self, -1, "6")
600 FredericG 314
        self.label_39 = wx.StaticText(self, -1, "")
626 FredericG 315
        self.panel_3 = wx.Panel(self, -1)
316
        self.button_4 = wx.Button(self, -1, "Measure")
317
        self.graphCtrl = wx.lib.plot.PlotCanvas(self, size=(800,300))
600 FredericG 318
        self.label_40 = wx.StaticText(self, -1, "Graph Type ")
319
        self.graphTypeChoice = wx.Choice(self, -1, choices=["Raw Signal", "Filtered Signal", "Spectrum"])
320
        self.label_41 = wx.StaticText(self, -1, "Y Axis Range ")
321
        self.yAxisChoice = wx.Choice(self, -1, choices=["25", "50", "100", "200"])
586 FredericG 322
        self.TestListCtrl = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
584 FredericG 323
 
324
        self.__set_properties()
325
        self.__do_layout()
587 FredericG 326
 
607 FredericG 327
        self.Bind(wx.EVT_MENU, self.OnSettings, id=101)
626 FredericG 328
        self.Bind(wx.EVT_MENU, self.onExit, id=150)
607 FredericG 329
        self.Bind(wx.EVT_MENU, self.onClear, id=301)
616 FredericG 330
        self.Bind(wx.EVT_MENU, self.onClearSelected, id=302)
331
        self.Bind(wx.EVT_MENU, self.OnImport, id=303)
332
        self.Bind(wx.EVT_MENU, self.onExport, id=304)
626 FredericG 333
        self.Bind(wx.EVT_MENU, self.onAbout, id=1099)
612 FredericG 334
        self.Bind(wx.EVT_BUTTON, self.onStartMeasure, self.button_4)
600 FredericG 335
        self.Bind(wx.EVT_CHOICE, self.onGraphTypeChange, self.graphTypeChoice)
336
        self.Bind(wx.EVT_CHOICE, self.onYAxisChange, self.yAxisChoice)
584 FredericG 337
        # end wxGlade
626 FredericG 338
        favicon = wx.Icon('%s/Resources/60px-Procman.ico' % rootPath, wx.BITMAP_TYPE_ICO, 32, 32)
339
        wx.Frame.SetIcon(self, favicon)
584 FredericG 340
 
587 FredericG 341
    def setApp(self, app):
342
        self.app = app
585 FredericG 343
 
584 FredericG 344
    def __set_properties(self):
345
        # begin wxGlade: MainFrame.__set_properties
587 FredericG 346
        self.SetTitle("VibrationTest")
600 FredericG 347
        self.SetSize((850, 700))
348
        self.Description.SetMinSize((53, 13))
601 FredericG 349
        self.button_4.SetMinSize((80, 80))
626 FredericG 350
        self.graphCtrl.SetMinSize((800,300))
600 FredericG 351
        self.graphTypeChoice.SetSelection(0)
352
        self.yAxisChoice.SetSelection(1)
353
        self.TestListCtrl.SetMinSize((800,300))
584 FredericG 354
        # end wxGlade
355
 
356
    def __do_layout(self):
357
        # begin wxGlade: MainFrame.__do_layout
600 FredericG 358
        sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
359
        sizer_8 = wx.BoxSizer(wx.VERTICAL)
360
        sizer_11 = wx.BoxSizer(wx.VERTICAL)
361
        sizer_12 = wx.BoxSizer(wx.HORIZONTAL)
362
        sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
363
        sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
364
        grid_sizer_1 = wx.GridSizer(3, 4, 4, 5)
365
        sizer_3.Add((20, 20), 0, 0, 0)
366
        sizer_8.Add((20, 20), 0, 0, 0)
367
        grid_sizer_1.Add(self.Description, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
613 FredericG 368
        grid_sizer_1.Add(self.tcDescr, 0, 0, 0)
600 FredericG 369
        grid_sizer_1.Add(self.label_37, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
613 FredericG 370
        grid_sizer_1.Add(self.tcSpeeds, 0, 0, 0)
600 FredericG 371
        grid_sizer_1.Add(self.label_35, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
613 FredericG 372
        grid_sizer_1.Add(self.tcMotors, 0, 0, 0)
600 FredericG 373
        grid_sizer_1.Add(self.label_38, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
626 FredericG 374
        grid_sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0)
600 FredericG 375
        grid_sizer_1.Add(self.label_36, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
613 FredericG 376
        grid_sizer_1.Add(self.tcChannels, 0, 0, 0)
600 FredericG 377
        grid_sizer_1.Add(self.label_39, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL, 0)
626 FredericG 378
        grid_sizer_1.Add(self.panel_3, 1, wx.EXPAND, 0)
600 FredericG 379
        sizer_9.Add(grid_sizer_1, 0, 0, 0)
380
        sizer_10.Add((50, 20), 0, 0, 0)
381
        sizer_10.Add(self.button_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
382
        sizer_9.Add(sizer_10, 1, wx.EXPAND, 0)
383
        sizer_8.Add(sizer_9, 0, 0, 0)
384
        sizer_8.Add((20, 30), 0, 0, 0)
626 FredericG 385
        sizer_11.Add(self.graphCtrl, 1, wx.EXPAND, 0)
600 FredericG 386
        sizer_11.Add((20, 5), 0, 0, 0)
387
        sizer_12.Add(self.label_40, 0, wx.ALIGN_CENTER_VERTICAL, 0)
388
        sizer_12.Add(self.graphTypeChoice, 0, 0, 0)
389
        sizer_12.Add((40, 20), 0, 0, 0)
390
        sizer_12.Add(self.label_41, 0, wx.ALIGN_CENTER_VERTICAL, 0)
391
        sizer_12.Add(self.yAxisChoice, 0, 0, 0)
392
        sizer_11.Add(sizer_12, 0, 0, 0)
393
        sizer_8.Add(sizer_11, 0, 0, 0)
394
        sizer_8.Add((20, 30), 0, 0, 0)
395
        sizer_8.Add(self.TestListCtrl, 1, 0, 0)
396
        sizer_8.Add((20, 20), 0, 0, 0)
397
        sizer_3.Add(sizer_8, 1, wx.EXPAND, 0)
398
        self.SetSizer(sizer_3)
584 FredericG 399
        self.Layout()
600 FredericG 400
        self.SetSize((850, 700))
584 FredericG 401
        # end wxGlade
402
 
590 FredericG 403
        # List events
404
        self.TestListCtrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnTestSelected, self.TestListCtrl)
405
 
586 FredericG 406
        # Configure Graph
626 FredericG 407
        #self.graphCtrl = wx.lib.plot.PlotCanvas(self.GraphPanel, size=(800,300))
593 FredericG 408
 
626 FredericG 409
        self.graphCtrl.SetPointLabelFunc(self.DrawPointLabel)
585 FredericG 410
 
626 FredericG 411
        self.graphCtrl.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
412
        self.graphCtrl.SetFontSizeAxis(10)
413
        self.graphCtrl.SetFontSizeLegend(7)
414
        self.graphCtrl.setLogScale((False,False))
585 FredericG 415
 
586 FredericG 416
 
417
        # Configure TestListCtrl
594 FredericG 418
        self.TestListCtrl.InsertColumn(0, "Description")
619 FredericG 419
        self.TestListCtrl.InsertColumn(1, "Voltage")
420
        self.TestListCtrl.InsertColumn(2, "Speed")
421
        self.TestListCtrl.InsertColumn(3, "Channel")
422
        self.TestListCtrl.InsertColumn(4, "Vibration Value")
423
        self.TestListCtrl.SetColumnWidth(4, 500)
586 FredericG 424
 
585 FredericG 425
    def DrawPointLabel(self, dc, mDataDict):
426
        """This is the fuction that defines how the pointLabels are plotted
427
            dc - DC that will be passed
428
            mDataDict - Dictionary of data that you want to use for the pointLabel
429
 
430
            As an example I have decided I want a box at the curve point
431
            with some text information about the curve plotted below.
432
            Any wxDC method can be used.
433
        """
434
        # ----------
435
        dc.SetPen(wx.Pen(wx.BLACK))
436
        dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
437
 
438
        sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
439
        dc.DrawRectangle( sx-5,sy-5, 10, 10)  #10by10 square centered on point
440
        px,py = mDataDict["pointXY"]
441
        cNum = mDataDict["curveNum"]
442
        pntIn = mDataDict["pIndex"]
443
        legend = mDataDict["legend"]
444
        #make a string to display
445
        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, pntIn)
446
        dc.DrawText(s, sx , sy+1)
447
        # -----------
448
 
596 FredericG 449
 
450
    def onNewTest(self, test):
451
        index = self.TestListCtrl.InsertStringItem(sys.maxint, test.descr)
619 FredericG 452
        self.TestListCtrl.SetStringItem(index, 1, "%.1f V" %test.voltage)
453
        self.TestListCtrl.SetStringItem(index, 2, str(test.speed))
454
        self.TestListCtrl.SetStringItem(index, 3, test.channel)
607 FredericG 455
 
615 FredericG 456
        vv = int(test.getVibValue(self.app.settings["hpf"].value, self.app.settings["lpf"].value))
607 FredericG 457
        vvs = "|%s| (%d)" % ("----------------------------------------------------------------------------------------------------"[0:min(vv,100)], vv)
619 FredericG 458
        self.TestListCtrl.SetStringItem(index, 4, vvs)
613 FredericG 459
        self.TestListCtrl.Select(index)
596 FredericG 460
 
461
 
590 FredericG 462
    def OnTestSelected(self, event):
463
         testId = event.m_itemIndex
464
         print "Test Selected id=%d" % (testId)
592 FredericG 465
         self.activeTestId = testId
466
         self.drawGraph()
590 FredericG 467
 
592 FredericG 468
    def drawGraph(self):
607 FredericG 469
 
600 FredericG 470
         y = int(self.yAxisChoice.GetStringSelection())
590 FredericG 471
 
607 FredericG 472
         nbSelected = self.TestListCtrl.SelectedItemCount
596 FredericG 473
 
616 FredericG 474
         if nbSelected == 0:
626 FredericG 475
              self.graphCtrl.Clear()
616 FredericG 476
 
477
         elif nbSelected > 1:
607 FredericG 478
             self.graphTypeChoice.Disable()
479
             x = 1
480
             data = []
481
             idx = self.TestListCtrl.GetFirstSelected()
482
             while idx != -1:
615 FredericG 483
                 data.append([x,self.app.getTest(idx).getVibValue(self.app.settings["hpf"].value, self.app.settings["lpf"].value)])
607 FredericG 484
                 x += 1
485
                 idx = self.TestListCtrl.GetNextSelected(idx)
486
             line = wx.lib.plot.PolyLine(data, legend= 'Vibrations', colour='red', width=2)
487
             markers = wx.lib.plot.PolyMarker(data, legend= '', colour='red', marker='circle',size=2)
488
             title = "Comparing tests"
626 FredericG 489
             self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line, markers], title, "Test", "Vibration Value"), xAxis=(1,max(x,10)), yAxis=(0,y))
490
             self.graphCtrl.SetEnableGrid('Horizontal')
600 FredericG 491
 
607 FredericG 492
         else:
493
             self.graphTypeChoice.Enable()
494
             vibTest = self.app.getTest(self.activeTestId)
495
             nb = vibTest.getDataLen()
590 FredericG 496
 
607 FredericG 497
             if self.graphTypeChoice.GetSelection() == 0:
498
                 xydata = _Numeric.linspace(0,0.09*nb,2*nb)
499
                 xydata.shape = (nb, 2)
500
                 xydata[:,1] = vibTest.getRawData()
501
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
502
 
503
                 title = "Raw Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
626 FredericG 504
                 self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
505
                 self.graphCtrl.SetEnableGrid('Horizontal')
599 FredericG 506
 
607 FredericG 507
             if self.graphTypeChoice.GetSelection() == 1:
508
                 xydata = _Numeric.linspace(0,0.09*nb,2*nb)
509
                 xydata.shape = (nb, 2)
615 FredericG 510
                 xydata[:,1] = vibTest.getFilteredData(self.app.settings["hpf"].value, self.app.settings["lpf"].value)
607 FredericG 511
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Raw Data', colour='red', width=2)
512
 
513
                 title = "Filtered Signal: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
626 FredericG 514
                 self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line], title, "Time (ms)", "Acc"), yAxis= (-y,y))
515
                 self.graphCtrl.SetEnableGrid('Horizontal')
607 FredericG 516
 
517
             elif self.graphTypeChoice.GetSelection() == 2:
615 FredericG 518
                 xydata = _Numeric.linspace(0,FS/2,nb)
607 FredericG 519
                 xydata.shape = (nb/2, 2)
520
 
521
                 xydata[:,1] = vibTest.getSpectrum()
522
 
523
                 line = wx.lib.plot.PolyLine(xydata, legend= 'Spectrum', colour='red')
524
                 markers = wx.lib.plot.PolyMarker(xydata, legend= '', colour='red', marker='circle',size=2)
615 FredericG 525
 
526
                 fc = self.app.settings["hpf"].value
527
                 filterLine1 = wx.lib.plot.PolyLine(((fc,0),(fc,y)), legend='HP Filter', colour='Black', width=4)
528
                 fc = self.app.settings["lpf"].value
529
                 filterLine2 = wx.lib.plot.PolyLine(((fc,0),(fc,y)), legend='HP Filter', colour='Black', width=4)
607 FredericG 530
 
531
                 title = "Spectrum: %s %s %d" %(vibTest.descr, vibTest.channel, vibTest.speed)
626 FredericG 532
                 self.graphCtrl.Draw(wx.lib.plot.PlotGraphics([line,markers, filterLine1, filterLine2], title, "Freq (Hz)", "Acc"), xAxis=(0,200), yAxis= (-0,y))
533
                 self.graphCtrl.SetEnableGrid(True)
590 FredericG 534
 
599 FredericG 535
 
587 FredericG 536
    def OnImport(self, event): # wxGlade: MainFrame.<event_handler>
606 FredericG 537
        dlg = wx.FileDialog(
538
            self, message="Choose a file",
619 FredericG 539
            defaultDir="%s/Data/" % os.getcwd(),
606 FredericG 540
            defaultFile="*.txt",
619 FredericG 541
            wildcard="*.txt",
606 FredericG 542
            style=wx.OPEN | wx.CHANGE_DIR
543
            )
544
        if dlg.ShowModal() == wx.ID_OK:
545
            paths = dlg.GetPaths();
619 FredericG 546
            self.app.loadTests(paths[0])
606 FredericG 547
        dlg.Destroy()
587 FredericG 548
 
619 FredericG 549
    def onExport(self, event): # wxGlade: MainFrame.<event_handler>
550
        dlg = wx.FileDialog(
551
              self, message="Save file as ...",
552
              defaultDir="%s/Data/" % os.getcwd(),
553
              defaultFile="*.txt",
554
              wildcard="",
555
              style=wx.SAVE
556
              )
557
        if dlg.ShowModal() == wx.ID_OK:
558
            paths = dlg.GetPaths();
559
            self.app.saveTests(paths[0])
560
        dlg.Destroy()
561
 
599 FredericG 562
    def onYAxisChange(self, event): # wxGlade: MainFrame.<event_handler>
592 FredericG 563
        self.drawGraph()
564
 
600 FredericG 565
    def onGraphTypeChange(self, event): # wxGlade: MainFrame.<event_handler>
599 FredericG 566
        self.drawGraph()
567
 
607 FredericG 568
    def OnSettings(self, event): # wxGlade: MainFrame.<event_handler>
569
        dlg = SettingsDialog(self, -1, "Sample Dialog", size=(350, 200),
570
                         #style=wx.CAPTION | wx.SYSTEM_MENU | wx.THICK_FRAME,
571
                         style=wx.DEFAULT_DIALOG_STYLE, # & ~wx.CLOSE_BOX
572
                         )
573
        dlg.CenterOnScreen()
611 FredericG 574
        val = dlg.ShowModal()  # this does not return until the dialog is closed.
607 FredericG 575
        dlg.Destroy()
611 FredericG 576
        self.app.onSettingsChanged()
607 FredericG 577
 
612 FredericG 578
    def onStartMeasure(self, event): # wxGlade: MainFrame.<event_handler>
613 FredericG 579
        # Collect measure parameters
580
        mp = MeasureParameters()
581
        mp.descr = self.tcDescr.GetValue()
582
        mp.motors = map(int,self.tcMotors.GetValue().split(','))
583
        mp.channels = map(int,self.tcChannels.GetValue().split(','))
584
        s = self.tcSpeeds.GetValue()
619 FredericG 585
        if s=="test":
586
          mp.speeds = (100,100,100,100,100, 150,150,150,150,150, 200,200,200,200,200, 100,150,200, 100,150,200, 100,150,200, 100,150,200)
587
        elif s.count("-") == 1:
613 FredericG 588
            # assume from-to:step format
589
            s = s.split("-")
590
            if len(s) != 2: raise Exception("Invalid format")
591
            s[1] = s[1].split(":")
592
            if len(s[1]) != 2: raise Exception("Invalid format")
593
            mp.speeds = range(int(s[0]),int(s[1][0])+int(s[1][1]),int(s[1][1]))
594
        else:
614 FredericG 595
            mp.speeds = map(int,s.split(','))
596
 
613 FredericG 597
 
612 FredericG 598
        # create the dialog that will show the satus
599
        dlg = MeasureDialog(self)
600
        dlg.CenterOnScreen()
613 FredericG 601
 
602
        # Signal the application
603
        self.app.startMeasure(mp, dlg)
604
 
612 FredericG 605
        # Show the dialog
606
        val = dlg.ShowModal()  # this does not return until the dialog is closed.
607
        dlg.Destroy()
608
 
616 FredericG 609
    def _removeTest(self, idx):
610
        print "Deleting test %d" % idx
611
        self.app.removeTest(idx)
612
        self.TestListCtrl.DeleteItem(idx)
613
 
614
 
615
    def onClear(self, event): # wxGlade: MainFrame.<event_handler>
616
        print "Clear all tests"
617
        for i in range(len(self.app.VibTests)-1, -1, -1):
618
            self._removeTest(i)
619
        self.drawGraph()
620
 
621
 
622
    def onClearSelected(self, event): # wxGlade: MainFrame.<event_handler>
623
        while True:
624
            idx = self.TestListCtrl.GetFirstSelected()
625
            if idx == -1: break
626
            self._removeTest(idx)
627
 
619 FredericG 628
 
626 FredericG 629
    def onCopyData(self, event): # wxGlade: MainFrame.<event_handler>
630
        clipdata = wx.TextDataObject()
631
        txt = ""
632
        idx = self.TestListCtrl.GetFirstSelected()
633
        while idx != -1:
634
             txt += ("%d\n" % self.app.getTest(idx).getVibValue(self.app.settings["hpf"].value, self.app.settings["lpf"].value))
635
             idx = self.TestListCtrl.GetNextSelected(idx)
636
        clipdata.SetText(txt)
637
        wx.TheClipboard.Open()
638
        wx.TheClipboard.SetData(clipdata)
639
        wx.TheClipboard.Close()
640
 
641
    def onAbout(self, event): # wxGlade: MainFrame.<event_handler>
642
         # First we create and fill the info object
643
        print "about"
644
        info = wx.AboutDialogInfo()
645
        info.Name = "MK Vibration Test"
646
        info.Version = "0.2"
647
        info.Copyright = ""
648
        info.Developers=["Frederic Goddeeris"]
649
        info.Description = "Please consult the WIKI page for a complete description of the tool:"
650
        info.WebSite = ("http://www.mikrokopter.de/ucwiki/en/VibrationTest", "VibrationTest WIKI page")
651
        wx.AboutBox(info)
652
 
653
 
654
    def onExit(self, event): # wxGlade: MainFrame.<event_handler>
655
        self.Close(True)
656
 
657
 
584 FredericG 658
# end of class MainFrame
659
 
607 FredericG 660
class Setting:
661
    def __init__(self, descr, defaultValue):
662
        self.descr = descr
663
        self.value = defaultValue
611 FredericG 664
 
665
    def set(self, newValue):
666
        if isinstance(self.value, int):
667
            self.value = int(newValue)
668
        else:
669
            self.value = str(newValue)
584 FredericG 670
 
613 FredericG 671
class MeasureParameters:
672
      pass
612 FredericG 673
 
674
class MeasureThread:
613 FredericG 675
    def __init__(self, measureParameters, evtConsumer):
676
        self.mk = mkProto.MkComm()
677
        self.param = measureParameters
612 FredericG 678
        self.evtConsumer = evtConsumer
613 FredericG 679
        self.cancel = False
680
        self.running = False
612 FredericG 681
 
682
    def start(self):
683
        thread.start_new_thread(self._run, ())
684
 
613 FredericG 685
    def stop(self):
686
        self.cancel = True
687
 
688
    def _testCancel(self):
689
        if self.cancel:
690
            raise Exception("Operation cancelled")
691
 
623 FredericG 692
    def _sendEvent(self, msg=None, error=False, parVoltage=None, speed=None):
693
        evt = MeasStatusUpdateEvent(running=self.running, msg=msg, error=error, voltage=parVoltage, speed=speed)
613 FredericG 694
        wx.PostEvent(self.evtConsumer, evt)
695
 
696
    def _setMotorSpeed(self, speed, settlingTime):
697
        speeds = [0,0,0,0]
698
        for motor in self.param.motors:
699
            speeds[motor-1] = speed
700
        for i in range(int(settlingTime*10)):
701
          self._testCancel()
702
          self.mk.setMotorTest(speeds)
703
          time.sleep(.1)
704
 
705
 
612 FredericG 706
    def _run(self):
613 FredericG 707
        self.running = True
708
        self._sendEvent("Starting test \"%s\"" % self.param.descr)    
709
 
710
        try:
711
            self._sendEvent("Opening SerialPort \"%s\"" % self.param.serialPort)
712
            self.mk.open(comPort=self.param.serialPort)
612 FredericG 713
 
613 FredericG 714
            msg = self.mk.getVersionMsg()
715
            version = msg.getVersion()
716
            self._sendEvent("Version: %d.%d" % version)
717
 
718
            msg = self.mk.getDebugMsg()
719
            voltage = msg.getVoltage()
720
            if (voltage == 0):
721
              minVoltage = 0
623 FredericG 722
              maxVoltage = 1
613 FredericG 723
            else:
724
              if (voltage > 4.2*3):
623 FredericG 725
                nbCells = 4  
613 FredericG 726
              else:
623 FredericG 727
                nbCells = 3
728
              minVoltage = nbCells*3.5
729
              maxVoltage = nbCells*3.9  
613 FredericG 730
            self._sendEvent("Voltage: %2.1fV" % voltage)
623 FredericG 731
            self._sendEvent("Min/Max Voltage: %2.1fV-%2.1fV" % (minVoltage, maxVoltage), parVoltage=(minVoltage, maxVoltage, voltage))
732
 
613 FredericG 733
 
623 FredericG 734
            self._sendEvent("Starting motor(s) (speed=%d)... " % self.param.motorStartupSpeed, speed=self.param.motorStartupSpeed)
613 FredericG 735
            self._setMotorSpeed(self.param.motorStartupSpeed, self.param.motorStartupSettlingTime)
736
 
737
            for speed in self.param.speeds:
623 FredericG 738
                self._sendEvent("Changing motor speed to %d... " % speed, speed=speed)
613 FredericG 739
                self._setMotorSpeed(speed, 1)
740
 
741
                for channel in self.param.channels:
742
                    self._setMotorSpeed(speed, .1)
619 FredericG 743
                    msg = self.mk.getDebugMsg()
744
                    voltage = msg.getVoltage()
745
 
623 FredericG 746
                    self._sendEvent("Getting data from channel %s" % CHANNEL_NAMES[channel], parVoltage=(minVoltage, maxVoltage, voltage))
613 FredericG 747
                    data = self.mk.doVibrationTest(1000, channel)
748
 
619 FredericG 749
                    vt = VibTest(self.param.descr, voltage, self.param.motors, speed, CHANNEL_NAMES[channel], data)
613 FredericG 750
                    evt = MeasDataEvent(vibTest = vt)
751
                    wx.PostEvent(self.evtConsumer, evt)
752
 
619 FredericG 753
                    if voltage<minVoltage:
754
                        raise Exception("Voltage too low")
755
 
613 FredericG 756
            self._sendEvent("Done !")            
612 FredericG 757
 
613 FredericG 758
        except Exception, e:
759
            self._sendEvent("Exception \"%s\"" % e, error=True)  
760
 
761
        self.running = False
762
        self._sendEvent("")    
763
 
612 FredericG 764
 
586 FredericG 765
class VibTest:
619 FredericG 766
    def __init__(self, descr, voltage, motor, speed, channel, rawData):
594 FredericG 767
        self.descr = descr
619 FredericG 768
        self.voltage = voltage
594 FredericG 769
        self.motor = motor
770
        self.speed = speed
596 FredericG 771
        self.channel = channel
599 FredericG 772
 
773
        self.dataLen = len(rawData)
774
 
590 FredericG 775
        self.rawData = _Numeric.array(rawData)
776
        self.dc = self.rawData.mean()
777
        self.rawData -= self.dc
586 FredericG 778
 
600 FredericG 779
        self.fft = _Numeric.fft.rfft(self.rawData)
780
 
781
        self.spectrum = None
782
        self.filteredData = None
615 FredericG 783
        self.fc1 = None
784
        self.fc2 = None
599 FredericG 785
 
602 FredericG 786
        self.vibValue = None
787
 
594 FredericG 788
    def getDescr(self):
789
        return self.Descr
587 FredericG 790
 
590 FredericG 791
    def getRawData(self):
792
        return self.rawData
793
 
794
    def getDataLen(self):
795
        return self.dataLen
796
 
599 FredericG 797
    def getSpectrum(self):
600 FredericG 798
        if self.spectrum == None:
799
            self.spectrum = _Numeric.absolute(self.fft[1:self.dataLen/2+1]) / (self.dataLen/2)
800
        return self.spectrum
590 FredericG 801
 
615 FredericG 802
    def getFilteredData(self, fc1, fc2):
803
        if self.fc1 != fc1 or self.fc2 != fc2:
804
            self.filteredData = None  
805
 
600 FredericG 806
        if self.filteredData == None:
807
            tmpfft = self.fft.copy()
615 FredericG 808
            fc = (float(fc1))/(FS/2)*len(tmpfft)
809
            print "fc1=%d => fc=%d" % (fc1,fc)
810
            for i in range(0,int(fc)):
600 FredericG 811
                tmpfft[i] = 0
615 FredericG 812
            fc = (float(fc2))/(FS/2)*len(tmpfft)
813
            print "fc2=%d => fc=%d" % (fc2,fc)
814
            for i in range(int(fc), len(tmpfft)):
600 FredericG 815
                tmpfft[i] = 0
816
            self.filteredData = _Numeric.fft.irfft(tmpfft)
615 FredericG 817
            self.fc1 = fc1
818
            self.fc2 = fc2
819
 
600 FredericG 820
        return self.filteredData
602 FredericG 821
 
615 FredericG 822
    def getVibValue(self, fc1, fc2):
823
      if self.fc1 != fc1 or self.fc2 != fc2:
824
        self.vibValue = None  
602 FredericG 825
      if self.vibValue == None:
615 FredericG 826
        fd = self.getFilteredData(fc1, fc2)[100:-100];
602 FredericG 827
        self.vibValue = max(fd)-min(fd)
828
      return self.vibValue
599 FredericG 829
 
607 FredericG 830
 
831
 
584 FredericG 832
class App(wx.App):
607 FredericG 833
 
834
    SETTINGSFILE = "settings.cfg"
835
 
586 FredericG 836
    def __init__(self, par):
837
        self.VibTests = []
838
        wx.App.__init__(self, par)
839
 
607 FredericG 840
        # Init settings
841
        self.settings={}
611 FredericG 842
        self.settings["serialport"] = Setting("Serial Port", "COM1")
613 FredericG 843
        self.settings["startupspeed"] = Setting("Motor Startup Speed", 25)
844
        self.settings["startupsettling"] = Setting("Motor Startup Setting time (s)", 3)
845
        self.settings["serialport"] = Setting("Serial Port", "COM1")
607 FredericG 846
        self.settings["hpf"] = Setting("HP Filter cutoff (Hz)", 50)
615 FredericG 847
        self.settings["lpf"] = Setting("LP Filter cutoff (Hz)", 180)
607 FredericG 848
 
849
        self.readSettings()
850
 
606 FredericG 851
        if len(sys.argv)>1:
619 FredericG 852
            self.loadTests(sys.argv[1])
586 FredericG 853
 
606 FredericG 854
 
607 FredericG 855
    def readSettings(self):
856
        print "Reading settings"
857
        cp = ConfigParser.ConfigParser()
858
 
859
        try:
860
            cp.read(App.SETTINGSFILE)
861
            for setting in cp.items("DEFAULT"):
862
                print " ",setting
863
                try:
613 FredericG 864
                    self.settings[setting[0]].set(setting[1])
607 FredericG 865
                except:
866
                    print "WARNING, unknown setting"
867
        except:
868
            print "ERROR reading settingsfile"
869
 
870
 
871
    def storeSettings(self):
872
        print "Storing settings"
873
 
874
        cp = ConfigParser.ConfigParser()
875
        for setting in self.settings.iteritems():
876
            cp.set("", setting[0], setting[1].value)
877
 
878
        file = open(App.SETTINGSFILE, "w")
879
        cp.write(file)
880
        file.close()
881
 
611 FredericG 882
 
883
    def onSettingsChanged(self):
884
        self.storeSettings()
613 FredericG 885
 
886
    def AddTest2(self, vibTest):
887
        self.VibTests.append(vibTest)
888
        self.frame_1.onNewTest(vibTest)
611 FredericG 889
 
619 FredericG 890
    def AddTest(self, descr, voltage, motor, speed, channel, rawData):
891
        test = VibTest(descr, voltage, motor, speed, channel, rawData)
613 FredericG 892
        self.AddTest2(test)
586 FredericG 893
 
616 FredericG 894
    def removeTest(self, idx):
895
        del(self.VibTests[idx])
896
 
590 FredericG 897
    def getTest(self, testId):
898
        return self.VibTests[testId]
899
 
584 FredericG 900
    def OnInit(self):
901
        wx.InitAllImageHandlers()
586 FredericG 902
        self.frame_1 = MainFrame(None, -1, "")
587 FredericG 903
        self.frame_1.setApp(self);
586 FredericG 904
        self.SetTopWindow(self.frame_1)
905
 
607 FredericG 906
        self.frame_1.CenterOnScreen()
587 FredericG 907
        self.frame_1.Show()
908
        return 1
909
 
619 FredericG 910
    def saveTests(self, filePath):
911
        try:
912
          logfile = open(filePath, "r")
913
          newFile = False
914
          logfile.close()
915
        except:
916
          newFile = True
917
 
918
        for test in self.VibTests:
919
          if newFile:
920
            logfile = open(filePath, "w")
921
            print "Writing result to %s ..." % filePath,
922
            logfile.write("%s %d %s\n" % (test.descr, test.speed, test.channel))
923
            for value in test.rawData:
924
              logfile.write("%d\n" % value)
925
            logfile.close()  
926
            print "OK"
927
          else:
928
            print "Appending result to %s ..." % filePath,
929
            logfile = open(filePath, "r")
930
            prevData = []
931
            for line in logfile:
932
              prevData.append(line[:-1])
933
            logfile.close()
934
            logfile = open(filePath, "w")
935
            logfile.write("%s,%s %d %s\n" % (prevData[0], test.descr, test.speed, test.channel))
936
            i = 1
937
            for value in test.rawData:
938
              logfile.write("%s,%d\n" % (prevData[i], value))
939
              i += 1
940
            logfile.close()
941
            print "OK"
942
          newFile = False
943
 
944
 
945
    def loadTests(self, filePath):
596 FredericG 946
 
606 FredericG 947
        print "Importing file \"%s\"" % filePath
596 FredericG 948
 
949
        logfile = open(filePath, "r")
590 FredericG 950
        data = None
596 FredericG 951
 
619 FredericG 952
        headers = (logfile.readline()[:-1]).split(',')
596 FredericG 953
        nbCols = len(headers)
954
        print "NbCols =", nbCols
955
 
956
        data = []
957
        descr = []
958
        speed = []
959
        channel = []
960
        for c in range(nbCols):
961
            data.append([])
962
            h = headers[c].split(' ')
963
            descr.append(h[0]);
964
            speed.append(h[1]);
965
            channel.append(h[2]);
966
 
590 FredericG 967
        for line in logfile:
968
            values = line.split(',')
596 FredericG 969
            for i in range(nbCols):
970
                data[i].append(int(values[i]))
590 FredericG 971
        logfile.close()
596 FredericG 972
 
973
        for c in range(nbCols):
599 FredericG 974
            if (len(data[c]) % 2) != 0:
975
                data[c].append(data[c][-1])
619 FredericG 976
            self.AddTest(descr[c], 0, 0, int(speed[c]), channel[c], data[c])
612 FredericG 977
 
613 FredericG 978
    def startMeasure(self, measureParams, dialog):
612 FredericG 979
        print "Start measuring"
590 FredericG 980
 
613 FredericG 981
        measureParams.serialPort = self.settings["serialport"].value
982
        measureParams.motorStartupSpeed = self.settings["startupspeed"].value
983
        measureParams.motorStartupSettlingTime = self.settings["startupsettling"].value
984
 
985
        self.measureThread = MeasureThread(measureParams, dialog)
612 FredericG 986
        self.measureThread.start()
590 FredericG 987
 
613 FredericG 988
    def cancelMeasurement(self):
989
        print "Measuring CANCEL"
990
 
991
        self.measureThread.stop()
992
 
612 FredericG 993
 
994
 
995
 
996
 
590 FredericG 997
 
586 FredericG 998
 
590 FredericG 999
 
584 FredericG 1000
# end of class App
1001
 
1002
if __name__ == "__main__":
626 FredericG 1003
 
1004
    rootPath = os.path.abspath(os.path.dirname(sys.argv[0]))
1005
 
1006
    print rootPath
1007
 
584 FredericG 1008
    VibrationTestGui = App(0)
1009
    VibrationTestGui.MainLoop()