public override void execute(Tag tag, String devCode, CellTag cellTag,
                                     SystemDateTag systemDateTag, CasicSession session)
        {
            //TODO LIST:解析压力数据保存压力数据
            UploadTag rqTag      = tag as UploadTag;
            int       itv        = rqTag.CollectInter;
            String    collecTime = rqTag.CollectTime;
            int       len        = rqTag.Len;
            String    dataValue  = rqTag.DataValue;

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

            int num = len / 4; //上传的燃气数据个数
            List <Model.RQPeriodInfo> rqs = new List <Model.RQPeriodInfo>();

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

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

                Model.RQPeriodInfo rq = new Model.RQPeriodInfo();
                rq.ADDRESS     = devCode;
                rq.INPRESS     = "0";
                rq.OUTPRESS    = "0";
                rq.FLOW        = "0";
                rq.STRENGTH    = density;
                rq.TEMPERATURE = "0";
                rq.CELL        = (cellTag == null ? "" : cellTag.Cell);
                rq.UPTIME      = baseTime.AddMinutes(i * itv);
                rq.LOGTIME     = DateTime.Now;
                rqs.Add(rq);
            }
            BLL.RQPeriod bll = new BLL.RQPeriod();
            bll.insert(rqs);
            bll.saveAlarmInfo(rqs);
            session.Logger.Info("燃气数据保存成功");
        }
Beispiel #2
0
        /// <summary>
        /// An internal function to bind values parameters for insert
        /// </summary>
        /// <param name="parms">Database parameters</param>
        /// <param name="RQ">Values to bind to parameters</param>
        private void SetAdapterParameters(OracleParameter[] parms, Model.RQPeriodInfo RQ)
        {
            if (null != RQ.ADDRESS)
            {
                parms[0].Value = RQ.ADDRESS;
            }
            else
            {
                parms[0].Value = DBNull.Value;
            }

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

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

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

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

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

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

            if (null != RQ.UPTIME)
            {
                parms[7].Value = RQ.UPTIME;
            }
            else
            {
                parms[7].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            }

            if (null != RQ.LOGTIME)
            {
                parms[8].Value = RQ.LOGTIME;
            }
            else
            {
                parms[8].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            }
        }
        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());
            }
        }