Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
    private static void ProcessPacket(int packet_Type, byte[] buffer)
    {
        switch (packet_Type)
        {
        case (int)ServerPacketType.BLEList: {
            Debug.Log("BLEList : ");
            ServerBLEList receiveclass = (ServerBLEList)Packet.Deserialize(buffer);
            foreach (var data in receiveclass.BLEList)
            {
                _bleList.Add(data);
                Debug.Log(data.ToString());
            }
        }
        break;

        case (int)ServerPacketType.BPMData: {
            Debug.Log("BPMData : ");
            ServerBPMData receiveclass = (ServerBPMData)Packet.Deserialize(buffer);
            _nowBPM = receiveclass.nowBPM.ToString();
        }
        break;

        case (int)ServerPacketType.SendPacket: {
            Debug.Log("SendPacket : ");
            publicPostData receiveclass = (publicPostData)Packet.Deserialize(buffer);

            if (receiveclass.data == (int)ServerStatus.BLEConnectComplete)
            {
                // BLE 연결에 성공 했을 경우
                publicPostData clientPostData = new publicPostData();
                clientPostData.packet_Type = (int)ClientPacketType.AuthBLE;
                clientPostData.data        = 0;
                Send(client, Packet.Serialize(clientPostData));
            }
            else if (receiveclass.data == (int)ServerStatus.BLEAuthComplete)
            {
                // Auth 성공 했을 경우
                publicPostData clientPostData = new publicPostData();
                clientPostData.packet_Type = (int)ClientPacketType.StartBLE;
                clientPostData.data        = 0;
                Send(client, Packet.Serialize(clientPostData));
            }
        }
        break;
        }
    }
Exemplo n.º 3
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);
            }
        }