예제 #1
0
        private static void HDAPIRefresh()
        {
            uint   i, iDtuAmount;
            string str = "";

            StringBuilder  mess      = new StringBuilder(1000);
            GPRS_USER_INFO user_info = new GPRS_USER_INFO();

            str        = str + 0x00 + 0x00 + 0x00;
            iDtuAmount = HDDTUAPI.get_max_user_amount();    // 取最大数量, 为 3000

            for (i = 0; i < iDtuAmount; i++)
            {
                HDDTUAPI.get_user_at(i, ref user_info);

                if (user_info.m_status == 1)    // 在线
                {
                    // 判断 DTU 最后注册时间与现在时间的差值是否超过设置的超时时间
                    if ((DateTime.Now - HDDTUAPI.ConvertToDateTime(user_info.m_update_time)) > TimeSpan.FromMinutes(dtuTimeoutNum))
                    {
                        string dtuID = user_info.m_userid;
                        // 若超时则认为该 DTU 不在线, 调用开发包函数使其下线
                        HDDTUAPI.do_close_one_user2(dtuID, mess);
                        // 从缓存队列移除
                        DTUInfo dtuCache = DTUCacheManager.GetDTUInfo(dtuID);
                        if (dtuCache != null)
                        {
                            DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.Delete, dtuID, null);//DTUCacheManager.RemoveDtuCache(dtuID);
                            // 下线状态回填数据库
                            DBWorker.Append(DBCommand.CreateDtuOffline(dtuID));
                        }
                        else
                        {
                            TraceManager.AppendWarning("DTU:" + dtuID + "超时未注册,从缓存队列移除未发现该对象!");
                        }
                        continue;
                    }
                }
            }
        }
예제 #2
0
파일: DTUInfo.cs 프로젝트: Jaasdsa/CityIoT
        public static DTUInfo ToDTUInfoForSoc(GPRS_USER_INFO gprsUserInfo)
        {
            try
            {
                DTUInfo dtuInfo = new DTUInfo();
                dtuInfo.ID               = gprsUserInfo.m_userid;
                dtuInfo.IsUsed           = 1;
                dtuInfo.IsActive         = 1;
                dtuInfo.ActiveTime       = DataUtil.ToDateString(gprsUserInfo.m_logon_date);
                dtuInfo.LastRegisterTime = DataUtil.ToDateString(HDDTUAPI.ConvertToDateString(gprsUserInfo.m_update_time));
                dtuInfo.TerminalIP       = HDDTUAPI.inet_ntoa(HDDTUAPI.ntohl(gprsUserInfo.m_sin_addr));
                dtuInfo.TerminalPort     = gprsUserInfo.m_sin_port;
                dtuInfo.GatewayIP        = HDDTUAPI.inet_ntoa(HDDTUAPI.ntohl(gprsUserInfo.m_local_addr));
                dtuInfo.GatewayPort      = gprsUserInfo.m_local_port;

                return(dtuInfo);
            }
            catch
            {
            }
            return(null);
        }
예제 #3
0
        private static void Excute(GPRS_DATA_RECORD item)
        {
            switch (item.m_data_type)
            {
            case 0x01:      // 注册包
                GPRS_USER_INFO userInfo = new GPRS_USER_INFO();
                if (HDDTUAPI.get_user_info(item.m_userid, ref userInfo) == 0)
                {
                    DTUInfo sourceDTU = DTUInfo.ToDTUInfoForSoc(userInfo);
                    if (sourceDTU == null)
                    {
                        return;
                    }
                    DTUInfo targetDTU = DTUCacheManager.GetDTUInfo(item.m_userid);
                    if (targetDTU == null)
                    {
                        // 首次注册--在DBWorker从数据读取业务信息添加到缓存
                        DBWorker.Append(DBCommand.CreateDtuRegister(sourceDTU));
                    }
                    else
                    {
                        // 更新链路
                        DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.UpdateSocketInfo, targetDTU, sourceDTU);
                    }
                }
                break;

            case 0x02:      // 注销包
            {
                DTUCacheManager.OperDTUCache(DTUCacheManager.OPeratingType.Delete, item.m_userid, null);
            }
            break;

            case 0x04:      // 无效包
                TraceManager.AppendInfo(item.m_userid + "---接收无效的数据包");
                break;

            case 0x05:      // DTU已经接收到DSC发送的用户数据包
                TraceManager.AppendInfo(item.m_userid + "---已经接收到DSC发送的用户数据包");
                break;

            case 0x09:      // 数据包
            {
                //TraceManager.AppendInfo("DTU:" + item.m_userid + "接收了" +
                //                       ByteUtil.BytesToText(item.m_data_buf, item.m_data_len)
                //                       + "--共计" + item.m_data_len.ToString() + "个字节");

                DTUInfo dtu = DTUCacheManager.GetDTUInfo(item.m_userid);
                if (dtu == null)
                {
                    return;
                }
                dtu.Analysis(item.m_data_buf, item.m_data_len);
            }
            break;

            case 0x0d:
                TraceManager.AppendInfo(item.m_userid + "---参数设置成功");
                break;

            case 0x0b:
                TraceManager.AppendInfo(item.m_userid + "---参数查询成功");
                //  config.readconf();
                break;

            case 0x06:
                TraceManager.AppendInfo("---断开PPP连接成功");
                break;

            case 0x07:
                TraceManager.AppendInfo(item.m_userid + "---停止向DSC发送数据");
                break;

            case 0x08:
                TraceManager.AppendInfo("---允许向DSC发送数据");
                break;

            case 0x0A:
                TraceManager.AppendInfo("---丢弃用户数据");
                break;

            default:
                break;
            }
        }
예제 #4
0
파일: HDDTUAPI.cs 프로젝트: Jaasdsa/CityIoT
 public static extern int get_user_at(uint index, ref GPRS_USER_INFO infoPtr);
예제 #5
0
파일: HDDTUAPI.cs 프로젝트: Jaasdsa/CityIoT
 public static extern int get_user_info(
     [MarshalAs(UnmanagedType.LPStr)]
     string userid,
     ref GPRS_USER_INFO infoPtr);