# CosmicAsyncSDK class

This page describes the CosmicAsyncSDK C++ class and its generic public methods. For each specific protocol APIs, please refer to the corresponding sections.

group CosmicSDK C++ non-blocking API

  High-level non-blocking C++ interface to Binho devices.

  This module provides a non-blocking C++ API. It allows users to connect to Binho devices and perform various operations asynchronously. Users must set up a response callback using the `onResponse` method to handle incoming data from the device.

  class CosmicAsyncSDK
    #include <CosmicAsyncSDK.hpp>

    This class provides a non-blocking C++ interface. It allows users to connect to Binho devices and perform various operations asynchronously. Users must set up a response callback using the onResponse method to handle incoming data from the device.

    Public Functions

    CosmicAsyncSDK()

      Construct a new Cosmic Async SDK object.

    ~CosmicAsyncSDK()

      Destroy the Cosmic Async SDK object.

    void onResponse(std::function<void(const std::vector<uint8_t>&)> callback)

      Sets the callback function to be called when a response is received from the device.

      Parameters:

        callback – The callback function that takes a vector of uint8_t as parameter.

    bool connect(const std::string &devicePath = "")

      Connects to the device using the provided path.

      Parameters:

        devicePath – The path to the device. If empty, connects to the first available device.

      Returns:

        true if the connection was successful, false otherwise.

    bool connectWithSerialNumber(const std::string &serial)

      Connects to the device using the provided serial number.

      Parameters:

        serial – The serial number of the device to connect to.

      Returns:

        true if the connection was successful, false otherwise.

    void disconnect()

      Disconnects from the device.

    inline bool isConnected()

      Checks if the device is connected.

      Returns:

        true if the device is connected.

      Returns:

        false if the device is not connected.

    uint16_t getUsbString(uint16_t id, uint8_t subCmd)

      Get one USB String identified by the subcommand.

      Parameters:

        - id – uint16_t Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

        - subCmd – unint8_t Subcommand to identify the USB String to be retrieved.

      Returns:

        uint16_t SUCCESS or SDK_ERROR_DISCONNECT if the device is not connected.

    uint16_t enterBootMode(uint16_t id)

      Puts the device into boot mode. Once the device process the request, it immediately jumps into the bootloader. After the user has flashed the device with a firmware, a new connection needs to be done to continue using the device.

      Parameters:

        id – uint16_t Command Id to identify the request. Values from 1 to 65535 are valid. 0 is reserved for notifications.

      Returns:

        uint16_t Result of the request.

    Public Static Functions

    static inline std::string getVersion()

      Gets the CosmicSDK library version string.

      Returns a string containing the version number of the linked CosmicSDK library. This allows verification at startup that the linked library matches what they were built against.

      Returns:

        A version string in the format “MAJOR.MINOR.PATCH”, e.g. “1.2.3”