Exemple #1
0
        async public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var deviceCount = DfuContext.Current.GetDevices().Count;

            DeployButton.Enabled = false;

            var productId = 0;

            if (deviceCount == 1)
            {
                OtpManager otpManager = new OtpManager();
                var        settings   = otpManager.GetOtpSettings();
                productId = settings.ProductID;
                LoadDeviceList(productId);
            }
            else
            {
                LoadDeviceList();
            }

            LoadForm();
            MacAddress.Changed += MacAddress_Changed;
            await DownloadFirmware();
        }
        public MainPage()
        {
            this.InitializeComponent();

            display = new DisplayRequest();

            otp = new OtpManager(Configurations.Tid, Configurations.Index, Configurations.UserId);
            //decrypt seed
            OtpShareStore.putString(Application.Current, Configurations.Tid, Configurations.EncryptedSeed, OtpShareStore.SETTING_INFOS_NEW);
            OtpShareStore.putString(Application.Current, "interval", Configurations.Interval, OtpShareStore.SETTING_INFOS_NEW);
        }
Exemple #3
0
        // OTP STUFFS

        partial void SaveConfiguration(NSObject sender)
        {
            OtpSettings settings = new OtpSettings();

            settings.ProductID  = Convert.ToByte(Globals.DeviceTypes.SingleOrDefault(x => x.Name == DeviceType.SelectedItem.Title).ProductID);
            settings.MacAddress = MacAddress.StringValue.Split(':').Select(x => Convert.ToByte(x, 16)).ToArray();
            OtpManager manager = new OtpManager();

            manager.SaveOtpSettings(settings);
            OutputToConsole("Configuration saved successfully");
            LoadForm();
        }
Exemple #4
0
        // FORM STUFFS

        private void LoadForm()
        {
            var deviceCount = DfuContext.Current.GetDevices().Count;

            MacAddress.Enabled = false;
            SaveConfigurationButton.Enabled = false;
            UpdateFirmwareButton.Enabled    = false;

            if (deviceCount == 0)
            {
                OutputToConsole("Please connect a device in bootloader mode and restart the application");
            }
            else if (deviceCount > 1)
            {
                OutputToConsole("Please connect only one device in bootloader mode and restart the application");
            }
            else if (_selectedDeviceIndex == 0)
            {
                DeviceType.Enabled = true;
            }
            else
            {
                DeviceType.Enabled = true;

                var deviceType = Globals.DeviceTypes.SingleOrDefault(x => x.Name == DeviceType.ItemAtIndex(_selectedDeviceIndex).Title);

                if (deviceType != null)
                {
                    OtpManager otpManager = new OtpManager();
                    var        settings   = otpManager.GetOtpSettings();
                    MacAddress.StringValue = BitConverter.ToString(settings.MacAddress).Replace('-', ':');
                    FreeSlots.StringValue  = string.Format("Device settings can be saved {0} more time{1}", settings.FreeSlots, settings.FreeSlots > 1 ? "s" : "");

                    SaveConfigurationButton.Enabled = settings.FreeSlots > 0;

                    MacAddress.Enabled = deviceType.HasMacAddress;

                    if (settings.ProductID > 0)
                    {
                        UpdateFirmwareButton.Enabled = true;
                    }
                }

                if (deviceType.HasMacAddress)
                {
                    _networkManager = new NetworkManager();
                    LoadAuthenticationTypes();
                    LoadEncryptionTypes();
                    LoadNetworkKeyTypes();
                    LoadNetworkSettings();
                }
            }
        }
Exemple #5
0
        // NETWORK STUFFS

        private void LoadNetworkSettings(bool skipReadFromDevice = false)
        {
            if (!skipReadFromDevice)
            {
                ReadNetworkSettingsFromDevice();
            }

            if (_networkConfig.NetworkMacAddress == null || _networkConfig.NetworkMacAddress.Length == 0)
            {
                OtpManager otpManager = new OtpManager();
                var        settings   = otpManager.GetOtpSettings();

                _networkConfig = new NetworkConfig();
                _networkConfig.NetworkMacAddress = settings.MacAddress;
                _networkConfig.IsWireless        = _selectedDeviceType.IsWirelessCapable;
                SaveNetworkSettings();
                ReadNetworkSettingsFromDevice();
            }

            EnableManualIpSettings(!_networkConfig.EnableDHCP);
            EnableDHCP.State              = _networkConfig.EnableDHCP ? NSCellStateValue.On : NSCellStateValue.Off;
            StaticIPAddress.StringValue   = _networkConfig.StaticIPAddress.ToString();
            SubnetMask.StringValue        = _networkConfig.SubnetMask.ToString();
            DefaultGateway.StringValue    = _networkConfig.DefaultGateway.ToString();
            NetworkMacAddress.StringValue = BitConverter.ToString(_networkConfig.NetworkMacAddress).Replace("-", ":");
            PrimaryDNS.StringValue        = _networkConfig.PrimaryDNS.ToString();
            SecondaryDNS.StringValue      = _networkConfig.SecondaryDNS.ToString();

            EnableWifiSettings();

            if (_networkConfig.IsWireless)
            {
                Authentication.SelectItem(_networkConfig.Authentication);
                Encryption.SelectItem(_networkConfig.Encryption);

                RadioA.State = (_networkConfig.Radio & (int)MFWirelessConfiguration.RadioTypes.a) != 0 ? NSCellStateValue.On : NSCellStateValue.Off;
                RadioB.State = (_networkConfig.Radio & (int)MFWirelessConfiguration.RadioTypes.b) != 0 ? NSCellStateValue.On : NSCellStateValue.Off;
                RadioG.State = (_networkConfig.Radio & (int)MFWirelessConfiguration.RadioTypes.g) != 0 ? NSCellStateValue.On : NSCellStateValue.Off;
                RadioN.State = (_networkConfig.Radio & (int)MFWirelessConfiguration.RadioTypes.n) != 0 ? NSCellStateValue.On : NSCellStateValue.Off;

                Passphrase.StringValue = _networkConfig.Passphrase;
                EncryptConfig.State    = _networkConfig.EncryptConfig ? NSCellStateValue.On : NSCellStateValue.Off;
                int index = (int)Math.Log(_networkConfig.NetworkKeyLength / 8.0, 2);
                NetworkKey.SelectItem(index < NetworkKey.ItemCount && index > 0 ? index : NetworkKey.ItemCount - 1);
                NetworkValue.StringValue  = _networkConfig.NetworkKey;
                ReKeyInternal.StringValue = _networkConfig.ReKeyInternal;
                SSID.StringValue          = _networkConfig.SSID;
            }
        }