Exemplo n.º 1
0
 public DACWorker FindWorker(uint dtuId)
 {
     if (_workers.ContainsKey(dtuId) && _workers[dtuId] != null)
     {
         return(_workers[dtuId]);
     }
     else
     {
         DACWorker w = new DACWorker(_adapterManager, this.OnSensorCollectMsgHandler);
         w.AssignContext(this.CreateContext(dtuId));
         _workers[dtuId] = w;
         w.StartWork();
         return(w);
     }
 }
Exemplo n.º 2
0
        // Node 状态变更。
        public void OnConnectionStatusChanged(IDtuConnection c, WorkingStatus oldStat, WorkingStatus newStat)
        {
            string dtuCode = c.DtuID;

            if (newStat == WorkingStatus.IDLE)
            {
                // Online;
                if (OnDTUConnectionStatusChanged != null)
                {
                    OnDTUConnectionStatusChanged.Invoke(new DTUConnectionStatusChangedMsg
                    {
                        DTUID             = dtuCode,
                        IsOnline          = true,
                        TimeStatusChanged = DateTime.Now //c.LoginTime
                    });
                }
                if (c is GprsDtuConnection)
                {
                    var cg = c as GprsDtuConnection;
                    Log.InfoFormat("Gprs Node Online: {0}, ip={1}, phone={2}.", cg.DtuID, cg.IP, cg.PhoneNumber);
                }
                else if (c is FileDtuConnection)
                {
                    var cf = c as FileDtuConnection;
                    Log.InfoFormat("File Node Online: {0}, path={1}.", cf.DtuID, cf.FilePath);
                }
                else
                {
                    Log.WarnFormat("Node Unkown Type Online");
                }
                this.CheckDtuInfo(c);
                DACWorker w = this.FindWorker(dtuCode);

                if (w != null)
                {
                    DacTaskContext ctx = w.GetContext();
                    ctx.UpdateConnection(c);
                    w.AssignContext(ctx);
                }
            }
            else if (newStat == WorkingStatus.NA)
            {
                if (c is GprsDtuConnection)
                {
                    var cg = c as GprsDtuConnection;
                    Log.InfoFormat("Gprs Node Offline: {0}, ip={1}, phone={2}.", cg.DtuID, cg.IP, cg.PhoneNumber);
                }
                else if (c is FileDtuConnection)
                {
                    var cf = c as FileDtuConnection;
                    Log.InfoFormat("File Node Offline: {0}, path={1}.", cf.DtuID, cf.FilePath);
                }
                else
                {
                    Log.WarnFormat("Node Unkown Type Offline");
                }
                // offline;
                if (OnDTUConnectionStatusChanged != null)
                {
                    OnDTUConnectionStatusChanged.Invoke(new DTUConnectionStatusChangedMsg
                    {
                        DTUID             = dtuCode,
                        IsOnline          = false,
                        TimeStatusChanged = DateTime.Now
                    });
                }
            }
        }