Changes in / [29bf25a:dff8988] in ammosreader


Ignore:
Files:
29 added
21 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • ammosreader/AmmosGlobalFrameHeader.py

    r29bf25a rdff8988  
    11"""I provide an AMMOS global frame header."""
    22import struct
    3 import logging
    4 
    5 logging.basicConfig(filename='ammos.log', level=logging.DEBUG)
    6 
     3from ammosreader import logger
    74
    85class AmmosGlobalFrameHeader:
     
    2118        magic_word = elements[0].hex()
    2219
     20        logger.debug("Header created")
    2321        if magic_word != cls.MAGIC_WORD:
    2422            return None
     
    4038        """I return a new instance of myself initialized with above parameters."""
    4139        if magic_word != type(self).MAGIC_WORD:
    42             logging.error("Wrong magic word found")
     40            logger.error("Wrong magic word found")
    4341            self.magic_word = magic_word
    4442        else:
  • ammosreader/PDW.py

    r29bf25a rdff8988  
    44import math
    55import numpy as np
    6 
     6from ammosreader import logger
    77
    88class PDW():
     
    2424        :rtype: PDW
    2525        """
    26         assert(len(byte_string) == 32)
     26
     27        logger.info("from bytes")
     28        if (len(byte_string) != 32):
     29            logger.error("Byte count invalid")
     30            raise TypeError("Byte count invalid")
    2731
    2832        parts = struct.unpack('<Q4s4s4s4s4s4s', byte_string)
     33
    2934        nanoseconds = (parts[0])
     35        unix_time = np.datetime64('now', 'ns').astype(int)
     36        if nanoseconds >= unix_time:
     37            raise OverflowError("Timestamp invalid")
    3038        time_of_arrival = np.datetime64(nanoseconds, 'ns')
    3139
     
    6169        modulations = {0: 'Unknown', 1: 'Unmodulated', 2: 'FM', 3: 'LFM', 4: 'PSK-2', 5: 'PSK-3', 6: 'PSK-4',
    6270                       7: 'PSK-m', 8: 'NLFM', 9: 'SFM', 10: 'TFM', 11: 'Pulse too short'}
    63         modulation = modulations[int(sixth_entry_bit_string[7:12], 2)]
     71        modulation = modulations.get(int(sixth_entry_bit_string[7:12], 2), 0)
    6472        sector = int(sixth_entry_bit_string[28:32], 2)
    6573
  • ammosreader/__init__.py

    r29bf25a rdff8988  
     1import logging
     2import logging.config
     3import os
     4from pathlib import Path
     5
     6# change the default log path to /var/log/ammos/ammos.log when system configuration created this dir
     7# with the appropriate rights
     8
     9log_dir = Path(os.environ.get('AMMOS_LOG_DIR', '/tmp/'))
     10
     11log_path = log_dir / 'ammos.log'
     12
     13if not log_path.exists():
     14#   print(log_path, "does not exist")
     15    try:
     16#       print("Trying to create logfile", str(log_path))
     17        log_path.touch()
     18    except PermissionError:
     19#       print("Logging to file disabled")
     20        conf_file = Path(__file__).parent / 'ammos_logging.conf'
     21        print("Conf file", conf_file)
     22        logging.config.fileConfig(conf_file)
     23else:
     24#   print("Logging to", str(log_path))
     25    logging.basicConfig(filename=str(log_path), encoding='utf-8', level=logging.DEBUG)
     26
     27logger = logging.getLogger(__name__)
     28
     29logger.warning("Text")
Note: See TracChangeset for help on using the changeset viewer.