Esempio n. 1
0
    def Collect(self):
        list = self.GetCollectors()
        if len(list) < 1:
            return None
        try:
            for objCollector in list:
                if not hasattr(objCollector, "MaxCollectedValue"):
                    objCollector.MaxCollectedValue = objCollector.GetLastValue()

            if not Utility.IsNumeric(list[0].MaxCollectedValue):
                if not self._InvalidInpWarningSent:
                    Log.getLogger().warn("An Input to Operator MaxValue is non numeric.--> " + objCollector.MaxCollectedValue)
                    self._InvalidInpWarningSent = True
                return "HelenKeller"

            max = float(list[0].MaxCollectedValue)
            for objCollector in list:
                if not Utility.IsNumeric(objCollector.MaxCollectedValue):
                    return None

                val = float(objCollector.MaxCollectedValue)
                if not objCollector.ReadyForConsumption() and not objCollector.IsDefaultValue():
                    
                    return None # hasn't yet collecte

                if val > max:
                    max = val

        except Exception as Ex:
            if not self._InvalidInpWarningSent:
                Log.getLogger().warn("An Input to Operator MaxValue is non numeric.--> " + objCollector.MaxCollectedValue)
                self._InvalidInpWarningSent = True
            max = ""

        return str(max)
    def SetCurrentNumber(self,newNumber):
        if Utility.IsNumeric(newNumber) and newNumber> -1 and newNumber < self.GetDataCount():
            self.CurrentIndex = newNumber
            self.IndexExternallySet = True

        else:
            Log.getLogger().warn("Tried to set playback index to invalid value: " + str(newNumber))
    def SetPlaybackSpeed(self,newVal):
        if False == Utility.IsNumeric(newVal):
            Log.getLogger().warn("Tried to set playback speed to invalid value: " + str(newVal))
            return

        if newVal > 0 and newVal < 101:
            self.PlaybackSpeed = newVal
        else:
            Log.getLogger().warn("Tried to set playback speed to invalid value: " + str(newVal))
    def OnSetPlaybackSpeed(self,speed):
        if not Utility.IsNumeric(speed):
            Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed))
            return

        if speed<=0 :
            Log.getLogger().error("Tried to set playback speed to invalid value: " + str(speed))
            return

        Playback.get().SetPlaybackSpeed(speed)
    def HandleAnyExtraStuff(self):
        try:
            if hasattr(self, "MaxCollectedValue"):
                if Utility.IsNumeric(self._LastValue):
                    if Utility.IsNumeric(self.MaxCollectedValue):
                        if float(self._LastValue) > float(self.MaxCollectedValue):
                            self.MaxCollectedValue = self._LastValue
                    else:
                        self.MaxCollectedValue = self._LastValue # last val wasn't numeric

            if hasattr(self, "MinCollectedValue"):
                if Utility.IsNumeric(self._LastValue):
                    if Utility.IsNumeric(self.MinCollectedValue):
                        if float(self._LastValue) < float(self.MaxCollectedValue):
                            self.MinCollectedValue = self._LastValue
                    else:
                        self.MinCollectedValue = self._LastValue # last val wasn't numeric

        except Exception as Ex:
            pass
Esempio n. 6
0
def create_frame(ip, order, timestamp, body=[]):
    CMD_TYPE_10 = order
    frame = [
        HEAD_FIRST_0, HEAD_SECOND_1, PROTOCOL_VERSION_2, LEN_HIGH_3, LEN_LOW_4,
        PROJECT_CODE_5, SUPPLIER_CODE_6
    ]
    frame.extend(ip)
    frame.append(CMD_TYPE_10)
    frame.extend(timestamp)
    frame.extend(body)
    length = len(frame) + 3
    frame[3], frame[4] = Utility.int_to_2bytes(length)
    c8 = crc8(bytes(frame)).hexdigest()
    frame.append(int(c8, 16))
    frame.extend([TAIL_FIRST, TAIL_LAST])
    return frame
Esempio n. 7
0
    def PerformPlayFileTask(self, Params):
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>speed=2</Param>
        #</Marvin>
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>speed=2</Param>
        #     <Param>repeat</Param>
        #</Marvin>
        #<?xml version="1.0" encoding="utf-8"?>
        #<Marvin Type="OscarTask">
        #    <Version>1.0</Version>
        #     <OscarID>DemoOscar</OscarID>
        #     <Task>Playback</Task>
        #     <Param>loop</Param>
        #     <Param>speed=2</Param>
        #     <Param>start=10</Param>
        #     <Param>end=2400</Param>
        #</Marvin>

        speed = 1
        start = 0
        end = Playback.get().GetDataCount()
        type = Playback.RepeatMode.NONE
        file = None

        for param in Params:
            tParam = Alias.Alias(param.lower())
            if tParam == "repeat":
                type = Playback.RepeatMode.REPEAT
            elif tParam == "loop":
                type = Playback.RepeatMode.LOOP
            else:
                parts = tParam.split("=")
                if len(parts) == 2:
                    if parts[0].lower() == 'start' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        start = int(parts[1])
                    elif parts[0].lower() == 'end' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        end = int(parts[1])
                    elif parts[0].lower() == 'speed' and Utility.IsNumeric(
                            Alias.Alias(parts[1])):
                        speed = int(parts[1])
                    elif parts[0].lower() == 'file':
                        file = parts[1]
                        if False == self.PerformLoadFileTask([file]):
                            return

                        end = Playback.get().GetDataCount()

                    else:
                        Log.getLogger().info(
                            "Received unknown Oscar Play parameter: " + param)
                        return
                else:
                    Log.getLogger().info(
                        "Received unknown Oscar Play parameter: " + param)
                    return

        if Playback.get().GetDataCount() == 0:
            Log.getLogger().info("Oscar Play received - but no file loaded.")
            return

        if start >= end:
            Log.getLogger().info("Oscar Play Loop  - but start > end.")
            return

        Log.getLogger().info("Performing Oscar task: Start Playback.")
        GuiMgr.OnStopRecording(True)  #drop all recorded packets
        GuiMgr.OnStopLiveData()

        GuiMgr.OnSetPlaybackSpeed(speed)
        GuiMgr.OnSetRepeatMode(type, start, end)
        GuiMgr.OnStartPlayback()