Esempio n. 1
0
    def __ioSampleCallback(self, buf, addr):
        try:
            sample = parse_is(buf)
        except:
            logger.warning("__ioSampleCallback(): bad I/O sample format")
            return

        # build pin sets:
        ad_set = set(map(lambda d: "AD%d" % d, range(7)))
        dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
        io_set = ad_set.union(dio_set)
        sample_set = set(sample.keys())

        count = 0
        for io_pin in io_set.intersection(sample_set):
            unit = "bool"
            value = str(bool(int(sample[io_pin])))
            if io_pin in ad_set:
                unit = "int"
                value = str(int(sample[io_pin]))
            self._sample_add(
                addr2iDigiDataLabel(addr) + "." + io_pin, value, unit,
                iso_date(None, True))
            count += 1
        logger.debug('queued %d I/O samples for upload to iDigi' % count)
Esempio n. 2
0
    def __ioSampleCallback(self, buf, addr_tuple):
        if self.__io_sample_destination_url is None:
            logger.info("__ioSampleCallback(): no URL configured.")
            return

        try:
            sample = parse_is(buf)
        except:
            logger.warning("__ioSampleCallback(): bad I/O sample format")
            return

        # build pin sets:
        ad_set = set(map(lambda d: "AD%d" % d, range(7)))
        dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
        io_set = ad_set.union(dio_set)
        sample_set = set(sample.keys())

        # find appropriate I/O sample URL destination:
        dest_url = self.__io_sample_destination_url.get(
            addr_tuple.address, self.__default_destination_url)
        if not dest_url:
            # no url configured to send values
            return

        # built URL predicate:
        url_pred = {"addr": addr_tuple.address}
        for io_pin in io_set.intersection(sample_set):
            url_pred[io_pin] = str(int(sample[io_pin]))
        if "?" in dest_url:
            url_pred = urlencode(url_pred)
        else:
            url_pred = "?" + urlencode(url_pred)
        url = dest_url + url_pred

        # schedule HTTP session operation:
        http_session = HTTPSession(self.__core, url, addr_tuple, True)
        try:
            self.__core.enqueueSession(http_session)
        except OverflowError:
            return self.__xml_err_msg("queue full for destination")
Esempio n. 3
0
 def __ioSampleCallback(self, buf, addr_tuple):
     if self.__io_sample_destination_url is None:
         logger.info("__ioSampleCallback(): no URL configured.")
         return
     
     try:
         sample = parse_is(buf)
     except:
         logger.warning("__ioSampleCallback(): bad I/O sample format")
         return
     
     # build pin sets:
     ad_set = set(map(lambda d: "AD%d" % d, range(7)))
     dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
     io_set = ad_set.union(dio_set)
     sample_set = set(sample.keys())
     
     # find appropriate I/O sample URL destination:
     dest_url = self.__io_sample_destination_url.get(addr_tuple.address, self.__default_destination_url)
     if not dest_url:
         # no url configured to send values
         return
         
     # built URL predicate:
     url_pred = { "addr": addr_tuple.address }
     for io_pin in io_set.intersection(sample_set):
         url_pred[io_pin] = str(int(sample[io_pin]))
     if "?" in dest_url:
         url_pred = urlencode(url_pred)
     else:
         url_pred = "?" + urlencode(url_pred)
     url = dest_url + url_pred
         
     # schedule HTTP session operation:
     http_session = HTTPSession(self.__core, url, addr_tuple, True)
     try:
         self.__core.enqueueSession(http_session)
     except OverflowError:
         return self.__xml_err_msg("queue full for destination")
Esempio n. 4
0
    def __format_is_response_tree(self, is_data):
        sample = parse_is(is_data)
        # build pin sets:
        ad_set = set(map(lambda d: "AD%d" % d, range(7)))
        dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
        io_set = ad_set.union(dio_set)
        sample_set = set(sample.keys())

        # build nodes:
        new_nodes = [ ]
        for io_pin in io_set.intersection(sample_set):
            response_tree = ET.Element("io_pin")
            response_tree.set("name", io_pin)
            value = str(bool(int(sample[io_pin])))
            if io_pin in ad_set:
                value = str(int(sample[io_pin]))
                response_tree.set("unit", "int")
            else:
                response_tree.set("unit", "bool")
            response_tree.set("value", value)
            new_nodes.append(response_tree)

        return new_nodes
Esempio n. 5
0
    def __ioSampleCallback(self, buf, addr):
        try:
            sample = parse_is(buf)
        except:
            logger.warning("__ioSampleCallback(): bad I/O sample format")
            return

        # build pin sets:
        ad_set = set(map(lambda d: "AD%d" % d, range(7)))
        dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
        io_set = ad_set.union(dio_set)
        sample_set = set(sample.keys())

        count = 0
        for io_pin in io_set.intersection(sample_set):
            unit = "bool"
            value = str(bool(int(sample[io_pin])))
            if io_pin in ad_set:
                unit = "int"
                value = str(int(sample[io_pin]))
            self._sample_add(addr2iDigiDataLabel(addr) + "." + io_pin, value, unit, iso_date(None, True))
            count += 1
        logger.debug("queued %d I/O samples for upload to iDigi" % count)
Esempio n. 6
0
    def __format_is_response_tree(self, is_data):
        sample = parse_is(is_data)
        # build pin sets:
        ad_set = set(map(lambda d: "AD%d" % d, range(7)))
        dio_set = set(map(lambda d: "DIO%d" % d, range(13)))
        io_set = ad_set.union(dio_set)
        sample_set = set(sample.keys())

        # build nodes:
        new_nodes = []
        for io_pin in io_set.intersection(sample_set):
            response_tree = ET.Element("io_pin")
            response_tree.set("name", io_pin)
            value = str(bool(int(sample[io_pin])))
            if io_pin in ad_set:
                value = str(int(sample[io_pin]))
                response_tree.set("unit", "int")
            else:
                response_tree.set("unit", "bool")
            response_tree.set("value", value)
            new_nodes.append(response_tree)

        return new_nodes