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

📄 mtel.c

📁 Zigbee2006入门(源代码+文档讲解+系统推荐)
💻 C
📖 第 1 页 / 共 4 页
字号:
 * @fn      MT_ProcessAppUserCmd
 *
 * @brief
 *
 *   Temp function for testing
 *
 * @param   data - received message
 *
 * @return  void
 */
void MT_ProcessAppUserCmd( byte *pData) 						
{
  uint16 app_cmd;
  byte srcEp;
  uint16 param1;
  uint16 param2;
  byte len;
  uint16 ret;

  ret = INVALID_TASK;     //should be changed later

  srcEp = *pData++;

  app_cmd = BUILD_UINT16( pData[1] , pData[0] );
  pData = pData + sizeof( uint16 );

  param1 = BUILD_UINT16( pData[1] , pData[0] );
  pData = pData + sizeof( uint16 );

  param2 = BUILD_UINT16( pData[1] , pData[0] );

  len = SPI_RESP_MSG_LEN_DEFAULT;


  switch ( app_cmd )
  {

#if defined (APP_TGEN)
    case TGEN_START:
      TrafficGenApp_SendCmdMSG( param1, param2, TRAFFICGENAPP_CMD_START );
      ret = ZSUCCESS;
      break;

    case TGEN_STOP:
      TrafficGenApp_SendCmdMSG( param1, param2, TRAFFICGENAPP_CMD_STOP );
      ret = ZSUCCESS;
      break;

    case TGEN_COUNT:
      ret = TrafficGenApp_CountPkt( param1, param2 );
      return;		// so that spi_resp is not sent...
      //ret = ZSUCCESS;
      break;				
#endif

#if defined (NWK_TEST)
    case HW_TEST:
      HwApp_Start( HI_UINT16(param1), LO_UINT16(param1), HI_UINT16(param2),
                    1000, LO_UINT16(param2), 3, 0 );
      break;

    case HW_DISPLAY_RESULT:
      HwApp_TestInfo();
      break;

    case HW_SEND_STATUS:
      HwApp_SendStats();
      break;
#endif

#if defined( APP_TP ) || defined ( APP_TP2 )
  #if defined( APP_TP )
    case TP_SEND_NODATA:
      ret = TestProfileApp_SendNoData( srcEp, (byte)param1 );
      break;
  #endif // APP_TP
			
    case TP_SEND_BUFFERTEST:
      ret = TestProfileApp_SendBufferReq( srcEp, (byte)param1 );
      break;
			
  #if defined( APP_TP )
    case TP_SEND_UINT8:
      ret = TestProfileApp_SendUint8( srcEp, (byte)param1 );
      break;

    case TP_SEND_INT8:
      ret = TestProfileApp_SendInt8( srcEp, (byte)param1 );
      break;

    case TP_SEND_UINT16:
      ret = TestProfileApp_SendUint16( srcEp, (byte)param1 );
      break;

    case TP_SEND_INT16:
      ret = TestProfileApp_SendInt16( srcEp, (byte)param1 );
      break;

    case TP_SEND_SEMIPREC:
      ret = TestProfileApp_SendSemiPrec( srcEp, (byte)param1 );
      break;

    case TP_SEND_FREEFORM:
      ret = TestProfileApp_SendFreeFormReq( srcEp, (byte)param1 );
      break;
			
  #else // APP_TP
    case TP_SEND_FREEFORM:
      ret = TestProfileApp_SendFreeFormReq(srcEp, (byte)param1, (byte)param2);
      break;
  #endif
			
  #if defined( APP_TP )
    case TP_SEND_ABS_TIME:
      ret = TestProfileApp_SendAbsTime( srcEp, (byte)param1 );
      break;

    case TP_SEND_REL_TIME:
      ret = TestProfileApp_SendRelativeTime( srcEp, (byte)param1 );
      break;

    case TP_SEND_CHAR_STRING:
      ret = TestProfileApp_SendCharString( srcEp, (byte)param1 );
      break;

    case TP_SEND_OCTET_STRING:
      ret = TestProfileApp_SendOctetString( srcEp, (byte)param1 );
      break;		
  #endif // APP_TP
				
    case TP_SET_DSTADDRESS:			
      ret = TestProfileApp_SetDestAddress(HI_UINT16(param1), LO_UINT16(param1), param2);
      break;	

  #if defined( APP_TP2 )
    case TP_SEND_BUFFER_GROUP:
      ret = TestProfileApp_SendBufferGroup( srcEp, (byte)param1 );
      break;
  #endif // APP_TP

    case TP_SEND_BUFFER:
      ret = TestProfileApp_SendBuffer( srcEp, (byte)param1 );
      break;
				
  #if defined( APP_TP )
    case TP_SEND_MULT_KVP_8BIT:
      TestProfileApp_SendMultiKVP_8bit( srcEp, (byte)param1 );
      ret = ZSuccess;
      break;

    case TP_SEND_MULT_KVP_16BIT:
      TestProfileApp_SendMultiKVP_16bit( srcEp, (byte)param1 );
      ret = ZSuccess;
      break;

    case TP_SEND_MULT_KVP_TIME:
      TestProfileApp_SendMultiKVP_Time( srcEp, (byte)param1 );
      ret = ZSuccess;
      break;

    case TP_SEND_MULT_KVP_STRING:
      TestProfileApp_SendMultiKVP_String( srcEp, (byte)param1 );
      ret = ZSuccess;
      break;

    case TP_SEND_MULTI_KVP_STR_TIME:
      ret = ZSuccess;
      TestProfileApp_SendMultiKVP_String_Time( srcEp, (byte)param1 );
      break;
  #endif // APP_TP
				
    case TP_SEND_COUNTED_PKTS:
      TestProfileApp_SendCountedPktsReq(HI_UINT16(param1), LO_UINT16(param1), param2);
      ret = ZSuccess;
      break;

    case TP_SEND_RESET_COUNTER:
      TestProfileApp_CountedPakts_ResetCounterReq( (byte)param1 );
      ret = ZSuccess;
      break;

    case TP_SEND_GET_COUNTER:
      TestProfileApp_CountedPakts_GetCounterReq( srcEp, (byte)param1 );
      ret = ZSuccess;
      break;
				
    case TP_SET_PERMIT_JOIN:
  #if defined ( RTR_NWK )
      NLME_PermitJoiningRequest( (byte)param1 );
      ret = ZSuccess;
  #else
      ret = ZFailure;
  #endif
      break;

  #if defined ( APP_TP2 )
    case TP_ADD_GROUP:
      ret = TestProfileApp_SetGroup( srcEp, param1 );
      break;

    case TP_REMOVE_GROUP:
      ret = TestProfileApp_RemoveGroup( srcEp, param1 );
      break;

    case TP_SEND_UPDATE_KEY:
      ret = TestProfileApp_UpdateKey( srcEp, (uint8)param1 );
      break;

    case TP_SEND_SWITCH_KEY:
      ret = TestProfileApp_SwitchKey(  srcEp, (uint8)param1 );
      break;
			
    case TP_SEND_BUFFERTEST_GROUP:
      ret = TestProfileApp_SendBufferGroupReq( srcEp, (byte)param1 );
      break;

    case TP_SEND_ROUTE_DISC_REQ:
      ret = TestProfileApp_SendRouteDiscReq( srcEp, param1,
                                  HI_UINT16( param2 ), LO_UINT16( param2 ) );
      break;

    case TP_SEND_ROUTE_DISCOVERY:
#if defined ( RTR_NWK )
      ret = TestProfileApp_SendRouteDiscovery( param1,
                                  HI_UINT16( param2 ), LO_UINT16( param2 ) );
#endif
      break;

  #endif // APP_TP2

#endif  // APP_TP || APP_TP2

#if defined ( OSAL_TOTAL_MEM )
    case OSAL_MEM_STACK_HIGH_WATER:
    case OSAL_MEM_HEAP_HIGH_WATER:
      if ( app_cmd == OSAL_MEM_STACK_HIGH_WATER)
        param1 = osal_stack_used();
      else
        param1 = osal_heap_high_water();
      pData[0] = HI_UINT16( param1 );
      pData[1] = LO_UINT16( param1 );

      // The pData for this response will only send one byte,
      // so we are going to call it twice.
      //        MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + sizeof( uint16 )),
      //                                    (SPI_CMD_USER_TEST | SPI_RESPONSE_BIT),
      //                                    sizeof( uint16 ), pData );
      MT_SendSPIRespMsg( pData[0], SPI_CMD_USER_TEST, SPI_RESP_MSG_LEN_DEFAULT, 1);
      MT_SendSPIRespMsg( pData[1], SPI_CMD_USER_TEST, SPI_RESP_MSG_LEN_DEFAULT, 1);
      return;
#endif

#if defined ( APP_DEBUG )
    case DEBUG_GET:
      DebugApp_SendQuery( param1 );
      ret = ZSUCCESS;
      break;
#endif

#if defined ( APP_TP2 )
    case TP_SEND_BCAST_RSP:
      ret = TestProfileApp_SendBcastRsp( srcEp, (byte)param1 );
      break;
#endif
			
    default:
      break;
  }

  MT_SendSPIRespMsg( ( byte )ret, SPI_CMD_USER_TEST, len, 1);

}
#endif // MT_USER_TEST_FUNC
#endif // ZTOOL

#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
/***************************************************************************************************
 * @fn      MT_RAMRead
 *
 * @brief
 *
 *   Process Serial Message.
 *
 * @param   UINT16 addr - address to read from
 * @param   pData - pointer to buffer to put read data
 *
 * @return  ZSuccess or ZFailure
 *
 * @MT SPI_CMD_SYS_RAM_READ
 *
 ***************************************************************************************************/
byte MT_RAMRead( UINT16 addr, byte *pData  )
{
  byte *pAddr;

  if ( IS_MEM_VALID( addr ) )
  {
    pAddr = (byte *)addr;
    *pData = *pAddr;
    return ( (byte)ZSuccess );
  }
  else
  {
    *pData = 0;
    return ( (byte)ZFailure );
  }
}
#endif

#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
/***************************************************************************************************
 * @fn      MT_RAMWrite
 *
 * @brief
 *
 *   Process Serial Message.
 *
 * @param   UINT16 addr - address to write at
 * @param   byte val  - values to fill in the above address and the next
 *
 * @return  ZSuccess or ZFailure
 *
 * @MT SPI_CMD_SYS_RAM_WRITE
 *
 ***************************************************************************************************/
byte MT_RAMWrite( UINT16 addr, byte val )
{
  if ( IS_MEM_VALID( addr ) )
  {
    *((byte*)(addr)) = val;
    return ( (byte)ZSuccess );
  }
  else
    return ( (byte)ZFailure );
}
#endif

#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
/***************************************************************************************************
 * @fn      MT_SetDebugThreshold
 *
 * @brief
 *
 *   Set Debug Threshold for software components.
 *
 * @param   comp_id   - software component ID.
 * @param   threshold - threshold value for reporting debug messages.
 *
 * @return  ZSuccess
 *
 * @MT SPI_CMD_SYS_SET_DEBUG_THRESHOLD
 *
 ***************************************************************************************************/
byte MT_SetDebugThreshold( byte compID, byte threshold )
{
  // *** RKJ - for now if we get any threshold message, set it on
  debugThreshold = threshold;
  debugCompId = compID;

  return ( (byte)ZSuccess );
}
#endif

/***************************************************************************************************
 * @fn      MT_Reset
 *
 * @brief
 *
 *   Reset/reprogram the device.
 *
 * @param   typID: 0=reset, 1=serial bootloader
 *
 * @return  void
 *
 * @MT SPI_CMD_SYS_RESET
 ***************************************************************************************************/
void MT_Reset( byte typID )
{
  if ( typID )
  {
    // Jump to bootloader
    BootLoader();
  }
  else
  {
    // Restart this program
    SystemReset();
  }
}

#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
/***************************************************************************************************
 * @fn      MT_SendErrorNotification
 *
 * @brief
 *
 *   Send Error Notofication Message to Test Tool.
 *
 * @param   byte err
 *
 * @return  void
 ***************************************************************************************************/
void MT_SendErrorNotification( byte err )
{
  MT_BuildAndSendZToolResponse( (SPI_0DATA_MSG_LEN + 1),
                              (SPI_RESPONSE_BIT | SPI_CMD_SYS_RAM_WRITE),
                              1, &err );
}
#endif

/***************************************************************************************************
 * @fn      MT_ReverseBytes
 *
 * @brief
 *
 *   Reverses bytes within an array
 *
 * @param   data - ptr to data buffer to reverse
 * @param    len - number of bytes in buffer
 *
 * @return  void
 ***************************************************************************************************/
void MT_ReverseBytes( byte *pData, byte len )
{
  byte i,j;
  byte temp;

  for ( i = 0, j = len-1; len > 1; len-=2 ) {
    temp = pData[i];
    pData[i++] = pData[j];
    pData[j--] = temp;
  }
}

/***************************************************************************************************
 * @fn      MT_SendSPIRespMsg
 *
 * @brief
 *
 *   This function is used to process messages in the queue
 *
 * @param   none
 *
 * @return  void
 ***************************************************************************************************/
void MT_SendSPIRespMsg( byte ret, uint16 cmd_id, byte msgLen, byte respLen)
{
  byte *msgPtr;

  msgPtr = osal_mem_alloc( msgLen );
  if ( msgPtr )
  {
#if defined (ZTOOL_P1) || defined (ZTOOL_P2)
    MT_BuildSPIMsg( (SPI_RESPONSE_BIT | cmd_id), msgPtr, respLen, &ret );
    HalUARTWrite ( SPI_MGR_DEFAULT_PORT, msgPtr, msgLen );
#endif

    osal_mem_free( msgPtr );
  }
}

#endif  // MT_TASK

/***************************************************************************************************
***************************************************************************************************/

⌨️ 快捷键说明

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