private void phasingMSRdata(byte valData)
        {
            byte val1 = 0x02;
            byte val2 = valData;

            /*
             * valData 별 MSR 타입과 데이터 길이
             * 1. 0x43
             *   a. 12T  = prefix(2) + other_prefix(3) + data(76) + postfix(4) = 2 + 83
             *   b. 23T  = prefix(2) + other_prefix(3) + data(37) + postfix(4) = 2 + 44
             *   c. 123T = prefix(2) + other_prefix(3) + data(76) + postfix(4) = 2 + 83
             *
             * 2. 0x44
             *   a. 12T  = prefix(2) + other_prefix(3) + data(37) + postfix(3)  = 2 + 43
             *   b. 23T  = prefix(2) + other_prefix(3) + data(104) + postfix(3) = 2 + 110
             *   c. 123T = prefix(2) + other_prefix(3) + data(37) + postfix(3)  = 2 + 43
             *
             * 3. 0x45
             *   a. 12T  = prefix(2) + other_prefix(4) + data(76) + gap(1) + data(37) + postfix(4)  = 2 + 122
             *   b. 23T  = prefix(2) + other_prefix(4) + data(37) + gap(1) + data(104) + postfix(4) = 2 + 150
             *   c. 123T = prefix(2) + other_prefix(4) + data(76) + gap(1) + data(37) + postfix(4)  = 2 + 122
             *
             * 4. 0x46 (123T only)
             *   a. 123T = prefix(2) + other_prefix(4)
             + data(76) + gap(1) + data(37) + gap(1)
             + data(104) + postfix(4)
             +              = 2 + 227
             *
             * 5. 0x47 (123T only)
             *   a. 123T = prefix(2) + other_prefix(3) + data(104) + postfix(3) = 2 + 110
             */

            byte[] containedData = new byte[2 + que.getUseSpace()];
            containedData[0] = val1;
            containedData[1] = val2;
            int cnt = que.getUseSpace();

            byte[] test = que.DeQueue(cnt);
            Buffer.BlockCopy(test, 0, containedData, 2, test.Length);

            BTMessage data = new BTMessage();

            data.type   = BTMessage.MSR_Response_Type;
            data.length = containedData.Length;
            data.data   = containedData;

            RecvMessage(this, data);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            /*string str;
             * int count;
             * TimerManager manager = new TimerManager();
             * Person p = new Person("Jon", manager);
             * Person a = new Person("Joe", manager);
             * Person b = new Person("Jeffrey", manager);
             *
             * System.Console.WriteLine("Enter the count of seconds:");
             * do
             * {
             *  str = System.Console.ReadLine();
             *
             * } while (!Int32.TryParse(str,out count));
             *
             * manager.SimulateTimer(count*1000);
             */
            CustomQueue <int> queue = new CustomQueue <int>();

            queue.EnQueue(1);
            queue.EnQueue(5);
            queue.EnQueue(10);
            WriteQueue(queue);
            queue.DeQueue();
            WriteQueue(queue);


            System.Console.ReadKey();

            foreach (int number in FibonacciNumbers.GetNubers(10))
            {
                System.Console.WriteLine(number);
            }

            System.Console.ReadKey();
            foreach (int number in FibonacciNumbers.GetNubers(5))
            {
                System.Console.WriteLine(number);
            }

            System.Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // create some test data for the stack and the queue
            string[] text = new string[3];
            text[0] = "De eerste string";
            text[1] = "De tweede string";
            text[2] = "De derde string";

            #region CustomStack test

            Console.WriteLine("CustomStack test (LIFO)");
            // create a stack of the type string
            CustomStack <string> stack = new CustomStack <string>();
            // add the strings to the stack
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                stack.Push(text[i]);
            }

            // remove and show the order of removed items
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                Console.WriteLine("- " + stack.Pop());
            }

            #endregion

            Console.WriteLine();

            #region CustomQueue test

            Console.WriteLine("CustomQueue test (FIFO)");
            // create a generic questom queue
            CustomQueue <string> queue = new CustomQueue <string>();
            // add items to the queue
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                queue.EnQueue(text[i]);
            }

            // remove the items and show the position
            for (int i = 0; i <= text.GetUpperBound(0); i++)
            {
                Console.WriteLine("- " + queue.Peek());
                queue.DeQueue();
            }

            #endregion

            Console.WriteLine();

            #region CustomPriorityQueue test

            Console.WriteLine("CustomPriorityQueue");
            // create a CustomPriorityQueue to simulate a waiting room for patients
            // where priority 0 is first
            CustomPriorityQueue waitingRoom = new CustomPriorityQueue();
            pqItem[]            patients    = new pqItem[4];
            patients[0].name     = "Klaas";
            patients[0].priority = 1;
            patients[1].name     = "Gerald";
            patients[1].priority = 3;
            patients[2].name     = "Tessa";
            patients[2].priority = 0;
            patients[3].name     = "Yvonne";
            patients[3].priority = 7;
            // add all patients to the priority queue
            for (int i = 0; i <= patients.GetUpperBound(0); i++)
            {
                waitingRoom.Enqueue(patients[i]);
            }

            // remove patients from waiting list in order of their priority
            for (int i = 0; i <= patients.GetUpperBound(0); i++)
            {
                pqItem patient = (pqItem)waitingRoom.Dequeue();
                Console.WriteLine(patient.priority + ": " + patient.name);
            }

            #endregion

            Console.ReadKey();
        }
Exemplo n.º 4
0
        static void Main()
        {
            try
            {
                // استک و صف همزمان
                Console.WriteLine("queue: ");
                FifoLifoList <string> fl = new FifoLifoList <string>((int)CollectionNames.Queue);
                fl.Add("a");
                fl.Add("b");
                fl.Add("c");

                Console.WriteLine(fl.Remove().GetData());
                Console.WriteLine(fl.Remove().GetData());

                Console.WriteLine("stack: ");

                // استک و صف همزمان
                FifoLifoList <string> fl2 = new FifoLifoList <string>((int)CollectionNames.Stack);
                fl2.Add("a");
                fl2.Add("b");
                fl2.Add("c");

                Console.WriteLine(fl2.Remove().GetData());
                Console.WriteLine(fl2.Remove().GetData());

                // (استک با پایه آرایه برای سرعت بیشتر (چون ولیو تایپ است
                Console.WriteLine("ArrayBasedStack: ");
                ArrayBasedStack <int> arbStack = new ArrayBasedStack <int>();
                arbStack.Push(1);
                arbStack.Push(2);
                arbStack.Push(3);
                Console.WriteLine(arbStack.Pop());
                Console.WriteLine(arbStack.Pop());

                //---------------------------
                Console.WriteLine("CustomQueue: ");
                CustomQueue <string> cq = new CustomQueue <string>();
                cq.EnQueue("a");
                cq.EnQueue("b");
                cq.EnQueue("c");

                Console.WriteLine(cq.DeQueue().GetData());
                Console.WriteLine(cq.DeQueue().GetData());
                cq.Clear();
                //Console.WriteLine(cq.DeQueue().Data);


                Console.WriteLine("CustomStack: ");
                CustomStack <int> numbers = new CustomStack <int>();
                numbers.Push(1);
                numbers.Push(2);
                numbers.Push(3);
                numbers.Push(4);
                numbers.Push(5);
                numbers.PrintAll();

                Console.WriteLine("Count of stack is: {0}", numbers.Count());

                Console.WriteLine("Popping {0}", numbers.PopData());
                Console.WriteLine("Popping {0}", numbers.PopData());
                numbers.Clear();
                //Console.WriteLine("Popping '{0}'", numbers.Pop2());

                //-------------------
                CustomStack <string> stack = new CustomStack <string>();
                stack.Push("first");
                stack.Push("second");
                stack.Push("third");
                Console.WriteLine("\nall data");
                stack.PrintAll();
                Console.WriteLine("\nPeek");
                Console.WriteLine(stack.PeekFromStack().GetData());
                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nnow try to pop");
                Console.WriteLine(stack.Pop().GetData());
                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nnow try to popping two items ");
                Console.WriteLine("Popping {0}", stack.Pop().GetData());
                Console.WriteLine("Popping {0}", stack.Pop().GetData());

                Console.WriteLine("\nPrintAll again");
                stack.PrintAll();
                Console.WriteLine("\nPush three item");
                stack.Push("first");
                stack.Push("second");
                stack.Push("third");
                stack.PrintAll();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }