/// <summary>
        /// 远程还原最近一次备份程序
        /// </summary>
        /// <param name="masProtocol"></param>
        /// <param name="reductionRequest"></param>
        /// <param name="deviceCode"></param>
        /// <returns></returns>
        public byte[] HandReduction(MasProtocol masProtocol, ReductionRequest reductionRequest, ref string deviceCode)
        {
            DeviceInfo              deviceinfoobject = null;
            DeviceTypeInfo          devicetypeobject = null;
            NetworkDeviceInfo       netmacobject     = null;
            ReductionRequestCommand commandobject    = new ReductionRequestCommand();

            byte[] sendbuff = null;
            if (masProtocol == null || reductionRequest == null)
            {
                return(sendbuff);
            }
            if (!GetDeviceObject(ref deviceinfoobject, ref devicetypeobject, ref netmacobject, ProtocolType.DeviceControlRequest, reductionRequest.DeviceCode))
            {
                return(sendbuff);
            }
            if (netmacobject.NetID > 0)
            {
                deviceCode    = netmacobject.MAC;                                                                                          //向下的发送的MAC地址
                commandobject = Basic.Framework.Common.ObjectConverter.Copy <ReductionRequest, ReductionRequestCommand>(reductionRequest); //得到基础数据

                commandobject.DeviceId    = reductionRequest.DeviceId;
                commandobject.HardVersion = reductionRequest.HardVersion;
                commandobject.SoftVersion = reductionRequest.SoftVersion;

                commandobject.def = deviceinfoobject;        // Framework.Common.ObjectConverter.DeepCopy<DeviceInfo>(deviceinfoobject);//得到分站的对象必须是深度拷贝;
                sendbuff          = commandobject.ToBytes(); //得到通讯命令的返回Buffer数组
                //if (sendbuff != null)
                //{
                //    sendbuff = Cache.GetPackages(sendbuff, netmacobject, deviceinfoobject, 2, CommandCodes.ExtendCommand, (byte)devicetypeobject.LC2);//通过当前网络模块进行打包
                //}
            }
            return(sendbuff);
        }
Ejemplo n.º 2
0
        public static StationUpdateItem GetStationItem(int fzh)
        {
            StationUpdateItem item = null;

            if (fzh >= 0 && fzh < stationItems.Length - 1)
            {
                if (stationItems[fzh - 1] == null)
                {
                    return(item);
                }
                item = DeepCopy(stationItems[fzh - 1]);
                item.isSendBuffer = false;
                switch (item.updateState)
                {
                case StationUpdateState.requesting:    //下发请求升级    下发请求升级
                    StationUpdateRequest stationUpdateRequest = new StationUpdateRequest();
                    stationUpdateRequest.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    stationUpdateRequest.DeviceId    = (byte)updatetTypeid;
                    stationUpdateRequest.HardVersion = (byte)updateHardVersion;
                    stationUpdateRequest.FileVersion = (byte)updateFileVersion;
                    stationUpdateRequest.maxVersion  = (byte)updateMaxVersion;
                    stationUpdateRequest.minVersion  = (byte)updateMinVersion;
                    stationUpdateRequest.FileCount   = updateCount;
                    stationUpdateRequest.Crc         = crcValue;
                    item.isSendBuffer = true;
                    item.protocol     = stationUpdateRequest;
                    item.protocolType = ProtocolType.StationUpdateRequest;
                    break;

                case StationUpdateState.recivingFile:    //文件接收中    下发文件
                    if (item.nowNeedSendBuffIndex >= updateCount)
                    {
                        item.updateState = StationUpdateState.reiciveCheck;
                        return(null);
                    }
                    SendUpdateBufferRequest sendUpdateBufferRequest = new SendUpdateBufferRequest();
                    sendUpdateBufferRequest.DeviceCode     = fzh.ToString().PadLeft(3, '0') + "0000";
                    sendUpdateBufferRequest.DeviceId       = (byte)updatetTypeid;
                    sendUpdateBufferRequest.HardVersion    = (byte)updateHardVersion;
                    sendUpdateBufferRequest.FileVersion    = (byte)updateFileVersion;
                    sendUpdateBufferRequest.NowBufferIndex = item.nowNeedSendBuffIndex;
                    sendUpdateBufferRequest.Buffer         = new byte[256];
                    for (int i = 0; i < sendUpdateBufferRequest.Buffer.Length; i++)
                    {
                        sendUpdateBufferRequest.Buffer[i] = updateBuffer[(item.nowNeedSendBuffIndex - 1) * 256 + i];
                    }
                    item.isSendBuffer = true;
                    item.protocol     = sendUpdateBufferRequest;
                    item.protocolType = ProtocolType.SendUpdateBufferRequest;
                    stationItems[fzh - 1].nowNeedSendBuffIndex += 1;
                    if (stationItems[fzh - 1].nowNeedSendBuffIndex >= updateCount)
                    {
                        stationItems[fzh - 1].updateState = StationUpdateState.reiciveCheck;    //下发完成后自动切换到巡检
                    }
                    break;

                case StationUpdateState.reiciveCheck:    //巡检文件接收情况     下发巡检
                    InspectionRequest inspectionRequest = new InspectionRequest();
                    inspectionRequest.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    inspectionRequest.DeviceId    = (byte)updatetTypeid;
                    inspectionRequest.HardVersion = (byte)updateHardVersion;
                    inspectionRequest.FileVersion = (byte)updateFileVersion;
                    inspectionRequest.LostFileNum = 0;
                    item.isSendBuffer             = true;
                    item.protocol     = inspectionRequest;
                    item.protocolType = ProtocolType.InspectionRequest;
                    break;

                case StationUpdateState.replacement:    //补发文件中       补发文件
                    InspectionRequest replacement = new InspectionRequest();
                    replacement.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    replacement.DeviceId    = (byte)updatetTypeid;
                    replacement.HardVersion = (byte)updateHardVersion;
                    replacement.FileVersion = (byte)updateFileVersion;
                    replacement.LostFileNum = item.nowNeedSendBuffIndex;
                    if (replacement.LostFileNum > 0)
                    {
                        replacement.FileBuffer = new byte[256];
                        for (int i = 0; i < replacement.FileBuffer.Length; i++)
                        {
                            replacement.FileBuffer[i] = updateBuffer[(item.nowNeedSendBuffIndex - 1) * 256 + i];
                        }
                    }
                    item.isSendBuffer = true;
                    item.protocol     = replacement;
                    item.protocolType = ProtocolType.InspectionRequest;
                    break;

                case StationUpdateState.restart:    //重启升级      下发重启命令
                    RestartRequest restartRequest = new RestartRequest();
                    restartRequest.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    restartRequest.DeviceId    = (byte)updatetTypeid;
                    restartRequest.HardVersion = (byte)updateHardVersion;
                    restartRequest.FileVersion = (byte)updateFileVersion;
                    item.isSendBuffer          = true;
                    item.protocol     = restartRequest;
                    item.protocolType = ProtocolType.RestartRequest;
                    break;

                case StationUpdateState.restore:    //恢复备份      下发恢复备份命令
                    ReductionRequest reductionRequest = new ReductionRequest();
                    reductionRequest.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    reductionRequest.DeviceId    = (byte)updatetTypeid;
                    reductionRequest.HardVersion = (byte)updateHardVersion;
                    reductionRequest.SoftVersion = (byte)updateFileVersion;
                    item.isSendBuffer            = true;
                    item.protocol     = reductionRequest;
                    item.protocolType = ProtocolType.ReductionRequest;
                    break;

                case StationUpdateState.updateCancle:     //取消升级    //下取消升级命令
                    UpdateCancleRequest updateCancleRequest = new UpdateCancleRequest();
                    updateCancleRequest.DeviceCode  = fzh.ToString().PadLeft(3, '0') + "0000";
                    updateCancleRequest.DeviceId    = (byte)updatetTypeid;
                    updateCancleRequest.HardVersion = (byte)updateHardVersion;
                    updateCancleRequest.FileVersion = (byte)updateFileVersion;
                    item.isSendBuffer = true;
                    item.protocol     = updateCancleRequest;
                    item.protocolType = ProtocolType.UpdateCancleRequest;
                    break;

                case StationUpdateState.getVersion:    //获取分站信息
                    GetStationUpdateStateRequest getStationUpdateStateRequest = new GetStationUpdateStateRequest();
                    getStationUpdateStateRequest.DeviceCode     = fzh.ToString().PadLeft(3, '0') + "0000";
                    getStationUpdateStateRequest.GetSoftVersion = 1;
                    getStationUpdateStateRequest.GetUpdateState = 1;
                    getStationUpdateStateRequest.GetDevType     = 1;
                    getStationUpdateStateRequest.GetHardVersion = 1;
                    item.isSendBuffer = true;
                    item.protocol     = getStationUpdateStateRequest;
                    item.protocolType = ProtocolType.GetStationUpdateStateRequest;
                    break;
                }
            }
            return(item);
        }