sonar_command_tcp_once.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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.210", 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 = 16
  62. self.range_b = 38
  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. '''
  346. def get_range_command(self, command_head, str_key, mode, range):
  347. range_list = [3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
  348. offset_list = [0x40, 0x80, 0xa0, 0xc0, 0xe0, 0x00, 0x10, 0x20, 0x40, 0x60, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0]
  349. # print(len(range_list),len(offset_list))
  350. if range in range_list:
  351. index = range_list.index(range)
  352. offset = offset_list[index]
  353. a = str_key[0:2]
  354. bcd = str_key[2:8]
  355. ab = str_key[0:4]
  356. c = str_key[4:6]
  357. d = str_key[6:8]
  358. range_c = self.get_str_hex(c, offset)
  359. if range > 7:
  360. range_d = self.get_str_hex(d, 0x41)
  361. else:
  362. range_d = self.get_str_hex(d, 0x40)
  363. body1 = self.get_str_hex(a, 0x04) + bcd
  364. if mode == 'H':
  365. body2 = self.get_str_hex(a, 0x24) + bcd
  366. elif mode == 'V':
  367. body2 = self.get_str_hex(a, 0x22) + bcd
  368. body3 = ab + range_c + range_d
  369. body4 = self.get_str_hex(a, 0x04) + bcd
  370. command = command_head + body1 + body2 + body3 + body4
  371. return command
  372. else:
  373. return None
  374. '''
  375. def get_range_command(self, command_head, str_key, mode, range):
  376. range_list = [3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52]
  377. offset_list = [0x40, 0x80, 0xa0, 0xc0, 0xe0, 0x00, 0x10, 0x20, 0x40, 0x60, 0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
  378. 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50]
  379. # print(len(range_list),len(offset_list))
  380. if range in range_list:
  381. index = range_list.index(range)
  382. offset = offset_list[index]
  383. a = str_key[0:2]
  384. bcd = str_key[2:8]
  385. ab = str_key[0:4]
  386. c = str_key[4:6]
  387. d = str_key[6:8]
  388. range_c = self.get_str_hex(c, offset)
  389. if range > 7 and range <= 30:
  390. range_d = self.get_str_hex(d, 0x41)
  391. elif range <= 7:
  392. range_d = self.get_str_hex(d, 0x40)
  393. elif range > 30:
  394. range_d = self.get_str_hex(d, 0x42)
  395. body1 = self.get_str_hex(a, 0x04) + bcd
  396. if mode == 'H':
  397. body2 = self.get_str_hex(a, 0x24) + bcd
  398. elif mode == 'V':
  399. body2 = self.get_str_hex(a, 0x22) + bcd
  400. body3 = ab + range_c + range_d
  401. body4 = self.get_str_hex(a, 0x04) + bcd
  402. command = command_head + body1 + body2 + body3 + body4
  403. return command
  404. else:
  405. return None
  406. # 接收服务器发送的数据
  407. def receive_data(self):
  408. try:
  409. data = self.__sock.recv(self.status_len)
  410. except socket.timeout as e:
  411. logger.error(f"{self.name}: {e}")
  412. time.sleep(5)
  413. self.__reconnect()
  414. print('recv', e)
  415. except Exception as e:
  416. logger.error(f"{self.name}: {e}")
  417. time.sleep(5)
  418. self.__reconnect()
  419. if len(data) == self.status_len:
  420. self.open_key = data[20:24].hex()
  421. print(self.open_key)
  422. # if len(self.set_command_dict) < 1:
  423. self.open_command = self.get_open_command(self.command_head, self.open_key, 'open')
  424. self.close_command = self.get_open_command(self.command_head, self.open_key, 'close')
  425. self.range_command_H_s = self.get_range_command(self.command_head, self.open_key, 'H', self.range_s)
  426. self.range_command_V_s = self.get_range_command(self.command_head, self.open_key, 'V', self.range_s)
  427. self.range_command_H_b = self.get_range_command(self.command_head, self.open_key, 'H', self.range_b)
  428. self.range_command_V_b = self.get_range_command(self.command_head, self.open_key, 'V', self.range_b)
  429. self.set_command_dict['forward'] = self.get_installation_command(self.command_head, self.open_key, 'forward')
  430. self.set_command_dict['noise'] = self.get_noise_command(self.command_head, self.open_key, 'close')
  431. self.set_command_dict['tvg_close'] = self.get_tvg_command_forward(self.command_head, self.open_key, 'close')
  432. # self.set_command_dict['tvg_hig'] = self.get_tvg_command_forward(self.command_head, self.open_key, 'hig')
  433. self.set_command_dict['ghosting_suppression'] = self.ghosting_suppression(self.command_head, self.open_key, 'close')
  434. # self.set_command_dict['under'] = self.get_installation_command(self.command_head, self.open_key, 'under')
  435. self.set_command_dict['depth_0m'] = self.get_installation_depth_0m_command(self.command_head, self.open_key)
  436. self.set_command_dict['focus'] = self.get_focus_command(self.command_head, self.open_key, 'salt')
  437. if self.ahrs_status == True:
  438. self.set_command_dict['ahrs_open'] = self.get_ahrs_command(self.command_head, self.open_key, 'open')
  439. else:
  440. self.set_command_dict['ahrs_close'] = self.get_ahrs_command(self.command_head, self.open_key, 'close')
  441. self.set_command_dict['flip_close'] = self.get_flip_command(self.command_head, self.open_key, 'close')
  442. # self.set_command_dict['flip_open'] = self.get_ahrs_command(self.command_head, self.open_key, 'close'
  443. self.set_command_dict['pitch'] = self.get_pitch_command(self.command_head, self.open_key)
  444. noise_close = self.get_noise_command(self.command_head, self.open_key, 'close')
  445. noise_low = self.get_noise_command(self.command_head, self.open_key, 'low')
  446. noise_med = self.get_noise_command(self.command_head, self.open_key, 'med')
  447. noise_hig = self.get_noise_command(self.command_head, self.open_key, 'hig')
  448. tvg_close = self.get_tvg_command_forward(self.command_head, self.open_key, 'close')
  449. tvg_low = self.get_tvg_command_forward(self.command_head, self.open_key, 'low')
  450. tvg_med = self.get_tvg_command_forward(self.command_head, self.open_key, 'med')
  451. tvg_hig = self.get_tvg_command_forward(self.command_head, self.open_key, 'hig')
  452. range_H_3 = self.get_range_command(self.command_head, self.open_key, 'H', 3)
  453. range_H_4 = self.get_range_command(self.command_head, self.open_key, 'H', 4)
  454. range_H_5 = self.get_range_command(self.command_head, self.open_key, 'H', 5)
  455. range_H_6 = self.get_range_command(self.command_head, self.open_key, 'H', 6)
  456. range_H_7 = self.get_range_command(self.command_head, self.open_key, 'H', 7)
  457. range_H_8 = self.get_range_command(self.command_head, self.open_key, 'H', 8)
  458. range_H_9 = self.get_range_command(self.command_head, self.open_key, 'H', 9)
  459. range_H_10 = self.get_range_command(self.command_head, self.open_key, 'H', 10)
  460. range_H_12 = self.get_range_command(self.command_head, self.open_key, 'H', 12)
  461. range_H_14 = self.get_range_command(self.command_head, self.open_key, 'H', 14)
  462. range_H_16 = self.get_range_command(self.command_head, self.open_key, 'H', 16)
  463. range_H_18 = self.get_range_command(self.command_head, self.open_key, 'H', 18)
  464. range_H_20 = self.get_range_command(self.command_head, self.open_key, 'H', 20)
  465. range_H_22 = self.get_range_command(self.command_head, self.open_key, 'H', 22)
  466. range_H_24 = self.get_range_command(self.command_head, self.open_key, 'H', 24)
  467. range_H_26 = self.get_range_command(self.command_head, self.open_key, 'H', 26)
  468. range_H_28 = self.get_range_command(self.command_head, self.open_key, 'H', 28)
  469. range_H_30 = self.get_range_command(self.command_head, self.open_key, 'H', 30)
  470. range_V_3 = self.get_range_command(self.command_head, self.open_key, 'V', 3)
  471. range_V_4 = self.get_range_command(self.command_head, self.open_key, 'V', 4)
  472. range_V_5 = self.get_range_command(self.command_head, self.open_key, 'V', 5)
  473. range_V_6 = self.get_range_command(self.command_head, self.open_key, 'V', 6)
  474. range_V_7 = self.get_range_command(self.command_head, self.open_key, 'V', 7)
  475. range_V_8 = self.get_range_command(self.command_head, self.open_key, 'V', 8)
  476. range_V_9 = self.get_range_command(self.command_head, self.open_key, 'V', 9)
  477. range_V_10 = self.get_range_command(self.command_head, self.open_key, 'V', 10)
  478. range_V_12 = self.get_range_command(self.command_head, self.open_key, 'V', 12)
  479. range_V_14 = self.get_range_command(self.command_head, self.open_key, 'V', 14)
  480. range_V_16 = self.get_range_command(self.command_head, self.open_key, 'V', 16)
  481. range_V_18 = self.get_range_command(self.command_head, self.open_key, 'V', 18)
  482. range_V_20 = self.get_range_command(self.command_head, self.open_key, 'V', 20)
  483. range_V_22 = self.get_range_command(self.command_head, self.open_key, 'V', 22)
  484. range_V_24 = self.get_range_command(self.command_head, self.open_key, 'V', 24)
  485. range_V_26 = self.get_range_command(self.command_head, self.open_key, 'V', 26)
  486. range_V_28 = self.get_range_command(self.command_head, self.open_key, 'V', 28)
  487. range_V_30 = self.get_range_command(self.command_head, self.open_key, 'V', 30)
  488. auto = self.get_installation_command(self.command_head, self.open_key, 'auto')
  489. under = self.get_installation_command(self.command_head, self.open_key, 'under')
  490. forward = self.get_installation_command(self.command_head, self.open_key, 'forward')
  491. perspective = self.get_installation_command(self.command_head, self.open_key, 'perspective')
  492. depth_0m = self.get_installation_depth_0m_command(self.command_head, self.open_key)
  493. pitch = self.get_pitch_command(self.command_head, self.open_key)
  494. ahrs_open = self.get_ahrs_command(self.command_head, self.open_key, 'open')
  495. ahrs_close = self.get_ahrs_command(self.command_head, self.open_key, 'close')
  496. flip_open = self.get_flip_command(self.command_head, self.open_key, 'open')
  497. fiip_close = self.get_flip_command(self.command_head, self.open_key, 'close')
  498. focus_salt = self.get_focus_command(self.command_head, self.open_key, 'salt')
  499. focus_fresh = self.get_focus_command(self.command_head, self.open_key, 'fresh')
  500. ghosting_suppression_close = self.ghosting_suppression(self.command_head, self.open_key, 'close')
  501. ghosting_suppression_low = self.ghosting_suppression(self.command_head, self.open_key, 'low')
  502. ghosting_suppression_med = self.ghosting_suppression(self.command_head, self.open_key, 'med')
  503. ghosting_suppression_hig = self.ghosting_suppression(self.command_head, self.open_key, 'hig')
  504. ghosting_suppression_auto = self.ghosting_suppression(self.command_head, self.open_key, 'auto')
  505. # self.status_list['1']
  506. # print(data.hex(), end='\n')
  507. # if not data:
  508. # break
  509. command = 1
  510. def hex_to_str1(self, s): # s="68656c6c6f"
  511. s = binascii.unhexlify(s) # unhexlify()传入的参数也可以是b'xxxx'(xxxx要符合16进制特征)
  512. print(s.decode('utf-8')) # s的类型是bytes类型,用encode()方法转化为str类型
  513. # 启动客户端
  514. if __name__ == '__main__':
  515. p = Client() # 实例化进程对象
  516. p.start()
  517. # data = '0409efbe140000001000020069e8a9fb89e8a9fb65e8c13d69e8a9fb'
  518. # data12 = bytes.fromhex('0409efbe140000001000020069e8a9fb89e8a9fb65e8e93c69e8a9fb')
  519. # #'0409efbe 14000000 10000200 69e8a9fb 89e8a9fb 65e8c13d 69e8a9fb'
  520. # data10 = bytes.fromhex('0409efbe140000001000020069e8a9fb89e8a9fb65e8c93c69e8a9fb')
  521. # # send_data = bytes.fromhex(data)
  522. # # data = command_data.parse(send_data)
  523. # # print(data)
  524. # data12 = command_data.parse(data12)
  525. # print(data12)
  526. # data10 = command_data.parse(data10)
  527. # print(data10)
  528. # print(data12.pack_data - data10.pack_data)
  529. # # data = '0409efbef00000000800030069e8a9fb9ee8a9fb65e8a9fb65e8a9fb65e8293a64e7a8fa65e8a9fb27a05b3965e8a9fb65e2131065e8a9fb67e8a9fb64e7a8fa65e829ba6575198666f69de965e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8693b668cdead4e2ec03e65e8293a66c9931140f7f23a65884de724f6453966e8a9fb65e8a9fb80e8a9fb80e8a9fb6675198665f79de965e8a9fb65e8a9fb65e8493b6527c89d65e8c13d65884de769e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8a9fb65e8a9fb66884de7658cdead65e8a9fb75e8aafb65e8a9fb6502f91ce2e8a9fb67e8a9fb65e8a9fb65e8693b66884de765884de769e8a9fb'
  530. # # send_data = bytes.fromhex(data)
  531. # # data = status_data.parse(send_data)
  532. # # print(data)