예제 #1
0
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session;

            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.OPERATETYPE = "下发";
            log.LOGTIME     = DateTime.Now;

            if (session.Conf != null)
            {
                //记录实际下发信息
                string   content  = session.Conf.FrameContent;
                string[] items    = content.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                byte[]   sendData = new byte[items.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    sendData[i] = byte.Parse(items[i], System.Globalization.NumberStyles.HexNumber);
                }
                log.MESSAGE = "更新渗漏配置:密集开始时间:" + sendData[4] + ":" + sendData[5] +
                              "样本间隔:" + sendData[6] + "采集个数:" + sendData[7];
            }
            else
            {
                //记录默认配置信息
                byte[] set = ApplicationContext.getInstance().getDefaultSLConfig();
                log.MESSAGE = "更新渗漏配置:密集开始时间:" + set[4] + ":" + set[5] +
                              "样本间隔:" + set[6] + "采集个数:" + set[7];
            }
            bllLog.insert(log);
        }
예제 #2
0
        public void add(Model.DeviceLogInfo log)
        {
            try
            {
                OracleParameter[] parms = new OracleParameter[] {
                    new OracleParameter(":ID", log.DEVICE_ID),
                    new OracleParameter(":MSG", log.MESSAGE),
                    new OracleParameter(":TP", log.OPERATETYPE),
                    new OracleParameter(":TM", log.LOGTIME)
                };
                string SQL = "INSERT INTO ALARM_DEVICE_LOG (DBID,DEVICE_ID,MESSAGE,OPERATETYPE,LOGTIME) "
                             + "VALUES"
                             + " (SEQ_ALARM_DEVICE_LOG_ID.NEXTVAL,:ID,:MSG,:TP,:TM)";

                string strCnn = OracleHelper.ConnectionStringOrderDistributedTransaction;
                using (OracleConnection cnn = new OracleConnection(strCnn))
                {
                    OracleHelper.ExecuteNonQuery(cnn, CommandType.Text, SQL, parms);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public override void OnCommandExecuting(SuperSocket.SocketBase.CommandExecutingContext commandContext)
        {
            BLL.DeviceLog bllLog    = new DeviceLog();
            BLL.Device    bllDevice = new Device();
            DGNSZSession  session   = (DGNSZSession)commandContext.Session;

            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);
        }
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session;

            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     = "渗漏噪声服务器地址配置:" + ApplicationContext.getInstance().getSLIpConfig();
            log.OPERATETYPE = "下发";
            log.LOGTIME     = DateTime.Now;

            bllLog.insert(log);
        }
예제 #5
0
 public void insert(Model.DeviceLogInfo log)
 {
     try
     {
         if (log.DEVICE_ID <= 0)
         {
             return;
         }
         IDAL.IDeviceLog dal = DALFactory.DeviceLog.Create();
         dal.add(log);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            BLL.DeviceLog    bllLog    = new DeviceLog();
            BLL.Device       bllDevice = new Device();
            SZSLNoiseSession session   = (SZSLNoiseSession)commandContext.Session;

            try
            {
                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);
            }
            catch (Exception e)
            {
                commandContext.Session.Logger.Error("设备重启记录保存异常" + e.ToString());
            }
        }
예제 #7
0
        public override void OnCommandExecuting(SuperSocket.SocketBase.CommandExecutingContext commandContext)
        {
            DeviceLog bllLog    = new DeviceLog();
            Device    bllDevice = new Device();

            DGNSZSession  session = (DGNSZSession)commandContext.Session;
            DeviceLogInfo log     = null;

            if (session.PressConf != null)
            {
                session.Logger.Info("多功能漏损监测仪压力(" + session.MacID + ")配置成功!");

                session.PressConf.Status = true;
                new DeviceConfig().Update(session.PressConf);

                string[] config    = session.PressConf.FrameContent.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                string   interval1 = Int16.Parse(config[8] + config[9], System.Globalization.NumberStyles.HexNumber).ToString();
                string   interval2 = Int16.Parse(config[10] + config[11], System.Globalization.NumberStyles.HexNumber).ToString();

                log             = new Model.DeviceLogInfo();
                log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
                log.MESSAGE     = "压力配置下发.采集间隔" + interval1 + ";发送间隔" + interval2;
                log.OPERATETYPE = "add";
                log.LOGTIME     = DateTime.Now;
                bllLog.insert(log);
            }
            else
            {
                session.Logger.Info("多功能漏损监测仪压力(" + session.MacID + ")默认配置成功!");

                log             = new Model.DeviceLogInfo();
                log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
                log.MESSAGE     = "压力初始化!";
                log.OPERATETYPE = "add";
                log.LOGTIME     = DateTime.Now;
                bllLog.insert(log);
            }
        }
        public override void ExecuteCommand(RQSession session, BinaryRequestInfo requestInfo)
        {
            try
            {
                session.Logger.Info("燃气数据已经上传!");
                session.Logger.Info(BitConverter.ToString(requestInfo.Body, 0, requestInfo.Body.Length));
                byte[] body = requestInfo.Body;

                //sim卡号
                byte[] sim = new byte[6];
                Buffer.BlockCopy(body, 0, sim, 0, 6);


                ///
                ///校时
                ///
                string now  = DateTime.Now.ToString("yyMMddHHmmss");
                byte[] head = { 0x7B, 0x89, 0x00, 0x14,
                                0x00, 0x15,
                                0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
                                0x02,
                                0x10,
                                0x00, 0x34,
                                0x00, 0x03,
                                0x06 };
                byte[] bcd          = Utility.CodeUtils.Time2BCD(now);
                byte[] validateData = new byte[head.Length + bcd.Length];
                head.CopyTo(validateData, 0);
                bcd.CopyTo(validateData, head.Length);
                byte[] crc  = Utility.CodeUtils.getCrcByModBusData(validateData);
                byte[] resp = new byte[validateData.Length + crc.Length];
                validateData.CopyTo(resp, 0);
                crc.CopyTo(resp, validateData.Length);

                session.Logger.Info("燃气开始校时");
                session.Send(resp, 0, resp.Length);
                session.Logger.Info("燃气校时数据已经发送!");
                session.Logger.Info(BitConverter.ToString(resp));


                if (string.IsNullOrEmpty(session.MacID))
                {
                    //session.MacID = BitConverter.ToString(sim, 0, sim.Length).Replace("-", "").Replace("F", "");
                    #region how can u repalce f in ff ff ff ff ??
                    session.MacID = BitConverter.ToString(sim, 0, sim.Length).Replace("-", "").Substring(1);
                    #endregion
                }

                //主机地址
                string address = session.MacID;

                //本次上传一共有多少条数据
                //int count = (body.Length - 9) / 32;
                int count = (body.Length - 15) / 32;

                //将本次上传的所有采集数据保存在records数组中
                byte[] records = new byte[body.Length - 15];
                Buffer.BlockCopy(body, 13, records, 0, records.Length);

                List <Model.RQPeriodInfo> rqs = new List <Model.RQPeriodInfo>();
                for (int i = 0; i < count; i++)
                {
                    byte[] record   = new byte[32];
                    byte[] dateTime = new byte[6];

                    //将第i条数据保存在record数组中
                    Buffer.BlockCopy(records, i * 32, record, 0, 32);
                    Buffer.BlockCopy(record, 0, dateTime, 0, 6);

                    session.Logger.Info(BitConverter.ToString(dateTime));
                    session.Logger.Info(Utility.CodeUtils.String2DateTime(BitConverter.ToString(dateTime).Replace("-", "")));

                    Model.RQPeriodInfo rq = new Model.RQPeriodInfo();
                    rq.ADDRESS     = address;
                    rq.INPRESS     = BitConverter.ToSingle(new byte[] { record[7], record[6], record[9], record[8] }, 0).ToString();
                    rq.OUTPRESS    = BitConverter.ToSingle(new byte[] { record[11], record[10], record[13], record[12] }, 0).ToString();
                    rq.FLOW        = BitConverter.ToSingle(new byte[] { record[15], record[14], record[17], record[16] }, 0).ToString();
                    rq.STRENGTH    = BitConverter.ToSingle(new byte[] { record[19], record[18], record[21], record[20] }, 0).ToString();
                    rq.TEMPERATURE = BitConverter.ToSingle(new byte[] { record[23], record[22], record[25], record[24] }, 0).ToString();
                    rq.CELL        = BitConverter.ToSingle(new byte[] { record[27], record[26], record[29], record[28] }, 0).ToString();
                    rq.UPTIME      = Utility.CodeUtils.String2DateTime(BitConverter.ToString(dateTime).Replace("-", ""));
                    rq.LOGTIME     = DateTime.Now;
                    rqs.Add(rq);
                }

                BLL.RQPeriod bll = new BLL.RQPeriod();
                bll.insert(rqs);
                session.Logger.Info("迅腾燃气数据已经保存!");

                //增加燃气数据上报设备运行日志thc20150610
                Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                log.DEVICE_ID   = session.ID;
                log.MESSAGE     = "燃气监测数据上报!";
                log.OPERATETYPE = "燃气数据上报";
                log.LOGTIME     = DateTime.Now;
                new BLL.DeviceLog().insert(log);


                //之后进行数据记录的操作
                byte[] first      = { 0x7B, 0x89, 0x00, 0x10, 0x00, 0x0E };
                byte[] second     = { 0x01, 0x10, 0x00, 0x2C, 0x00, 0x60 };
                byte[] modBusData = new byte[first.Length + sim.Length + second.Length];

                first.CopyTo(modBusData, 0);
                sim.CopyTo(modBusData, first.Length);
                second.CopyTo(modBusData, first.Length + sim.Length);

                byte[] crcData      = Utility.CodeUtils.getCrcByModBusData(modBusData);
                byte[] responseData = new byte[modBusData.Length + crcData.Length];
                modBusData.CopyTo(responseData, 0);
                crcData.CopyTo(responseData, modBusData.Length);

                session.Send(responseData, 0, responseData.Length);

                session.Logger.Info("迅腾燃气数据上传确认已经发送!");



                ///
                ///配置SIM卡号
                ///
                //byte[] head = { 0x7B, 0x89, 0x00, 0x15,
                //                  0x00, 0x0F,
                //                  0x02,
                //                  0x10,
                //                  0x00, 0x56,
                //                  0x00, 0x03,
                //                  0x06,
                //                  0xF1, 0x52, 0x32, 0x67, 0x15, 0x21
                //              };
                //byte[] crc = Utility.CodeUtils.getCrcByModBusData(head);

                //byte[] resp = new byte[head.Length + crc.Length];

                //head.CopyTo(resp, 0);
                //crc.CopyTo(resp, head.Length);

                //session.Logger.Info("燃气SIM卡开始配置");
                //session.Send(resp, 0, resp.Length);
                //session.Logger.Info("燃气SIM卡号已经发送!");
                //session.Logger.Info(BitConverter.ToString(resp));

                ///
                ///读取采集器配置信息
                //
                //byte[] head = { 0x7B, 0x89, 0x00, 0x12,
                //                 0x00, 0x0E,
                //                 0xF1, 0x50, 0x11, 0x19, 0x19, 0x23,
                //                 0x02,
                //                 0x03,
                //                 0x00, 0x0D,
                //                 0x00, 0x27 };
                //byte[] crc = Utility.CodeUtils.getCrcByModBusData(head);
                //byte[] resp = new byte[head.Length + crc.Length];
                //head.CopyTo(resp, 0);
                //crc.CopyTo(resp, head.Length);

                //session.Logger.Info("燃气读取配置信息开始请求");
                //session.Send(resp, 0, resp.Length);
                //session.Logger.Info("燃气读取配置信息请求已经发送!");
                //session.Logger.Info(BitConverter.ToString(resp));

                //发送配置信息
                this.SendConfig(session, requestInfo);
            }
            catch (Exception e)
            {
                session.Logger.Error("燃气上传数据处理异常!");
                session.Logger.Error(e.ToString());
            }
        }
예제 #9
0
        public override void ExecuteCommand(WSSession session, StringRequestInfo requestInfo)
        {
            try
            {
                //SewPeriodData:设备ID,上传时间,CO数据,O2氧气数据,H2S数据,可燃气体数据\r\n
                session.Logger.Info("污水数据已经上传!");
                session.Logger.Info(requestInfo.Body);

                string[] bt = requestInfo.Body.Split(',');

                if (string.IsNullOrEmpty(session.MacID))
                {
                    session.MacID = bt[0];
                }

                Model.SewPeriodDataInfo sew = new Model.SewPeriodDataInfo();

                sew.DEVID = bt[0];
                //转换bt[1] 20131212101010 bug fix by predator
                string sdate = bt[1].Substring(0, 4) + "-" + bt[1].Substring(4, 2) + "-" + bt[1].Substring(6, 2) + " " + bt[1].Substring(8, 2) + ":" + bt[1].Substring(10, 2) + ":" + bt[1].Substring(12, 2);
                sew.UPTIME  = Convert.ToDateTime(sdate);
                sew.CO      = bt[2];
                sew.O2      = bt[3];
                sew.H2S     = bt[4];
                sew.FIREGAS = bt[5];
                new BLL.SewPeriodData().insert(sew);

                //send the time calibrating cmd

                /*
                 * string sdata = "SewTiming:" + bt[0]+","+DateTime.Now.ToString("yyyyMMddHHmmss");
                 * byte[] data = new byte[sdata.Length + 2];
                 * Encoding.ASCII.GetBytes(sdata, 0, sdata.Length, data, 0);
                 * data[sdata.Length] =  0x0D;
                 * data[sdata.Length + 1] = 0x0A;
                 * session.Send(data, 0, data.Length);
                 * */

                //send the success cmd;
                string sdata0 = "SewPeriodData:success";
                byte[] data0  = new byte[sdata0.Length + 2];
                Encoding.ASCII.GetBytes(sdata0, 0, sdata0.Length, data0, 0);
                data0[sdata0.Length]     = 0x0D;
                data0[sdata0.Length + 1] = 0x0A;
                session.Send(data0, 0, data0.Length);

                //增加设备运行日志
                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);
            }
            catch (Exception e)
            {
                session.Logger.Error("污水数据保存失败!");
                session.Logger.Error(e.ToString());
            }
        }
예제 #10
0
        public override void ExecuteCommand(RQSession session, BinaryRequestInfo requestInfo)
        {
            try
            {
                //F1-50-11-19-19-23-01-10-00-2D-00-10-20-14-09-17-15-56-36-00-
                //00-42-3C-F5-C3-40-18-80-00-43-6F-00-00-00-00-00-00-00-00-67-27-
                //41-72-00-02-11-6C
                byte[] body = requestInfo.Body;

                session.Logger.Info("接收到燃气报警数据上!" + BitConverter.ToString(body, 0, body.Length));

                byte[] sim = new byte[6];

                Buffer.BlockCopy(body, 0, sim, 0, 6);

                if (string.IsNullOrEmpty(session.MacID))
                {
                    session.MacID = BitConverter.ToString(sim).Replace("-", "").Substring(1);
                }

                //获取设备ID
                string devId = session.MacID;

                //将采集上的数据保存到数据库
                byte[] record   = new byte[30];
                byte[] dateTime = new byte[6];

                //获取报警记录信息
                Buffer.BlockCopy(body, 13, record, 0, body.Length - 17);

                //获取报警记录时间
                Buffer.BlockCopy(record, 0, dateTime, 0, 6);

                string   timeStr = BitConverter.ToString(dateTime).Replace("-", "");
                string   msg     = "燃气设备警告:@devid:@itemname:@itemvalue:@time";
                DateTime date    = Convert.ToDateTime("20" + timeStr.Substring(0, 2)
                                                      + "-" + timeStr.Substring(2, 2)
                                                      + "-" + timeStr.Substring(4, 2)
                                                      + " " + timeStr.Substring(6, 2)
                                                      + ":" + timeStr.Substring(8, 2)
                                                      + ":" + timeStr.Substring(10, 2));
                string inPress     = BitConverter.ToSingle(new byte[] { record[7], record[6], record[9], record[8] }, 0).ToString();
                string outPress    = BitConverter.ToSingle(new byte[] { record[11], record[10], record[13], record[12] }, 0).ToString();
                string flow        = BitConverter.ToSingle(new byte[] { record[15], record[14], record[17], record[16] }, 0).ToString();
                string strength    = BitConverter.ToSingle(new byte[] { record[19], record[18], record[21], record[20] }, 0).ToString();
                string temperature = BitConverter.ToSingle(new byte[] { record[23], record[22], record[25], record[24] }, 0).ToString();
                string cell        = BitConverter.ToSingle(new byte[] { record[27], record[26], record[29], record[28] }, 0).ToString();

                List <Model.AlarmRecordInfo> alarms = new List <Model.AlarmRecordInfo>();
                if (float.Parse(inPress) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_INPRESS_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    //alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "燃气进站压力")
                    // .Replace("@itemvalue", inPress).Replace("@time", date.ToString());

                    alarm.ITEMNAME         = "进站压力超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = inPress;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);

                    //增加进站压力超限设备运行日志thc20150610
                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = session.ID;
                    log.MESSAGE     = "燃气进站压力超限报警!";
                    log.OPERATETYPE = "报警数据上报";
                    log.LOGTIME     = DateTime.Now;
                    new BLL.DeviceLog().insert(log);
                }
                if (float.Parse(outPress) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_OUTPRESS_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    // alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "燃气出站压力")
                    //     .Replace("@itemvalue", outPress).Replace("@time", date.ToString());
                    alarm.ITEMNAME         = "出站压力超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = outPress;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);

                    //增加出站压力超限设备运行日志thc20150610
                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = session.ID;
                    log.MESSAGE     = "燃气出站压力超限报警!";
                    log.OPERATETYPE = "报警数据上报";
                    log.LOGTIME     = DateTime.Now;
                    new BLL.DeviceLog().insert(log);
                }
                if (float.Parse(flow) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_FLOW_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    //   alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "燃气流量")
                    //       .Replace("@itemvalue", flow).Replace("@time", date.ToString());
                    alarm.ITEMNAME         = "流量超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = flow;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);

                    //增加流量超限设备运行日志thc20150610
                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = session.ID;
                    log.MESSAGE     = "燃气流量超限报警!";
                    log.OPERATETYPE = "报警数据上报";
                    log.LOGTIME     = DateTime.Now;
                    new BLL.DeviceLog().insert(log);
                }
                if (float.Parse(strength) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_STRENGTH_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    // alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "燃气浓度")
                    //      .Replace("@itemvalue", strength).Replace("@time", date.ToString());
                    alarm.ITEMNAME         = "浓度超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = strength;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);

                    //增加浓度超限设备运行日志thc20150610
                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = session.ID;
                    log.MESSAGE     = "燃气浓度超限报警!";
                    log.OPERATETYPE = "报警数据上报";
                    log.LOGTIME     = DateTime.Now;
                    new BLL.DeviceLog().insert(log);
                }
                if (float.Parse(temperature) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_TEMPERATURE_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    // alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "燃气温度")
                    //     .Replace("@itemvalue", temperature).Replace("@time", date.ToString());
                    alarm.ITEMNAME         = "温度超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = temperature;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);

                    //增加温度超限设备运行日志thc20150610
                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = session.ID;
                    log.MESSAGE     = "燃气温度超限报警!";
                    log.OPERATETYPE = "报警数据上报";
                    log.LOGTIME     = DateTime.Now;
                    new BLL.DeviceLog().insert(log);
                }
                if (float.Parse(cell) != 0)
                {
                    Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                    alarm.RECORDCODE = "ALARM_XT_CELL_" + devId + "_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                    //  alarm.MESSAGE = msg.Replace("@devid", devId).Replace("@itemname", "电池电量")
                    //      .Replace("@itemvalue", cell).Replace("@time", date.ToString());
                    alarm.ITEMNAME         = "电量超限";
                    alarm.MESSAGE          = alarm.ITEMNAME;
                    alarm.ITEMVALUE        = cell;
                    alarm.DEVICE_ID        = (int)session.ID;
                    alarm.RECORDDATE       = DateTime.Now;
                    alarm.MESSAGE_STATUS   = 0;
                    alarm.ACTIVE           = true;
                    alarm.DEVICE_CODE      = session.MacID;
                    alarm.DEVICE_TYPE_NAME = "燃气智能监测终端";
                    alarms.Add(alarm);
                }

                new BLL.AlarmRecord().insert(alarms);

                //发送反馈信息
                byte[] first      = { 0x7B, 0x89, 0x00, 0x11, 0x00, 0x0E };
                byte[] second     = { 0x01, 0x10, 0x00, 0x2D, 0x00, 0x10 };
                byte[] modBusData = new byte[first.Length + sim.Length + second.Length];
                first.CopyTo(modBusData, 0);
                sim.CopyTo(modBusData, first.Length);
                second.CopyTo(modBusData, first.Length + sim.Length);

                byte[] crcData = Utility.CodeUtils.getCrcByModBusData(modBusData);
                byte[] resp    = new byte[modBusData.Length + crcData.Length];
                modBusData.CopyTo(resp, 0);
                crcData.CopyTo(resp, modBusData.Length);
                session.Send(resp, 0, resp.Length);
                session.Logger.Info("报警主动上报已确认!" + BitConverter.ToString(body, 0, body.Length));
            }
            catch (Exception e)
            {
                session.Logger.Error("燃气报警数据上传处理异常" + e.ToString());
            }
        }
예제 #11
0
        public override void ExecuteCommand(SZLiquidSession session, StringRequestInfo requestInfo)
        {
            try
            {
                session.Logger.Info("LSSETREQU:液位配置请求帧:" + requestInfo.Body);

                session.MacID = requestInfo.Parameters[5];
                string address = requestInfo.Parameters[3];
                byte   add0    = byte.Parse(address.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                byte   add1    = byte.Parse(address.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
                byte   add2    = byte.Parse(address.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);

                byte ss  = byte.Parse(DateTime.Now.ToString("yy"));
                byte ss1 = byte.Parse(DateTime.Now.ToString("MM"));
                byte ss2 = byte.Parse(DateTime.Now.ToString("dd"));
                byte ss3 = byte.Parse(DateTime.Now.ToString("HH"));
                byte ss4 = byte.Parse(DateTime.Now.ToString("mm"));
                byte ss5 = byte.Parse(DateTime.Now.ToString("ss"));
                byte ss7 = byte.Parse("0" + ((int)DateTime.Now.DayOfWeek).ToString());

                BLL.DeviceLog bllLog    = new DeviceLog();
                BLL.Device    bllDevice = new Device();

                DeviceConfigInfo conf;

                conf = (new DeviceConfig()).GetDeviceConfByDeviceCodeAndSensorCode(session.MacID, "000034");

                if (conf != null)
                {
                    //状态传感配置信息

                    //50# 00#14 #01 #00#00#34# C1 #00#05 #00#00#00#00 #1.23 #2D#17#0F#04#0F#0A#0F#03#

                    string   content = conf.FrameContent;
                    string[] items   = content.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);

                    //byte[] sendData = new byte[items.Length];
                    byte[] sendData = new byte[26];//固定26字节
                    //for (int i = 0; i < items.Length; i++)
                    for (int i = 0; i < 10; i++)
                    {
                        sendData[i] = byte.Parse(items[i], System.Globalization.NumberStyles.HexNumber);
                    }
                    //TODO LIST:修正液位警界高度、探头安装高度、当前时间
                    BLL.DjLiquid  djBll       = new BLL.DjLiquid();
                    AlarmRuleInfo rule        = djBll.getAlarmRuleByDevcode(session.MacID);
                    float         highValue   = rule != null ? rule.HighValue : 1000;
                    byte[]        btHighValue = BitConverter.GetBytes(highValue);
                    sendData[10 + 0] = btHighValue[0];
                    sendData[10 + 1] = btHighValue[1];
                    sendData[10 + 2] = btHighValue[2];
                    sendData[10 + 3] = btHighValue[3];

                    float  height   = float.Parse(items[14]);
                    byte[] btHeight = BitConverter.GetBytes(height);
                    sendData[14 + 0] = btHeight[0];
                    sendData[14 + 1] = btHeight[1];
                    sendData[14 + 2] = btHeight[2];
                    sendData[14 + 3] = btHeight[3];

                    if (requestInfo.Parameters[0] == "50")
                    {
                        //液位时间修正
                        sendData[18] = ss5;
                        sendData[19] = ss4;
                        sendData[20] = ss3;
                        sendData[21] = ss7;
                        sendData[22] = ss2;
                        sendData[23] = ss1;
                        sendData[24] = ss;
                        sendData[25] = 0x03;
                    }

                    string head   = "LSSETREQU:";
                    byte[] btHead = System.Text.Encoding.Default.GetBytes(head);
                    byte[] result = new byte[sendData.Length + btHead.Length];

                    Buffer.BlockCopy(btHead, 0, result, 0, btHead.Length);
                    Buffer.BlockCopy(sendData, 0, result, btHead.Length, sendData.Length);

                    session.Send(result, 0, result.Length);

                    //

                    /*
                     * String crcIn = "";
                     * for (int i = 0; i < sendData.Length; i++)
                     * {
                     *  crcIn += sendData[i].ToString("X2");
                     * }
                     * ushort crcOut = CodeUtils.QuickCRC16(crcIn, 0, crcIn.Length);
                     * byte[] crcOutByte = BitConverter.GetBytes(crcOut);
                     * sendData[7] = crcOutByte[1];
                     * sendData[8] = crcOutByte[0];
                     * **/

                    session.Logger.Info("成功下发液位配置帧:" + BitConverter.ToString(result));
                    session.LiquidConf          = conf;
                    session.LiquidConf.SendTime = DateTime.Now;

                    Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                    log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
                    log.MESSAGE     = "液位数据配置:采集间隔:" + sendData[9] + "分钟";
                    log.OPERATETYPE = "下发";
                    log.LOGTIME     = DateTime.Now;
                    bllLog.insert(log);

                    return;
                }

                //无配置信息处理发送校时帧

                byte[] setTime = { 0x50,
                                   0x00, 0x14,
                                   0x01,
                                   0x00, 0x00, 0x34,
                                   0xC2,
                                   0x00, 0x05,
                                   0x00, 0x00, 0x00, 0x00,
                                   0x00, 0x00, 0x00, 0x00,
                                   ss5, ss4,  ss3,
                                   ss7, ss2,  ss1,  ss,
                                   0x03 };

                string head0   = "LSSETREQU:";
                byte[] btHead0 = System.Text.Encoding.Default.GetBytes(head0);
                byte[] result0 = new byte[setTime.Length + btHead0.Length];

                Buffer.BlockCopy(btHead0, 0, result0, 0, btHead0.Length);
                Buffer.BlockCopy(setTime, 0, result0, btHead0.Length, setTime.Length);

                session.Send(result0, 0, result0.Length);
                session.Logger.Info("成功下发液位计校时帧:" + BitConverter.ToString(result0, 0));
            }
            catch (Exception e)
            {
                session.Logger.Error(e.ToString());
            }
        }
        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
            {
            }
        }
예제 #13
0
        public override void ExecuteCommand(WSSession session, StringRequestInfo requestInfo)
        {
            try
            {
                //SewAlarmData:设备ID,上传时间,CO数据,O2氧气数据,H2S数据,可燃气体数据\r\n
                session.Logger.Info("污水报警数据上传!");
                session.Logger.Info(requestInfo.Body);

                string[] bt = requestInfo.Body.Split(',');
                if (string.IsNullOrEmpty(session.MacID))
                {
                    session.MacID = bt[0];
                }
                List <Model.AlarmRecordInfo> alarms = new List <Model.AlarmRecordInfo>();
                //TODO LIST:根据李雨龙需求,修改可能发生的4个报警记录合并为一条报警记录
                // 一氧化碳、硫化氢、氧气、甲烷

                Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                alarm.RECORDCODE     = "WS_ALARM_H2S_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                alarm.MESSAGE        = "有害气体超标";
                alarm.ITEMNAME       = "FIREGAS";
                alarm.DEVICE_ID      = session.ID;
                alarm.DEVICE_CODE    = session.MacID;
                alarm.MESSAGE_STATUS = 0;
                alarm.ACTIVE         = true;
                string stime = bt[1];
                string sdate = stime.Substring(0, 4) + "-" + stime.Substring(4, 2) + "-" + stime.Substring(6, 2)
                               + " " + stime.Substring(8, 2) + ":" + stime.Substring(10, 2) + ":" + stime.Substring(12, 2);
                alarm.RECORDDATE       = Convert.ToDateTime(sdate);
                alarm.DEVICE_TYPE_NAME = "有害气体监测仪";
                string result       = "";
                double coAlarm      = Convert.ToDouble(bt[2]) > 50.0?Convert.ToDouble(bt[2]):0;
                double o2Alarm      = Convert.ToDouble(bt[3]) > 18 && Convert.ToDouble(bt[3]) < 23 ? 0 : Convert.ToDouble(bt[3]);
                double h2sAlarm     = Convert.ToDouble(bt[4]) > 10.0 ? Convert.ToDouble(bt[4]) : 0;
                double firegasAlarm = Convert.ToDouble(bt[5]) > 2 ? Convert.ToDouble(bt[5]) : 0;
                result = coAlarm + "," +
                         h2sAlarm + "," +
                         o2Alarm + "," +
                         firegasAlarm;
                alarm.ITEMVALUE = result;

                alarms.Add(alarm);

                /*
                 * if (Convert.ToDouble(bt[3]) > 0)
                 * {
                 *  Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                 *  alarm.RECORDCODE = "WS_ALARM_CO_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                 *  //alarm.MESSAGE = "污水一氧化碳报警:【值:" + bt[3] + "】【时间:"+bt[1] + "】";
                 *  alarm.MESSAGE = "CO超标";
                 *  alarm.ITEMNAME = "CO";
                 *  alarm.ITEMVALUE = bt[3];
                 *  alarm.DEVICE_ID = session.ID;
                 *  alarm.MESSAGE_STATUS = false;
                 *  alarm.ACTIVE = true;
                 *  alarm.DEVICE_CODE = session.MacID;
                 *  alarm.DEVICE_TYPE_NAME = "有害气体监测仪";
                 *  alarms.Add(alarm);
                 *
                 *  //增加CO气体浓度报警设备运行日志thc20150610
                 *  Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                 *  log.DEVICE_ID = session.ID;
                 *  log.MESSAGE = "CO浓度超限!";
                 *  log.OPERATETYPE = "有害气体数据上报";
                 *  log.LOGTIME = DateTime.Now;
                 *  new BLL.DeviceLog().insert(log);
                 * }
                 * if (Convert.ToDouble(bt[4]) > 0)
                 * {
                 *  Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                 *  alarm.RECORDCODE = "WS_ALARM_O2_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                 * // alarm.MESSAGE = "污水氧气报警:【值:" + bt[3] + "】【时间:"+bt[1] + "】";
                 *  alarm.MESSAGE = "氧气过低";
                 *  alarm.ITEMNAME = "O2";
                 *  alarm.ITEMVALUE = bt[4];
                 *  alarm.DEVICE_ID = session.ID;
                 *  alarm.MESSAGE_STATUS = false;
                 *  alarm.ACTIVE = true;
                 *  alarm.DEVICE_CODE = session.MacID;
                 *  alarm.DEVICE_TYPE_NAME = "有害气体监测仪";
                 *  alarms.Add(alarm);
                 *
                 *  //增加O2气体浓度报警设备运行日志thc20150610
                 *  Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                 *  log.DEVICE_ID = session.ID;
                 *  log.MESSAGE = "O2浓度超限!";
                 *  log.OPERATETYPE = "有害气体数据上报";
                 *  log.LOGTIME = DateTime.Now;
                 *  new BLL.DeviceLog().insert(log);
                 * }
                 * if (Convert.ToDouble(bt[5]) > 0)
                 * {
                 *  Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                 *  alarm.RECORDCODE = "WS_ALARM_H2S_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                 * //  alarm.MESSAGE = "污水H2S报警:【值:" + bt[4] + "】【时间:" +bt[1] + "】";
                 *  alarm.MESSAGE = "H2S超标";
                 *  alarm.ITEMNAME = "H2S";
                 *  alarm.ITEMVALUE = bt[5];
                 *  alarm.DEVICE_ID = session.ID;
                 *  alarm.MESSAGE_STATUS = false;
                 *  alarm.ACTIVE = true;
                 *  alarm.DEVICE_CODE = session.MacID;
                 *  alarm.DEVICE_TYPE_NAME = "有害气体监测仪";
                 *  alarms.Add(alarm);
                 *
                 *  //增加H2S气体浓度报警设备运行日志thc20150610
                 *  Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                 *  log.DEVICE_ID = session.ID;
                 *  log.MESSAGE = "H2S浓度超限!";
                 *  log.OPERATETYPE = "有害气体数据上报";
                 *  log.LOGTIME = DateTime.Now;
                 *  new BLL.DeviceLog().insert(log);
                 * }
                 *
                 * if (Convert.ToDouble(bt[6]) > 0)
                 * {
                 *  Model.AlarmRecordInfo alarm = new Model.AlarmRecordInfo();
                 *  alarm.RECORDCODE = "WS_ALARM_H2S_" + DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
                 * //  alarm.MESSAGE = "污水可燃气体报警:【值:" + bt[5] + "】【时间:" + bt[1] + "】";
                 *  alarm.MESSAGE = "甲烷超标";
                 *  alarm.ITEMNAME = "FIREGAS";
                 *  alarm.ITEMVALUE = bt[6];
                 *  alarm.DEVICE_ID = session.ID;
                 *  alarm.DEVICE_CODE = session.MacID;
                 *  alarm.MESSAGE_STATUS = false;
                 *  alarm.ACTIVE = true;
                 *  alarm.DEVICE_TYPE_NAME = "有害气体监测仪";
                 *  alarms.Add(alarm);
                 *
                 *  //增加可燃气体报警设备运行日志thc20150610
                 *  Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                 *  log.DEVICE_ID = session.ID;
                 *  log.MESSAGE = "可燃气体浓度超限!";
                 *  log.OPERATETYPE = "有害气体数据上报";
                 *  log.LOGTIME = DateTime.Now;
                 *  new BLL.DeviceLog().insert(log);
                 * }
                 **/
                new BLL.AlarmRecord().insert(alarms);

                Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                log.DEVICE_ID   = session.ID;
                log.MESSAGE     = "有害气体浓度超标!";
                log.OPERATETYPE = "有害气体数据上报";
                log.LOGTIME     = DateTime.Now;
                new BLL.DeviceLog().insert(log);

                //send the success cmd
                string sdata0 = "SewAlarmData:success";
                byte[] data0  = new byte[sdata0.Length + 2];
                Encoding.ASCII.GetBytes(sdata0, 0, sdata0.Length, data0, 0);
                data0[sdata0.Length]     = 0x0D;
                data0[sdata0.Length + 1] = 0x0A;
                session.Send(data0, 0, data0.Length);
            }
            catch (Exception e)
            {
                session.Logger.Error("污水报警数据保存异常!");
                session.Logger.Error(requestInfo.Body);
                session.Logger.Error(e.ToString());
            }
        }