sonar_command_tcp_once.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #-*-coding=utf-8-*-
  2. import socket
  3. import threading
  4. import construct as c
  5. import time
  6. import binascii
  7. import struct
  8. import datetime
  9. from multiprocessing import Process
  10. from memory_storage import MemoryStorage
  11. from logging_config import tcp_connector as logger
  12. from hard_disk_storage import HardDiskStorage
  13. hard_disk_db = HardDiskStorage()
  14. SERVER_ADDRESS = ('172.16.3.0', 50224)
  15. #SERVER_ADDRESS = ('172.16.3.21', 50224)
  16. status_data = c.Struct(
  17. magic_number=c.Int32ul, #固定不便,可能用于区分不同设备
  18. length_mm=c.Int32ul, # 数据包长度
  19. data_head=c.Int32ul,
  20. data_head2=c.Int32ul,
  21. pack_data = c.Bytes(c.this.length_mm-12),
  22. data_wei=c.Int32ul,
  23. )
  24. command_data = c.Struct(
  25. magic_number=c.Int32ul, #固定不便,可能用于区分不同设备
  26. length_mm=c.Int32ul, # 数据包长度
  27. data_head=c.Int32ul,
  28. data_head2=c.Int32ul,
  29. data_head3=c.Int32ul,
  30. pack_data = c.Int32ul,
  31. data_wei=c.Int32ul,
  32. )
  33. def get_sonar_conf():
  34. sql = "select * from sonar_settings;"
  35. result = hard_disk_db.execute_sql(sql,None)[0]
  36. return result
  37. # 客户端类定义
  38. class Client(Process):#继承Process类
  39. def __init__(self):
  40. super(Client, self).__init__()
  41. self.__sock = None
  42. self.__connected = False
  43. self.__stopped = False
  44. self.__ip = SERVER_ADDRESS[0]
  45. self.__port = SERVER_ADDRESS[1]
  46. self.status_list = {}
  47. self.status_len = 248 #34
  48. #self.status_len = 252 #62
  49. self.open_key = None
  50. self.command_head = '0409efbe1400000010000200'
  51. self.set_command_dict = {}
  52. self.open_command = None
  53. self.close_command = None
  54. self.range_command_H_s = None
  55. self.range_command_V_s = None
  56. self.range_command_H_b = None
  57. self.range_command_V_b = None
  58. self.set_flag = True
  59. self.redis_db = None
  60. self.send_set_command = 0
  61. self.range_s = 10
  62. self.range_b = 24
  63. self.begin = True
  64. self.begin2 = True
  65. self.ahrs_status = True
  66. def open(self):
  67. self.__stopped = False
  68. self.start()
  69. def run(self):
  70. self.__connect()
  71. self.__connected = True
  72. self.redis_db = MemoryStorage()
  73. # t = threading.Thread(target=self.receive_data)
  74. # t.start()
  75. while True:
  76. sonar_conf = get_sonar_conf()
  77. self.range_b = sonar_conf['range_big']
  78. if len(self.set_command_dict) == 0:
  79. begin_data = '3f08efbe0200000028d7'
  80. get_status_data = '0409efbe0400000000000400'
  81. begin_data_1 = '0409efbe1400000010000100305941378f9a5704236641372659c843'
  82. begin_data_2 = '0409efbe1400000010000100305941378f9a57042366413736594036'
  83. self.send_command(begin_data)
  84. self.send_command(get_status_data)
  85. self.send_command(begin_data_1)
  86. self.send_command(begin_data_2)
  87. self.receive_data()
  88. time.sleep(1)
  89. # if self.begin == True:
  90. #
  91. # begin_data_2 = '0409efbe1400000010000100305941378f9a57042366413736594036'
  92. # self.send_command(get_status_data)
  93. # self.send_command(begin_data_1)
  94. # self.send_command(begin_data_1)
  95. # self.send_command(begin_data_2)
  96. # self.begin = False
  97. if self.set_flag == True:
  98. for command in self.set_command_dict.values():
  99. self.send_command(command)
  100. self.send_command(self.open_command)
  101. #print('send_command', self.open_key)
  102. time.sleep(0.2)
  103. self.send_set_command = self.send_set_command + 1
  104. if self.send_set_command > 2:
  105. self.set_flag = False
  106. self.send_set_command = 0
  107. if self.redis_db.get_value(['range'])['range'] == 'big' and self.redis_db.get_value(['sonar_status'])['sonar_status'] != 'close':
  108. if self.range_command_H_b != None and self.range_command_V_b != None:
  109. self.send_command(self.range_command_H_b)
  110. self.send_command(self.range_command_V_b)
  111. elif self.redis_db.get_value(['range'])['range'] == 'small' and self.redis_db.get_value(['sonar_status'])['sonar_status'] != 'close':
  112. if self.range_command_H_s != None and self.range_command_V_s != None:
  113. self.send_command(self.range_command_H_s)
  114. self.send_command(self.range_command_V_s)
  115. if self.redis_db.get_value(['sonar_open'])['sonar_open'] == 'open' and self.redis_db.get_value(['sonar_status'])['sonar_status'] != 'open':
  116. if self.open_command != None:
  117. self.send_command(self.open_command)
  118. print('sonar_open',self.open_command,self.redis_db.get_value(['sonar_status'])['sonar_status'])
  119. elif self.redis_db.get_value(['sonar_open'])['sonar_open'] == 'close' and self.redis_db.get_value(['sonar_status'])['sonar_status'] != 'close':
  120. if self.close_command != None:
  121. self.send_command(self.close_command)
  122. print('sonar_close',2222222222222222)
  123. heart_data = '0409efbe1400000010000100305941378f9a5704236641372659c843'
  124. self.send_command(heart_data)
  125. begin_data_2 = '0409efbe1400000010000100305941378f9a57042366413736594036'
  126. self.send_command(begin_data_2)
  127. #print('send_command', heart_data)
  128. time.sleep(1)
  129. def send_command(self, command):
  130. if self.__connected:
  131. try:
  132. send_data = bytes.fromhex(command)
  133. self.__sock.send(send_data)
  134. except Exception as e:
  135. time.sleep(5)
  136. self.__reconnect()
  137. # logger.info(f'Send command to [{self.name}]:[{self.__ip}]:[{self.__port}] error:{e}')
  138. else:
  139. self.__reconnect()
  140. # 建立socket连接
  141. def __connect(self):
  142. if self.__sock:
  143. self.__sock.close()
  144. self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  145. self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # 允许重用本地地址和端口
  146. self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳维护
  147. self.__sock.settimeout(10) # 设置超时时间3mins
  148. try:
  149. self.__sock.connect((self.__ip, self.__port))
  150. logger.info(f'Connect to [{self.name}]:[{self.__ip}]:[{self.__port}] success !')
  151. self.__connected = True
  152. except Exception as e:
  153. logger.info(f'Connect to [{self.name}]:[{self.__ip}]:[{self.__port}] failed:{e} !!!')
  154. self.__connected = False
  155. self.__reconnect()
  156. def __reconnect(self):
  157. while True:
  158. try:
  159. if self.__sock:
  160. self.__sock.close()
  161. self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  162. self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  163. self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # 在客户端开启心跳维护
  164. self.__sock.settimeout(10) # 设置超时时间,单位:秒
  165. self.__sock.connect((self.__ip, self.__port))
  166. self.set_command_dict = {}
  167. self.__connected = True
  168. logger.info(f'Reconnect to [{self.name}]:[{self.__ip}]:[{self.__port}] success !')
  169. break
  170. except Exception as e:
  171. logger.info(f'Reconnect to [{self.name}]:[{self.__ip}]:[{self.__port}] failed:{e} !!! Continue reconnect in 5s..')
  172. self.__connected = False
  173. self.set_command_dict = {}
  174. time.sleep(5)
  175. def get_str_hex(self,data,offset):
  176. data = int(data, 16)
  177. data = (data + offset) & 0xff
  178. data = struct.pack("=B", data).hex()
  179. return data
  180. def get_open_command(self,command_head,str_key,mode):
  181. a = str_key[0:2]
  182. b = str_key[2:4]
  183. c = str_key[4:6]
  184. d = str_key[6:8]
  185. bcd = str_key[2:8]
  186. body1 = self.get_str_hex(a, 0x0c) + bcd
  187. if mode == 'open':
  188. body2 = a + self.get_str_hex(b, 0x33) + self.get_str_hex(c, -0x16) + self.get_str_hex(d, 0x01)
  189. elif mode == 'close':
  190. body2 = self.get_str_hex(a, 0x01) + self.get_str_hex(b, 0x33) + self.get_str_hex(c, -0x16) + self.get_str_hex(d, 0x01)
  191. body3 = self.get_str_hex(a, 0x01) + bcd
  192. open_command = command_head + str_key + body1 + body2 + body3
  193. return open_command
  194. def get_noise_command(self,command_head,str_key,mode):
  195. a = str_key[0:2]
  196. bcd = str_key[2:8]
  197. body1 = self.get_str_hex(a, 0x04) + bcd
  198. body2 = self.get_str_hex(a, 0x09) + bcd
  199. if mode == 'close':
  200. body3 = self.get_str_hex(a, 0x00) + bcd
  201. elif mode == 'low':
  202. body3 = self.get_str_hex(a, 0x01) + bcd
  203. elif mode == 'med':
  204. body3 = self.get_str_hex(a, 0x02) + bcd
  205. elif mode == 'hig':
  206. body3 = self.get_str_hex(a, 0x03) + bcd
  207. body4 = self.get_str_hex(a, 0x04) + bcd
  208. command = command_head + body1 + body2 + body3 + body4
  209. return command
  210. # 视角和下扫模式可用
  211. def get_tvg_command(self,command_head,str_key,mode):
  212. a = str_key[0:2]
  213. bcd = str_key[2:8]
  214. body1 = self.get_str_hex(a, 0x02) + bcd
  215. body2 = self.get_str_hex(a, 0x30) + bcd
  216. if mode == 'close':
  217. body3 = self.get_str_hex(a, 0x00) + bcd
  218. elif mode == 'low':
  219. body3 = self.get_str_hex(a, 0x01) + bcd
  220. elif mode == 'med':
  221. body3 = self.get_str_hex(a, 0x02) + bcd
  222. elif mode == 'hig':
  223. body3 = self.get_str_hex(a, 0x03) + bcd
  224. body4 = self.get_str_hex(a, 0x04) + bcd
  225. command = command_head + body1 + body2 + body3 + body4
  226. return command
  227. def get_tvg_command_forward(self,command_head,str_key,mode):
  228. a = str_key[0:2]
  229. bcd = str_key[2:8]
  230. body1 = self.get_str_hex(a, 0x04) + bcd
  231. body2 = self.get_str_hex(a, 0x30) + bcd
  232. if mode == 'close':
  233. body3 = self.get_str_hex(a, 0x00) + bcd
  234. elif mode == 'low':
  235. body3 = self.get_str_hex(a, 0x01) + bcd
  236. elif mode == 'med':
  237. body3 = self.get_str_hex(a, 0x02) + bcd
  238. elif mode == 'hig':
  239. body3 = self.get_str_hex(a, 0x03) + bcd
  240. body4 = self.get_str_hex(a, 0x04) + bcd
  241. command = command_head + body1 + body2 + body3 + body4
  242. return command
  243. def ghosting_suppression(self,command_head,str_key,mode):
  244. a = str_key[0:2]
  245. bcd = str_key[2:8]
  246. body1 = self.get_str_hex(a, 0x04) + bcd
  247. body2 = self.get_str_hex(a, 0x38) + bcd
  248. if mode == 'close':
  249. body3 = self.get_str_hex(a, 0x00) + bcd
  250. elif mode == 'low':
  251. body3 = self.get_str_hex(a, 0x01) + bcd
  252. elif mode == 'med':
  253. body3 = self.get_str_hex(a, 0x02) + bcd
  254. elif mode == 'hig':
  255. body3 = self.get_str_hex(a, 0x03) + bcd
  256. elif mode == 'auto':
  257. body3 = self.get_str_hex(a, 0x04) + bcd
  258. body4 = self.get_str_hex(a, 0x04) + bcd
  259. command = command_head + body1 + body2 + body3 + body4
  260. return command
  261. def get_installation_command(self,command_head,str_key,mode):
  262. a = str_key[0:2]
  263. b = str_key[2:4]
  264. c = str_key[4:6]
  265. d = str_key[6:8]
  266. bcd = str_key[2:8]
  267. body1 = str_key
  268. body2 = self.get_str_hex(a, 0x2f) + bcd
  269. if mode == 'under':
  270. body3 = self.get_str_hex(a, 0x04) + bcd
  271. elif mode == 'forward':
  272. body3 = self.get_str_hex(a, 0x04) + b + self.get_str_hex(c, 0x01) + d
  273. elif mode == 'perspective':
  274. body3 = self.get_str_hex(a, 0x10) + b + self.get_str_hex(c, 0x02) + d
  275. elif mode == 'auto':
  276. body3 = self.get_str_hex(a, 0x10) + b + self.get_str_hex(c, 0x01) + self.get_str_hex(d, 0x80)
  277. body4 = self.get_str_hex(a, 0x04) + bcd
  278. command = command_head + body1 + body2 + body3 + body4
  279. return command
  280. def get_installation_depth_0m_command(self,command_head,str_key):
  281. a = str_key[0:2]
  282. bcd = str_key[2:8]
  283. body1 = self.get_str_hex(a, 0x04) + bcd
  284. body2 = self.get_str_hex(a, 0x19) + bcd
  285. body3 = str_key
  286. body4 = self.get_str_hex(a, 0x04) + bcd
  287. command = command_head + body1 + body2 + body3 + body4
  288. return command
  289. def get_ahrs_command(self,command_head,str_key,mode):
  290. a = str_key[0:2]
  291. b = str_key[2:4]
  292. c = str_key[4:6]
  293. d = str_key[6:8]
  294. bcd = str_key[2:8]
  295. bcd_2 = self.get_str_hex(b, 0x33) + self.get_str_hex(c, 0xea) + self.get_str_hex(d, 0x01)
  296. body1 = str_key
  297. body2 = self.get_str_hex(a, 0x1e) + bcd
  298. if mode == 'open':
  299. body3 = self.get_str_hex(a, 0x01) + bcd_2
  300. elif mode == 'close':
  301. body3 = a + bcd_2
  302. body4 = self.get_str_hex(a, 0x01) + bcd
  303. command = command_head + body1 + body2 + body3 + body4
  304. return command
  305. def get_flip_command(self,command_head,str_key,mode):
  306. a = str_key[0:2]
  307. b = str_key[2:4]
  308. c = str_key[4:6]
  309. d = str_key[6:8]
  310. bcd = str_key[2:8]
  311. bcd_2 = self.get_str_hex(b, 0x33) + self.get_str_hex(c, 0xea) + self.get_str_hex(d, 0x01)
  312. body1 = str_key
  313. body2 = self.get_str_hex(a, 0x18) + bcd
  314. if mode == 'open':
  315. body3 = self.get_str_hex(a, 0x01) + bcd_2
  316. elif mode == 'close':
  317. body3 = a + bcd_2
  318. body4 = self.get_str_hex(a, 0x01) + bcd
  319. command = command_head + body1 + body2 + body3 + body4
  320. return command
  321. def get_pitch_command(self,command_head,str_key):
  322. a = str_key[0:2]
  323. b = str_key[2:4]
  324. c = str_key[4:6]
  325. d = str_key[6:8]
  326. bcd = str_key[2:8]
  327. body1 = self.get_str_hex(a, 0x04) + bcd
  328. body2 = self.get_str_hex(a, 0x17) + bcd
  329. body3 = self.get_str_hex(a, 0x09) + self.get_str_hex(b, 0x98) + self.get_str_hex(c, 0xc4) + self.get_str_hex(d, 0x3e)
  330. body4 = self.get_str_hex(a, 0x04) + bcd
  331. command = command_head + body1 + body2 + body3 + body4
  332. return command
  333. def get_focus_command(self,command_head,str_key,mode):
  334. a = str_key[0:2]
  335. bcd = str_key[2:8]
  336. body1 = str_key
  337. body2 = self.get_str_hex(a, 0x33) + bcd
  338. if mode == 'salt':
  339. body3 = self.get_str_hex(a, 0x01) + bcd
  340. elif mode == 'fresh':
  341. body3 = self.get_str_hex(a, 0x02) + bcd
  342. body4 = self.get_str_hex(a, 0x04) + bcd
  343. command = command_head + body1 + body2 + body3 + body4
  344. return command
  345. def get_range_command(self,command_head,str_key,mode,range):
  346. range_list = [3,4,5,6,7,8,9,10,12,14,16,18,20,22,24,26,28,30]
  347. offset_list = [0x40,0x80,0xa0,0xc0,0xe0,0x00,0x10,0x20,0x40,0x60,0x80,0x90,0xa0,0xb0,0xc0,0xd0,0xe0,0xf0]
  348. #print(len(range_list),len(offset_list))
  349. if range in range_list:
  350. index = range_list.index(range)
  351. offset = offset_list[index]
  352. a = str_key[0:2]
  353. bcd = str_key[2:8]
  354. ab = str_key[0:4]
  355. c = str_key[4:6]
  356. d = str_key[6:8]
  357. range_c = self.get_str_hex(c, offset)
  358. if range > 7:
  359. range_d = self.get_str_hex(d, 0x41)
  360. else:
  361. range_d = self.get_str_hex(d, 0x40)
  362. body1 = self.get_str_hex(a, 0x04) + bcd
  363. if mode == 'H':
  364. body2 = self.get_str_hex(a, 0x24) + bcd
  365. elif mode == 'V':
  366. body2 = self.get_str_hex(a, 0x22) + bcd
  367. body3 = ab + range_c + range_d
  368. body4 = self.get_str_hex(a, 0x04) + bcd
  369. command = command_head + body1 + body2 + body3 + body4
  370. return command
  371. else:
  372. return None
  373. # 接收服务器发送的数据
  374. def receive_data(self):
  375. try:
  376. data = self.__sock.recv(self.status_len)
  377. except socket.timeout as e:
  378. logger.error(f"{self.name}: {e}")
  379. time.sleep(5)
  380. self.__reconnect()
  381. print('recv',e)
  382. except Exception as e:
  383. logger.error(f"{self.name}: {e}")
  384. time.sleep(5)
  385. self.__reconnect()
  386. if len(data) == self.status_len:
  387. self.open_key = data[20:24].hex()
  388. print(self.open_key)
  389. #if len(self.set_command_dict) < 1:
  390. self.open_command = self.get_open_command(self.command_head, self.open_key, 'open')
  391. self.close_command = self.get_open_command(self.command_head,self.open_key, 'close')
  392. self.range_command_H_s = self.get_range_command(self.command_head, self.open_key,'H',self.range_s)
  393. self.range_command_V_s = self.get_range_command(self.command_head, self.open_key,'V',self.range_s)
  394. self.range_command_H_b = self.get_range_command(self.command_head, self.open_key,'H',self.range_b)
  395. self.range_command_V_b = self.get_range_command(self.command_head, self.open_key,'V',self.range_b)
  396. self.set_command_dict['forward'] = self.get_installation_command(self.command_head, self.open_key, 'forward')
  397. self.set_command_dict['noise'] = self.get_noise_command(self.command_head,self.open_key,'close')
  398. self.set_command_dict['tvg_close'] = self.get_tvg_command_forward(self.command_head, self.open_key, 'close')
  399. #self.set_command_dict['tvg_hig'] = self.get_tvg_command_forward(self.command_head, self.open_key, 'hig')
  400. self.set_command_dict['ghosting_suppression'] = self.ghosting_suppression(self.command_head, self.open_key, 'close')
  401. #self.set_command_dict['under'] = self.get_installation_command(self.command_head, self.open_key, 'under')
  402. self.set_command_dict['depth_0m'] = self.get_installation_depth_0m_command(self.command_head, self.open_key)
  403. self.set_command_dict['focus'] = self.get_focus_command(self.command_head, self.open_key, 'fresh')
  404. if self.ahrs_status == True:
  405. self.set_command_dict['ahrs_open'] = self.get_ahrs_command(self.command_head, self.open_key, 'open')
  406. else:
  407. self.set_command_dict['ahrs_close'] = self.get_ahrs_command(self.command_head, self.open_key, 'close')
  408. self.set_command_dict['flip_close'] = self.get_flip_command(self.command_head, self.open_key, 'close')
  409. #self.set_command_dict['flip_open'] = self.get_ahrs_command(self.command_head, self.open_key, 'close'
  410. self.set_command_dict['pitch'] = self.get_pitch_command(self.command_head, self.open_key)
  411. noise_close = self.get_noise_command(self.command_head,self.open_key,'close')
  412. noise_low = self.get_noise_command(self.command_head,self.open_key,'low')
  413. noise_med = self.get_noise_command(self.command_head,self.open_key,'med')
  414. noise_hig = self.get_noise_command(self.command_head,self.open_key,'hig')
  415. tvg_close = self.get_tvg_command_forward(self.command_head, self.open_key, 'close')
  416. tvg_low = self.get_tvg_command_forward(self.command_head, self.open_key, 'low')
  417. tvg_med = self.get_tvg_command_forward(self.command_head, self.open_key, 'med')
  418. tvg_hig = self.get_tvg_command_forward(self.command_head, self.open_key, 'hig')
  419. range_H_3 = self.get_range_command(self.command_head, self.open_key,'H',3)
  420. range_H_4 = self.get_range_command(self.command_head, self.open_key,'H',4)
  421. range_H_5 = self.get_range_command(self.command_head, self.open_key,'H',5)
  422. range_H_6 = self.get_range_command(self.command_head, self.open_key,'H',6)
  423. range_H_7 = self.get_range_command(self.command_head, self.open_key,'H',7)
  424. range_H_8 = self.get_range_command(self.command_head, self.open_key,'H',8)
  425. range_H_9 = self.get_range_command(self.command_head, self.open_key,'H',9)
  426. range_H_10 = self.get_range_command(self.command_head, self.open_key,'H',10)
  427. range_H_12 = self.get_range_command(self.command_head, self.open_key,'H',12)
  428. range_H_14 = self.get_range_command(self.command_head, self.open_key,'H',14)
  429. range_H_16 = self.get_range_command(self.command_head, self.open_key,'H',16)
  430. range_H_18 = self.get_range_command(self.command_head, self.open_key,'H',18)
  431. range_H_20 = self.get_range_command(self.command_head, self.open_key,'H',20)
  432. range_H_22 = self.get_range_command(self.command_head, self.open_key,'H',22)
  433. range_H_24 = self.get_range_command(self.command_head, self.open_key,'H',24)
  434. range_H_26 = self.get_range_command(self.command_head, self.open_key,'H',26)
  435. range_H_28 = self.get_range_command(self.command_head, self.open_key,'H',28)
  436. range_H_30 = self.get_range_command(self.command_head, self.open_key,'H',30)
  437. range_V_3 = self.get_range_command(self.command_head, self.open_key,'V',3)
  438. range_V_4 = self.get_range_command(self.command_head, self.open_key,'V',4)
  439. range_V_5 = self.get_range_command(self.command_head, self.open_key,'V',5)
  440. range_V_6 = self.get_range_command(self.command_head, self.open_key,'V',6)
  441. range_V_7 = self.get_range_command(self.command_head, self.open_key,'V',7)
  442. range_V_8 = self.get_range_command(self.command_head, self.open_key,'V',8)
  443. range_V_9 = self.get_range_command(self.command_head, self.open_key,'V',9)
  444. range_V_10 = self.get_range_command(self.command_head, self.open_key,'V',10)
  445. range_V_12 = self.get_range_command(self.command_head, self.open_key,'V',12)
  446. range_V_14 = self.get_range_command(self.command_head, self.open_key,'V',14)
  447. range_V_16 = self.get_range_command(self.command_head, self.open_key,'V',16)
  448. range_V_18 = self.get_range_command(self.command_head, self.open_key,'V',18)
  449. range_V_20 = self.get_range_command(self.command_head, self.open_key,'V',20)
  450. range_V_22 = self.get_range_command(self.command_head, self.open_key,'V',22)
  451. range_V_24 = self.get_range_command(self.command_head, self.open_key,'V',24)
  452. range_V_26 = self.get_range_command(self.command_head, self.open_key,'V',26)
  453. range_V_28 = self.get_range_command(self.command_head, self.open_key,'V',28)
  454. range_V_30 = self.get_range_command(self.command_head, self.open_key,'V',30)
  455. auto = self.get_installation_command(self.command_head, self.open_key,'auto')
  456. under = self.get_installation_command(self.command_head, self.open_key,'under')
  457. forward = self.get_installation_command(self.command_head, self.open_key,'forward')
  458. perspective = self.get_installation_command(self.command_head, self.open_key,'perspective')
  459. depth_0m = self.get_installation_depth_0m_command(self.command_head, self.open_key)
  460. pitch = self.get_pitch_command(self.command_head, self.open_key)
  461. ahrs_open = self.get_ahrs_command(self.command_head, self.open_key,'open')
  462. ahrs_close = self.get_ahrs_command(self.command_head, self.open_key, 'close')
  463. flip_open = self.get_flip_command(self.command_head, self.open_key, 'open')
  464. fiip_close = self.get_flip_command(self.command_head, self.open_key, 'close')
  465. focus_salt = self.get_focus_command(self.command_head, self.open_key, 'salt')
  466. focus_fresh = self.get_focus_command(self.command_head, self.open_key, 'fresh')
  467. ghosting_suppression_close = self.ghosting_suppression(self.command_head, self.open_key, 'close')
  468. ghosting_suppression_low = self.ghosting_suppression(self.command_head, self.open_key, 'low')
  469. ghosting_suppression_med = self.ghosting_suppression(self.command_head, self.open_key, 'med')
  470. ghosting_suppression_hig = self.ghosting_suppression(self.command_head, self.open_key, 'hig')
  471. ghosting_suppression_auto= self.ghosting_suppression(self.command_head, self.open_key, 'auto')
  472. # self.status_list['1']
  473. # print(data.hex(), end='\n')
  474. # if not data:
  475. # break
  476. command = 1
  477. def hex_to_str1(self,s): #s="68656c6c6f"
  478. s=binascii.unhexlify(s) #unhexlify()传入的参数也可以是b'xxxx'(xxxx要符合16进制特征)
  479. print(s.decode('utf-8')) #s的类型是bytes类型,用encode()方法转化为str类型
  480. # 启动客户端
  481. if __name__ == '__main__':
  482. p = Client() # 实例化进程对象
  483. p.start()
  484. # data = '0409efbe140000001000020069e8a9fb89e8a9fb65e8c13d69e8a9fb'
  485. # data12 = bytes.fromhex('0409efbe140000001000020069e8a9fb89e8a9fb65e8e93c69e8a9fb')
  486. # #'0409efbe 14000000 10000200 69e8a9fb 89e8a9fb 65e8c13d 69e8a9fb'
  487. # data10 = bytes.fromhex('0409efbe140000001000020069e8a9fb89e8a9fb65e8c93c69e8a9fb')
  488. # # send_data = bytes.fromhex(data)
  489. # # data = command_data.parse(send_data)
  490. # # print(data)
  491. # data12 = command_data.parse(data12)
  492. # print(data12)
  493. # data10 = command_data.parse(data10)
  494. # print(data10)
  495. # print(data12.pack_data - data10.pack_data)
  496. # # data = '0409efbef00000000800030069e8a9fb9ee8a9fb65e8a9fb65e8a9fb65e8293a64e7a8fa65e8a9fb27a05b3965e8a9fb65e2131065e8a9fb67e8a9fb64e7a8fa65e829ba6575198666f69de965e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8693b668cdead4e2ec03e65e8293a66c9931140f7f23a65884de724f6453966e8a9fb65e8a9fb80e8a9fb80e8a9fb6675198665f79de965e8a9fb65e8a9fb65e8493b6527c89d65e8c13d65884de769e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8a9fb66884de7658cdead65e8a9fb75e8aafb65e8a9fb6502f91ce2e8a9fb67e8a9fb65e8a9fb65e8693b66884de765884de769e8a9fb'
  497. # # send_data = bytes.fromhex(data)
  498. # # data = status_data.parse(send_data)
  499. # # print(data)