ECU C++

Classes

class  Ecu
 Allows to interact with a platform manager. More...
 
class  EcuClient
 This class is responsible of the client logic. His main target is to subscribe to the server information (Alarms publishment) as well as to ask for information to the server (PID request). More...
 

Detailed Description

ECU API related documentation

Here it will give a quick overview of basic ECU capabilities. If you find ECU API useful and would like to know more details, please check out further sections of the ECU documentation or contact the Deepsy platform team.

Examples

  • Getting the available EPIDs and their values

    #include <dpy/ecuApi.h>
    #include <iostream>
    volatile bool waiting = true;
    static Ecu ecu;
    void parameters_values_handler(boost::system::error_code& error_code, std::vector<dpyEcu::Parameter> params)
    {
    if (error_code.value() != 0) {
    std::cout << "Error : " << error_code.message() << std::endl;
    } else {
    for (unsigned int i = 0; i < params.size(); i++) {
    std::cout << params[i].id << ": " << params[i].value << " " << params[i].units << std::endl;
    }
    }
    waiting = false;
    }
    void epids_handler(boost::system::error_code error_code, std::vector<std::string> EPIDs)
    {
    if (error_code.value() != 0) {
    std::cout << "Error : " << error_code.message() << std::endl;
    } else {
    if (EPIDs.size() > 0) {
    std::cout << "Available parameters:" << std::endl;
    for (auto epid : EPIDs) {
    std::cout << "\"" << epid << "\"" << std::endl;
    }
    ecu.asyncGetParameter(parameters_values_handler, EPIDs);
    } else {
    std::cout << "There are not available parameters" << std::endl;
    std::vector<std::string> epids;
    epids.push_back("Vehicle_Speed");
    ecu.asyncGetParameter(parameters_values_handler, epids);
    }
    }
    }
    int main(int argc, char *argv[])
    {
    ecu.asyncGetAvailableEPIDs(epids_handler);
    while (waiting) {
    usleep(300000);
    }
    }

  • Getting CAN bus messages

    #include "dpy/ecuApi.h"
    #include <iostream>
    volatile bool waiting = true;
    static Ecu ecu;
    void can_bus_messages(boost::system::error_code &ec, dpyEcu::CANBusFrame frame)
    {
    if (ec.value() != 0) {
    std::cout << "\rError : " << ec.message() << std::endl;
    } else {
    std::ostringstream id_hex;
    id_hex << std::hex << frame.id;
    std::string id_string = id_hex.str();
    std::cout <<"0x" << id_string <<
    "\t["<< std::to_string(frame.data_size) <<"]" <<
    "\t"<< frame.data << std::endl;
    }
    }
    int main(int argc, char *argv[])
    {
    Ecu ecu;
    std::cout << "CAN BUS MESSAGES: " << std::endl;
    std::cout << "Id\t\tSize\tData" << std::endl;
    ecu.getCanBusMessages_S(can_bus_messages);
    while (waiting) {
    usleep(10000);
    }
    }