Beispiel #1
0
        /// <summary>
        /// 主站请求写数据对象
        /// </summary>
        /// <param name="buffer"></param>
        /// <returns></returns>
        private DataItem getWriteDataAskItem(byte[] buffer)
        {
            IdentityCode identityCode = MyDataConvert.get数据表示符(buffer);
            DataItem     item         = null;

            switch (identityCode)
            {
            case IdentityCode.写价格表:
                item = new DataItem_A010(buffer);
                break;

            case IdentityCode.写结算日:
                item = new DataItem_A011(buffer);
                break;

            case IdentityCode.写购入金额:
                item = new DataItem_A013(buffer);
                break;

            case IdentityCode.写新密钥:
                item = new DataItem_A014(buffer);
                break;

            case IdentityCode.写标准时间:
                item = new DataItem_A015(buffer);
                break;

            case IdentityCode.写阀门控制:
                item = new DataItem_A017(buffer);
                break;

            case IdentityCode.出厂启用:
                item = new DataItem_A019(buffer);
                break;

            case IdentityCode.写地址:
                item = new DataItem_A018(buffer);
                break;

            case IdentityCode.写表底数:
                item = new DataItem_A016(buffer);
                break;

            default:
                break;
            }

            return(item);
        }
        public static string TurnOff(IoT_Meter meter, out string taskID)
        {
            //创建一个任务
            string result = "";
            MongoDBHelper <Task> mongo_task = new MongoDBHelper <Task>();
            Task task = new Task();

            task.MeterMac  = meter.MeterNo.Trim();
            task.TaskDate  = QuShi.getDate();
            task.TaskID    = Guid.NewGuid().ToString(); //用于和指令进行进行关联
            task.TaskState = TaskState.Waitting;
            task.TaskType  = TaskType.TaskType_关阀;      //点火任务(DH),换表登记(HB)、开阀(KF)、关阀(GF)、充值(CZ)、调整价格(TJ)
            //写任务
            result = mongo_task.Insert(CollectionNameDefine.TaskCollectionName, task);
            taskID = task.TaskID;
            if (result != "")
            {
                return(result);
            }

            //创建命令
            Command       cmd       = new Command();
            byte          ser       = Convert.ToByte(new Random().Next(0, 255));
            DataItem_A017 item_A017 = new DataItem_A017(ser, false);

            cmd.TaskID         = task.TaskID;
            cmd.Identification = ((UInt16)item_A017.IdentityCode).ToString("X2");
            cmd.ControlCode    = (byte)ControlCode.WriteData;//写操作
            cmd.DataLength     = Convert.ToByte(item_A017.Length);
            cmd.DataCommand    = MyDataConvert.BytesToHexStr(item_A017.GetBytes());
            cmd.Order          = 1;
            result             = CommandDA.Insert(cmd);
            if (result != "")
            {
                return(result);
            }
            return("");
        }
Beispiel #3
0
        /// <summary>
        /// 处理主站请求的写操作,并返回应答数据对象
        /// </summary>
        /// <param name="identityCode"></param>
        /// <param name="ser"></param>
        /// <param name="oldItem"></param>
        /// <returns></returns>
        private DataItem DowithWriteData(IdentityCode identityCode, byte ser, DataItem oldItem)
        {
            //在该方法中将写入数据设置到响应变量中
            DataItem item = null;

            switch (identityCode)
            {
            case IdentityCode.写价格表:
                DataItem_A010 item_10 = oldItem as DataItem_A010;
                this.MeterType = ((byte)item_10.CT.CTMeterType).ToString().PadLeft(2, '0');
                if (出厂状态 && item_10.CT.CTMeterType == Common.Item.MeterType.金额表)
                {
                    this.出厂状态           = false;
                    this.IsUsedLadder   = item_10.CT.CTIsLadder;
                    this.Ladder         = item_10.CT.CTLadderNum;
                    this.Price1         = item_10.Price1;
                    this.Gas1           = item_10.UseGas1;
                    this.Price2         = item_10.Price2;
                    this.Gas2           = item_10.UseGas2;
                    this.Price3         = item_10.Price3;
                    this.Gas3           = item_10.UseGas3;
                    this.Price4         = item_10.Price4;
                    this.Gas4           = item_10.UseGas4;
                    this.Price5         = item_10.Price5;
                    this.SettlementType = ((byte)item_10.CT.CTJieSuanType).ToString().PadLeft(2, '0');    //结算类型
                    //设置初次转换为金额表的当前计价参数
                    this.CurrentLadder = 1;
                    this.CurrentPrice  = this.Price1;
                    this.LastGasPoint  = 0;   //上次结算时表底

                    if (this.IsUsedLadder && this.Ladder > this.CurrentLadder)
                    {
                        //计算下一个结算点
                        this.NextSettlementPointGas = this.Gas1;
                        this.SetNextSettlementDateTime();
                    }
                    else
                    {
                        //非阶梯价或无阶梯,-1表示正无穷大
                        this.NextSettlementPointGas = -1;
                    }
                }
                else if (!出厂状态 && item_10.CT.CTMeterType == Common.Item.MeterType.金额表)
                {
                    //调价
                    PricingPlan plan = new PricingPlan();

                    plan.IsUsedLadder   = item_10.CT.CTIsLadder;
                    plan.Ladder         = item_10.CT.CTLadderNum;
                    plan.Price1         = item_10.Price1;
                    plan.Gas1           = item_10.UseGas1;
                    plan.Price2         = item_10.Price2;
                    plan.Gas2           = item_10.UseGas2;
                    plan.Price3         = item_10.Price3;
                    plan.Gas3           = item_10.UseGas3;
                    plan.Price4         = item_10.Price4;
                    plan.Gas4           = item_10.UseGas4;
                    plan.Price5         = item_10.Price5;
                    plan.UseDate        = item_10.StartDate.ToString();
                    plan.MeterType      = ((byte)item_10.CT.CTMeterType).ToString();
                    plan.SettlementType = ((byte)item_10.CT.CTJieSuanType).ToString().PadLeft(2, '0');    //结算类型
                    plan.MeterNo        = this.Mac;
                    this.AddPlan(plan);
                }
                item = new DataItem_A010_Answer(ser, _st1);
                break;

            case IdentityCode.写结算日:
                DataItem_A011 item_11 = oldItem as DataItem_A011;

                this.SettlementDay   = item_11.JieSuanDay;
                this.SettlementMonth = item_11.JieSuanMonth;
                SetNextSettlementDateTime();
                item = new DataItem_A011_Answer(ser);
                break;

            case IdentityCode.写购入金额:
                DataItem_A013 item_13 = oldItem as DataItem_A013;
                if (this.lastBuySer != ser)
                {
                    if (this.lastBuySer != ser)
                    {
                        this.LastSettlementAmount += item_13.BuyMoney;    //写入购买金额
                        this.TotalTopUp           += item_13.BuyMoney;
                        this.CurrentBalance       += item_13.BuyMoney;
                        this.lastBuySer            = ser;
                    }
                }
                item = new DataItem_A013_ASK(ser, item_13.BuyIndex, item_13.BuyMoney);
                break;

            case IdentityCode.写新密钥:
                DataItem_A014 item_14 = oldItem as DataItem_A014;
                this.Key     = item_14.Key;
                this.MKeyVer = item_14.Version;
                item         = new DataItem_A014_ASK(ser, item_14.Version);
                break;

            case IdentityCode.写标准时间:
                item = new DataItem_A015_ASK(ser);
                break;

            case IdentityCode.写阀门控制:
                DataItem_A017 item_17 = oldItem as DataItem_A017;
                this.ValveState      = item_17.IsOpen == true ? "0" : "1";
                this._st1.ValveStatu = item_17.IsOpen;
                item = new DataItem_A017_ASK(ser, this._st1);
                break;

            case IdentityCode.出厂启用:
                item = new DataItem_A019(ser);
                break;

            case IdentityCode.写地址:
                item = new DataItem_A018_Answer(ser);
                break;

            default:
                break;
            }
            Update();
            return(item);
        }