Example #1
0
        private void ProcessPacket(int packet_Type, byte[] buffer)
        {
            switch (packet_Type)
            {
            case (int)ClientPacketType.LoadBLEList: {
                Console.WriteLine("LoadBLEList");
                while (true)
                {
                    if (comboBox1.Items.Count != 0)
                    {
                        break;
                    }
                    BLEList();
                }

                ServerBLEList serverPostData = new ServerBLEList();
                serverPostData.BLEList = new List <string>();
                foreach (var data in comboBox1.Items)
                {
                    serverPostData.BLEList.Add(data.ToString());
                }
                serverPostData.packet_Type = (int)ServerPacketType.BLEList;
                AsynchronousSocketServer.Send(asyncServer.getSocket(), Packet.Serialize(serverPostData));
            }
            break;

            case (int)ClientPacketType.ConnectBLE: {
                Console.WriteLine("ConnectBLE");
                publicPostData receiveclass = (publicPostData)Packet.Deserialize(buffer);
                comboBox1.SelectedIndex = receiveclass.data;
                ConnectBLE();
            }
            break;

            case (int)ClientPacketType.AuthBLE: {
                Console.WriteLine("AuthBLE");
                AuthBLE();
            }
            break;

            case (int)ClientPacketType.StartBLE: {
                Console.WriteLine("StartBLE");
                StartBPM();
            }
            break;

            case (int)ClientPacketType.StopBLE: {
                Console.WriteLine("StopBLE");
                StopBPM();
            }
            break;

            case (int)ClientPacketType.SendPacket: {
                Console.WriteLine("SendPacket");
                //  딱히 쓸일 없을 듯 지금은..!
                publicPostData receiveclass = (publicPostData)Packet.Deserialize(buffer);
            }
            break;
            }
        }
Example #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            Random r       = new Random(unchecked ((int)DateTime.Now.Ticks) + nowBPM);
            int    fakeBPM = 0;

            if (nowBPM >= 145)
            {
                fakeBPM = r.Next(-4, 1);
            }
            else if (nowBPM <= 80)
            {
                fakeBPM = r.Next(-1, 4);
            }
            else
            {
                fakeBPM = r.Next(-3, 4);
            }
            nowBPM += fakeBPM;
            listBox3.Items.Add(String.Format("{0} bpm", nowBPM));

            ServerBPMData serverPostData = new ServerBPMData();

            serverPostData.nowBPM      = (int)nowBPM;
            serverPostData.packet_Type = (int)ServerPacketType.BPMData;
            AsynchronousSocketServer.Send(asyncServer.getSocket(), Packet.Serialize(serverPostData));
        }
Example #3
0
 // delegate 처리 함수
 void ConnectChange(bool v)
 {
     if (InvokeRequired)
     {
         ConnectBLEDevice c = new ConnectBLEDevice(ConnectChange);
         Invoke(c, new object[] { v });
     }
     else
     {
         if (v == true)
         {
             // 연결에 성공 했을시
             button3.Enabled = true;
             publicPostData serverPostData = new publicPostData();
             serverPostData.data        = (int)ServerStatus.BLEConnectComplete;
             serverPostData.packet_Type = (int)ServerPacketType.SendPacket;
             AsynchronousSocketServer.Send(asyncServer.getSocket(), Packet.Serialize(serverPostData));
         }
         else
         {
             // 연결에 실패 했을시
             button2.Enabled = true;
         }
     }
 }
Example #4
0
        // delegate 처리 함수
        void OnHeartrateChange(MiBand d, UInt16 v)
        {
            if (InvokeRequired)
            {
                OnHeartrateChangeHandler c = new OnHeartrateChangeHandler(OnHeartrateChange);
                Invoke(c, new object[] { d, v });
            }
            else
            {
                listBox3.Items.Add(String.Format("{0} bpm", v));
                nowBPM         = v;
                nowTime        = 17;
                timer1.Enabled = true;
                timer2.Enabled = true;

                ServerBPMData serverPostData = new ServerBPMData();
                serverPostData.nowBPM      = (int)v;
                serverPostData.packet_Type = (int)ServerPacketType.BPMData;
                AsynchronousSocketServer.Send(asyncServer.getSocket(), Packet.Serialize(serverPostData));

                //asyncServer.SendPacket(v, asyncServer.GetSocket);
            }
        }
Example #5
0
 // delegate 처리 함수
 void OnAuth(MiBand d, bool s)
 {
     if (InvokeRequired)
     {
         OnAuthHandler c = new OnAuthHandler(OnAuth);
         Invoke(c, new object[] { d, s });
     }
     else
     {
         if (s)
         {
             // 연결에 성공 했을시
             button4.Enabled = true;
             publicPostData serverPostData = new publicPostData();
             serverPostData.data        = (int)ServerStatus.BLEAuthComplete;
             serverPostData.packet_Type = (int)ServerPacketType.SendPacket;
             AsynchronousSocketServer.Send(asyncServer.getSocket(), Packet.Serialize(serverPostData));
         }
         else
         {
             MessageBox.Show("Auth failed !", "Device error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }