Ramses 算法修正 ip

server
esea_info 3 years ago
parent ea9338cac9
commit d1d65c7580
  1. 133
      Ramses.py
  2. 22
      awrams.py
  3. 6
      data/2022/8/17/17/2022_08_17_12_20_13.csv
  4. 0
      data/2022/8/17/51/0.bin
  5. 0
      data/2022/8/17/51/1.bin
  6. 0
      data/2022/8/17/51/2.bin
  7. 6
      data/2022/8/17/51/2022_08_17_12_20_13.csv
  8. 0
      data/2022/8/17/51/2022_08_17_12_20_13_info.txt
  9. 0
      data/2022/8/17/51/3.bin
  10. 0
      data/2022/8/17/51/4.bin
  11. 0
      data/2022/8/17/51/info.bin
  12. 0
      data/2022/8/17/51/pic.jpg
  13. 3
      tcp_awrams.py

@ -28,9 +28,12 @@ class Ramses(object):
@Returns : realWavelength Intensity @Returns : realWavelength Intensity
""" """
self.buf = b'' self.buf = b''
self.mode = 0 # 默认0 空气中,1:水中
self.buf_ip = b''
self.it = None self.it = None
self.light_int = None # 未标定的整数值 self.light_int = None # 未标定的整数值
self.spectrum = None # 光谱强度 self.spectrum = None # 光谱强度
self.ip = []
# self.current_buf = "" # self.current_buf = ""
# self.current_buf_seq = 0 # self.current_buf_seq = 0
# self.current_it_int = {"it": 0, "light_int": []} # 积分时间及换算的整数值 # self.current_it_int = {"it": 0, "light_int": []} # 积分时间及换算的整数值
@ -39,10 +42,14 @@ class Ramses(object):
# self.current_cal = {} # 当前传感器的序列号 # self.current_cal = {} # 当前传感器的序列号
pass pass
def setBuf(self, buf: bytes): def setBuf( self, buf: bytes ):
self.buf = buf self.buf = buf
pass pass
def setMode( self, mode = 1 ):
self.mode = mode
pass
def setCalCfg(self, d: dict): def setCalCfg(self, d: dict):
self.cal_cfg = d self.cal_cfg = d
pass pass
@ -86,27 +93,31 @@ class Ramses(object):
if len_ < 576: if len_ < 576:
return return
if ip_included: if ip_included:
self.buf_ip = self.buf[:26]
self.ip = self.decode_ip_buf(self.buf_ip, self.cal_cfg)
self.buf = self.buf[26:] self.buf = self.buf[26:]
len_ = len_ - 26 len_ = len_ - 26
if len_ % 576 != 0: if len_ % 576 != 0:
return return
for i in range(int(len_/576)): for i in range( int(len_/576) ):
res.update({i+1: {}}) res.update( {i+1: {}} )
temp_buf = self.buf[7:71] + self.buf[79:143] + \ temp_buf = self.buf[7:71] + self.buf[79:143] + \
self.buf[151:215] + self.buf[223:287] + \ self.buf[151:215] + self.buf[223:287] + \
self.buf[295:359] + self.buf[367:431] + \ self.buf[295:359] + self.buf[367:431] + \
self.buf[439:503] + self.buf[511:575] self.buf[439:503] + self.buf[511:575]
self.ConvertAndCalibrate( temp_buf ) self.ConvertAndCalibrate( temp_buf )
# print(len(temp_buf)) # print(len(temp_buf))
temp = self.__ConvertBytesToInt(temp_buf) # temp = self.__ConvertBytesToInt(temp_buf)
res.update( { i+1: temp } ) # res.update( { i+1: temp } )
# print(res) # print(res)
pass pass
def ConvertAndCalibrate(self,) -> None: def ConvertAndCalibrate(self,) -> None:
'''单个成功数据转化 标定'''
log.debug(f" ConvertAndCalibrate ", __name__) log.debug(f" ConvertAndCalibrate ", __name__)
temp = self.__ConvertBytesToInt( ) temp = self.__ConvertBytesToInt( )
# print( f"int : {self.it} {temp}" )
self.__CalibrateSpectrumData( ) self.__CalibrateSpectrumData( )
pass pass
@ -114,30 +125,40 @@ class Ramses(object):
def __ConvertBytesToInt(self ) -> None: def __ConvertBytesToInt(self ) -> None:
res = {} res = {}
d = [] # List [ Tuple[ it:int, sing_set:tuple[int] ] ] d = [] # List [ Tuple[ it:int, sing_set:tuple[int] ] ]
self.it = 2 << int(self.buf[1]) # integrated time print(f" ================= ")
print(f" {self.buf.hex()} ")
# self.it = 2 << int(self.buf[1]) # integrated time
self.it = 2 << int(self.buf[0]) # integrated time
self.light_int = struct.unpack( self.light_int = struct.unpack(
"<HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \ "<HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \ HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \ HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH \
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", self.buf[2:]) HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH", self.buf[2:])
print( self.light_int )
def __CalibrateSpectrumData(self ,) : def __CalibrateSpectrumData(self ,) :
t0 = 8092 t0 = 8092
log.debug(f" __CalibrateSpectrumData ..... ", __name__) log.debug(f" __CalibrateSpectrumData ..... ", __name__)
raw = np.asarray(self.light_int, dtype=float) raw = np.asarray(self.light_int, dtype=float)
B0 = np.asarray(self.cal_cfg["b0"], dtype=float) B0 = np.asarray(self.cal_cfg["b0"], dtype=float)
B1 = np.asarray(self.cal_cfg["b1"], dtype=float) B1 = np.asarray(self.cal_cfg["b1"], dtype=float)
Mn = raw/65535 Mn = raw/65535
Bn = B0 + B1 * (self.it/t0) Bn = B0 + B1 * ( self.it/t0 )
Cn = Mn-Bn Cn = Mn-Bn
Offset = self.getOffset( Offset = self.getOffset(
Cn, int(self.cal_cfg['DarkPixelStart']), int(self.cal_cfg['DarkPixelStop'])) Cn, int(self.cal_cfg['DarkPixelStart']), int(self.cal_cfg['DarkPixelStop']))
Dn = Cn-Offset Dn = Cn - Offset
En = Dn * (t0/self.it) En = Dn * ( t0/self.it )
Fn = En/np.asarray(self.cal_cfg["cal"], dtype=float) # 空气或水中的标定文件 if self.mode == 0:
Fn = En/np.asarray(self.cal_cfg["cal"], dtype=float) # 空气的标定文件
else:
Fn = En/np.asarray(self.cal_cfg["calaq"], dtype=float) # 水中的标定文件
# Fn = En/np.asarray(self.cal_cfg["cal"], dtype=float) # 空气或水中的标定文件
self.spectrum = Fn self.spectrum = Fn
# print(self.spectrum)
def getOffset(self, data: np.ndarray, start: int, stop: int): def getOffset(self, data: np.ndarray, start: int, stop: int):
@ -145,20 +166,86 @@ class Ramses(object):
for i in range(start-1, stop, 1): for i in range(start-1, stop, 1):
ret = ret + data[i] ret = ret + data[i]
return ret / (stop - start + 1) return ret / (stop - start + 1)
pass
def removeMask(self, buf:bytes ) -> bytes:
'''去除遮罩 0x64 0x65 0x66 0x67'''
ret = b''
flag = False
blen = len(buf)
for i in range(blen):
if flag == False and buf[i] == 64 :
flag = True
continue
if flag == False and buf[i] != 64 :
ret = ret + buf[i].to_bytes( 1, byteorder = 'big' )
continue
if flag == True and buf[i] == 100:
ret = ret + b'\x40'
flag = False
continue
if flag == True and buf[i] == 101:
ret = ret + b'\x23'
flag = False
continue
if flag == True and buf[i] == 102:
ret = ret + b'\x11'
flag = False
continue
if flag == True and buf[i] == 103:
ret = ret + b'\x13'
flag = False
continue
return ret
pass
def decode_ip_buf(self, buf, ip_cal:dict):
tmpbuf = buf
if len(tmpbuf) ==26 and tmpbuf[0] == 0x13:
tmpbuf = tmpbuf[2:]
Incl_XGain = float(ip_cal['Incl_XOffset'] )
Incl_XOffset = float(ip_cal['Incl_XOffset'] )
Incl_YGain = float(ip_cal['Incl_YGain'] )
Incl_YOffset = float(ip_cal['Incl_YOffset'] )
Incl_KRef = float(ip_cal['Incl_KRef'] )
Press_Sens_mV_bar_1mA = float(ip_cal['Press_Sens_mV_bar_1mA'] )
Incl_KBG = float(ip_cal['Incl_KBG'] )
Press_Sens_mV_bar_4mA = float(ip_cal['Press_Sens_mV_bar_4mA'] )
Press_Gain = float(ip_cal['Press_Gain'] )
Press_Surface_bar = float(ip_cal['Press_Surface_bar'] )
# def read_bin(self,fpath: Path):
# log.debug(f" readbin: ", __name__, "", "" ) ip_info = struct.unpack("<BBBBBBBBBBBBBBBBBBBBBBBB", buf)
# ret = None byte11 = ip_info[11]
# if not fpath.exists() : byte12 = ip_info[12]
# log.info(f"not find file: {fpath} ") byte13 = ip_info[13]
# return ret byte14 = ip_info[14]
# with open(fpath, 'rb') as file: byte15 = ip_info[15]
# ret = file.read() byte16 = ip_info[16]
# return ret byte17 = ip_info[17]
# log.debug(f" readbin: {ret} ", __name__, "", "" ) byte18 = ip_info[18]
# return ret byte19 = ip_info[19]
# pass byte20 = ip_info[20]
byte21 = ip_info[21]
byte22 = ip_info[22]
X = (byte11 -Incl_XOffset) / Incl_XGain # 单位 度
Y = (byte12 - Incl_YOffset ) / Incl_YGain # 单位 度
npress = byte14 *256 + byte13
nbg = byte18 * 256 + byte17
nrefh = byte20 * 256 + byte19
nrefl = byte22 * 256 + byte21
noffset = nrefl - ( Incl_KRef * (nrefh-nrefl))
VPress = Incl_KBG * (npress-noffset) / (nbg- noffset) #电压值
press_sens = Press_Sens_mV_bar_4mA
if press_sens <= 0:
press_sens = 4* Press_Sens_mV_bar_1mA
p_bar = 1000 * VPress / (press_sens * Press_Gain )
press_delta = p_bar - 1.021
depth_m = press_delta * 10
return [depth_m,X,Y]
pass
if __name__ == "__main__": if __name__ == "__main__":

@ -634,25 +634,29 @@ class AWRAMS(object):
# res_before_avg = [] # res_before_avg = []
self.clearRes() # 清空数据 self.clearRes() # 清空数据
while True: while True:
## 以下代码已经处理了 ip的数据帧
if not self.hhb.decode_one_group_handheld() : if not self.hhb.decode_one_group_handheld() :
break # 清空数据 break # 清空数据
res = {} res = {}
buf = self.hhb.one_group_data[26:] ## 上方代码已经处理了 ip的数据帧
for i in range(1,4,1): buf = self.hhb.one_group_data
temp_buf = buf[7:71] + buf[79:143] + \ # buf = self.hhb.one_group_data[26:]
buf[151:215] + buf[223:287] + \ for i in range( 1, 4, 1 ):
buf[295:359] + buf[367:431] + \ site = (i-1) * 576
buf[439:503] + buf[511:575] temp_buf = buf[7+site:71+site] + buf[79+site:143+site] + \
buf[151+site:215+site] + buf[223+site:287+site] + \
buf[295+site:359+site] + buf[367+site:431+site] + \
buf[439+site:503+site] + buf[511+site:575+site]
# Ramses类 标定处理,设置buf 标定文件 # Ramses类 标定处理,设置buf 标定文件
self.ramses.setBuf(temp_buf) self.ramses.setBuf(temp_buf)
func = self.getFuncBySeq(i) func = self.getFuncBySeq(i)
cfg = self.getCfgByFunc( func) cfg = self.getCfgByFunc( func)
self.ramses.setCalCfg(cfg) self.ramses.setCalCfg(cfg)
self.ramses.resetItSpectrum() self.ramses.resetItSpectrum()
self.ramses.ConvertAndCalibrate() self.ramses.ConvertAndCalibrate()
res.update({ func : self.ramses.spectrum }) res.update( { func : self.ramses.spectrum } )
self.intensity_before_avg.append( res ) self.intensity_before_avg.append( res )
pass pass

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

@ -140,11 +140,10 @@ if __name__ == '__main__':
ta.send_pic() ta.send_pic()
time.sleep( 2) time.sleep( 20)
except Exception as e: except Exception as e:
print(e) print(e)
ta.disconnect ta.disconnect

Loading…
Cancel
Save