示例#1
0
        static void ConfigPrompt()
        {
            Connection.Send(new byte[] { IAC, DO, ECHO });
            Connection.Send(new byte[] { IAC, WONT, ECHO });    // Turn client echo on
            SendData("\r\nMiniGate Console\n\r\n");
            while (IsConnected())
            {
                SendData("cmd: ");
                string   InFull = GetInput();
                string[] InCmd  = InFull.Split(' ');
                switch (InCmd[0].ToUpper())
                {
                case "QUIT":
                case "EXIT":
                    return;

                case "DISP":
                    string Mon = "";
                    if (RFMonEnable)
                    {
                        Mon = "ON";
                    }
                    else
                    {
                        Mon = "OFF";
                    }
                    SendData("MONITOR: " + Mon + "\r\n");
                    SendData("MYCALL: " + MiniGate.FullCall + "\r\n");
                    SendData("APRSSRV: " + APRSIS.Server + ":" + APRSIS.Port + "\r\n");
                    SendData("APRSPASS: "******"\r\n");
                    SendData("MYIP: " + MiniGate.eth[0].IPAddress +
                             " GW: " + MiniGate.eth[0].GatewayAddress +
                             " SN: " + MiniGate.eth[0].SubnetMask + "\r\n");
                    SendData("DNSSRV: ");
                    for (int i = 0; i < MiniGate.eth[0].DnsAddresses.Length; i++)
                    {
                        SendData(MiniGate.eth[0].DnsAddresses[i] + "\r\n");
                    }
                    SendData("TXDELAY: " + Packet.TXDelay.ToString() + "\r\n");
                    SendData("BTEXT: " + Beacon.BText + "\r\n");
                    SendData("BINTERVAL: " + Beacon.Interval.ToString() + "\r\n");
                    break;

                case "MON":
                case "MONITOR":
                    if (InCmd.Length == 2)
                    {
                        RFMon(InCmd[1].ToUpper());
                    }
                    else
                    {
                        SendData("?\r\n");
                    }
                    break;

                case "MYCALL":
                    if (InCmd.Length == 2)
                    {
                        ChangeCall(InCmd[1]);
                        break;
                    }
                    if (InCmd.Length == 1)
                    {
                        SendData(MiniGate.FullCall + "\r\n");
                        break;
                    }
                    SendData("?\r\n");
                    break;

                case "APRSSRV":
                    if (InCmd.Length == 2)
                    {
                        ChangeAPRSSrv(InCmd[1]);
                        break;
                    }
                    if (InCmd.Length == 1)
                    {
                        SendData(APRSIS.Server + ":" + APRSIS.Port + "\r\n");
                        break;
                    }
                    SendData("?\r\n");
                    break;

                case "APRSPASS":
                    if (InCmd.Length == 2)
                    {
                        try
                        {
                            APRSIS.Pass = int.Parse(InCmd[1]);
                            Config.Write("aprsis.pass", InCmd[1]);
                            break;
                        }
                        catch       // User must not have entered an integer
                        { }
                    }
                    if (InCmd.Length == 1)
                    {
                        break;
                    }
                    SendData("?\r\n");
                    break;

                case "DHCP":
                    break;

                case "MYIP":
                    SendData("IP: " + MiniGate.eth[0].IPAddress + "\r\n" +
                             "GW: " + MiniGate.eth[0].GatewayAddress + "\r\n" +
                             "SN: " + MiniGate.eth[0].SubnetMask + "\r\n");
                    break;

                case "DNSSRV":
                    for (int i = 0; i < MiniGate.eth[0].DnsAddresses.Length; i++)
                    {
                        SendData(MiniGate.eth[0].DnsAddresses[i] + "\r\n");
                    }
                    break;

                case "TXD":
                case "TXDELAY":
                    if (InCmd.Length == 2)
                    {
                        try
                        {
                            Packet.TXDelay = int.Parse(InCmd[1]);
                            Config.Write("stn.txdelay", InCmd[1]);
                            break;
                        }
                        catch           // User must not have entered an integer
                        {
                            SendData("?\r\n");
                            break;
                        }
                    }
                    if (InCmd.Length == 1)
                    {
                        SendData(Packet.TXDelay.ToString() + "\r\n");
                        break;
                    }
                    SendData("?\r\n");
                    break;

                case "PASSWD":
                    if (InCmd.Length > 1)
                    {
                        Config.Write("telnet.pass", InFull.Substring(InCmd[0].Length + 1));
                        TelnetServer.Pass = InFull.Substring(InCmd[0].Length + 1);
                        break;
                    }
                    SendData("?\r\n");      // We're not gonna tell you the password...
                    break;

                case "BTEXT":
                    if (InCmd.Length > 1)
                    {
                        Config.Write("stn.btext", InFull.Substring(InCmd[0].Length + 1));
                        Beacon.BText = InFull.Substring(InCmd[0].Length + 1);
                        break;
                    }
                    SendData(Beacon.BText + "\r\n");
                    break;

                case "BINT":
                case "BINTERVAL":
                    if (InCmd.Length == 2)
                    {
                        try
                        {
                            Beacon.Interval = int.Parse(InCmd[1]);
                            Config.Write("stn.binterval", InCmd[1]);
                            break;
                        }
                        catch       // User must not have entered an integer
                        {
                            SendData("?\r\n");
                            break;
                        }
                    }
                    if (InCmd.Length == 1)
                    {
                        SendData(Beacon.Interval.ToString() + "\r\n");
                        break;
                    }
                    SendData("?\r\n");
                    break;

                case "PATH":
                    break;

                case "VOLT":
                    SendData(Toolbox.GetVin() + "\r\n");
                    break;

                default:
                    SendData("?\r\n");
                    break;
                }
            }
        }
示例#2
0
 public static void SendISBeacon()
 {
     APRSIS.SendData(MiniGate.FullCall + ">" + MiniGate.MiniGateDest + ",TCPIP*:" + BText + " " + Toolbox.GetVin() + "\r\n");
 }
示例#3
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;
        }