Esempio n. 1
0
 public static void SendISBeacon()
 {
     APRSIS.SendData(MiniGate.FullCall + ">" + MiniGate.MiniGateDest + ",TCPIP*:" + BText + " " + Toolbox.GetVin() + "\r\n");
 }
Esempio n. 2
0
        private static void Parse()                   // Where most of the packet decoding magic happens
        {
            if (bytes > 17)                           // If the packet is less than 18 bytes, it's obviously broken, so don't even bother.
            {
                ushort CalcFCS = 0xFFFF;              // We will check the FCS before going on

                for (int i = 0; i < (bytes - 2); i++) // Loop thru all bytes in the packet except the FCS field
                {
                    byte inbyte = indata[i];
                    for (int k = 0; k < 8; k++)                       // Loop thru all 8 bits in this byte
                    {
                        bool inbit  = ((inbyte & 0x01) == 0x01);      // Grab the LSB of the current byte
                        bool fcsbit = ((CalcFCS & 0x0001) == 0x0001); // Grab the LSB of the current FCS value
                        CalcFCS >>= 1;                                // Shift the current FCS value one bit right
                        if (fcsbit != inbit)
                        {
                            CalcFCS = (ushort)(CalcFCS ^ 0x8408); // If the LSB of this byte and the bit that was shifted off the FCS don't match, XOR the FCS with 0x8408
                        }
                        inbyte >>= 1;                             // Shift this byte right to get ready for the next bit
                    }
                }
                CalcFCS = (ushort)(CalcFCS ^ 0xFFFF);      // XOR The FCS with 0xFFFF

                if ((indata[bytes - 1] == (CalcFCS >> 8)) && (indata[bytes - 2] == (CalcFCS & 0xFF)))
                {
                    int      NumCalls  = 0;
                    byte[][] Callsigns = new byte[10][];
                    byte[]   SSIDs     = new byte[10];
                    bool[]   HBit      = new bool[10];
                    string   Via       = "";

                    for (int i = 0; i <= 9; i++)
                    {
                        Callsigns[i] = new byte[6];     // Initialize "jagged" callsign array
                    }

                    for (int a = 0; a <= 9; a++)    // Loop through up to 10 callsigns in the address field
                    {
                        NumCalls++;

                        for (int i = 0; i <= 5; i++)
                        {
                            Callsigns[a][i] = (byte)(indata[((a * 7) + i)] >> 1);   // Get the byte for each letter of this call, and shift it right one bit
                        }

                        SSIDs[a] = (byte)((indata[((a + 1) * 7) - 1] & 0x1E) >> 1); // Get the SSID of this call (bits 4-1 of the last octect of this call)
                        HBit[a]  = ((indata[((a + 1) * 7) - 1] & 0x80) == 0x80);    // See if the "H bit" of this SSID octet is set (indicates if this digi slot has been used)

                        if ((indata[((a + 1) * 7) - 1] & 0x01) == 0x01)
                        {
                            break;                                                  // Exit the loop if this is the last call in the address field
                        }
                    }

                    if ((indata[NumCalls * 7] == 0x03) && (indata[(NumCalls * 7) + 1] == 0xF0))     // Don't bother going on if this isn't a UI packet
                    {                                                                               // We'd check this sooner, but need to know where these bytes are in the packet first
                        if (NumCalls > 2)
                        {
                            Via = ",";
                            for (int i = 2; i < NumCalls; i++)
                            {
                                string Callsign = new String(Toolbox.Bytes2Chars(Callsigns[i]));
                                Via = Via + Callsign.Trim();
                                if (SSIDs[i] != 0x00)
                                {
                                    Via = Via + "-" + SSIDs[i].ToString();                      // Only add the SSID if it's not zero
                                }
                                if (HBit[i])
                                {
                                    Via = Via + "*";            // Add a "*" if this digi slot has been used
                                }
                                if ((i + 1) < NumCalls)
                                {
                                    Via = Via + ",";                        // Add a "," if there are more digi's in the list
                                }
                            }
                        }
                        string Source = new String(Toolbox.Bytes2Chars(Callsigns[1]));
                        Source = Source.Trim();
                        if (SSIDs[1] != 0x00)
                        {
                            Source = Source + "-" + SSIDs[1].ToString();
                        }
                        string Dest = new String(Toolbox.Bytes2Chars(Callsigns[0]));
                        Dest = Dest.Trim();
                        if (SSIDs[0] != 0x00)
                        {
                            Dest = Dest + "-" + SSIDs[0].ToString();
                        }
                        string Payload = new String(Toolbox.Bytes2Chars(Utility.ExtractRangeFromArray(indata, (NumCalls * 7) + 2, bytes - (NumCalls * 7) - 4)));
                        if (Via.IndexOf("TCPIP") == -1 && Via.IndexOf("TCPXX") == -1)
                        {
                            APRSIS.SendData(Source + ">" + Dest + Via + ",qAR," + MiniGate.FullCall + ":" + Payload + "\r\n");
                        }
                        if (TelnetServer.RFMonEnable)
                        {
                            TelnetServer.SendData(Source + ">" + Dest + Via + ":" + Payload + "\r\n");
                        }
                    }
                }
            }
            Array.Clear(indata, 0, bytes + 1);
            bytes = 0;
        }