Example #1
0
def main():
    args = argparser()
    browser = NtripBrowser(args.url, port=args.port, timeout=args.timeout, coordinates=args.coordinates)
    try:
        ntrip_table = browser.get_mountpoints()
    except ExceededTimeoutError:
        print('Connection timed out')
    except UnableToConnect:
        print('Unable to connect to NTRIP caster')
    except NoDataReceivedFromCaster:
        print('No data received from NTRIP caster')
    except HandshakeFiledError:
        print('Unable to connect to NTRIP caster, handshake error')
    else:
        display_ntrip_table(ntrip_table)
def test_valid_net_data():
    browser = NtripBrowser('test', 1234)
    assert browser.get_mountpoints() == {
        'cas': [],
        'net': [{
            'Authentication': 'B',
            'Distance': None,
            'Fee': 'N',
            'ID': 'Str1',
            'Operator': 'Str2',
            'Other Details': 'none',
            'Web-Net': 'https://example.htm',
            'Web-Reg': 'http://sample',
            'Web-Str': 'http://example.htm'
        }],
        'str': []
    }
def test_valid_str_data():
    browser = NtripBrowser('test', 1234)
    assert browser.get_mountpoints() == {
        'cas': [],
        'net': [],
        'str': [{
            'Carrier': 'https://example2.htm',
            'Country': 'none',
            'Distance': None,
            'Format': 'B',
            'Format-Details': 'N',
            'ID': 'Str4',
            'Mountpoint': 'Str3',
            'Nav-System': 'http://example2.htm',
            'Network': 'http://sample2'
        }]
    }
def test_valid_net_data():
    browser = NtripBrowser('test', 1234)
    assert browser._process_raw_data(testing_content.VALID_NET_NTRIP) == {
        'cas': [],
        'net': [{
            'Authentication': 'B',
            'Distance': None,
            'Fee': 'N',
            'ID': 'Str1',
            'Operator': 'Str2',
            'Other Details': 'none',
            'Web-Net': 'https://example.htm',
            'Web-Reg': 'http://sample',
            'Web-Str': 'http://example.htm'
        }],
        'str': []
    }
def test_valid_str_data():
    browser = NtripBrowser('test', 1234)
    assert browser._process_raw_data(testing_content.VALID_STR_NTRIP) == {
        'cas': [],
        'net': [],
        'str': [{
            'Carrier': 'https://example2.htm',
            'Country': 'none',
            'Distance': None,
            'Format': 'B',
            'Format-Details': 'N',
            'ID': 'Str4',
            'Mountpoint': 'Str3',
            'Nav-System': 'http://example2.htm',
            'Network': 'http://sample2'
        }]
    }
def test_valid_cas_data():
    browser = NtripBrowser('test', 1234)
    assert browser.get_mountpoints() == {
        'cas': [{
            'Country': 'Null',
            'Distance': None,
            'FallbackHost': '1.2.3.4',
            'FallbackPort': '5',
            'Host': 'example',
            'ID': 'NtripCaster',
            'Latitude': '11',
            'Longitude': '22.33',
            'NMEA': '0',
            'Operator': 'None',
            'Port': '2101',
            'Site': 'http://sample.htm'
        }],
        'net': [],
        'str': []
    }
def test_valid_cas_data():
    browser = NtripBrowser('test', 1234)
    assert browser._process_raw_data(testing_content.VALID_CAS_NTRIP) == {
        'cas': [{
            'Country': 'Null',
            'Distance': None,
            'FallbackHost': '1.2.3.4',
            'FallbackPort': '5',
            'Host': 'example',
            'ID': 'NtripCaster',
            'Latitude': '11',
            'Longitude': '22.33',
            'NMEA': '0',
            'Operator': 'None',
            'Port': '2101',
            'Site': 'http://sample.htm'
        }],
        'net': [],
        'str': []
    }
def test_add_coordinates():
    browser = NtripBrowser('test', 1234, coordinates=(1.0, 2.0))
    assert browser.get_mountpoints() == {
        'cas': [{
            'Country': 'Null',
            'Distance': 2505.0572138274565,
            'FallbackHost': '1.2.3.4',
            'FallbackPort': '5',
            'Host': 'example',
            'ID': 'NtripCaster',
            'Latitude': '11',
            'Longitude': '22.33',
            'NMEA': '0',
            'Operator': 'None',
            'Port': '2101',
            'Site': 'http://sample.htm'
        }],
        'net': [{
            'Authentication': 'B',
            'Distance': 248.57556516798113,
            'Fee': 'N',
            'ID': 'Str1',
            'Operator': 'Str2',
            'Other Details': 'none',
            'Web-Net': 'https://example.htm',
            'Web-Reg': 'http://sample',
            'Web-Str': 'http://example.htm'
        }],
        'str': [{
            'Carrier': 'https://example2.htm',
            'Country': 'none',
            'Distance': 248.57556516798113,
            'Format': 'B',
            'Format-Details': 'N',
            'ID': 'Str4',
            'Mountpoint': 'Str3',
            'Nav-System': 'http://example2.htm',
            'Network': 'http://sample2'
        }]
    }
def test_valid_data():
    browser = NtripBrowser('test', 1234)
    assert browser._process_raw_data(testing_content.VALID_NTRIP) == {
        'cas': [{
            'Country': 'Null',
            'Distance': None,
            'FallbackHost': '1.2.3.4',
            'FallbackPort': '5',
            'Host': 'example',
            'ID': 'NtripCaster',
            'Latitude': '11',
            'Longitude': '22.33',
            'NMEA': '0',
            'Operator': 'None',
            'Port': '2101',
            'Site': 'http://sample.htm'
        }],
        'net': [{
            'Authentication': 'B',
            'Distance': None,
            'Fee': 'N',
            'ID': 'Str1',
            'Operator': 'Str2',
            'Other Details': 'none',
            'Web-Net': 'https://example.htm',
            'Web-Reg': 'http://sample',
            'Web-Str': 'http://example.htm'
        }],
        'str': [{
            'Carrier': 'https://example2.htm',
            'Country': 'none',
            'Distance': None,
            'Format': 'B',
            'Format-Details': 'N',
            'ID': 'Str4',
            'Mountpoint': 'Str3',
            'Nav-System': 'http://example2.htm',
            'Network': 'http://sample2'
        }]
    }
Example #10
0
def ntripbrowser():
    global browser
    global getmp
    global flt1
    global mp_use1
    global mp_use1_km
    global mp_Carrier
    ## 2-Get caster sourcetable
    browser = (NtripBrowser(config.caster, port=config.port,
    timeout=10,coordinates=(config.rlat,config.rlon),
    maxdist=config.maxdist ))
    getmp= browser.get_mountpoints()
    flt = getmp['str']
    # Purge list
    flt1 = []
    ## filter carrier L1-L2
    flt1 = [m for m in flt if int(m['Carrier'])>=2]
    ## GET nearest mountpoint
    for i, value in enumerate(flt1):
        ## Get first row
        if i == 0 :
            ## LOG Nearest base available
            mp_use1 = value["Mountpoint"]
            mp_use1_km = value["Distance"]
            mp_Carrier = value["Carrier"]
            print(
                "INFO: Nearest base is ",mp_use1,
                round(mp_use1_km,2),"km; Carrier:",mp_Carrier)
            print(
                "INFO: Distance between Rover & connected base ",
                config.mp_use,round(config.dist_r2mp,2),"km")
            print(config.mp_use)
    ## Value on connected base
    flt_r2mp = [m for m in flt if m['Mountpoint']==config.mp_use]
    ## GET distance between rover and mountpoint used.
    for r in flt_r2mp:
        config.dist_r2mp = r["Distance"]
        config.mp_alive = r['Mountpoint']
def test_reassign_parameters():
    browser = NtripBrowser('example', 1234)
    assert [
        'http://example:1234',
        'http://example:1234/sourcetable.txt',
        'https://example:1234',
        'https://example:1234/sourcetable.txt',
    ] == browser.urls
    browser.host = 'http://sample'
    browser.port = 4321
    assert [
        'http://sample:4321',
        'http://sample:4321/sourcetable.txt',
        'https://sample:4321',
        'https://sample:4321/sourcetable.txt',
    ] == browser.urls
    browser.host = 'https://eg'
    browser.port = 123
    assert [
        'http://eg:123',
        'http://eg:123/sourcetable.txt',
        'https://eg:123',
        'https://eg:123/sourcetable.txt',
    ] == browser.urls
def test_invalid_data():
    browser = NtripBrowser('example', 1234)
    with pytest.raises(NoDataReceivedFromCaster):
        browser.get_mountpoints()
def run_caster_test(caster):
    browser = NtripBrowser(caster.url, caster.port)
    try:
        browser.get_mountpoints()
    except (UnableToConnect, ExceededTimeoutError, HandshakeFiledError):
        pass
def test_invalid_data():
    browser = NtripBrowser('example', 1234)
    with pytest.raises(NoDataReceivedFromCaster):
        browser._process_raw_data(b'<Some invalid NTRIP data>')