Exemple #1
0
    def detect(self):
        detected = {}
        for port, conn in self._conn.iteritems():
            if self._isdetecting == False or self.isexecuting() == False:
                self._logger.info("Total detection is canceled.")
                break
            info = self.detectone(port, conn)
            detected[port] = info

        self._logger.info("finished to detect devices : " + str(detected))
        noti = Notice(None, NotiCode.DETECT_FINISHED)  # Detection Started
        if noti:
            noti.setkeyvalue("opid", self._detection["opid"])
            for port, info in detected.iteritems():
                noti.setcontent(port, info)
            self.writecb(noti)
        self.setdetection(False)
Exemple #2
0
    def detect(self):
        detected = {}
        for unit in range(self._detection["saddr"], self._detection["eaddr"]):
            if self._isdetecting == False or self.isexecuting() == False:
                break

            noti = Notice(None, NotiCode.DETECT_NODE_STARTED,
                          devid=unit)  # Detection Started
            if noti:
                noti.setkeyvalue("opid", self._detection["opid"])
                self.writecb(noti)

            noti = None
            info = None
            while True:
                res = self.readregister(self._startregister, 6, unit)
                if res.isError():
                    break

                if len(res.registers) != 6:
                    self._logger.info(
                        "retry to get data since size of data is not matched. 6 "
                        + str(len(res.registers)))
                    continue
                break

            if res.isError():
                noti = Notice(None, NotiCode.DETECT_NO_NODE,
                              devid=unit)  # Detection Started
                self._logger.info("Fail to get information from a node : " +
                                  str(unit) + " " + str(res))

            elif res.registers[1] in (NodeType.SENNODE, NodeType.ACTNODE,
                                      NodeType.INTNODE):  # device type
                if res.registers[3] == ProtoVer.KS_X_3267_2018:
                    info = self.detect_node(unit, res.registers)
                    self._logger.info("Found a node : " + str(unit) + " " +
                                      str(info))
                else:
                    noti = Notice(None,
                                  NotiCode.DETECT_UNKNOWN_PROTOCOL_VER,
                                  devid=unit)  # unknown protocol version
            elif res.registers[1] == NodeType.NUTNODE:
                if res.registers[3] == ProtoVer.TTA_1:
                    info = self.detect_nutri(unit, res.registers)
                    self._logger.info("Found a nutrient system : " +
                                      str(unit) + " " + str(info))
                else:
                    noti = Notice(None,
                                  NotiCode.DETECT_UNKNOWN_PROTOCOL_VER,
                                  devid=unit)  # unknown protocol version
            else:
                noti = Notice(unit, NotiCode.DETECT_UNKNOWN_NODE,
                              devid=unit)  # unknown device

            if noti is None:
                if info is None:
                    noti = Notice(None,
                                  NotiCode.DETECT_WRONG_DEVICE,
                                  devid=unit)  # fail to find a node
                else:
                    noti = Notice(None,
                                  NotiCode.DETECT_NODE_DETECTED,
                                  devid=self._option["conn"]["port"][8:],
                                  content={unit: info})  # found a node
                    detected[unit] = info

            noti.setkeyvalue("opid", self._detection["opid"])
            print "noti", noti.stringify()
            self.writecb(noti)
            time.sleep(0.1)

        self._logger.info("finished to detect devices : " + str(detected))
        noti = Notice(None, NotiCode.DETECT_FINISHED)  # Detection Started
        if noti:
            noti.setkeyvalue("opid", self._detection["opid"])
            noti.setcontent(self._option["conn"]["port"][8:], detected)
            #for lid, info in detected.iteritems():
            #                noti.setcontent(lid, info)
            self.writecb(noti)
        self.setdetection(False)
Exemple #3
0
 def sendnoticeforactuatorstatus(self, ndinfo):
     blk = Notice(ndinfo["id"], NotiCode.ACTUATOR_STATUS, ndinfo["id"],
                  ndinfo["nd"])
     for devid, info in ndinfo["act"].iteritems():
         blk.setcontent(devid, info)
     self.writecb(blk)