Esempio n. 1
0
        private void WriteAllocationTable(Stream result, IEnumerable <UploadAudioPattern> audioPatterns, IEnumerable <UploadLedPattern> ledPatterns)
        {
            byte[] b;
            int    audioPatternCount = audioPatterns.Count();
            int    ledPatternCount   = ledPatterns.Count();
            int    dataAddress       = Marshal.SizeOf(typeof(FileSystemHeader));

            dataAddress += 32 - (dataAddress % 32);
            dataAddress += ledPatternCount * Marshal.SizeOf(typeof(UsbLedFatPacket));
            dataAddress += audioPatternCount * Marshal.SizeOf(typeof(UsbAudioFatPacket));
            dataAddress += 32 - dataAddress % 32;

            // led patterns
            foreach (var uploadLedPattern in ledPatterns)
            {
                ushort          patternLength   = (ushort)(uploadLedPattern.Pattern.Count());
                UsbLedFatPacket usbLedFatPacket = new UsbLedFatPacket
                {
                    Name   = Encoding.ASCII.GetBytes(uploadLedPattern.Name.PadRight(16, '\0')),
                    Addr   = (uint)dataAddress,
                    Length = patternLength
                };

                b = usbLedFatPacket.SerializeToBytes();
                result.Write(b, 0, b.Length);

                dataAddress += patternLength;
                dataAddress += 32 - dataAddress % 32;
            }

            // audio pattern
            foreach (var audioPattern in audioPatterns)
            {
                ushort            patternLength     = GetAdjustedAudioPatternLength(audioPattern.DataLength);
                UsbAudioFatPacket usbAudioFatPacket = new UsbAudioFatPacket
                {
                    Name   = Encoding.ASCII.GetBytes(audioPattern.Name.PadRight(16, '\0')),
                    Addr   = (uint)dataAddress,
                    Length = patternLength
                };

                b = usbAudioFatPacket.SerializeToBytes();
                result.Write(b, 0, b.Length);

                dataAddress += patternLength;
                dataAddress += 32 - dataAddress % 32;
            }

            Write32BytePadding(result);
        }
        private void WriteAllocationTable(Stream result, IEnumerable<UploadAudioPattern> audioPatterns, IEnumerable<UploadLedPattern> ledPatterns)
        {
            byte[] b;
            int audioPatternCount = audioPatterns.Count();
            int ledPatternCount = ledPatterns.Count();
            int dataAddress = Marshal.SizeOf(typeof(FileSystemHeader));
            dataAddress += 32 - (dataAddress % 32);
            dataAddress += ledPatternCount * Marshal.SizeOf(typeof(UsbLedFatPacket));
            dataAddress += audioPatternCount * Marshal.SizeOf(typeof(UsbAudioFatPacket));
            dataAddress += 32 - dataAddress % 32;

            // led patterns
            foreach (var uploadLedPattern in ledPatterns)
            {
                ushort patternLength = (ushort)(uploadLedPattern.Pattern.Count());
                UsbLedFatPacket usbLedFatPacket = new UsbLedFatPacket
                {
                    Name = Encoding.ASCII.GetBytes(uploadLedPattern.Name.PadRight(16, '\0')),
                    Addr = (uint)dataAddress,
                    Length = patternLength
                };

                b = usbLedFatPacket.SerializeToBytes();
                result.Write(b, 0, b.Length);

                dataAddress += patternLength;
                dataAddress += 32 - dataAddress % 32;
            }

            // audio pattern
            foreach (var audioPattern in audioPatterns)
            {
                ushort patternLength = GetAdjustedAudioPatternLength(audioPattern.DataLength);
                UsbAudioFatPacket usbAudioFatPacket = new UsbAudioFatPacket
                {
                    Name = Encoding.ASCII.GetBytes(audioPattern.Name.PadRight(16, '\0')),
                    Addr = (uint)dataAddress,
                    Length = patternLength
                };

                b = usbAudioFatPacket.SerializeToBytes();
                result.Write(b, 0, b.Length);

                dataAddress += patternLength;
                dataAddress += 32 - dataAddress % 32;
            }

            Write32BytePadding(result);
        }