cec21_converter.py 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. """
  2. @File : cec21_converter.py
  3. @Author: lee
  4. @Date : 2022/8/30/0030 14:42:02
  5. @Desc : CEC21国产单点流速仪解析器
  6. """
  7. from logging_config import cec21_converter as logger
  8. from converter import Converter
  9. from tools.format_value import format_value
  10. class CEC21Converter(Converter):
  11. def __init__(self, name):
  12. self._name = name
  13. def convert(self, config, data):
  14. # 原始data: {'data': b'\x11\x11pval,22.650,-37.896,3.613,11.104,14.158,17.992,70.457,243.563,-8.010,-16.111,11.813,0\r\n'}
  15. # 格式化数据:['\x11\x11pval', '22.658', '-36.617', '11.304', '10.291', '14.330', '17.643', '82.970', '253.655', '-4.965', '-16.930', '11.813', '0\r\n']
  16. # 温度, pitch, roll, X流速, Y流速, 流速, 方位, 流向, 南 - 北向流速,东 - 西向流速,电压,状态
  17. try:
  18. logger.info(f"[{self._name}]原始接收数据: values: {data}")
  19. data = data.decode('utf-8').split(',')
  20. logger.info(f"[{self._name}]decode后数据: values: {data}")
  21. dict = {}
  22. for index in config:
  23. name = 'c' + str(index['serial_number'])
  24. i = int(index['address'])
  25. dict[name] = format_value(index, data[i])
  26. logger.info(f"[{self._name}]返回数据: values: {dict}")
  27. return dict
  28. except Exception as e:
  29. logger.info(f"[{self._name}]:{repr(e)}")
  30. return