【MiCOKit试用体验】+ 如何扫描附近WiFi热点 - 问答 - 电子技术论坛 - 最好最受欢迎电子论坛!

【MiCOKit试用体验】+ 如何扫描附近WiFi热点

GalaIO ( 楼主 ) 2015-11-8 20:03:46  只看该作者 倒序浏览
    在上一节中,我们学会了如何给MicoKit的Cli的工具中添加命令,对于我们来说,这是为了我们扩展源程序,来开发更灵活的功能。在这一节我们将会添加一个扫描附近WiFi热点的命令,来提供给开发者调试。
$ }/ l# c2 L* l/ q% B! x3 m   在标准的SDK中的Demo中有给出,SDK_MiCO_v2.3.0DemosCOM.MXCHIP.BASICwifiscan相对目录,主要的原理就是想mico中注册 一个回调函数,当wifi核扫描完热点信息后,会通过回调函数来传递数据给用户层,注册函数原型如下:
6 M3 I: W3 [+ L; e  I
. {% }9 R$ [+ X9 u
/**
  * @brief  Register a user function to a MiCO notification.
  * @param  notify_type: The type of MiCO notification.
  * @param  functionAddress: The address of user function.
  * @param  arg: The address of argument, which will be called by registered user function.
  * @retval kNoErr is returned on success, otherwise, kXXXErr is returned.
  */
OSStatus mico_system_notify_register( mico_notify_types_t notify_type, void* functionAddress, void* arg );
复制代码
7 ]' e. G. \9 |" s3 h

9 G5 o/ d& _/ s1 g' y  H" E! i/ u! |; G4 U1 [  F( G
   回调函数定义如下:
- k2 N, Y  r9 S5 l* c1 @' ]1 `2 C8 ~; G' V

  1. ) j6 l1 Y) m2 v$ y5 c5 _1 z
static void micoNotify_ApListCallback(ScanResult *pApList)
{
  int i=0;
  wifi_scan_log("got %d AP", pApList->ApNum);
  for(i=0; iApNum; i++)
  {
    wifi_scan_log("ap%d: name = %s  | strenth=%d",  
                  i,pApList->ApList[i].ssid, pApList->ApList[i].ApPower);
# n9 |5 Y  e0 o8 d
  •   }
    }
    复制代码& n( A# o, u6 E: l% K/ e
    8 ]+ U" Q3 l$ q4 D4 Q& ~

    2 R$ N" l* @; J* Y3 w$ K4 Y9 R: l/ q( ^
       当注册了回调函数后,现在需要使能系统的扫描功能,函数原型如下:% t( [9 k7 j* L1 _" Y, i0 C0 _

    1 }8 d9 V, O4 Z+ T
    1. ) S/ n, R7 T! M0 p7 A* _  _
    /** @brief  Start a wlan scanning in 2.4GHz in MICO backfround.
    *  
    *  [url=home.php?mod=space&uid=512752]@detail[/url] Once the scan is completed, MICO sends a notify:
    *          mico_notify_WIFI_SCAN_COMPLETED, with callback function:
    *          void (*function)(ScanResult *pApList, mico_Context_t * const inContext)
    *          Register callback function using [url=home.php?mod=space&uid=1352397]@ref[/url] mico_add_notification() before scan.
    */
    void micoWlanStartScan(void);
    复制代码
    8 |' \% Q# D7 L2 f3 k5 ?! k0 t; C) }3 E! M+ u" z
    6 W, h! m( m0 Z4 g; j7 M1 k
       现在只需要等待,回调函数返回结果就好了,在这里我们直接在回调函数中打印输出结果。对于有些应用为了同步数据,所以需要设置信号量来等待回调函数返回结果,由于我们在这里并不需要同步,因为我们都是手动操作的嘛~~~结果如下:- _: d2 W5 @. ]' F* J

    - @; W) o& e2 r% x9 L8 o
    . b% A; G6 \2 {# P3 i2 `( k; e5 k) }( z4 T- [* h* ?3 ]: R

    1个回复

    micolover 发表于 2015-11-9 11:52:22
    感谢楼主的分享!
    回复 1

    举报 使用道具

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

    本版积分规则


    关闭

    站长推荐上一条 /9 下一条

    小黑屋|手机版|Archiver|电子发烧友 ( 湘ICP备2023018690号 )

    GMT+8, 2025-12-1 16:31 , Processed in 0.485853 second(s), Total 34, Slave 23 queries .

    Powered by 电子发烧友网

    © 2015 bbs.elecfans.com

    微信扫描
    快速回复 返回顶部 返回列表