Exemplo n.º 1
0
        public float getLastData(DjLiquidInfo liquidInfo)
        {
            using (OracleConnection conn = new OracleConnection(OracleHelper.ConnectionStringOrderDistributedTransaction))
            {
                String SQL = " SELECT LIQUIDDATA " +
                             " FROM " +
                             " (SELECT * " +
                             " FROM AD_DJ_LIQUID " +
                             " WHERE DEVCODE = :devCode " +
                             " and UPTIME < :uptime " +
                             " order by UPTIME desc) " +
                             " where rownum=1 ";

                OracleParameter[] oraParams = new OracleParameter[] {
                    new OracleParameter(":devCode",liquidInfo.DEVID),
                    new OracleParameter(":uptime",liquidInfo.UPTIME)
                };
                DataTable dt = OracleHelper.ExecuteDataset(conn,CommandType.Text,SQL,oraParams).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    float lastData = float.Parse(dt.Rows[0]["LIQUIDDATA"].ToString());
                    return(lastData);
                }
            }
            return(-1);
        }
Exemplo n.º 2
0
        public override void execute(Tag tag)
        {
            //TODO LIST:解析液位数据,保存液位数据
            UploadTag liquidTag  = tag as UploadTag;
            int       itv        = liquidTag.CollectInter;
            String    collecTime = liquidTag.CollectTime;
            int       len        = liquidTag.Len;
            String    dataValue  = liquidTag.DataValue;

            AdlerCmd.adlerSession.Logger.Info("液位数据上传TAG:oid:" + liquidTag.Oid + " 采集间隔: " +
                                              itv + "采集时间:" + collecTime + "上传数值:" + dataValue);

            int num = len / 4; //上传的液位数据个数
            List <Model.DjLiquidInfo> djs = new List <Model.DjLiquidInfo>();

            DateTime baseTime = Convert.ToDateTime(AdlerCmd.currentSystemDate + " " + collecTime);

            for (int i = 0; i < num; i++)
            {
                DjLiquidInfo liquidInfo = new DjLiquidInfo();
                String       liquid     = strHexToFloat(dataValue.Substring(i * 8, 8)).ToString();

                //TODO LIST:电池电量
                liquidInfo.LIQUIDDATA = liquid;
                liquidInfo.LOGTIME    = DateTime.Now;
                liquidInfo.UPTIME     = baseTime.AddMinutes(i * itv);
                liquidInfo.DEVID      = AdlerCmd.devCode;
                djs.Add(liquidInfo);
            }
            new BLL.DjLiquid().insert(djs);
            AdlerCmd.adlerSession.Logger.Info("液位数据保存成功");
        }
Exemplo n.º 3
0
        /// <summary>
        /// An internal function to bind values parameters for insert
        /// </summary>
        /// <param name="parms">Database parameters</param>
        /// <param name="liquid">Values to bind to parameters</param>
        private void SetAdapterParameters(OracleParameter[] parms, DjLiquidInfo liquid)
        {
            parms[0].Value = liquid.DEVID;

            if (null != liquid.LIQUIDDATA)
            {
                parms[1].Value = liquid.LIQUIDDATA;
            }
            else
            {
                parms[1].Value = DBNull.Value;
            }

            if (null != liquid.CELL)
            {
                parms[2].Value = liquid.CELL;
            }
            else
            {
                parms[2].Value = DBNull.Value;
            }

            if (null != liquid.SIGNAL)
            {
                parms[3].Value = liquid.SIGNAL;
            }
            else
            {
                parms[3].Value = DBNull.Value;
            }

            if (null != liquid.STATUS)
            {
                parms[4].Value = liquid.STATUS;
            }
            else
            {
                parms[4].Value = DBNull.Value;
            }

            if (null != liquid.UPTIME)
            {
                parms[5].Value = liquid.UPTIME;
            }
            else
            {
                parms[5].Value = DBNull.Value;
            }

            if (null != liquid.LOGTIME)
            {
                parms[6].Value = liquid.LOGTIME;
            }
            else
            {
                parms[6].Value = DBNull.Value;
            }
        }
Exemplo n.º 4
0
        static void testLiquid()
        {
            List <SensorHub.Model.DjLiquidInfo> djs = new List <SensorHub.Model.DjLiquidInfo>();
            DjLiquidInfo liquidInfo = new DjLiquidInfo();

            liquidInfo.CELL       = "1.1";
            liquidInfo.LIQUIDDATA = "1.9";
            liquidInfo.LOGTIME    = DateTime.Now;
            liquidInfo.UPTIME     = DateTime.Now;
            liquidInfo.DEVID      = "YWS_YW002";
            djs.Add(liquidInfo);

            new SensorHub.BLL.DjLiquid().saveAlarmInfo(djs);
            new SensorHub.BLL.DjLiquid().updateDevStatus(djs);
        }
Exemplo n.º 5
0
        private AlarmRecordInfo getAlarmRecord(AlarmRuleInfo alarmRuleInfo, DjLiquidInfo liquidInfo)
        {
            if (null != alarmRuleInfo)
            {
                float     curValue  = float.Parse(liquidInfo.LIQUIDDATA);
                IDevice   deviceDal = SensorHub.DALFactory.Device.Create();
                IDjLiquid liquidDal = SensorHub.DALFactory.DjLiquid.Create();

                AlarmRecordInfo alarmRecordInfo = new AlarmRecordInfo();
                alarmRecordInfo.ACTIVE           = true;
                alarmRecordInfo.DEVICE_CODE      = liquidInfo.DEVID;
                alarmRecordInfo.DEVICE_ID        = alarmRuleInfo.DeviceId;
                alarmRecordInfo.DEVICE_TYPE_NAME = deviceDal.getDevTypeByCode(liquidInfo.DEVID);
                alarmRecordInfo.ITEMNAME         = "液位值";
                alarmRecordInfo.ITEMVALUE        = curValue.ToString();
                alarmRecordInfo.MESSAGE_STATUS   = 0;
                alarmRecordInfo.MESSAGE          = (int)LiquidAlarmEnum.OVER_THRESH + "";

                alarmRecordInfo.RECORDCODE = "";
                alarmRecordInfo.RECORDDATE = System.DateTime.Now;

                if (alarmRuleInfo.HighValue != null && curValue > alarmRuleInfo.HighValue)
                {
                    alarmRecordInfo.MESSAGE = (int)LiquidAlarmEnum.OVER_THRESH + "";
                    return(alarmRecordInfo);
                }

                if (alarmRuleInfo.Saltation != null)
                {
                    float lastData = liquidDal.getLastData(liquidInfo);
                    if (-1 != lastData && Math.Abs(curValue - lastData) > alarmRuleInfo.Saltation)
                    {
                        alarmRecordInfo.MESSAGE = "液位突变";
                        //   return alarmRecordInfo;
                        return(null);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        public override void execute(Tag tag, String devCode, CellTag cellTag,
                                     SystemDateTag systemDateTag, CasicSession session)
        {
            //TODO LIST:解析液位数据,保存液位数据
            UploadTag liquidTag  = tag as UploadTag;
            int       itv        = liquidTag.CollectInter;
            String    collecTime = liquidTag.CollectTime;
            int       len        = liquidTag.Len;
            String    dataValue  = liquidTag.DataValue;

            session.Logger.Info("液位数据上传TAG:oid:" + liquidTag.Oid + " 采集间隔: " +
                                itv + "采集时间:" + collecTime + "上传数值:" + dataValue);

            int num = len / 4; //上传的液位数据个数
            List <Model.DjLiquidInfo> djs = new List <Model.DjLiquidInfo>();

            DateTime baseTime = Convert.ToDateTime(systemDateTag.CollectDate + " " + collecTime);

            for (int i = 0; i < num; i++)
            {
                DjLiquidInfo liquidInfo = new DjLiquidInfo();
                String       liquid     = strHexToFloat(dataValue.Substring(i * 8, 8)).ToString();

                //TODO LIST:电池电量
                liquidInfo.CELL       = (cellTag == null ? "" : cellTag.Cell);
                liquidInfo.LIQUIDDATA = liquid;
                liquidInfo.LOGTIME    = DateTime.Now;
                liquidInfo.UPTIME     = baseTime.AddMinutes(i * itv);
                liquidInfo.DEVID      = devCode;
                djs.Add(liquidInfo);
            }
            new BLL.DjLiquid().insert(djs);
            new BLL.DjLiquid().saveAlarmInfo(djs);
            new BLL.DjLiquid().updateDevStatus(devCode);
            session.Logger.Info("液位数据保存成功");
        }
        public override void ExecuteCommand(SZLiquidSession session, StringRequestInfo requestInfo)
        {
            try
            {
                session.Logger.Info("LSLEVDATA:液位监测仪器:" + requestInfo.Body);
                //采集时间
                string   year   = (Int32.Parse(requestInfo.Parameters[9].Substring(8, 2), System.Globalization.NumberStyles.HexNumber) + 2000).ToString();
                string   mon    = Int32.Parse(requestInfo.Parameters[9].Substring(6, 2), System.Globalization.NumberStyles.HexNumber).ToString();
                string   day    = Int32.Parse(requestInfo.Parameters[9].Substring(4, 2), System.Globalization.NumberStyles.HexNumber).ToString();
                string   hor    = Int32.Parse(requestInfo.Parameters[9].Substring(2, 2), System.Globalization.NumberStyles.HexNumber).ToString();
                string   min    = Int32.Parse(requestInfo.Parameters[9].Substring(0, 2), System.Globalization.NumberStyles.HexNumber).ToString();
                DateTime upTime = Convert.ToDateTime(year + "-" + mon + "-" + day + " " + hor + ":" + min + ":00");

                session.MacID = requestInfo.Parameters[5];

                string cfg   = requestInfo.Parameters[6];
                string ldata = requestInfo.Parameters[10];

                BLL.DeviceLog       bllLog    = new DeviceLog();
                BLL.Device          bllDevice = new Device();
                Model.DeviceLogInfo log       = new Model.DeviceLogInfo();
                log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
                log.MESSAGE     = "液位数据上传";
                log.OPERATETYPE = "上报";
                log.LOGTIME     = DateTime.Now;
                bllLog.insert(log);

                //采集个数
                int count   = Int16.Parse(requestInfo.Parameters[8], System.Globalization.NumberStyles.HexNumber);
                int isAlarm = Int16.Parse(requestInfo.Parameters[7], System.Globalization.NumberStyles.HexNumber);

                List <Model.DjLiquidInfo> djs      = new List <DjLiquidInfo>();
                List <Model.DjLiquidInfo> alarmDjs = new List <DjLiquidInfo>();
                for (int i = 0; i < count; i++)
                {
                    Model.DjLiquidInfo dj = new DjLiquidInfo();

                    //设备ID
                    dj.DEVID = session.MacID;

                    //液位数据
                    string lStr = ldata.Substring(i * 8, 8);
                    byte[] lBt  =
                    {
                        byte.Parse(lStr.Substring(0, 2), System.Globalization.NumberStyles.HexNumber),
                        byte.Parse(lStr.Substring(2, 2), System.Globalization.NumberStyles.HexNumber),
                        byte.Parse(lStr.Substring(4, 2), System.Globalization.NumberStyles.HexNumber),
                        byte.Parse(lStr.Substring(6, 2), System.Globalization.NumberStyles.HexNumber)
                    };
                    float liquidData = verifyLiquidData(BitConverter.ToSingle(lBt, 0), session.MacID, session);
                    dj.LIQUIDDATA = liquidData.ToString();

                    //电池电量
                    dj.CELL = Int16.Parse(requestInfo.Parameters[11], System.Globalization.NumberStyles.HexNumber).ToString();

                    //采集时间
                    dj.UPTIME = upTime;

                    //记录时间
                    dj.LOGTIME = DateTime.Now;

                    djs.Add(dj);

                    upTime = upTime.AddMinutes(60);

                    //如果存在报警
                    if (isAlarm == 1)
                    {
                        alarmDjs.Add(dj);
                    }
                }
                new BLL.DjLiquid().insert(djs);
                new BLL.DjLiquid().saveSZAlarmInfo(alarmDjs);
                // new BLL.DjLiquid().updateDevStatus(session.MacID);

                session.Logger.Info("液位监测仪器:" + session.MacID + "液位数据已经保存! ");

                //TODO LIST:下发上传数据返回帧
                byte[] asck =
                {
                    0x50,
                    0x00, 0x09,
                    0x02,
                    0x00, 0x00, 0x34,
                    0x22,
                    0x03
                };
                string head   = "LSLEVDATA:";
                byte[] btHead = System.Text.Encoding.Default.GetBytes(head);
                byte[] result = new byte[asck.Length + btHead.Length];

                Buffer.BlockCopy(btHead, 0, result, 0, btHead.Length);
                Buffer.BlockCopy(asck, 0, result, btHead.Length, asck.Length);
                session.Send(result, 0, result.Length);
            }
            catch (Exception e)
            {
                session.Logger.Error("液位数据已经保存失败" + requestInfo.Body);
                session.Logger.Error(e.ToString());
            }
            finally
            {
            }
        }
Exemplo n.º 8
0
 public float getLastData(DjLiquidInfo liquidInfo)
 {
     return(SensorHub.DALFactory.DjLiquid.Create().getLastData(liquidInfo));
 }