# 示例代码

Source: [https://docs.qualcomm.com/doc/80-PK177-134Y/topic/lce_example_code.html](https://docs.qualcomm.com/doc/80-PK177-134Y/topic/lce_example_code.html)

## Java

**需要导入**

    import com.qualcomm.qti.qesdk.Modem.ILinkCapacityEstimateCBs;
          import com.qualcomm.qti.qesdk.Modem.LinkCapacityEstimateEnums;
          import com.qualcomm.qti.qesdk.Modem.LinkCapacityEstimateManager;
          import com.qualcomm.qti.qesdkIntf.IQesdk;Copy to clipboard

**初始化**

    IQesdk qesdkManager = Iqesdk.createInstance(getApplicationContext());
          int statusId = qesdkManager.init(eventCallbackHandler);
          LinkCapacityEstimateManager lceManager = new LinkCapacityEstimateManager(qesdkManager);
          LinkCapacityEstimateEnums.reportingAction action = LinkCapacityEstimateEnums.reportingAction.START;
          //action = LinkCapacityEstimateEnums.reportingAction.STOP;
          //action = LinkCapacityEstimateEnums.reportingAction.RESET;Copy to clipboard

**声明回调**

    IQesdkEventCallBack eventCallbackHandler = new IQesdkEventCallBack() {
          @Override
          public void onEvent(int opcode, int[] subsys) {
          // Handle QESDK event
          }
          };
          
          IlinkCapacityEstimateCBs.IestimationReport estimationReportCallback  = new IlinkCapacityEstimateCBs.IestimationReport() {
          @Override
          public void onValues(long rate,LinkCapacityEstimateEnums.confidenceLevel confidenceLevel, LinkCapacityEstimateEnums.linkDirection linkDirection, long queueSizeUL, String error) {
          // Handle LCE estimation report callback
          }
          }
          
          ILinkCapacityEstimateCBs.IasyncResult() resultCallback = new ILinkCapacityEstimateCBs.IasyncResult() {
          @Override
          public void onValues(boolean success, String error) {
          // Handle API result callback
          }
          }
          
          IlinkCapacityEstimateCBs.IestimationReport lastEstimationReportCallback  = new IlinkCapacityEstimateCBs.IestimationReport() {
          @Override
          public void onValues(long rate,LinkCapacityEstimateEnums.confidenceLevel confidenceLevel, LinkCapacityEstimateEnums.linkDirection linkDirection, long queueSizeUL, String error) {
          // Handle last LCE estimation report callback
          }
          }Copy to clipboard

**注册估计报告**

    int ret = lceManager.registerForEstimationReports(estimationReportCallback);Copy to clipboard

**设置报告标准**

    ret = lceManager.setReportingCriteria(hyst, thresholdDown, thresholdUp, techType, period, resultCallback);Copy to clipboard

**获取最后一个估计报告**

    int m =  lceManager.getLastEstimationReport(lastEstimationReportCallback);Copy to clipboard

**根据设定的标准执行启动/停止/复位操作**

    int m =  lceManager.performReportingAction(action);Copy to clipboard

## 原生

**需要包括的内容**

    #include "qesdk_ndk.h"
          #include "qesdk_Modem_LinkCapacityEstimate.h"Copy to clipboard

**初始化**

    qesdk_handle_t qesdk_handle = qesdk_init(nativeLicense, len, event_callback_handler);
          LinkCapacityEstimateManager *lceManager = new LinkCapacityEstimateManager();
          lce_reportingAction action = lce_reportingAction.START;
          //action = lce_reportingAction.STOP;
          //action = lce_reportingAction.RESET;Copy to clipboard

**声明回调**

    void event_callback_handler(uint32_t opcode, uint32_t subsys[]) {
          // Callback to handle QESDK events
          }
          
          void estimationReportCallback(uint32_t rate, lce_confidenceLevel confidenceLevel, lce_linkDirection linkDirection, uint32_t queueSizeUL, std::string error){
          // Handle LCE estimation report
          }
          
          void lastEstimationReportCallback(uint32_t rate, lce_confidenceLevel confidenceLevel, lce_linkDirection linkDirection, uint32_t queueSizeUL, std::string error){
          // Handle last LCE estimation report
          }
          
          void setCriteriaStatusCallback(bool success, std::string error){
          // Handle set criteria status
          }Copy to clipboard

**注册估计报告**

    int ret = lceManager->registerForEstimationReports(estimationReportCallback);Copy to clipboard

**设置报告标准**

    lceManager->setReportingCriteria(hyst, thresholds_down_vector, thresholds_up_vector, tech_type, period, setCriteriaStatusCallback);Copy to clipboard

**获取最后一个估计报告**

    ret = lceManager->getLastEstimationReport(lastEstimationReportCallback);Copy to clipboard

**根据设定的标准执行启动/停止/复位操作**

    ret = lceManager->performReportingAction(action);Copy to clipboard

**Parent Topic:** [链路容量估算 (Link capacity estimation)](https://docs.qualcomm.com/doc/80-PK177-134Y/topic/latency_capacity_estimation.html)

Last Published: Jun 22, 2023

[Previous Topic
reportingAction](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134Y/topics/lce_enum_reporting_action.md) [Next Topic
链路延迟管理器 (Link latency manager)](https://docs.qualcomm.com/bundle/publicresource/80-PK177-134Y/topics/llm.md)