Example #1
0
        private void Upload(object sender, RoutedEventArgs e)
        {
            if (ShoppingCart.Count > 0)
            {
                TimeSpan scaleDuration = new TimeSpan(0, 0, 0, 0, ShoppingCart.Count * 200);
                DoubleAnimation ProgressAnimation = new DoubleAnimation(0, 100, scaleDuration, FillBehavior.Stop);
                UploadProgressBar.BeginAnimation(ProgressBar.ValueProperty, ProgressAnimation);
               // MessageBox.Show(ShoppingCart.Count.ToString());

                foreach (var imageCart in ShoppingCart)
                {
                    BitmapSource imageForCust = imageCart.Photo;
                    CurrentPhoto.Source = imageForCust;
                    MessageBox.Show(imageForCust.ToString());

                    using (var fileStream = new FileStream("..\\..\\photosCust", FileMode.Create))
                    {
                        BitmapEncoder encoder = new PngBitmapEncoder();
                        encoder.Frames.Add(BitmapFrame.Create(imageForCust));
                        encoder.Save(fileStream);
                    }
                  
                }
                ShoppingCart.Clear();
                UploadButton.IsEnabled = false;
                if (true == RemoveButton.IsEnabled)
                    RemoveButton.IsEnabled = false;
            }
        }
Example #2
0
        private void SendData(byte[] buffer, int startAddress, int size, bool debugMode)
        {
            try
            {
                if (serial.IsOpen)
                {
                    // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus)
                    if (debugMode)
                    {
                        GetFnxInDebugMode();
                    }
                    // Now's let's transfer the code
                    if (size <= 2048)
                    {
                        // DataBuffer = The buffer where the loaded Binary File resides
                        // FnxAddressPtr = Pointer where to put the Data in the Fnx
                        // i = Pointer Inside the data buffer
                        // Size_Of_File = Size of the Payload we want to transfer which ought to be smaller than 8192
                        PreparePacket2Write(buffer, startAddress, 0, size);
                        UploadProgressBar.Increment(size);
                    }
                    else
                    {
                        int BufferSize = 2048;
                        int Loop       = size / BufferSize;
                        int offset     = startAddress;
                        for (int j = 0; j < Loop; j++)
                        {
                            PreparePacket2Write(buffer, offset, j * BufferSize, BufferSize);
                            offset = offset + BufferSize;   // Advance the Pointer to the next location where to write Data in the Foenix
                            UploadProgressBar.Increment(BufferSize);
                        }
                        BufferSize = (size % BufferSize);
                        if (BufferSize > 0)
                        {
                            PreparePacket2Write(buffer, offset, size - BufferSize, BufferSize);
                            UploadProgressBar.Increment(BufferSize);
                        }
                    }

                    if (debugMode)
                    {
                        // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00
                        if (startAddress < 0xFF00 && (startAddress + buffer.Length) > 0xFFFF || (startAddress == 0x18_0000 && buffer.Length > 0xFFFF))
                        {
                            PreparePacket2Write(buffer, 0x00FF00, 0x00FF00, 256);
                        }

                        // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode
                        ExitFnxDebugMode();
                    }

                    MessageBox.Show("Transfer Done! System Reset!", "Send Binary Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Send Binary Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #3
0
        private bool FetchData(byte[] buffer, int startAddress, int size, bool debugMode)
        {
            bool success = false;

            byte[] partialBuffer;

            try
            {
                if (serial.IsOpen)
                {
                    if (debugMode)
                    {
                        GetFnxInDebugMode();
                    }

                    if (size < 2048)
                    {
                        partialBuffer = PreparePacket2Read(startAddress, size);
                        Array.Copy(partialBuffer, 0, buffer, 0, size);
                        UploadProgressBar.Increment(size);
                    }
                    else
                    {
                        int BufferSize = 2048;
                        int Loop       = size / BufferSize;

                        for (int j = 0; j < Loop; j++)
                        {
                            partialBuffer = PreparePacket2Read(startAddress, BufferSize);
                            Array.Copy(partialBuffer, 0, buffer, j * BufferSize, BufferSize);
                            partialBuffer = null;
                            startAddress += BufferSize;   // Advance the Pointer to the next location where to write Data in the Foenix
                            UploadProgressBar.Increment(BufferSize);
                        }
                        BufferSize = (size % BufferSize);
                        if (BufferSize > 0)
                        {
                            partialBuffer = PreparePacket2Read(startAddress, BufferSize);
                            Array.Copy(partialBuffer, 0, buffer, size - BufferSize, BufferSize);
                            UploadProgressBar.Increment(BufferSize);
                        }
                    }

                    if (debugMode)
                    {
                        ExitFnxDebugMode();
                    }
                    success = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Fetch Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(success);
        }
Example #4
0
 private void Upload(object sender, RoutedEventArgs e)
 {
     if (ShoppingCart.Count > 0)
     {
         var scaleDuration     = new TimeSpan(0, 0, 0, 0, ShoppingCart.Count * 200);
         var progressAnimation = new DoubleAnimation(0, 100, scaleDuration, FillBehavior.Stop);
         UploadProgressBar.BeginAnimation(RangeBase.ValueProperty, progressAnimation);
         ShoppingCart.Clear();
         UploadButton.IsEnabled = false;
         if (RemoveButton.IsEnabled)
         {
             RemoveButton.IsEnabled = false;
         }
     }
 }
Example #5
0
 private void SendData(byte[] buffer, int startAddress, int size)
 {
     try
     {
         if (serial.IsOpen)
         {
             // Now's let's transfer the code
             if (size <= 2048)
             {
                 // DataBuffer = The buffer where the loaded Binary File resides
                 // FnxAddressPtr = Pointer where to put the Data in the Fnx
                 // i = Pointer Inside the data buffer
                 // Size_Of_File = Size of the Payload we want to transfer which ought to be smaller than 8192
                 PreparePacket2Write(buffer, startAddress, 0, size);
                 UploadProgressBar.Increment(size);
             }
             else
             {
                 int BufferSize = 2048;
                 int Loop       = size / BufferSize;
                 int offset     = startAddress;
                 for (int j = 0; j < Loop; j++)
                 {
                     PreparePacket2Write(buffer, offset, j * BufferSize, BufferSize);
                     offset += BufferSize;   // Advance the Pointer to the next location where to write Data in the Foenix
                     UploadProgressBar.Increment(BufferSize);
                 }
                 BufferSize = (size % BufferSize);
                 if (BufferSize > 0)
                 {
                     PreparePacket2Write(buffer, offset, size - BufferSize, BufferSize);
                     UploadProgressBar.Increment(BufferSize);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Send Binary Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #6
0
        private void Upload(object sender, RoutedEventArgs e)
        {
            if (ShoppingCart.Count > 0)
            {
                var scaleDuration     = new TimeSpan(0, 0, 0, 0, ShoppingCart.Count * 200);
                var progressAnimation = new DoubleAnimation(0, 100, scaleDuration, FillBehavior.Stop);
                UploadProgressBar.BeginAnimation(RangeBase.ValueProperty, progressAnimation);
                InitializeIoTClient();
                _iotClient.SendTelemetryDataAsync(ShoppingCart, 3);

                _iotClient.SendStorageDataAsync(ShoppingCart, 3);
                _iotClient.SendDataToServiceBusAsync(ShoppingCart, 3);

                // ShoppingCart.Clear();
                UploadButton.IsEnabled = false;
                if (RemoveButton.IsEnabled)
                {
                    RemoveButton.IsEnabled = false;
                }
            }
        }
Example #7
0
        private void SendBinaryButton_Click(object sender, EventArgs e)
        {
            SendBinaryButton.Enabled = false;
            DisconnectButton.Enabled = false;
            hideLabelTimer_Tick(null, null);
            int transmissionSize = GetTransmissionSize();

            UploadProgressBar.Maximum = transmissionSize;
            UploadProgressBar.Value   = 0;
            UploadProgressBar.Visible = true;

            int BaseBankAddress = 0x38_0000;

            if (boardVersion == BoardVersion.RevB)
            {
                BaseBankAddress = 0x18_0000;
            }

            if (SendFileRadio.Checked)
            {
                if (serial.IsOpen)
                {
                    // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus)
                    if (DebugModeCheckbox.Checked)
                    {
                        GetFnxInDebugMode();
                    }

                    if (Path.GetExtension(FileNameTextBox.Text).ToUpper().Equals(".BIN"))
                    {
                        // Read the bytes and put them in the buffer
                        byte[] DataBuffer    = System.IO.File.ReadAllBytes(FileNameTextBox.Text);
                        int    FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                        Console.WriteLine("Starting Address: " + FnxAddressPtr);
                        Console.WriteLine("File Size: " + transmissionSize);
                        SendData(DataBuffer, FnxAddressPtr, transmissionSize);

                        // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00
                        if (FnxAddressPtr < 0xFF00 && (FnxAddressPtr + DataBuffer.Length) > 0xFFFF || (FnxAddressPtr == BaseBankAddress && DataBuffer.Length > 0xFFFF))
                        {
                            PreparePacket2Write(DataBuffer, 0x00FF00, 0x00FF00, 256);
                        }
                    }
                    else
                    {
                        bool resetVector = false;
                        // Page FF is used to store IRQ vectors - this is only used when the program modifies the
                        // values between BaseBank + FF00 to BaseBank + FFFF
                        // BaseBank on RevB is $18
                        // BaseBank on RevC is $38
                        byte[] pageFF = PreparePacket2Read(0xFF00, 0x100);
                        // If send HEX files, each time we encounter a "bank" change - record 04 - send a new data block
                        string[] lines   = System.IO.File.ReadAllLines(FileNameTextBox.Text);
                        int      bank    = 0;
                        int      address = 0;

                        foreach (string l in lines)
                        {
                            if (l.StartsWith(":"))
                            {
                                string mark     = l.Substring(0, 1);
                                string reclen   = l.Substring(1, 2);
                                string offset   = l.Substring(3, 4);
                                string rectype  = l.Substring(7, 2);
                                string data     = l.Substring(9, l.Length - 11);
                                string checksum = l.Substring(l.Length - 2);

                                switch (rectype)
                                {
                                case "00":
                                    int    length     = Convert.ToInt32(reclen, 16);
                                    byte[] DataBuffer = new byte[length];
                                    address = HexFile.GetByte(offset, 0, 2);
                                    for (int i = 0; i < data.Length; i += 2)
                                    {
                                        DataBuffer[i / 2] = (byte)HexFile.GetByte(data, i, 1);
                                    }
                                    PreparePacket2Write(DataBuffer, bank + address, 0, length);

                                    // TODO - make this backward compatible
                                    if (bank + address >= (BaseBankAddress + 0xFF00) && (bank + address) < (BaseBankAddress + 0xFFFF))
                                    {
                                        int pageFFLen = length - ((bank + address + length) - (BaseBankAddress + 0x1_0000));
                                        if (pageFFLen > length)
                                        {
                                            pageFFLen = length;
                                        }
                                        Array.Copy(DataBuffer, 0, pageFF, bank + address - (BaseBankAddress + 0xFF00), length);
                                        resetVector = true;
                                    }
                                    UploadProgressBar.Increment(length);

                                    break;

                                case "01":
                                    // Don't do anything... this is the end of file record.
                                    break;

                                case "02":
                                    bank = HexFile.GetByte(data, 0, 2) * 16;
                                    break;

                                case "04":
                                    bank = HexFile.GetByte(data, 0, 2) << 16;
                                    break;

                                default:
                                    Console.WriteLine("Unsupport HEX record type:" + rectype);
                                    break;
                                }
                            }
                        }
                        if (DebugModeCheckbox.Checked)
                        {
                            // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00
                            if (resetVector)
                            {
                                PreparePacket2Write(pageFF, 0x00FF00, 0, 256);
                            }
                        }
                    }
                    if (ReflashCheckbox.Checked && MessageBox.Show("Are you sure you want to reflash your C256 System?", "Reflash", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        CountdownLabel.Visible = true;
                        this.Update();

                        EraseFlash();
                        int SrcFlashAddress = Convert.ToInt32(C256DestAddress.Text.Replace(":", ""), 16);
                        ProgramFlash(SrcFlashAddress);
                        CountdownLabel.Visible = false;
                    }
                    if (DebugModeCheckbox.Checked)
                    {
                        // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode
                        ExitFnxDebugMode();
                    }
                    HideProgressBarAfter5Seconds("Transfer Done! System Reset!");
                }
            }
            else if (BlockSendRadio.Checked && kernel.CPU != null)
            {
                // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus)
                if (DebugModeCheckbox.Checked)
                {
                    GetFnxInDebugMode();
                }
                int blockAddress = Convert.ToInt32(EmuSrcAddress.Text.Replace(":", ""), 16);
                // Read the data directly from emulator memory
                int    offset        = 0;
                int    FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                byte[] DataBuffer    = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF.
                for (int start = blockAddress; start < blockAddress + transmissionSize; start++)
                {
                    DataBuffer[offset++] = kernel.CPU.MemMgr.ReadByte(start);
                }
                SendData(DataBuffer, FnxAddressPtr, transmissionSize);
                // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00
                if (FnxAddressPtr < 0xFF00 && (FnxAddressPtr + DataBuffer.Length) > 0xFFFF || (FnxAddressPtr == BaseBankAddress && DataBuffer.Length > 0xFFFF))
                {
                    PreparePacket2Write(DataBuffer, 0x00FF00, 0x00FF00, 256);
                }
                if (DebugModeCheckbox.Checked)
                {
                    // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode
                    ExitFnxDebugMode();
                }
                HideProgressBarAfter5Seconds("Transfer Done! System Reset!");
            }
            else
            {
                int    blockAddress = Convert.ToInt32(C256SrcAddress.Text.Replace(":", ""), 16);
                byte[] DataBuffer   = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF.
                if (FetchData(DataBuffer, blockAddress, transmissionSize, DebugModeCheckbox.Checked))
                {
                    MemoryRAM mem = new MemoryRAM(blockAddress, transmissionSize);
                    mem.Load(DataBuffer, 0, 0, transmissionSize);
                    MemoryWindow tempMem = new MemoryWindow
                    {
                        Memory = mem,
                        Text   = "C256 Memory from " + blockAddress.ToString("X6") +
                                 " to " + (blockAddress + transmissionSize - 1).ToString("X6")
                    };
                    tempMem.GotoAddress(blockAddress);
                    tempMem.AllowSave();
                    tempMem.Show();
                }
                SendBinaryButton.Enabled = true;
                DisconnectButton.Enabled = true;
            }
        }
Example #8
0
 //Done on UI thread
 private void UploadBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     UploadProgressBar.PerformStep();
     UpdateProgressLabel();
     RefreshDataGrid();
 }
Example #9
0
        private void SendBinaryButton_Click(object sender, EventArgs e)
        {
            SendBinaryButton.Enabled = false;
            DisconnectButton.Enabled = false;

            int transmissionSize = GetTransmissionSize();

            UploadProgressBar.Maximum = transmissionSize;
            UploadProgressBar.Value   = 0;
            UploadProgressBar.Visible = true;

            if (SendFileRadio.Checked)
            {
                if (Path.GetExtension(FileNameTextBox.Text).ToUpper().Equals(".BIN"))
                {
                    //byte[] DataBuffer = new byte[transmissionSize];  // Maximum 2 MB, example from $0 to $1F:FFFF.
                    // Read the bytes and put them in the buffer
                    byte[] DataBuffer    = System.IO.File.ReadAllBytes(FileNameTextBox.Text);
                    int    FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                    Console.WriteLine("Starting Address: " + FnxAddressPtr);
                    Console.WriteLine("Size of File: " + transmissionSize);
                    SendData(DataBuffer, FnxAddressPtr, transmissionSize, DebugModeCheckbox.Checked);
                }
                else
                {
                    if (serial.IsOpen)
                    {
                        // Get into Debug mode (Reset the CPU and keep it in that state and Gavin will take control of the bus)
                        if (DebugModeCheckbox.Checked)
                        {
                            GetFnxInDebugMode();
                        }

                        // If send HEX files, each time we encounter a "bank" change - record 04 - send a new data block
                        string[] lines       = System.IO.File.ReadAllLines(FileNameTextBox.Text);
                        int      bank        = 0;
                        int      address     = 0;
                        byte[]   pageFF      = new byte[256];
                        bool     resetVector = false;
                        foreach (string l in lines)
                        {
                            if (l.StartsWith(":"))
                            {
                                string mark     = l.Substring(0, 1);
                                string reclen   = l.Substring(1, 2);
                                string offset   = l.Substring(3, 4);
                                string rectype  = l.Substring(7, 2);
                                string data     = l.Substring(9, l.Length - 11);
                                string checksum = l.Substring(l.Length - 2);

                                switch (rectype)
                                {
                                case "00":
                                    int    length     = Convert.ToInt32(reclen, 16);
                                    byte[] DataBuffer = new byte[length];
                                    address = HexFile.GetByte(offset, 0, 2);
                                    for (int i = 0; i < data.Length; i += 2)
                                    {
                                        DataBuffer[i / 2] = (byte)HexFile.GetByte(data, i, 1);
                                    }
                                    PreparePacket2Write(DataBuffer, bank + address, 0, length);
                                    if (bank + address >= 0xFF00 && (bank + address) < 0xFFFF)
                                    {
                                        int pageFFLen = length - ((bank + address + length) - 0x1_0000);
                                        if (pageFFLen > length)
                                        {
                                            pageFFLen = length;
                                        }
                                        Array.Copy(DataBuffer, 0, pageFF, bank + address - 0xFF00, pageFFLen);
                                        resetVector = true;
                                    }
                                    else if (bank + address >= 0x18_FF00 && (bank + address) < 0x18_FFFF)
                                    {
                                        int pageFFLen = length - ((bank + address + length) - 0x19_0000);
                                        if (pageFFLen > length)
                                        {
                                            pageFFLen = length;
                                        }
                                        Array.Copy(DataBuffer, 0, pageFF, bank + address - 0x18_FF00, length);
                                        resetVector = true;
                                    }
                                    UploadProgressBar.Increment(length);

                                    break;

                                case "04":
                                    bank = HexFile.GetByte(data, 0, 2) << 16;
                                    break;
                                }
                            }
                        }

                        if (DebugModeCheckbox.Checked)
                        {
                            // Update the Reset Vectors from the Binary Files Considering that the Files Keeps the Vector @ $00:FF00
                            if (resetVector)
                            {
                                PreparePacket2Write(pageFF, 0x00FF00, 0, 256);
                            }
                            // The Loading of the File is Done, Reset the FNX and Get out of Debug Mode
                            ExitFnxDebugMode();
                        }
                        MessageBox.Show("Transfer Done! System Reset!", "Send Binary Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else if (BlockSendRadio.Checked)
            {
                int blockAddress = Convert.ToInt32(EmuSrcAddress.Text.Replace(":", ""), 16);
                // Read the data directly from emulator memory
                int    offset        = 0;
                int    FnxAddressPtr = int.Parse(C256DestAddress.Text.Replace(":", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                byte[] DataBuffer    = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF.
                for (int start = blockAddress; start < blockAddress + transmissionSize; start++)
                {
                    DataBuffer[offset++] = Memory.ReadByte(start);
                }
                SendData(DataBuffer, FnxAddressPtr, transmissionSize, DebugModeCheckbox.Checked);
            }
            else
            {
                int    blockAddress = Convert.ToInt32(C256SrcAddress.Text.Replace(":", ""), 16);
                byte[] DataBuffer   = new byte[transmissionSize]; // Maximum 2 MB, example from $0 to $1F:FFFF.
                if (FetchData(DataBuffer, blockAddress, transmissionSize, DebugModeCheckbox.Checked))
                {
                    BasicMemory mem = new BasicMemory("tempbuffer", blockAddress, transmissionSize);
                    mem.Load(DataBuffer, 0, 0, transmissionSize);
                    MemoryWindow tempMem = new MemoryWindow
                    {
                        Memory = mem,
                        Text   = "C256 Memory from " + blockAddress.ToString("X6") +
                                 " to " + (blockAddress + transmissionSize - 1).ToString("X6")
                    };
                    tempMem.GotoAddress(blockAddress);
                    tempMem.Show();
                }
            }

            UploadProgressBar.Visible = false;
            SendBinaryButton.Enabled  = true;
            DisconnectButton.Enabled  = true;
        }