QSH 示例客户端 Callflow 和 QSH 客户端 API 与 QSH 的用法

  1. 传感器数据流会进行传感器数据流传输并接收数据事件:

    • 通过使用新的 sessionFactory() 类调用 getSession() 来创建用于传感器数据流的新接口会话。在这里,对于任何用例,请求传感器数据是请求数据类型的最后阶段。
    sessionFactory()class.  
    
    /* create a new ISession for streaming activity */ 
      sessionFactory* factory = new sessionFactory(); 
      if(nullptr == factory){ 
        printf("failed to create factory instance"); 
        return false; 
      } 
      ISession* streamingSession = factory->getSession(); 
      if(nullptr == streamingSession){ 
        printf("failed to create streaming session"); 
        return false; 
      } 
    
    • 通过调用 open() API 打开创建的会话接口。
      /* open the streamingSession session */ 
      int ret = streamingSession->open(); 
      if(-1 == ret){ 
        printf("failed to open ISession for attribute query"); 
        return false; 
    
    • 通过调用 setCallBacks() 并处理用于数据流活动的响应/事件/错误来设置回调。
    for (const suid& uid : suidList){ 
        /* set callbacks for the session for 'uid' */ 
        int ret = streamingSession->setCallBacks(uid, dataResp, dataError, dataEvent); 
        if(-1 == ret) 
          printf("all callbacks are null, no need to register it"); 
    
    • 通过调用 sendRequest() API 创建并发送 pb 编码的配置请求,以对给定数据类型的传感器进行数据流传输,最终启用请求的传感器。
    /* create pb-encoded config request message to be sent for streaming request */ 
        string pb_req_encoded = ""; 
        sns_std_sensor_config pb_stream_cfg; 
        pb_stream_cfg.set_sample_rate(sampleRate); 
        pb_stream_cfg.SerializeToString(&pb_req_encoded); 
        sns_client_request_msg pb_req_msg; 
        pb_req_msg.mutable_request()->mutable_batching()->set_batch_period(batchPeriod); 
        pb_req_msg.set_msg_id(SNS_STD_SENSOR_MSGID_SNS_STD_SENSOR_CONFIG); 
    .. 
    .. 
    /* send proto encoded message to sensing-hub using the opened session */ 
        unique_lock<mutex> respLock(respMutex); 
        ret = streamingSession->sendRequest(uid, pb_req_msg_encoded); 
     
    
    • 处理事件回调中的示例,并等待指定的测试持续时间。
    void handle_event_cb(const uint8_t *data, size_t size, uint64_t time_stamp){ 
    if(true == deletion_started){ 
    printf("\nEvent coming when deletion of qmi connection started"); 
    return; 
    } 
    sns_client_event_msg pb_event_msg; 
    /* Parse the pb encoded event */ 
    pb_event_msg.ParseFromArray(data, size); 
    /* Iterate over all events in the message */ 
    for (int i = 0; i < pb_event_msg.events_size(); i++) { 
    auto& pb_event = pb_event_msg.events(i);  
    
    • 通过调用 sendRequest() API 发送禁用请求来停止数据流传输活动。
    pb_req_msg.set_msg_id(SNS_CLIENT_MSGID_SNS_CLIENT_DISABLE_REQ); 
        pb_req_msg.mutable_suid()->set_suid_high(uid.high); 
        pb_req_msg.mutable_suid()->set_suid_low(uid.low); 
    .. 
    .. 
    /* send disable request to sensing-hub */ 
        int ret = streamingSession->sendRequest(uid, pb_req_msg_encoded); 
    
    • 在收到请求数据类型的数据流事件后,通过调用 close() API 来关闭会话。
    /* close and delete the streamingSession */ 
      streamingSession->close(); 
      delete streamingSession; 
      delete factory; 
    

以下代码片段显示了 SessionClient 示例程序输出。它使加速度计传感器具有 10 Hz 采样率和 2 s 的批处理周期,持续 10 s,并打印接收到的传感器事件。

root@qcm6490:~# SessionClient
Streaming configuration is as follows :
        Sensor name : accel     Sample rate : 10 Hz     Batch period : 2 sec    Test duration : 10 sec


SUID discovery response received.
Received SUIDs for accel, number of suids received = 1

SUID received - suid_low=6360260105974108950 suid_high=7037810611998542250
Sensor suid list created

requesting attributes for - suid_low=6360260105974108950 suid_high=7037810611998542250

Attribute query response received.
Attributes for - suid_low=6360260105974108950 suid_high=7037810611998542250 are :
attribute count 0        and values are: attr_id: 16     sint: 0
attribute count 1        and values are: attr_id: 9      sint: 50sint: 240sint: 240
attribute count 2        and values are: attr_id: 12     std: LPM std: NORMAL std: HIGH_PERF
attribute count 3        and values are: attr_id: 5      std: sns_accel.proto
attribute count 4        and values are: attr_id: 0      std: icm4x6xx
attribute count 5        and values are: attr_id: 1      std: TDK-Invensense
attribute count 6        and values are: attr_id: 26     boolean 1
attribute count 7        and values are: attr_id: 17     boolean 0
attribute count 8        and values are: attr_id: 10     sint: 6
attribute count 9        and values are: attr_id: 15     sint: 16
attribute count 10       and values are: attr_id: 21     boolean 1
attribute count 11       and values are: attr_id: 22     sint: 3sint: 2sint: 1
attribute count 12       and values are: attr_id: 2      std: accel
attribute count 13       and values are: attr_id: 4      sint: 82179
attribute count 14       and values are: attr_id: 13     boolean 1
attribute count 15       and values are: attr_id: 14     boolean 0
attribute count 16       and values are: attr_id: 18     sint: 0
attribute count 17       and values are: attr_id: 20     flt: 0.000000  flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000flt: 0.000000    flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000   flt: 0.000000
attribute count 18       and values are: attr_id: 19     sint: 0
attribute count 19       and values are: attr_id: 11
attribute count 20       and values are: attr_id: 7      flt: 0.000019  flt: 0.000037   flt: 0.000075   flt: 0.000150   flt: 0.000299
attribute count 21       and values are: attr_id: 24
attribute count 22       and values are: attr_id: 23     flt: 0.000299
attribute count 23       and values are: attr_id: 6      flt: 12.500000 flt: 25.000000  flt: 50.000000  flt: 100.000000 flt: 200.000000 flt: 500.000000
attribute count 24       and values are: attr_id: 25     flt: 1000.000000       flt: 2000.000000
attribute count 25       and values are: attr_id: 8      sint: 80
attribute count 26       and values are: attr_id: 3      boolean 1

Attributes for all suids received


Streaming started
sending request for - suid_low=6360260105974108950 suid_high=7037810611998542250
Data request response received.
Received re-configuration event
Cal event packet received
Received Samples:       [0.347159],     [-0.181959],    [9.450213],
Received Samples:       [0.102951],     [-0.183156],    [9.545981],
Received Samples:       [0.096965],     [-0.189142],    [9.550770],
Received Samples:       [0.092177],     [-0.192733],    [9.541193],
Received Samples:       [0.090980],     [-0.183156],    [9.555558],
Received Samples:       [0.093374],     [-0.185551],    [9.555558],
Received Samples:       [0.108936],     [-0.184354],    [9.541193],
Received Samples:       [0.098162],     [-0.185551],    [9.565135],
Received Samples:       [0.095768],     [-0.185551],    [9.550770],
Received Samples:       [0.100556],     [-0.193930],    [9.550770],
Received Samples:       [0.092177],     [-0.186748],    [9.550770],
Received Samples:       [0.094571],     [-0.199916],    [9.541193],
Received Samples:       [0.105345],     [-0.199916],    [9.550770],
Received Samples:       [0.098162],     [-0.185551],    [9.550770],

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐