Skip to content

Commit

Permalink
get data length from AGWPE connection
Browse files Browse the repository at this point in the history
  • Loading branch information
baskiton committed May 9, 2024
1 parent ab402bf commit 8c9b317
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 0 additions & 2 deletions SatsDecoder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
19 changes: 10 additions & 9 deletions SatsDecoder/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__


Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions SatsDecoder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import datetime as dt
import enum
import struct
import sys
import tkinter as tk

Expand Down Expand Up @@ -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')

0 comments on commit 8c9b317

Please sign in to comment.