コード例 #1
0
        private void SetDeviceId(MFDevice device, Guid id)
        {
            var buffer = id.ToByteArray();
            var config = new MFConfigHelper(device);

            config.WriteConfig("S4NID", buffer);
        }
コード例 #2
0
        public MFUsbConfigDialog(MFDevice device)
        {
            m_cfgHelper = new MFConfigHelper(device);
            m_cfg       = new MFUsbConfiguration(device);

            InitializeComponent();
        }
コード例 #3
0
        public MFNetworkConfigDialog(MFDevice device)
        {
            m_cfg         = new MFNetworkConfiguration(device);
            m_cfgHelper   = new MFConfigHelper(device);
            m_wirelessCfg = new MFWirelessConfiguration(device);

            InitializeComponent();
        }
コード例 #4
0
        public MFAppDeployConfigDialog(MFDevice device, ConfigDialogCommand command)
        {
            if (device != null)
            {
                m_cfgHelper = new MFConfigHelper(device);
                m_appDeploy = new MFApplicationDeployment(device);
            }
            m_command = command;
            m_device  = device;

            InitializeComponent();
        }
コード例 #5
0
        private void WriteConfiguration(byte[] cfg)
        {
            var config = new MFConfigHelper(_device);

            if (!config.IsValidConfig)
            {
                throw new Exception("Invalid config");
            }
            if (config.IsFirmwareKeyLocked)
            {
                throw new Exception("Firmware locked");
            }
            if (config.IsDeploymentKeyLocked)
            {
                throw new Exception("Deployment locked");
            }
            config.WriteConfig("S4NCFG", cfg);
        }
コード例 #6
0
        private byte[] ReadConfiguration()
        {
            byte[] result = null;
            try
            {
                var config = new MFConfigHelper(_device);
                if (!config.IsValidConfig)
                {
                    throw new Exception("Invalid config");
                }
                if (config.IsFirmwareKeyLocked)
                {
                    throw new Exception("Firmware locked");
                }
                if (config.IsDeploymentKeyLocked)
                {
                    throw new Exception("Deployment locked");
                }

                var data = config.FindConfig("S4NCFG");
                //if (data.Length > 16)
                //{
                //    var temp = new byte[16];
                //    Array.Copy(data, data.Length - 16, temp, 0, 16);
                //    data = temp;
                //}
                if (data == null)
                {
                    result = null;
                }
                else
                {
                    //BUG: FindConfig returns a lot of garbage at the beginning of the config block
                    result = data; //TODO: copy only the config bytes
                }
            }
            catch
            {
                result = null;
            }
            return(result);
        }
コード例 #7
0
        private Guid GetDeviceId(MFDevice device)
        {
            var result = Guid.Empty;

            try
            {
                var config = new MFConfigHelper(device);
                if (!config.IsValidConfig)
                {
                    throw new Exception("Invalid config");
                }
                if (config.IsFirmwareKeyLocked)
                {
                    throw new Exception("Firmware locked");
                }
                if (config.IsDeploymentKeyLocked)
                {
                    throw new Exception("Deployment locked");
                }
                var data = config.FindConfig("S4NID");
                if (data.Length > 16)
                {
                    var temp = new byte[16];
                    Array.Copy(data, data.Length - 16, temp, 0, 16);
                    data = temp;
                }
                if (data == null)
                {
                    result = Guid.Empty;
                }
                else
                {
                    result = new Guid(data);
                }
            }
            catch
            {
                result = Guid.Empty;
            }
            return(result);
        }
コード例 #8
0
ファイル: MFDeployForm.cs プロジェクト: yisea123/NETMF-LPC
        private void OnMenuItem_Click(System.Object sender, System.EventArgs e)
        {
            ToolStripMenuItem mi = sender as ToolStripMenuItem;
            Form dlg             = null;

            if (mi == null)
            {
                return;
            }

            MFDevice       device    = null;
            MFConfigHelper cfgHelper = null;

            Cursor old = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (mi != signDeploymentFileToolStripMenuItem1)
                {
                    device = ConnectToSelectedDevice();

                    if (device == null || !device.IsConnected)
                    {
                        MessageBox.Show(this, string.Format(Properties.Resources.ErrorDeviceNotResponding, comboBoxDevice.Text), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    cfgHelper = new MFConfigHelper(device);

                    if (!cfgHelper.IsValidConfig)
                    {
                        MessageBox.Show(this, Properties.Resources.ErrorUnsupportedConfiguration, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }

                if (mi == signDeploymentFileToolStripMenuItem1)
                {
                    dlg = new MFAppDeployConfigDialog(MFAppDeployConfigDialog.ConfigDialogCommand.SignDeployment);
                }
                else if (mi == updateDeviceKeysToolStripMenuItem)
                {
                    dlg = new MFAppDeployConfigDialog(device, MFAppDeployConfigDialog.ConfigDialogCommand.Configure);
                }
                else if (mi == createApplicationDeploymentToolStripMenuItem1)
                {
                    dlg = new MFAppDeployConfigDialog(device, MFAppDeployConfigDialog.ConfigDialogCommand.CreateDeployment);
                }
                else if (mi == uSBToolStripMenuItem)
                {
                    dlg = new MFUsbConfigDialog(device);
                }
                else if (mi == networkToolStripMenuItem)
                {
                    dlg = new MFNetworkConfigDialog(device);
                }

                if (dlg != null)
                {
                    dlg.StartPosition = FormStartPosition.CenterParent;
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        if (dlg is MFUsbConfigDialog)
                        {
                            cfgHelper.Dispose();
                            cfgHelper = null;
                            while (!DisconnectFromSelectedDevice())
                            {
                                ;
                            }
                            Thread.Sleep(500); // wait for device to reset
                            OnDeviceListUpdate(null, null);
                        }
                    }
                }

                else if (mi == uSBConfigurationToolStripMenuItem)
                {
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Title           = "Load USB Config File";
                    ofd.DefaultExt      = "*.xml";
                    ofd.Filter          = "USB Config File (*.xml)|*.xml";
                    ofd.CheckFileExists = true;
                    ofd.Multiselect     = false;

                    cfgHelper.MaintainConnection = true;

                    if (DialogResult.OK == ofd.ShowDialog())
                    {
                        UsbXMLConfigSet xmlConfig    = new UsbXMLConfigSet(ofd.FileName);
                        byte[]          nativeConfig = xmlConfig.Read();
                        if (nativeConfig != null)
                        {
                            ofd.DefaultExt      = "*.txt";
                            ofd.CheckFileExists = false;
                            ofd.CheckPathExists = true;
                            ofd.FileName        = "USB Hex dump.txt";
                            ofd.Title           = "Dump file for native config data";
                            if (DialogResult.OK == ofd.ShowDialog())
                            {
                                FileStream dumpFile;
                                try
                                {
                                    dumpFile = File.Create(ofd.FileName);
                                }
                                catch (Exception e2)
                                {
                                    MessageBox.Show("Text dump file could not be opened due to exception: " + e2.Message);
                                    return;
                                }

                                // Dump byte array to text file for review
                                byte[] buffer    = new byte[16 * 3 + 2];
                                int    blockSize = 0;
                                int    bufIndex  = 0;
                                for (int index = 0; index < nativeConfig.Length; index += blockSize)
                                {
                                    blockSize = nativeConfig.Length - index;
                                    if (blockSize > 16)
                                    {
                                        blockSize = 16;
                                    }
                                    bufIndex = 0;
                                    for (int i = 0; i < blockSize; i++)
                                    {
                                        byte c;

                                        c  = (byte)((nativeConfig[index + i] >> 4) & 0x0F);
                                        c += (byte)'0';       // Convert to ASCII
                                        if (c > '9')
                                        {
                                            c += (byte)('A' - '9' - 1);
                                        }
                                        buffer[bufIndex++] = c;
                                        c  = (byte)(nativeConfig[index + i] & 0x0F);
                                        c += (byte)'0';       // Convert to ASCII
                                        if (c > '9')
                                        {
                                            c += (byte)('A' - '9' - 1);
                                        }
                                        buffer[bufIndex++] = c;
                                        buffer[bufIndex++] = (byte)' ';
                                    }
                                    buffer[bufIndex++] = (byte)'\r';
                                    buffer[bufIndex++] = (byte)'\n';
                                    dumpFile.Write(buffer, 0, bufIndex);
                                }
                                dumpFile.Close();
                                MessageBox.Show("Written " + nativeConfig.Length.ToString() + " configuration bytes to '" + ofd.FileName + "'.");
                            }

                            try
                            {
                                if (!cfgHelper.IsValidConfig)
                                {
                                    MessageBox.Show(null, Properties.Resources.ErrorUnsupportedConfiguration, Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                // NOTE:
                                // This assumes there is only one USB controller:  controller 0.  In the future, if
                                // support is needed for multiple USB controllers, the user must be allowed to select
                                // which controller the XML configuration is for.  Then, the correct configuration
                                // name needs to be used for the selected controller.  "USB1" is used for controller 0,
                                // "USB2" is used for controller 1, etc.
                                cfgHelper.WriteConfig("USB1", nativeConfig);
                            }
                            catch (Exception ex2)
                            {
                                MessageBox.Show(null, string.Format(Properties.Resources.ErrorX, ex2.Message), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format(Properties.Resources.ErrorX, ex.Message), Properties.Resources.ApplicationTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                Cursor.Current = old;

                if (cfgHelper != null)
                {
                    cfgHelper.Dispose();
                }

                DisconnectFromSelectedDevice();

                if (dlg != null)
                {
                    dlg.Dispose();
                }
            }
        }