def onRecordStartBtn(self): if not Recorder.get().HasBeenSaved( ) and Recorder.get().GetRecordedCount() > 0: response = GuiMgr.MessageBox_OkCancel( "Restart Recording?", "You have not saved the current recorded data. OK to Discard?" ) if False == response: return GuiMgr.OnStartRecording()
def PerformGoLiveTask(self, Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>Go Live</Task> #</Marvin> Log.getLogger().info("Performing Oscar task: Start Live Data.") GuiMgr.OnStopPlayback() GuiMgr.OnStopRecording() GuiMgr.OnStartLiveData()
def onLiveStartBtn(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.OnStartLiveData() GuiMgr.SetPlaybackFilename("")
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 HandleSave(self): options = {} options['filetypes'] = [('Oscar Data files', '.biff')] options['initialfile'] = 'OscarSaveFile.biff' options['defaultextension'] = '.biff' options['parent'] = self.root filename = tkinter.filedialog.asksaveasfilename(**options) if len(filename) < 1: return GuiMgr.WriteToFile(filename) GuiMgr.SetPlaybackFilename(filename)
def HandleOpen(self): options = {} options['filetypes'] = [('Oscar Data files', '.biff')] options['parent'] = self.root filename = tkinter.filedialog.askopenfilename(**options) if len(filename) < 1 : return if not GuiMgr.ReadFromFile(filename): GuiMgr.MessageBox_Error("Python Error","Error loading file: " + filename) self._PreviousFileMenuStatus = None GuiMgr.SetPlaybackFilename(filename)
def HandleIncomingGroupPacket(self, rawData, node, fromAddress): from Helpers import Configuration if Configuration.get().GetBITW_Active(): rawData = Configuration.get().HandleBITWBuffer( rawData) # handle Bump in the wire if 0 != TargetManager.GetTargetManager().BroadcastDownstream( rawData, False, node, True): # send to all - towards a Marvin Statistics.GetStatistics().OnPacketChainedDownstream(rawData) # Break up packet and do bump in the wire. # If BITW not active, maybe we don't need to do this could be a lot of processing for nothing.... objGroupPacket = MarvinGroupData.MarvinDataGroup( "", "", "", 0, "1.0", True) for packet in node.getElementsByTagName('Oscar'): objMarvinPacket = self.CreateMarvinData(packet, rawData, fromAddress) if None == objMarvinPacket: return objGroupPacket.AddPacket(objMarvinPacket) # objData = MarvinData.MarvinData(namespace,ID,value,0,version,True) GuiMgr.OnDataPacketSentDownstream(objGroupPacket, "Chained") Recorder.get().AddData(objGroupPacket)
def updateGui(self): gm = GuiMgr.get() if gm.Live_Receiving or gm.Playback_Playing: val = DISABLED else: val = NORMAL if self._PreviousFileMenuStatus != val: #will kill performance if you do this every loop! self.FileMenu.entryconfigure(self.SaveAsCSV, state=val) self.FileMenu.entryconfigure(self.SaveStr, state=val) self.FileMenu.entryconfigure(self.OpenStr, state=val) self.FileMenu.entryconfigure(self.ExportToDB, state=val) self._PreviousFileMenuStatus = val self.__KludgeCounter = 0 if val == NORMAL: if Playback.get().GetDataCount() < 1: self.FileMenu.entryconfigure(self.SaveStr, state=DISABLED) self.FileMenu.entryconfigure(self.SaveAsCSV, state=DISABLED) self.FileMenu.entryconfigure(self.ExportToDB, state=DISABLED) else: self.__KludgeCounter += 1 # easy to get out of sync if stopped live, but no data, etc. Quick hack if self.__KludgeCounter > 100: self._PreviousFileMenuStatus = None self.__KludgeCounter = 0
def updateGui(self): try: dlist = GuiMgr.get().GetDatalist() for key in dlist.keys(): try: objData = dlist[key][0] strFrom = dlist[key][1] self.dataViewTree.set(key, 'Value', objData.Value) self.dataViewTree.set(key, 'Source', strFrom) except Exception as Ex: try: index = self.__findIndex(key) self.dataViewTree.insert('', index, key, values=(objData.Namespace, objData.ID, str(objData.Value), strFrom)) except Exception as Ex: Log.getLogger().error(str(Ex)) except Exception as Ex: # Likely had the list updated while I was iterating (didn't make this thread safe), just ignore and wait for next loop pass
def PerformStartRecordingTask(self, Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>StartRecording</Task> #</Marvin> GuiMgr.OnStartRecording()
def sliderHandler(self, event): if GuiMgr.get().Playback_Playing: return percent = float(self.slider.get()) / 100.0 number = int(Playback.get().GetDataCount() * percent) Playback.get().SetCurrentNumber(number) strVal = str(number) + "/" + str(Playback.get().GetDataCount()) self.lblPacketNumber.config(text=strVal)
def sliderUpdate(self, event): number = Playback.get().GetCurrentNumber() strVal = str(number) + "/" + str(Playback.get().GetDataCount()) if GuiMgr.get().GetRepeatMode()[0] != Playback.RepeatMode.NONE: strVal = strVal + " Loop: " + str(Playback.get().GetLoopCount()) self.lblPacketNumber.config(text=strVal)
def onStartLoopBtn(self): currNum = Playback.get().GetCurrentNumber() currEnd = Playback.get().GetLoopMode()[2] maxNum = Playback.get().GetDataCount() if currNum >= currEnd: GuiMgr.MessageBox_Error("Error","You cannot set the beginning of a loop to be beyond the end") return Playback.get().SetLoopMode(Playback.RepeatMode.LOOP,currNum,currEnd)
def UpdateGui(self): for widget in self.updateList: widget.updateGui() currCount = len(GuiMgr.get().GetDatalist()) if currCount != self._LastDataPointCount: self.dataText.set("Data {" + str(currCount) + "}") self._LastDataPointCount = currCount self.root.after(100, self.UpdateGui)
def onStopLoopBtn(self): currNum = Playback.get().GetCurrentNumber() currStart = Playback.get().GetLoopMode()[1] maxNum = Playback.get().GetDataCount() if currStart >= currNum : GuiMgr.MessageBox_Error("Error","You cannot set the end of a loop to be before the start") return Playback.get().SetLoopMode(Playback.RepeatMode.LOOP,currStart,currNum)
def PerformPausePlaybackTask(self, Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>PausePlayback</Task> #</Marvin> Log.getLogger().info("Performing Oscar task: Pause Playback.") GuiMgr.OnPausePlayback()
def PerformInsertBookmark(self,Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <UniqueID>1233456</UniqueID> # <Task>InsertBookmark</Task> # <Param>Namespace=foo</Param> # <Param>ID=TestMarker</Param> # <Param>Data=StartTest</Param> # <Param>Propagate=True</Param> -- if True, the data is sent back upstream towards Marvin #</Marvin> if len(Params) >= 3: fPropagate = False for param in Params: parts = param.split("=") if len(parts)==2: if parts[0].lower()=='namespace': namespace = Alias.Alias(parts[1]) elif parts[0].lower()=='id': id = Alias.Alias(parts[1]) elif parts[0].lower()=='data': data = Alias.Alias(parts[1]) elif parts[0].lower()=='propagate': propagate = Alias.Alias(parts[1]) if propagate.lower() == "true": fPropagate = True else: Log.getLogger().error("Received invalid InsertBookmark task parameter: " + str(param)) return else: Log.getLogger().error("Received invalid InsertBookmark task. Insufficient Parameters.") return if None == namespace: Log.getLogger().error("Received invalid InsertBookmark task. Namespace not specified.") return if None == id: Log.getLogger().error("Received invalid InsertBookmark task. ID not specified.") return if None == data: Log.getLogger().error("Received invalid InsertBookmark task. Data not specified.") return eTime = Time.GetCurrMS() objData = MarvinData.MarvinData(namespace,id,data,eTime,1.0) if None != objData: Recorder.get().AddData(objData) GuiMgr.OnDataPacketSentDownstream(objData,"Minion") if fPropagate: TargetManager.GetTargetManager().BroadcastDownstream(objData.ToXML(),False,None)
def PerformLoadFileTask(self, Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>LoadFile</Task> # <Param>filename</Param> #</Marvin> if len(Params) != 1: Log.getLogger().error( "Oscar Task to load file failed - no file specified.") filename = Alias.Alias(Params[0]) Log.getLogger().info("Performing Oscar task: Load File -->" + str(filename)) GuiMgr.OnStopPlayback() GuiMgr.OnStopRecording(True) #drop all recorded packets GuiMgr.OnStopLiveData() if GuiMgr.ReadFromFile(filename): GuiMgr.OnEnablePlayback() GuiMgr.SetPlaybackFilename(filename) else: Log.getLogger().warning("Oscar Task to load file [" + filename + "] failed") return False return True
def updatePlaybackSpeed(self): if GuiMgr.get().GetPlaybackSpeed() == float(self.lstBoxPlaybackSpeed.get()): return currSpeed = GuiMgr.get().GetPlaybackSpeed() insertIndex = 0 index = 0 for strVal in self.lstBoxPlaybackSpeed['values']: fVal = float(strVal) if fVal < currSpeed: insertIndex = index if fVal == currSpeed: self.lstBoxPlaybackSpeed.set(strVal) return index +=1 #so it wasn't there, must have been set via cmdline OR via Oscar Task itemList = list(self.lstBoxPlaybackSpeed['values']) itemList.insert(insertIndex, str(currSpeed)) self.lstBoxPlaybackSpeed['values'] = tuple(itemList)
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 main(): if not HandleCommandlineArguments(): return if not Configuration.get().ReadConfigFile(): return PrintVersion() downstreamConnInfo = Configuration.get().GetDownstreamConnection() upstreamConnInfo = Configuration.get().GetUpstreamConnection() downstreamServer = ServerUDP.ServerUDP(downstreamConnInfo,ConnectionType.DownstreamServer) upstreamServer = ServerUDP.ServerUDP(upstreamConnInfo,ConnectionType.UpstreamServer) # if None == Configuration.get().GetAutorunFilename() or 1==1: if upstreamServer.Start(): if None == downstreamConnInfo: return if None == upstreamConnInfo: return ThreadManager.GetThreadManager().CreateThread("StartupStuff",StartupWorkerProc,(downstreamServer,upstreamServer)) if not Configuration.get().GetUseGUI(): GuiMgr.Initialize(GuiMgr.UI.NONE,downstreamServer,upstreamServer) else: try: GuiMgr.Initialize(GuiMgr.UI.TKINTR,downstreamServer,upstreamServer) except Exception as Ex: print(str(Ex)) GuiMgr.Initialize(GuiMgr.UI.NONE,downstreamServer,upstreamServer) ThreadManager.GetThreadManager().StartThread("StartupStuff") GuiMgr.Start() ThreadManager.GetThreadManager().StopAllThreads()
def PerformStopRecordingTask(self,Params): #<?xml version="1.0" encoding="utf-8"?> #<Marvin Type="OscarTask"> # <Version>1.0</Version> # <OscarID>DemoOscar</OscarID> # <Task>StopRecording</Task> # <Param>File=SaveFile.glk</Param> #</Marvin> fileName = None param="" if len(Params) > 0: param = Params[0] parts = param.split("=") if len(parts)==2: if parts[0].lower()=='file': fileName = Alias.Alias(parts[1]) if None == fileName: Log.getLogger().error("Received invalid Stop Recording task. No save file: " + str(param)) return GuiMgr.OnStopRecording() GuiMgr.WriteToFile(fileName)
def HandleIncomingOscarDatapacket(self, node, rawData, fromAddress): from Helpers import Configuration # Use this object to update the gui and for recording # is also where BITW check update of checked map occurs objData = self.CreateMarvinData(node, rawData, fromAddress) if Configuration.get().GetBITW_Active(): rawData = Configuration.get().HandleBITWBuffer( rawData) # handle Bump in the wire if 0 != TargetManager.GetTargetManager().BroadcastDownstream( rawData, False, node): # send to all - towards a Marvin Statistics.GetStatistics().OnPacketChainedDownstream(rawData) if None != objData: GuiMgr.OnDataPacketSentDownstream(objData, "Chained") Recorder.get().AddData(objData)
def HandleIncomingMinionData(self, rawData, node, fromAddress): # <?xml version="1.0" encoding="utf-8"?> # <Minion> # <Version>1</Version> # <PacketNumber>44</PacketNumber> # <Namespace>Namespace_Foo</Namespace> # <Name>CPU_UTIL_CORE0</Name> # <Value>33.2</Value> # <Normalized>False</Normalized> # <ElapsedTime>253</ElapsedTime> # </Minion> objData = self.CreateMarvinPacket(rawData, node, fromAddress) if None != objData: TargetManager.GetTargetManager().BroadcastDownstream( objData.ToXML(), False, node) GuiMgr.OnDataPacketSentDownstream(objData, "Minion") Recorder.get().AddData(objData)
def ReadFromFile(self, filename): from Helpers import GuiMgr import os.path if not os.path.isfile(filename): Log.getLogger().error("Asked to read from non-existant file: " + filename) return False with open(filename, 'r+b') as fp: try: entries = pickle.load(fp) except Exception as ex: Log.getLogger().error(filename + ": " + str(ex)) GuiMgr.MessageBox_Error( "Error Loading File", "The format of this file requires Python 3.4 or greater.") return False if len(entries) < 1: Log.getLogger().error( filename + " does not appear to have any data in it. ") return False objEntry = entries[0] if hasattr(objEntry, 'FormatVersion'): entries = Configuration.get().HandleBITW_FromLoad(entries) self.SetData(entries) return True elif hasattr(objEntry, 'PacketNumber'): newList = self.ConvertFromAlphaFormat(entries) else: newList = self.ConvertFromBetaFormat(entries) if None != newList: self.SetData(newList) return True return False
def HandleIncomingGroupPacket(self, rawData, node, fromAddress): # <?xml version="1.0" encoding="utf-8"?> # <MinionGroup> # <Minion> # <Version>1</Version> # <PacketNumber>44</PacketNumber> # <Namespace>Namespace_Foo</Namespace> # <Name>CPU_UTIL_CORE0</Name> # <Value>33.2</Value> # <Normalized>False</Normalized> # <ElapsedTime>253</ElapsedTime> # </Minion> # <Minion> # <Version>1</Version> # <PacketNumber>45</PacketNumber> # <Namespace>Namespace_Foo</Namespace> # <Name>CPU_UTIL_CORE1</Name> # <Value>3.2</Value> # <Normalized>False</Normalized> # <ElapsedTime>273</ElapsedTime> # </Minion> # </MinionGroup> objGroupPacket = MarvinGroupData.MarvinDataGroup( "", "", "", 0, "1.0", True) for packet in node.getElementsByTagName('Minion'): objMarvinPacket = self.CreateMarvinPacket(rawData, packet, fromAddress) if None == objMarvinPacket: return objGroupPacket.AddPacket(objMarvinPacket) GuiMgr.OnDataPacketSentDownstream(objGroupPacket, "Minion") TargetManager.GetTargetManager().BroadcastDownstream( objGroupPacket.ToXML(), False, None, True) Recorder.get().AddData(objGroupPacket)
def onPauseBtn(self): GuiMgr.OnPausePlayback()
def updateGui(self): playbackMgr = Playback.get() guiMgr = GuiMgr.get() if False == guiMgr.Playback_Active and False == self.Visible: return self.updatePlaybackSpeed() self.updateLoopValue() self.updatePlaybackTime() if guiMgr.Playback_Active and False == self.Visible: self.root.grid() self.Visible = True self.slider.set(0) self.lstBoxRepeatMode.current(0) self.lstBoxPlaybackSpeed.current(4) if guiMgr.Live_Receiving and self.Visible: self.Visible = False guiMgr.ShowPlayback(False) self.root.grid_remove() if guiMgr.GetRepeatMode( )[0] == Playback.RepeatMode.LOOP and False == self.LoopValuesVisible: self.LoopValuesVisible = True self.lblEndLoop.grid() self.lblStartLoop.grid() if guiMgr.GetRepeatMode( )[0] != Playback.RepeatMode.LOOP and True == self.LoopValuesVisible: self.LoopValuesVisible = False self.lblEndLoop.grid_remove() self.lblStartLoop.grid_remove() if guiMgr.Playback_Playing and not (enabled(self.btnPausePlayback) or enabled(self.btnStopPlayback)): enable(self.btnPausePlayback) enable(self.btnStopPlayback) disable(self.btnStartPlayback) if not guiMgr.Playback_Playing and (enabled(self.btnPausePlayback) or enabled(self.btnStopPlayback)): disable(self.btnPausePlayback) disable(self.btnStopPlayback) enable(self.btnStartPlayback) if guiMgr.Playback_Playing and enabled(self.slider): disable(self.slider) if not guiMgr.Playback_Playing and not enabled(self.slider): enable(self.slider) currNum = playbackMgr.GetCurrentNumber() total = playbackMgr.GetDataCount() if guiMgr.Playback_Playing: enable(self.slider) self.slider.set(int(currNum * 100 / total)) disable(self.slider) elif currNum == total and self.slider.get() != 100: self.slider.set(100) if guiMgr.GetRepeatMode()[0] != Playback.RepeatMode.LOOP and enabled( self.btnStartLoop): disable(self.btnStartLoop) self.btnStartLoop.grid_remove() self.btnStopLoop.grid_remove() if guiMgr.Playback_Playing and enabled(self.btnStartLoop): disable(self.btnStartLoop) self.btnStartLoop.grid_remove() self.btnStopLoop.grid_remove() if not guiMgr.Playback_Playing and guiMgr.GetRepeatMode( )[0] == Playback.RepeatMode.LOOP and not enabled(self.btnStartLoop): enable(self.btnStartLoop) self.btnStartLoop.grid() self.btnStopLoop.grid() if True == self.LoopValuesVisible: mode = guiMgr.GetRepeatMode() self.lblStartLoop.config(text=str(mode[1])) self.lblEndLoop.config(text=str(mode[2]))
def updateLoopValue(self): mode = GuiMgr.get().GetRepeatMode()[0] if Playback.RepeatMode.toString(mode) == self.lstBoxRepeatMode.get(): return self.lstBoxRepeatMode.set(Playback.RepeatMode.toString(mode))
def onSetPlaybackSpeed(self, event): GuiMgr.get().OnSetPlaybackSpeed(float(self.lstBoxPlaybackSpeed.get()))