Beispiel #1
0
void gateway_to_pda(uint16 shortaddr, uint8*buf, uint8 len)// 这儿的buf也 是一完整的协议data
{
   uint8*mbuf;
   uint8 i;
   mbuf = osal_mem_alloc( (len+4)*sizeof(uint8));
   
   mbuf[0] = len+3;
   mbuf[1] = 0x08;
   
   mbuf[2] = HI_UINT16(shortaddr);
   mbuf[3] = LO_UINT16(shortaddr);
   
   for( i = 0; i < len; i++)
   {
     mbuf[i+4] = buf[i];
   }
   
   // uart to send
   if( HalUARTWrite(0,mbuf, len+4) > 0)
   {
     osal_mem_free(mbuf);
   }else
   {
     HalUARTWrite(SER_PORT,mbuf, len+4);
     osal_mem_free(mbuf);
   }
   
   return;
}
//*********************************************
static void deleteSignalStrength( uint8 modbus_id)
{
  signalStrength_t *pLoop, *pNext;
  
  pLoop = pSignalStren;
  pNext = pSignalStren->next;
  
  if( pLoop != NULL)
  {
    if(pLoop->modbus_id == modbus_id)
    {
      numSignalStren--;
      if(pNext != NULL)
        pSignalStren = pNext;
      else
        pSignalStren = NULL;
      osal_mem_free( pLoop);
    }
    else
    {
      while( pNext != NULL)
      {
        if(pNext->modbus_id == modbus_id)
        {
          numSignalStren--;
          pLoop->next = pNext->next;
          osal_mem_free(pNext);
          return;
        }
        pLoop = pNext;
        pNext = pLoop->next;
      }
    }
  }
}
Beispiel #3
0
int rbuf_destroy(ringbuffer_t *rb)
{
    if (!rb || !(rb->buffer))
      return -1;
    
    osal_mem_free(rb->buffer);
    osal_mem_free(rb);
    return 0;
}
/*********************************************************************
 * @fn      Glucose_AddService
 *
 * @brief   Initializes the Glucose   service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Glucose_AddService(uint32 services)
{
    uint8 status;

    // Allocate Client Characteristic Configuration table
    glucoseMeasConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                        linkDBNumConns );
    if ( glucoseMeasConfig == NULL )
    {
        return ( bleMemAllocError );
    }

    // Allocate Client Characteristic Configuration table
    glucoseContextConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                           linkDBNumConns );
    if ( glucoseContextConfig == NULL )
    {
        // Free already allocated data
        osal_mem_free( glucoseMeasConfig );

        return ( bleMemAllocError );
    }

    // Allocate Client Characteristic Configuration table
    glucoseControlConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                           linkDBNumConns );
    if ( glucoseControlConfig == NULL )
    {
        // Free already allocated data
        osal_mem_free( glucoseMeasConfig );
        osal_mem_free( glucoseContextConfig );

        return ( bleMemAllocError );
    }

    // Initialize Client Characteristic Configuration attributes.
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseMeasConfig);
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseContextConfig);
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, glucoseControlConfig);

    if (services & GLUCOSE_SERVICE)
    {
        // Register GATT attribute list and CBs with GATT Server App.
        status = GATTServApp_RegisterService(glucoseAttrTbl,
                                             GATT_NUM_ATTRS(glucoseAttrTbl),
                                             GATT_MAX_ENCRYPT_KEY_SIZE,
                                             &glucoseCBs);
    }
    else
    {
        status = SUCCESS;
    }

    return (status);
}
Beispiel #5
0
/*************************************************************************************************
 * @fn      HalUARTCloseIsr()
 *
 * @brief   Close the UART
 *
 * @param   port - UART port (not used.)
 *
 * @return  none
 *************************************************************************************************/
void HalUARTCloseIsr(uint8 port)
{
  (void)port;

  UARTDisable(HAL_UART_PORT);

  if (uartRecord.configured)
  {
    (void)osal_mem_free(uartRecord.rx.pBuffer);
    (void)osal_mem_free(uartRecord.tx.pBuffer);
    recRst();
  }
}
Beispiel #6
0
/*
1, 思路:  当串口收到数据后,就会马上调用以下回调函数,在实际测试中发现,此回调
函数调用频繁, 如果你不执行NPI_ReadTransport函数进行读取, 那么这个回调函数就会
频繁地被执行,但是,你通过串口发送一段数据, 你本意是想处理这一完整一段的数据,所以,
我们在下面引入了时间的处理方法, 也即接收的数据够多或者超时,就读取一次数据, 
然后根据当前的状态决定执行,如果没有连接上,就把所有数据当做AT命令处理, 如果连接
上了,就把数据送到对端。  ---------------amomcu   2014.08.17
*/
void NpiSerialCallback( uint8 port, uint8 events )
{
    (void)port;//加个 (void),是未了避免编译告警,明确告诉缓冲区不用理会这个变量

    if (events & (HAL_UART_RX_TIMEOUT | HAL_UART_RX_FULL))   //串口有数据
    {
        uint8 numBytes = 0;

        numBytes = NPI_RxBufLen();           //读出串口缓冲区有多少字节
        
        if(numBytes == 0)
        {
            return;
        }
        else
        {
            //申请缓冲区buffer
            uint8 *buffer = osal_mem_alloc(numBytes);
            if(buffer)
            {
                //读取读取串口缓冲区数据,释放串口数据   
                NPI_ReadTransport(buffer,numBytes);   

                //把收到的数据发送到串口-实现回环 
                NPI_WriteTransport(buffer, numBytes);  

                //释放申请的缓冲区
                osal_mem_free(buffer);
            }
        }
    }
}
/*********************************************************************
 * @fn      resetCharacteristicValue
 *
 * @brief   Initialize a characteristic value to zero
 *
 * @param   servID - service ID (UUID)
 *
 * @param   paramID - parameter ID of the value is to be cleared
 *
 * @param   vakue - value to initialise with
 *
 * @param   paramLen - length of the parameter
 *
 * @return  none
 */
static void resetCharacteristicValue(uint16 servUuid, uint8 paramID, uint8 value, uint8 paramLen)
{
    uint8* pData = osal_mem_alloc(paramLen);
    if (pData == NULL)
    {
        return;
    }
    osal_memset(pData,value,paramLen);
    switch(servUuid)
    {
            //case IRTEMPERATURE_SERV_UUID:
            //    IRTemp_SetParameter( paramID, paramLen, pData);
            //    break;
            case ACCELEROMETER_SERV_UUID:
                Accel_SetParameter( paramID, paramLen, pData);
                break;
            //case MAGNETOMETER_SERV_UUID:
            //    Magnetometer_SetParameter( paramID, paramLen, pData);
            //    break;
            //case HUMIDITY_SERV_UUID:
            //    Humidity_SetParameter( paramID, paramLen, pData);
            //    break;
            //case BAROMETER_SERV_UUID:
            //    Barometer_SetParameter( paramID, paramLen, pData);
            //    break;
        case GYROSCOPE_SERV_UUID:
            Gyro_SetParameter( paramID, paramLen, pData);
            break;
        default:
            // Should not get here
            break;
    }
    osal_mem_free(pData);
}
Beispiel #8
0
/***************************************************************************************************
 * @fn          nwk_MTCallbackSubJoinIndication
 *
 * @brief       Process the callback subscription for NLME-INIT-COORD.indication
 *
 * @param       ShortAddress - 16-bit address
 * @param       ExtendedAddress - IEEE (64-bit) address
 * @param       CapabilityFlags - Association Capability Information
 *
 * @return      ZStatus_t
 ***************************************************************************************************/
void nwk_MTCallbackSubJoinIndication( uint16 ShortAddress, uint8 *ExtendedAddress,
                                      uint8 CapabilityFlags )
{
  uint8 *msgPtr;
  uint8 *msg;
  uint8 len;

  len = sizeof( uint16 ) + Z_EXTADDR_LEN + sizeof( uint8 );
  msgPtr = osal_mem_alloc( len );

  if ( msgPtr )
  {
    /* Fill up the data bytes */
    msg = msgPtr;

    /* First fill in details */
    *msg++ = LO_UINT16( ShortAddress );
    *msg++ = HI_UINT16( ShortAddress );

    osal_cpyExtAddr( msg, ExtendedAddress );
    msg += Z_EXTADDR_LEN;

    *msg = CapabilityFlags;

    MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLME_JOIN_IND, len, msgPtr );

    osal_mem_free( msgPtr );
  }
}
Beispiel #9
0
/***************************************************************************************************
 * @fn          nwk_MTCallbackSubDataIndication
 *
 * @brief       Process the callback subscription for NLDE-DATA.indication
 *
 * @param       SrcAddress      - 16 bit address
 * @param       nsduLength      - Length of incoming data
 * @param       nsdu            - Pointer to incoming data
 * @param       LinkQuality     - Link quality measured during
 *                                reception.
 *
 * @return      none
 ***************************************************************************************************/
void nwk_MTCallbackSubDataIndication(uint16 SrcAddress, int16 nsduLength, uint8 *nsdu, uint8 LinkQuality)
{
  uint8 *msgPtr;
  uint8 *msg;
  uint8 msgLen;

  msgLen = sizeof( uint16 ) + sizeof( uint8 ) + ZTEST_DEFAULT_DATA_LEN
            + sizeof( uint8);

  msgPtr = osal_mem_alloc( msgLen );
  if ( msgPtr )
  {
    //Fill up the data bytes
    msg = msgPtr;

    //First fill in details
    *msg++ = LO_UINT16( SrcAddress );
    *msg++ = HI_UINT16( SrcAddress );

    //Since the max packet size is less than 255 bytes, a byte is enough
    //to represent nsdu length
    *msg++ = ( uint8 ) nsduLength;

    osal_memset( msg, NULL, ZTEST_DEFAULT_DATA_LEN ); // Clear the mem
    osal_memcpy( msg, nsdu, nsduLength );
    msg += ZTEST_DEFAULT_DATA_LEN;

    *msg++ = LinkQuality;

    MT_BuildAndSendZToolResponse( ((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_NWK), MT_NLDE_DATA_IND, msgLen, msgPtr );

    osal_mem_free( msgPtr );
  }
}
/*********************************************************************
 * @fn      zclSS_Send_IAS_ACE_BypassCmd
 *
 * @brief   Call to send out a Bypass Command  ( IAS ACE Cluster )
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   numberOfZones - one byte
 * @param   bypassBuf - zone IDs array of 256 entries one byte each
 *
 * @return  ZStatus_t
 */
ZStatus_t zclSS_Send_IAS_ACE_BypassCmd( uint8 srcEP, afAddrType_t *dstAddr,
                                        uint8 numberOfZones, uint8 *bypassBuf,
                                        uint8 disableDefaultRsp, uint8 seqNum )
{
    uint8 *buf;
    uint8 *pBuf;
    uint8 len = 1 + numberOfZones;
    ZStatus_t stat;

    buf = osal_mem_alloc( len );
    if ( buf )
    {
        pBuf = buf;

        *pBuf++ = numberOfZones;
        osal_memcpy( pBuf, bypassBuf, numberOfZones );

        stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_SS_IAS_ACE,
                                COMMAND_SS_IAS_ACE_BYPASS, TRUE,
                                ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, len, buf );
        osal_mem_free( buf );
    }
    else
        stat = ZFailure;

    return ( stat );
}
Beispiel #11
0
/***************************************************************************************************
 * @fn          zb_MTCallbackReceiveDataIndication
 *
 * @brief       Process the callback subscription for zb_ReceiveDataIndication
 *
 * @param
 *
 * @return      none
 ***************************************************************************************************/
void zb_MTCallbackReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData  )
{
  uint8 *memPtr;
  int8 i;
  uint8 msgLen = 6 + len;

  memPtr = osal_mem_alloc(msgLen);

  if (memPtr)
  {
    memPtr[0] = LO_UINT16(source);
    memPtr[1] = HI_UINT16(source);
    memPtr[2] = LO_UINT16(command);
    memPtr[3] = HI_UINT16(command);
    memPtr[4] = LO_UINT16(len);
    memPtr[5] = HI_UINT16(len);

    for (i=0; i<len; i++)
    {
      memPtr[6+i] = pData[i];
    }

    /* Build and send back the response */
    MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_SAPI), MT_SAPI_RCV_DATA_IND, msgLen, memPtr);

    osal_mem_free( memPtr );
  }
}
Beispiel #12
0
/***************************************************************************************************
 * @fn      MT_AfRegister
 *
 * @brief   Process AF Register command
 *
 * @param   pBuf - pointer to the received buffer
 *
 * @return  none
 ***************************************************************************************************/
void MT_AfRegister(uint8 *pBuf)
{
  uint8 cmdId;
  uint8 retValue = ZMemError;
  endPointDesc_t *epDesc;

  /* parse header */
  cmdId = pBuf[MT_RPC_POS_CMD1];
  pBuf += MT_RPC_FRAME_HDR_SZ;

  epDesc = (endPointDesc_t *)osal_mem_alloc(sizeof(endPointDesc_t));
  if ( epDesc )
  {
    epDesc->task_id = &MT_TaskID;
    retValue = MT_BuildEndpointDesc( pBuf, epDesc );
    if ( retValue == ZSuccess )
    {
      retValue = afRegister( epDesc );
    }

    if ( retValue != ZSuccess )
    {
      osal_mem_free( epDesc );
    }
  }

  /* Build and send back the response */
  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_AF), cmdId, 1, &retValue);
}
Beispiel #13
0
/*********************************************************************
 * @fn      osal_bm_free
 *
 * @brief   Implementation of the de-allocator functionality.
 *
 * @param   payload_ptr - pointer to the memory to free.
 *
 * @return  none
 */
void osal_bm_free( void *payload_ptr )
{
  bm_desc_t *loop_ptr;
  bm_desc_t *prev_ptr = NULL;
  
  loop_ptr = bm_list_ptr;
  while ( loop_ptr != NULL )
  {
    if ( payload_ptr >= (void *)START_PTR( loop_ptr ) &&
         payload_ptr <= (void *)END_PTR( loop_ptr) )
    {
      // unlink item from the linked list
      if ( prev_ptr == NULL )
      {
        // it's the first item on the list
        bm_list_ptr = loop_ptr->next_ptr;
      }
      else
      {
        prev_ptr->next_ptr = loop_ptr->next_ptr;
      }

      // free the memory
      osal_mem_free( loop_ptr );

      // we're done here
      break;
    }
    
    // move on to next item
    prev_ptr = loop_ptr;
    loop_ptr = loop_ptr->next_ptr;
  }
}
Beispiel #14
0
/*******************************************************************************
 * @fn      zclPI_Send_11073TransferAPDUCmd
 *
 * @brief   Call to send out an 11073 Transfer APDU Command. This command is 
 *          used when an 11073 network layer wishes to transfer an 11073 APDU 
 *          across a ZigBee tunnel to another 11073 network layer.
 *
 *          The most stringent reliability characteristic of a given transport
 *          technology is “Best” reliability. Note - For ZigBee, this corresponds
 *          to use of APS-ACKs.
 *
 *          The least stringent reliability characteristic of a given transport
 *          technology is “Good” reliability. Note - For ZigBee, this corresponds
 *          to no use of APS-ACKs.
 *
 *          Note: This command shall always be transmitted with the Disable Default 
 *          Response bit in the ZCL frame control field set to 1.
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   len - length of APDU
 * @param   apdu - APDU to be sent
 * @param   seqNum - sequence number
 *
 * @return  ZStatus_t
 */
ZStatus_t zclPI_Send_11073TransferAPDUCmd( uint8 srcEP, afAddrType_t *dstAddr,
                                           uint16 len, uint8 *apdu, uint8 seqNum )
{
  uint8 *buf;
  ZStatus_t stat;

  buf = osal_mem_alloc( len+2 ); // 2 for length field (long octet string)
  if ( buf )
  {  
    buf[0] = LO_UINT16( len );
    buf[1] = HI_UINT16( len );
    osal_memcpy( &(buf[2]), apdu, len );

    // This command shall always be transmitted with the Disable Default 
    // Response bit in the ZCL frame control field set to 1.
    stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL,
                            COMMAND_PI_11073_TUNNEL_TRANSFER_APDU, TRUE, 
                            ZCL_FRAME_CLIENT_SERVER_DIR, TRUE, 0, seqNum, (len+2), buf );
    osal_mem_free( buf );
  }
  else
  {
    stat = ZMemError;
  }
  
  return ( stat );
}
Beispiel #15
0
/*******************************************************************************
 * @fn      zclPI_Send_MatchProtocolAddrRsp
 *
 * @brief   Call to send out a Match Protocol Address Response. This response
 *          is sent back upon receipt of a Match Protocol Address command to
 *          indicate that the Protocol Address was successfully matched.
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   ieeeAddr - device address
 * @param   len - length of protocol address
 * @param   protocolAddr - protocol address
 * @param   disableDefaultRsp - whether to disable the Default Response command
 * @param   seqNum - sequence number
 *
 * @return  ZStatus_t
 */
ZStatus_t zclPI_Send_MatchProtocolAddrRsp( uint8 srcEP, afAddrType_t *dstAddr,
                                           uint8 *ieeeAddr, uint8 len, uint8 *protocolAddr, 
                                           uint8 disableDefaultRsp, uint8 seqNum )
{
  uint8 *buf;
  uint8 msgLen = Z_EXTADDR_LEN + 1 + len; // IEEE Address + 1 for length field
  ZStatus_t stat;

  buf = osal_mem_alloc( msgLen ); // 1 for length field
  if ( buf )
  {
    // Copy over IEEE Address
    osal_cpyExtAddr( buf, ieeeAddr );

    // Copy over Protocol Address
    buf[8] = len;
    osal_memcpy( &(buf[9]), protocolAddr, len );

    stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
                            COMMAND_PI_GENERIC_TUNNEL_MATCH_PROTOCOL_ADDR_RSP, TRUE, 
                            ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum,
                            msgLen, buf );
    osal_mem_free( buf );
  }
  else
  {
    stat = ZMemError;
  }
  
  return ( stat );
}
/*********************************************************************
 * @fn      zclSS_Send_IAS_ACE_GetZoneIDMapResponseCmd
 *
 * @brief   Call to send out a Get Zone ID Map Response Cmd  ( IAS ACE Cluster )
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   zoneIDMap - pointer to an array of 16 uint16
 *
 * @return  ZStatus_t
 */
ZStatus_t zclSS_Send_IAS_ACE_GetZoneIDMapResponseCmd( uint8 srcEP, afAddrType_t *dstAddr,
        uint16 *zoneIDMap, uint8 disableDefaultRsp, uint8 seqNum )
{
    uint8 *buf;
    uint8 *pIndex;
    uint8 j,len = 32;
    ZStatus_t stat;

    buf = osal_mem_alloc( len );

    if ( buf )
    {
        pIndex = buf;

        for( j = 0; j < 16; j++ )
        {
            *pIndex++  = LO_UINT16( *zoneIDMap   );
            *pIndex++  = HI_UINT16( *zoneIDMap++ );
        }

        stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_SS_IAS_ACE,
                                COMMAND_SS_IAS_ACE_GET_ZONE_ID_MAP_RESPONSE, TRUE,
                                ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum, len, buf );
        osal_mem_free( buf );
    }
    else
        stat = ZMemError;

    return ( stat );

}
/*******************************************************************************
 * @fn      zclSS_Send_IAS_ACE_GetZoneInformationResponseCmd
 *
 * @brief   Call to send out Get Zone Information Response Cmd (IAS ACE Cluster)
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   zoneID - 8 bit value from 0 to 255
 * @param   zoneType - 16 bit
 * @param   ieeeAddress - pointer to 64 bit address ( 8bytes*8)
 *
 * @return  ZStatus_t
 */
ZStatus_t zclSS_Send_IAS_ACE_GetZoneInformationResponseCmd( uint8 srcEP, afAddrType_t *dstAddr,
        uint8 zoneID, uint16 zoneType, uint8 *ieeeAddress,
        uint8 disableDefaultRsp, uint8 seqNum )
{
    uint8 *buf;
    uint8 len = 11; // zoneID (1) + zoneType (2) + zoneAddress (8)
    ZStatus_t stat;

    buf = osal_mem_alloc( len );

    if ( buf )
    {
        buf[0] = zoneID;
        buf[1] = LO_UINT16( zoneType);
        buf[2] = HI_UINT16( zoneType);
        osal_cpyExtAddr( &buf[3], ieeeAddress );

        stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_SS_IAS_ACE,
                                COMMAND_SS_IAS_ACE_GET_ZONE_INFORMATION_RESPONSE, TRUE,
                                ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum, len, buf );
        osal_mem_free( buf );
    }
    else
        stat = ZMemError;

    return ( stat );
}
Beispiel #18
0
/*********************************************************************
 * @fn      OADTarget_AddService
 *
 * @brief   Initializes the OAD Service by registering GATT attributes
 *          with the GATT server. Only call this function once.
 *
 * @return  The return value of GATTServApp_RegisterForMsg().
 */
bStatus_t OADTarget_AddService(void)
{
  // Allocate Client Characteristic Configuration table
  oadImgIdentifyConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                          linkDBNumConns);
  if (oadImgIdentifyConfig == NULL)
  {
    return ( bleMemAllocError );
  }
  
  // Allocate Client Characteristic Configuration table
  oadImgBlockConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                       linkDBNumConns);
  
  if (oadImgBlockConfig == NULL)
  {
    // Free already allocated data
    osal_mem_free( oadImgIdentifyConfig );
    
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgIdentifyConfig );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgBlockConfig );

  return GATTServApp_RegisterService(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl),
                                     GATT_MAX_ENCRYPT_KEY_SIZE, &oadCBs);
}
// 串口回调函数
static void simpleBLE_NpiSerialCallback( uint8 port, uint8 events )
{
    (void)port;
    
    if (events & (HAL_UART_RX_TIMEOUT | HAL_UART_RX_FULL))   //串口有数据
    {
        uint8 numBytes = 0;

        numBytes = NPI_RxBufLen();           //读出串口缓冲区有多少字节
        
        if(numBytes > 0)
        {
            uint8 *buffer = osal_mem_alloc(numBytes);            
            if(buffer)
            {
                // 读出串口数据
                NPI_ReadTransport(buffer,numBytes);  
#if 1
                // 作为测试, 把读到的数据也通过串口返回, 这只是一个test功能, 你可以把去掉
                NPI_WriteTransport(buffer,numBytes);  
#endif              
                osal_mem_free(buffer);
            }
        }
    }
}
/*********************************************************************
 * @fn      zclSS_RemoveZone
 *
 * @brief   Remove a zone with endpoint and zoneID
 *
 * @param   endpoint -
 * @param   zoneID - ID to look for zone
 *
 * @return  TRUE if removed, FALSE if not found
 */
uint8 zclSS_RemoveZone( uint8 endpoint, uint8 zoneID )
{
    zclSS_ZoneItem_t *pLoop;
    zclSS_ZoneItem_t *pPrev;

    // Look for end of list
    pLoop = zclSS_ZoneTable;
    pPrev = NULL;
    while ( pLoop )
    {
        if ( pLoop->endpoint == endpoint && pLoop->zone.zoneID == zoneID )
        {
            if ( pPrev == NULL )
                zclSS_ZoneTable = pLoop->next;
            else
                pPrev->next = pLoop->next;

            // Free the memory
            osal_mem_free( pLoop );

            return ( TRUE );
        }
        pPrev = pLoop;
        pLoop = pLoop->next;
    }

    return ( FALSE );
}
Beispiel #21
0
/*******************************************************************************
 * @fn      zclPI_Send_AdvertiseProtocolAddrCmd
 *
 * @brief   Call to send out an Advertise Protocol Address Command. This command
 *          is sent out typically upon startup or whenever the Protocol Address
 *          attribute changes. It is typically multicast to a group of inter-
 *          communicating Generic Tunnel clusters.
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   len - length of protocol address
 * @param   protocolAddr - protocol address
 * @param   disableDefaultRsp - whether to disable the Default Response command
 * @param   seqNum - sequence number
 *
 * @return  ZStatus_t
 */
ZStatus_t zclPI_Send_AdvertiseProtocolAddrCmd( uint8 srcEP, afAddrType_t *dstAddr,
                                               uint8 len, uint8 *protocolAddr, 
                                               uint8 disableDefaultRsp, uint8 seqNum )
{
  uint8 *buf;
  ZStatus_t stat;

  buf = osal_mem_alloc( len+1 ); // 1 for length field
  if ( buf )
  {  
    buf[0] = len;
    osal_memcpy( &(buf[1]), protocolAddr, len );

    stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
                            COMMAND_PI_GENERIC_TUNNEL_ADVERTISE_PROTOCOL_ADDR, TRUE, 
                            ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum,
                            (len+1), buf );
    osal_mem_free( buf );
  }
  else
  {
    stat = ZMemError;
  }
  
  return ( stat );
}
Beispiel #22
0
/***************************************************************************************************
 * @fn      MT_AppPB_ZCLInd
 *
 * @brief   Send an MT_APP_PB_ZCL_IND command
 *
 * @param   pInd - pointer to the indication
 *
 * @return  void
 ***************************************************************************************************/
void MT_AppPB_ZCLInd( mtAppPB_ZCLInd_t *pInd )
{
  uint8 *pData;
  uint8 *pBuf;
  uint8 len;

  len = MT_APP_PB_ZCL_IND_HDR_LEN + pInd->appPBDataLen;

  pData = (uint8 *)osal_mem_alloc( len );
  if ( pData != NULL )
  {
    pBuf = pData;
    *pBuf++ = pInd->appEP;
    *pBuf++ = LO_UINT16( pInd->srcAddr );
    *pBuf++ = HI_UINT16( pInd->srcAddr );
    *pBuf++ = pInd->srcEP;
    *pBuf++ = LO_UINT16( pInd->clusterID );
    *pBuf++ = HI_UINT16( pInd->clusterID );
    *pBuf++ = pInd->commandID;
    *pBuf++ = pInd->specific;
    *pBuf++ = pInd->direction;
    *pBuf++ = pInd->disableDefRsp;
    *pBuf++ = LO_UINT16( pInd->manuCode );
    *pBuf++ = HI_UINT16( pInd->manuCode );
    *pBuf++ = pInd->transSeqNum;
    osal_memcpy( pBuf, pInd->appPBData, pInd->appPBDataLen );

    MT_BuildAndSendZToolResponse( ( (uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_APP ),
                                  MT_APP_PB_ZCL_IND, len, pData );
    osal_mem_free( pData );
  }
}
Beispiel #23
0
/*******************************************************************************
 * @fn      zclPI_Send_11073ConnectReq
 *
 * @brief   Call to send out an 11073 Connect Request Command. This command
 *          is generated when a Data Management device wishes to connect to
 *          an 11073 agent device. This may be in response to receiving a 
 *          connect status notification command from that agent device with
 *          the connect status field set to RECONNECT_REQUEST.
 *
 * @param   srcEP - Sending application's endpoint
 * @param   dstAddr - where you want the message to go
 * @param   connectCtrl - connect control
 * @param   idleTimeout - inactivity time (in minutes) which Data Management device
 *                        will wait w/o receiving any data before it disconnects
 * @param   managerAddr - IEEE address (64-bit) of Data Management device 
 *                        transmitting this frame
 * @param   managerEP - source endpoint from which Data Management device is
                        transmitting this frame
 * @param   disableDefaultRsp - whether to disable the Default Response command
 * @param   seqNum - sequence number
 *
 * @return  ZStatus_t
 */
ZStatus_t zclPI_Send_11073ConnectReq( uint8 srcEP, afAddrType_t *dstAddr,
                                      uint8 connectCtrl, uint16 idleTimeout,
                                      uint8 *managerAddr, uint8 managerEP, 
                                      uint8 disableDefaultRsp, uint8 seqNum )
{
  uint8 *buf;
  uint8 msgLen = 1 + 2 + Z_EXTADDR_LEN + 1; // connect ctrl + idle timeout + IEEE Address + manager EP
  ZStatus_t stat;

  buf = osal_mem_alloc( msgLen );
  if ( buf )
  {
    buf[0] = connectCtrl;
    buf[1] = LO_UINT16( idleTimeout );
    buf[2] = HI_UINT16( idleTimeout );
    osal_memcpy( &(buf[3]), managerAddr, Z_EXTADDR_LEN );
    buf[11] = managerEP;

    stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL,
                            COMMAND_PI_11073_TUNNEL_CONNECT_REQ, TRUE, 
                            ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum,
                            msgLen, buf );
    osal_mem_free( buf );
  }
  else
  {
    stat = ZMemError;
  }
  
  return ( stat );
}
Beispiel #24
0
 /***************************************************************************************************
 * @fn      MT_ZllNotifyTL
 *
 * @brief   Process and send Indication for a successful ZLL Touch-Link over MT_APP.
 *
 * @param   pRec - Target's information record
 *
 * @return  none
 ***************************************************************************************************/
void MT_ZllNotifyTL( epInfoRec_t *pRec )
{
  byte *pBuf;
  pBuf = osal_mem_alloc( ZLL_CMDLENOPTIONAL_GET_EP_LIST_RSP ); // endpoint information record entry
  if ( pBuf )
  {
    pBuf[0] = LO_UINT16( pRec->nwkAddr );
    pBuf[1] = HI_UINT16( pRec->nwkAddr );

    pBuf[2] = pRec->endpoint;

    pBuf[3] = LO_UINT16( pRec->profileID );
    pBuf[4] = HI_UINT16( pRec->profileID );

    pBuf[5] = LO_UINT16( pRec->deviceID );
    pBuf[6] = HI_UINT16( pRec->deviceID );

    pBuf[7] = pRec->version;

    /* Send out Reset Response message */
    MT_BuildAndSendZToolResponse( ((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_APP),
                                   MT_APP_ZLL_TL_IND,
                                   ZLL_CMDLENOPTIONAL_GET_EP_LIST_RSP, pBuf );

    osal_mem_free( pBuf );
  }
}
void AT_AF_Cmd_REPPRINT_req(afIncomingMSGPacket_t *pkt ){
  const uint8 AT_CMD_EP_ARRAY[] = AT_CMD_EPs;
  uint8 epNum = afNumEndPoints()-1;
  byte* epBuf = (byte*)  osal_mem_alloc(epNum);
  if(epBuf==NULL) return;
  afEndPoints( epBuf, true);
  AT_sort_arr(epBuf,epNum);
  
  //the epStatus store the search result
  uint8 pbuf_temp[sizeof(AT_CMD_EP_ARRAY)+sizeof(AT_AF_hdr)];
  AT_AF_Cmd_REPPRINT_rsp_t* pbuf = (AT_AF_Cmd_REPPRINT_rsp_t*)pbuf_temp;
  pbuf->hdr.cmd=AT_AF_Cmd_rsp;
  pbuf->hdr.numItem=AT_CMD_EPs_Num;
  
  int i,j;
  for(i=0,j=0;j<AT_CMD_EPs_Num;j++){
    if(epBuf[i]==AT_CMD_EP_ARRAY[j]){
      pbuf->status[j] = AT_AF_enable;
      i++;
    }
    else pbuf->status[j] = AT_AF_disable;
  }
  osal_mem_free(epBuf);
  AF_DataRequest( & (pkt->srcAddr), & AT_AF_epDesc,
                       AT_AF_Cmd_REPPRINT_CLUSTERID,
                       sizeof(AT_CMD_EP_ARRAY)+sizeof(AT_AF_hdr),
                       (uint8*)pbuf,
                       &AT_AF_TransID,
                       AF_DISCV_ROUTE,
                       AF_DEFAULT_RADIUS );
  
}
Beispiel #26
0
/*********************************************************************
 * @fn      OTA_ProcessZDOMsgs
 *
 * @brief   Process messages from the ZDO layer.
 *
 * @param   pMsg - The message from the server.
 *
 * @return  none
 */
void OTA_ProcessZDOMsgs(zdoIncomingMsg_t * pMsg)
{
    if (pMsg)
    {
        if (pMsg->clusterID == Match_Desc_rsp)
        {
            ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );

            if (pRsp)
            {
                // Notify the console application of the client device's OTA endpoint
                if (pRsp->cnt)
                    OTA_Send_EndpointInd(pRsp->nwkAddr, pRsp->epList[0]);

                osal_mem_free(pRsp);
            }
        }
        else if (pMsg->clusterID == Device_annce)
        {
            cId_t otaCluster = ZCL_CLUSTER_ID_OTA;
            zAddrType_t dstAddr;

            ZDO_DeviceAnnce_t devAnnce;
            ZDO_ParseDeviceAnnce(pMsg, &devAnnce);
            OTA_Send_DeviceInd(devAnnce.nwkAddr);

            // Send out a match for the OTA cluster ID
            dstAddr.addrMode = Addr16Bit;
            dstAddr.addr.shortAddr = devAnnce.nwkAddr;
            ZDP_MatchDescReq( &dstAddr, devAnnce.nwkAddr, ZCL_OTA_SAMPLE_PROFILE_ID,
                              0, NULL, 1, &otaCluster, FALSE );
        }
    }
}
Beispiel #27
0
/**************************************************************************************************
 * @fn          MT_AfDataStore
 *
 * @brief   Process AF Data Store command to incrementally store the data buffer for very large
 *          outgoing AF message.
 *
 * input parameters
 *
 * @param pBuf - pointer to the received buffer
 *
 * output parameters
 *
 * @param rtrn - AF-Status of the operation.
 *
 * @return      None.
 **************************************************************************************************
 */
void MT_AfDataStore(uint8 *pBuf)
{
  uint16 idx;
  uint8 len, rtrn = afStatus_FAILED;

  pBuf += MT_RPC_FRAME_HDR_SZ;
  idx = BUILD_UINT16(pBuf[0], pBuf[1]);
  len = pBuf[2];
  pBuf += 3;

  if (pMtAfDataReq == NULL)
  {
    rtrn = afStatus_MEM_FAIL;
  }
  else if (len == 0)  // Indication to send the message.
  {
    rtrn = AF_DataRequest(&(pMtAfDataReq->dstAddr), pMtAfDataReq->epDesc, pMtAfDataReq->cId,
                            pMtAfDataReq->dataLen,  pMtAfDataReq->data,
                          &(pMtAfDataReq->transId), pMtAfDataReq->txOpts, pMtAfDataReq->radius);
    (void)osal_mem_free(pMtAfDataReq);
    pMtAfDataReq = NULL;
  }
  else
  {
    (void)osal_memcpy(pMtAfDataReq->data+idx, pBuf, len);
    rtrn = afStatus_SUCCESS;
  }

  MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_AF),
                                                                MT_AF_DATA_STORE, 1, &rtrn);
}
Beispiel #28
0
/*********************************************************************
 * @fn      OTA_Dongle_ProcessIncomingMsg
 *
 * @brief   Process ZCL Foundation incoming message
 *
 * @param   pInMsg - pointer to the received message
 *
 * @return  none
 */
static void OTA_Dongle_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg)
{
    switch ( pInMsg->zclHdr.commandID )
    {
#ifdef ZCL_READ
    case ZCL_CMD_READ_RSP:
        OTA_Dongle_ProcessInReadRspCmd( pInMsg );
        break;
#endif
#ifdef ZCL_WRITE
    case ZCL_CMD_WRITE_RSP:
        OTA_Dongle_ProcessInWriteRspCmd( pInMsg );
        break;
#endif
    case ZCL_CMD_DEFAULT_RSP:
        OTA_Dongle_ProcessInDefaultRspCmd( pInMsg );
        break;
#ifdef ZCL_DISCOVER
    case ZCL_CMD_DISCOVER_RSP:
        OTA_Dongle_ProcessInDiscRspCmd( pInMsg );
        break;
#endif
    default:
        break;
    }

    if ( pInMsg->attrCmd )
        osal_mem_free( pInMsg->attrCmd );
}
/*********************************************************************
 * @fn      loadcontrol_ProcessZCLMsg
 *
 * @brief   Process ZCL Foundation incoming message
 *
 * @param   pInMsg - message to process
 *
 * @return  none
 */
static void loadcontrol_ProcessZCLMsg( zclIncomingMsg_t *pInMsg )
{
  switch ( pInMsg->zclHdr.commandID )
  {
#if defined ( ZCL_READ )
    case ZCL_CMD_READ_RSP:
      loadcontrol_ProcessInReadRspCmd( pInMsg );
      break;
#endif // ZCL_READ
#if defined ( ZCL_WRITE )
    case ZCL_CMD_WRITE_RSP:
      loadcontrol_ProcessInWriteRspCmd( pInMsg );
      break;
#endif // ZCL_WRITE
    case ZCL_CMD_DEFAULT_RSP:
      loadcontrol_ProcessInDefaultRspCmd( pInMsg );
      break;
#if defined ( ZCL_DISCOVER )
    case ZCL_CMD_DISCOVER_RSP:
      loadcontrol_ProcessInDiscRspCmd( pInMsg );
      break;
#endif // ZCL_DISCOVER
    default:
      break;
  }

  if ( pInMsg->attrCmd != NULL )
  {
    // free the parsed command
    osal_mem_free( pInMsg->attrCmd );
    pInMsg->attrCmd = NULL;
  }
}
Beispiel #30
0
/********************************************************************************************************
 * @fn      ZMacReset
 *
 * @brief   Reset the MAC.
 *
 * @param   Default to PIB defaults.
 *
 * @return  status.
 ********************************************************************************************************/
uint8 ZMacReset( uint8 SetDefaultPIB )
{
  byte stat;
  byte value;

  stat = MAC_MlmeResetReq( SetDefaultPIB );

  // Don't send PAN ID conflict
  value = FALSE;
  MAC_MlmeSetReq( MAC_ASSOCIATED_PAN_COORD, &value );
#ifdef FEATURE_DUAL_MAC
  {
    uint8 aExtendedAddress[8] = { 0};
    if ( SUCCESS == DMMGR_GetExtAddr( aExtendedAddress) ) 
    {
      MAC_MlmeSetReq( MAC_EXTENDED_ADDRESS, &aExtendedAddress );
    }
  }
#else
  MAC_MlmeSetReq( MAC_EXTENDED_ADDRESS, &aExtendedAddress );
#endif /* FEATURE_DUAL_MAC */

  if (ZMac_ScanBuf)
  {
    osal_mem_free(ZMac_ScanBuf);
    ZMac_ScanBuf = NULL;
  }

  return ( stat );
}