mcuApi.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <boost/function.hpp>
9 #include <boost/system/error_code.hpp>
10 #include <boost/shared_ptr.hpp>
11 #include <list>
12 
13 #include "mcuTypes.h"
14 #include "firmware.h"
15 
16 class McuClient;
17 
23 namespace dpyMcu {
29 
33 {
34  RED = 1,
35  BLUE = 2,
36  GREEN = 3,
37  MAGENTA = 4,
38  YELLOW = 5,
39  CYAN = 6,
40  UNDEFINED = 7
41 };
42 
45 {
46  N_A = 1,
47  POWER_ON = 2,
48  REBOOT = 3,
49  STANDBY = 4,
50  HALT = 5,
51  ABORT = 6,
53 };
54 
56  GPI1 = 1,
57  GPI2 = 2,
58  GPI3 = 3,
59  GPI4 = 4,
60  GPI5 = 5,
61  GPI6 = 6,
62  GPI7 = 7,
63  GPI8 = 8,
64  BUTTON1 = 9,
65  BUTTON2 = 10,
66  BUTTON3 = 11,
67  BUTTON4 = 12,
68  BUTTON5 = 13,
69  BUTTON6 = 14,
70  BUTTON7 = 15,
71  BUTTON8 = 16,
72  POWER_BUTTON = 17,
73  ODO = 18,
74  ODO_REDU = 19,
75  IGN = 20,
76  GPO1 = 21,
77  GPO2 = 22,
78  GPO3 = 23,
79  GPO4 = 24,
80  GPO5 = 25,
81  GPO6 = 26,
82  GPO7 = 27,
83  GPO8 = 28
84 };
85 
87 enum Result {
88  OK = 0,
89  ERROR = 1
90 };
92 
98 struct LedsConfig
101 {
102  std::string timestamp;
104  std::uint32_t period;
105  std::uint32_t duty_cycle;
106 };
107 
110 {
111  std::string timestamp;
112  std::uint32_t gpio;
113  bool value;
114 };
115 
117 struct I2CValue
118 {
119  int bus;
120  int device;
121  std::list<int> address;
122  std::list<int> values;
123 };
124 
127 {
128  std::string timestamp;
129  std::string partition_written;
130 };
131 
134 {
135  std::string timestamp;
136  bool ignition;
140  std::int32_t temperature;
141  bool fault;
143 };
144 
147 {
148  std::string timestamp;
150  std::uint32_t event_flags;
152 };
153 
156 {
157  std::string timestamp;
158  std::uint32_t timer_standby_minutes;
159  std::uint32_t timer_halt_minutes;
160 };
161 
164 {
165  std::string timestamp;
166  std::string part_number;
167  std::string serial_number;
168  std::string cidl_number;
169 };
170 
173 {
174  std::list<struct GUIDConfig> guids;
175 };
176 
179 {
180  std::string timestamp;
181  std::uint32_t power_on_hours_working;
182  std::uint32_t standby_hours_working;
183  std::uint32_t halt_hours_working;
184 };
185 
187 struct MCUStatus
188 {
189  std::string timestamp;
190  std::uint32_t hardware_exceptions;
191  std::uint32_t software_exceptions;
192 };
193 
196 {
197  std::string timestamp;
198  float idle_voltage;
201  std::uint32_t grace_period_minutes;
202 };
203 
206 {
207  std::string timestamp;
208  std::uint32_t seconds;
209  std::uint32_t minutes;
210  std::uint32_t hours;
211  std::uint32_t day;
212  std::uint32_t month;
213  std::uint32_t year;
214 };
216 
221 typedef boost::function<void(const bool &available)> service_availability_handler;
222 
228 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::PowerInformationConfig &)> power_mng_handler_function;
234 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::LedsConfig &)> leds_handler_function;
240 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::PowerStateConfig &)> power_states_handler_function;
246 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::TimersConfig &)> timers_handler_function;
252 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::UpdateConfig &)> update_firmware_handler_function;
258 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::GUIDConfigList &)> guid_handler_function;
265 typedef boost::function<void(boost::system::error_code error_code, char &, char &)> eqvar_handler_function;
271 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::WorkingTimeConfig &)> working_time_handler_function;
277 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::MCUStatus &)> mcu_status_handler_function;
283 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::BatteryProtectionConfig &)> battery_protection_handler_function;
289 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::DateConfig &)> rtc_date_handler_function;
295 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::GpioConfig &)> gpio_handler_function;
301 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::GpiosAvailable &)> gpios_events_handler_function;
307 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::I2CValue &)> i2c_handler_function;
313 typedef boost::function<void(boost::system::error_code error_code, const dpyFirmware::FirmwareVersionInfo& fw_version)> version_handler_function;
319 typedef boost::function<void(boost::system::error_code error_code, dpyMcu::CanStatusEvent &)> can_status_handler_function;
320 
325 typedef boost::function<void(boost::system::error_code error_code)> test_misc_handler_function;
326 
331 typedef boost::function<void(boost::system::error_code error_code)> set_power_button_state_handler_function;
332 
338 typedef boost::function<void(boost::system::error_code error_code, bool enabled)> get_power_button_state_handler_function;
339 
344 typedef boost::function<void(boost::system::error_code error_code)> result_handler_function;
345 
346 }
347 
353 class Mcu
354 {
355 protected:
359  boost::shared_ptr<McuClient> mClient;
360 public:
365  explicit Mcu(std::string ip = "127.0.0.1");
366 
370  virtual ~Mcu();
371 
373 #ifndef TESTING
374 
378  bool isAlive();
379 
380  void monitorServiceAvailability_S(dpyMcu::service_availability_handler handler);
381  void monitorServiceAvailability_U();
382 
387  void asyncGetLedsConfig(dpyMcu::leds_handler_function handler);
388 
396  void asyncSetLedsConfig(dpyMcu::leds_handler_function handler, dpyMcu::LedsColor color, std::uint32_t period, std::uint32_t duty_cycle);
397 
409  void asyncSetBatteryProtectionConfig(dpyMcu::battery_protection_handler_function handler, float idle_voltage, float voltage_percentage_threshold,
410  float hysteresis_percentage, std::uint32_t grace_period_minutes);
411 
416  void asyncGetBatteryProtectionConfig(dpyMcu::battery_protection_handler_function handler);
417 
422  void asyncGetRtcDateConfig(dpyMcu::rtc_date_handler_function handler);
423 
429  boost::system::error_code getRtcDateConfig(dpyMcu::DateConfig & config);
430 
435  void asyncGetTimersConfig(dpyMcu::timers_handler_function handler);
436 
441  void asyncUpdateMCU(dpyMcu::update_firmware_handler_function handler);
442 
447  void asyncGetGUIDValues(dpyMcu::guid_handler_function handler);
448 
454  virtual boost::system::error_code getGUIDValues( dpyMcu::GUIDConfigList &guid_list);
455 
456 
461  void asyncGetEQVar(dpyMcu::eqvar_handler_function handler);
462 
469  virtual boost::system::error_code getEQVar(char &eq_id, char &var_id);
470 
475  void asyncGetWorkingTimeValues(dpyMcu::working_time_handler_function handler);
476 
481  void asyncGetMCUStatus(dpyMcu::mcu_status_handler_function handler);
482 
487  void getPowerInformation_S(dpyMcu::power_mng_handler_function handler);
488 
493  void asyncGetPowerInformation(dpyMcu::power_mng_handler_function handler);
494 
500  void asyncGetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number);
501 
508  void asyncSetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number, bool gpio_value);
509 
514  void asyncGetGpiosEvents(dpyMcu::gpios_events_handler_function handler);
515 
524  void asyncGetI2CValue(dpyMcu::i2c_handler_function handler, unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, int lenght);
525 
535  void asyncSetI2CValue(dpyMcu::i2c_handler_function handler, unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, std::list<unsigned char> values);
536 
542  void asyncGetVersion(dpyMcu::version_handler_function handler, dpyFirmware::Rfs rfs);
543 
547  void getPowerInformation_U();
548 
549 
560  boost::system::error_code setI2CValue(unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, std::list<unsigned char> values,dpyMcu::I2CValue& result);
561 
572  boost::system::error_code getI2CValue(unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, int length,dpyMcu::I2CValue& result);
573 
578  void asyncGetCanStatus(dpyMcu::can_status_handler_function handler);
579 
580 
581 #else
582  virtual bool isAlive();
583  virtual void asyncGetLedsConfig(dpyMcu::leds_handler_function handler);
584  virtual void asyncSetLedsConfig(dpyMcu::leds_handler_function handler, dpyMcu::LedsColor color, std::uint32_t period, std::uint32_t duty_cycle);
585  virtual void asyncSetBatteryProtectionConfig(dpyMcu::battery_protection_handler_function handler, float idle_voltage, float voltage_percentage_threshold, float hysteresis_percentage, std::uint32_t grace_period_minutes);
586  virtual void asyncGetBatteryProtectionConfig(dpyMcu::battery_protection_handler_function handler);
587  virtual void asyncGetRtcDateConfig(dpyMcu::rtc_date_handler_function handler);
588  virtual boost::system::error_code getRtcDateConfig(dpyMcu::DateConfig & config);
589  virtual void asyncGetTimersConfig(dpyMcu::timers_handler_function handler);
590  virtual void asyncUpdateMCU(dpyMcu::update_firmware_handler_function handler);
591  virtual void asyncGetGUIDValues(dpyMcu::guid_handler_function handler);
592  virtual boost::system::error_code getGUIDValues( dpyMcu::GUIDConfigList &guid_list);
593  virtual void asyncGetEQVar(dpyMcu::eqvar_handler_function handler);
594  virtual boost::system::error_code getEQVar(char &eq_id, char &var_id);
595  virtual void asyncGetWorkingTimeValues(dpyMcu::working_time_handler_function handler);
596  virtual void asyncGetMCUStatus(dpyMcu::mcu_status_handler_function handler);
597  virtual void getPowerInformation_S(dpyMcu::power_mng_handler_function handler);
598  virtual void asyncGetPowerInformation(dpyMcu::power_mng_handler_function handler);
599  virtual void asyncGetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number);
600  virtual void asyncSetGpioValue(dpyMcu::gpio_handler_function handler, std::uint32_t gpio_number, bool gpio_value);
601  virtual void asyncGetGpiosEvents(dpyMcu::gpios_events_handler_function handler);
602  virtual void asyncGetVersion(dpyMcu::version_handler_function handler, dpyFirmware::Rfs rfs);
603  virtual void getPowerInformation_U();
604  virtual boost::system::error_code setI2CValue(unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, std::list<unsigned char> values,dpyMcu::I2CValue& value);
605  virtual boost::system::error_code getI2CValue(unsigned char busid, unsigned char deviceid, std::list<unsigned char> address, int lenght,dpyMcu::I2CValue& value);
606 
607 #endif
608 };
boost::function< void(boost::system::error_code error_code)> result_handler_function
Prototype of the handler function for obtaining the result of the operations status.
Definition: mcuApi.h:344
ODO.
Definition: mcuApi.h:73
GPO8.
Definition: mcuApi.h:83
BUTTON3.
Definition: mcuApi.h:66
std::string timestamp
timestamp
Definition: mcuApi.h:197
int bus
bus
Definition: mcuApi.h:119
I2C Struct which contains the response received from the service.
Definition: mcuApi.h:117
std::string serial_number
Serial Number of the equipment.
Definition: mcuApi.h:167
PowerInformation struct which contains the response received from the service.
Definition: mcuApi.h:146
std::string timestamp
timestamp
Definition: mcuApi.h:207
float battery_inner_percent
battery inner percent
Definition: mcuApi.h:138
std::uint32_t hardware_exceptions
Hardware exceptions.
Definition: mcuApi.h:190
IGNITION.
Definition: mcuApi.h:75
std::string timestamp
timestamp
Definition: mcuApi.h:148
BUTTON8.
Definition: mcuApi.h:71
boost::function< void(boost::system::error_code error_code, dpyMcu::TimersConfig &)> timers_handler_function
Prototype of the handler function for obtaining the Timers Configuration.
Definition: mcuApi.h:246
UNDEFINED.
Definition: mcuApi.h:40
Power On.
Definition: mcuApi.h:47
std::uint32_t year
year
Definition: mcuApi.h:213
MAGENTA.
Definition: mcuApi.h:37
std::uint32_t period
Period in seconds (range: 0 - 10)
Definition: mcuApi.h:104
std::uint32_t software_exceptions
Software exceptions.
Definition: mcuApi.h:191
GUID struct which contains the response received from the service.
Definition: mcuApi.h:163
DateConfig struct which contains the response received from the service.
Definition: mcuApi.h:205
GPI2.
Definition: mcuApi.h:57
Class with the logic of the client.
Definition: mcuClient.h:26
Standby.
Definition: mcuApi.h:49
GpiosAvailable
Possible color to be set.
Definition: mcuApi.h:55
boost::function< void(boost::system::error_code error_code, dpyMcu::MCUStatus &)> mcu_status_handler_function
Prototype of the handler function for obtaining the MCU Status.
Definition: mcuApi.h:277
Working Time struct which contains the response received from the service.
Definition: mcuApi.h:178
int device
device
Definition: mcuApi.h:120
PowerStates power_state
power_state
Definition: mcuApi.h:149
boost::function< void(boost::system::error_code error_code, const dpyFirmware::FirmwareVersionInfo &fw_version)> version_handler_function
Prototype of the handler function for obtaining the fw version.
Definition: mcuApi.h:313
std::uint32_t timer_halt_minutes
Halt Timer.
Definition: mcuApi.h:159
std::string part_number
Part Number of the equipment.
Definition: mcuApi.h:166
std::uint32_t timer_standby_minutes
Standby Timer.
Definition: mcuApi.h:158
std::string timestamp
timestamp
Definition: mcuApi.h:157
std::string timestamp
timestamp
Definition: mcuApi.h:189
std::string timestamp
timestamp
Definition: mcuApi.h:165
boost::function< void(boost::system::error_code error_code, dpyMcu::GpioConfig &)> gpio_handler_function
Prototype of the handler function for obtaining the GPIO Configuration.
Definition: mcuApi.h:295
Halt.
Definition: mcuApi.h:50
Class which interfaces with the API logic.
Definition: mcuApi.h:353
std::string timestamp
timestamp
Definition: mcuApi.h:135
BUTTON7.
Definition: mcuApi.h:70
std::uint32_t grace_period_minutes
grace period in minutes used to enter in halt mode irrevocably
Definition: mcuApi.h:201
Battery Protection Config struct which contains the response received from the service.
Definition: mcuApi.h:195
BLUE.
Definition: mcuApi.h:35
boost::function< void(const bool &available)> service_availability_handler
Prototype of the handler function used to monitor service availability.
Definition: mcuApi.h:221
BUTTON4.
Definition: mcuApi.h:67
GPI6.
Definition: mcuApi.h:61
std::string partition_written
partition_written
Definition: mcuApi.h:129
BUTTON5.
Definition: mcuApi.h:68
RED.
Definition: mcuApi.h:34
std::uint32_t duty_cycle
duty_cycle in percentage (range: 0% - 100%)
Definition: mcuApi.h:105
GPO6.
Definition: mcuApi.h:81
float voltage_percentage_over_idle_voltage_threshold
voltage percentage threshold calculated over idle voltage
Definition: mcuApi.h:199
GPI7.
Definition: mcuApi.h:62
BUTTON1.
Definition: mcuApi.h:64
Result result
result
Definition: mcuApi.h:151
Defines a class for checking firmware binaries available for upgrading.
Rfs
Defines the possible root file systems where binaries are located.
Definition: firmware.h:54
std::uint32_t day
day
Definition: mcuApi.h:211
GPI3.
Definition: mcuApi.h:58
boost::function< void(boost::system::error_code error_code, dpyMcu::CanStatusEvent &)> can_status_handler_function
Prototype of the handler function for obtaining the CAN Status Information.
Definition: mcuApi.h:319
std::uint32_t power_on_hours_working
Power-On hours working.
Definition: mcuApi.h:181
std::uint32_t seconds
seconds
Definition: mcuApi.h:208
MCU Status struct which contains the response received from the service.
Definition: mcuApi.h:187
boost::function< void(boost::system::error_code error_code, dpyMcu::WorkingTimeConfig &)> working_time_handler_function
Prototype of the handler function for obtaining the Working Time Values.
Definition: mcuApi.h:271
Deepsy Mcu namespace that includes the different enums, structs or method signatures that should be u...
Definition: mcuApi.h:16
bool fault
fault
Definition: mcuApi.h:141
GPO4.
Definition: mcuApi.h:79
OK.
Definition: mcuApi.h:88
boost::function< void(boost::system::error_code error_code, dpyMcu::GpiosAvailable &)> gpios_events_handler_function
Prototype of the handler function for obtaining the GPIO Events.
Definition: mcuApi.h:301
GPI5.
Definition: mcuApi.h:60
GPO1.
Definition: mcuApi.h:76
Abort.
Definition: mcuApi.h:51
boost::function< void(boost::system::error_code error_code, bool enabled)> get_power_button_state_handler_function
Prototype of the handler function for obtaining the result of power button.
Definition: mcuApi.h:338
GPO7.
Definition: mcuApi.h:82
boost::function< void(boost::system::error_code error_code, dpyMcu::I2CValue &)> i2c_handler_function
Prototype of the handler function for obtaining the I2C information.
Definition: mcuApi.h:307
std::uint32_t minutes
minutes
Definition: mcuApi.h:209
BUTTON6.
Definition: mcuApi.h:69
PowerInformation struct which contains the response received from the service.
Definition: mcuApi.h:133
std::string timestamp
timestamp
Definition: mcuApi.h:102
GPI4.
Definition: mcuApi.h:59
Update struct which contains the response received from the service.
Definition: mcuApi.h:126
Timers struct which contains the response received from the service.
Definition: mcuApi.h:155
std::string timestamp
timestamp
Definition: mcuApi.h:180
std::list< int > values
i2c values
Definition: mcuApi.h:122
boost::function< void(boost::system::error_code error_code, dpyMcu::GUIDConfigList &)> guid_handler_function
Prototype of the handler function for obtaining the GUIDs.
Definition: mcuApi.h:258
bool battery_protection_mode
battery protection mode
Definition: mcuApi.h:142
boost::function< void(boost::system::error_code error_code)> set_power_button_state_handler_function
Prototype of the handler function for obtaining the result of power button.
Definition: mcuApi.h:331
Not Available.
Definition: mcuApi.h:46
boost::function< void(boost::system::error_code error_code, dpyMcu::UpdateConfig &)> update_firmware_handler_function
Prototype of the handler function for obtaining the updated configuration.
Definition: mcuApi.h:252
std::string timestamp
timestamp
Definition: mcuApi.h:111
GPO3.
Definition: mcuApi.h:78
float hysteresis_percentage_over_idle_voltage
hysteresis percentage calculated over idle voltage
Definition: mcuApi.h:200
BUTTON2.
Definition: mcuApi.h:65
boost::function< void(boost::system::error_code error_code, dpyMcu::BatteryProtectionConfig &)> battery_protection_handler_function
Prototype of the handler function for obtaining the Battery Protection Configuration.
Definition: mcuApi.h:283
Result
Possible received result.
Definition: mcuApi.h:87
Definition: mcuApi.h:100
boost::function< void(boost::system::error_code error_code, dpyMcu::DateConfig &)> rtc_date_handler_function
Prototype of the handler function for obtaining the RTC Date Configuration.
Definition: mcuApi.h:289
YELLOW.
Definition: mcuApi.h:38
boost::function< void(boost::system::error_code error_code, dpyMcu::PowerStateConfig &)> power_states_handler_function
Prototype of the handler function for obtaining the Power State Configuration.
Definition: mcuApi.h:240
std::list< int > address
memory address
Definition: mcuApi.h:121
float battery_extern_voltage
battery extern voltage
Definition: mcuApi.h:137
float idle_voltage
idle voltage identified by ignition position off, engine off and stationary vehicle ...
Definition: mcuApi.h:198
bool value
GPIO value (values: 0 or 1)
Definition: mcuApi.h:113
Critical battery.
Definition: mcuApi.h:52
POWER_BUTTON.
Definition: mcuApi.h:72
bool battery_type
battery type: 1 –> 24V, 0 –> 12V
Definition: mcuApi.h:139
LedsColor color
state
Definition: mcuApi.h:103
GREEN.
Definition: mcuApi.h:36
GUID list struct which contains the response received from the service.
Definition: mcuApi.h:172
bool ignition
ignition
Definition: mcuApi.h:136
PowerStates
Possible power state to be set.
Definition: mcuApi.h:44
std::list< struct GUIDConfig > guids
GUIDs elements.
Definition: mcuApi.h:174
std::string cidl_number
CIDL Number of the equipment.
Definition: mcuApi.h:168
std::uint32_t standby_hours_working
Standby hours working.
Definition: mcuApi.h:182
ERROR.
Definition: mcuApi.h:89
std::int32_t temperature
temperature
Definition: mcuApi.h:140
GPO2.
Definition: mcuApi.h:77
GPO5.
Definition: mcuApi.h:80
std::uint32_t halt_hours_working
Halt hours working.
Definition: mcuApi.h:183
boost::function< void(boost::system::error_code error_code)> test_misc_handler_function
Prototype of the handler function for obtaining the current MISC status.
Definition: mcuApi.h:325
ODO_REDU.
Definition: mcuApi.h:74
std::uint32_t gpio
GPIOs values (values: 1 - 4)
Definition: mcuApi.h:112
std::uint32_t hours
hours
Definition: mcuApi.h:210
std::uint32_t event_flags
set flags to enter in power state
Definition: mcuApi.h:150
boost::function< void(boost::system::error_code error_code, char &, char &)> eqvar_handler_function
Prototype of the handler function for obtaining the GUIDs.
Definition: mcuApi.h:265
CYAN.
Definition: mcuApi.h:39
boost::function< void(boost::system::error_code error_code, dpyMcu::LedsConfig &)> leds_handler_function
Prototype of the handler function for obtaining the LEDs configuration.
Definition: mcuApi.h:234
GPI8.
Definition: mcuApi.h:63
Reboot.
Definition: mcuApi.h:48
std::uint32_t month
month
Definition: mcuApi.h:212
boost::shared_ptr< McuClient > mClient
Reference to an Client Object.
Definition: mcuApi.h:359
std::string timestamp
timestamp
Definition: mcuApi.h:128
GPIO Struct which contains the response received from the service.
Definition: mcuApi.h:109
boost::function< void(boost::system::error_code error_code, dpyMcu::PowerInformationConfig &)> power_mng_handler_function
Prototype of the handler function for obtaining the Power Information.
Definition: mcuApi.h:228
LedsColor
Possible color to be set.
Definition: mcuApi.h:32
GPI1.
Definition: mcuApi.h:56