コード例 #1
0
        public PackageHelper(BinInfo info, IDownloadSender downloadSender)
        {
            _binInfo       = info;
            DownloadSender = downloadSender;
            var rest              = info.BinConfigFileLength % info.PackageBinLength;
            var fullPackageCount  = info.BinConfigFileLength / info.PackageBinLength;
            var totalPackageCount = rest == 0 ? (ushort)fullPackageCount : (ushort)(fullPackageCount + 1);

            _package       = new FirmwareUpdatePackage(totalPackageCount, info);
            _timerOutTimer = new Timer
            {
                Interval = _binInfo.TimeOut * 1000,
                Enabled  = true
            };
            _timerOutTimer.Elapsed += (sender, args) =>
            {
                _isDownloading           = false;
                DownloadSender.Received -= Received;
                DownloadInterrupt(new DownloadInterruptedEventArgs
                {
                    Message = "等待回复超时。"
                });
                _timerOutTimer.Stop();
            };
        }
コード例 #2
0
        public FirmwareUpdatePackage(ushort totalPackageCount, BinInfo info) : this()
        {
            var packageCountBytes = BitConverter.GetBytes(totalPackageCount);

            Array.Reverse(packageCountBytes);
            _totalPackageCount = packageCountBytes;
            var fileLengthBytes = BitConverter.GetBytes(info.BinConfigFileLength);

            Array.Reverse(fileLengthBytes);
            _binfileByteLength = fileLengthBytes;
            var timeOutBtesBytes = BitConverter.GetBytes(info.TimeOut);

            Array.Reverse(timeOutBtesBytes);
            _timeOut  = timeOutBtesBytes;
            _sender   = 0x01;
            _receiver = info.TargetObject;
        }