Changeset d6535bd in ammosreader
- Timestamp:
- 05/28/23 15:00:01 (2 years ago)
- Branches:
- AmmosSource
- Children:
- 90cd378
- Parents:
- 1de11fa
- Location:
- ammosreader
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ammosreader/AbstractAmmosReader.py
r1de11fa rd6535bd 45 45 assert a_key not in self.__tags 46 46 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() 47 51 48 52 def read_all_frames_left(self): -
ammosreader/AmmosSocketSource.py
r1de11fa rd6535bd 11 11 12 12 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 13 24 byte_array = [] 14 25 logger.info("Start reading bytes from socket") 15 26 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) 20 31 21 32 if not new_bytes: 22 33 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)) 24 35 byte_array.append(new_bytes) 25 print(byte_array)26 36 except TimeoutError: 27 37 logger.info("Timeout error while reading from socket") -
ammosreader/AmmosSource.py
r1de11fa rd6535bd 1 1 from abc import ABC, abstractmethod 2 2 from collections import deque 3 from ammosreader.AmmosGlobalFrameHeader import AmmosGlobalFrameHeader 4 3 5 4 6 class AmmosSource(ABC): … … 6 8 self.__source = source 7 9 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 8 19 9 20 @property 10 21 def name(self): 11 return self.__name 22 return self.__name 12 23 13 24 @name.setter … … 22 33 def source(self, a_source): 23 34 self.__source = a_source 24 35 25 36 @abstractmethod 26 37 def read_bytes(self, bytes_to_read): … … 31 42 while True: 32 43 try: 33 magic_word_que .append(self.read_bytes(1))34 except Time OutError:44 magic_word_queue.append(self.read_bytes(1)) 45 except TimeoutError: 35 46 result = False 36 47 break
Note:
See TracChangeset
for help on using the changeset viewer.