demo.dtu/dtu_channels.py
elian.wang d5c4007e32 1.删除offline_storage.py文件
2.将所有py文件中的'改为"
3.将透传模式从modbus中分成单独文件through_mode
4.将uart中从串口和云端接收数据处理的函数重新命名
5.将command.py文件改为command_mode.py文件、将modbus.py文件改为modbus_mode.py文件
2022-05-06 19:47:27 +08:00

37 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from usr.modules.common import Singleton
class ChannelTransfer(Singleton):
def __init__(self, woke_mode, channels_conf):
# channel_dict字典中key值是云通道序号”1“v值是不同的云配置
self.cloud_channel_dict = dict()
# cloud_object_dict字典中key值是云通道序号”1“v值是不同的云对象
self.cloud_object_dict = dict()
# serial_channel_dict字典中每个串口号对应一个数组数组中记录着串口号对应的云通道序号在command模式下每个串口号可能对应多个云通道其他模式都是一对一
self.serial_channel_dict = dict()
self.init(woke_mode, channels_conf)
def init(self, woke_mode, channels_conf):
# serial_channel_dict字典中每个串口号对应一个数组数组中记录着串口号对应的云通道序号
# 在command模式下每个串口号可能对应多个云通道其他模式都是一对一
if woke_mode == "command":
for cid, channel in channels_conf.items():
serial_id = int(channel.get("serialID"))
if serial_id in self.serial_channel_dict:
self.serial_channel_dict[serial_id].append(cid)
else:
self.serial_channel_dict[serial_id] = [cid]
self.cloud_channel_dict = channels_conf
else:
serv_map = dict()
serial_list = [0, 1, 2]
for cid, channel in channels_conf.items():
serial_id = int(channel.get("serialID"))
if serial_id in serial_list:
serv_map[cid] = channel
self.serial_channel_dict[serial_id] = [cid]
serial_list.remove(serial_id)
else:
continue
self.cloud_channel_dict = serv_map