BAS Exported Functions

group BAS_Exported_Functions

Functions

T_SERVER_ID bas_add_service(void *p_func)

Add battery service to the Bluetooth Host.

Example usage

void profile_init()
{
    server_init(service_num);
    bas_id = bas_add_service(app_handle_profile_message);
}

Parameters:

p_func[in] Callback when service attribute is read, written or CCCD updated.

Return values:
  • 0xFF – Operation failure.

  • Others – Service ID assigned by Bluetooth Host.

Returns:

Service ID generated by the Bluetooth Host: T_SERVER_ID.

bool bas_set_parameter(T_BAS_PARAM_TYPE param_type, uint8_t length, uint8_t *p_value)

Set a battery service parameter.

Call this function with a battery service parameter type and it will set the battery service parameter. Battery service parameters are defined in T_BAS_PARAM_TYPE. If the “length” field is set to the size of a “uint16_t”, the “p_value” field must point to data with type of “uint16_t”.

Example usage

void test(void)
{
    bool ret = bas_set_parameter(BAS_PARAM_BATTERY_LEVEL, 1, &battery_level);
}

Parameters:
  • param_type[in] Battery service parameter type: T_BAS_PARAM_TYPE.

  • length[in] Length of data to write.

  • p_value[in] Pointer to data to write. This is dependent on the parameter type and will be cast to the appropriate data type. If param_type is set to BAS_PARAM_BATTERY_LEVEL, p_value points to the current charge level of a battery. Unit is org.bluetooth.unit.percentage. Minimum value is 0, and maximum value is 100. 100% represents fully charged while 0% represents fully discharged.

Return values:
  • true – Operation success.

  • false – Operation failure.

Returns:

Operation result.

bool bas_battery_level_value_notify(uint8_t conn_id, T_SERVER_ID service_id, uint8_t battery_level)

Send notify battery level notification data.

Example usage

void test(void)
{
    bool ret = bas_battery_level_value_notify(conn_id, bas_id, battery_level);
}

Parameters:
  • conn_id[in] Connection ID.

  • service_id[in] Service ID.

  • battery_level[in] The current charge level of a battery. Unit is org.bluetooth.unit.percentage. Minimum value is 0, and maximum value is 100. 100% represents fully charged while 0% represents fully discharged.

Return values:
  • true – Operation success.

  • false – Operation failure.

Returns:

Operation result.

bool bas_battery_level_value_read_confirm(uint8_t conn_id, T_SERVER_ID service_id, uint8_t battery_level)

Confirm read battery level value request.

Example usage

void test(void)
{
    bool ret = bas_battery_level_value_read_confirm(conn_id, bas_id, battery_level);
}

Parameters:
  • conn_id[in] Connection ID.

  • service_id[in] Service ID.

  • battery_level[in] The current charge level of a battery. Unit is org.bluetooth.unit.percentage. Minimum value is 0, and maximum value is 100. 100% represents fully charged while 0% represents fully discharged.

Return values:
  • true – Operation success.

  • false – Operation failure.

Returns:

Operation result.