Represents a Meadow Device execution target; which is the actual device that gets deployed to when executing.
Inheritance: ExecutionTarget, IDisposable
Esempio n. 1
0
        async Task <bool> InitializeMeadowDevice(MeadowDeviceExecutionTarget target, CancellationTokenSource cts)
        {
            if (cts.IsCancellationRequested)
            {
                return(true);
            }

            target.Write($"Initializing Meadow {target.meadowSerialDevice.connection.ToString()}\n");

            if (target.meadowSerialDevice == null)
            {
                target.WriteError("Can't read Meadow device\n");
                return(false);
            }

            Console.WriteLine("MonoDisable");
            MeadowDeviceManager.MonoDisable(target.meadowSerialDevice);

            if (!(await target.meadowSerialDevice.AwaitStatus(5000, MeadowCLI.DeviceManagement.MeadowSerialDevice.DeviceStatus.PortOpen)).HasValue)
            {
                target.Write("The Meadow has failed to restart.\n");
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        async Task <MeadowDeviceExecutionTarget> InitalizeMeadow(Connection connection)
        {
            MeadowDeviceExecutionTarget target = null;

            await Task <MeadowDeviceExecutionTarget> .Run(() =>
            {
                var meadowSerialDevice = new MeadowSerialDevice(true);
                if (MeadowDeviceManager.CurrentDevice == null || (MeadowDeviceManager.CurrentDevice?.connection.Removed ?? true))
                {
                    MeadowDeviceManager.CurrentDevice = meadowSerialDevice;
                }

                lock (_lockObject)
                {
                    target = new MeadowDeviceExecutionTarget(meadowSerialDevice, connection);
                    if (target != null)
                    {
                        Console.WriteLine($"DeploymentTargetsManagerLinux Added: {target}");
                        Targets.Add(target);
                        target.SerialNumberSet += Target_SerialNumberSet;
                        DeviceListChanged?.Invoke(target);
                    }
                }
            });

            return(target);
        }
Esempio n. 3
0
        //https://stackoverflow.com/questions/29798243/how-to-write-to-the-tool-output-pad-from-within-a-monodevelop-add-in
        async Task DeployApp(MeadowDeviceExecutionTarget target, string folder, CancellationTokenSource cts)
        {
            //ProgressMonitor toolMonitor = MonoDevelop.Ide.IdeApp.Workbench.ProgressMonitors.GetToolOutputProgressMonitor(true, cts);
            //ProgressMonitor outMonitor = MonoDevelop.Ide.IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor("Meadow", IconId.Null, true);

            //var monitor = new AggregatedProgressMonitor(toolMonitor, new ProgressMonitor[] { outMonitor });

            //target.meadowPad.Window.Visible = true;
            target.meadowPad.Window.Activate(true);
            target.meadowPad.Window.Sticky = true;



            target.Write("Deploying to Meadow ...\n");

            try
            {
                var meadow = target.meadowSerialDevice;

                if (await InitializeMeadowDevice(target, cts) == false)
                {
                    throw new Exception($"Failed to initialize Meadow {meadow.connection.ToString()}");
                }

                var meadowFiles = await GetFilesOnDevice(target, cts);

                var localFiles = await GetLocalFiles(target, cts, folder);

                await DeleteUnusedFiles(target, cts, meadowFiles, localFiles);

                await DeployApp(target, cts, folder, meadowFiles, localFiles);

                await ResetMeadowAndStartMono(target, cts);
            }
            catch (Exception ex)
            {
                target.WriteError($"Error: {ex.Message}\n");
            }
        }
Esempio n. 4
0
        async Task <(List <string> files, List <UInt32> crcs)> GetLocalFiles(MeadowDeviceExecutionTarget target, CancellationTokenSource cts, string folder)
        {
            //get list of files in folder
            var paths = Directory.EnumerateFiles(folder, "*.*", SearchOption.TopDirectoryOnly)
                        .Where(s => s.EndsWith(".exe") ||
                               s.EndsWith(".dll") ||
                               s.EndsWith(".bmp") ||
                               s.EndsWith(".jpg") ||
                               s.EndsWith(".jpeg") ||
                               s.EndsWith(".txt"));

            var files = new List <string>();
            var crcs  = new List <UInt32>();

            foreach (var file in paths)
            {
                if (cts.IsCancellationRequested)
                {
                    break;
                }

                using (FileStream fs = File.Open(file, FileMode.Open))
                {
                    var len   = (int)fs.Length;
                    var bytes = new byte[len];

                    fs.Read(bytes, 0, len);

                    //0x
                    var crc = CrcTools.Crc32part(bytes, len, 0);// 0x04C11DB7);

                    Console.WriteLine($"{file} crc is {crc}");
                    files.Add(Path.GetFileName(file));
                    crcs.Add(crc);
                }
            }

            return(files, crcs);
        }
Esempio n. 5
0
        async Task <(List <string> files, List <UInt32> crcs)> GetFilesOnDevice(MeadowDeviceExecutionTarget target, CancellationTokenSource cts)
        {
            if (cts.IsCancellationRequested)
            {
                return(new List <string>(), new List <UInt32>());
            }

            target.Write("Checking files on device (may take several seconds)\n");

            var meadowFiles = await target.meadowSerialDevice.GetFilesAndCrcs(30000);

            foreach (var f in meadowFiles.files)
            {
                if (cts.IsCancellationRequested)
                {
                    break;
                }
                target.Write($"Found {f}\n");
            }

            return(meadowFiles);
        }
Esempio n. 6
0
 async Task DeleteUnusedFiles(MeadowDeviceExecutionTarget target, CancellationTokenSource cts,
                              (List <string> files, List <UInt32> crcs) meadowFiles, (List <string> files, List <UInt32> crcs) localFiles)
Esempio n. 7
0
        public override Control Control => control; //?? (control = new MeadowPadWidget(meadowSerialDevice));
        //  public override string Id => "MeadowPad";


        public MeadowPad(MeadowDeviceExecutionTarget target, MeadowSerialDevice meadow)
        {
            Target             = target;
            meadowSerialDevice = meadow;
            control            = new MeadowPadWidget(meadowSerialDevice, this);
        }