⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtel.lst

📁 cc2430应用实例
💻 LST
📖 第 1 页 / 共 5 页
字号:
    696              // Status bit mask - bit=1 indicates failure
    697              *buf = stat;
    698          
    699              MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + len),
    700                                            (SPI_RESPONSE_BIT | SPI_CMD_SYS_GET_NV_INFO),
    701                                            len, buf );
    702          
    703              osal_mem_free( buf );
    704            }
    705          }
    706          #endif  // NONWK
    707          #endif  // ZTOOL
    708          
    709          #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
    710          #define DEVICE_INFO_RESPONSE_LEN 46
    711          #define TYPE_COORDINATOR         1
    712          #define TYPE_ROUTER              2
    713          #define TYPE_ENDDEVICE           4
    714          /***************************************************************************************************
    715           * @fn      MT_ProcessGetDeviceInfo
    716           *
    717           * @brief
    718           *
    719           *   The Get Device Info serial message.
    720           *
    721           * @param   byte *msg - pointer to the data
    722           *
    723           * @return  void
    724           ***************************************************************************************************/
    725          void MT_ProcessGetDeviceInfo( void )
    726          {
    727            byte *buf;
    728            byte *pBuf;
    729            uint8 deviceType = 0;
    730            uint16 shortAddr;
    731            uint16 *assocList;
    732            byte assocCnt;
    733            uint16 *puint16;
    734            byte x;
    735          
    736            buf = osal_mem_alloc( DEVICE_INFO_RESPONSE_LEN );
    737            if ( buf )
    738            {
    739              pBuf = buf;
    740          
    741              *pBuf++ = ZSUCCESS;
    742          
    743              osal_nv_read( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, pBuf );
    744              // Outgoing extended address needs to be reversed
    745              MT_ReverseBytes( pBuf, Z_EXTADDR_LEN );
    746              pBuf += Z_EXTADDR_LEN;
    747          
    748          #if !defined( NONWK )
    749              shortAddr = NLME_GetShortAddr();
    750          #else
    751              shortAddr = 0;
    752          #endif
    753          
    754              *pBuf++ = HI_UINT16( shortAddr );
    755              *pBuf++ = LO_UINT16( shortAddr );
    756          
    757              // Return device type
    758          #if !defined( NONWK )
    759          #if defined (ZDO_COORDINATOR)
    760              deviceType |= (uint8) TYPE_COORDINATOR;
    761            #if defined (SOFT_START)
    762              deviceType |= (uint8) TYPE_ROUTER;
    763            #endif
    764          #endif
    765          #if defined (RTR_NWK) && !defined (ZDO_COORDINATOR)
    766              deviceType |= (uint8) TYPE_ROUTER;
    767          #elif !defined (RTR_NWK)
    768              deviceType |= (uint8) TYPE_ENDDEVICE;
    769          #endif
    770          #endif
    771              *pBuf++ = (byte) deviceType;
    772          
    773              //Return device state
    774          #if !defined( NONWK )
    775              *pBuf++ = (byte)devState;
    776          #else
    777              *pBuf++ = (byte)0;
    778          #endif
    779          
    780          #if defined(RTR_NWK) && !defined( NONWK )
    781              assocList = AssocMakeList( &assocCnt );
    782          #else
    783              assocCnt = 0;
    784              assocList = NULL;
    785          #endif
    786          
    787              *pBuf++ = assocCnt;
    788          
    789              // upto 16 devices
    790              osal_memset( pBuf, 0, (16 * sizeof(uint16)) );
    791              puint16 = assocList;
    792              for ( x = 0; x < assocCnt; x++ )
    793              {
    794                *pBuf++ = HI_UINT16( *puint16 );
    795                *pBuf++ = LO_UINT16( *puint16 );
    796                puint16++;
    797              }
    798          
    799              if ( assocList )
    800                osal_mem_free( assocList );
    801          
    802              MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + DEVICE_INFO_RESPONSE_LEN),
    803                                            (SPI_RESPONSE_BIT | SPI_CMD_SYS_GET_DEVICE_INFO),
    804                                            DEVICE_INFO_RESPONSE_LEN, buf );
    805          
    806              osal_mem_free( buf );
    807            }
    808          }
    809          #endif
    810          
    811          #if defined (ZTOOL_P1) || defined (ZTOOL_P2)
    812          /***************************************************************************************************
    813           * @fn      MT_ProcessSerialCommand
    814           *
    815           * @brief
    816           *
    817           *   Process Serial Message.
    818           *
    819           * @param   byte *msg - pointer to event message
    820           *
    821           * @return  void
    822           ***************************************************************************************************/
    823          void MT_ProcessSerialCommand( byte *msg )
    824          {
    825            UINT16 cmd;
    826            UINT16 callbackID;
    827            byte len;
    828            byte ret;
    829            byte *pData;
    830            uint16 tmp16;
    831            uint32 tmp32;
    832            byte extAddr[Z_EXTADDR_LEN];
    833            byte *retValue;
    834            byte x = 0;
    835          #if !defined ( NONWK )
    836            uint16 attLen;
    837          #endif // NONWK
    838          
    839            // dig out header info
    840            cmd = BUILD_UINT16( msg[1], msg[0] );
    841            save_cmd = cmd;
    842            len = msg[2];
    843            pData = &msg[3];
    844          
    845              // Setup for return;
    846              len = 0;
    847              retValue = &ret;
    848          
    849              //Process the contents of the message
    850              switch ( cmd )
    851              {
    852          #ifdef MACSIM
    853                case SPI_CMD_ZIGNET_DATA:
    854                  MACSIM_TranslateMsg( pData, len );
    855                  break;
    856          #endif
    857          
    858                case SPI_CMD_SYS_RAM_READ:
    859                  extAddr[0] = MT_RAMRead( (UINT16)BUILD_UINT16( pData[1], pData[0] ), &extAddr[1] );
    860                  len = MT_RAM_READ_RESP_LEN;
    861                  retValue = extAddr;
    862                  break;
    863          
    864                case SPI_CMD_SYS_RAM_WRITE:
    865                  ret = MT_RAMWrite( (UINT16)BUILD_UINT16( pData[1], pData[0] ), pData[2] );
    866                  len = MT_RAM_WRITE_RESP_LEN;
    867                  break;
    868          
    869                case SPI_CMD_SYS_SET_DEBUG_THRESHOLD:
    870                  ret = MT_SetDebugThreshold( pData[0], pData[1] );
    871                  len = 1;
    872                  break;
    873          
    874                case SPI_CMD_TRACE_SUB:
    875                  break;
    876          
    877                case SPI_CMD_SYS_RESET:
    878                  MT_Reset( pData[0] );
    879                  break;
    880          
    881                case SPI_CMD_SYS_CALLBACK_SUB_CMD:
    882                  // a callback value of 0xFFFF turns on all available callbacks
    883                  callbackID = BUILD_UINT16( pData[1] , pData[0] );
    884                  if ( callbackID == 0xFFFF )
    885                  {
    886                    // What is the action
    887                    if ( pData[2] )
    888                    {
    889                      // Turn on
    890          #if defined( MT_MAC_CB_FUNC )
    891                      _macCallbackSub = 0xFFFF;
    892          #endif
    893          #if defined( MT_NWK_CB_FUNC )
    894                      _nwkCallbackSub = 0xFFFF;
    895          #endif
    896          
    897          #if defined( MT_ZDO_FUNC )
    898                      _zdoCallbackSub = 0xFFFFFFFF;
    899          #endif
    900          #if defined( MT_AF_CB_FUNC )
    901                      _afCallbackSub = 0xFFFF;
    902          #endif
    903          #if defined( MT_SAPI_CB_FUNC )
    904                      _sapiCallbackSub = 0xFFFF;
    905          #endif
    906                    }
    907                    else
    908                    {
    909                      // Turn off
    910          #if defined( MT_MAC_CB_FUNC )
    911                      _macCallbackSub = 0x0000;
    912          #endif
    913          #if defined( MT_NWK_CB_FUNC )
    914                      _nwkCallbackSub = 0x0000;
    915          #endif
    916          
    917          #if defined( MT_ZDO_FUNC )
    918                      _zdoCallbackSub = 0x00000000;
    919          #endif
    920          #if defined( MT_AF_CB_FUNC )
    921                      _afCallbackSub = 0x0000;
    922          #endif
    923          #if defined( MT_SAPI_CB_FUNC )
    924                      _sapiCallbackSub = 0x0000;
    925          #endif
    926                    }
    927                  }
    928                  else
    929                  {
    930                    //First check which layer callbacks are desired and then set the preference
    931          
    932          #if defined( MT_MAC_CB_FUNC )
    933                    //If it is a MAC callback, set the corresponding callback subscription bit
    934                    if (( callbackID & 0xFFF0 ) == SPI_MAC_CB_TYPE )
    935                    {
    936                      //Based on the action field, either enable or disable subscription
    937                      if ( pData[2] )
    938                        _macCallbackSub |=  ( 1 << ( pData[1] & 0x0F ) );
    939                      else
    940                        _macCallbackSub &= ~( 1 << ( pData[1] & 0x0F ) );
    941                    }
    942          #endif
    943          
    944          #if defined( MT_NWK_CB_FUNC )
    945                    //If it is a NWK callback, set the corresponding callback subscription bit
    946                    if (( callbackID & 0xFFF0 ) == SPI_NWK_CB_TYPE )
    947                    {
    948          
    949                      //Based on the action field, either enable or disable subscription
    950                      if ( pData[2] )
    951                        _nwkCallbackSub |=  ( 1 << ( pData[1] & 0x0F ) ) ;
    952                      else
    953                        _nwkCallbackSub &= ~( 1 << ( pData[1] & 0x0F ) );
    954                    }
    955          #endif
    956          
    957          #if defined( MT_ZDO_FUNC )
    958                    //If it is a APS callback, set the corresponding callback subscription bit
    959                    if ( ((callbackID & 0xFFF0) == SPI_ZDO_CB_TYPE) ||
    960                         ((callbackID & 0xFFF0) == SPI_ZDO_CB2_TYPE) )
    961                    {
    962                      //Based on the action field, either enable or disable subscription
    963                      if ( pData[2] )
    964                        _zdoCallbackSub |=  ( 1L << ( pData[1] & 0x1F ) );
    965                      else
    966                        _zdoCallbackSub &= ~( 1L << ( pData[1] & 0x1F ) );
    967                    }
    968          #endif
    969          
    970          #if defined( MT_AF_CB_FUNC )
    971                    // Set the corresponding callback subscription bit for an AF callback.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -