Beispiel #1
0
        /// <summary>
        /// 注册DTU(上线DTU注册)
        /// </summary>
        /// <param name="dtuid"></param>
        /// <param name="isnewstate"></param>
        /// <returns></returns>
        private GprsDtuConnection RegisterConnection(string dtuid, out bool isnewstate)
        {
            isnewstate = false;
            GprsDtuConnection c;

            if (!this._connectPool.ContainsKey(dtuid))
            {
                c = new GprsDtuConnection(this)
                {
                    DtuID = dtuid
                };
                this._connectPool.TryAdd(c.DtuID, c);
                // _connectPool[c.DtuID] = c;
                isnewstate = true;
            }
            else
            {
                c = this._connectPool[dtuid];
                if (!c.IsOnline)
                {
                    isnewstate = true;
                }
            }
            c.DtuID = dtuid;
            return(c);
        }
Beispiel #2
0
 private void FireConnectionStatusChanged(GprsDtuConnection c, WorkingStatus oldStatus, WorkingStatus newStatus)
 {
     if (this.OnConnectStatusChanged != null)
     {
         this._log.InfoFormat("DtuConnection {0} going {1}", c, newStatus);
         this.OnConnectStatusChanged(c, oldStatus, newStatus);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 更新传感器信息时,添加表中不存在的DTU
 /// </summary>
 /// <param name="dtuCode"></param>
 public void AddDtu(string dtuCode)
 {
     if (!this._connectPool.ContainsKey(dtuCode))
     {
         var c = new GprsDtuConnection(this)
         {
             DtuID = dtuCode
         };
         this._connectPool[dtuCode] = c;
     }
     this._server.Disconnect(dtuCode);
 }
Beispiel #4
0
 /// <summary>
 /// Connect, 注册服务.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void server_ClientConnect(object sender, ZYBEventArgs e)
 {
     lock (sender)
     {
         bool isnewstate;
         GprsDtuConnection c = this.RegisterConnection(e.DTU.ID, out isnewstate);
         c.UpdateDtuConnection(e);
         if (!isnewstate)
         {
             this._log.ErrorFormat("DTU {0} is online twice !!!", e.DTU.ID);
             return;
         }
         this.FireConnectionStatusChanged(c, WorkingStatus.NA, WorkingStatus.IDLE);
     }
 }