def HandleExit(self): if not Recorder.get().HasBeenSaved( ) and Recorder.get().GetRecordedCount() > 0: response = GuiMgr.MessageBox_OkCancel( "Warning", "You have not saved the current recorded data. OK to Discard?" ) if False == response: return GuiMgr.Quit()
def StartupWorkerProc(fnKillSignalled, userData): downstreamServer = userData[0] upstreamServer = userData[1] Sleep.SleepMs(500) downstreamServer.Start() upstreamServer.DropPackets(True) upstreamServer.Start() Watchdog.ConnectionUpdateTimer() Watchdog.WatchdogTimer() conf = Configuration.get() if None != conf.GetAutorunFilename(): GuiMgr.OnStopLiveData() #GuiMgr.OnStopPlayback() #GuiMgr.OnStopRecording(True) #drop all recorded packets GuiMgr.OnSetPlaybackSpeed(Configuration.get().GetPlaybackSpeed()) ss = Configuration.get().GetAutorunLocations() #GuiMgr.OnEnablePlayback() GuiMgr.ReadFromFile(Configuration.get().GetAutorunFilename()) GuiMgr.OnStopPlayback() Sleep.SleepMs( 100) # let gui worker threads catch up, so gui updates properly GuiMgr.OnStartPlayback() GuiMgr.OnSetRepeatMode(Configuration.get().GetAutoRunMode(), ss[0], ss[1]) else: upstreamServer.DropPackets(False) if None != conf.GetAutorunTime() and conf.GetAutorunTime( ) > 0: # specified a --time, so let's hang out for that long endTime = Time.GetCurrMS() + conf.GetAutorunTime() * 60 * 1000 Log.getLogger().info("Waiting for " + str(conf.GetAutorunTime()) + " minutes before auto shutdown") if conf.GetRecordFilename(): GuiMgr.OnStartRecording() while not fnKillSignalled() and endTime > Time.GetCurrMS(): Sleep.SleepMs(250) Log.getLogger().info("Shutting down after time period") if conf.GetRecordFilename( ): # was a recording session, so quit after that time GuiMgr.OnStopRecording() GuiMgr.WriteToFile(conf.GetRecordFilename()) Log.getLogger().info("Saving Recorded data to file: " + conf.GetRecordFilename()) GuiMgr.Quit()
def performBatchConvert(filematch): import os import fnmatch GuiMgr.Initialize(GuiMgr.UI.NONE,None,None) #dir_path = os.path.dirname(os.path.realpath(filematch)) convertCount = 0 rel_path,filename = os.path.split(filematch) if len(rel_path) < 1: rel_path='.' for file in os.listdir(rel_path): if fnmatch.fnmatch(file, filename): inputFilename = os.path.join(rel_path,file) if Playback.get().ReadFromFile(inputFilename): baseName,ext = os.path.splitext(inputFilename) csvFilename = baseName+".csv" Playback.get().WriteCSVFile(csvFilename,1) print("{0} --> {1}".format(inputFilename,csvFilename)) convertCount += 1 Playback.get().Clear() print("Converted {0} files".format(convertCount)) GuiMgr.Quit()
def __workerProc(self, fnKillSignalled, userData): from Helpers import GuiMgr self.CurrentIndex = self.startIndex self.StartTime = None xmlList = [] while not fnKillSignalled( ): # run until signalled to end - call passed function to check for the signal if self.Paused or self.Stopped: Sleep.SleepMs(100) continue if None == self.StartTime: self.StartTime = int( self.PlaybackData[self.CurrentIndex].ArrivalTime ) - 10 # can't remember why I subract 10ms... objData = self.PlaybackData[self.CurrentIndex] sleepVal = (int(objData.ArrivalTime) - self.StartTime) / self.PlaybackSpeed Sleep.SleepMs(sleepVal) try: # when looping, this data will be here after the 1st loop xmlData = self.PlaybackData[self.CurrentIndex].xmlData node = self.PlaybackData[self.CurrentIndex].firstNode except: xmlData = objData.ToXML( ) # be more efficient if I create a list of already created xmldata self.PlaybackData[ self. CurrentIndex].xmlData = xmlData # LOVe how you can just add stuff to an object in Python! if Configuration.get().GetShunting(): try: dom = xml.dom.minidom.parseString(rawData) node = dom._get_firstChild() except Exception as ex: Log.getLogger().error( "Error Something bad in Trying to re-encode saved data" ) else: node = None self.PlaybackData[self.CurrentIndex].firstNode = node TargetManager.GetTargetManager().BroadcastDownstream( xmlData, False, node) GuiMgr.OnDataPacketSentDownstream(objData, "Playback") try: self.StartTime = int( self.PlaybackData[self.CurrentIndex].ArrivalTime) except Exception: self.StartTime = None # just in case get an out of bounds error self.CurrentIndex += 1 if None == self.endIndex: self.endIndex = len(self.PlaybackData) - 1 if self.CurrentIndex >= self.endIndex: preProcessingDone = True if self.LoopMode == RepeatMode.NONE: GuiMgr.OnStopPlayback() if Configuration.get().GetExitAfterAutoPlay(): Log.getLogger().info( "Playback finished, exiting application per arguments" ) GuiMgr.Quit() elif self.LoopMode == RepeatMode.REPEAT: self.CurrentIndex = 0 self.LoopCount += 1 elif self.LoopMode == RepeatMode.LOOP: self.CurrentIndex = self.startIndex self.LoopCount += 1 self.StartTime = None