OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 34539|回复: 28

最近快要被51822搞疯了,分享我我对百度手环OTA的分析,顺带求助蓝牙发大量数据的方法!

[复制链接]

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
发表于 2015-5-15 21:01:00 | 显示全部楼层 |阅读模式
5金钱
<div style="font-family:'lucida Grande', Verdana, 'Microsoft YaHei';font-size:13.63636302948px;background-color:#FFFFFF;">
        <br />
<br />
最近快要被51822搞疯了,分享我我对百度手环OTA的分析,顺带求助蓝牙发大量数据的方法!<br />
本人第一次接触蓝牙,蓝牙协议基本上是不懂,最近在做51822需要发大量数据,发现数据有很多丢失。<br />
我先把数据全部拆成20字节,每次发两组10ms发一次,发现很多数据都丢失。<br />
<br />
<br />
以下是我对百度手环OTA的分析,直接从前段时间发的微信公众号上复制下来的大家别见怪。<br />
<br />
<br />
<br />
<br />
<br />
<img src="http://set2.mail.qq.com/cgi-bin/viewfile?f=0C561DD1CA22518F808D802F5C0925A96BA4E0B23B627A7CEBE0BF0343180A56D1BDFE4B668F6C0260842AB11989A33814B3AB564977E6CA0D3A6F129B034A3F4306E3EB0099EB286ACB6E3EBB05B258C100FD3ED1B83E8A9F0567587E81AFD0&amp;mailid=ZL2311-yV5j%7E1qQGOPLTkkc2Qpoe54&amp;sid=av3NiyrPCfKnCg1Y&amp;net=1535428106" /><br />
</div>
<div style="font-family:'lucida Grande', Verdana, 'Microsoft YaHei';font-size:13.63636302948px;background-color:#FFFFFF;">
        <br />
</div>
<div style="font-family:'lucida Grande', Verdana, 'Microsoft YaHei';font-size:13.63636302948px;background-color:#FFFFFF;">
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                话说上周末
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                约了5年的女神终于答应跟我去吃饭了
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                中午跟他去吃猪扒饭
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                我坐在对面静静的看着她吃饭的样子
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                甚可爱,就忍不住多看了几眼
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfLX3VRZTtibYmDzmEV0HZ9iaOXo32Gyialb71PkKicGs3201vThHL3EPJmPW19OK4SAMgYn13ibXkuKjZw/0" style="height:auto !important;" />
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                发现我偷看之后,她脸一红
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                说:你看什么呢?
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                突然间,我有点紧张,不知所措
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                说道:“没什么,你吃吧,我看猪扒饭呢”
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                她正在扒饭的手一顿。。。抬起头看着我
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                然后。。。。。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfLX3VRZTtibYmDzmEV0HZ9iaO3vxAgpXDc58JPzKuTU0mgiaDtKkqOBP2bdJYoZNrLcpia0OpOO1AUA7g/0" style="height:auto !important;" /><br />
好言归正传,
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                智能产品迅猛发展,今天我们就来揭秘百度手环。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfLX3VRZTtibYmDzmEV0HZ9iaO9YbuBU8BjxKkAAML6aLOlEiaFD1L1cFKUApYY1ysEu2anwpQLYMRJPA/0" style="height:auto !important;" />
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                我们先来看看百度手环的OTA。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                OTA是指空中升级,百度手环的OTA使用蓝牙通过APP把.bin文件发到手环进行固件升级。这样就可以对设备进行远程升级、维护了是不是很吊。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfLX3VRZTtibYmDzmEV0HZ9iaOGcIicIJibQibfz44XH6A7xoX46rnDJ3Ll6kC3Mhh2ceTNv52uvEW6Fbwg/0" style="height:auto !important;" /><br />
<span>51822</span>是百度手环采用的低功耗蓝牙,下面我们解读一下他的OTA。<br />
先看他的ROM组成。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfLX3VRZTtibYmDzmEV0HZ9iaOjuhkI75uaebE4FicZtJor4iawGAicicia8vPkKGfpU1mAe6X17t5LyV5LFg/0" style="height:auto !important;" /><br />
可以看出来,在Flash里烧了三个代码(常见单片机只烧一个)。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                他由BOOTLOADER<br />
APPLICATION<br />
SOFTDEVICE三部分代码组成,<br />
还有一部分是SWAP这部分是进行OTA时存放接收手机发过来的Bin文件的。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                SOFTDEVICE是官方提供的HEX,我们不能修改。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;color:#1F497D;">nRF<span>51822</span>程序加载顺序</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">1)SoftDevice加载;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">2)SoftDevice初始化蓝牙协议栈;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">3)SoftDevice检查0x<span>10001014</span>处是否保存有有效的BootLoader地址, 如果不是跳转到0x<span>14000</span>处的APP执行,流程结束.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">4)SoftDevice跳转到BootLoader</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">5)BootLoader进行他的业务处理工作;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">6)BootLoader跳转到0x<span>14000</span>处的APP执行,流程结束.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <br />
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;"><span style="color:#FF0000;">下面介绍百度手环的成个代码关于OTA的工作流程</span>。</span><br />
1:<span style="font-size:15.8620681762695px;">SoftDevice加载;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">2:</span><span style="font-size:15.8620681762695px;">SoftDevice初始化蓝牙协议栈;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">3:我们已经有&nbsp;</span><span style="font-size:15.8620681762695px;">Bootloader了所以他检查</span><span style="font-size:15.8620681762695px;">Bootloader是不是合理</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">代码: APP_ERROR_CHECK_BOOL(NRF_UICR-&gt;CLENR0 == CODE_REGION_1_START);//检测BOOTLOADER是否存在</span><span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                4:检查<span style="font-size:15.8620681762695px;">Bootloader标志位</span><span style="font-size:15.8620681762695px;">if (should_enter_bootloader || (wdt_reset &amp; 0x02))</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">if</span><span style="font-size:15.8620681762695px;">进入OTA模式&nbsp;</span><span style="font-size:15.8620681762695px;"></span><span style="font-size:15.8620681762695px;">err_code = bootloader_dfu_start();//进入OTA里面完成:蓝牙连接,BIN传到WSAP.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                等待完成进入。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                然后进入APP(<span style="color:#FF0000;">是否设置标志位都进入</span>)
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;//跳到</span><span style="font-size:15.8620681762695px;">DFU_BANK_0_REGION_START(0x<span>00014000</span>)</span><span style="font-size:15.8620681762695px;">&nbsp;</span><span style="font-size:15.8620681762695px;">application</span><span style="font-size:15.8620681762695px;">程序存放的首地址跳过去就不会往下运行了</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;bootloader_app_start(DFU_BANK_0_REGION_START);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                5:<span style="color:#FF0000;">进入APP后如果设置标志位,然后复位循环以上的。</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">注意:Bootloader和Application还有SoftDevice是三个独立的代码,</span><br />
<span style="font-size:16px;">其中SoftDevice是官方提供的HEX文件,(S110、S120或者S130等蓝牙协议)不可修改。</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">代码分析</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">这时Application工程中的触发OTA模式</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">/**********************************************************************</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">* User to reset the MCU &amp; enter OTA</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">***********************************************************************/</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">void trigger_ota_mode(void)</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">{</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">&nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">&nbsp; &nbsp;sd_power_gpregret_set(0x01);//设置一个保留的寄存器为0X01(作为启动OTA的标志)</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">&nbsp; &nbsp;//reset the system and start OTA</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">&nbsp; &nbsp;NVIC_SystemReset();//复位进入OTA</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:16px;">}</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <br />
然后再BOOTLOADER里判断标志位。
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">uint8_t should_enter_bootloader = &nbsp;NRF_POWER-&gt;GPREGRET &amp; 0xff;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;uint16_t wdt_reset = (NRF_POWER-&gt;RESETREAS) &amp; (0xFFFF);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;if (should_enter_bootloader || (wdt_reset &amp; 0x02))</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">满足进入OTA,不满足跳转<span style="font-size:16.3636360168457px;">Application。</span></span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="color:#FF0000;">简单的说就是:</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="color:#FF0000;">设置标志位》</span><span style="color:#FF0000;font-size:16px;">判断》</span><span style="color:#FF0000;font-size:16px;">进入》运行》跳转到APP。</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="color:#FF0000;font-size:16px;">下面是BOOTLOAER &nbsp; mian完整代码</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <br />
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">int main(void)</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">{</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;uint32_t err_code;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;wdt_stop(); //stop wdt whether it started or not &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;leds_init();</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;// This check ensures that the defined fields in the bootloader corresponds with actual</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;// setting in the nRF51 chip.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;APP_ERROR_CHECK_BOOL(NRF_UICR-&gt;CLENR0 == CODE_REGION_1_START);//检测BOOTLOADER是否存在</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;//检查BOOTLOADER的地址是不是0X03C800<br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;APP_ERROR_CHECK_BOOL(*((uint32_t *)NRF_UICR_BOOT_START_ADDRESS) == BOOTLOADER_REGION_START);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;APP_ERROR_CHECK_BOOL(NRF_FICR-&gt;CODEPAGESIZE == CODE_PAGE_SIZE);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;// Initialize.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;timers_init();</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;//进入 &nbsp;OTA的条件, application程序中</span><span style="font-size:15.8620681762695px;">&nbsp; sd_power_gpregret_set(0x01);就是设置这个</span><span style="font-size:15.8620681762695px;">&nbsp;</span><span style="font-size:15.8620681762695px;">NRF_POWER-&gt;GPREGRET</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;uint8_t should_enter_bootloader = &nbsp;NRF_POWER-&gt;GPREGRET &amp; 0xff;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;uint16_t wdt_reset = (NRF_POWER-&gt;RESETREAS) &amp; (0xFFFF);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;if (should_enter_bootloader || (wdt_reset &amp; 0x02))</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;{</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;nrf_gpio_pin_set(LED1);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;// Initiate an update of the firmware.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;err_code = bootloader_dfu_start();//进入OTA里面完成:蓝牙连接,BIN传到WSAP.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;APP_ERROR_CHECK(err_code);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;nrf_gpio_pin_clear(LED1);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;}</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;//exit from DFU unit so just Start application</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">//进入OTA条件不满足进入</span><span style="font-size:15.8620681762695px;">application</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;{</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;//set retain register</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;NRF_POWER-&gt;GPREGRET = 0x00;//清0</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;//clear AIRCR register</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;NRF_POWER-&gt;RESETREAS = 0x04;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;if(wdt_reset &amp; 0x02) {</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NRF_POWER-&gt;RESETREAS = 0x02;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;}</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;// Select a bank region to use as application region.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;// @note: Only applications running from DFU_BANK_0_REGION_START is supported.</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;</span><span style="font-size:15.8620681762695px;">//跳到</span><span style="font-size:15.8620681762695px;">DFU_BANK_0_REGION_START(0x<span>00014000</span>)</span><span style="font-size:15.8620681762695px;">&nbsp;</span><span style="font-size:15.8620681762695px;">application</span><span style="font-size:15.8620681762695px;">程序存放的首地址跳过去就不会往下运行了</span><span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;bootloader_app_start(DFU_BANK_0_REGION_START);</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp; &nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;}</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;leds_off();</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;//comes here should reenter DFU</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;//这里重新进入OTA应该是如果</span><span style="font-size:15.8620681762695px;">bootloader_app_start(DFU_BANK_0_REGION_START);失败</span><span style="font-size:15.8620681762695px;"><br />
</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;NRF_POWER-&gt;GPREGRET = 0x01;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">&nbsp; &nbsp;NVIC_SystemReset();//复位重新进入OTA因为</span><span style="font-size:15.8620681762695px;">NRF_POWER-&gt;GPREGRET = 0x01;</span>
        </p>
        <p style="font-family:sans-serif;font-size:16.3636360168457px;">
                <span style="font-size:15.8620681762695px;">}<br />
<br />
<br />
大家看完帮我看看上面的问题。。。。</span>
        </p>
</div>

简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-5-15 21:02:02 | 显示全部楼层
我是个蓝牙菜鸟,分析错的莫怪
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-5-15 21:27:24 | 显示全部楼层
百度手环代码及资料

duband-master.rar

25.92 MB, 下载次数: 14035

简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2015-5-15 22:29:52 | 显示全部楼层
大家都搞蓝牙了,哈哈....
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-5-17 13:46:48 | 显示全部楼层
回复【4楼】正点原子:
<br>---------------------------------
<br>这蓝牙性能还是有点不行啊
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-5-17 14:02:19 | 显示全部楼层
<span><span style="font-size:16.3636360168457px;line-height:normal;">帖子这么快就沉了,继续轰炸。<br />
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        星期天有个漂亮MM加了我微信
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXfmj6876jTLwOxbTwSASxu84nia6e4196BboqZGicLib8bbeCD6tibzfVpQ/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        一看我去师妹,最后还认识我
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        我却什么看也不认识不说了学美图秀秀去。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
<img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXmQQhsU9nxvyiaCkvYINfV0Bia3K7avuOJQibWpd7Zsp1QmxZH2G9aANVQ/0" style="height:auto !important;" /><br />
<img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXOJVwTPk5xgpSE89JiasAsxJzVHNGDoRJuE9D858eBtDvsiaHicH5JgTJA/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        前天在路上偶遇了以为大师
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        “大师有什么方法可以让我更帅一点呢”
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        “你家有电脑不?”
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        “大师我懂了,勤奋学习成为一个优秀的程序猿,以内补外”。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        “你丫有病吧,我让你回家P图去”。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXyA3TpfEdL2YUibq8rZicLnfbADvqYJHLwriazM9KHqm0rdosrrn9kMh7Q/0" style="height:auto !important;" /><br />
好了,我还是给大家解读下<span>51822</span>这个有魅力的蓝牙芯片吧。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        百度手环正是使用了这一芯片加一个加速度传感器和两个电机。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        我们来下他的官方提供的HRM(心率)代码。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        int main(void)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        uint32_t err_code;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        timers_init();//定时器初始化
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        gpiote_init();//led_init
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        buttons_init();//按键初始化
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_stack_init();//蓝牙协议初始化
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        bond_manager_init();//绑定
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Initialize Bluetooth Stack parameters
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        gap_params_init();
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        advertising_init();//广播初始化
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        services_init();//服务
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        conn_params_init();//连接
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        sec_params_init();//安全参数
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Start advertising
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        advertising_start();//开始广播
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Enter main loop
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        for (;;)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Switch to a low power state until an event is avai &nbsp; &nbsp; &nbsp; &nbsp;//lable for the application
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = sd_app_evt_wait();
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_ERROR_CHECK(err_code);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXv7Y3z46y86a5cnI9DR7agh3b1Piaeq4DicbhEic3I3LM4qA1LrufBicoLQ/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        初始化中有几个重要的函数
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void timers_init(void)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        uint32_t err_code;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Initialize timer module
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Create timers时间到之后电量处理
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = app_timer_create(&amp;m_battery_timer_id,
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; APP_TIMER_MODE_REPEATED,
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;battery_level_meas_timeout_handler);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_ERROR_CHECK(err_code);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        //时间到之后心率数据处理
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = app_timer_create(&amp;m_heart_rate_timer_id,
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; APP_TIMER_MODE_REPEATED,
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; heart_rate_meas_timeout_handler);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_ERROR_CHECK(err_code);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        我们进心率中断函数看看
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void heart_rate_meas_timeout_handler(void * p_context)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        uint32_t err_code;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        UNUSED_PARAMETER(p_context);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = ble_hrs_heart_rate_measurement_send(&amp;m_hrs, m_cur_heart_rate);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16px;"></span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        其实就是把心率数据发送到手机,那心率数据取得在那呢?不急往下
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void buttons_init(void)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16px;">&nbsp; &nbsp;static app_button_cfg_t buttons[] =</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {HR_INC_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler},
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {HR_DEC_BUTTON_PIN_NO, false, BUTTON_PULL, button_event_handler} &nbsp;// Note: This pin is also BONDMNGR_DELETE_BUTTON_PIN_NO
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        };
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXuAKv0TicbNXfx4ars7qOHadDAQxB1iaOGp2zPnsYwWK1qOct1qJDdabw/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        用中断的方式定义了两个按键,进中断函数
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void button_event_handler(uint8_t pin_no, uint8_t button_action)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        if (button_action == APP_BUTTON_PUSH)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        switch (pin_no)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; case HR_INC_BUTTON_PIN_NO:
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; // Increase Heart Rate measurement
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; m_cur_heart_rate += HEART_RATE_CHANGE;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; if (m_cur_heart_rate &gt; MAX_HEART_RATE)<span style="font-size:16px;">{</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_cur_heart_rate = MIN_HEART_RATE;<span style="font-size:16px;">&nbsp;}</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; break;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; case HR_DEC_BUTTON_PIN_NO:
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; m_cur_heart_rate -= HEART_RATE_CHANGE;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; if (m_cur_heart_rate &lt; MIN_HEART_RATE)<span style="font-size:16px;">{</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_cur_heart_rate = MAX_HEART_RATE;<span style="font-size:16px;">&nbsp;}</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; break;<span style="font-size:16px;"></span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; default:
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; APP_ERROR_HANDLER(pin_no);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        &nbsp; &nbsp; &nbsp; &nbsp; break;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        } &nbsp; &nbsp;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        哎哎,,<span style="font-size:16.3636360168457px;">&nbsp;m_cur_heart_rate这不是要发送的数据吗,原来是用按键模拟心率啊。有点明朗了继续</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void ble_stack_init(void)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        uint32_t err_code;
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        // Initialize the SoftDevice handler module.
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16px;">// Register with the SoftDevice handler module for BLE events</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_ERROR_CHECK(err_code);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        APP_ERROR_CHECK(err_code);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        还不知干啥的没关系进<span style="font-size:16.3636360168457px;">ble_evt_dispatch</span>去看看
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        {
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_bondmngr_on_ble_evt(p_ble_evt);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_hrs_on_ble_evt(&amp;m_hrs, p_ble_evt);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_bas_on_ble_evt(&amp;bas, p_ble_evt);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_conn_params_on_ble_evt(p_ble_evt);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        on_ble_evt(p_ble_evt);
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        }
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXt6icq8ziaicFoArPys3VxEsjt8dsmHRsgFGEJZ8KbQkIRRHYVoxOU5AnA/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        这些应该都是中断时蓝牙的一下处理
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        重点看看<span style="font-size:16.3636360168457px;">on_ble_evt(p_ble_evt);</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXYHJP6icWAiaeOOyI7m8qBJ2QyxzL8eo4QrYLU2dPuYY37hYUhgia2bibuw/0" style="height:auto !important;" /><br />
nrf_gpio_cfg_sense_input配置唤醒引脚。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">可以看出来这是做蓝牙连接、断开等中断的处理。</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">蓝牙连接时启动定时器,时能按键,初始化心率值。</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">蓝牙超时进行休眠等等。</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">接着往下</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">services_init();//服务</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16.3636360168457px;">这个就不进去看了,主要工作是给蓝牙添加服务,比如心率、电量等</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        我们要自己添加服务的时候模仿里面的添加一个就行了。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        gap_params_init里面的
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        sd_ble_gap_appearance_set(BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT);需要说一下这个是设置外观值,手机APP可以根据这个外观值知道是哪个蓝牙。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <img src="https://mmbiz.qlogo.cn/mmbiz/4Eu1j9dibXfJvjHa0nK3Kzc9iaOROpsBoXstDw2jOuIJwd5fdibwbjX2zaQG2R0Q9AeaLKricnQoiaKzPicM0dLLZ7hw/0" style="height:auto !important;" />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        好了,看起来有点复杂。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="color:#FF0000;">总结一下我们要用重要的步奏</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <span style="font-size:16px;">buttons_init();//按键初始化在中断里面体现动作</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        timers_init();//定时器初始化<span style="font-size:16.3636360168457px;">在中断里面体现动作</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        ble_stack_init();//蓝牙协议初始化在里面添加<span style="font-size:16.3636360168457px;">ble_hrs_on_ble_evt(&amp;m_hrs, p_ble_evt);在</span><span style="font-size:16.3636360168457px;">on_ble_evt(p_ble_evt);</span><span style="font-size:16.3636360168457px;">做定时器启动,休眠,亮灯等,</span>
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        services_init();//添加服务。
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
<p style="font-family:sans-serif;font-size:16.3636360168457px;background-color:#FFFFFF;">
        <br />
</p>
</span></span>
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2015-5-17 23:23:09 | 显示全部楼层
回复【6楼】LTKKS:
<br>---------------------------------
<br>不错啊,可以约炮了。。。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-5-18 19:36:38 | 显示全部楼层
回复【7楼】正点原子:
<br>---------------------------------
<br>我是个好男人,这是好多妹子的评价
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2015-5-19 00:35:33 | 显示全部楼层
回复【8楼】LTKKS:
<br>---------------------------------
<br>约完以后评价?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

0

主题

1

帖子

0

精华

新手入门

积分
21
金钱
21
注册时间
2015-8-31
在线时间
0 小时
发表于 2015-8-31 22:47:10 | 显示全部楼层
如果要烧录,可以找我,我们是专业IC代烧录的
回复

使用道具 举报

34

主题

322

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1835
金钱
1835
注册时间
2014-12-4
在线时间
717 小时
发表于 2015-9-3 18:23:06 | 显示全部楼层
楼主有没有透传的??拿来讲一讲。最近看的头都大了。。。
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-9-4 23:54:33 | 显示全部楼层
回复【11楼】loudianxin:
<br>---------------------------------
<br>有是有但是不想讲了,最近我们研发部跟平面设计干上了心累。
<br>给你一份网上找的!见楼下
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-9-4 23:59:03 | 显示全部楼层
<p class="MsoNormal">
        <a href="http://gg.eefocus.com/www/delivery/ck.php?oaparams=2__bannerid=4595__zoneid=380__cb=70145fc168__oadest=http%3A%2F%2Furl.eefocus.com%2Fsq" target="_blank"></a>
</p>
<p class="MsoNormal">
        以下内容来自网络,如有侵权请及时联系删除!
</p>
<p class="MsoNormal">
        <a href="http://gg.eefocus.com/www/delivery/ck.php?oaparams=2__bannerid=4595__zoneid=380__cb=70145fc168__oadest=http%3A%2F%2Furl.eefocus.com%2Fsq" target="_blank">仅供学习,<br />
花了一个早上写的。板子是pca10001<br />
<img border="0" width="32" height="32" src="file://C:/Users/SLHuang/AppData/Local/Temp/msohtml1/01/clip_image003.gif" /><span class="apple-converted-space">&nbsp;</span></a><a href="http://www.eeboard.com/bbs/forum.php?mod=attachment&amp;aid=OTAzMDh8ZTY4ZTAzMTh8MTQzMDU3Mzk3MXw5NDAzNHwzOTUxMg%3D%3D" target="_blank">nrf51822.part02.rar</a><span class="apple-converted-space">&nbsp;</span><em>(4.07
MB, </em><em>下载次数</em><em>: 372)</em><span class="apple-converted-space">&nbsp;</span><img border="0" width="32" height="32" src="file://C:/Users/SLHuang/AppData/Local/Temp/msohtml1/01/clip_image003.gif" /><a href="http://www.eeboard.com/bbs/forum.php?mod=attachment&amp;aid=OTAzMDd8OTUwMWFiMjh8MTQzMDU3Mzk3MXw5NDAzNHwzOTUxMg%3D%3D" target="_blank">nrf51822.part01.rar</a><span class="apple-converted-space">&nbsp;</span><em>(7
MB, </em><em>下载次数</em><em>: 516)</em><span class="apple-converted-space">&nbsp;</span><img border="0" width="32" height="32" src="file://C:/Users/SLHuang/AppData/Local/Temp/msohtml1/01/clip_image003.gif" /><a href="http://www.eeboard.com/bbs/forum.php?mod=attachment&amp;aid=OTAzMDZ8NjcwMjc2Nzd8MTQzMDU3Mzk3MXw5NDAzNHwzOTUxMg%3D%3D" target="_blank">NRF51822 SD_HEX.rar</a><span class="apple-converted-space">&nbsp;</span><em>(535.87
KB, </em><em>下载次数</em><em>: 138)</em><span class="apple-converted-space">&nbsp;</span><br />
工程文件nrf51822\Board\nrf6310\s120\experimental\ble_app_uart_c\arm<br />
配套的uart的串口从机是nrf51822\Board\pca10001\s110\experimental\ble_app_uart<br />
<br />
1、首先添加16位的uuid号,重新宏定义如下<br />
<img border="0" width="600" height="22" src="file://C:/Users/SLHuang/AppData/Local/Temp/msohtml1/01/clip_image005.jpg" /><br />
<br />
<strong></strong>
</p>
<p class="MsoNormal">
        <b>点击</b><b>(</b><b>此处</b><b>)</b><b>折叠或打开</b>
</p>
<p class="MsoNormal">
        <br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_UUID_NUS_SERVICE&nbsp; &nbsp;&nbsp;&nbsp;0x0001 /**&lt; The UUID of the
Nordic UART Service. */
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_UUID_NUS_TX_C_CHARACTERISTIC 0x0003 /**&lt;<span class="apple-converted-space">&nbsp;</span>主机的TX 特性 对应于从机的RX特性*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_UUID_NUS_RX_C_CHARACTERISTIC 0x0002 /**&lt;<span class="apple-converted-space">&nbsp;</span>主机的RX 特性.<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_NUS_MAX_DATA_LEN<span class="apple-converted-space">&nbsp;</span>(GATT_MTU_SIZE_DEFAULT<span class="apple-converted-space">&nbsp;</span>-<span class="apple-converted-space">&nbsp;</span>3)<span class="apple-converted-space">&nbsp;</span>/**&lt;<span class="apple-converted-space">&nbsp;</span>最大20字节Maximum<span class="apple-converted-space">&nbsp;</span>length<span class="apple-converted-space">&nbsp;</span>of<span class="apple-converted-space">&nbsp;</span>data<span class="apple-converted-space">&nbsp;</span>(in<span class="apple-converted-space">&nbsp;</span>bytes)<span class="apple-converted-space">&nbsp;</span>that can be transmitted by the Nordic
UART service module to the peer.<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_NUS_MAX_RX_CHAR_LEN BLE_NUS_MAX_DATA_LEN /**&lt;<span class="apple-converted-space">&nbsp;</span>等价于接收长度Maximum<span class="apple-converted-space">&nbsp;</span>length<span class="apple-converted-space">&nbsp;</span>of<span class="apple-converted-space">&nbsp;</span>the
RX Characteristic(in<span class="apple-converted-space">&nbsp;</span>bytes).<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#define
BLE_NUS_MAX_TX_CHAR_LEN BLE_NUS_MAX_DATA_LEN /**&lt;<span class="apple-converted-space">&nbsp;</span>Maximum<span class="apple-converted-space">&nbsp;</span>length<span class="apple-converted-space">&nbsp;</span>of<span class="apple-converted-space">&nbsp;</span>the
TX Characteristic<span class="apple-converted-space">&nbsp;</span>(in<span class="apple-converted-space">&nbsp;</span>bytes).<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal">
        <br />
<br />
蓝牙ble是基于属性协议的<br />
属性协议:客户端通过它可以发现并获取属**器上的属性:6种基本操作<br />
1、请求:客户端发给请求给服务器,需要服务器回复一个响应<br />
2、响应:<br />
3、命令:客户端发给请求给服务器,不需要服务器回复一个响应<br />
4、指示:服务器发给指示给客户端,需要客户端发一个确认给服务器<br />
5、确认:<br />
6、通知:客户端发给请求给服务器,不需要服务器回复一个响应<br />
例子用到了请求,通知。<br />
写入请求包含:一个句柄和一个该属性的值,什么是句柄?首先服务器运行属性数据库(跟数组差不多),里面包含了很多属性,每一个属性都有一个句柄(跟内存地址差不多,随机分配)。<br />
通知:一个句柄和一个该属性的值,客户端在连接建立的时候需要对特性的描述符进行写操作,允许服务器发送通知。<br />
主函数
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int main(void)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
// Initialization<span class="apple-converted-space">&nbsp;</span>of<span class="apple-converted-space">&nbsp;</span>various modules.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
//初始化调试模块:用串口输出信息
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;app_trace_init();
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;NRF_UART0-&gt;INTENSET<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>UART_INTENSET_RXDRDY_Enabled<span class="apple-converted-space">&nbsp;</span>&lt;&lt;<span class="apple-converted-space">&nbsp;</span>UART_INTENSET_RXDRDY_Pos;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
NVIC_SetPriority(UART0_IRQn,<span class="apple-converted-space">&nbsp;</span>APP_IRQ_PRIORITY_LOW);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
NVIC_EnableIRQ(UART0_IRQn);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; app_trace_log("init\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; leds_init();//led初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; buttons_init();//按键初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; ble_stack_init();//蓝牙协议栈初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; device_manager_init();//从设备管理模块初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; db_discovery_init();/发现模块初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//串口服务客户端初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; nus_c_init();
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; // Start scanning<span class="apple-converted-space">&nbsp;</span>for<span class="apple-converted-space">&nbsp;</span>peripherals<span class="apple-converted-space">&nbsp;</span>and<span class="apple-converted-space">&nbsp;</span>initiate
connection
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; // with devices that advertise Heart Rate
UUID.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; scan_start();/开始扫描
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; app_trace_log("start\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>for<span class="apple-converted-space">&nbsp;</span>(;;)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;power_manage();//等待事件发生
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
主要分析nus_c_init();<br />
<br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*<span class="apple-converted-space">&nbsp;</span>@brief 初始化串口服务的客户端
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
nus_c_init(void)<br />
{<br />
&nbsp; &nbsp; ble_nus_c_init_t nus_c_init_obj;<br />
//注册一个回调函数,这个函数是在main文件实现的,主要实现1、发现服务的处理,2、通知事件的处理,<br />
&nbsp; &nbsp; nus_c_init_obj.evt_handler = nus_c_evt_handler;<br />
<br />
&nbsp; &nbsp; uint32_t err_code = ble_nus_c_init(&amp;m_ble_nus_c,
&amp;nus_c_init_obj);<br />
&nbsp; &nbsp; APP_ERROR_CHECK(err_code);<br />
}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal">
        <br />
<br />
接下来看一下nus_c_evt_handler,里面主要处理的就是两个宏定义,<br />
<b><br />
</b>
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/**@brief
ble_nus_c_evt_type_t Handler.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
nus_c_evt_handler(ble_nus_c_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_nus_c,<span class="apple-converted-space">&nbsp;</span>ble_nus_c_evt_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_nus_c_evt)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
bool success;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
switch<span class="apple-converted-space">&nbsp;</span>(p_nus_c_evt-&gt;evt_type)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;APPL_LOG("[APP]: 发现了从机,进行绑定,及允许服务器发送通知\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//发现了串口的从机,进行绑定
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//
Initiate bonding.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>dm_security_setup_req(&amp;m_dm_device_handle);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;APP_ERROR_CHECK(err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//使能从机发送通知事件
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>ble_nus_c_tx_notif_enable(p_nus_c);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;APP_ERROR_CHECK(err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case
BLE_NUS_C_EVT_TX_NOTIFICATION:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;char
hr_as_string[LCD_LLEN;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//接收到了通知事件,直接打印下来
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;APPL_LOG("[APP]: receive=%s.\r\n",<span class="apple-converted-space">&nbsp;</span>p_nus_c_evt-&gt;params.tx.tx_value);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;default:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
ble_nus_c_init函数主要是添加了一个自定义的uuid基数,并把服务的16位uuid号的回调函数注册到了发现模块,当系统运行扫描后,当发现模块发现这个uuid后,会调用这个回调函数<br />
<b><br />
<br />
</b>
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*<span class="apple-converted-space">&nbsp;</span>@brief s120 串口初始化
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
uint32_t
ble_nus_c_init(ble_nus_c_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>ble_nus_c_init_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c_init){
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>((p_ble_nus_c<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NULL)<span class="apple-converted-space">&nbsp;</span>||<span class="apple-converted-space">&nbsp;</span>(p_ble_nus_c_init<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NULL))
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return
NRF_ERROR_NULL;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//增加一个自定义的蓝牙uuid基数,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; ble_uuid128_t nus_base_uuid<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>{0x9E,<span class="apple-converted-space">&nbsp;</span>0xCA,<span class="apple-converted-space">&nbsp;</span>0xDC,<span class="apple-converted-space">&nbsp;</span>0x24,<span class="apple-converted-space">&nbsp;</span>0x0E,<span class="apple-converted-space">&nbsp;</span>0xE5,<span class="apple-converted-space">&nbsp;</span>0xA9,<span class="apple-converted-space">&nbsp;</span>0xE0,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 0x93,<span class="apple-converted-space">&nbsp;</span>0xF3,<span class="apple-converted-space">&nbsp;</span>0xA3,<span class="apple-converted-space">&nbsp;</span>0xB5,<span class="apple-converted-space">&nbsp;</span>0x00,<span class="apple-converted-space">&nbsp;</span>0x00,<span class="apple-converted-space">&nbsp;</span>0x40,<span class="apple-converted-space">&nbsp;</span>0x6E};
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mp_ble_nus_c<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>sd_ble_uuid_vs_add(&amp;nus_base_uuid,<span class="apple-converted-space">&nbsp;</span>&amp;mp_ble_nus_c-&gt;nus_uuid.type);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>!=<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//设置服务的16位uuid,配合前面加的蓝牙uuid基数,组成一组完整128位的uuid号
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; mp_ble_nus_c-&gt;nus_uuid.uuid<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_UUID_NUS_SERVICE;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; mp_ble_nus_c-&gt;evt_handler<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c_init-&gt;evt_handler;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//设置服务连接句柄为:无效
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; mp_ble_nus_c-&gt;conn_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_CONN_HANDLE_INVALID;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//设置特性的句柄为无效
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;mp_ble_nus_c-&gt;nus_rx_handle&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;=<span class="apple-converted-space">&nbsp;</span>BLE_GATT_HANDLE_INVALID;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        32.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;mp_ble_nus_c-&gt;nus_tx_handle&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;=<span class="apple-converted-space">&nbsp;</span>BLE_GATT_HANDLE_INVALID;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        33.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//设置接收的描述符句柄为:无效
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        34.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; mp_ble_nus_c-&gt;nus_rx_cccd_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_GATT_HANDLE_INVALID;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        35.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;mp_ble_nus_c-&gt;nus_tx_cccd_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_GATT_HANDLE_INVALID;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        36.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//注册服务的uuid,及其回调函数,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        37.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//当发现模块发送有该uuid,就会调用db_discover_evt_handler
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        38.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; return
ble_db_discovery_register(&amp;mp_ble_nus_c-&gt;nus_uuid,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        39.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; db_discover_evt_handler);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        40.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
<br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//当这个服务 的uuid号被发现,那么这个函数就被调用
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
db_discover_evt_handler(ble_db_discovery_evt_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_evt)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
//检查uuid号和类型是不是一致
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(p_evt-&gt;evt_type<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>BLE_DB_DISCOVERY_COMPLETE
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&amp;&amp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.srv_uuid.uuid<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>mp_ble_nus_c-&gt;nus_uuid.uuid
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&amp;&amp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.srv_uuid.type<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>mp_ble_nus_c-&gt;nus_uuid.type)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//获取属性句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;LOG("[NUS_C]: 服务被发现,获得了连接句柄\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;mp_ble_nus_c-&gt;conn_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_evt-&gt;conn_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// Find the CCCD
Handle<span class="apple-converted-space">&nbsp;</span>of<span class="apple-converted-space">&nbsp;</span>the Heart Rate Measurement
characteristic.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;uint8_t i;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;for<span class="apple-converted-space">&nbsp;</span>(i<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>0;<span class="apple-converted-space">&nbsp;</span>i<span class="apple-converted-space">&nbsp;</span>&lt;<span class="apple-converted-space">&nbsp;</span>p_evt-&gt;params.discovered_db.char_count;<span class="apple-converted-space">&nbsp;</span>i++)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//检查特性的uuid号是不是一致
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if<span class="apple-converted-space">&nbsp;</span>(p_evt-&gt;params.discovered_db.charateristics[i.characteristic.uuid.uuid
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>==
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; BLE_UUID_NUS_RX_C_CHARACTERISTIC)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; // characteristic.<span class="apple-converted-space">&nbsp;</span>Store
CCCD handle<span class="apple-converted-space">&nbsp;</span>and<span class="apple-converted-space">&nbsp;</span>break.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //rx的描述符句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; mp_ble_nus_c-&gt;nus_rx_cccd_handle<span class="apple-converted-space">&nbsp;</span>=
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.charateristics[i.cccd_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //rx的句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; mp_ble_nus_c-&gt;nus_rx_handle<span class="apple-converted-space">&nbsp;</span>=
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        32.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.charateristics[i.characteristic.handle_value;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        33.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;LOG("[NUS_C]: RX 特性被发现,nus_rx_cccd_handle = %d&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;nus_rx_handle
=%d\r\n",mp_ble_nus_c-&gt;nus_rx_cccd_handle,mp_ble_nus_c-&gt;nus_rx_handle);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        34.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        35.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<span class="apple-converted-space">&nbsp;</span>else<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(p_evt-&gt;params.discovered_db.charateristics[i.characteristic.uuid.uuid
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        36.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>==
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        37.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; BLE_UUID_NUS_TX_C_CHARACTERISTIC)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        38.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        39.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        40.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; // Found Heart Rate characteristic.<span class="apple-converted-space">&nbsp;</span>Store CCCD handle<span class="apple-converted-space">&nbsp;</span>and<span class="apple-converted-space">&nbsp;</span>break.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        41.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; mp_ble_nus_c-&gt;nus_tx_cccd_handle<span class="apple-converted-space">&nbsp;</span>=
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        42.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.charateristics[i.cccd_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        43.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; mp_ble_nus_c-&gt;nus_tx_handle<span class="apple-converted-space">&nbsp;</span>=
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        44.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;p_evt-&gt;params.discovered_db.charateristics[i.characteristic.handle_value;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        45.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; LOG("[NUS_C]:
TX 特性被发现,nus_tx_cccd_handle = %d&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;nus_tx_handle
=%d\r\n",mp_ble_nus_c-&gt;nus_tx_cccd_handle,mp_ble_nus_c-&gt;nus_tx_handle);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        46.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<span class="apple-converted-space">&nbsp;</span>else<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        47.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
LOG("[NUS_C]:有其他的特性\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        48.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        49.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        50.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        51.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        52.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        53.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ble_nus_c_evt_t
evt;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        54.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        55.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;evt.evt_type<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_NUS_C_EVT_DISCOVERY_COMPLETE;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        56.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; //运行main文件注册的回调函数,nus_c_evt_handler
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        57.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;mp_ble_nus_c-&gt;evt_handler(mp_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>&amp;evt);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        58.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        59.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
<br />
上面就是初始化做的所有事,接下来分析事件,每发生一个事件都会调用其回调函数,<br />
看一下蓝牙协议栈初始化,主要有ble_evt_dispatch,sys_evt_dispatch两个回调函数,主要讲解ble_evt_dispatch<br />
<br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
ble_stack_init(void)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
// Initialize the SoftDevice handler module.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,<span class="apple-converted-space">&nbsp;</span>false);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
// Register with the SoftDevice handler module<span class="apple-converted-space">&nbsp;</span>for<span class="apple-converted-space">&nbsp;</span>BLE
events.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>softdevice_ble_evt_handler_set(ble_evt_dispatch);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; APP_ERROR_CHECK(err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; // Register with the SoftDevice handler
module<span class="apple-converted-space">&nbsp;</span>for<span class="apple-converted-space">&nbsp;</span>System events.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>softdevice_sys_evt_handler_set(sys_evt_dispatch);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; APP_ERROR_CHECK(err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
ble_evt_dispatch:把事件分派给各个模块处理,自己主要需要编写的ble_nus_c_on_ble_evt,及on_ble_evt<br />
<b><br />
<br />
</b>
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
ble_evt_dispatch(ble_evt_t * p_ble_evt)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
app_trace_log("evt_id = %x\r\n",p_ble_evt-&gt;header.evt_id);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
dm_ble_evt_handler(p_ble_evt);//管理模块的处理
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
ble_db_discovery_on_ble_evt(&amp;m_ble_db_discovery,<span class="apple-converted-space">&nbsp;</span>p_ble_evt);//发现模块的处理
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
ble_nus_c_on_ble_evt(&amp;m_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>p_ble_evt);//nus的处理
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
on_ble_evt(p_ble_evt);//main的处理:广播包处理-&gt;进行连接
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}
</p>
<p class="MsoNormal">
        <br />
<br />
<br />
看一下main函数中的on_ble_evt,<br />
<b><br />
</b>
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
/**@brief
Function for handling the Application's BLE Stack events.这里主要处理的广播包
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*<span class="apple-converted-space">&nbsp;</span>@param[in<span class="apple-converted-space">&nbsp;</span>p_ble_evt Bluetooth stack event.,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
on_ble_evt(ble_evt_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_ble_evt)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
ble_uuid_t peer_uuid;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>const<span class="apple-converted-space">&nbsp;</span>ble_gap_evt_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_gap_evt<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>&amp;p_ble_evt-&gt;evt.gap_evt;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; app_trace_log("on_ble_evt\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; switch<span class="apple-converted-space">&nbsp;</span>(p_ble_evt-&gt;header.evt_id)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>//发现了一个广播包
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case<span class="apple-converted-space">&nbsp;</span>BLE_GAP_EVT_ADV_REPORT:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;data_t adv_data;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;data_t type_data;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//<span class="apple-converted-space">&nbsp;</span>Initialize advertisement report<span class="apple-converted-space">&nbsp;</span>for<span class="apple-converted-space">&nbsp;</span>parsing.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//首先是要从广播包解析出数据
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;adv_data.p_data<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>(uint8_t<span class="apple-converted-space">&nbsp;</span>*)p_gap_evt-&gt;params.adv_report.data;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;adv_data.data_len<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_gap_evt-&gt;params.adv_report.dlen;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//获得完整的128bit,uuid号
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>adv_report_parse(BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>&amp;adv_data,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>&amp;type_data);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//<span class="apple-converted-space">&nbsp;</span>Verify<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>short<span class="apple-converted-space">&nbsp;</span>or<span class="apple-converted-space">&nbsp;</span>complete
name matches target.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;{&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//对uuid进行换算:128bit换算成一个16bit及其类型,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>sd_ble_uuid_decode(type_data.data_len,type_data.p_data,&amp;peer_uuid);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        32.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        33.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if<span class="apple-converted-space">&nbsp;</span>((peer_uuid.uuid<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>m_ble_nus_c.nus_uuid.uuid<span class="apple-converted-space">&nbsp;</span>)&amp;&amp;peer_uuid.type<span class="apple-converted-space">&nbsp;</span>==m_ble_nus_c.nus_uuid.type<span class="apple-converted-space">&nbsp;</span>)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        34.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//发现了从机的,停止广播并尝试连接
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        35.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>sd_ble_gap_scan_stop();
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        36.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>!=<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        37.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
APPL_LOG("[APPL]: Scan stop failed, reason %d\r\n",<span class="apple-converted-space">&nbsp;</span>err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        38.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        39.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;nrf_gpio_pin_clear(SCAN_LED_PIN_NO);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        40.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>sd_ble_gap_connect(&amp;p_gap_evt-&gt;params.adv_report.\
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        41.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;peer_addr,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        42.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&amp;m_scan_param,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        43.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&amp;m_connection_param);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        44.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        45.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>!=<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        46.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        47.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;APPL_LOG("[APPL]: Connection Request Failed, reason %d\r\n",<span class="apple-converted-space">&nbsp;</span>err_code);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        48.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<span class="apple-converted-space">&nbsp;</span>else<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        49.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
APPL_LOG("连接建立\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        50.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        51.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        52.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        53.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}else<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        54.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;APPL_LOG("匹配出错\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        55.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        56.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        57.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        58.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        59.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        60.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        61.&nbsp;&nbsp;&nbsp;&nbsp; 以下省略,直接拷贝官方的处理方式
</p>
<p class="MsoNormal">
        <br />
<br />
<br />
看一下nus模块的处理<br />
<br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
void
ble_nus_c_on_ble_evt(ble_nus_c_t * p_ble_nus_c, const ble_evt_t * p_ble_evt) {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
ble_uuid_t server_uuid;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>((p_ble_nus_c<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NULL)||(p_ble_evt<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NULL))<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return<span class="apple-converted-space">&nbsp;</span>;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
switch<span class="apple-converted-space">&nbsp;</span>(p_ble_evt-&gt;header.evt_id)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case
BLE_GAP_EVT_CONNECTED:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//连接完成,获取连接句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;p_ble_nus_c-&gt;conn_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_evt-&gt;evt.gap_evt.conn_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("[NUS_C]:BLE_GAP_EVT_CONNECTED ,conn_handle =
%d\r\n",p_ble_nus_c-&gt;conn_handle);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case
BLE_GATTC_EVT_HVX:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//通知事件
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("[NUS_C]:BLE_GATTC_EVT_HVX\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;on_hvx(p_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>p_ble_evt);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;case
BLE_GATTC_EVT_WRITE_RSP:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("[NUS_C]:BLE_GATTC_EVT_WRITE_RSP\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//客户端发送写请求给服务器,服务器会回一个应答信号给客户端。这时客户端可以发送下一条写请求给服务器端。
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//属性协议规定:写请求需要在前一条请求接收到应答后才能继续
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//添加的原因:猜测:发送写请求是通过一个队列的,如果发送失败,那么就会有一个未发送的在队列里,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//如果这时在发送一个写请求,那么发送将会是前一条写请求,而后收到应答后会继续发送写请求,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
on_write_rsp(p_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>p_ble_evt);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        32.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;default:
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        33.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;break;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        34.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        35.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
通知事件处理:<br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//通知事件的处理方式
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
static void
on_hvx(ble_nus_c_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>const ble_evt_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_ble_evt)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
// Check<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>this<span class="apple-converted-space">&nbsp;</span>is
a heart rate notification.
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
//检查是不是tx的句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(p_ble_evt-&gt;evt.gattc_evt.params.hvx.handle<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c-&gt;nus_tx_handle)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;ble_nus_c_evt_t ble_nus_c_evt;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;uint8_t index<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>0;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//设置成BLE_NUS_C_EVT_TX_NOTIFICATION
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;ble_nus_c_evt.evt_type<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_NUS_C_EVT_TX_NOTIFICATION;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;strncpy(ble_nus_c_evt.params.tx.tx_value,p_ble_evt-&gt;evt.gattc_evt.params.hvx.data,p_ble_evt-&gt;evt.gattc_evt.params.hvx.len);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;ble_nus_c_evt.params.tx.tx_len<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_evt-&gt;evt.gattc_evt.params.hvx.len;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; //调用main函数注册的回调函数nus_c_evt_handler
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;p_ble_nus_c-&gt;evt_handler(p_ble_nus_c,<span class="apple-converted-space">&nbsp;</span>&amp;ble_nus_c_evt);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
对于写应答,主要是继续发送下一条请求(如果有的话),<br />
<br />
<br />
接下来讲解一下客户端怎么发送数据到服务器,<br />
串口中断程序<br />
<br />
<br />
<strong></strong>
</p>
<p class="MsoNormal">
        <b>点击</b><b>(</b><b>此处</b><b>)</b><b>折叠或打开</b>
</p>
<p class="MsoNormal">
        <br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
void
UART0_IRQHandler(void)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
static uint8_t index<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>0;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
/**@snippet<span class="apple-converted-space">&nbsp;</span>[Handling the data
received over UART<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
data_array[index<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>simple_uart_get();
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; index++;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>((data_array[index<span class="apple-converted-space">&nbsp;</span>-<span class="apple-converted-space">&nbsp;</span>1<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>'\n')<span class="apple-converted-space">&nbsp;</span>||<span class="apple-converted-space">&nbsp;</span>(index<span class="apple-converted-space">&nbsp;</span>&gt;=<span class="apple-converted-space">&nbsp;</span>(BLE_NUS_MAX_DATA_LEN<span class="apple-converted-space">&nbsp;</span>-<span class="apple-converted-space">&nbsp;</span>1)))
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; //发送数据到服务器
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;tx_send(&amp;m_ble_nus_c,data_array,index);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;index<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>0;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; /**@snippet<span class="apple-converted-space">&nbsp;</span>[Handling the data received over UART<span class="apple-converted-space">&nbsp;</span>*/
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <br />
<br />
<br />
<br />
<br />
<strong></strong>
</p>
<p class="MsoNormal">
        <b>点击</b><b>(</b><b>此处</b><b>)</b><b>折叠或打开</b>
</p>
<p class="MsoNormal">
        <br />
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
void
tx_send(ble_nus_c_t * p_ble_nus_c,char *str ,unsigned char len){
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
tx_message_t<span class="apple-converted-space">&nbsp;</span>*<span class="apple-converted-space">&nbsp;</span>p_msg;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        4.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(len<span class="apple-converted-space">&nbsp;</span>&gt;<span class="apple-converted-space">&nbsp;</span>WRITE_MESSAGE_LENGTH)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        5.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return<span class="apple-converted-space">&nbsp;</span>;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        6.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        7.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        8.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//发送队列
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        9.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;
p_msg<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>&amp;m_tx_buffer[m_tx_insert_index++;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        10.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; m_tx_insert_index &amp;=<span class="apple-converted-space">&nbsp;</span>TX_BUFFER_MASK;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        11.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; strncpy(<span class="apple-converted-space">&nbsp;</span>p_msg-&gt;req.write_req.gattc_value,str,len);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        12.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//属性句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        13.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; p_msg-&gt;req.write_req.gattc_params.handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c-&gt;nus_rx_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        14.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//数据长度
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        15.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; p_msg-&gt;req.write_req.gattc_params.len<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>len;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        16.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//数据
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        17.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;
p_msg-&gt;req.write_req.gattc_params.p_value<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_msg-&gt;req.write_req.gattc_value;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        18.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; p_msg-&gt;req.write_req.gattc_params.offset<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>0;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        19.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//写请求
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        20.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;
p_msg-&gt;req.write_req.gattc_params.write_op<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>BLE_GATT_OP_WRITE_REQ;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        21.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//连接句柄
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        22.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; p_msg-&gt;conn_handle<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>p_ble_nus_c-&gt;conn_handle;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        23.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//不是协议的东西
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        24.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; p_msg-&gt;type<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>WRITE_REQ;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        25.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; //发送过程
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        26.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; tx_buffer_process();
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        27.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        28.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        29.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        30.&nbsp;&nbsp;&nbsp;&nbsp; /*
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        31.&nbsp;&nbsp;&nbsp;&nbsp; *@<span class="apple-converted-space">&nbsp;</span>brief 发送数据
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        32.&nbsp;&nbsp;&nbsp;&nbsp; */
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        33.&nbsp;&nbsp;&nbsp;&nbsp; static void tx_buffer_process(void)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        34.&nbsp;&nbsp;&nbsp;&nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        35.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>if<span class="apple-converted-space">&nbsp;</span>(m_tx_index<span class="apple-converted-space">&nbsp;</span>!=<span class="apple-converted-space">&nbsp;</span>m_tx_insert_index)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        36.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; {
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        37.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;uint32_t err_code;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        38.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//本例子中只有写请求
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        39.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if<span class="apple-converted-space">&nbsp;</span>(m_tx_buffer[m_tx_index.type<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>WRITE_REQ)<span class="apple-converted-space">&nbsp;</span>{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        40.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("enter the write \r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        41.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;err_code<span class="apple-converted-space">&nbsp;</span>=<span class="apple-converted-space">&nbsp;</span>sd_ble_gattc_write(m_tx_buffer[m_tx_index.conn_handle,
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        42.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&amp;m_tx_buffer[m_tx_index.req.write_req.gattc_params);
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        43.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        44.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if<span class="apple-converted-space">&nbsp;</span>(err_code<span class="apple-converted-space">&nbsp;</span>==<span class="apple-converted-space">&nbsp;</span>NRF_SUCCESS)
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        45.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        46.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("[NUS_C]: SD Write API returns Success..\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        47.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;m_tx_index++;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        48.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;m_tx_index &amp;=<span class="apple-converted-space">&nbsp;</span>TX_BUFFER_MASK;
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        49.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        50.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        51.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;{
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        52.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//发送失败
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        53.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;LOG("[NUS_C]: SD Write API returns error. This message sending will
be "
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        54.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span class="apple-converted-space">&nbsp;</span>"attempted again..\r\n");
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        55.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        56.&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; }
</p>
<p class="MsoNormal" style="margin-left:32.4pt;text-indent:-18.0pt;">
        57.&nbsp;&nbsp;&nbsp;&nbsp; }
</p>
<p class="MsoNormal">
        <span>&nbsp;</span>
</p>

nrf51822m.rar

1.73 MB, 下载次数: 3062

简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

34

主题

322

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1835
金钱
1835
注册时间
2014-12-4
在线时间
717 小时
发表于 2015-9-5 18:44:06 | 显示全部楼层
谢谢,做的串口透传用的官方例子,数据只能20个,想做的更长一些
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2015-9-6 19:58:21 | 显示全部楼层
回复【14楼】loudianxin:
<br>---------------------------------
<br>私有协议自己做吧
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
34
金钱
34
注册时间
2015-11-18
在线时间
4 小时
发表于 2015-12-3 19:44:15 | 显示全部楼层
回复【14楼】loudianxin:
<br>---------------------------------
<br>兄弟我也在做透传,加我QQ(124878117)吧大家沟通下
回复

使用道具 举报

30

主题

705

帖子

1

精华

新手上路

积分
21
金钱
21
注册时间
2013-3-14
在线时间
52 小时
发表于 2015-12-15 15:18:57 | 显示全部楼层
在广播初始化函数里有个函数:ble_advdata_set。中有个函数是:sd_ble_gap_adv_data_set。我在个函数里添加&nbsp;scan&nbsp;response&nbsp;数据就会死机。
<br>不知道大家有写过扫描响应数据没有呀。
原子哥是不是又要出黑科技了呀。^_^...
回复

使用道具 举报

7

主题

57

帖子

0

精华

初级会员

Rank: 2

积分
144
金钱
144
注册时间
2012-11-13
在线时间
11 小时
发表于 2015-12-23 12:10:11 | 显示全部楼层
好文章,多谢楼主,厚读
回复

使用道具 举报

0

主题

3

帖子

0

精华

新手入门

积分
34
金钱
34
注册时间
2015-11-18
在线时间
4 小时
发表于 2016-1-7 13:30:23 | 显示全部楼层
loudianxin 发表于 2015-9-5 18:44
谢谢,做的串口透传用的官方例子,数据只能20个,想做的更长一些

哥们,你做的怎么样了?我也在开发,欢迎加我QQ交流124878117
回复

使用道具 举报

4

主题

67

帖子

0

精华

初级会员

Rank: 2

积分
125
金钱
125
注册时间
2014-3-10
在线时间
28 小时
发表于 2016-1-22 15:48:45 | 显示全部楼层
只遇到过填充过快会丢包。
菜鸟也会成为老鸟
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2016-1-22 15:56:18 | 显示全部楼层
xuyuhaoa 发表于 2016-1-22 15:48
只遇到过填充过快会丢包。

做透传串口发的数据太多蓝牙会直接断开的
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

4

主题

67

帖子

0

精华

初级会员

Rank: 2

积分
125
金钱
125
注册时间
2014-3-10
在线时间
28 小时
发表于 2016-4-25 11:45:27 | 显示全部楼层
没遇到过,用蓝牙做在线升级80多K的数据量,2分钟传完,也没见过断开
菜鸟也会成为老鸟
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2016-5-1 11:59:04 | 显示全部楼层
xuyuhaoa 发表于 2016-4-25 11:45
没遇到过,用蓝牙做在线升级80多K的数据量,2分钟传完,也没见过断开

80K两分钟1秒1K都不到,很多吗?
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

4

主题

67

帖子

0

精华

初级会员

Rank: 2

积分
125
金钱
125
注册时间
2014-3-10
在线时间
28 小时
发表于 2016-5-3 14:55:37 | 显示全部楼层
不知道你说的“多”,具体是多少
菜鸟也会成为老鸟
回复

使用道具 举报

27

主题

774

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
1473
金钱
1473
注册时间
2013-4-12
在线时间
77 小时
 楼主| 发表于 2016-5-3 20:25:07 | 显示全部楼层
xuyuhaoa 发表于 2016-5-3 14:55
不知道你说的“多”,具体是多少

1秒超过6K
简单是多么的快乐,而快乐就因你而简单!微芯动力LTKKS
回复

使用道具 举报

4

主题

67

帖子

0

精华

初级会员

Rank: 2

积分
125
金钱
125
注册时间
2014-3-10
在线时间
28 小时
发表于 2016-5-4 10:59:04 | 显示全部楼层
我表示无法跟你交流,数量和速率不分,你要别人去理解下,“多”和“快”是不是两回事。
菜鸟也会成为老鸟
回复

使用道具 举报

0

主题

2

帖子

0

精华

初级会员

Rank: 2

积分
88
金钱
88
注册时间
2016-3-29
在线时间
16 小时
发表于 2016-6-29 17:16:50 | 显示全部楼层
xuyuhaoa 发表于 2016-5-4 10:59
我表示无法跟你交流,数量和速率不分,你要别人去理解下,“多”和“快”是不是两回事。

哈哈,多好像是跟多少字节有关吧。
回复

使用道具 举报

0

主题

5

帖子

0

精华

新手上路

积分
22
金钱
22
注册时间
2016-6-23
在线时间
2 小时
发表于 2016-7-1 16:50:16 | 显示全部楼层
蓝牙手环,属于智能穿戴应用领域,目前喆华在此领域拥有比较成熟的案例和市场,同时配备相应客户端。其主控芯片为A81X07。 蓝牙4.0 芯片.jpg
回复

使用道具 举报

0

主题

1

帖子

0

精华

新手入门

积分
7
金钱
7
注册时间
2016-12-19
在线时间
0 小时
发表于 2016-12-19 16:42:45 | 显示全部楼层
楼主的图都看不到啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-22 22:12

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表