Skip to content

Commit

Permalink
chg: dev: Collect all serial writes for modem, for consistent encodin…
Browse files Browse the repository at this point in the history
…g. !minor

Closes #139
  • Loading branch information
ashmastaflash committed Dec 26, 2019
1 parent 348e895 commit 7b3e20d
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion sitch/sitchlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
from .geo_correlator import GeoCorrelator # NOQA

__author__ = "Ash Wilson"
__version__ = "4.0"
__version__ = "4.1"
3 changes: 1 addition & 2 deletions sitch/sitchlib/alert_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .utility import Utility


class AlertManager(object):
class AlertManager:
"""AlertManager is used to ensure alerts are consistently formatted."""

def __init__(self, device_id):
Expand All @@ -20,7 +20,6 @@ def __init__(self, device_id):
310: "GPS time delta over threshold.",
400: "Failed to locate a valid license for ARFCN in this area."
}
return

def get_alert_type(self, alert_id):
"""Return the alert description for alert_id."""
Expand Down
5 changes: 2 additions & 3 deletions sitch/sitchlib/arfcn_correlator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""ARFCN Correlator."""

from . import alert_manager
import os
import sqlite3
from . import alert_manager
from .utility import Utility


class ArfcnCorrelator(object):
class ArfcnCorrelator:
"""The ArfcnCorrelator compares ARFCN metadata against feeds and threshold.
The feed data is put in place by the FeedManager class, prior to
Expand Down Expand Up @@ -34,7 +34,6 @@ def __init__(self, feed_dir, whitelist, power_threshold, device_id):
self.observed_arfcn = whitelist
self.arfcn_threshold = []
self.arfcn_range = []
return

def correlate(self, scan_bolus):
"""Entrypoint for correlation, wraps individual checks.
Expand Down
3 changes: 1 addition & 2 deletions sitch/sitchlib/cgi_correlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .utility import Utility


class CgiCorrelator(object):
class CgiCorrelator:
"""The CgiCorrelator compares CGI addressing against the OpenCellID DB.
The feed data is put in place by the FeedManager class, prior to
Expand All @@ -33,7 +33,6 @@ def __init__(self, feed_dir, cgi_whitelist, mcc_list, device_id):
self.cgi_db = os.path.join(feed_dir, "cgi.db")
self.alarm_140_cache = ""
print(CgiCorrelator.cgi_whitelist_message(self.cgi_whitelist))
return

def correlate(self, scan_bolus):
"""Entrypoint for the CGI correlation component.
Expand Down
2 changes: 0 additions & 2 deletions sitch/sitchlib/config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def print_devices_as_detected(self):
pp.pprint(self.detector.gsm_radios)
print("Configurator: Detected GPS devices:")
pp.pprint(self.detector.gps_devices)
return

def get_gsm_modem_port(self):
"""Get GSM modem port from detector, override with env var."""
Expand Down Expand Up @@ -129,7 +128,6 @@ def write_filebeat_config(self):
fb = self.set_filebeat_logfile_paths(self.log_prefix, fb)
with open(self.filebeat_config_file_path, 'w') as out_file:
yaml.safe_dump(fb, out_file)
return

@classmethod
def set_filebeat_logfile_paths(cls, log_prefix, filebeat_config):
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .geoip_decomposer import GeoipDecomposer


class Decomposer(object):
class Decomposer:
"""Decompose device messages into normalized log messages."""

decomp_ref = {"kalibrate": KalDecomposer(),
Expand Down
5 changes: 2 additions & 3 deletions sitch/sitchlib/device_detector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Device Detector interrogates USB TTY devices."""

import time
import pyudev
import serial
import time
from .utility import Utility


class DeviceDetector(object):
class DeviceDetector:
"""Interrogate all USB TTY ports.
Attributes:
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/feed_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .utility import Utility


class FeedManager(object):
class FeedManager:
"""Manage downloading the feed DB, and merging it into the sqlite DB."""

def __init__(self, config):
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/feed_schema_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import geopy


class FeedSchemaTranslator(object):
class FeedSchemaTranslator:
def __init__(self, schema):
self.field_maps = schema
self.translators = self.translators_from_schema(schema)
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/geo_correlator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .utility import Utility


class GeoCorrelator(object):
class GeoCorrelator:
"""Geographic correlator."""

def __init__(self, device_id):
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/geo_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

GEO_DB_LOCATION = "/var/mmdb//GeoLite2-City.mmdb" # NOQA

class GeoIp(object):
class GeoIp:
"""Generate GeoIP events."""

def __init__(self, delay=60):
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/geoip_decomposer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Decompose GeoIP Events."""


class GeoipDecomposer(object):
class GeoipDecomposer:
"""GeoIP Decomposer."""

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/gps_decomposer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Decompose GPS Events."""


class GpsDecomposer(object):
class GpsDecomposer:
"""GPS Decomposer."""

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/gps_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time


class GpsListener(object):
class GpsListener:
"""Wrap the GPS device with an iterator."""

def __init__(self, delay=60):
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/gsm_decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .utility import Utility


class GsmDecomposer(object):
class GsmDecomposer:
"""Decomposes GSM scans."""

@classmethod
Expand Down
20 changes: 11 additions & 9 deletions sitch/sitchlib/gsm_modem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time


class GsmModem(object):
class GsmModem:
"""GSM Modem handler class. Interfaces with device over serial.
Calling GsmModem.set_eng_mode() causes the module to go into
Expand Down Expand Up @@ -40,7 +40,6 @@ def __init__(self, ser_port):
if ser_open_iter > 5:
print("GSM: Failed to open serial port %s!" % ser_port)
sys.exit(2)
return

def __iter__(self):
"""Yield scans from GSM modem."""
Expand All @@ -63,6 +62,10 @@ def __iter__(self):
else:
page.append(processed_line)

def serial_write(self, write_me):
"""Convert string to bytes then write to serial."""
self.serconn.write(write_me.encode("utf-8"))

def eng_mode(self, status):
"""Set or unset engineering mode on the modem.
Expand All @@ -72,7 +75,7 @@ def eng_mode(self, status):
self.serconn.flush()
if status is False:
print("GsmModem: Unsetting engineering mode, flushing")
self.serconn.write(self.unset_eng)
self.serial_write(self.unset_eng)
while True:
output = self.serconn.readline()
if output == '':
Expand All @@ -81,17 +84,16 @@ def eng_mode(self, status):
print(output)
else:
print("GsmModem: Setting engineering mode")
self.serconn.write(self.eng_init)
self.serial_write(self.eng_init)
self.serconn.flush()
time.sleep(2)
output = self.serconn.readline()
print(output)
self.serconn.flush()
return

def get_reg_info(self):
"""Get registration information from the modem."""
self.serconn.write(self.reg_info)
self.serial_write(self.reg_info)
self.serconn.flush()
time.sleep(2)
output = self.serconn.readline()
Expand All @@ -103,7 +105,7 @@ def get_reg_info(self):

def dump_config(self):
"""Dump modem's configuration."""
self.serconn.write(self.config_dump)
self.serial_write(self.config_dump)
self.serconn.flush()
time.sleep(2)
retval = []
Expand All @@ -118,7 +120,7 @@ def dump_config(self):
def get_imsi(self):
"""Get the IMSI of the SIM installed in the modem."""
rx = r'(?P<imsi>\S+)'
self.serconn.write(self.imsi_info)
self.serial_write(self.imsi_info)
self.serconn.flush()
time.sleep(2)
retval = []
Expand Down Expand Up @@ -158,7 +160,7 @@ def set_band(self, band):
"EGSM_PCS_MODE", "ALL_BAND"]:
term_command = "AT+CBAND=\"%s\" \r\n" % band
print("GSM: Setting GSM band with: %s" % term_command)
self.serconn.write(term_command)
self.serial_write(term_command)
self.serconn.flush()
time.sleep(2)
output = self.serconn.readline()
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/kal_decomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .utility import Utility


class KalDecomposer(object):
class KalDecomposer:
"""Decompose Kalibrate scans."""

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion sitch/sitchlib/location_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from geopy.distance import great_circle


class LocationTool(object):
class LocationTool:
"""Class with location-oriented functions."""
@classmethod
def validate_geo(cls, latlon):
Expand Down

0 comments on commit 7b3e20d

Please sign in to comment.