Beispiel #1
0
        static internal void DoDemo(int numDevices)
        {
            Program.IODir += "MultiDevice/";
            CertMaker m = new CertMaker(Program.IODir);

            IoTDevice[] deviceList = new IoTDevice[numDevices];
            HubController = new HubControl();

            // make the devices and enroll them in the hub
            for (int j = 0; j < numDevices; j++)
            {
                string devId = GetDeviceID(j);
                Program.SetDeviceNumber(j);

                int fwidSeed = 0;
                m.MakeNew(5, false, fwidSeed);

                HubController.Connect();
                HubController.RemoveDevice(devId);

                var devInfo = ExtensionDecoder.Decode(Program.ToPath(Program.AliasCert));
                HubController.EnrollDevice(devId, fwidSeed, Helpers.Hexify(devInfo.FirmwareID), devInfo.Cert.Thumbprint);

                IoTDevice device = new IoTDevice(devId, 0, j);
                deviceList[j] = device;
            }

            // run through messaging and update
            bool[] primaryOrSEcondary = new bool[numDevices];
            int    epoch = 0;

            while (true)
            {
                for (int j = 0; j < numDevices; j++)
                {
                    Program.SetDeviceNumber(j);
                    var    device = deviceList[j];
                    string devId  = GetDeviceID(j);

                    // send messages using current firmware
                    device.RefreshCert();
                    device.SendMessages(1, 30);

                    if (device.FirmwareUpdateNeeded)
                    {
                        // update the firmware on the device
                        int fwidSeed = device.DesiredFwVersionNumber;
                        m.MakeAliasCert(true, fwidSeed);
                        var devInfo = ExtensionDecoder.Decode(Program.ToPath(Program.AliasCert));

                        // and tell the hub
                        HubController.RefreshDevice(devId, fwidSeed, Helpers.Hexify(devInfo.FirmwareID), devInfo.Cert.Thumbprint, primaryOrSEcondary[j]);
                        primaryOrSEcondary[j]         = !primaryOrSEcondary[j];
                        device.CurrentFwVersionNumber = fwidSeed;
                    }
                }
                Debug.WriteLine($"Epoch == {epoch++}");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Make a bunch of IOTDevice objects and give them a name, keys and certs, but do not enroll them
        /// in the hub
        /// </summary>
        /// <param name="numDevices"></param>
        void MakeClientDevicesAndCerts(int numDevices)
        {
            Program.IODir += "MultiDevice/";
            CertMaker m = new CertMaker(Program.IODir);

            ClientDevices = new IoTDevice[numDevices];
            // make the devices and enroll them in the hub
            for (int j = 0; j < numDevices; j++)
            {
                string devId = GetDeviceID(j);
                Program.SetDeviceNumber(j);

                // todo - have the devices chain to the same vendor root.
                int fwidSeed = 0;
                m.MakeNew(5, false, fwidSeed);
                IoTDevice device = new IoTDevice(devId, 0, j);
                ClientDevices[j] = device;
            }
        }