From 8c9b3173501079bfc10bacc60ca48336409329c3 Mon Sep 17 00:00:00 2001 From: baskiton Date: Fri, 10 May 2024 00:32:32 +0700 Subject: [PATCH] get data length from AGWPE connection --- SatsDecoder/__init__.py | 2 -- SatsDecoder/ui.py | 19 ++++++++++--------- SatsDecoder/utils.py | 5 +++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/SatsDecoder/__init__.py b/SatsDecoder/__init__.py index 8bc6ec1..0323465 100644 --- a/SatsDecoder/__init__.py +++ b/SatsDecoder/__init__.py @@ -11,5 +11,3 @@ HOMEDIR = pathlib.Path('~/SatsDecoder').expanduser().absolute() CONFIG = HOMEDIR / 'config.ini' RES = pathlib.Path(__file__).parent.parent / 'res' -AGWPE_CON = b'\x00\x00\x00\x00k\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ - b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' diff --git a/SatsDecoder/ui.py b/SatsDecoder/ui.py index 0526fe8..08802c1 100644 --- a/SatsDecoder/ui.py +++ b/SatsDecoder/ui.py @@ -33,7 +33,7 @@ import PIL.ImageFile import PIL.ImageTk -from SatsDecoder import AGWPE_CON, HOMEDIR, RES, systems, utils +from SatsDecoder import HOMEDIR, RES, systems, utils from SatsDecoder.version import __version__ @@ -657,8 +657,9 @@ def _finish(ok=0): ask_hex.update() def _start(self): - self.is_server = utils.ConnMode(self.conn_mode.current()) == utils.ConnMode.TCP_SRV - self.is_raw_tcp = 1 + curr_mode = utils.ConnMode(self.conn_mode.current()) + self.is_server = curr_mode == utils.ConnMode.TCP_SRV + self.is_agwpe_cli = curr_mode == utils.ConnMode.AGWPE_CLI try: self.frame_off = 0 s = sk.socket(sk.AF_INET, sk.SOCK_STREAM) @@ -669,10 +670,9 @@ def _start(self): else: s.connect((self.server_v.get(), int(self.port_v.get()))) - if utils.ConnMode(self.conn_mode.current()) == utils.ConnMode.AGWPE_CLI: - self.is_raw_tcp = 0 - self.frame_off = 37 - s.send(AGWPE_CON) + if self.is_agwpe_cli: + self.frame_off = 1 + s.send(utils.AGWPE_CON) s.setblocking(0) self.sk = s @@ -751,8 +751,9 @@ def _recvall(conn, n): def _receive(self, conn): try: - if not self.is_raw_tcp: - frame = conn.recv(4096) + if self.is_agwpe_cli: + port, kind, pid, c_from, c_to, dlen = utils.AGWPE_HDR_FMT.unpack_from(conn.recv(utils.AGWPE_HDR_FMT.size)) + frame = conn.recv(dlen) else: frame_sz = frame = self._recvall(conn, 4) if frame_sz: diff --git a/SatsDecoder/utils.py b/SatsDecoder/utils.py index aa7501c..5a75a0a 100644 --- a/SatsDecoder/utils.py +++ b/SatsDecoder/utils.py @@ -7,6 +7,7 @@ import datetime as dt import enum +import struct import sys import tkinter as tk @@ -399,3 +400,7 @@ def gps_to_utc(week, sec): 'anBnLyVzcHgtQ3ViZVNhdF9HZW9zY2FuLUVkZWx2ZWlzX2VtYmxlbS5qcGc=', '\x72\x73\x31\x35\x73': 'aHR0cHM6Ly9zcHV0bml4LnJ1L3RwbC9pbWcvbG9nby16b3JraXkuanBnPyVz', } + +AGWPE_CON = b'\x00\x00\x00\x00k\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +AGWPE_HDR_FMT = struct.Struct('BxxxBxBx10s10sIxxxx')