コード例 #1
0
def to_cot(aprs_frame):
    decoded_ll = decode_ll(aprs_frame.text)
    if decoded_ll is None:
        return

    my_point = pycot.Point()
    my_point.lat = decoded_ll[0]
    my_point.lon = decoded_ll[1]
    my_point.ce = '1'
    my_point.le = '1'
    my_point.hae = '1'

    evt = pycot.Event()
    evt.version = '2.0'
    evt.event_type = 'a-.-G-E-V-C'
    evt.uid = 'APRS.%s' % aprs_frame.source
    evt.time = datetime.datetime.now()
    evt.how = 'h-e'
    evt.point = my_point

    print(evt.render(standalone=True))
    #evt_bytes = str.encode(evt.render(standalone=True))
    evt_bytes = evt.render(standalone=True)
    print(evt_bytes)

    addr1 = ('192.168.99.140', 8087)
    #addr2 = ('192.168.99.140', 18999)
    addr3 = ('192.168.10.74', 18999)

    cot_int = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    cot_int.sendto(evt_bytes, addr1)
    #cot_int.sendto(evt_bytes, addr2)
    cot_int.sendto(evt_bytes, addr3)
コード例 #2
0
ファイル: functions.py プロジェクト: joshuafuller/aprscot
def aprs_to_cot(aprs_frame):
    """
    Converts an APRS Frame to a Cursor-on-Target Event.
    """
    lat = aprs_frame.get('latitude')
    lng = aprs_frame.get('longitude')
    if not lat or not lng:
        return

    point = pycot.Point()
    point.lat = lat
    point.lon = lng
    point.ce = '10'
    point.le = '10'
    point.hae = '10'

    event = pycot.Event()
    event.version = '1.0'
    event.event_type = 'a-f-G-E-V-C'
    event.uid = 'APRS.%s' % aprs_frame['from']
    event.time = datetime.datetime.now()
    event.how = 'h-e'
    event.point = point

    return event
コード例 #3
0
def spot_to_cot(response, stale: int = None) -> pycot.Event:
    """
    Converts an Spot Response to a Cursor-on-Target Event.
    """
    message = response["feedMessageResponse"]["messages"]["message"][0]

    #    time = datetime.datetime.now(datetime.timezone.utc)
    time = datetime.datetime.fromtimestamp(message["unixTime"])
    stale = stale or spotcot.DEFAULT_STALE

    lat = message.get("latitude")
    lon = message.get("longitude")

    if lat is None or lon is None:
        return None

    cot_type = "a-.-G-E-V-C"
    name = message.get("messengerName")
    callsign = name

    point = pycot.Point()
    point.lat = lat
    point.lon = lon
    point.ce = "9999999.0"
    point.le = "9999999.0"
    point.hae = "9999999.0"

    uid = pycot.UID()
    uid.Droid = name

    contact = pycot.Contact()
    contact.callsign = callsign

    remarks = pycot.Remarks()
    _remarks = (f"batteryState: {message.get('batteryState')} "
                f"messengerId: {message.get('messengerId')} "
                f"modelId: {message.get('modelId')}")
    remarks.value = _remarks

    detail = pycot.Detail()
    detail.uid = uid
    detail.contact = contact
    detail.remarks = remarks

    event = pycot.Event()
    event.version = "2.0"
    event.event_type = cot_type
    event.uid = f"Spot.{name}"
    event.time = time
    event.start = time
    event.stale = time + datetime.timedelta(seconds=stale)
    event.how = "m-g"
    event.point = point
    event.detail = detail

    return event
コード例 #4
0
ファイル: functions.py プロジェクト: nconder/spotcot
def spot_to_cot(message: spot_sdk.Message) -> pycot.Event:
    """
    Converts an Spot Message to a Cursor-on-Target Event.

    :param message: Spot Message to convert to CoT.
    :type message: `spot_sdk.Message`
    """
    time = datetime.datetime.now()

    lat = message.__getattribute__('latitude')
    lon = message.__getattribute__('longitude')

    if lat is None or lon is None:
        return None

    print(message.raw)
    name = message.raw.get('messengerName')

    point = pycot.Point()
    point.lat = lat
    point.lon = lon
    point.ce = '10'
    point.le = '10'
    point.hae = '10'

    uid = pycot.UID()
    uid.Droid = name

    detail = pycot.Detail()
    detail.uid = uid

    event = pycot.Event()
    event.version = '2.0'
    event.event_type = 'a-f-G-E-V-C'
    event.uid = f"Spot.{name}"
    event.time = time
    event.start = time
    event.stale = time + +datetime.timedelta(hours=1)  # 1 hour expire
    event.how = 'h-e'
    event.point = point
    event.detail = detail

    return event
コード例 #5
0
ファイル: functions.py プロジェクト: nconder/aiscot
def ais_to_cot(ais_sentence: dict) -> pycot.Event:
    """
    Converts an AIS Sentence to a Cursor-on-Target Event.

    :param ais_sentence: AIS Sentence to convert to CoT.
    :type ais_sentence: `dict`
    """
    time = datetime.datetime.now()

    lat = ais_sentence.get('y')
    lon = ais_sentence.get('x')
    mmsi = ais_sentence.get('mmsi')

    if lat is None or lon is None or mmsi is None:
        return None

    point = pycot.Point()
    point.lat = lat
    point.lon = lon
    point.ce = '10'
    point.le = '10'
    point.hae = '10'

    uid = pycot.UID()
    uid.Droid = ais_sentence.get('name', mmsi)

    detail = pycot.Detail()
    detail.uid = uid

    event = pycot.Event()
    event.version = '2.0'
    event.event_type = 'a-f-G-E-V-C'
    event.uid = f"AIS.{mmsi}"
    event.time = time
    event.start = time
    event.stale = time + +datetime.timedelta(hours=1)  # 1 hour expire
    event.how = 'h-e'
    event.point = point
    event.detail = detail

    return event
コード例 #6
0
def hello_event():
    time = datetime.datetime.now(datetime.timezone.utc)
    name = 'adsbcot'
    callsign = 'adsbcot'

    point = pycot.Point()
    point.lat = 0.0
    point.lon = 0.0

    # FIXME: These values are static, should be dynamic.
    point.ce = '9999999.0'
    point.le = '9999999.0'
    point.hae = '9999999.0'

    uid = pycot.UID()
    uid.Droid = name

    contact = pycot.Contact()
    contact.callsign = callsign

    detail = pycot.Detail()
    detail.uid = uid
    detail.contact = contact

    event = pycot.Event()
    event.version = '2.0'
    event.event_type = 'a-u-G'
    event.uid = name
    event.time = time
    event.start = time
    event.stale = time + datetime.timedelta(hours=1)
    event.how = 'h-g-i-g-o'
    event.point = point
    event.detail = detail

    return event
コード例 #7
0
def adsb_to_cot(
        craft: dict,
        cot_type: str = None,  # NOQA pylint: disable=too-many-locals
        stale: int = None) -> pycot.Event:
    """
    Transforms a Dump1090 ADS-B Aircraft Object to a Cursor-on-Target PLI.
    """
    time = datetime.datetime.now(datetime.timezone.utc)
    stale = stale or adsbcot.constants.DEFAULT_STALE

    lat = craft.get("lat")
    lon = craft.get("lon")

    if lat is None or lon is None:
        return None

    icao_hex = craft.get("hex", "").upper()
    if not icao_hex:
        return None

    name = f"ICAO-{icao_hex}"

    flight = craft.get("flight", "").strip()
    if flight:
        callsign = flight
    else:
        callsign = icao_hex

    cot_type = pytak.faa_to_cot_type(craft.get("hex"), craft.get("category"),
                                     flight)

    point = pycot.Point()
    point.lat = lat
    point.lon = lon
    point.ce = craft.get('nac_p', '9999999.0')
    point.le = craft.get('nac_v', '9999999.0')

    # alt_geom: geometric (GNSS / INS) altitude in feet referenced to the
    #           WGS84 ellipsoid
    alt_geom = int(craft.get('alt_geom', 0))
    if alt_geom:
        point.hae = alt_geom * 0.3048
    else:
        point.hae = '9999999.0'

    uid = pycot.UID()
    uid.Droid = name

    contact = pycot.Contact()
    contact.callsign = callsign

    track = pycot.Track()
    track.course = craft.get('track', '9999999.0')

    # gs: ground speed in knots
    gs = int(craft.get("gs", 0))
    if gs:
        track.speed = gs * 0.514444
    else:
        track.speed = "9999999.0"

    remarks = pycot.Remarks()
    _remarks = f"Squawk: {craft.get('squawk')} Category: {craft.get('category')}"

    if flight:
        _remarks = f"{icao_hex}({flight}) {_remarks}"
    else:
        _remarks = f"{icao_hex} {_remarks}"

    if bool(os.environ.get('DEBUG')):
        _remarks = f"{_remarks} via adsbcot"

    remarks.value = _remarks

    detail = pycot.Detail()
    detail.uid = uid
    detail.contact = contact
    detail.track = track
    detail.remarks = remarks

    event = pycot.Event()
    event.version = "2.0"
    event.event_type = cot_type
    event.uid = name
    event.time = time
    event.start = time
    event.stale = time + datetime.timedelta(seconds=stale)
    event.how = "m-g"
    event.point = point
    event.detail = detail

    return event