Fork me on GitHub

一 方案简介
1.简介
Apollo3 Blue Wireless SoC是一款超低功耗无线mcu芯片,它的运行功耗降至6μA/ MHz以下。该器件采用ARM Cortex M4F内核,运行频率高达96 MHz,集成了蓝牙低功耗(BLE5),并提供一些更新的外设,附加内存和高级DMA引擎。凭借着出色的超低功耗性能,该芯片在智能手表上应用十分广泛。
2.特性
  • 通过ble和手机同步信息
  • 支持按键操作
  • 支持ble的特性
二 源码解析
1.启动并初始化手表相关的协议内容
void WatchStart(void)
{
  /* Register for stack callbacks */
  DmRegister(watchDmCback);
  DmConnRegister(DM_CLIENT_ID_APP, watchDmCback);
  AttRegister(watchAttCback);
  AttConnRegister(AppServerConnCback);
  AttsCccRegister(WATCH_NUM_CCC_IDX, (attsCccSet_t *) watchCccSet, watchCccCback);

  /* Register for app framework button callbacks */
  AppUiBtnRegister(watchBtnCback);

  /* Register for app framework discovery callbacks */
  AppDiscRegister(watchDiscCback);

  /* Initialize attribute server database */
  SvcCoreAddGroup();

  /* Reset the device */
  DmDevReset();
}

2. 处理手表的无线业务信息

void WatchHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
{
  if (pMsg != NULL)
  {
    APP_TRACE_INFO1("Watch got evt %d", pMsg->event);

    /* process ATT messages */
    if (pMsg->event <= ATT_CBACK_END)
    {
      /* process discovery-related ATT messages */
      AppDiscProcAttMsg((attEvt_t *) pMsg);

      /* process server-related ATT messages */
      AppServerProcAttMsg(pMsg);
    }
    /* process DM messages */
    else if (pMsg->event <= DM_CBACK_END)
    {
      if (pMsg->param == DM_CONN_ID_NONE || DmConnRole((dmConnId_t) pMsg->param) == DM_ROLE_MASTER)
      {
        /* process advertising and connection-related messages */
        AppMasterProcDmMsg((dmEvt_t *) pMsg);

        /* process security-related messages */
        AppMasterSecProcDmMsg((dmEvt_t *) pMsg);
      }

      if (pMsg->param == DM_CONN_ID_NONE || DmConnRole((dmConnId_t) pMsg->param) == DM_ROLE_SLAVE)
      {
        /* process advertising and connection-related messages */
        AppSlaveProcDmMsg((dmEvt_t *) pMsg);

        /* process security-related messages */
        AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
      }

      /* process discovery-related messages */
      AppDiscProcDmMsg((dmEvt_t *) pMsg);
    }

    /* perform profile and user interface-related operations */
    watchProcMsg((dmEvt_t *) pMsg);
  }
}

3.更新手表的业务信息

static void watchMasterValueUpdate(attEvt_t *pMsg)
{
  if (pMsg->hdr.status == ATT_SUCCESS)
  {
    /* determine which profile the handle belongs to; start with most likely */

    /* heart rate */
    if (HrpcHrsValueUpdate(pWatchHrsHdlList, pMsg) == ATT_SUCCESS)
    {
      return;
    }

    /* device information */
    if (DisValueUpdate(pWatchDisHdlList, pMsg) == ATT_SUCCESS)
    {
      return;
    }

    /* GATT */
    if (GattValueUpdate(pWatchMstGattHdlList, pMsg) == ATT_SUCCESS)
    {
      return;
    }
  }
}
三 总结备忘
1.还需要进一步的分析显示屏和协议部分。
2.ble的各种状态信息值得深入分析
posted on 2022-05-19 16:42  虚生  阅读(508)  评论(1编辑  收藏  举报