Beispiel #1
0
        /// <summary>
        /// Build 32 bit binary header.
        ///
        /// A "32 bit CRC" Binary header is similar to a Binary Header, except the
        /// ZBIN(A) character is replaced by a ZBIN32(C) character, and four
        /// characters of CRC are sent.
        /// 0 or more binary data subpackets with 32 bit CRC will follow depending
        /// on the frame type.
        /// * ZDLE C TYPE F3/P0 F2/P1 F1/P2 F0/P3 CRC-1 CRC-2 CRC-3 CRC-4
        /// </summary>
        /// <param name="type"></param>
        /// <param name="p0"></param>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <param name="p3"></param>
        /// <returns></returns>
        public static string Build32BitBinHeader(HeaderType type, ZFILEConversionOption f0, ZFILEManagementOption f1, ZFILETransportOption f2, ZFILEExtendedOptions f3, CRC32 crcCalculator)
        {
            var sb = new StringBuilder();

            sb.Append(Bin32BitHeader);
            sb.Append(((char)(int)type).ToString());
            sb.Append(((char)f3).ToString());
            sb.Append(((char)f2).ToString());
            sb.Append(((char)f1).ToString());
            sb.Append(((char)f0).ToString());

            var crc = CRCHelper.Compute32BitHeaderAsArray((int)type, (int)f3, (int)f2, (int)f1, (int)f0, crcCalculator);

            foreach (char c in crc)
            {
                sb.Append(c);
            }

            var command = sb.ToString();

            return(command);
        }
        public void Return32BitBinFileHeader(HeaderType type, ZFILEConversionOption f0, ZFILEManagementOption f1, ZFILETransportOption f2, ZFILEExtendedOptions f3, string expected)
        {
            var actual = Utils.Build32BitBinHeader(type, f0, f1, f2, f3, CRC32Calculator);

            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        /// <summary>
        /// Build 16 bit binary header.
        ///
        /// A binary header is sent by the sending program to the receiving program.All bytes in a binary header are ZDLE encoded.
        /// A binary header begins with the sequence ZPAD, ZDLE, ZBIN.
        /// 0 or more binary data subpackets with 16 bit CRC will follow depending on the frame type.
        /// * ZDLE A TYPE F3/P0 F2/P1 F1/P2 F0/P3 CRC-1 CRC-2
        /// </summary>
        /// <param name="type"></param>
        /// <param name="f0"></param>
        /// <param name="f1"></param>
        /// <param name="f2"></param>
        /// <param name="f3"></param>
        /// <returns></returns>
        public static string Build16BitBinHeader(HeaderType type, ZFILEConversionOption f0, ZFILEManagementOption f1, ZFILETransportOption f2, ZFILEExtendedOptions f3, CRC16 crcCalculator)
        {
            var sb = new StringBuilder();

            sb.Append(Bin16BitHeader);
            sb.Append(((char)(int)type).ToString());
            sb.Append(((char)f3).ToString());
            sb.Append(((char)f2).ToString());
            sb.Append(((char)f1).ToString());
            sb.Append(((char)f0).ToString());

            var b = new byte[5];

            b[0] = Convert.ToByte(type);
            b[1] = Convert.ToByte(f3);
            b[2] = Convert.ToByte(f2);
            b[3] = Convert.ToByte(f1);
            b[4] = Convert.ToByte(f0);

            var crc = CRCHelper.Compute16BitHeaderAsArray((int)type, (int)f3, (int)f2, (int)f1, (int)f0, crcCalculator);

            int crc1 = crc[1];
            int crc2 = crc[0];

            sb.Append(((char)crc1).ToString());
            sb.Append(((char)crc2).ToString());

            var command = sb.ToString();

            return(command);
        }