MCU C++

MCU API related documentation. More...

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

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.value() != 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.value() != 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.value() != 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.value() != 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.value() != 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.value() != 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.value() != 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.value() != 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.value() != 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.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 << "\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;
      }

bool fault
fault
Definition: mcuApi.h:141
std::string protocol
protocol
Definition: firmware.h:35
std::string cidl_number
CIDL Number of the equipment.
Definition: mcuApi.h:168
std::string timestamp
timestamp
Definition: mcuApi.h:128
std::uint32_t period
Period in seconds (range: 0 - 10)
Definition: mcuApi.h:104
void asyncSetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number, bool gpio_value)
Method which requests to set a GPIO pin with a value.
void asyncSetI2CValue(dpyMcu::i2c_handler_function handler, unsigned char busid, unsigned char deviceid, std::list< unsigned char > address, std::list< unsigned char > values)
Method which requests to set a I2C address pin with a value.
std::string timestamp
timestamp
Definition: mcuApi.h:102
float voltage_percentage_over_idle_voltage_threshold
voltage percentage threshold calculated over idle voltage
Definition: mcuApi.h:199
std::string timestamp
timestamp
Definition: mcuApi.h:197
float idle_voltage
idle voltage identified by ignition position off, engine off and stationary vehicle
Definition: mcuApi.h:198
std::string vendor
vendor
Definition: firmware.h:34
GPIO Struct which contains the response received from the service.
Definition: mcuApi.h:109
LedsColor color
state
Definition: mcuApi.h:103
std::string product
product
Definition: firmware.h:33
bool value
GPIO value (values: 0 or 1)
Definition: mcuApi.h:113
std::uint32_t timer_halt_minutes
Halt Timer.
Definition: mcuApi.h:159
@ RED
RED.
Definition: mcuApi.h:34
std::uint32_t timer_standby_minutes
Standby Timer.
Definition: mcuApi.h:158
GUID struct which contains the response received from the service.
Definition: mcuApi.h:163
std::string serial_number
Serial Number of the equipment.
Definition: mcuApi.h:167
std::string timestamp
timestamp
Definition: mcuApi.h:157
Timers struct which contains the response received from the service.
Definition: mcuApi.h:155
void getPowerInformation_S(dpyMcu::power_mng_handler_function handler)
Method which receives one message with Power information coming from the service periodically.
float hysteresis_percentage_over_idle_voltage
hysteresis percentage calculated over idle voltage
Definition: mcuApi.h:200
std::list< int > address
memory address
Definition: mcuApi.h:121
void asyncUpdateMCU(dpyMcu::update_firmware_handler_function handler)
Method which updates the firmware of the MCU (the new image must be in the right PATH of the system)
@ CYAN
CYAN.
Definition: mcuApi.h:39
void asyncSetBatteryProtectionConfig(dpyMcu::battery_protection_handler_function handler, float idle_voltage, float voltage_percentage_threshold, float hysteresis_percentage, std::uint32_t grace_period_minutes)
Method which requests to set battery protection configuration values.
std::list< int > values
i2c values
Definition: mcuApi.h:122
void asyncGetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number)
Method which requests one message with GPIO information.
std::string version
firmware version
Definition: firmware.h:32
@ UNDEFINED
UNDEFINED.
Definition: mcuApi.h:40
std::string partition_written
partition_written
Definition: mcuApi.h:129
@ MAGENTA
MAGENTA.
Definition: mcuApi.h:37
PowerInformation struct which contains the response received from the service.
Definition: mcuApi.h:133
Battery Protection Config struct which contains the response received from the service.
Definition: mcuApi.h:195
Class which interfaces with the API logic.
Definition: mcuApi.h:353
A structure use to store firmware info.
Definition: firmware.h:30
void asyncGetI2CValue(dpyMcu::i2c_handler_function handler, unsigned char busid, unsigned char deviceid, std::list< unsigned char > address, int lenght)
Method which requests one message with I2C information.
int device
device
Definition: mcuApi.h:120
I2C Struct which contains the response received from the service.
Definition: mcuApi.h:117
@ YELLOW
YELLOW.
Definition: mcuApi.h:38
std::string part_number
Part Number of the equipment.
Definition: mcuApi.h:166
float battery_inner_percent
battery inner percent
Definition: mcuApi.h:138
void asyncGetGUIDValues(dpyMcu::guid_handler_function handler)
Method which requests one message with Part Number, Serial Number and CIDL of the equipment.
std::string timestamp
timestamp
Definition: mcuApi.h:135
Definition: mcuApi.h:100
float battery_extern_voltage
battery extern voltage
Definition: mcuApi.h:137
bool battery_type
battery type: 1 --> 24V, 0 --> 12V
Definition: mcuApi.h:139
std::uint32_t duty_cycle
duty_cycle in percentage (range: 0% - 100%)
Definition: mcuApi.h:105
bool battery_protection_mode
battery protection mode
Definition: mcuApi.h:142
void asyncGetTimersConfig(dpyMcu::timers_handler_function handler)
Method which requests one message with Standby and Halt Timers.
std::string timestamp
timestamp
Definition: mcuApi.h:165
void asyncSetLedsConfig(dpyMcu::leds_handler_function handler, dpyMcu::LedsColor color, std::uint32_t period, std::uint32_t duty_cycle)
Method which requests to change the LED color state.
@ GREEN
GREEN.
Definition: mcuApi.h:36
bool ignition
ignition
Definition: mcuApi.h:136
std::uint32_t gpio
GPIOs values (values: 1 - 4)
Definition: mcuApi.h:112
@ BLUE
BLUE.
Definition: mcuApi.h:35
Update struct which contains the response received from the service.
Definition: mcuApi.h:126
std::uint32_t grace_period_minutes
grace period in minutes used to enter in halt mode irrevocably
Definition: mcuApi.h:201
std::string timestamp
timestamp
Definition: mcuApi.h:111
void asyncGetVersion(dpyMcu::version_handler_function handler, dpyFirmware::Rfs rfs)
Method which requests the firware version of the MCU.
std::int32_t temperature
temperature
Definition: mcuApi.h:140