Esempio n. 1
0
    def _read(self, wait_time=None, numretries=None):
        """Reads the device.

        Sends the request packet, recieves the response packet.
        Parses it. Updates the current reading value

        Should be called only by get_value()
        """
        if numretries is None:
            numretries = self.retry_count
        while numretries:
            try:
                self._send_request(self.request_obj, self.response_obj,
                                   wait_time, 1)
                resp_addr = self.response_obj.findChildByName('addr')
                resp_cs = self.response_obj.findChildByName('cs')
                resp_data = self.response_obj.findChildByName('data')
                addr = resp_addr.getValue()
                cs = resp_cs.getValue()
                data = resp_data.getValue()
                checksum = (0x5D + calc_sum(addr) + calc_sum(data)) & 0xFF
                if checksum != cs:
                    #some error in the response packet
                    if self.debug:
                        msglog.log("omnimeter", msglog.types.WARN,
                                   "Checksum didn't match %s" % self.address)
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    #it's not me. don't think this would ever happen, but who knows
                    if self.debug:
                        msglog.log(
                            'omnimeter', msglog.types.WARN,
                            "Got some other meter's response (Strange!!) %s" %
                            self.address)
                    raise EInvalidMessage()
                meter_reading = format_reading(data)
                self.update_value(meter_reading)
                return
            except:
                numretries -= 1
        raise
Esempio n. 2
0
    def _read(self, wait_time=None, numretries=None):
        """Reads the device.

        Sends the request packet, recieves the response packet.
        Parses it. Updates the current reading value

        Should be called only by get_value()
        """
        if numretries is None:
            numretries = self.retry_count
        while numretries:
            try:
                self._send_request(self.request_obj, self.response_obj, wait_time, 1)
                resp_addr = self.response_obj.findChildByName("addr")
                resp_cs = self.response_obj.findChildByName("cs")
                resp_data = self.response_obj.findChildByName("data")
                addr = resp_addr.getValue()
                cs = resp_cs.getValue()
                data = resp_data.getValue()
                checksum = (0x5D + calc_sum(addr) + calc_sum(data)) & 0xFF
                if checksum != cs:
                    # some error in the response packet
                    if self.debug:
                        msglog.log("omnimeter", msglog.types.WARN, "Checksum didn't match %s" % self.address)
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    # it's not me. don't think this would ever happen, but who knows
                    if self.debug:
                        msglog.log(
                            "omnimeter",
                            msglog.types.WARN,
                            "Got some other meter's response (Strange!!) %s" % self.address,
                        )
                    raise EInvalidMessage()
                meter_reading = format_reading(data)
                self.update_value(meter_reading)
                return
            except:
                numretries -= 1
        raise
Esempio n. 3
0
    def _read(self, wait_time=None, numretries=None):
        """Reads the device
        Sends the request packet, recieves the response packet,
        Parses it. Updates the current reading value

        Shouldn't be called by anyone. Use get_value_by_name instead
        """
        if numretries is None:
            numretries = self.retry_count
        while numretries:
            try:
                self._send_request(self.request_obj,
                                   self.response_obj, wait_time, 1)
                resp_addr = self.response_obj.findChildByName('addr')
                resp_data = self.response_obj.findChildByName('data')
                resp_cs = self.response_obj.findChildByName('cs')
                addr = resp_addr.getValue()
                data = resp_data.getValue()
                cs = resp_cs.getValue()
                #relay variable included because of bug #CSCts88534
                relay = 0
                resp_relay = self.response_obj.findChildByName('relay')
                if resp_relay is not None:
                    relay = resp_relay.getValue() + 1
                checksum = (0xD2 + calc_sum(addr) + 
                            calc_sum(data) + relay) & 0xFF
                if self.debug:
                    msglog.log('omnimeter', msglog.types.INFO, 
                               'checksum calculated %s Received %s' 
                               % (str(checksum),
                                  str(cs)))
                if checksum != cs:
                    msglog.log("omnimeter", msglog.types.WARN, 
                               "Checksum didn't match %s" % self.address)
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    #it's not me. don't think this would ever happen, but who knows
                    msglog.log('omnimeter', msglog.types.WARN, 
                               "Got some other meter's response (Strange!!!) %s" % 
                               self.address)
                    raise EInvalidMessage()
                #everything fine till here, get the reading and update self.value
                #Get the error status flag
                meter_reading = {}
                err_status = ord(data[24]) - 0x33
                if not (err_status & 0x01):
                    meter_reading['SP'] = format_reading(data[20:24])
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO, 
                                   "Got Reading SP:%s" % (meter_reading['SP'],))
                else:
                    meter_reading['SP'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for SP')
                if not (err_status & 0x02):
                    meter_reading['CM'] = format_reading(data[12:16])
                    if self.debug:
                        msglog.log('omnimeter',msglog.types.INFO, 
                                   "Got Reading CM:%s" % (meter_reading['CM'],))
                else:
                    meter_reading['CM'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for CM')
                if not (err_status & 0x04):
                    meter_reading['GM'] = format_reading(data[8:12])
                    if self.debug:
                        msglog.log('omnimeter',msglog.types.INFO, 
                                   "Got Reading GM:%s" % (meter_reading['GM'],))
                else:
                    meter_reading['GM'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for GM')
                if not (err_status & 0x08):
                    meter_reading['HM'] = format_reading(data[4:8])
                    if self.debug:
                        msglog.log('omnimeter',msglog.types.INFO, 
                                   "Got Reading HM:%s" % (meter_reading['HM'],))
                else:
                    meter_reading['HM'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for HM')
                if not (err_status & 0x10):
                    meter_reading['WM'] = format_reading(data[0:4])
                    if self.debug:
                        msglog.log('omnimeter',msglog.types.INFO, 
                                   "Got Reading WM:%s" % (meter_reading['WM'],))
                else:
                    meter_reading['WM'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for WM')
                if not (err_status & 0x20):
                    meter_reading['EM'] = format_reading(data[16:20])
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO, 
                                   "Got Reading EM:%s" 
                                   % (meter_reading['EM'],))
                else:
                    meter_reading['EM'] = EConnectionError()
                    if self.debug:
                        msglog.log('omnimeter', msglog.types.INFO,
                                   'Did not get reading for EM')
                self.update_value(meter_reading)
                return
            except:
                numretries -= 1
        raise