/// <summary>
        /// CRC16校验器
        /// </summary>
        /// <param name="package"></param>
        /// <returns></returns>
        public static bool Crc16Checker(IProtocolPackage package)
        {
            var calcCrc = Check.GetCCITTCheck(package.GetBytes(), (ushort)(package.PackageLenth - 3));

            var protocolCrc = NumberConvert.BytesToUint16(package[StructureNames.CRCValue].ComponentBytes, 0, false);

            return(calcCrc == protocolCrc);
        }
Example #2
0
        /// <summary>
        /// 将收到的协议包按原样回发
        /// </summary>
        /// <param name="package">接收到的协议包</param>
        /// <param name="source">接收数据源</param>
        public void ReplyOriginal(IProtocolPackage <T> package, IPackageSource source)
        {
            if (source.Type != PackageSourceType.CommunicationServer)
            {
                return;
            }

            source.Send(package.GetBytes());
        }
Example #3
0
        /// <summary>
        /// 存储协议包数据
        /// </summary>
        /// <param name="package">协议数据包</param>
        /// <returns>保存数据包相关信息</returns>
        public static void ParseProtocolData(IProtocolPackage package)
        {
            var protocolData = new ProtocolDataRepository().CreateDefaultModel();

            protocolData.DeviceIdentity  = package.Device.Identity;
            protocolData.ProtocolId      = package.Protocol.Id;
            protocolData.ProtocolTime    = package.ReceiveDateTime;
            protocolData.UpdateTime      = DateTime.Now;
            protocolData.DomainId        = package.Device.DomainId;
            protocolData.ProtocolContent = package.GetBytes();
            protocolData.Length          = protocolData.ProtocolContent.Length;

            package.ProtocolData = protocolData;
            ProcessInvoke.Instance <ProtocolPackageProcess>().AddOrUpdateProtocolData(protocolData);
        }