Changeset d6535bd in ammosreader


Ignore:
Timestamp:
05/28/23 15:00:01 (2 years ago)
Author:
Enrico Schwass <ennoausberlin@…>
Branches:
AmmosSource
Children:
90cd378
Parents:
1de11fa
Message:

more refactoring to clean up superfluous classes

Location:
ammosreader
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • ammosreader/AbstractAmmosReader.py

    r1de11fa rd6535bd  
    4545        assert a_key not in self.__tags
    4646        self.__tags[a_key] = a_value
     47
     48    def resync(self):
     49        """I try to resync, when reading from source was garbled."""
     50        self.source.resync()
    4751
    4852    def read_all_frames_left(self):
  • ammosreader/AmmosSocketSource.py

    r1de11fa rd6535bd  
    1111
    1212    def read_bytes(self, bytes_to_read):
     13        """
     14        I read bytes_to_read bytes from my socket. Incomplete reads get discarded.
     15
     16        :param bytes_to_read: the number of bytes to read
     17        :type bytes_to_read: int
     18
     19        :return: the complete byte string or None if not all the bytes are read
     20        :rtype: bytes
     21        """
     22
     23        assert bytes_to_read > 0
    1324        byte_array = []
    1425        logger.info("Start reading bytes from socket")
    1526        try:
    16             while len(b''.join(byte_array)) < bytes_to_read:
    17                 logger.info("Remaining Bytes: %s", bytes_to_read - len(b''.join(byte_array)))
    18                 self.source.settimeout(5)
    19                 new_bytes = self.source.recv(bytes_to_read - len(b''.join(byte_array)), socket.MSG_WAITALL)
     27            while len(byte_array) < bytes_to_read:
     28                logger.info("Remaining Bytes: %s", bytes_to_read - len(byte_array))
     29                self.source.settimeout(self.timeout)
     30                new_bytes = self.source.recv(bytes_to_read - len(byte_array), socket.MSG_WAITALL)
    2031
    2132                if not new_bytes:
    2233                    raise TimeoutError("Socket timed out while reading data")
    23                 logger.info("Got %s bytes of %s remaining", len(new_bytes), bytes_to_read - len(b''.join(byte_array)))
     34                logger.info("Got %s bytes of %s remaining", len(new_bytes), bytes_to_read - len(byte_array))
    2435                byte_array.append(new_bytes)
    25                 print(byte_array)
    2636        except TimeoutError:
    2737            logger.info("Timeout error while reading from socket")
  • ammosreader/AmmosSource.py

    r1de11fa rd6535bd  
    11from abc import ABC, abstractmethod
    22from collections import deque
     3from ammosreader.AmmosGlobalFrameHeader import AmmosGlobalFrameHeader
     4
    35
    46class AmmosSource(ABC):
     
    68        self.__source = source
    79        self.__name = ""
     10        self.__timeout = 5
     11
     12    @property
     13    def timeout(self):
     14        return self.__timeout
     15
     16    @timeout.setter
     17    def timeout(self, a_timeout):
     18        self.__timeout = a_timeout
    819
    920    @property
    1021    def name(self):
    11         return self.__name 
     22        return self.__name
    1223
    1324    @name.setter
     
    2233    def source(self, a_source):
    2334        self.__source = a_source
    24        
     35
    2536    @abstractmethod
    2637    def read_bytes(self, bytes_to_read):
     
    3142        while True:
    3243            try:
    33                 magic_word_que.append(self.read_bytes(1))
    34             except TimeOutError:
     44                magic_word_queue.append(self.read_bytes(1))
     45            except TimeoutError:
    3546                result = False
    3647                break
Note: See TracChangeset for help on using the changeset viewer.