C# MCU API
Collaboration diagram for C# MCU API:

Modules

 Enumerations
 
 Events related with MCU
 

Classes

class  McuManager
 Mcu Manager that allows to interact with the Mcu More...
 
interface  IMcu
 MCU More...
 

Detailed Description

To work with Deepsy MCU service it is necessary to use McuManager located in GMV.ITS.HAL.DEEPSY.Mcu.Facade for getting the initial McuManager object.

McuManager mcuManager = new McuManager("");


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

McuManager mcuManager = new McuManager("172.22.198.103");


McuManager is an IDisposable interface. An object that may hold resources (such as file or socket handles) until it is closed. 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 (McuManager mcuManager = new McuManager("172.22.198.103")){
}


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

mcuManager.Dispose();

Examples

  • Get power information

    using System;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class PowerInformationApp
    {
    static void Main(string[] args)
    {
    //GnssDeepsyService gnssDeepsyService = new GnssDeepsyService("172.22.198.103");
    //McuManager mcuManager = new McuManager("192.168.0.150");
    McuManager mcuManager = new McuManager("172.22.198.103");
    IMcu mcu = mcuManager.Mcu;
    //First get current power information
    IMcuPowerInformation powerInfo = mcu.McuPowerInformation;
    Console.WriteLine($"-------------------------------");
    Console.WriteLine($"Mcu Power information status:");
    Console.WriteLine($"Ignition ON: {powerInfo.Ignition}");
    Console.WriteLine($"Extern Battery Voltage: {powerInfo.BatteryExternVoltage}");
    Console.WriteLine($"Inner Battery Percentage: {powerInfo.BatteryInnerPercent}");
    Console.WriteLine($"Battery Type: {powerInfo.BatteryType}");
    Console.WriteLine($"Entering in Battery Protection Mode: {powerInfo.BatteryProtectionMode}");
    Console.WriteLine($"MCU Temperature: {powerInfo.Temperature}");
    Console.WriteLine($"Voltage Fault/Overcurrent Fault: {powerInfo.PowerFaultStatus}");
    Console.WriteLine($"-------------------------------");
    //Subscribe to power information periodic events
    mcu.PowerEvent += Mcu_PowerEvent;
    Console.WriteLine("Press ESC to quit");
    while (Console.ReadKey().Key != ConsoleKey.Escape)
    {
    Console.WriteLine("Press ESC to quit");
    }
    }
    private static void Mcu_PowerEvent(object sender, IMcuPowerEvent e)
    {
    IMcuPowerInformation powerInfo = e.PowerInformation;
    Console.WriteLine($"*****************************");
    Console.WriteLine($"Mcu Power information event:");
    Console.WriteLine($"Ignition ON: {powerInfo.Ignition}");
    Console.WriteLine($"Extern Battery Voltage: {powerInfo.BatteryExternVoltage}");
    Console.WriteLine($"Inner Battery Percentage: {powerInfo.BatteryInnerPercent}");
    Console.WriteLine($"Battery Type: {powerInfo.BatteryType}");
    Console.WriteLine($"Entering in Battery Protection Mode: {powerInfo.BatteryProtectionMode}");
    Console.WriteLine($"MCU Temperature: {powerInfo.Temperature}");
    Console.WriteLine($"Voltage Fault/Overcurrent Fault: {powerInfo.PowerFaultStatus}");
    Console.WriteLine($"*****************************");
    }
    }
    }


  • Manage MCU GPIOs
    using System;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class ManageGpiosApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.150");
    IMcu mcu = mcuManager.Mcu;
    bool gpio_one = mcu.GetGpioValue(1);
    Console.WriteLine($"GPIO 1 status is: { (gpio_one? "Active" : "Inactive")}");
    bool gpio_two = mcu.GetGpioValue(2);
    Console.WriteLine($"GPIO 1 status is: { (gpio_two ? "Active" : "Inactive")}");
    bool gpio_three = mcu.GetGpioValue(3);
    Console.WriteLine($"GPIO 1 status is: { (gpio_three ? "Active" : "Inactive")}");
    bool gpio_four = mcu.GetGpioValue(4);
    Console.WriteLine($"GPIO 1 status is: { (gpio_four ? "Active" : "Inactive")}");
    mcu.GpioActiveEvent += Mcu_GpioActiveEvent;
    }
    private static void Mcu_GpioActiveEvent(object sender, IGpioActiveEvent e)
    {
    Console.WriteLine($"GPIO Event: {e.Gpio} has become active");
    }
    }
    }

  • Get Set IC2 Values
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class GetSetI2CApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.150");
    IMcu mcu = mcuManager.Mcu;
    byte[] array = { 3, 4, 3, 4 };
    byte address = 0x10;
    Console.WriteLine($"Set I2C values [3,4,3,4] at address 0x10 \n");
    mcu.SetI2CValues((byte)0x1, (byte)0x50, address, array.ToList());
    IEnumerable<byte> result = mcu.GetI2CValues((byte)0x1, (byte)0x50, address, (byte)4);
    Console.WriteLine($"Get I2C Values result: ");
    foreach (byte b in result)
    {
    Console.Write($"{b} ");
    }
    Console.WriteLine("");
    }
    }
    }

  • Get firmware information
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class FirmwareInformationApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.150");
    IMcu mcu = mcuManager.Mcu;
    IMcuFirmwareInfo firmwareInfoCurrent = mcu.CurrentMcuFirmwareInfo;
    Console.WriteLine($"MCU Current firmware version");
    Console.WriteLine($"Firmware {firmwareInfoCurrent.FirmwareVersion}");
    Console.WriteLine($"Bootloaded {firmwareInfoCurrent.BootLoaderVersion}");
    IMcuFirmwareInfo firmwareInfoAlternative = mcu.AlternativeMcuFirmwareInfo;
    Console.WriteLine($"MCU Alternative firmware version");
    Console.WriteLine($"Firmware {firmwareInfoAlternative.FirmwareVersion}");
    Console.WriteLine($"Bootloaded {firmwareInfoAlternative.BootLoaderVersion}");
    }
    }
    }

  • Get GUID information
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class GuidInformationApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.150");
    IMcu mcu = mcuManager.Mcu;
    IEnumerable<IConfigGuid> guidInfo = mcu.ConfigGUID;
    foreach(IConfigGuid guid in guidInfo)
    {
    if (guid.PartNumber.Contains("EQ)"))
    {
    Console.WriteLine($"RQ Part Number {guid.PartNumber}");
    Console.WriteLine($"EQ Serial Number {guid.SerialNumber}");
    Console.WriteLine($"EQ CIDL Number {guid.CidlNumber}");
    }
    else if (guid.PartNumber.Contains("CIDL)"))
    {
    Console.WriteLine($"CIDL Part Number {guid.PartNumber}");
    Console.WriteLine($"CIDL Serial Number {guid.SerialNumber}");
    Console.WriteLine($"CIDL Number {guid.CidlNumber}");
    }
    else
    {
    Console.WriteLine($"Part Number {guid.PartNumber}");
    Console.WriteLine($"Serial Number {guid.SerialNumber}");
    Console.WriteLine($"CIDL Number {guid.CidlNumber}");
    }
    }
    }
    }
    }

  • Get battery configuration
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class BatteryConfigurationApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.150");
    IMcu mcu = mcuManager.Mcu;
    IConfigBatteryProtection batteryProtection = mcu.BatteryProtectionConfig;
    Console.WriteLine($"Idle Voltage: {batteryProtection.IdleVoltage}");
    Console.WriteLine($"Voltage Percentage Threshold: {batteryProtection.VoltagePercentageThreshold}");
    Console.WriteLine($"Hysteresis Percentage: {batteryProtection.HysteresisPercentage}");
    Console.WriteLine($"Grace Period Minutes: {batteryProtection.GracePeriodMinutes}");
    mcu.SetBatteryProtectionConfig(12.3f, 81.2f, 2.3f, 5);
    Console.WriteLine("-----------------");
    IConfigBatteryProtection batteryProtectionAfter = mcu.BatteryProtectionConfig;
    Console.WriteLine($"Idle Voltage: {batteryProtectionAfter.IdleVoltage}");
    Console.WriteLine($"Voltage Percentage Threshold: {batteryProtectionAfter.VoltagePercentageThreshold}");
    Console.WriteLine($"Hysteresis Percentage: {batteryProtectionAfter.HysteresisPercentage}");
    Console.WriteLine($"Grace Period Minutes: {batteryProtectionAfter.GracePeriodMinutes}");
    }
    }
    }

  • Change Power Button state
    using System;
    using System.Collections.Generic;
    using System.Linq;
    namespace GMV.ITS.HAL.DEEPSY.Examples.Mcu
    {
    class ChangePowerButtonStateApp
    {
    static void Main(string[] args)
    {
    McuManager mcuManager = new McuManager("192.168.0.125");
    IMcu mcu = mcuManager.Mcu;
    IPwrBtnState state = mcu.GetPowerButtonState();
    Console.WriteLine($"Power Button state enabled: {state.Enable}");
    mcu.EnablePowerButton();
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine($"Enabling Power Button");
    state = mcu.GetPowerButtonState();
    Console.WriteLine($"Power Button state enabled: {state.Enable}");
    mcu.DisablePowerButton();
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine($"Disabling Power Button");
    state = mcu.GetPowerButtonState();
    Console.WriteLine($"Power Button state enabled: {state.Enable}");
    mcu.EnablePowerButton();
    System.Threading.Thread.Sleep(1000);
    Console.WriteLine($"Enabling Power Button");
    state = mcu.GetPowerButtonState();
    Console.WriteLine($"Power Button state enabled: {state.Enable}");
    Console.WriteLine("-----------------");
    }
    }
    }