Exemplo n.º 1
0
    public void EnterQueue()
    {
        Debug.Log("Queue");
        int num = 0;

        for (byte i = 0; i < 3; i++)
        {
            proInfo    = new IOEvent();
            proInfo.ID = this.Read(num);
            byte state = this.Read(num + 1);
            proInfo.IsPush1     = this.IsBool(IOParser.GetBit(7, state));
            proInfo.IsPush2     = this.IsBool(IOParser.GetBit(6, state));
            proInfo.IsShake     = this.IsBool(IOParser.GetBit(5, state));
            proInfo.IsWarning   = this.IsBool(IOParser.GetBit(4, state));
            proInfo.IsOutTicket = this.IsBool(IOParser.GetBit(3, state));
            proInfo.IsCoin      = this.IsBool(IOParser.GetBit(2, state));
            proInfo.IsStart     = this.IsBool(IOParser.GetBit(1, state));
            proInfo.IsSet       = this.IsBool(IOParser.GetBit(0, state));
            proInfo.RockerBar   = new Vector3(this.Read(num + 2), this.Read(num + 3), 0);
            proInfo.ScreenPos   = IOParser.World2ScreenPos(proInfo.RockerBar, i);
            num += 4;
            if (quequeInfo[i].Count > 5)
            {
                this.quequeInfo[i].Dequeue();
            }
            this.quequeInfo[i].Enqueue(proInfo);
        }
    }
Exemplo n.º 2
0
 public void UpdateWithIOEvent(IOEvent ioEvent)
 {
     if (ioEvent.Equals(space))
     {
         Fire();
     }
 }
Exemplo n.º 3
0
 public static void Event(IOEvent @event, string path)
 {
     if (EnableVerbose)
     {
         WriteLine(OutWriter, ConsoleColor.DarkCyan, @event.ToString().ToLower() + " " + path.Relative());
     }
 }
Exemplo n.º 4
0
 //初始化操作,打开端口,初始化ioEvent数组
 public void Init(int portCount)
 {
     iocount = portCount;
     ioevent = new IOEvent[portCount];
     for (byte i = 0; i < iocount; i++)
     {
         ioevent[i] = new IOEvent();
     }
     serialiohost = new SerialIOHost();
     serialiohost.Init(7, 7, 10);
 }
Exemplo n.º 5
0
 public static IOListener CreateListen(
     this IStorageObject storage,
     IOEvent verb,
     Action responder
     ) =>
 storage
 .Graph
 .CreateListen_Node(
     storage.ID,
     verb,
     responder
     );
Exemplo n.º 6
0
 public IOMessage(
     StorageObjectID subject,
     IOEvent verb
     )
     : this(
         subject,
         verb,
         default(string),
         default(string),
         default(StorageObjectID)
         )
 {
 }
Exemplo n.º 7
0
 public static IOListener CreateListen_Node(
     this IStorageGraph graph,
     StorageObjectID subject,
     IOEvent verb,
     Action responder
     ) =>
 CreateListen_Node(
     graph,
     subject,
     verb,
     (key, @object) =>
     responder()
     );
Exemplo n.º 8
0
 public static IOListener CreateListen_Node(
     this IStorageGraph graph,
     StorageObjectID subject,
     IOEvent verb,
     Action <string, StorageObjectID> childresponder
     ) =>
 new IOListener(
     new IOMessage(
         subject,
         verb
         ),
     message =>
     childresponder(message.Relation, message.Object)
     );
Exemplo n.º 9
0
 public IOMessage(
     StorageObjectID subject,
     IOEvent verb,
     string relation,
     string newrelation,
     StorageObjectID @object
     )
 {
     Subject     = subject;
     Verb        = verb;
     Relation    = relation;
     NewRelation = newrelation;
     Object      = @object;
 }
Exemplo n.º 10
0
        public GunnerController(Color color, Keys upKey, Keys downKey, Keys leftKey, Keys rightKey, Keys fireKey)
        {
            this.color = color;
            forward    = new KeyDown(upKey);
            back       = new KeyDown(downKey);
            left       = new KeyDown(leftKey);
            right      = new KeyDown(rightKey);
            fire       = new KeyDown(fireKey);

            inputManager.Register(forward, this);
            inputManager.Register(back, this);
            inputManager.Register(left, this);
            inputManager.Register(right, this);
            inputManager.Register(fire, this);
        }
Exemplo n.º 11
0
    //初始化操作,打开端口,初始化ioEvent数组
    public void Init(int portCount, E_InputType type)
    {
        ioCount = portCount;
        ioEvent = new IOEvent[portCount];
        for (byte i = 0; i < ioCount; i++)
        {
            ioEvent[i] = new IOEvent();
        }

        if (inputType == E_InputType.External)
        {
            serialIoHost = new SerialIOHost();
            serialIoHost.Init(7, 7, 10);
        }
    }
Exemplo n.º 12
0
 public IOMessage(
     StorageObjectID subject,
     IOEvent verb,
     string relation,
     StorageObjectID @object
     )
     : this(
         subject,
         verb,
         relation,
         default(string),
         @object
         )
 {
 }
Exemplo n.º 13
0
        public IOEvent RDC_ReadEventDo()
        {
            // 报警时间 /t事件类型/t时间级别/t事件内容/t归属厂站/t变电所/t变量ID号/t报警变量/t报警区域/报警值/t操作员/t处理时间/t处理过程/t处理结果/t备注/t
            if (this.Handle == null)
            {
                return(null);
            }
            //IntPtr pData = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("");

            try
            {
                int len = 500;
                int rst = RdcFunc.RDC_ReadEvent(this.Handle.Value, pReadEventData, len);
                if (rst == 0)
                {
                    string str = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(pReadEventData);
                    //string[] temp = Regex.Split(str.ToString(), "/t", RegexOptions.IgnoreCase); // str.ToString().Split(new char[] { "/t" }, StringSplitOptions.RemoveEmptyEntries);
                    string[] ss = str.Split(new char[] { '\t' }, StringSplitOptions.None);
                    if (ss.Count() < 15)
                    {
                        FileLog.WriteLog("获取告警值数组错误:" + str);
                        return(null);
                    }
                    IOEvent cls = new IOEvent();
                    cls.lpszdateTime  = CommFunc.ConvertDBNullToDateTime(ss[0]);
                    cls.lpszDbVarName = CommFunc.ConvertDBNullToString(ss[7]);
                    cls.lpszVal       = CommFunc.ConvertDBNullToString(ss[9]);
                    cls.lpszType      = CommFunc.ConvertDBNullToString(ss[1]);
                    cls.lpszGrade     = CommFunc.ConvertDBNullToString(ss[2]);
                    cls.content       = CommFunc.ConvertDBNullToString(ss[3]);
                    return(cls);
                }
                else
                {
                    //FileLog.WriteLog("获取告警值返回值错误:" + rst);
                }
            }
            catch (Exception ex)
            {
                FileLog.WriteLog("获取事件错误:" + ex.Message + ex.StackTrace);
            }
            finally
            {
                //System.Runtime.InteropServices.Marshal.FreeHGlobal(pData);
            }
            return(null);
        }
Exemplo n.º 14
0
        public void Event(IOEvent @event, string path, string extra = null)
        {
            if (Level < LogLevel.UltraVerbose)
            {
                return;
            }

            path = path.IsValidPath() && Path.IsPathRooted(path)
                ? path.ToRelativePath()
                : path.TrimPath();
            if (!string.IsNullOrEmpty(extra))
            {
                path += "; " + extra;
            }

            WriteLine(@event.ToString().ToLowerInvariant() + " " + path, ConsoleColor.DarkCyan);
        }
        public LocalPlayerController(ClientGame game) : base()
        {
            this.game = game;

            forward = new KeyDown(Keys.W);
            back    = new KeyDown(Keys.S);
            left    = new KeyDown(Keys.A);
            right   = new KeyDown(Keys.D);
            fire    = new LeftMouseDown();
            space   = new KeyDown(Keys.Space);

            this.game.InputManager.Register(forward, this);
            this.game.InputManager.Register(back, this);
            this.game.InputManager.Register(left, this);
            this.game.InputManager.Register(right, this);
            this.game.InputManager.Register(fire, this);
            this.game.InputManager.Register(space, this);
        }
Exemplo n.º 16
0
 public static IOListener CreateListen(
     this IStorageGraph graph,
     Action <IOMessage> responder,
     StorageObjectID subject,
     IOEvent verb,
     StorageObjectID @object = default(StorageObjectID),
     string key    = default(string),
     string newkey = default(string)
     ) =>
 new IOListener(
     new IOMessage(
         subject,
         verb,
         key,
         newkey,
         @object
         ),
     responder
     );
Exemplo n.º 17
0
 public void UpdateWithIOEvent(IOEvent ioEvent)
 {
     if (ioEvent.Equals(forward))
     {
         this.SpeedUp = true;
     }
     else if (ioEvent.Equals(back))
     {
         this.SlowDown = true;
     }
     else if (ioEvent.Equals(left))
     {
         turnRight = false;
         turnLeft  = true;
     }
     else if (ioEvent.Equals(right))
     {
         turnRight = true;
         turnLeft  = false;
     }
 }
Exemplo n.º 18
0
    //初始化操作,打开端口,初始化ioEvent数组
    public void Init(int portCount)
    {
        ioCount             = portCount;
        ioEvent             = new IOEvent[portCount];
        playerGameBegine    = new bool[portCount];
        playerGameEnd       = new bool[portCount];
        ticketNumber        = new int[portCount];
        isSetGameEnd        = new bool[portCount];
        outtick             = new bool[portCount];
        shootingCalibration = new bool[portCount];
        checkPass           = true;
        idString            = null;
        hasCheck            = true;
        connectDown         = false;

        serialIoHost = new SerialIOHost();
        for (byte i = 0; i < ioCount; i++)
        {
            ioEvent[i] = new IOEvent();
        }
    }
Exemplo n.º 19
0
    //初始化操作,打开端口,初始化ioEvent数组
    public void Init(int portCount)
    {
        ioCount = portCount;
        ioEvent = new IOEvent[portCount];

        serialIoHost = new SerialIOHost();
        for (byte i = 0; i < ioCount; i++)
        {
            ioEvent[i] = new IOEvent();
        }

        //if (!serialIoHost.Setup(14, 8, 10))
        //{
        //    Debug.Log("SerialIO setup failed!!");
        //}
        //else
        //{
        //    serialIoHost.OnReceiveFailed += () => { Debug.Log("Read Failed !!!"); };
        //    serialIoHost.OnReceiveSucceed += ReadDatas;
        //}
    }
Exemplo n.º 20
0
    /// <summary>
    /// 根据得到的字节数进行解析
    /// </summary>
    /// <param name="bytes">上位机一次能接受到的所有的字节数</param>
    /// <param name="ioEvent">存储按键事件</param>
    public static void GetBools(byte[] bytes, IOEvent ioEvent)
    {
        //byte[0]为协议头
        byte k = bytes[1];
        byte q = bytes[2];

        ioEvent.IsGather    = (IOParser.GetBit(0, k) == 1);
        ioEvent.IsPullDown  = (IOParser.GetBit(1, k) == 1);
        ioEvent.IsPullUp    = (IOParser.GetBit(2, k) == 1);
        ioEvent.IsTurnRight = (IOParser.GetBit(3, k) == 1);
        ioEvent.IsTurnLeft  = (IOParser.GetBit(4, k) == 1);
        ioEvent.IsMissile   = (IOParser.GetBit(5, k) == 1);
        ioEvent.IsStart     = (IOParser.GetBit(6, k) == 1);
        ioEvent.IsCoin      = (IOParser.GetBit(7, k) == 1);

        ioEvent.IsConfirm  = (IOParser.GetBit(7, q) == 1);
        ioEvent.IsSelect   = (IOParser.GetBit(6, q) == 1);
        ioEvent.IsResetEye = (IOParser.GetBit(5, q) == 1);
        ioEvent.IsUpEye    = (IOParser.GetBit(4, q) == 1);
        ioEvent.IsDownEye  = (IOParser.GetBit(3, q) == 1);
        ioEvent.IsTicket   = (IOParser.GetBit(2, q) == 1);
    }
Exemplo n.º 21
0
 public void UpdateWithIOEvent(IOEvent ioEvent)
 {
     if (ioEvent.Equals(forward))
     {
         aimPointMove = aimPointMove + new Vector2(0, -1);
     }
     else if (ioEvent.Equals(back))
     {
         aimPointMove = aimPointMove + new Vector2(0, 1);
     }
     else if (ioEvent.Equals(left))
     {
         aimPointMove = aimPointMove + new Vector2(-1, 0);
     }
     else if (ioEvent.Equals(right))
     {
         aimPointMove = aimPointMove + new Vector2(1, 0);
     }
     else if (ioEvent.Equals(fire))
     {
         NotifyObservers(new GunnerFire());
     }
 }
 public void UpdateWithIOEvent(IOEvent ioEvent)
 {
     if (ioEvent.Equals(forward))
     {
         movementControl = movementControl + 1;
     }
     else if (ioEvent.Equals(back))
     {
         movementControl = movementControl - 1;
     }
     else if (ioEvent.Equals(left))
     {
         angleControl = angleControl - 1;
     }
     else if (ioEvent.Equals(right))
     {
         angleControl = angleControl + 1;
     }
     else if (ioEvent.Equals(fire) || ioEvent.Equals(space))
     {
         isFire = true;
     }
 }
Exemplo n.º 23
0
        public int Write(byte[] data, int length)
        {
            ThrowOnDisposed();
            if (length > REPORT_SIZE)
            {
                return(0);
            }

            IOEvent e = new IOEvent();

            e.Length    = length;
            e.Timestamp = Clock;
            for (int i = 0; i < e.Length; i++)
            {
                e.Data.Data[i] = data[i];
            }

            lock (sending)
            {
                sending.Enqueue(e);
                writeCount.Release();
            }
            return(length);
        }
Exemplo n.º 24
0
 internal void Start()
 {
     Array.ForEach(IOEvents, IOEvent => IOEvent.FireOnStart());
 }
Exemplo n.º 25
0
        void ReaderThreadProc()
        {
            byte[] buf = new byte[REPORT_SIZE];

            using (ManualResetEvent asyncRead = new ManualResetEvent(false))
            {
                WaitHandle[] waitHandles = new WaitHandle[2] {
                    asyncRead, disposing
                };

                while (!disposing.WaitOne(0))
                {
                    uint             r;
                    NativeOverlapped overlaped = new NativeOverlapped();
                    overlaped.EventHandle = asyncRead.SafeWaitHandle.DangerousGetHandle();
                    bool ret = NativeMethods.ReadFile(deviceHandle.DangerousGetHandle(), buf, (uint)buf.Length, out r, ref overlaped);
                    if (!ret)
                    {
                        int error = Marshal.GetLastWin32Error();
                        if (error != 997) // 997 = ERROR_IO_PENDING
                        {
                            Debug.WriteLine("ReadFile failed: " + error);
                            continue;
                        }

                        int result = WaitHandle.WaitAny(waitHandles);
                        if (result == 1) // disposing?
                        {
                            NativeMethods.CancelIo(deviceHandle.DangerousGetHandle());
                            asyncRead.WaitOne();
                            continue;
                        }

                        if (!NativeMethods.GetOverlappedResult(deviceHandle.DangerousGetHandle(), ref overlaped, out r, true))
                        {
                            error = Marshal.GetLastWin32Error();
                            Debug.WriteLine("Read GetOverlappedResult failed: " + error);
                            continue;
                        }

                        if (overlaped.InternalLow == new IntPtr(0x00000103)) // 103 = STATUS_PENDING
                        {
                            NativeMethods.CancelIo(deviceHandle.DangerousGetHandle());
                            continue;
                        }
                    }

                    IOEvent e = new IOEvent();
                    e.Timestamp = Clock;
                    e.Length    = (int)r;
                    for (int i = 0; i < r; i++)
                    {
                        e.Data.Data[i] = buf[i];
                    }
                    lock (recieved)
                    {
                        if (recieved.Count > 16)
                        {
                            recieved.Dequeue();
                        }
                        recieved.Enqueue(e);
                        readCount.Release();
                    }
                }
            }
        }
Exemplo n.º 26
0
    /// <summary>
    /// 每帧分别读取一次协议队列中的协议,并存入协议信息类对象数组ioEvent
    /// </summary>
    public void UpdateIOEvent()
    {
        if (null != idString)
        {
            Main.SettingManager.CheckID = idString;
            Main.SettingManager.Save();
            idString = null;
        }

        if (isfindport)
        {
            // 丢失连接
            if (!isConnect)
            {
                if (connectTime > 0)
                {
                    connectTime -= Time.deltaTime;
                }
                else
                {
                    isfindport  = false;
                    connectTime = 2.0f;
                    Main.IOManager.SetFindPort("空");
                    Main.IOManager.ResetIO();
                }
            }
            else
            {
                connectTime = 2.0f;
            }
        }


        //// 测试
        checkTime += Main.NonStopTime.deltaTime;

        // 先屏蔽检测

        //if (!checkPass)
        //{
        //    connectDown = true;
        //}

        //if (connectDown)
        //{
        //    return;
        //}

        //if (hasCheck)
        //{
        //    checkTime = GameConfig.GAME_CONFIG_HAS_NO_CHECK_TIME;
        //    hasCheck = false;
        //}

        //checkTime -= Main.NonStopTime.deltaTime;
        //if (checkTime <= 0)
        //{
        //    checkTime = 0;
        //    checkPass = false;
        //}


        if (cansearch && !isfindport && searchcount < 50)
        {
            beginFind  = true;
            isfindport = serialIoHost.Setup(14, 8, 10);
            cansearch  = false;
            ++searchcount;
        }

        if (!isfindport)
        {
            time += Main.NonStopTime.deltaTime;
        }

        if (time >= ticktime)
        {
            cansearch = true;
            time      = 0.0f;
        }
        if (serialIoHost != null && serialIoHost.HadDevice())
        {
            serialIoHost.Update();
            for (byte i = 0; i < ioCount; i++)
            {
                if (serialIoHost.quequeInfo[i].Count > 0)
                {
                    //接受到的下位机数据
                    {
                        this.ie                = serialIoHost.quequeInfo[i].Dequeue();
                        ioEvent[i].ID          = this.ie.ID;
                        ioEvent[i].RockerBar   = this.ie.RockerBar;
                        ioEvent[i].IsSet       = this.ie.IsSet;
                        ioEvent[i].IsWarning   = this.ie.IsWarning;
                        ioEvent[i].IsOutTicket = this.ie.IsOutTicket;
                        ioEvent[i].IsCoin      = this.ie.IsCoin;
                        ioEvent[i].IsStart     = this.ie.IsStart;
                        ioEvent[i].ScreenPos   = this.ie.ScreenPos;
                        ioEvent[i].IsShake     = this.ie.IsShake;
                        ioEvent[i].IsPush1     = this.ie.IsPush1;
                        ioEvent[i].IsPush2     = this.ie.IsPush2;
                        //if (i == 0)
                        //{
                        //    ioEvent[i].IsPush1 = this.ie.IsPush1;
                        //    ioEvent[i].IsPush2 = this.ie.IsPush2;
                        //}else if(i == 1)
                        //{
                        //    IsWaterLow = this.ie.IsPush1;
                        //    IsWaterHight = this.ie.IsPush2;
                        //}
                        if (i == 1)
                        {
                            IsWaterLow   = this.ie.IsPush2;
                            IsWaterHight = this.ie.IsPush1;
                        }
                    }
                }
            }

            //向下位机发协议
            int num = 0;
            for (byte i = 0; i < ioCount; i++)
            {
                serialIoHost.Write(num, i);
                serialIoHost.Write(num + 1, 7, playerGameBegine[i]);
                serialIoHost.Write(num + 1, 6, playerGameEnd[i]);
                if (ioEvent[i].IsOutTicket)
                {
                    Main.SettingManager.LogTicket(1);
                    --ticketNumber[i];
                    if (ticketNumber[i] > 0)
                    {
                        outtick[i] = true;
                    }
                    else
                    {
                        Main.SettingManager.Save();
                        outtick[i] = false;
                    }
                }
                serialIoHost.Write(num + 1, 5, outtick[i]);
                serialIoHost.Write(num + 1, 4, bossCome);
                serialIoHost.Write(num + 1, 3, shootingCalibration[i]);

                if (bossCome)
                {
                    bossCome = false;
                }

                num += 2;
            }
        }
    }