예제 #1
0
    def ldcurve_rx_data(self, data):
        "data: 表示返回帧数据域(已做减33H处理), 格式为字符串数组"
        import meter
        # 将data转为字符串,方便使用正则表达式进行提取
        data_str = " ".join(data)
        # 匹配组提取所需的数据信息
        r = r'.*A0 A0 [\da-fA-F]{2} (\d{2} \d{2} \d{2} \d{2} \d{2} )(.*)AA (.*)AA (.*)AA (.*)AA (.*)AA (.*)AA [\da-fA-F]{2} E5'
        # 每个数据项占用字节数列表,按照负荷曲线数据项的顺序配置,第一项为数据标识
        bl = [
            [5],  # 存储时刻
            [2, 2, 2, 3, 3, 3, 2],  # 电压、电流、频率
            [3] * 8,  # 有、无功功率
            [2] * 4,  # 功率因数
            [4] * 4,  # 有、无功总电能
            [4] * 4,  # 四象限无功总电能
            [3] * 4  # 有、无功需量、零线电流、总视在功率
        ]
        # 每个数据项的数据格式列表
        df = [
            ["YYMMDDhhmm"],  # 存储时刻
            [
                "XXX.X", "XXX.X", "XXX.X", "XXX.XXX", "XXX.XXX", "XXX.XXX",
                "XX.XX"
            ],  # 电压、电流、频率
            [
                "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX",
                "XX.XXXX", "XX.XXXX", "XX.XXXX"
            ],  # 有、无功功率
            ["X.XXX", "X.XXX", "X.XXX", "X.XXX"],  # 功率因数
            ["XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX"],  # 有、无功总电能
            ["XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX"],  # 四象限无功总电能
            ["XX.XXXX", "XX.XXXX", "XXX.XXX", "XX.XXXX"]  # 有、无功需量、零线电流、总视在功率
        ]
        # 提取匹配数据
        data_matched = re.match(r, data_str)
        result = []
        if data_matched:
            data_matched = data_matched.groups()
            # 将tuple类型转化为list,因为需要修改数据的值
            data_matched = list(data_matched)
            # 对数据项进行分组、反序处理
            for i in range((len(data_matched))):
                data_matched[i] = meter.splitByLen(data_matched[i].split(),
                                                   bl[i])
                for j in range(len(data_matched[i])):
                    data_matched[i][j].reverse()

            # 针对数据项进行数据格式处理
            for i in range(len(data_matched)):
                if data_matched[i]:
                    for j in range(len(data_matched[i])):
                        data_matched[i][j] = meter.id.format(
                            "".join(data_matched[i][j]), df[i][j])
            result = []
            for i in data_matched:
                result.extend(i)
        else:
            result = ["返回数据区为空"]
        return result
예제 #2
0
 def eng_rx_data(self, data):
     "data: 表示返回帧数据域(已做减33H处理), 格式为字符串数组"
     import meter
     # 数据标识和每一项电能量数据均占用4字节,按4字节对每一项数据进行分组并反向
     all_items = [item[::-1] for item in meter.splitByLen(data, [4] * 9)]
     result = []
     for item in all_items[1::]:
         result.append(self.format("".join(item), "XXXXXX.XX"))
     return result
예제 #3
0
    def dmd_rx_data(self, data):
        "data: 返回帧数据已做减33H处理, 格式为字符串数组"
        import meter

        # 数据标识和每一项需量数据均占用8字节,按8字节对每一项数据进行分组并反向
        all_items = [item[::-1] for item in meter.splitByLen(data, [4] + [8] * 9)]
        result = []
        for item in all_items[1::]:
            result.append(self.format("".join(item[5:] + item[:5]), "XX.XXXX,YYMMDDhhmm"))
        return result
예제 #4
0
    def eng_rx_data(self, data):
        "data: 表示返回帧数据域(已做减33H处理), 格式为字符串数组"
        import meter

        # 数据标识和每一项电能量数据均占用4字节,按4字节对每一项数据进行分组并反向
        all_items = [item[::-1] for item in meter.splitByLen(data, [4] * 9)]
        result = []
        for item in all_items[1::]:
            result.append(self.format("".join(item), "XXXXXX.XX"))
        return result
예제 #5
0
    def get_slice_name(self, id, slice_name):
        # 需要使用meter模块的splitByLen函数,为防止互相引用导致错误,在此处引用
        import meter
        # 将数据标识进行拆分为4个部分DI3 DI2 DI1 DI0
        split_id = [i.upper() for i in meter.splitByLen(id, [2, 2, 2, 2])]

        # 根据DI3 DI2 DI1 DI0的值从slice_name中获取具体的表示名称数组
        result = []
        for index in range(len(split_id)):
            result.append(slice_name[index][split_id[index]])
        return result
예제 #6
0
 def reverse_setting_data(self, setting):
     """setting-为命令的设置参数部分
     如命令为:set-cycle-display xxxxxxxx xxxxxxxx,nn,则
     setting的值为xxxxxxxx,nn
     """
     import meter
     reverse_list = []
     set_list = setting.split(',')
     for set in set_list:
         reverse_list.extend(
             meter.splitByLen(set, [2] * (len(set) // 2))[::-1])
     return reverse_list
예제 #7
0
    def get_slice_name(self, id, slice_name):
        # 需要使用meter模块的splitByLen函数,为防止互相引用导致错误,在此处引用
        import meter

        # 将数据标识进行拆分为4个部分DI3 DI2 DI1 DI0
        split_id = [i.upper() for i in meter.splitByLen(id, [2, 2, 2, 2])]

        # 根据DI3 DI2 DI1 DI0的值从slice_name中获取具体的表示名称数组
        result = []
        for index in range(len(split_id)):
            result.append(slice_name[index][split_id[index]])
        return result
예제 #8
0
    def reverse_setting_data(self, setting):
        """setting-为命令的设置参数部分
        如命令为:set-cycle-display xxxxxxxx xxxxxxxx,nn,则
        setting的值为xxxxxxxx,nn
        """
        import meter

        reverse_list = []
        set_list = setting.split(",")
        for set in set_list:
            reverse_list.extend(meter.splitByLen(set, [2] * (len(set) // 2))[::-1])
        return reverse_list
예제 #9
0
    def ldcurve_rx_data(self, data):
        "data: 表示返回帧数据域(已做减33H处理), 格式为字符串数组"
        import meter

        # 将data转为字符串,方便使用正则表达式进行提取
        data_str = " ".join(data)
        # 匹配组提取所需的数据信息
        r = r".*A0 A0 [\da-fA-F]{2} (\d{2} \d{2} \d{2} \d{2} \d{2} )(.*)AA (.*)AA (.*)AA (.*)AA (.*)AA (.*)AA [\da-fA-F]{2} E5"
        # 每个数据项占用字节数列表,按照负荷曲线数据项的顺序配置,第一项为数据标识
        bl = [
            [5],  # 存储时刻
            [2, 2, 2, 3, 3, 3, 2],  # 电压、电流、频率
            [3] * 8,  # 有、无功功率
            [2] * 4,  # 功率因数
            [4] * 4,  # 有、无功总电能
            [4] * 4,  # 四象限无功总电能
            [3] * 4,  # 有、无功需量、零线电流、总视在功率
        ]
        # 每个数据项的数据格式列表
        df = [
            ["YYMMDDhhmm"],  # 存储时刻
            ["XXX.X", "XXX.X", "XXX.X", "XXX.XXX", "XXX.XXX", "XXX.XXX", "XX.XX"],  # 电压、电流、频率
            ["XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX", "XX.XXXX"],  # 有、无功功率
            ["X.XXX", "X.XXX", "X.XXX", "X.XXX"],  # 功率因数
            ["XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX"],  # 有、无功总电能
            ["XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX", "XXXXXX.XX"],  # 四象限无功总电能
            ["XX.XXXX", "XX.XXXX", "XXX.XXX", "XX.XXXX"],  # 有、无功需量、零线电流、总视在功率
        ]
        # 提取匹配数据
        data_matched = re.match(r, data_str)
        result = []
        if data_matched:
            data_matched = data_matched.groups()
            # 将tuple类型转化为list,因为需要修改数据的值
            data_matched = list(data_matched)
            # 对数据项进行分组、反序处理
            for i in range((len(data_matched))):
                data_matched[i] = meter.splitByLen(data_matched[i].split(), bl[i])
                for j in range(len(data_matched[i])):
                    data_matched[i][j].reverse()

            # 针对数据项进行数据格式处理
            for i in range(len(data_matched)):
                if data_matched[i]:
                    for j in range(len(data_matched[i])):
                        data_matched[i][j] = meter.id.format("".join(data_matched[i][j]), df[i][j])
            result = []
            for i in data_matched:
                result.extend(i)
        else:
            result = ["返回数据区为空"]
        return result
예제 #10
0
 def dmd_rx_data(self, data):
     "data: 返回帧数据已做减33H处理, 格式为字符串数组"
     import meter
     # 数据标识和每一项需量数据均占用8字节,按8字节对每一项数据进行分组并反向
     all_items = [
         item[::-1] for item in meter.splitByLen(data, [4] + [8] * 9)
     ]
     result = []
     for item in all_items[1::]:
         result.append(
             self.format("".join(item[5:] + item[:5]),
                         "XX.XXXX,YYMMDDhhmm"))
     return result