Exemple #1
0
def print_frame3(f):
    print("Raw Frame={}".format(f[1:]))

    pf = aprs.parse_frame(f)
    src = pf.source.callsign.decode(encoding='UTF-8')
    dst = pf.destination.callsign.decode(encoding='UTF-8')
    path = pf.path
    info = pf.info.data.decode('UTF-8')
    info = info.replace("\n","")
    info = info.replace("\r","")
    info = info.replace("\t","")

    print("Src:  [%s]" % src)
    print("Dst:  [%s]" % dst)
    print("Path: [%s]" % path)
    print("(PRE) Info: [%s]" % info)

    mf=""
    mt=""
    msg=""
    mid=""

    # FROM     }N0CALL-8>
    # PATH     >APRS,TCPIP,N6KMA*::
    # TO       ::N0CALL-11:
    # MESSAGE  (last-index-of):This is message 461 {
    # MSG_ID   {461$

    a=b=c=d=e=0

    try:
        a = info.index("}")
        b = info.index(">")
        c = info.index(":")+1
        d = info[c+1:].index(":")+c+1
        e = info.index("{")
    except:
        pass

    if d > 0:
        mf = info[a+1:b]
        mt = info[c+1:d]
        msg = info[d+1:e]
        mid = info[e+1:]


    print("\nINFO:      [%s]\n" % info)
    print("MSG-FROM   [%s]" % mf)
    mt = mt.strip()
    print("MSG-TO     [%s]" % mt)
    print("MSG        [%s]" % msg)
    print("MSG_ID     [%s]" % mid)

    print("\n")
Exemple #2
0
    def send(self, frame: bytes) -> bool:
        """
        Sends frame to APRS-IS.

        :param frame: Frame to send to APRS-IS.
        :type frame: str
        """
        if isinstance(frame, str):
            frame = aprs.parse_frame(frame)
        if isinstance(frame, aprs.Frame):
            frame = bytes(frame)
        self._logger.info('Sending frame="%s"', frame)
        content = b"\n".join([self._auth, frame])
        result = self.interface(self.url, data=content, headers=self.headers)
        return result.status_code == 204
Exemple #3
0
    def process_frame(self, frame):
        """
        Process an incoming frame according to configured options.
        """

        frame_dict = {}

        # If we're in debug mode...
        if self.__debug:
            print("Incoming frame:")
            self.hexdump(frame)
            print("")

        frame_base64 = "%s" % base64.standard_b64encode(frame).decode()
        frame_dict.update({'frame_base64': frame_base64})

        try:
            aprs_parsed = "%s" % aprs.parse_frame(frame)
            frame_dict.update(aprslib.parse(aprs_parsed))

        except ValueError:
            frame_dict.update({'parse_error_message': "ValueError"})

        except aprslib.exceptions.ParseError:
            frame_dict.update({'parse_error_message': "ParseError"})

        except aprslib.exceptions.UnknownFormat:
            frame_dict.update({'parse_error_message': "UnknownFormat"})

        # Ugly AF, we really don't want to be doing this.
        try:
            self.__m.publish(self.__mqtt_rx_topic, json.dumps(frame_dict))

        except (KeyboardInterrupt, SystemExit):
            raise

        except:
            print(traceback.format_exc())
            self.__mqtt_connect()
Exemple #4
0
def process_frame(f):
    global CALLSIGN

    #print("Raw Frame={}".format(f[1:]))

    src=""
    dst=""
    path=""
    info=""

    try:
        pf = aprs.parse_frame(f)
        src = pf.source.callsign.decode(encoding='UTF-8')
        dst = pf.destination.callsign.decode(encoding='UTF-8')
        path = pf.path
        #info = pf.info 	# THIS IS AN OBJECT, NOT A STRING! >:{
        try:
            info = pf.info.data.decode('UTF-8')	# This is stringified object ;)
            info = info.replace("\n","")
            info = info.replace("\r","")
            info = info.replace("\t","")
        except:
            # In case we can't convert data
            info=""
            pass
    except:
        # In case frame can't be parsed
        pass

    #print("Src:  [%s]" % src)
    #print("Dst:  [%s]" % dst)
    #print("Path: [%s]" % path)
    #print("Info: [%s]" % info)

    #print("Src:[%s]  Dst:[%s]  Path:[%s]  Info:[%s]" % (src,dst,path,info))

    # Start with frame from/to/info and message id of zero
    mf=src
    mt=dst
    msg=info
    mid="0"

    try:
        # First, try parsing the entire thing, just to ensure it's in the correct format
        # m1 = re.search(r'}.*>.*::.*:.*{.*', info) # This format REQUIRES a message ID
        m1 = re.search(r'}.*>.*::.*:.*', info)	    # This format DOES NOT require a message ID
        m2 = re.search(r':.*:.*', info)	    # This format DOES NOT require a message ID
        if m1:
            # Try parsing "from" using close-curly-brace format
            m1 = re.search(r'}(.+?)>', info)
            if m1:
                # Found close-curly-brace, so use this field as FROM
                mf = m1.group(1)
            else:
                # Didn't have close-curly-brace, so use PACKET SOURCE as FROM
                mf = src
        else:
            if m2:
                m3 = re.search(r':(.+?):', info)
                if m3:
                    mt = m3.group(1)

        if m1 or m2:
            m1 = re.search(r'::(.+?):', info)
            if m1:
                mt = m1.group(1)

            m1 = re.search(r':.*:(.+?){', info)
            if m1:
                msg = m1.group(1)
            else:
                m2 = re.search(r':.*:(.+?)$', info)
                if m2:
                    msg = m2.group(1)

            m1 = re.search(r'{(.+?)$', info)
            if m1:
                mid = m1.group(1)

    except:
        pass

    #print("MSG-FROM   [%s]" % mf)
    mt = mt.strip()
    #print("MSG-TO     [%s]" % mt)
    #print("MSG        [%s]" % msg)
    #print("MSG_ID     [%s]" % mid)

    # The message might have <CR> in it, so print it last on the line
    if not mf == "" and not mt == "":
        # '2019-05-21 07:15:58'
        ahora = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
        print("%s %-9s > %-9s ID: %3s  MSG[%s]" % (ahora,mf,mt,mid,msg), flush=True)

    # If message is TO payload, ack it and send a response
    if (not mid == "") and (mt == CALLSIGN):
        try:
            #print("DEBUG: Calling ackmsg...")
            subprocess.run(["/home/direwolf/ackmsg", mt, mf, mid, msg])
            #print("DEBUG: Back from calling ackmsg...")
        except:
            print("DEBUG: *EXCEPTION* while trying to call ackmsg!")
            pass
import aprs
#pip install aprs
frame = aprs.parse_frame('ZR6AIC>APRS:>Hello World!')

a = aprs.TCP('ZR6AIC', '12345')
a.start()

a.send(frame)