private DirectiveResult ParsePausingResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (!DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                ret.Status = false;
                return(ret);
            }

            ret.Status = true;
            var data = new RockerDirectiveData();

            data.DeviceId      = bytes[0];
            data.DirectiveType = (DirectiveTypeEnum)bytes[1];
            data.TimeInterval  = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray());
            data.Speed         = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(4).Take(2).ToArray());
            data.DeviceStatus  = bytes.Skip(6).Take(1).FirstOrDefault();
            data.DirectiveId   = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(7).Take(2).ToArray());
            data.DeviceType    = TargetDeviceTypeEnum.Rocker;

            ret.SourceDirectiveType = DirectiveTypeEnum.Pausing;
            ret.Data = data;

            return(ret);
        }
Example #2
0
        private DirectiveResult ParseIdleResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (!DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                ret.Status = false;
                return(ret);
            }

            ret.Status = true;
            var data = new TemperatureDirectiveData();

            data.DeviceId      = bytes[0];
            data.DirectiveType = (DirectiveTypeEnum)bytes[1];

            data.Temperature = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray()) / 10;
            data.DirectiveId = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(4).Take(2).ToArray());
            data.DeviceType  = (TargetDeviceTypeEnum)bytes.Skip(6).Take(1).FirstOrDefault();

            ret.Data = data;
            ret.SourceDirectiveType = DirectiveTypeEnum.Idle;

            return(ret);
        }
Example #3
0
        private void HandleFeedback(DirectiveResult recvData, byte[] directiveBytes)
        {
            WaitForFeedBack metadata = null;

            if (!_waitForFeedbackDirectives.ContainsKey(recvData.Data.DirectiveId))
            {
                LogFactory.Create().Warnning($"waitForFeedbackDirectives not ContainsKey {recvData.Data.DirectiveId}");
                return;
            }

            var feedback = _waitForFeedbackDirectives[recvData.Data.DirectiveId];

            //修正同一个指令id,发送和反馈对应的设备不同或者类型不同
            if (feedback?.Directive == null || feedback.Directive.TargetDeviceId != recvData.Data.DeviceId)
            {
                LogFactory.Create().Warnning("send and feedback not match");
                return;
            }

            if (_waitForFeedbackDirectives.TryRemove(recvData.Data.DirectiveId, out metadata) && null != metadata)
            {
                var args = new SerialPortEventArgs
                {
                    IsSucceed = true,
                    Result    = recvData,
                    Command   = directiveBytes
                };

                OnSerialPortEvent(args);
            }
            else
            {
                LogFactory.Create().Warnning($"waitForFeedbackDirectives TryRemove {recvData.Data.DirectiveId} failed");
            }
        }
Example #4
0
        private DirectiveResult ParseRunningResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (!DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                ret.Status = false;
                return(ret);
            }

            ret.Status = true;
            var data = new GasDirectiveData();

            data.DeviceId      = bytes[0];
            data.DirectiveType = (DirectiveTypeEnum)bytes[1];
            data.Concentration = (double)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray()) / 10;
            data.Flowrate      = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(4).Take(2).ToArray());
            data.DeviceStatus  = bytes.Skip(6).Take(1).FirstOrDefault();
            data.DirectiveId   = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(8).Take(2).ToArray());
            data.DeviceType    = TargetDeviceTypeEnum.Gas;

            ret.SourceDirectiveType = DirectiveTypeEnum.Running;
            ret.Data = data;

            return(ret);
        }
Example #5
0
        private DirectiveResult ParseCloseResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (!DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                ret.Status = false;
                return(ret);
            }

            return(ret);
        }
        private DirectiveResult ParseRunningResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength() + 2))
            {
                return(ParseLongRunningResultData(bytes));
            }

            if (DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                return(ParseNormalRunningResultData(bytes));
            }

            ret.Status = false;
            return(ret);
        }
        private DirectiveResult ParseNormalRunningResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            ret.Status = true;
            var data = new RockerDirectiveData();

            data.DeviceId      = bytes[0];
            data.DirectiveType = (DirectiveTypeEnum)bytes[1];
            data.Angle         = (double)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray()) / 10;
            data.Speed         = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(4).Take(2).ToArray());
            data.DeviceStatus  = bytes.Skip(6).Take(1).FirstOrDefault();
            data.RockMode      = (RockEnum)bytes.Skip(7).Take(1).FirstOrDefault();
            data.DirectiveId   = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(8).Take(2).ToArray());
            data.DeviceType    = TargetDeviceTypeEnum.Rocker;

            ret.SourceDirectiveType = DirectiveTypeEnum.Running;
            ret.Data = data;

            return(ret);
        }
        private DirectiveResult ParseLongRunningResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            ret.Status = true;
            var data = new RockerDirectiveData();

            data.DeviceId          = bytes[0];
            data.DirectiveType     = (DirectiveTypeEnum)bytes[1];
            data.CenterTemperature = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray()) / 10;
            data.Speed             = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(4).Take(2).ToArray());
            data.HeaterTemperature = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(6).Take(2).ToArray()) / 10;
            data.EnvTemperature    = DirectiveHelper.Parse2BytesToNumber(bytes.Skip(8).Take(2).ToArray()) / 10;
            data.DirectiveId       = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(10).Take(2).ToArray());
            data.DeviceType        = TargetDeviceTypeEnum.Rocker;

            ret.SourceDirectiveType = DirectiveTypeEnum.Running;
            ret.Data = data;

            return(ret);
        }
        private DirectiveResult ParseTryStartResultData(byte[] bytes)
        {
            var ret = new DirectiveResult();

            if (!DirectiveHelper.IsValidationResult(bytes, ((DirectiveTypeEnum)bytes[1]).GetFeedbackLength()))
            {
                ret.Status = false;
                return(ret);
            }

            ret.Status = true;
            var data = new RockerDirectiveData();

            data.DeviceId      = bytes[0];
            data.DirectiveType = (DirectiveTypeEnum)bytes[1];
            data.DirectiveId   = (int)DirectiveHelper.Parse2BytesToNumber(bytes.Skip(2).Take(2).ToArray());
            data.DeviceType    = TargetDeviceTypeEnum.Rocker;

            ret.SourceDirectiveType = DirectiveTypeEnum.TryStart;
            ret.Data = data;

            return(ret);
        }