예제 #1
0
        //################      Public Methods     ##################
        /// <summary>
        /// Check and change input's mac addresses and signals with the Fingerprint's mac addresses and signal ranges
        /// <para>For each successive changes to the range, the value returned will increase</para>
        /// <para>Returns 0 if no mac address ranges has been changed</para>
        /// <para>Uses the following functions: MacTable.AddMac</para>
        /// </summary>
        /// <param name="MAddress">array of Mac Address, EG:"M1,20,M2,20...M10,20"</param>
        /// <returns></returns>
        public int FingCalibrate(string[] MAddress)
        {
            lock (MacStack)
            {
                lock (SigRange)
                {
                    int Calibrated = 0;
                    int macIndex, macLoc;

                    bool valueFound = false;

                    for (int i = 0; i < MAddress.Length; i = i + 2)
                    {
                        valueFound = Macs.TryGetValue(MAddress[i], out macIndex);

                        if (valueFound)
                        {
                            Calibrated += SigCalibrate(macIndex, Convert.ToInt16(MAddress[i + 1]));
                        }
                        else if (MacStack.Count != 0)
                        {
                            if (MacTable.AddMac(MAddress[i], MacTable.GetFingObject(FName)))
                            {
                                macLoc = MacStack.Pop();
                                Macs.Add(MAddress[i], macLoc);
                                SigRange[macLoc, 0] = SigRange[macLoc, 1] = Convert.ToInt16(MAddress[i + 1]);
                                Calibrated++;
                            }
                        }
                    }
                    return(Calibrated);
                }
            }
        }
예제 #2
0
 public MainWindow()
 {
     MT = new MacTable();
     CH = new ClientHandler();
     TS = new TCPserver();
     InitializeComponent();
 }
예제 #3
0
        private void BSave_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Are you sure you want to save?", "Save", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.No);
            if (result == MessageBoxResult.Yes)
            {
                Stopwatch timing = new Stopwatch();

                timing.Start();
                int count = MacTable.Save();
                timing.Stop();

                Console.WriteLine("Time taken to save {0} commands is {1} seconds", count, (float)timing.ElapsedMilliseconds / 1000);
            }
            else
                return;
        }
예제 #4
0
        private void BLoad_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Are you sure you want to load?", "Load", MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.Yes)
            {
                Stopwatch timing = new Stopwatch();

                timing.Start();
                int count = MacTable.Load();
                timing.Stop();

                if (!(count < 0))
                    Console.WriteLine("Time taken to load {0} commands is {1} seconds", count, (float)timing.ElapsedMilliseconds / 1000);
                else
                    Console.WriteLine("\nLoad Failed");
            }
            else
                return;
        }
예제 #5
0
        public static string Parse(string input)
        {
            input.TrimEnd(' ');
            input = input.Replace("\r\n", "");
            string[] split = input.Split(',');
            string   Fname, result;

            string[] XY, mac;


            switch (split[0].ToLower())
            {
            case "addfing":
                int addResult;
                Fname = split[1];
                XY    = new string[] { split[2], split[3] };
                mac   = new string[split.Length - 4];

                for (int i = 0; (i + 4) < split.Length; i++)
                {
                    mac[i] = split[i + 4];
                }

                result = MacTable.ScanLocation(mac, Precision);

                if (result.CompareTo("NULL") == 0)
                {
                    addResult = MacTable.AddFing(Fname, XY, mac);

                    if (addResult == 0)
                    {
                        result = string.Format("Successfully added the fingerprint: {0}", Fname);
                    }
                    else
                    {
                        result = string.Format("Failed to add fingerprint: {0}, the name is being used!", Fname);
                    }
                }
                else
                {
                    result = string.Format("Fingerprint {0} collision with current add attempt", result);
                }

                return(result);

            case "delfing":
                Fname = split[1];
                if (MacTable.DelFing(Fname) == 0)
                {
                    result = string.Format("Deleted Fingerprint: {0}", Fname);
                }
                else
                {
                    result = string.Format("Failed to delete Fingerprint: {0}, Fingerprint does not exist!", Fname);
                }
                return(result);

            case "calibrate":
                int Calibration;
                Fname = split[1];
                mac   = new string[split.Length - 2];

                for (int i = 0; (i + 2) < split.Length; i++)
                {
                    mac[i] = split[i + 2];
                }

                Calibration = MacTable.CalibrateFing(Fname, mac);

                if (Calibration != -1)
                {
                    result = string.Format("Calibrated {0} signal range for Fingerprint: {1}", Calibration, Fname);
                }
                else
                {
                    result = "Fingerprint not found";
                }

                return(result);

            case "recalibrate":
                int Calibration2;
                Fname = split[1];
                mac   = new string[split.Length - 2];

                for (int i = 0; (i + 2) < split.Length; i++)
                {
                    mac[i] = split[i + 2];
                }

                Calibration2 = MacTable.RecalibrateFing(Fname, mac);

                if (Calibration2 != -1)
                {
                    result = string.Format("Recalibrated {0} signal range for Fingerprint: {1}", Calibration2, Fname);
                }
                else
                {
                    result = "Fingerprint not found";
                }

                return(result);

            case "locate":
                mac = new string[split.Length - 1];

                for (int i = 0; (i + 1) < split.Length; i++)
                {
                    mac[i] = split[i + 1];
                }

                if (mac.Length >= 6)
                {
                    result = MacTable.ScanLocation(mac, Precision);
                }
                else
                {
                    result = "DeadZone";
                }

                return(result);

            case "addblack":
                if (split.Length > 1)
                {
                    if (MacTable.BlacklistMac(split[1]))
                    {
                        result = string.Format("Successfully added Mac Address \"{0}\" into blacklist", split[1]);
                    }
                    else
                    {
                        result = string.Format("Mac Address \"{0}\" already exist in the blacklist", split[1]);
                    }
                }
                else
                {
                    result = ("Empty name detected!");
                }
                return(result);

            case "delblack":
                if (split.Length > 1)
                {
                    if (MacTable.WhitelistMac(split[1]))
                    {
                        result = string.Format("Successfully removed Mac Address \"{0}\" from blacklist", split[1]);
                    }
                    else
                    {
                        result = string.Format("Mac Address \"{0}\" does not exist in the blacklist", split[1]);
                    }
                }
                else
                {
                    result = ("Empty name detected!");
                }
                return(result);

            case "emergency":
                Fname = split[1];
                XY    = new string[] { split[2], split[3] };
                return(string.Format("Broadcast,{0},{1},{2}", Fname, XY[0], XY[1]));

            case "remergency":
                return("Not Implemented yet");

            default:
                Console.WriteLine(">>Parser received unknown command");
                Console.WriteLine(input);
                return("ERROR");
            }
        }