Пример #1
0
    def SendInitialState(self):
        if "Analogs" in self.ConfigDict:
            for x in self.ConfigDict["Analogs"]:
                odc.PublishEvent(self.guid, "Analog", x["Index"], "|ONLINE|",
                                 str(x["Value"]))

        if "Binaries" in self.ConfigDict:
            for x in self.ConfigDict["Binaries"]:
                odc.PublishEvent(self.guid, "Binary", x["Index"], "|ONLINE|",
                                 str(x["Value"]))
        return
Пример #2
0
 def SendInitialState(self, Json):
     for x in Json:
         if (x["SimType"] == "CBStateBit0") or (x["SimType"]
                                                == "CBStateBit1"):
             odc.PublishEvent(
                 self.guid, "Binary", x["Index"], "|ONLINE|",
                 str(x["State"]
                     ))  # Need to send this change through as an event
     return
Пример #3
0
    def EventHandler(self,EventType, Index, Time, Quality, Payload, Sender):
        self.LogTrace("EventHander: {}, {}, {} {} - {}".format(self.guid,Sender,Index,EventType,Payload))

        self.processedevents += 1

        if (EventType == "Binary"):
            self.LogDebug("Event is a Binary")
        if ("ONLINE" not in Quality):
            self.LogDebug("Event Quality not ONLINE")

        odc.PublishEvent(self.guid,EventType,Index,Quality,Payload)  # Echoing Event for testing. Sender, Time auto created in ODC
        return True
Пример #4
0
    def UpdateAnalogValue(self, x, secs):
        # use the secs, value, mean and std dev to calculate a new value - also if there is actually a new value.
        try:
            newval = numpy.random.normal(x["Mean"], x["StdDev"])
            if (newval != x["Value"]):
                x["Value"] = newval
                odc.PublishEvent(
                    self.guid, "Analog", x["Index"], "|ONLINE|",
                    str(x["Value"]
                        ))  # Need to send this change through as an event

        except (RuntimeError, TypeError, NameError, Exception) as e:
            self.LogError("Exception - {}".format(e))
            return  # dont change anything
        return
Пример #5
0
    def SetAnalogValue(self, Type, Number, Value):
        for x in self.ConfigDict["Analogs"]:
            if (x["Type"] == Type) and (Type == "Sim"):
                if x["Index"] == Number:  # No number for Sim types, revert to ODCIndex
                    if type(Value) is str:  # Handle string values
                        Value = int(Value)
                    x["Value"] = Value
                    odc.PublishEvent(
                        self.guid, "Analog", x["Index"], "|ONLINE|", str(Value)
                    )  # Need to send this change through as an event
                    return

            elif (x["Type"] == Type) and (x["Number"] == Number):
                if type(Value) is str:  # Handle string values
                    Value = int(Value)
                x["Value"] = Value
                odc.PublishEvent(
                    self.guid, "Analog", x["Index"], "|ONLINE|",
                    str(Value))  # Need to send this change through as an event
                return

        raise Exception(
            "Could not find a matching analog field for {}, {}".format(
                Type, Number))
Пример #6
0
    def SetState(self, Json, CBNumber, CBStateBit, State):
        for x in Json:
            if (x["CBNumber"] == CBNumber) and (x["SimType"] == CBStateBit):
                # we have a match!

                if (x["State"] == State):
                    self.LogDebug(
                        "No Change in state bit {}".format(CBStateBit))
                    return  # nothing to do, the bit has not changed

                x["State"] = State
                odc.PublishEvent(
                    self.guid, "Binary", x["Index"], "|ONLINE|",
                    str(State))  # Need to send this change through as an event
                return

        raise Exception(
            "Could not find a matching State field for {}, {}".format(
                CBNumber, CBStateBit))
Пример #7
0
    def SetAnalogValueUsingIndex(self, Index, Value):
        for x in self.ConfigDict["Analogs"]:
            if (x["Index"] == Index):

                if type(Value) is str:  # Handle string values
                    Value = int(Value)

                if (x["Value"] == Value):
                    self.LogDebug(
                        "No Change in value of analog {}".format(Index))
                    return  # nothing to do, the value has not changed

                x["Value"] = Value
                odc.PublishEvent(
                    self.guid, "Analog", x["Index"], "|ONLINE|",
                    str(Value))  # Need to send this change through as an event
                return

        raise Exception(
            "Could not find a matching Value field for {}".format(Index))
Пример #8
0
    def SetBinaryValueUsingIndex(self, Index, Value):
        for x in self.ConfigDict["Binaries"]:
            if (x["Index"] == Index):
                # we have a match!
                if type(Value) is str:  # Handle string values
                    Value = int(Value)

                if (x["Value"] == Value):
                    self.LogDebug("No Change in value of bit {}".format(BitID))
                    return  # nothing to do, the bit has not changed

                x["Value"] = Value
                odc.PublishEvent(
                    self.guid, "Binary", x["Index"], "|ONLINE|",
                    str(Value))  # Need to send this change through as an event
                return

        raise Exception(
            "Could not find a matching binary value for Index {}".format(
                Index))
Пример #9
0
    def SetBinaryValue(self, Type, Number, BitID, Value):
        for x in self.ConfigDict["Binaries"]:
            if (x["Type"] == Type) and (x["Number"] == Number) and (x["BitID"]
                                                                    == BitID):

                if type(Value) is str:  # Handle string values
                    Value = int(Value)

                if (x["Value"] == Value):
                    self.LogDebug("No Change in value of bit {}".format(BitID))
                    return  # nothing to do, the bit has not changed

                x["Value"] = Value
                odc.PublishEvent(
                    self.guid, "Binary", x["Index"], "|ONLINE|",
                    str(Value))  # Need to send this change through as an event
                return

        raise Exception(
            "Could not find a matching binary value for {}, {}, {}".format(
                Type, Number, BitID))