コード例 #1
0
static void MHMSUartRx(uint8 port, uint8 event)
{

  uint8 ch[5];
  
  HalUARTRead(MHMS_PORT, ch, 5);
  
  dev_gateway = TRUE;   //flag that device is acting as device
  if (ch[2]==0x21)   //if statement to check for command from Mobile Health Monitor Software 
  {
    sysPingRsp(); //Ping sent back to Mobile Health Monitor Software 
    //syncAttempted=TRUE;
    zapSync();      
    if(znpPanId == INVALID_PAN_ID){
      //if still invalid id, there is no PAN so set one up by becoming the coordinator
     if(zap_set_logicalType(ZG_DEVICETYPE_COORDINATOR)){
      HalLcdWriteString("Initilizing NWK...",HAL_LCD_LINE_7);
     }    
     else{
      HalLcdWriteString("Problem",HAL_LCD_LINE_7);
     }
    }
    else{
      MHMSAddr = znpAddr;
    if (ZSuccess != osal_start_timerEx(MHMSTaskId, MHMS_EVT_ANN, MHMS_DLY_ANN))
      {
        (void)osal_set_event(MHMSTaskId, MHMS_EVT_ANN);
      }
    }
  }

}
コード例 #2
0
ファイル: MT_UART.c プロジェクト: kobefaith/zigbee
void readbuf(void)//拿出来的原因:因为只有在原来只有串口来数据才会将ID给pIDbuf,
//拿出来后就可以在初始化时调用这个函数所以在上电即可以提取ID,可以进行测试。
{
    uint8 i; 
    rbuf=osal_mem_alloc(rxlen+9);  //多分配1字节,分配如下  
    
    rbuf[0]=rxlen+8;                                     //一字节存放数据长度
    
    rbuf[1]=73;                                          //字符:I
    rbuf[2]=68;                                          //字符:D
    rbuf[3]=58;                                          //字符: :
    Setid();
    rbuf[4]=(uint8)((zgID&0xf000)>>12)+48;                   //1
    rbuf[5]=(uint8)((zgID&0x0f00)>>8)+48;                    //2
    rbuf[6]=(uint8)((zgID&0x00f0)>>4)+48;                    //3
    rbuf[7]=(uint8)(zgID&0x000f)+48;                         //4
    rbuf[8]='\n';
    
    buflen=rxlen+9;//获得rbuf的长度,放在buflen中,在SampleApp中直接调用
    
    for(i=0;i<5;i++)//提取设备ID,存放在数组IDbuf中,本地显示
    {
      IDbuf[i]=rbuf[4+i];//从rbuf[4]开始提取
    }    
    for(i=0;i<4;i++)//发送出去作为测试用
    {
      pIDbuf[i]=IDbuf[i];
    }
    pIDbuf[4]=rbuf[8];   //最后存放了换行符 
    HalUARTRead ( SERIAL_APP_PORT, rbuf+9, rxlen); //读接收缓冲区数据到内存rbuf+9
}
コード例 #3
0
ファイル: MT_UART.c プロジェクト: MenGe4ZB/CDSiHan
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
  uint8 flag=0,i,j=0;   //flag是判断有没有收到数据,j记录数据长度
  uint8 buf[128];     //串口buffer最大缓冲默认是128,我们这里用128.
  (void)event;        // Intentionally unreferenced parameter  

  while (Hal_UART_RxBufLen(port)) //检测串口数据是否接收完成

  {
    HalUARTRead (port,&buf[j], 1);  //把数据接收放到buf中
    j++;                           //记录字符数
    flag=1;                         //已经从串口接收到信息
  } 

  if(flag==1)       //已经从串口接收到信息

  {     /* Allocate memory for the data */
	    //分配内存空间,为机构体内容+数据内容+1个记录长度的数据
   pMsg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof  
          ( mtOSALSerialData_t )+j+1);
  //事件号用原来的CMD_SERIAL_MSG
  pMsg->hdr.event = CMD_SERIAL_MSG;
  pMsg->msg = (uint8*)(pMsg+1);  // 把数据定位到结构体数据部分
  pMsg->msg [0]= j;              //给上层的数据第一个是长度
  for(i=0;i<j;i++)                //从第二个开始记录数据 
  pMsg->msg [i+1]= buf[i];   
  osal_msg_send( App_TaskID, (byte *)pMsg );  //登记任务,发往上层
  /* deallocate the msg */
  osal_msg_deallocate ( (uint8 *)pMsg );      //释放内存
  }
}
コード例 #4
0
ファイル: SerialApp.c プロジェクト: kricnam/blackboxreader
/*********************************************************************
 * @fn      rxCB_Loopback
 *
 * @brief   Process UART Rx event handling.
 *          May be triggered by an Rx timer expiration - less than max
 *          Rx bytes have arrived within the Rx max age time.
 *          May be set by failure to alloc max Rx byte-buffer for the DMA Rx -
 *          system resources are too low, so set flow control?
 *
 * @param   none
 *
 * @return  none
 */
static void rxCB_Loopback( uint8 port, uint8 event )
{

  if ( rxLen )
  {
    if ( !HalUARTWrite( SERIAL_APP_PORT, rxBuf, rxLen ) )
    {
      osal_start_timerEx( SerialApp_TaskID, SERIALAPP_TX_RTRY_EVT,
                                            SERIALAPP_TX_RTRY_TIMEOUT );
      return;
    }
    else
    {
      osal_stop_timerEx( SerialApp_TaskID, SERIALAPP_TX_RTRY_EVT );
    }
  }

  // HAL UART Manager will turn flow control back on if it can after read.
  if ( !(rxLen = HalUARTRead( port, rxBuf, SERIAL_APP_RX_CNT )) )
  {
    return;
  }

  if ( HalUARTWrite( SERIAL_APP_PORT, rxBuf, rxLen ) )
  {
    rxLen = 0;
  }
  else
  {
    osal_start_timerEx( SerialApp_TaskID, SERIALAPP_TX_RTRY_EVT,
                                          SERIALAPP_TX_RTRY_TIMEOUT );
  }
}
コード例 #5
0
ファイル: ECGSensor.c プロジェクト: nevinxu/HM502B1
void uart_rx_cback(uint8 port, uint8 event)
{
  uint8 SerialApp_TxLen;
  uint8 usbEvent = event;
  switch(usbEvent)
  {
  case HAL_UART_RX_FULL:
    
  case HAL_UART_RX_ABOUT_FULL:
    
  case HAL_UART_RX_TIMEOUT:
//    delay(1);//防止不丢数据
    SerialApp_TxLen = HalUARTRead(HAL_UART_PORT, SerialApp_Buf, 50);
    if(SerialApp_TxLen)
    {     
      
    }
    break;
    
  case HAL_UART_TX_FULL:
    break;
    
  case HAL_UART_TX_EMPTY:
    break;
    
  default:
    break;
  }
}
コード例 #6
0
ファイル: MT_UART.c プロジェクト: TemcoLijun/Zigbee_Modules
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
  uint8  ch;
  
  (void)event;  // Intentionally unreferenced parameter

  while (Hal_UART_RxBufLen(port))
  {
    // while length of RX buffer is not none, read one byte and put into global variable TxBuffer
    HalUARTRead (port, &ch, 1);
 //   TxBuffer.buf[TxBuffer.size++] = ch;
  }
  
#if defined START_ROUTER
  // if start device as a router, check length of buffer, once size bigger than 3, send the event to user task
  if ( len_check_flag )
  {
    if( TxBuffer.size >= (reg_len*2 + 5))
    {
        osal_set_event( GenericApp_TaskID, TX_MSG_EVENT );
    }
  }
  else
  {
    osal_set_event( GenericApp_TaskID, TX_MSG_EVENT );
  }
#endif
}
コード例 #7
0
ファイル: sbl_exec.c プロジェクト: billy-wang/IOT
/**************************************************************************************************
 * @fn          sblPoll
 *
 * @brief       Serial Boot poll & parse according to the RPC protocol.
 *
 * input parameters
 *
 * None.
 *
 * output parameters
 *
 * None.
 *
 * @return      TRUE if the downloaded code has been enabled; FALSE otherwise.
 */
uint8 sblPoll(void)
{
  uint8 ch;

  while (HalUARTRead(0, &ch, 1))
  {
    switch (rpcSte)
    {
    case rpcSteSOF:
      if (RPC_UART_SOF == ch)
      {
        rpcSte = rpcSteLen;
      }
      break;

    case rpcSteLen:
      if (ch > SBL_MAX_SIZE)
      {
        rpcSte = rpcSteSOF;
        break;
      }
      else
      {
        rpcSte = rpcSteData;
        sbFcs = sbIdx = 0;
        sbLen = ch + 3;  // Combine the parsing of Len, Cmd0 & Cmd1 with the data.
        // no break;
      }

    case rpcSteData:
      sbFcs ^= ch;
      sbBuf[sbIdx] = ch;

      if (++sbIdx == sbLen)
      {
        rpcSte = rpcSteFcs;
      }
      break;

    case rpcSteFcs:
      rpcSte = rpcSteSOF;

      if ((sbFcs == ch) && ((sbBuf[RPC_POS_CMD0] & RPC_SUBSYSTEM_MASK) == RPC_SYS_BOOT))
      {
        sblProc();
        return sblResp();  // Send the SB response setup in the sbBuf passed to sblProc().
      }
      break;

    default:
      HAL_SYSTEM_RESET();
      break;
    }
  }

  return FALSE;
}
コード例 #8
0
void zclHomelink_UARTCallback(uint8 port, uint8 event)
{
  uint8 ch;
  while (Hal_UART_RxBufLen(port))
  {
    HalUARTRead (port, &ch, 1);
  }
  HalUARTWrite(HAL_UART_PORT_0, (uint8 *)"\r", 1);
}
コード例 #9
0
ファイル: MT_UART.c プロジェクト: flofeurstein/MTProj
/***************************************************************************************************
 * @fn      MT_UartProcessZAppData
 *
 * @brief   | SOP | CMD  |   Data Length   | FSC  |
 *          |  1  |  2   |       1         |  1   |
 *
 *          Parses the data and determine either is SPI or just simply serial data
 *          then send the data to correct place (MT or APP)
 *
 * @param   port    - UART port
 *          event   - Event that causes the callback
 *
 *
 * @return  None
 ***************************************************************************************************/
void MT_UartProcessZAppData ( uint8 port, uint8 event )
{

  osal_event_hdr_t  *msg_ptr;
  uint16 length = 0;
  uint16 rxBufLen  = Hal_UART_RxBufLen(MT_UART_DEFAULT_PORT);

  /*
     If maxZAppBufferLength is 0 or larger than current length
     the entire length of the current buffer is returned.
  */
  if ((MT_UartMaxZAppBufLen != 0) && (MT_UartMaxZAppBufLen <= rxBufLen))
  {
    length = MT_UartMaxZAppBufLen;
  }
  else
  {
    length = rxBufLen;
  }

  /* Verify events */
  if (event == HAL_UART_TX_FULL)
  {
    // Do something when TX if full
    return;
  }

  if (event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
  {
    if ( App_TaskID )
    {
      /*
         If Application is ready to receive and there is something
         in the Rx buffer then send it up
      */
      if ((MT_UartZAppRxStatus == MT_UART_ZAPP_RX_READY ) && (length != 0))
      {
        /* Disable App flow control until it processes the current data */
         MT_UartAppFlowControl (MT_UART_ZAPP_RX_NOT_READY);

        /* 2 more bytes are added, 1 for CMD type, other for length */
        msg_ptr = (osal_event_hdr_t *)osal_msg_allocate( length + sizeof(osal_event_hdr_t) );
        if ( msg_ptr )
        {
          msg_ptr->event = SPI_INCOMING_ZAPP_DATA;
          msg_ptr->status = length;

          /* Read the data of Rx buffer */
          HalUARTRead( MT_UART_DEFAULT_PORT, (uint8 *)(msg_ptr + 1), length );

          /* Send the raw data to application...or where ever */
          osal_msg_send( App_TaskID, (uint8 *)msg_ptr );
        }
      }
    }
  }
}
コード例 #10
0
static void UART_CallBack(uint8 port, uint8 event)
{
  (void)port;
  uint8 cmdbuff[1];
  if (event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
  {
    HalUARTRead(port, cmdbuff, 1);
    SendUART(cmdbuff,1);
  }
}
コード例 #11
0
ファイル: hal_uart.c プロジェクト: saiwaiyanyu/Zlight
void HalUARTReadAndFormate(uint8 port, uint8 *buf, uint16 len)
{
  (void)port;
  uint8 i;
  uint8 string[2];
  for(i = 0; i < len; i++)
  {
   HalUARTRead(port, string, 2);
   *buf++ = CharToValue(string);
  }
}
コード例 #12
0
ファイル: SerialApp.c プロジェクト: kricnam/blackboxreader
/*********************************************************************
 * @fn      rxCB
 *
 * @brief   Process UART Rx event handling.
 *          May be triggered by an Rx timer expiration - less than max
 *          Rx bytes have arrived within the Rx max age time.
 *          May be set by failure to alloc max Rx byte-buffer for the DMA Rx -
 *          system resources are too low, so set flow control?
 *
 * @param   none
 *
 * @return  none
 */
static void rxCB( uint8 port, uint8 event )
{
  uint8 *buf, len;

  /* While awaiting retries/response, only buffer 1 next buffer: otaBuf2.
   * If allow the DMA Rx to continue to run, allocating Rx buffers, the heap
   * will become so depleted that an incoming OTA response cannot be received.
   * When the Rx data available is not read, the DMA Rx Machine automatically
   * sets flow control off - it is automatically re-enabled upon Rx data read.
   * When the back-logged otaBuf2 is sent OTA, an Rx data read is scheduled.
   */
  if ( otaBuf2 )
  {
    return;
  }

  if ( !(buf = osal_mem_alloc( SERIAL_APP_RX_CNT )) )
  {
    return;
  }

  /* HAL UART Manager will turn flow control back on if it can after read.
   * Reserve 1 byte for the 'sequence number'.
   */
  len = HalUARTRead( port, buf+1, SERIAL_APP_RX_CNT-1 );
  
  if ( !len )  // Length is not expected to ever be zero.
  {
    osal_mem_free( buf );
    return;
  }
  //else
  //  HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);

  /* If the local global otaBuf is in use, then either the response handshake
   * is being awaited or retries are being attempted. When the wait/retries
   * process has been exhausted, the next OTA msg will be attempted from
   * otaBuf2, if it is not NULL.
   */
  if ( otaBuf )
  {
    otaBuf2 = buf;
    otaLen2 = len;
  }
  else
  {
    otaBuf = buf;
    otaLen = len;
    /* Don't call SerialApp_SendData() from here in the callback function.
     * Set the event so SerialApp_SendData() runs during this task's time slot.
     */
    osal_set_event( SerialApp_TaskID, SERIALAPP_MSG_SEND_EVT );
  }
}
コード例 #13
0
ファイル: os.c プロジェクト: JBtje/BlueBasic
short OS_serial_read(unsigned char port)
{
  unsigned char ch;
  if (HalUARTRead(HAL_UART_PORT_0, &ch, 1) == 1)
  {
    return ch;
  }
  else
  {
    return -1;
  }
}
コード例 #14
0
ファイル: os.c プロジェクト: jun930/BlueBasic
unsigned char OS_serial_read(void)
{
  unsigned char ch;
  if (HalUARTRead(HAL_UART_PORT_0, &ch, 1) == 1)
  {
    return ch;
  }
  else
  {
    return 255;
  }
}
コード例 #15
0
ファイル: ParkingAppE.c プロジェクト: kk30/kdc
/*********************************************************************
 * @fn      SerialApp_CallBack
 *
 * @brief   Send data OTA.
 *
 * @param   port - UART port.
 * @param   event - the UART port event flag.
 *
 * @return  none
*********************************************************************/
static void SerialApp_CallBack(uint8 port, uint8 event)
{
  (void)port;
  uint8 rxbuf[SERIAL_APP_TX_MAX+1];

  if ((event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT)))
  {
    if (!SerialApp_TxLen)
      SerialApp_Send(port);
    else
      HalUARTRead(port, rxbuf, SERIAL_APP_TX_MAX);
//      HalUARTRead(SERIAL_APP_PORT, rxbuf, SERIAL_APP_TX_MAX);
  }
}
コード例 #16
0
ファイル: uApp.c プロジェクト: DRuffer/coinForth
/*********************************************************************
 * @fn      uApp_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   port - where the Rx data
 *          event - type of event
 *                  HAL_UART_RX_FULL
 *                  HAL_UART_RX_ABOUT_FULL
 *                  HAL_UART_RX_TIMEOUT      
 *                  HAL_UART_TX_FULL         
 *                  HAL_UART_TX_EMPTY        
 *
 * @return  none
 *********************************************************************/
void uApp_UartProcessRxData ( uint8 port, uint8 events )
{
    uint8 rxData[10] = {'\n'};
    uint16 totaluint8Read = 0;

	if (events & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
	{
        DebugMsg("Received UART Event:", events);
        totaluint8Read = HalUARTRead(0, rxData, 10);
        HalUARTWrite(0, rxData, totaluint8Read);
	}


}
コード例 #17
0
/*uart接收回调函数*/
void sbpSerialAppCallback(uint8 port, uint8 event)
{
  uint8  pktBuffer[SBP_UART_RX_BUF_SIZE];
  // unused input parameter; PC-Lint error 715.
  (void)event;
  HalLcdWriteString("Data form my UART:", HAL_LCD_LINE_4 );
  //返回可读的字节
  if ( (numBytes = Hal_UART_RxBufLen(port)) > 0 ){
  	//读取全部有效的数据,这里可以一个一个读取,以解析特定的命令
	(void)HalUARTRead (port, pktBuffer, numBytes);
	HalLcdWriteString(pktBuffer, HAL_LCD_LINE_5 );
	sbpSerialAppSendNoti(pktBuffer,numBytes);
  }
  
}
コード例 #18
0
ファイル: uart.c プロジェクト: golf2109/zigbee-in-supermaket
/*********************************************************************
 * @brief   Process all event form UART that connect to PC
 *
 * @param   - port of the UART
 *          - event code
 *
 * @return  none
 */
static void UART_PC_process_evt(uint8 port, uint8 event){
  
  (void) port;
  //read command from PC and then push it to pc_buff
  //if (event && (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL)){
  uint16 tmplen = Hal_UART_RxBufLen (UART_PC_PORT);
  uint8 len = (uint8)tmplen;
  if(len){
    uint8 tmp[32];
    HalUARTRead(UART_PC_PORT, tmp, len);
    tmp[len]=0x0d;
    pc_buff = bufPush(pc_buff, tmp, len);
    osal_set_event(Cashier_TaskID, UART_PC_EVENT);
  }
}
コード例 #19
0
ファイル: zap_sbl.c プロジェクト: Daan1992/WSN-Lab
/**************************************************************************************************
 * @fn          zapSBL_Rx
 *
 * @brief       This function is temporarily set as the registered callback for the UART to the ZNP
 *              in order to complete a serial boot load.
 *
 * input parameters
 *
 * @param       port - Don't care.
 * @param       event - Don't care.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void zapSBL_Rx(uint8 port, uint8 event)
{
  uint8 ch;

  (void)port;
  (void)event;

  while (HalUARTRead(ZAP_SBL_ZNP_PORT, &ch, 1))
  {
    (void)HalUARTWrite(ZAP_SBL_EXT_PORT, &ch, 1);
  }

  /*
   * TODO: Need to design a way to terminate the SBL session and return back to normal ZAP
   *       operations. Among possible other things, need to restore the usurped UART callback.
   */
  //uartRecord.callBackFunc = usurpedCB;
  //zapSBL_Active = FALSE;
}
コード例 #20
0
ファイル: zap_sbl.c プロジェクト: Daan1992/WSN-Lab
/**************************************************************************************************
 * @fn          zapSBL_RxExt
 *
 * @brief       This function is the registered callback for the UART to the external application
 *              that is driving the serial boot load to the ZNP.
 *
 * input parameters
 *
 * @param       port - Don't care.
 * @param       event - Don't care.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void zapSBL_RxExt(uint8 port, uint8 event)
{
  uint8 ch;

  (void)port;
  (void)event;

  // Use external UART Rx as the trigger to start an SBL session.
  if (!zapSBL_Active)
  {
    // Usurp and save to restore the currently registered UART transport callback.
    usurpedCB = uartRecord.callBackFunc;
    uartRecord.callBackFunc = zapSBL_Rx;

    znpSystemReset(ZNP_RESET_SOFT);
    HalBoardDelay(1000, TRUE);

    ch = SB_FORCE_BOOT;
    (void)HalUARTWrite(ZAP_SBL_ZNP_PORT, &ch, 1);
    (void)HalUARTWrite(ZAP_SBL_ZNP_PORT, &ch, 1);

    zapSBL_Active = TRUE;

    if (ZSuccess != osal_start_timerEx(zapSBL_TaskId, ZAP_SBL_EVT_EXIT, ZAP_SBL_DLY_EXIT))
    {
      (void)osal_set_event(zapSBL_TaskId, ZAP_SBL_EVT_EXIT);
    }
  }

  while (HalUARTRead(ZAP_SBL_EXT_PORT, &ch, 1))
  {
    (void)HalUARTWrite(ZAP_SBL_ZNP_PORT, &ch, 1);

    if (ZSuccess != osal_start_timerEx(zapSBL_TaskId, ZAP_SBL_EVT_EXIT, ZAP_SBL_DLY_EXIT))
    {
      (void)osal_set_event(zapSBL_TaskId, ZAP_SBL_EVT_EXIT);
    }
  }
}
コード例 #21
0
/***************************************************************************************************
 * @fn      MT_UartProcessZToolData
 *
 * @brief   | SOP | Data Length  |   CMD   |   Data   |  FCS  |
 *          |  1  |     1        |    2    |  0-Len   |   1   |
 *
 *          Parses the data and determine either is SPI or just simply serial data
 *          then send the data to correct place (MT or APP)
 *
 * @param   port     - UART port
 *          event    - Event that causes the callback
 *
 *
 * @return  None
 ***************************************************************************************************/
void MT_UartProcessZToolData( uint8 port, uint8 event )
{
  uint8  ch;
  (void)event;  // Intentionally unreferenced parameter
  uint8 i,j,flag = 0;
  uint8 str[128];
  while (Hal_UART_RxBufLen(port))
  {
    HalUARTRead (port, &ch, 1);
    j++;
    str[j] = ch;
    flag = 1;
  }
  
  if(flag == 1)
  {
    pMsg = (mtOSALSerialData_t  *) osal_msg_allocate(sizeof(mtOSALSerialData_t)
                                                  + j +1);
                                                 
    pMsg->hdr.event = CMD_SERIAL_MSG; 
    pMsg->msg = (uint8 *)(pMsg + 1);
    pMsg->msg[0] = j;
    
    for(i = 1; i <= j; i++)
    {
      pMsg->msg[i] = str[i]; 
    }
    
    osal_msg_send(App_TaskID,(byte *) pMsg);
    
    osal_msg_deallocate( (uint8 *)pMsg);
    
  }
  
  
}
コード例 #22
0
ファイル: ParkingAppE.c プロジェクト: kk30/kdc
/*********************************************************************
 * @fn      SerialApp_Send
 *
 * @brief   Read data message for UART callback.
 *          Then broadcast the msg to all the network
 *          on cluster ID, perform the intended action.
 *
 * @param   none
 *
 * @return  none
*********************************************************************/
void SerialApp_Send(uint8 port)
{
  uint16 option=0;
  
  if (!SerialApp_TxLen && 
      (SerialApp_TxLen = HalUARTRead(port, SerialApp_TxBuf, SERIAL_APP_TX_MAX)))
  {
//    if(SerialApp_TxBuf[0] != 0xFB)
//    {
//      SerialApp_TxLen = 0;
//      return;
//    }
    if(port==0)
    {
      option=0xE101;      
    }
    else if (port==1)
    {
      option=0xE102;      
    }
    App_SendSample(SerialApp_TxBuf, SerialApp_TxLen, option);  
  }
  SerialApp_TxLen = 0;
}
コード例 #23
0
static void UART_CallBack(uint8 port, uint8 event)
{
  (void)port;
  //uint8 pData[1];
  uint8 cmdbuff[1];

  if (event & (HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT))
  {
    HalUARTRead(port, cmdbuff, 1);
    /************************************************* This was used to send some specific data do the last device connected to the COORDINATOR (HDA)**************************************/
    // if(*cmdbuff==48)
    // {
    //   SendUART("  Desligar",10);
    //   pData[0] = '0';
    //   AF_DataRequest( &teste, &ParkWay_epDesc,
    //                    ParkWay_CLUSTERID,
    //                    (byte)osal_strlen( pData ) + 1,
    //                    (byte *)&pData,
    //                    &ParkWay_TransID,
    //                    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); 
    // }
    // else
    // {
    //   SendUART("  Ligar",7);
    //   pData[0] = '1';
    //   AF_DataRequest( &teste, &ParkWay_epDesc,
    //                    ParkWay_CLUSTERID,
    //                    (byte)osal_strlen( pData ) + 1,
    //                    (byte *)&pData,
    //                    &ParkWay_TransID,
    //                    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ); 
    // }
    // SendUART(cmdbuff,1);
    /*********************************************** This was used to send some specific data do the last device connected to the COORDINATOR (HDA)**************************************/
  }
}
コード例 #24
0
/*********************************************************************
 * @fn          UART_callback
 * @brief       Uart callback function.
 * @param       port - Com Port 0 or com port 1. 
 * @param       event - UART Events.
 * @return      null.
 */
void UART_callback ( uint8 port, uint8 event )
{ 
  uint16 uart1_len=0;
  if(( event & ( HAL_UART_RX_FULL | HAL_UART_RX_ABOUT_FULL | HAL_UART_RX_TIMEOUT ) ) ) 
  {   
    if(port == HAL_UART_PORT_0)//不用来接收数据,仅仅用来上传数据
    {
      //(HAL_UART_PORT_0, i8_uart_buf, len);   //读取串口数据到buf指向的内存,处添加数据解析函数    
    }
    else//port == HAL_UART_PORT_1
    {
      uart1_len = Hal_UART_RxBufLen(HAL_UART_PORT_1); //取出本次接收到的字符长度 
      uint8 *uart1_buf = osal_mem_alloc(uart1_len);
      HalUARTRead(HAL_UART_PORT_1, uart1_buf, uart1_len);
    
      //数据逻辑操作
      afAddrType_t SampleApp_Send_DstAddr;//目标地址
      unsigned int len;
      //获取目标网络地址
      uint8 arr[2];
      uint16 nwkAddr;
      StrConvert2Hex(uart1_buf+3, arr,4);//转换网络地址
      nwkAddr = BUILD_UINT16(arr[0],arr[1]); 
      
      SampleApp_Send_DstAddr.addr.shortAddr = nwkAddr;
      SampleApp_Send_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
      SampleApp_Send_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
      len = strlen(uart1_buf);
      
      //HCCU发送控制命令,则将该指令转发给EP
      if(uart1_buf[1] == 'C' ||uart1_buf[1] == 'c'){
        
        //协调器 /c|IP|Cluster_id|Group_id|endPoint----|T,V|
       if( AF_DataRequest( &SampleApp_Send_DstAddr, 
                       &SampleApp_epDesc,
                       SAMPLEAPP_COM_CLUSTERID,
                       len,// 数据长度         
                       uart1_buf,//数据内容
                       &SampleApp_TransID,
                       AF_DISCV_ROUTE,
                       AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
       {
         HalUARTWrite(1,"success\n",9);       
       }else{
         HalUARTWrite(1,"failed\n",8);
       }
      }
      
      //发送自身的MAC地址,作为HCCU的唯一标识码;
      if(uart1_buf[1] == 'A' || uart1_buf[1] == 'a'){
         uint8 *TmpBuf = osal_mem_alloc(8);
         uint8 asc_16[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
         uint8 *IEEEAddr;
         //获取长地址
         IEEEAddr = NLME_GetExtAddr();
         osal_cpyExtAddr( TmpBuf,IEEEAddr);
         HalUARTWrite(1,"/H|",3);
         HalUARTWrite(1,&asc_16[TmpBuf[0]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[0]%16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[1]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[1]%16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[2]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[2]%16],1);  
         HalUARTWrite(1,&asc_16[TmpBuf[3]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[3]%16],1);   
         HalUARTWrite(1,&asc_16[TmpBuf[4]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[4]%16],1); 
         HalUARTWrite(1,&asc_16[TmpBuf[5]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[5]%16],1);      
         HalUARTWrite(1,&asc_16[TmpBuf[6]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[6]%16],1);  
         HalUARTWrite(1,&asc_16[TmpBuf[7]%256/16],1);
         HalUARTWrite(1,&asc_16[TmpBuf[7]%16],1);
         HalUARTWrite(1,"|*\r\n",6);
         osal_mem_free(TmpBuf);
      }
      osal_mem_free(uart1_buf);
    }
  } 
}
コード例 #25
0
ファイル: MT_UART.c プロジェクト: flofeurstein/MTProj
/***************************************************************************************************
 * @fn      MT_UartProcessZToolData
 *
 * @brief   | SOP | Data Length  |   CMD   |   Data   |  FCS  |
 *          |  1  |     1        |    2    |  0-Len   |   1   |
 *
 *          Parses the data and determine either is SPI or just simply serial data
 *          then send the data to correct place (MT or APP)
 *
 * @param   port     - UART port
 *          event    - Event that causes the callback
 *
 *
 * @return  None
 ***************************************************************************************************/
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
  uint8  ch;
  uint8  bytesInRxBuffer;
  
  (void)event;  // Intentionally unreferenced parameter

  while (Hal_UART_RxBufLen(port))
  {
    HalUARTRead (port, &ch, 1);

    switch (state)
    {
      case SOP_STATE:
        if (ch == MT_UART_SOF)
          state = LEN_STATE;
        break;

      case LEN_STATE:
        LEN_Token = ch;

        tempDataLen = 0;

        /* Allocate memory for the data */
        pMsg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof ( mtOSALSerialData_t ) +
                                                        MT_RPC_FRAME_HDR_SZ + LEN_Token );

        if (pMsg)
        {
          /* Fill up what we can */
          pMsg->hdr.event = CMD_SERIAL_MSG;
          pMsg->msg = (uint8*)(pMsg+1);
          pMsg->msg[MT_RPC_POS_LEN] = LEN_Token;
          state = CMD_STATE1;
        }
        else
        {
          state = SOP_STATE;
          return;
        }
        break;

      case CMD_STATE1:
        pMsg->msg[MT_RPC_POS_CMD0] = ch;
        state = CMD_STATE2;
        break;

      case CMD_STATE2:
        pMsg->msg[MT_RPC_POS_CMD1] = ch;
        /* If there is no data, skip to FCS state */
        if (LEN_Token)
        {
          state = DATA_STATE;
        }
        else
        {
          state = FCS_STATE;
        }
        break;

      case DATA_STATE:

        /* Fill in the buffer the first byte of the data */
        pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen++] = ch;

        /* Check number of bytes left in the Rx buffer */
        bytesInRxBuffer = Hal_UART_RxBufLen(port);

        /* If the remain of the data is there, read them all, otherwise, just read enough */
        if (bytesInRxBuffer <= LEN_Token - tempDataLen)
        {
          HalUARTRead (port, &pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen], bytesInRxBuffer);
          tempDataLen += bytesInRxBuffer;
        }
        else
        {
          HalUARTRead (port, &pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen], LEN_Token - tempDataLen);
          tempDataLen += (LEN_Token - tempDataLen);
        }

        /* If number of bytes read is equal to data length, time to move on to FCS */
        if ( tempDataLen == LEN_Token )
            state = FCS_STATE;

        break;

      case FCS_STATE:

        FSC_Token = ch;

        /* Make sure it's correct */
        if ((MT_UartCalcFCS ((uint8*)&pMsg->msg[0], MT_RPC_FRAME_HDR_SZ + LEN_Token) == FSC_Token))
        {
          osal_msg_send( App_TaskID, (byte *)pMsg );
        }
        else
        {
          /* deallocate the msg */
          osal_msg_deallocate ( (uint8 *)pMsg );
        }

        /* Reset the state, send or discard the buffers at this point */
        state = SOP_STATE;

        break;

      default:
       break;
    }
  }
}
コード例 #26
0
ファイル: npi.c プロジェクト: nevinxu/HM502B2
/*******************************************************************************
 * @fn          NPI_ReadTransport
 *
 * @brief       This routine reads data from the transport layer based on len,
 *              and places it into the buffer.
 *
 * input parameters
 *
 * @param       buf - Pointer to buffer to place read data.
 * @param       len - Number of bytes to read.
 *
 * output parameters
 *
 * @param       None.
 *
 * @return      Returns the number of bytes read from transport.
 */
uint16 NPI_ReadTransport( uint8 *buf, uint16 len )
{
  return( HalUARTRead( NPI_UART_PORT, buf, len ) );
}
コード例 #27
0
static void uartCallback(uint8 port, uint8 event) {    
  uint16 len;
  uint8 buf[8];
  uint8 i;
  
  switch(event) {
  case HAL_UART_RX_FULL:
  case HAL_UART_RX_ABOUT_FULL:
  case HAL_UART_RX_TIMEOUT:
#if (HAL_UART_ISR == 1)
    len = Hal_UART_RxBufLen(HAL_UART_PORT_0);
    HalUARTRead(HAL_UART_PORT_0, buf, len);
#else
    len = Hal_UART_RxBufLen(HAL_UART_PORT_1);
    HalUARTRead(HAL_UART_PORT_1, buf, len);
#endif
    
    /*
    Proposing states:
    - If 3 consequence @'s, ie. @@@ is sent, put device into command mode (0) 
    - If 3 consequent $'s, ie. $$$ is sent, put device into translation mode (1)
    
    - In command mode, use U<value>, D<value>, M<value><value><value><value>, S<value>,<value>
    all followed by a line return
    - In translation mode, if the buffer is within ASCII printable, create 
    reports with corresponding USB HID keycode and send to host (translate). Mouse data is sent with
    0x03 <state> <x> <y> <z>
    */
    
    for(i = 0; i < len; i++) {
      
      //Detects if a mode is being selected
      if((buf[i] == '@') || (buf[i] == '$')) { //not to waste time
        //printf("strIndex: %i\r\n",strIndex);
        modeSelStr[strIndex++] = buf[i];
        if(strIndex == 3) {
          //printf("Testing for selection\r\n");
          if((modeSelStr[0] == '@') && (modeSelStr[1] == '@') && (modeSelStr[2] == '@')) {
            //printf("CMD");
            mode = 0;
          } else if((modeSelStr[0] == '$') && (modeSelStr[1] == '$') && (modeSelStr[2] == '$')) {
            //printf("TRANS");
            mode = 1;
          }
          strIndex = 0;
          memset(modeSelStr, 0, 3);
          break; //stops filling buffer if a new mode is selected
        }
      } else {
        //printf("Gallifrey Falls No More\r\n");
        memset(modeSelStr, 0, 3);
        strIndex = 0;
      }
      
      if(mode == COMMAND_MODE) {
        //command mode is selected
        if((buf[i] != 0x0D) && (buf[i] != 0x0A)) {
          rxBuffer[rxBufferIndex++] = buf[i];
        } else {
          processCommands();
          if(sleepModeEnabled) {
            sleepMode();
          }
          break;
        }
      } else {
        sendKbdReportsWith(buf[i]);
      }
    }
    
    break; //break for case(HAL_UART_RX_TIMEOUT)
  }
}
コード例 #28
0
/*********************************************************************
 * @fn      Monitor_ProcessMonitorData()
 *
 * @brief   process the message from the pc monitor, this
 *			message is send by monitor and will send to the node.
 *
 * @return  none
 */
void Monitor_ProcessMonitorData()
{
  uint8  ch;				
  uint8  bytesInRxBuffer;
  
  // if the Rx hava data
  while ( Hal_UART_RxBufLen(UART_PORT) )
  {
    HalUARTRead (UART_PORT, &ch, 1);
    switch (readStep)
    {
	  // start of the frame
      case Machine_SOF_STATE:
        if (MONITOR_START_FRMAE == ch)
          readStep = Machine_LEN_STATE;
        break;
	  // record length
      case Machine_LEN_STATE:
        length = ch;
        recvDataLen = 0;
        pData = (byte*)osal_mem_alloc(length+5);
		osal_memset(pData, 0x00, length+5);
        if (NULL != pData)
        {
		  // record the length in pData
		  pData[0] = length;
          readStep = Machine_CMD1_STATE;
        }
        else
        {
          readStep = Machine_SOF_STATE;
          return;
        }
        break;
	  // record command
      case Machine_CMD1_STATE:
		pData[1] = ch;
        readStep = Machine_CMD2_STATE;
        break;
      case Machine_CMD2_STATE:
        pData[2] = ch;
		readStep = Machine_DST1_STATE;
		break;
	  // record dst addr
	  case Machine_DST1_STATE:
		pData[3] = ch;
		readStep = Machine_DST2_STATE;
		break;
	  case Machine_DST2_STATE:
	  	pData[4] = ch;
        if (0 != length)
        {
          readStep = Machine_DATA_STATE;
        }
        else
        {
          readStep = Machine_FCS_STATE;
        }
        break;
	  // receive data
      case Machine_DATA_STATE:

        /* Fill in the buffer the first byte of the data */
        pData[5+recvDataLen++] = ch;

        /* Check number of bytes left in the Rx buffer */
        bytesInRxBuffer = Hal_UART_RxBufLen(UART_PORT);

        /* If the remain of the data is there, read them all, otherwise, just read enough */
        if (bytesInRxBuffer <= length - recvDataLen)
        {
          HalUARTRead (UART_PORT, &pData[5+recvDataLen], bytesInRxBuffer);
          recvDataLen += bytesInRxBuffer;
        }
        else
        {
          HalUARTRead (UART_PORT, &pData[5+recvDataLen], length - recvDataLen);
          recvDataLen += (length - recvDataLen);
        }

        /* If number of bytes read is equal to data length, time to move on to FCS */
        if ( recvDataLen == length )
            readStep = Machine_FCS_STATE;

        break;
	  // check fcs
      case Machine_FCS_STATE:
        fcs = ch;
        /* Make sure it's correct */
        if (Monitor_CalcFCS ((uint8*)pData, length+5) == fcs)
        {
		  // if this is the allow start command from pc
		  // this allow the coordinator to ack start when
		  // it's already start when the application from
		  // pc is started. this is very flexiable for the 
		  // user
		  Monitor_ProcessMonitorIncomingData(pData);
		}
        else
        {
          /* deallocate the msg */
          osal_mem_free ( (uint8 *)pData );
        }
		
        /* Reset the readStep, send or discard the buffers at this point */
        readStep = Machine_SOF_STATE;
     	break;
    }
	// return to wait the send signal
	if( 0 == Hal_UART_RxBufLen(UART_PORT) )
	{
	  // all data hava read out
  	  HalUARTWrite(UART_PORT, (byte*)ACK, 7);
	}else{
	  break;	// get out the loop
	}
  }// read all data
}
コード例 #29
0
ファイル: zap_sbl.c プロジェクト: Daan1992/WSN-Lab
/**************************************************************************************************
 * @fn          zapSBL_RxExt
 *
 * @brief       This function is the registered callback for the UART to the external application
 *              that is driving the serial boot load to the ZNP.
 *
 * input parameters
 *
 * @param       port - Don't care.
 * @param       event - Don't care.
 *
 * output parameters
 *
 * None.
 *
 * @return      None.
 **************************************************************************************************
 */
static void zapSBL_RxExt(uint8 port, uint8 event)
{
  uint8 ch;

  (void)port;
  (void)event;

  // Use external UART Rx as the trigger to start an SBL session.
  if (!zapSBL_Active)
  {
    if ((zapSBL_Buf = osal_mem_alloc(SB_BUF_SIZE)) == NULL)
    {
      return;
    }

    zapSBL_Active = TRUE;
    zapSBL_ResetZNP();

    // Stop other tasks access (e.g. zapMonitor()) to SPI when in SBL mode.
    (void)osal_memset(tasksEvents+1, 0, ((tasksCnt-1) * sizeof(uint16)));
    for (ch = 1; ch < tasksCnt; ch++)
    {
      uint16 evt;

      for (evt = 0x0001; evt < 0x8000; evt <<= 1)
      {
        (void)osal_stop_timerEx(ch, evt);
      }
    }

    if (ZSuccess != osal_start_timerEx(zapSBL_TaskId, ZAP_SBL_EVT_EXIT, ZAP_SBL_DLY_EXIT))
    {
      (void)osal_set_event(zapSBL_TaskId, ZAP_SBL_EVT_EXIT);
    }

#if HAL_LCD
    HalLcdWriteString( "TexasInstruments", 1 );
    HalLcdWriteString( "ZAP Proxy to ZNP", 2 );
    HalLcdWriteString( "   BootLoader   ", 3 );
#endif
  }

  while (HalUARTRead(ZAP_SBL_EXT_PORT, &ch, 1))
  {
    sbBuf[sbSte + sbIdx] = ch;
    switch (sbSte)
    {
    case SB_SOF_STATE:
      if (SB_SOF == ch)
      {
        sbSte = SB_LEN_STATE;
      }
      break;
    
    case SB_LEN_STATE:
      sbFcs = 0;
      sbSte = ((sbLen = ch) >= SB_BUF_SIZE) ? SB_SOF_STATE : SB_CMD1_STATE;
      break;

    case SB_CMD1_STATE:
      sbSte = SB_CMD2_STATE;
      break;
    
    case SB_CMD2_STATE:
      sbSte = (sbLen) ? SB_DATA_STATE : SB_FCS_STATE;
      break;

    case SB_DATA_STATE:
      if (++sbIdx == sbLen)
      {
        sbSte = SB_FCS_STATE;
      }
      break;
    
    case SB_FCS_STATE:
      if (sbFcs == ch)
      {
        sbBuf[SB_DATA_STATE + sbIdx] = ch;
        zapSBL_Tx();
      }
      else
      {
        // TODO - RemoTI did not have here or on bad length - adding could cause > 1 SB_INVALID_FCS
        //        for a single data packet which could put out of sync with PC for awhile or
        //        infinte, depending on PC-side?
        // sbResp(SB_INVALID_FCS, 1);
      }
    
      sbSte = sbIdx = 0;
      break;
    
    default:
      break;
    }
    sbFcs ^= ch;

    if (ZSuccess != osal_start_timerEx(zapSBL_TaskId, ZAP_SBL_EVT_EXIT, ZAP_SBL_DLY_EXIT))
    {
      (void)osal_set_event(zapSBL_TaskId, ZAP_SBL_EVT_EXIT);
    }
  }
}
コード例 #30
0
void SbpHalUARTRead(uint8 port, uint8 *buf, uint16 len) {
	//UART_HAL_DELAY(1000);
	HalUARTRead(port, pktBuffer, numBytes);
	UART_PORT_HAVE_READ = 1;
}