Ejemplo 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)
Ejemplo n.º 2
0
    def __init__(self, xig_core, url, xbee_addr):
        self.__core = xig_core
        self.__idigi_data_autostart = xig_core.getAutostartSessions(
            obj_type=iDigiDataAutostartSession)
        self.__no_errors = getattr(self.__core.getConfig(),
                                   "idigi_data_no_errors", False)

        self.__xbee_addr = xbee_addr
        self.__write_buf = ""

        if not url.startswith("dc_data:") and not url.startswith(
                "idigi_data:"):
            self._do_error(
                'url does not start with "idigi_data:" or "dc_data"')
            return

        if (url.count("dc_data:") > 1) or (url.count("idigi_data:") > 1):
            # special case, malformed command buffer
            self._do_error("too many idigi_data: in command string")

        qs = url.split(":")[1]
        try:
            qs = parse_qs(qs)
        except:
            self._do_error("unable to parse sample string")
            return

        if "names" not in qs:
            self._do_error('required keyword "names" not present')
            return
        if "values" not in qs:
            self._do_error('required keyword "values" not present')
            return

        dl_addr = addr2iDigiDataLabel(xbee_addr)

        names_list = map(lambda n: dl_addr + "." + n,
                         qs["names"][0].split(','))
        param_lists = [names_list, qs["values"][0].split(',')]

        if "units" in qs:
            param_lists.append(qs["units"][0].split(','))
        else:
            param_lists.append([''] * len(param_lists[0]))

        if not all(len(l) == len(param_lists[0]) for l in param_lists[1:]):
            self._do_error("not all lists the same length")
            return

        # prepare all timestamps for samples
        param_lists.append(len(param_lists[0]) * [iso_date(None, True)])

        # submit samples:
        for sample_params in zip(*param_lists):
            self.__idigi_data_autostart._sample_add(*sample_params)
        logger.debug('queued %d samples for upload to iDigi' % len(names_list))
Ejemplo n.º 3
0
    def __init__(self, xig_core, url, xbee_addr):
        self.__core = xig_core
        self.__idigi_data_autostart = xig_core.getAutostartSessions(obj_type=iDigiDataAutostartSession)
        self.__no_errors = getattr(self.__core.getConfig(), "idigi_data_no_errors", False)

        self.__xbee_addr = xbee_addr
        self.__write_buf = ""

        if not url.startswith("dc_data:") and not url.startswith("idigi_data:"):
            self._do_error('url does not start with "idigi_data:" or "dc_data"')
            return

        if (url.count("dc_data:") > 1) or (url.count("idigi_data:") > 1):
            # special case, malformed command buffer
            self._do_error("too many idigi_data: in command string")

        qs = url.split(":")[1]
        try:
            qs = parse_qs(qs)
        except:
            self._do_error("unable to parse sample string")
            return

        if "names" not in qs:
            self._do_error('required keyword "names" not present')
            return
        if "values" not in qs:
            self._do_error('required keyword "values" not present')
            return

        dl_addr = addr2iDigiDataLabel(xbee_addr)

        names_list = map(lambda n: dl_addr + "." + n, qs["names"][0].split(","))
        param_lists = [names_list, qs["values"][0].split(",")]

        if "units" in qs:
            param_lists.append(qs["units"][0].split(","))
        else:
            param_lists.append([""] * len(param_lists[0]))

        if not all(len(l) == len(param_lists[0]) for l in param_lists[1:]):
            self._do_error("not all lists the same length")
            return

        # prepare all timestamps for samples
        param_lists.append(len(param_lists[0]) * [iso_date(None, True)])

        # submit samples:
        for sample_params in zip(*param_lists):
            self.__idigi_data_autostart._sample_add(*sample_params)
        logger.debug("queued %d samples for upload to iDigi" % len(names_list))
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
Archivo: xig.py Proyecto: Rahuldee/XIG
 def handleCommandTime(self):
     # Get the current time, add time zone adjustment, if any:
     time_str = helpers.iso_date(t=None, use_local_time_offset=True)          
     self.appendSessionToXBeeBuffer("Xig: " + time_str + "\r\n")
Ejemplo n.º 6
0
 def handleCommandTime(self):
     # Get the current time, add time zone adjustment, if any:
     time_str = helpers.iso_date(t=None, use_local_time_offset=True)
     self.appendSessionToXBeeBuffer("Xig: " + time_str + "\r\n")