Exemplo n.º 1
0
/******************************************************************************
 * @fn      modbus_uart_data_process
 * 
 * @brief   Process the message from UART
 * 
 * @param   uint8 - the pointer the buffer that to be process
 *          uint8 - length
 * 
 * @return  none
 */
void modbus_uart_data_process( uint8 *data_buffer, uint8 len)
{
  P2_1 = 0;
  if( TRUE == check_data( data_buffer, len))
  {
    initCRC16();
    modbus_process_msg( data_buffer, len);
  }
  P2_1 = 1;
}
Exemplo n.º 2
0
void calcCRC16( uint8* data, uint8 len)
{
  uint8 *pData = osal_mem_alloc( len);
  if( pData)
    osal_memcpy( pData, data, len);

  pData[rssi_send_hi] = 255;
  pData[rssi_send_lo] = modbus_rssi;
  initCRC16();
  for( uint8 i = 0; i<(len-2); i++)
  {
    CRC16_byte(pData[i]);
  }
  pData[len-2] = CRChi;
  pData[len-1] = CRClo;

  HalUARTWrite( 0, pData, len);
  osal_mem_free( pData);
}
Exemplo n.º 3
0
void response_scan_cmd(void)
{
  uint8 *pBuf;
  initCRC16();
  pBuf = osal_mem_alloc(9);
  if(pBuf!=NULL)
  {
    pBuf[0]=0xff;
    pBuf[1]=0x19;
    pBuf[2]=modbus_id;
    pBuf[3]=ttt[0];
    pBuf[4]=ttt[1];
    pBuf[5]=ttt[2];
    pBuf[6]=ttt[3];
  }
  for(uint8 i=0;i<7;i++)
    CRC16_byte(pBuf[i]);
  pBuf[7]=CRChi;
  pBuf[8]=CRClo;
  send_str_Uart( pBuf, 9, 0);
}
Exemplo n.º 4
0
/******************************************************************************
 * @fn      modbus_uart_data_process
 * 
 * @brief   Process the message from UART
 * 
 * @param   uint8 - the pointer the buffer that to be process
 *          uint8 - length
 * 
 * @return  none
 */
void modbus_uart_data_process( uint8 *data_buffer, uint8 len)
{
  afAddrType_t destAddr;
  destAddr.addrMode = afAddrBroadcast;
  destAddr.addr.shortAddr = 0xffff;                
  destAddr.endPoint = 10;

  if( TRUE == check_data( data_buffer, len))
  {
    initCRC16();
    modbus_process_msg( data_buffer, len);
  }
  else
  {
    AF_DataRequest( &destAddr, &temco_epDesc,
                     TEMCO_CLUSTERID,
                     len,
                     data_buffer,
                     &temcoApp_TransID,
                     AF_DISCV_ROUTE,
                     AF_DEFAULT_RADIUS );
  }
}
Exemplo n.º 5
0
/******************************************************************************
 * @fn      modbus_insert_msg
 */
void modbus_insert_msg( uint8 *pBuf, uint8 len)
{
  uint8 index = 0;
  afAddrType_t destAddr;
  destAddr.addrMode = afAddr16Bit;
  destAddr.addr.shortAddr = 0;                
  destAddr.endPoint = 10;
  signalStrength_t* pSigStren;
    
  initCRC16();
//  uint8 *pInsertBuf = osal_mem_alloc( modbusDataLength*2);
  if( firstAddr < 21)
    index = 45 - 2*firstAddr;
  else
    //index = (modbusStartAddr-20)*2 + 1;
    index = 3;
  
  for (uint8 i=0; i<modbusDataLength; i++)
  {
    if( i+modbusStartAddr == MODBUS_PANID)
    {
      pBuf[index++] = HI_UINT16( _NIB.nwkPanId);
      pBuf[index++] = LO_UINT16( _NIB.nwkPanId);
    }
    else if( i + modbusStartAddr == MODBUS_DEVICE_TYPE)
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = zgDeviceLogicalType;
    }
    else if( i + modbusStartAddr == MODBUS_CHANNEL_LIST_HI)
    {
      pBuf[index++] = BREAK_UINT32(zgDefaultChannelList, 3);
      pBuf[index++] = BREAK_UINT32(zgDefaultChannelList, 2);
    }
    else if( i + modbusStartAddr == MODBUS_CHANNEL_LIST_LO)
    {
      pBuf[index++] = BREAK_UINT32(zgDefaultChannelList, 1);
      pBuf[index++] = BREAK_UINT32(zgDefaultChannelList, 0);
    }
    else if( i + modbusStartAddr == MODBUS_SOFTWARE_REV)
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = ZIG_SOFTWARE_VER;
    }
    else if( (i + modbusStartAddr >= MODBUS_EXTENDED_ADDR_HI) && (i + modbusStartAddr <= MODBUS_EXTENDED_ADDR_LO))
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = aExtendedAddress[ i+modbusStartAddr-MODBUS_EXTENDED_ADDR_HI];
    }
    else if( (i + modbusStartAddr >= MODBUS_SECURITY_KEY_START) && (i + modbusStartAddr <= MODBUS_SECURITY_KEY_END))
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = defaultKey[ i+modbusStartAddr-MODBUS_SECURITY_KEY_START];
    }
    else if( i + modbusStartAddr == MODBUS_TSTAT_NUM)
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = numSignalStren;
    }
    else if( (i + modbusStartAddr >= MODBUS_FIRST_TSTAT_ID) && ( i+ modbusStartAddr <= MODBUS_LAST_TSTAT_ID))
    {
      if( i + modbusStartAddr == MODBUS_FIRST_TSTAT_ID)
      {
        pSigStren = pSignalStren;
      }
      else
      {
        pSigStren = pSignalStren;
        for( uint8 j=0; j<((i+modbusStartAddr)-MODBUS_FIRST_TSTAT_ID); j++)
        {
          if(pSigStren)
            pSigStren = pSigStren->next;
        }
      }
      pBuf[index++] = ZERO;
      if(pSigStren != NULL)
      {
        pBuf[index++] = pSigStren->modbus_id;
      }
      else
        pBuf[index++] = ZERO;
    }
    else if( (i + modbusStartAddr >= MODBUS_FIRST_SIG_STREN) && ( i+ modbusStartAddr <= MODBUS_LAST_SIG_STREN))
    {
      if( i + modbusStartAddr == MODBUS_FIRST_SIG_STREN)
      {
        pSigStren = pSignalStren;
      }
      else
      {
        pSigStren = pSignalStren;
        for( uint8 j=0; j<((i+modbusStartAddr)-MODBUS_FIRST_SIG_STREN); j++)
        {
          if(pSigStren)
            pSigStren = pSigStren->next;
        }
      }
      pBuf[index++] = ZERO;
      if(pSigStren != NULL)
      {
        pBuf[index++] = pSigStren->rssi;
      }
      else
        pBuf[index++] = ZERO;
    }
    else
    {
      pBuf[index++] = ZERO;
      pBuf[index++] = ZERO;
    }
  }
  
  for( uint8 i=0; i<len-2; i++)
    CRC16_byte(pBuf[i]);
  
  pBuf[len-2] = CRChi;
  pBuf[len-1] = CRClo;
  
  AF_DataRequest( &destAddr, &temco_epDesc,
                     TEMCO_CLUSTERID,
                     len,
                     pBuf,
                     &temcoApp_TransID,
                     AF_DISCV_ROUTE,
                     AF_DEFAULT_RADIUS );
  
  modbusStartAddr = 0;
  modbusDataLength = 0;
}