Пример #1
0
        private void serialize(bool previewOnly)
        {
            var qSerializer  = new QuestionsSerializer(File.ReadAllText(FILEDIR + QESTION_FILE));
            var sSerializer  = new SoundSerializer(File.ReadAllText(FILEDIR + SOUND_FILE));
            var lKSerializer = new LockKeySerializer(File.ReadAllText(FILEDIR + LOCKKEY_FILE));

            var qData  = qSerializer.Serialize();
            var sData  = sSerializer.Serialize();
            var lkData = lKSerializer.Serialize();

            var data = new List <byte>();

            UInt16 qDataAddr  = 0x06;
            UInt16 sDataAddr  = (UInt16)(qDataAddr + qData.Count);
            UInt16 lkDataAddr = (UInt16)(sDataAddr + sData.Count);

            BaseSerializer.addUInt16(data, qDataAddr);
            BaseSerializer.addUInt16(data, sDataAddr);
            BaseSerializer.addUInt16(data, lkDataAddr);

            data.AddRange(qData);
            data.AddRange(sData);
            data.AddRange(lkData);

            var bytes  = data.ToArray();
            var len    = bytes.Length;
            var pageCt = len / PAGE_SIZE + (len % PAGE_SIZE > 0 ? 1 : 0);

            tbInputHex.Text = string.Format("Total bytes: {0}, Pages: {1}\r\n\r\n", len, pageCt);

            tbInputHex.AppendText(FormatMemory((UInt16)0x0000, bytes, len));

            if (!previewOnly)
            {
                serial(port =>
                {
                    for (int page = 0; page < pageCt; page++)
                    {
                        var addr = (UInt16)(page * PAGE_SIZE);
                        var size = (byte)(page == pageCt - 1 ? len % PAGE_SIZE : PAGE_SIZE);

                        executeWrite(addr, size, bytes, addr, port);

                        tbOutput.AppendText(string.Format("writing to 0x{0} ... ", (page * PAGE_SIZE).ToString("x4")));

                        readRx(1, port);

                        tbOutput.AppendText(hex(_inputBuf[0], true) + "\r\n");
                    }
                });
            }
        }
Пример #2
0
        public static List <byte> Serialize(string uDataStr, string qDataStr, string sdDataStr)
        {
            try
            {
                var uSerializer = new UserDataSerializer(uDataStr);
                var uBytes      = uSerializer.Serialize();

                var qSerializer = new QuestionsSerializer(qDataStr, uSerializer.UserCt);
                var qBytes      = qSerializer.Serialize();

                var sSerializer = new SoundSerializer(sdDataStr);
                var sdBytes     = sSerializer.Serialize();


                var data = new List <byte>();

                UInt16 uDataAddr = 0x06;
                UInt16 qDataAddr = (UInt16)(uDataAddr + uBytes.Count);
                UInt16 sDataAddr = (UInt16)(qDataAddr + qBytes.Count);

                BaseSerializer.addUInt16(data, uDataAddr);
                BaseSerializer.addUInt16(data, qDataAddr);
                BaseSerializer.addUInt16(data, sDataAddr);

                data.AddRange(uBytes);
                data.AddRange(qBytes);
                data.AddRange(sdBytes);

                return(data);
            }
            catch (Exception)
            {
                // need some helpful error message to indicate where parse logic failed....
            }

            return(null);
        }