MCU C++

Namespaces

 dpyMcu
 Deepsy Mcu namespace that includes the different enums, structs or method signatures that should be used.
 

Classes

class  Mcu
 Class which interfaces with the API logic. More...
 

Detailed Description

MCU API related documentation

A quick overview of basic MCU capabilities and examples is given.
If you find MCU API useful and would like to know more details, please check out further sections of the MCU API documentation or contact the Deepsy platform team.

Examples

  • Getting the Current and the Alternative Firmware Version

    #include <dpy/mcuApi.h>
    #include <iostream>
    volatile bool waiting = true;
    static Mcu mcu;
    void version_handler(boost::system::error_code error_code, const dpyFirmware::FirmwareVersionInfo & fw_info)
    {
    if (error_code.value() != 0) {
    if (error_code.value() == 2) {
    std::cout << "\rError : Communication with MCU is not possible. Maybe firmware version is not up to date" << std::endl;
    } else {
    std::cout << "\rError : " << error_code.message() << std::endl;
    }
    } else {
    std::cout << "\rFirmware Version: " << fw_info.version << std::endl;
    std::cout << "\rFirmware Product: " << fw_info.product << std::endl;
    std::cout << "\rFirmware Protocol: " << fw_info.protocol << std::endl;
    std::cout << "\rFirmware Vendor: " << fw_info.vendor << std::endl;
    }
    waiting = false;
    }
    int main(int argc, char *argv[])
    {
    mcu.asyncGetVersion(version_handler, dpyFirmware::Rfs::CURRENT);
    mcu.asyncGetVersion(version_handler, dpyFirmware::Rfs::ALTERNATIVE);
    while(waiting){
    usleep(300000);
    }
    }

    • Creating a class object

      #include <dpy/mcuApi.h>
      Mcu mcu;


    • Set LEDs state Configuration
      The set LED state configuration message is provided by filling a ENUM called dpyMcu::LedsColor and attending a dpyMcu::LedsConfig struct. An example on how to set LEDs state configuration is provided:

      #include <dpy/mcuApi.h>
      void leds_handler(boost::system::error_code error_code, dpyMcu::LedsConfig & leds_struct)
      {
      std::string color;
      if (error_code != 0) {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << leds_struct.timestamp << std::endl;
      switch (leds_struct.color) {
      color = "Blue";
      break;
      color = "Red";
      break;
      color = "Green";
      break;
      color = "Magenta";
      break;
      color = "Yellow";
      break;
      color = "Cyan";
      break;
      color = "Undefined";
      break;
      }
      std::cout << "Color: " << color << std::endl;
      std::cout << "Period: " << leds_struct.period << " seconds" << std::endl;
      std::cout << "Duty Cycle: " << leds_struct.duty_cycle << " %" << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      std::uint32_t period = 10;
      std::uint32_t duty_cycle = 50;
      mcu.asyncSetLedsConfig(leds_handler, dpyMcu::LedsColor::RED, period, duty_cycle);
      return 0;
      }


    • Obtaining Power Information
      In order to obtain MCU Power Information dpyMcu::PowerInformationConfig struct must be attended. An example on how to register a handler function to obtain Power Information periodic updates is provided:
      #include <dpy/mcuApi.h>
      void info_power_mng_handler(boost::system::error_code error_code, dpyMcu::PowerInformationConfig & pm_struct)
      {
      std::string battery_type;
      std::string fault;
      std::string protection_mode;
      if (error_code != 0) {
      if (error_code.value() == 2) {
      std::cout << "Message Error: Communication with MCU is not possible. Maybe firmware version is not up to date" << std::endl;
      } else {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      }
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << pm_struct.timestamp << std::endl;
      std::cout << "Firmware Version: " << pm_struct.firmware_version << std::endl;
      std::cout << "Ignition: " << pm_struct.ignition << std::endl;
      std::cout << "Extern Battery Voltage: " << pm_struct.battery_extern_voltage << std::endl;
      std::cout << "Inner Battery Percentage: " << pm_struct.battery_inner_percent << std::endl;
      pm_struct.battery_type ? battery_type = "24V" : battery_type = "12V";
      std::cout << "Battery Type: " << battery_type << std::endl;
      pm_struct.fault ? fault = "True" : fault = "False";
      std::cout << "Voltage Fault/Overcurrent Fault: " << fault << std::endl;
      std::cout << "MCU Temperature: " << pm_struct.temperature << std::endl;
      pm_struct.battery_protection_mode ? protection_mode = "True" : protection_mode = "False";
      std::cout << "Entering in Battery Protection Mode: " << protection_mode << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      mcu.getPowerInformation_S(info_power_mng_handler);
      return 0;
      }

    • Updating MCU Firmware
      In order to update MCU firmware, dpyMcu::UpdateConfig struct must be attended. An example is:

      #include <dpy/mcuApi.h>
      void update_handler(boost::system::error_code error_code, dpyMcu::UpdateConfig & update_config)
      {
      if (error_code != 0) {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << update_config.timestamp << std::endl;
      std::cout << "Update Handler partition written " << update_config.partition_written << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      mcu.asyncUpdateMCU(update_handler);
      return 0;
      }


    • Get Standby/Halt Timers
      In order to get Standby and Halt Timers, dpyMcu::TimersConfig struct must be attended. An example is provided:

      #include <dpy/mcuApi.h>
      void timers_handler(boost::system::error_code error_code, dpyMcu::TimersConfig & timers_struct)
      {
      if (error_code != 0) {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << timers_struct.timestamp << std::endl;
      std::cout << "Timers Handler Standby Timer Minutes " << timers_struct.timer_standby_minutes << std::endl;
      std::cout << "Timers Handler Halt Timer Minutes " << timers_struct.timer_halt_minutes << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      mcu.asyncGetTimersConfig(timers_handler);
      return 0;
      }


    • Get GUID values
      In order to get GUID, dpyMcu::GUIDConfig struct must be attended. An example is:

      #include <dpy/mcuApi.h>
      void guid_handler(boost::system::error_code error_code, dpyMcu::GUIDConfig & guid_struct)
      {
      if (error_code != 0) {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << guid_struct.timestamp << std::endl;
      std::cout << "Part Number: " << guid_struct.part_number << std::endl;
      std::cout << "Serial Number: " << guid_struct.serial_number << std::endl;
      std::cout << "CIDL Number: " << guid_struct.cidl_number << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      mcu.asyncGetGUIDValues(guid_handler);
      return 0;
      }


    • Set Battery Protection Values
      In order to set battery protection values, dpyMcu::BatteryProtectionConfig struct must be attended. An example is:

      #include <dpy/mcuApi.h>
      void battery_protection_values_handler(boost::system::error_code error_code, dpyMcu::BatteryProtectionConfig & bat_protect_struct)
      {
      if (error_code != 0) {
      if (error_code.value() == 2) {
      std::cout << "Message Error: Communication with MCU is not possible. Maybe firmware version is not up to date" << std::endl;
      } else {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      }
      } else {
      std::cout << "Message OK" << std::endl;
      std::cout << "Date: " << bat_protect_struct.timestamp << std::endl;
      std::cout << "Idle voltage: " << bat_protect_struct.idle_voltage << std::endl;
      std::cout << "Voltage percentage threshold over idle voltage : " << bat_protect_struct.voltage_percentage_over_idle_voltage_threshold << std::endl;
      std::cout << "Hysteresis percentage over idle voltage: " << bat_protect_struct.hysteresis_percentage_over_idle_voltage << std::endl;
      std::cout << "Grace period in minutes: " << bat_protect_struct.grace_period_minutes << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      float idle_voltage = 12.3;
      float voltage_percentage_threshold = 85;
      float hysteresis_percentage = 3;
      std::uint32_t grace_period_minutes = 1;
      mcu.asyncSetBatteryProtectionConfig(battery_protection_values_handler, idle_voltage, voltage_percentage_threshold, hysteresis_percentage, grace_period_minutes);
      return 0;
      }


      NOTE: Next examples are only available for UC100 and TV10 equipments.

    • Set GPIO Values
      In order to set a GPIO values, dpyMcu::GpioConfig struct must be attended. An example is:
      #include <dpy/mcuApi.h>
      void gpio_values_handler(boost::system::error_code error_code, dpyMcu::GpioConfig & gpio_struct)
      {
      if (error_code != 0) {
      std::cout << "\rError : " << error_code.message() << std::endl;
      } else {
      std::cout << "\rSynchronous operation performed successfully" << std::endl;
      }
      waiting = false;
      }
      int main()
      {
      Mcu mcu;
      std::uint32_t gpio = 2;
      bool value = 1;
      mcu.asyncSetGpioValue(gpio_values_handler, gpio, value);
      return 0;
      }

    • Get GPIO Values
      In order to get a GPIO values, dpyMcu::GpioConfig struct must be attended. An example is:

      #include <dpy/mcuApi.h>
      void gpio_values_handler(boost::system::error_code error_code, dpyMcu::GpioConfig & gpio_struct)
      {
      if (error_code != 0) {
      if (error_code.value() == 2) {
      std::cout << "Message Error: Communication with MCU is not possible. Maybe firmware version is not up to date" << std::endl;
      } else {
      std::cout << "Message Error " << error_code.value() << ": " <<error_code.message().c_str() << std::endl;
      }
      } else {
      std::cout << "Date: " << gpio_struct.timestamp << std::endl;
      std::cout << "GPIO Number : " << gpio_struct.gpio << std::endl;
      std::cout << "GPIO Value: " << gpio_struct.value << std::endl;
      }
      }
      int main()
      {
      Mcu mcu;
      std::uint32_t gpio = 2;
      mcu.asyncGetGpioValue(gpio_values_handler, gpio);
      return 0;
      }


    • Set I2C Values
      In order to set a GPIO values, dpyMcu::I2CValue struct must be attended. An example is:
      #include <dpy/mcuApi.h>
      bool waiting;
      void set_i2c_handler(boost::system::error_code ec, __attribute__((unused)) dpyMcu::I2CValue & i2c_struct)
      {
      if (ec != 0) {
      std::cout << "\rError : " << ec.message() << std::endl;
      } else {
      std::cout << "\rSynchronous operation performed successfully" << std::endl;
      }
      waiting = false;
      }
      int main()
      {
      Mcu mcu;
      waiting = true;
      std::list<int> values({2,8,7,5,3,1,4});
      mcu.asyncSetI2CValue(set_i2c_handler, "15", "100", values);
      while(waiting);
      return 0;
      }

    • Get I2C Values
      In order to get a I2C values, dpyMcu::I2CValue struct must be attended. An example is:
      #include <dpy/mcuApi.h>
      bool waiting;
      void get_i2c_handler(boost::system::error_code error_code, dpyMcu::I2CValue & i2c_struct)
      {
      if (error_code != 0) {
      if (error_code.value() == 2) {
      std::cout << "\rError : Communication with MCU is not possible. Maybe firmware version is not up to date" << std::endl;
      } else {
      std::cout << "\rError : " << error_code.message() << std::endl;
      }
      } else {
      std::cout << "\rChip: " << i2c_struct.device << std::endl;
      std::cout << "Memory address : " << i2c_struct.address << std::endl;
      std::cout << "Values: ";
      for (int v : i2c_struct.values) {
      std::cout << v << " ";
      }
      std::cout << std::endl;
      }
      waiting = false;
      }
      int main()
      {
      Mcu mcu;
      waiting = true;
      mcu.asyncGetI2CValue(get_i2c_handler, "15", "100", 7);
      return 0;
      }