#! python3 # -*- encoding: utf-8 -*- ''' @File : Ramses.py @Time : 2023/03/03 11:09:50 @Author : Jim @ Yiwin @Version : 1.0 @Contact : jim@yi-win.com @Desc : @para : 23 ..07 .... 06 05 04 03 02 01 00 ip信息不包含 ''' import struct import numpy as np from pathlib import Path from tools.mylogger import log from myconfig import RamsesAWRAMS, RamsesSURFACE, RamsesPROFILE, DeviceType class Ramses(object): def __init__(self,): """ @description :处理Ramses的数据标定 Hex -- realWavelength Intensity @param : 23 ..07 .... 06 05 04 03 02 01 00 ip信息不包含 @Returns : realWavelength Intensity """ self.buf = b'' self.it = None self.light_int = None # 未标定的整数值 self.spectrum = None # 光谱强度 # self.current_buf = "" # self.current_buf_seq = 0 # self.current_it_int = {"it": 0, "light_int": []} # 积分时间及换算的整数值 # self.res = {"wavelength": [], "light": []} self.cal_cfg = {} # self.current_cal = {} # 当前传感器的序列号 pass def setBuf(self, buf: bytes): self.buf = buf pass def setCalCfg(self, d: dict): self.cal_cfg = d pass def getRealWavelength(self, d: dict): self.cal_cfg = d pass def getSpectrum(self): return self.spectrum def resetPara(self, ): self.buf = b'' self.it = None self.light_int = None self.spectrum = None # 光谱强度 self.cal_cfg = {} pass def resetItSpectrum(self, ): self.it = None self.spectrum = None # 光谱强度 pass def printPara(self, ): print(f"**************Ramses printPara*******************") print(f"{self.buf}") print(f"{self.cal_cfg}") print(f"{self.it}") print(f"{self.light_int}") print(f"{self.spectrum}") print(f"**************Ramses printPara*******************") pass def dealBuf(self, ip_included:bool=False): """多个传感器的数据处理, 头部是否包含Ip帧的信息""" log.info(f" dealBuf ", __name__) res = {} len_ = len(self.buf) if len_ < 576: return if ip_included: self.buf = self.buf[26:] len_ = len_ - 26 if len_ % 576 != 0: return for i in range(int(len_/576)): res.update({i+1: {}}) temp_buf = self.buf[7:71] + self.buf[79:143] + \ self.buf[151:215] + self.buf[223:287] + \ self.buf[295:359] + self.buf[367:431] + \ self.buf[439:503] + self.buf[511:575] self.ConvertAndCalibrate( temp_buf ) # print(len(temp_buf)) temp = self.__ConvertBytesToInt(temp_buf) res.update( { i+1: temp } ) # print(res) pass def ConvertAndCalibrate(self,) -> None: log.debug(f" ConvertAndCalibrate ", __name__) temp = self.__ConvertBytesToInt( ) self.__CalibrateSpectrumData( ) pass # 转换一个传感器的部分 def __ConvertBytesToInt(self ) -> None: res = {} d = [] # List [ Tuple[ it:int, sing_set:tuple[int] ] ] self.it = 2 << int(self.buf[1]) # integrated time self.light_int = struct.unpack( "