def _get_gps_status_as_bool(enodeb: EnodebAcsStateMachine) -> bool: try: if not enodeb.has_parameter(ParameterName.GPS_STATUS): return False else: param = enodeb.get_parameter(ParameterName.GPS_STATUS) stripped_value = param.lower().strip() if stripped_value == '0' or stripped_value == '2': # 2 = GPS locking return False elif stripped_value == '1': return True else: logger.warning('GPS status parameter not understood (%s)', param) return False except (KeyError, ConfigurationError): return False
def get_enb_status(enodeb: EnodebAcsStateMachine) -> EnodebStatus: """ Returns a dict representing the status of an enodeb The returned dictionary will be a subset of the following keys: - enodeb_connected - enodeb_configured - opstate_enabled - rf_tx_on - gps_connected - ptp_connected - mme_connected - gps_latitude - gps_longitude The set of keys returned will depend on the connection status of the enodeb. A missing key indicates that the value is unknown. Returns: Status dictionary for the enodeb state """ enodeb_configured = '1' if enodeb.is_enodeb_configured() else '0' # We cache GPS coordinates so try to read them before the early return # if the enB is not connected gps_lat, gps_lon = _get_and_cache_gps_coords(enodeb) enodeb_connected = '1' if enodeb.is_enodeb_connected() else '0' opstate_enabled = _parse_param_as_bool(enodeb, ParameterName.OP_STATE) rf_tx_on = _parse_param_as_bool(enodeb, ParameterName.RF_TX_STATUS) mme_connected = _parse_param_as_bool(enodeb, ParameterName.MME_STATUS) try: if not enodeb.has_parameter(ParameterName.GPS_STATUS): gps_connected = '0' else: param = enodeb.get_parameter(ParameterName.GPS_STATUS) pval = param.lower().strip() if pval == '0' or pval == '1': gps_connected = pval elif pval == '2': # 2 = GPS locking gps_connected = '0' else: logging.warning( 'GPS status parameter not understood (%s)', param) gps_connected = '0' except (KeyError, ConfigurationError): gps_connected = '0' try: if not enodeb.has_parameter(ParameterName.PTP_STATUS): ptp_connected = '0' else: param = enodeb.get_parameter(ParameterName.PTP_STATUS) pval = param.lower().strip() if pval == '0' or pval == '1': ptp_connected = pval else: logging.warning( 'PTP status parameter not understood (%s)', param) ptp_connected = '0' except (KeyError, ConfigurationError): ptp_connected = '0' return EnodebStatus(enodeb_configured=enodeb_configured, gps_latitude=gps_lat, gps_longitude=gps_lon, enodeb_connected=enodeb_connected, opstate_enabled=opstate_enabled, rf_tx_on=rf_tx_on, gps_connected=gps_connected, ptp_connected=ptp_connected, mme_connected=mme_connected, enodeb_state=enodeb.get_state())