sonicfirr 发表于 2022-4-15 09:04

【平头哥RVB2601创意应用开发】使用体验07 -- 基于NTP的代码追踪

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">上篇的</font><font face="Times New Roman">NTP</font><font face="宋体">使用记录已经篇幅很长了,所以将后续的代码追踪过程再记录一篇。也是出于好奇,对</font><font face="Times New Roman">NTP</font><font face="宋体">的实现过程进行了代码分析,暂有一处不解,文中细表。</font></span></span></span></span></span></p>

<h2 style="text-align:justify"><span style="font-size:14pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-weight:bold"><b><span style="font-size:14.0000pt"><span style="font-family:宋体"><span style="font-weight:bold"><font face="Times New Roman">1</font><font face="宋体">、从</font><font face="Times New Roman">lwip API</font><font face="宋体">开始追溯</font></span></span></span></b></span></span></span></span></h2>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="Times New Roman">NTP</font><font face="宋体">测试</font><font face="Times New Roman">Demo</font><font face="宋体">中明显使用了</font><font face="Times New Roman">lwip API</font><font face="宋体">,包括</font><font face="Times New Roman">connect</font><font face="宋体">、</font><font face="Times New Roman">send</font><font face="宋体">、</font><font face="Times New Roman">close</font><font face="宋体">等接口。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-1 NTP Demo</font><font face="宋体">中的</font><font face="Times New Roman">lwip</font><font face="宋体">接口使用</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">索性尝试从</font><font face="Times New Roman">send</font><font face="宋体">接口开始追溯,通过</font><font face="Times New Roman">CDK</font><font face="宋体">中按住&ldquo;</font><font face="Times New Roman">Ctrl</font><font face="宋体">键&rdquo;左键点击</font><font face="Times New Roman">send</font><font face="宋体">标识符,成功跳转到坑点。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-2 IDE</font><font face="宋体">帮着做得跳转不准确</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">接着,试着全文件搜索</font>&ldquo;<font face="Times New Roman">send(</font><font face="宋体">&rdquo;,加一个左圆括号去除单独出现</font><font face="Times New Roman">send</font><font face="宋体">的情况。可是只能搜到一个结果,那么依据经验判断</font><font face="Times New Roman">send</font><font face="宋体">并不是定义的函数原型,可能是宏定义。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-3 </font><font face="宋体">进行全文件字符串搜索</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">带着宏定义的判断继续搜索</font>&ldquo;<font face="Times New Roman">#define send</font><font face="宋体">&rdquo;,怕默认搜索路径不全面,手动添加了整个</font><font face="Times New Roman">pack</font><font face="宋体">目录,结果搜了个寂寞。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-4 #define send</font><font face="宋体">关键字检索无结果</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">于是,改为搜索</font><font face="Times New Roman">connect</font><font face="宋体">接口。超链接跳转一下就到了乍一看很靠谱的位置。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-5 connect</font><font face="宋体">关键字检索结果</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">看到这些宏的编译条件,于是做了一个判断,通过在</font><font face="Times New Roman">board_yoc_init()</font><font face="宋体">中添加</font><font face="Times New Roman">printf</font><font face="宋体">语句,使得启动时输出这个条件宏&ldquo;</font><font face="Times New Roman">LWIP_COMPAT_SOCKETS</font><font face="宋体">&rdquo;的值。</font></span></span></span></span></span></p>

<p>&nbsp;</p>

<pre>
<code>void board_yoc_init()
{
    board_init();
        event_service_init(NULL); //initialize event service for network events
    console_init(CONSOLE_UART_IDX, 115200, 128);
    ulog_init();
    aos_set_log_level(AOS_LL_DEBUG);   
    LOGI(TAG, "Build:%s,%s\n",__DATE__, __TIME__);
       
        printf("-----&gt; LWIP_COMPAT_SOCKETS: %d &lt;-----\n", LWIP_COMPAT_SOCKETS);
       
    /* load partition &amp; init kv function */
        aita_InitKV();
       
        /* set cycle timer for polling job */
        aita_InitTimer();
       
        /* initialize wifi network */
        aita_InitNetwork();

    board_cli_init();
}</code></pre>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-6 </font><font face="宋体">条件宏值为</font><font face="Times New Roman">2</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-7 </font><font face="宋体">符合条件的代码有更大惊喜</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<h2 style="text-align:justify"><span style="font-size:14pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-weight:bold"><b><span style="font-size:14.0000pt"><span style="font-family:宋体"><span style="font-weight:bold"><font face="Times New Roman">2</font><font face="宋体">、从</font><font face="Times New Roman">List</font><font face="宋体">文件开始追溯</font></span></span></span></b></span></span></span></span></h2>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">符合这个条件编译的宏定义中,</font><font face="Times New Roman">send</font><font face="宋体">却是另外标识符的宏替代。上述过程说得简单,其实搞起来也花了两个多小时,于是决定改变思路&mdash;&mdash;转看编译生成的</font><font face="Times New Roman">List</font><font face="宋体">文件。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-8 </font><font face="宋体">追溯结果</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">实际的追溯结果是预料到的,因为</font><font face="Times New Roman">NTP</font><font face="宋体">的实现就是修改了</font><font face="Times New Roman">w800_api.c</font><font face="宋体">中的</font><font face="Times New Roman">bug</font><font face="宋体">,唯一不解的是</font><font face="Times New Roman">w800</font><font face="宋体">的接口是如何映射到</font><font face="Times New Roman">lwip</font><font face="宋体">协议栈的。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">追踪</font><font face="Times New Roman">&lt;send&gt;</font><font face="宋体">位置的</font><font face="Times New Roman">c</font><font face="宋体">代码,发现是</font><font face="Times New Roman">sal_send()</font><font face="宋体">函数的定义代码。接着再搜索</font><font face="Times New Roman">sal_send</font><font face="宋体">,最大惊喜来了!</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">7-9 </font><font face="宋体">再追溯结果</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">这个惊喜直接让我放弃了,难道是</font><font face="Times New Roman">C</font><font face="宋体">语法了解还不足吗?</font><font face="Times New Roman">send</font><font face="宋体">怎么也成了</font><font face="Times New Roman">sal_send</font><font face="宋体">的替代了,还是这里的宏要反着去理解?要是有明白的朋友,恳请帮我指出吧!</font></span></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">此篇到此结束,后面准备进行</font><font face="Times New Roman">NTP</font><font face="宋体">对</font><font face="Times New Roman">RTC</font><font face="宋体">的初始化。</font></span></span></span></span></span></p>

lugl4313820 发表于 2022-4-15 15:27

分析代码辛苦了。我去发了工单,也按工单的操作了,还是没有解产,后面从我的服务返回时间解决了。希望你把这个问题反馈给阿里,看他们有什么更好的修改。

Fred_1977 发表于 2022-4-15 19:08

<p>分析的很仔细.</p>

sonicfirr 发表于 2022-4-15 23:35

lugl4313820 发表于 2022-4-15 15:27
分析代码辛苦了。我去发了工单,也按工单的操作了,还是没有解产,后面从我的服务返回时间解决了。希望你把 ...

<p>反应过了,发给我一个文档,是修改ntp&nbsp;bug的。感觉还是有坑。</p>

lugl4313820 发表于 2022-4-15 23:43

<div class="quote">
<blockquote><font size="2"><a href="forum.php?mod=redirect&amp;goto=findpost&amp;pid=3135770&amp;ptid=1199912" target="_blank"><font color="#999999">sonicfirr 发表于 2022-4-15 23:35</font></a></font> 反应过了,发给我一个文档,是修改ntp&nbsp;bug的。感觉还是有坑。</blockquote>
</div>

<p>楼主这么晚还在努力更新,给一个大大的赞</p>

sonicfirr 发表于 2022-4-16 09:50

lugl4313820 发表于 2022-4-15 23:43
还没休息呀,看来这个板子实在折磨人呀。

<p>说来好笑,AliOS最早出过一块开发板STM32L476的,昨天在闲鱼上看到有人出,底下一堆人跟帖骂板子的&mdash;&mdash;主要是骂开发环境。</p>

<p>看来这是个历史问题了。</p>

lugl4313820 发表于 2022-4-16 11:17

sonicfirr 发表于 2022-4-16 09:50
说来好笑,AliOS最早出过一块开发板STM32L476的,昨天在闲鱼上看到有人出,底下一堆人跟帖骂板子的&mdash ...

<p>接了任务吹了一下牛,这板子的外设资源太紧张了。唉!</p>
页: [1]
查看完整版本: 【平头哥RVB2601创意应用开发】使用体验07 -- 基于NTP的代码追踪