コード例 #1
0
    void OnRecivePackage(NemoUsbHid.Package p)
    {
        //////////////////////////////////////////////////////////////////////////
        //新命令
        //投币
        if (p.data[2] == 0x11)
        {
            int playeridx = p.data[mPackHeadSize];
            if (HandlerInsertCoin != null)
            {
                HandlerInsertCoin(1, playeridx);
            }
        }

        //控制器控制
        if (p.data[2] == 0x21)
        {
            //Debug.Log("p.data.len = " + p.data.Length);
            int  playeridx = p.data[mPackHeadSize];
            Key  k         = (Key)p.data[mPackHeadSize + 1];
            bool isDown    = p.data[mPackHeadSize + 2] == 1?true:false;

            if (HandlerKey != null)
            {
                HandlerKey(playeridx, k, isDown);
            }
        }

        //退币响应
        if (p.data[2] == 0x51)
        {
            int playeridx = p.data[mPackHeadSize];
            if (HandlerOutCoinReflect != null)
            {
                HandlerOutCoinReflect(1, playeridx);
            }
        }
        //退票响应
        if (p.data[2] == 0x61)
        {
            int playeridx = p.data[mPackHeadSize];
            if (HandlerOutTicketReflect != null)
            {
                HandlerOutTicketReflect(1, playeridx);
            }
        }

        //退币不足
        if (p.data[2] == 0x32)
        {
            int  playeridx = p.data[mPackHeadSize];
            uint num       = System.BitConverter.ToUInt32(p.data, mPackHeadSize + 1);
            if (HandlerLackCoin != null)
            {
                HandlerLackCoin(num, playeridx);
            }
        }
        //退票不足
        if (p.data[2] == 0x42)
        {
            int  playeridx = p.data[mPackHeadSize];
            uint num       = System.BitConverter.ToUInt32(p.data, mPackHeadSize + 1);
            if (HandlerLackTicket != null)
            {
                HandlerLackTicket(num, playeridx);
            }
        }

        //后台按键
        if (p.data[2] == 0xc3)
        {
            Key  k      = (Key)p.data[mPackHeadSize];
            bool isDown = p.data[mPackHeadSize + 1] == 1?true:false;

            if (HandlerBackGroundKeyEvent != null)
            {
                HandlerBackGroundKeyEvent(k, isDown);
            }
        }

        //状态返回
        if (p.data[2] == 0x71)
        {
            byte usbState = p.data[mPackHeadSize];
            byte arcState = p.data[mPackHeadSize + 1];
            if (HandlerStateCheck != null)
            {
                HandlerStateCheck(usbState == 1 ? true : false, arcState == 1 ? true : false);
            }
        }
    }
コード例 #2
0
    //组包处理
    //1.mPackageSetup_ReadBuf考虑删除?
    NemoUsbHid.Package Handle_PackageSetupProcess(byte[] datas)
    {
        //Debug.Log("        count:" + datas.Length + "   read:" + NemoUsbHid.ByteArrayToString(datas));
        int readNum = mPackageSetup_RestNum + datas.Length;

        //Debug.Log("datas.Length = " + datas.Length.ToString() + "  mPackageSetup_RestNum = " + mPackageSetup_RestNum);
        System.Array.Copy(datas, 0, mPackageSetup_ReadBuf, mPackageSetup_RestNum, datas.Length);

        //Debug.Log("Handle_PackageSetupProcess readNum = " + readNum + " mPackageSetup_ReadBuf.l = " + mPackageSetup_ReadBuf.Length);
        for (int i = 0; i != readNum; ++i)
        {
            byte b = mPackageSetup_ReadBuf[i];

            switch (mReadPackStage)
            {
            case ReadPackageStage.NotStart:
            {
                if (b == 0xFB)
                {
                    mPackageSetup_Readed.Add(b);
                    mReadPackStage = ReadPackageStage.Head;
                    //Debug.Log("NotStart to Head");
                }
            }
            break;

            case ReadPackageStage.Head:
            {
                mPackageSetup_Readed.Add(b);
                //Debug.Log("Head   mPackageSetup_Readed.length = " + mPackageSetup_Readed.Count + "b = " + b);
                if (mPackageSetup_Readed.Count == 5)
                {
                    //mPackSetupingID = 256 * mPackageSetup_Readed[1] + mPackageSetup_Readed[2];
                    mPackSetupingLen = 256 * mPackageSetup_Readed[3] + mPackageSetup_Readed[4];
                    mReadPackStage   = ReadPackageStage.DataToEnd;
                    //Debug.Log("Head to DataToEnd");
                }
            }
            break;

            case ReadPackageStage.DataToEnd:
            {
                mPackageSetup_Readed.Add(b);
                if (mPackageSetup_Readed.Count == mPackSetupingLen + 5 + 1)
                {
                    if (mPackageSetup_Readed[mPackageSetup_Readed.Count - 1]
                        == (mPackageSetup_Readed[1] ^ mPackageSetup_Readed[2]))        //结尾副符合-组包完成
                    {
                        mReadPackStage = ReadPackageStage.NotStart;

                        System.Array.Copy(mPackageSetup_ReadBuf, i + 1, mPackageSetup_ReadBuf, 0, readNum - i - 1);
                        //Debug.Log("package setuping:" + NemoUsbHid.ByteArrayToString(mPackageSetup_Readed.ToArray()));

                        //test Start
                        //byte[] testBytes = new byte[readNum - i - 1];
                        //System.Array.Copy(mPackageSetup_ReadBuf, testBytes, readNum - i - 1);
                        //Debug.Log("package setuping:"+NemoUsbHid.ByteArrayToString(testBytes));
                        //test End

                        mPackageSetup_RestNum = readNum - i - 1;
                        NemoUsbHid.Package p = new NemoUsbHid.Package();
                        p.data = mPackageSetup_Readed.ToArray();
                        mPackageSetup_Readed.Clear();

                        //Debug.Log("package : " + NemoUsbHid.ByteArrayToString(p.data));
                        return(p);
                    }
                    else        //有错误包出现
                    {
                        //test Start
                        //Debug.Log("package erro msg:" + NemoUsbHid.ByteArrayToString(mPackageSetup_Readed.ToArray()));
                        //test End

                        mReadPackStage = ReadPackageStage.NotStart;
                        mPackageSetup_Readed.Clear();
                        Debug.LogWarning("[ArcadeIO_Cheng] Wrong package appear in PackageSetup!");
                        return(null);
                    }
                }
            }
            break;
            }
        }
        mPackageSetup_RestNum = 0;
        return(null);
    }
コード例 #3
0
ファイル: ArcadeIO_Feng.cs プロジェクト: minh3d/Fish
    /// <summary>
    ///  �������
    /// </summary>
    /// <param name="datas"></param>
    /// <returns></returns>
    List<NemoUsbHid.Package> Handle_PackageSetupProcess2(byte[] datas)
    {
        List<NemoUsbHid.Package> packsOut = new List<NemoUsbHid.Package>();

        //int readNum = mPackageSetup_RestNum + datas.Length;
        //System.Array.Copy(datas, 0, mPackageSetup_ReadBuf, mPackageSetup_RestNum, datas.Length);

        //for (int i = 0; i != datas.Length; ++i)
        foreach(byte b in datas)
        {

            switch (mReadPackStage)
            {
                case ReadPackageStage.NotStart:
                    {
                        if (b == 0xFB)
                        {
                            mPackageSetup_Readed.Add(b);
                            mReadPackStage = ReadPackageStage.Head;
                        }
                    }
                    break;
                case ReadPackageStage.Head:
                    {
                        mPackageSetup_Readed.Add(b);
                        if (mPackageSetup_Readed.Count == 5)
                        {
                            mPackSetupingLen = 256 * mPackageSetup_Readed[3] + mPackageSetup_Readed[4];
                            mReadPackStage = ReadPackageStage.DataToEnd;

                            if (mPackSetupingLen > 256)
                            {
                                mReadPackStage = ReadPackageStage.NotStart;
                                mPackageSetup_Readed.Clear();
                                Debug.LogWarning("[ArcadeIO_Cheng] PackSetupingLen > 256,pack may wrong!");
                                //return packsOut;
                            }
                        }
                    }
                    break;
                case ReadPackageStage.DataToEnd:
                    {
                        mPackageSetup_Readed.Add(b);
                        if (mPackageSetup_Readed.Count == mPackSetupingLen + 5 + 1)
                        {
                            if (mPackageSetup_Readed[mPackageSetup_Readed.Count - 1]
                                == (mPackageSetup_Readed[1] ^ mPackageSetup_Readed[2]))//�������-������
                            {
                                mReadPackStage = ReadPackageStage.NotStart;

                                //System.Array.Copy(mPackageSetup_ReadBuf, i + 1, mPackageSetup_ReadBuf, 0, readNum - i - 1);

                                //mPackageSetup_RestNum = readNum - i - 1;
                                NemoUsbHid.Package pOut = new NemoUsbHid.Package();
                                pOut.data = mPackageSetup_Readed.ToArray();
                                mPackageSetup_Readed.Clear();

                                packsOut.Add(pOut);
                            }
                            else//��������
                            {
                                mReadPackStage = ReadPackageStage.NotStart;
                                mPackageSetup_Readed.Clear();
                                Debug.LogWarning("[ArcadeIO_Cheng] Wrong package appear in PackageSetup!");
                                //return packsOut;
                            }
                        }
                    }
                    break;

            }
        }
        //Debug.Log("outpack num = " + packsOut.Count.ToString());
        return packsOut;
    }
コード例 #4
0
    /// <summary>
    ///  组包处理
    /// </summary>
    /// <param name="datas"></param>
    /// <returns></returns>
    List <NemoUsbHid.Package> Handle_PackageSetupProcess2(byte[] datas)
    {
        List <NemoUsbHid.Package> packsOut = new List <NemoUsbHid.Package>();

        //int readNum = mPackageSetup_RestNum + datas.Length;
        //System.Array.Copy(datas, 0, mPackageSetup_ReadBuf, mPackageSetup_RestNum, datas.Length);

        //for (int i = 0; i != datas.Length; ++i)
        foreach (byte b in datas)
        {
            switch (mReadPackStage)
            {
            case ReadPackageStage.NotStart:
            {
                if (b == 0xFB)
                {
                    mPackageSetup_Readed.Add(b);
                    mReadPackStage = ReadPackageStage.Head;
                }
            }
            break;

            case ReadPackageStage.Head:
            {
                mPackageSetup_Readed.Add(b);
                if (mPackageSetup_Readed.Count == 5)
                {
                    mPackSetupingLen = 256 * mPackageSetup_Readed[3] + mPackageSetup_Readed[4];
                    mReadPackStage   = ReadPackageStage.DataToEnd;

                    if (mPackSetupingLen > 256)
                    {
                        mReadPackStage = ReadPackageStage.NotStart;
                        mPackageSetup_Readed.Clear();
                        Debug.LogWarning("[ArcadeIO_Cheng] PackSetupingLen > 256,pack may wrong!");
                        //return packsOut;
                    }
                }
            }
            break;

            case ReadPackageStage.DataToEnd:
            {
                mPackageSetup_Readed.Add(b);
                if (mPackageSetup_Readed.Count == mPackSetupingLen + 5 + 1)
                {
                    if (mPackageSetup_Readed[mPackageSetup_Readed.Count - 1]
                        == (mPackageSetup_Readed[1] ^ mPackageSetup_Readed[2]))        //结尾副符合-组包完成
                    {
                        mReadPackStage = ReadPackageStage.NotStart;

                        //System.Array.Copy(mPackageSetup_ReadBuf, i + 1, mPackageSetup_ReadBuf, 0, readNum - i - 1);

                        //mPackageSetup_RestNum = readNum - i - 1;
                        NemoUsbHid.Package pOut = new NemoUsbHid.Package();
                        pOut.data = mPackageSetup_Readed.ToArray();
                        mPackageSetup_Readed.Clear();

                        packsOut.Add(pOut);
                    }
                    else        //有错误包出现
                    {
                        mReadPackStage = ReadPackageStage.NotStart;
                        mPackageSetup_Readed.Clear();
                        Debug.LogWarning("[ArcadeIO_Cheng] Wrong package appear in PackageSetup!");
                        //return packsOut;
                    }
                }
            }
            break;
            }
        }
        //Debug.Log("outpack num = " + packsOut.Count.ToString());
        return(packsOut);
    }
コード例 #5
0
ファイル: ArcadeIO_Feng.cs プロジェクト: minh3d/Fish
    //�������
    //1.mPackageSetup_ReadBuf����ɾ��?
    NemoUsbHid.Package Handle_PackageSetupProcess(byte[] datas)
    {
        //Debug.Log("        count:" + datas.Length + "   read:" + NemoUsbHid.ByteArrayToString(datas));
        int readNum = mPackageSetup_RestNum + datas.Length;
        //Debug.Log("datas.Length = " + datas.Length.ToString() + "  mPackageSetup_RestNum = " + mPackageSetup_RestNum);
        System.Array.Copy(datas, 0, mPackageSetup_ReadBuf, mPackageSetup_RestNum, datas.Length);

        //Debug.Log("Handle_PackageSetupProcess readNum = " + readNum + " mPackageSetup_ReadBuf.l = " + mPackageSetup_ReadBuf.Length);
        for (int i = 0; i != readNum; ++i )
        {
            byte b = mPackageSetup_ReadBuf[i];

            switch (mReadPackStage)
            {
                case ReadPackageStage.NotStart:
                    {
                        if (b == 0xFB)
                        {
                            mPackageSetup_Readed.Add(b);
                            mReadPackStage = ReadPackageStage.Head;
                            //Debug.Log("NotStart to Head");
                        }
                    }
                    break;
                case ReadPackageStage.Head:
                    {
                        mPackageSetup_Readed.Add(b);
                        //Debug.Log("Head   mPackageSetup_Readed.length = " + mPackageSetup_Readed.Count + "b = " + b);
                        if (mPackageSetup_Readed.Count == 5)
                        {
                            //mPackSetupingID = 256 * mPackageSetup_Readed[1] + mPackageSetup_Readed[2];
                            mPackSetupingLen = 256 * mPackageSetup_Readed[3] + mPackageSetup_Readed[4];
                            mReadPackStage = ReadPackageStage.DataToEnd;
                            //Debug.Log("Head to DataToEnd");
                        }
                    }
                    break;
                case ReadPackageStage.DataToEnd:
                    {
                        mPackageSetup_Readed.Add(b);
                        if (mPackageSetup_Readed.Count == mPackSetupingLen + 5 + 1)
                        {
                            if (mPackageSetup_Readed[mPackageSetup_Readed.Count - 1]
                                == (mPackageSetup_Readed[1] ^ mPackageSetup_Readed[2]))//�������-������
                            {
                                mReadPackStage = ReadPackageStage.NotStart;

                                System.Array.Copy(mPackageSetup_ReadBuf, i+1, mPackageSetup_ReadBuf,0, readNum - i -1);
                                //Debug.Log("package setuping:" + NemoUsbHid.ByteArrayToString(mPackageSetup_Readed.ToArray()));

                                //test Start
                                //byte[] testBytes = new byte[readNum - i - 1];
                                //System.Array.Copy(mPackageSetup_ReadBuf, testBytes, readNum - i - 1);
                                //Debug.Log("package setuping:"+NemoUsbHid.ByteArrayToString(testBytes));
                                //test End

                                mPackageSetup_RestNum = readNum - i - 1;
                                NemoUsbHid.Package p = new NemoUsbHid.Package();
                                p.data = mPackageSetup_Readed.ToArray();
                                mPackageSetup_Readed.Clear();

                                //Debug.Log("package : " + NemoUsbHid.ByteArrayToString(p.data));
                                return p;
                            }
                            else//��������
                            {
                                //test Start
                                //Debug.Log("package erro msg:" + NemoUsbHid.ByteArrayToString(mPackageSetup_Readed.ToArray()));
                                //test End

                                mReadPackStage = ReadPackageStage.NotStart;
                                mPackageSetup_Readed.Clear();
                                Debug.LogWarning("[ArcadeIO_Cheng] Wrong package appear in PackageSetup!");
                                return null;
                            }
                        }
                    }
                    break;

            }
        }
        mPackageSetup_RestNum = 0;
        return null;
    }