Ejemplo n.º 1
0
        public void CalcCRC8Test()
        {
            byte[] bytes = new byte[] { 0x12, 0x34, 0x56, 0x78 };
            byte   crc   = CRC8Helper.CalculateCRC8(bytes);

            Assert.AreEqual(crc, 0x98);
        }
        /// <summary>
        /// 组补秒信号帧
        /// </summary>
        /// <param name="complementCode">补偿秒信号的码</param>
        /// <returns></returns>
        private string GetCompensateClockSignalFrame(byte complementCode)
        {
            List <byte> sendBuffer = new List <byte>();

            sendBuffer.AddRange(Microstar.Utility.Hex.FromString("68AAAAAAAAAAAA68040A341333999999173A"));
            sendBuffer.Add(complementCode);

            byte crc = CRC8Helper.CalculateCRC8((byte)(complementCode - 0x33), 0xFF);

            crc = (byte)(crc + 0x33);
            sendBuffer.Add(crc); //CRC8

            byte cs = CSHelper.CalculateCS(sendBuffer.ToArray());

            sendBuffer.Add(cs);
            sendBuffer.Add(0x16);

            return(Microstar.Utility.Hex.ToString(sendBuffer.ToArray()));
        }