Ejemplo n.º 1
0
 def configure_cr_packet(self):
     req_addr = self.cr_request_obj.findChildByName('addr')
     req_pwd = self.cr_request_obj.findChildByName('pwd')
     password = format_password(self.password)
     req_addr.setValue(self.bin_addr)
     req_pwd.setValue(password)
     self.cr_checksum = (0x58 + calc_sum(self.bin_addr) + 
                         calc_sum(password)) & 0xFF
Ejemplo n.º 2
0
 def configure_cr_packet(self):
     req_addr = self.cr_request_obj.findChildByName('addr')
     req_pwd = self.cr_request_obj.findChildByName('pwd')
     password = format_password(self.password)
     req_addr.setValue(self.bin_addr)
     req_pwd.setValue(password)
     self.cr_checksum = (0x58 + calc_sum(self.bin_addr) +
                         calc_sum(password)) & 0xFF
Ejemplo n.º 3
0
    def _write_cr_value(self, value, wait_time=None, numretries=None):
        """Only to be used by set_cr_value method

        Value should only be an integer
        """
        if not self.is_running():
            raise ENotRunning()
        if numretries is None:
            numretries = self.retry_count
        data = self.cr_request_obj.findChildByName('data')
        bcc = self.cr_request_obj.findChildByName('bcc')
        checksum = (self.cr_checksum + value) & 0xFF
        data.setValue(value)
        bcc.setValue(checksum)
        while numretries:
            try:
                self._send_request(self.cr_request_obj, self.cr_response_obj,
                                   wait_time, 1)
                resp_addr = self.cr_response_obj.findChildByName('addr')
                resp_bcc = self.cr_response_obj.findChildByName('bcc')
                addr = resp_addr.getValue()
                bcc = resp_bcc.getValue()
                checksum = (0xD3 + calc_sum(addr)) & 0xFF
                if checksum != bcc:
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    raise EInvalidMessage()
                return
            except:
                numretries -= 1
        raise
Ejemplo n.º 4
0
 def configure_packet(self):
     req_addr = self.request_obj.findChildByName('addr')
     req_cs = self.request_obj.findChildByName('cs')
     req_addr.setValue(self.bin_addr)
     #0xD9 is checksum of rest of field, which will remain constant
     checksum = (0xD9 + calc_sum(self.bin_addr)) & 0xFF
     req_cs.setValue(checksum)
Ejemplo n.º 5
0
    def _write_cr_value(self, value, wait_time=None, numretries=None):
        """Only to be used by set_cr_value method

        Value should only be an integer
        """
        if not self.is_running():
            raise ENotRunning()
        if numretries is None:
            numretries = self.retry_count
        data = self.cr_request_obj.findChildByName('data')
        bcc = self.cr_request_obj.findChildByName('bcc')
        checksum = (self.cr_checksum + value) & 0xFF
        data.setValue(value)
        bcc.setValue(checksum)
        while numretries:
            try:
                self._send_request(self.cr_request_obj,
                                   self.cr_response_obj, wait_time, 1)
                resp_addr = self.cr_response_obj.findChildByName('addr')
                resp_bcc = self.cr_response_obj.findChildByName('bcc')
                addr = resp_addr.getValue()
                bcc = resp_bcc.getValue()
                checksum = (0xD3 + calc_sum(addr)) & 0xFF
                if checksum != bcc:
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    raise EInvalidMessage()
                return
            except:
                numretries -= 1
        raise
Ejemplo n.º 6
0
 def configure_packet(self):
     req_addr = self.request_obj.findChildByName("addr")
     req_cs = self.request_obj.findChildByName("cs")
     req_addr.setValue(self.bin_addr)
     # 0xD9 is checksum of rest of field, which will remain constant
     checksum = (0xD9 + calc_sum(self.bin_addr)) & 0xFF
     req_cs.setValue(checksum)
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def _read_rt_value(self, wait_time=None, numretries=None):
        """Don't use Me.

        """
        if numretries is None:
            numretries = self.retry_count
        while numretries:
            try:
                self._send_request(self.rt_request_obj, self.rt_response_obj,
                                   wait_time, 1)
                resp_addr = self.rt_response_obj.findChildByName('addr')
                resp_data = self.rt_response_obj.findChildByName('data')
                resp_bcc = self.rt_response_obj.findChildByName('bcc')
                addr = resp_addr.getValue()
                data = resp_data.getValue()
                bcc = resp_bcc.getValue()
                checksum = (0xD9 + calc_sum(addr) + calc_sum(data)) & 0xFF
                if checksum != bcc:
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    raise EInvalidMessage()

                values = {}
                values['EM_RecMeterValue'] = format_rt_reading(data[0:4])
                values['EM_SenMeterValue'] = format_rt_reading(data[4:8])
                values['EM_RecActivePower'] = format_rt_reading(data[8:12])
                values['EM_SenActivePower'] = format_rt_reading(data[12:16])
                values['EM_RecPassive1MeterValue'] = format_rt_reading(
                    data[16:20])
                values['EM_RecPassive2MeterValue'] = format_rt_reading(
                    data[20:24])
                values['EM_RecPassivePower1'] = format_rt_reading(data[24:28])
                values['EM_RecPassivePower2'] = format_rt_reading(data[28:32])
                values['EM_SenPassive1MeterValue'] = format_rt_reading(
                    data[32:36])
                values['EM_SenPassive2MeterValue'] = format_rt_reading(
                    data[36:40])
                values['EM_SenPassivePower1'] = format_rt_reading(data[40:44])
                values['EM_SenPassivePower2'] = format_rt_reading(data[44:48])

                #have to rename voltages and currents
                values['EM_Voltage_1'] = format_rt_reading(data[48:52])
                values['EM_Voltage_2'] = format_rt_reading(data[52:56])
                values['EM_Voltage_3'] = format_rt_reading(data[56:60])
                values['EM_Current_1'] = format_rt_reading(data[60:64])
                values['EM_Current_2'] = format_rt_reading(data[64:68])
                values['EM_Current_3'] = format_rt_reading(data[68:72])
                values['EM_Phase_1'] = format_rt_reading(data[72:76])
                values['EM_Phase_2'] = format_rt_reading(data[76:80])
                values['EM_Phase_3'] = format_rt_reading(data[80:84])
                values['EM_Hz'] = format_rt_reading(data[84:88])
                values['EM_PowerRelay'] = format_rt_reading(data[88:92])

                values['WM_MeterValue'] = format_rt_reading(data[92:96])
                values['WM_MeterPower'] = format_rt_reading(data[96:100])
                values['HM_MeterValue'] = format_rt_reading(data[100:104])
                values['HM_MeterPower'] = format_rt_reading(data[104:108])
                values['GM_MeterValue'] = format_rt_reading(data[108:112])
                values['GM_MeterPower'] = format_rt_reading(data[112:116])
                values['CM_MeterValue'] = format_rt_reading(data[116:120])
                values['CM_MeterPower'] = format_rt_reading(data[120:124])
                self.update_rt_value(values)
                return
            except:
                numretries -= 1
        raise
Ejemplo n.º 10
0
 def configure_rt_packet(self):
     req_addr = self.rt_request_obj.findChildByName('addr')
     req_bcc = self.rt_request_obj.findChildByName('bcc')
     req_addr.setValue(self.bin_addr)
     checksum = (0xC3 + calc_sum(self.bin_addr)) & 0xFF
     req_bcc.setValue(checksum)
Ejemplo n.º 11
0
    def _read_rt_value(self, wait_time=None, numretries=None):
        """Don't use Me.

        """
        if numretries is None:
            numretries = self.retry_count
        while numretries:
            try:
                self._send_request(self.rt_request_obj, 
                                   self.rt_response_obj, wait_time, 1)
                resp_addr = self.rt_response_obj.findChildByName('addr')
                resp_data = self.rt_response_obj.findChildByName('data')
                resp_bcc = self.rt_response_obj.findChildByName('bcc')
                addr = resp_addr.getValue()
                data = resp_data.getValue()
                bcc = resp_bcc.getValue()
                checksum = (0xD9 + calc_sum(addr) + calc_sum(data)) & 0xFF
                if checksum != bcc:
                    raise EBadChecksum()
                if self.bin_addr != addr:
                    raise EInvalidMessage()

                values = {}
                values['EM_RecMeterValue'] = format_rt_reading(data[0:4])
                values['EM_SenMeterValue'] = format_rt_reading(data[4:8])
                values['EM_RecActivePower'] = format_rt_reading(data[8:12])
                values['EM_SenActivePower'] = format_rt_reading(data[12:16])
                values['EM_RecPassive1MeterValue'] = format_rt_reading(data[16:20])
                values['EM_RecPassive2MeterValue'] = format_rt_reading(data[20:24])
                values['EM_RecPassivePower1'] = format_rt_reading(data[24:28])
                values['EM_RecPassivePower2'] = format_rt_reading(data[28:32])    
                values['EM_SenPassive1MeterValue'] = format_rt_reading(data[32:36])
                values['EM_SenPassive2MeterValue'] = format_rt_reading(data[36:40])
                values['EM_SenPassivePower1'] = format_rt_reading(data[40:44])
                values['EM_SenPassivePower2'] = format_rt_reading(data[44:48]) 

                #have to rename voltages and currents
                values['EM_Voltage_1'] = format_rt_reading(data[48:52])
                values['EM_Voltage_2'] = format_rt_reading(data[52:56])      
                values['EM_Voltage_3'] = format_rt_reading(data[56:60])      
                values['EM_Current_1'] = format_rt_reading(data[60:64])
                values['EM_Current_2'] = format_rt_reading(data[64:68])
                values['EM_Current_3'] = format_rt_reading(data[68:72])
                values['EM_Phase_1'] = format_rt_reading(data[72:76])
                values['EM_Phase_2'] = format_rt_reading(data[76:80])
                values['EM_Phase_3'] = format_rt_reading(data[80:84])
                values['EM_Hz'] = format_rt_reading(data[84:88])
                values['EM_PowerRelay'] = format_rt_reading(data[88:92])

                values['WM_MeterValue'] = format_rt_reading(data[92:96])
                values['WM_MeterPower'] = format_rt_reading(data[96:100])
                values['HM_MeterValue'] = format_rt_reading(data[100:104])
                values['HM_MeterPower'] = format_rt_reading(data[104:108])
                values['GM_MeterValue'] = format_rt_reading(data[108:112])
                values['GM_MeterPower'] = format_rt_reading(data[112:116])
                values['CM_MeterValue'] = format_rt_reading(data[116:120])
                values['CM_MeterPower'] = format_rt_reading(data[120:124])
                self.update_rt_value(values)
                return
            except:
                numretries -= 1
        raise
Ejemplo n.º 12
0
 def configure_rt_packet(self):
     req_addr = self.rt_request_obj.findChildByName('addr')
     req_bcc = self.rt_request_obj.findChildByName('bcc')
     req_addr.setValue(self.bin_addr)
     checksum = (0xC3 + calc_sum(self.bin_addr)) & 0xFF
     req_bcc.setValue(checksum)
Ejemplo n.º 13
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
Ejemplo n.º 14
0
 def configure_packet(self):
     req_addr = self.request_obj.findChildByName('addr')
     req_cs = self.request_obj.findChildByName('cs')
     req_addr.setValue(self.bin_addr)
     checksum = (0x39 + calc_sum(self.bin_addr)) & 0xFF
     req_cs.setValue(checksum)