C# Ota Updater API
Collaboration diagram for C# Ota Updater API:

Modules

 Enumerations
 
 Events related with Ota Updater
 

Classes

class  OtaUpdaterChannel
 
class  OtaUpdater
 
class  OtaUpdaterManager
 
interface  IOtaUpdater
 OTA UPDATER More...
 
interface  IOtaUpdaterManager
 Ota Updated Manager. Allows to get the OTA Updated More...
 

Detailed Description

To work with Deepsy Ota Updater service it is necessary to use OtaUpdaterManager located in GMV.ITS.HAL.DEEPSY.OtaUpdater.Facade for getting the initial OtaUpdater object.

OtaUpdaterManager otaUpdaterManager = new OtaUpdaterManager("");


OtaUpdaterManager has an optional parameter indicating the ip address of remote service. For instance:

OtaUpdaterManager otaUpdaterManager = new OtaUpdaterManager("192.168.1.10");


OtaUpdaterManager is an IDisposable interface. An object that may hold resources (such as file or socket handles) until it is closed. The Dispose() method of an IDisposable object is called automatically when exiting a try-with-resources block, or exiting a using clause where it was declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur:

using (OtaUpdaterManager otaUpdaterManager = new OtaUpdaterManager("192.168.1.10")){
}


If this object is not inside a try with resources block, it is recommended to call to Dispose() in order to finalize properly;

otaUpdaterManager.Dispose();

Examples

  • Retrieve version from existing packages in the system , both in current and alternative RFS

    using System;
    using System.Collections.Generic;
    namespace GMV.ITS.HAL.DEEPSY.Examples.OtaUpdater
    {
    class OtaVersionApp
    {
    static void Main(string[] args)
    {
    OtaUpdaterManager otaUpdaterManager = new OtaUpdaterManager("192.168.0.150");
    IOtaUpdater ota = otaUpdaterManager.OtaUpdater;
    Console.WriteLine($"Retrieving packages ...");
    IList<IOtaUpdaterPackage> packages = ota.PackagesVersion;
    Console.WriteLine("{0,-30}|{1,-30}|{1,-30}", "Package", "Current RFS version", "Alternative RFS version");
    foreach(IOtaUpdaterPackage package in packages)
    {
    Console.WriteLine("{0,-30}|{1,-30}|{1,-30}", package.Name,package.VersionCurrentRfs,package.VersionAlternativeRfs);
    }
    Console.WriteLine("Press ESC to quit");
    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
    Console.WriteLine("Press ESC to quit");
    }
    }
    }
    }


  • Add a custom channel to perform updates and retrieve the channel list
    using System;
    using System.Collections.Generic;
    namespace GMV.ITS.HAL.DEEPSY.Examples.OtaUpdater
    {
    class OtaChannel
    {
    static void Main(string[] args)
    {
    OtaUpdaterManager otaUpdaterManager = new OtaUpdaterManager("192.168.0.150");
    IOtaUpdater ota = otaUpdaterManager.OtaUpdater;
    ota.AddChannel(new OtaUpdaterChannel()
    {
    Name = "mychannel",
    BaseUrl = "http://myrepochannelurl",
    Type = "rpm-md"
    });
    Console.WriteLine($"List of channels");
    IList<IOtaUpdaterChannel> channels = ota.Channels;
    foreach (IOtaUpdaterChannel channel in channels)
    {
    Console.WriteLine($"Channel: {channel.Name}, {channel.Type}, {channel.BaseUrl}");
    }
    Console.WriteLine("Press ESC to quit");
    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
    Console.WriteLine("Press ESC to quit");
    }
    }
    }
    }

  • Retrieve available updates for the existing channels
    In order to obtain the available updates it is needed to add at least channel to synchronize with. After this, get the current status of the system and check available updates on the existing channels.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading;
    namespace GMV.ITS.HAL.DEEPSY.Examples.OtaUpdater
    {
    class OtaUpdates
    {
    static void Main(string[] args)
    {
    MyOtaUpdaterApp app = new MyOtaUpdaterApp();
    Console.WriteLine($"Current status: {app.CurrentStatus.ServiceStatus}, {app.CurrentStatus.AlrRfsStatus}");
    // Execute sync, status should change to SYNCHRONIZING
    app.Sync();
    Console.WriteLine($"Current status: {app.CurrentStatus.ServiceStatus}, {app.CurrentStatus.AlrRfsStatus}");
    // Wait for synchronization to finish
    while (app.CurrentStatus.ServiceStatus == OtaUpdaterStatus.ServiceStatus.Synchronizing)
    {
    Console.WriteLine("Waiting for synchronization with package repo...");
    Thread.Sleep(5000);
    }
    // Retrieve available updates after sync
    IDictionary<string, string> updatesList = app.Updates;
    if (updatesList.Any())
    {
    Console.WriteLine("Packages available to update");
    Console.WriteLine("{0,-30}|{1,-30}", "Package", "Version");
    foreach (string entry in updatesList.Keys)
    {
    Console.WriteLine("{0,-30}|{1,-30}", entry, updatesList[entry]);
    }
    }
    else
    {
    Console.WriteLine("No updates available");
    }
    Console.WriteLine("Press ESC to quit");
    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
    Console.WriteLine("Press ESC to quit");
    }
    }
    }
    class MyOtaUpdaterApp
    {
    public IOtaUpdaterStatus CurrentStatus { get; private set; }
    public IDictionary<string, string> Updates => ota.Updates;
    private OtaUpdaterManager otaManager;
    private IOtaUpdater ota;
    public MyOtaUpdaterApp()
    {
    otaManager = new OtaUpdaterManager("192.168.0.144");
    ota = otaManager.OtaUpdater;
    ota.NewStatus += Ota_NewStatus;
    ota.AddChannel(new OtaUpdaterChannel()
    {
    Name = "deepsy",
    Type = "rpm-md",
    BaseUrl = @"http://172.22.196.105/download/yocto/sumo/builds/ep100/tmp/deploy/rpm/"
    });
    CurrentStatus = ota.Status;
    }
    public void Sync(){
    ota.RepoSync();
    }
    private void Ota_NewStatus(object sender, IOtaUpdaterEvent e)
    {
    CurrentStatus = e.Status;
    }
    }
    }