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

📄 wsn_router.c

📁 WSN-ROUTER,JENNIC实例程序
💻 C
📖 第 1 页 / 共 3 页
字号:
            vSendData();
           }
		    u8AppTicks = 0;
            /* Transmit data to coordinator */

           	//sADSensor.eState = E_STATE_READ_BATT_VOLT_IDLE;
			//sADSensor.u8currentCh=0;

        }
	}

    (void)bBosCreateTimer(vAppTick, &u8Msg, 0, (APP_TICK_PERIOD_ms / 10), &u8TimerId);

}

/****************************************************************************
 *
 * NAME: vReadBatteryVoltage
 *
 * DESCRIPTION:
 *
 * Uses ADC to read supply voltage. Measurement is performed using a state
 * machine to ensure that it never blocks.
 *
 ****************************************************************************/
PRIVATE void vReadADCs(void)
{

    // test();
    //   v_W1302(0x8e,0x00);
    //   v_W1302(0x80,0x59);
	//   sec=uc_R1302(0x81);
  //  uint16 u16AdcReading;
   // if(sADSensor.u8currentCh<1)
   // {
      //  switch(sADSensor.eState)
       // {
         //   case E_STATE_READ_BATT_VOLTS_READY:
       //         vAHI_AdcEnable(E_AHI_ADC_CONVERT_DISABLE,
     //                          E_AHI_AP_INPUT_RANGE_2,
     //                          sADSensor.u8Channel[sADSensor.u8currentCh]);
      //          vAHI_AdcStartSample();
     //           sADSensor.eState = E_STATE_READ_BATT_VOLTS_ADC_CONVERTING;
     //          break;

          //  case E_STATE_READ_BATT_VOLTS_ADC_CONVERTING:
          //      if (!bAHI_AdcPoll())
         //       {
        //            sADSensor.eState = E_STATE_READ_BATT_VOLTS_COMPLETE;
        //        }
        //        break;

        //    case E_STATE_READ_BATT_VOLTS_COMPLETE:

         //       u16AdcReading = u16AHI_AdcRead();

                /* Input range is 0 to 2.4V. ADC has full scale range of 12 bits.
                   Therefore a 1 bit change represents a voltage of approx 586uV */
         //       sADSensor.u16Reading[sADSensor.u8currentCh] = u16AdcReading;

         //       sADSensor.eState = E_STATE_READ_BATT_VOLTS_READY;
         //       sADSensor.u8currentCh++;
        //        break;
         //   default:
        //        break;
    //    }
   // }
 //  if(sADSensor.u8currentCh==1)
 //   {
  //     switch(sADSensor.eState)
    //    {
   //         case E_STATE_READ_BATT_VOLTS_READY:
    //            vAHI_AdcEnable(E_AHI_ADC_CONVERT_DISABLE,
      //                         E_AHI_AP_INPUT_RANGE_2,
     //                          sADSensor.u8Channel[sADSensor.u8currentCh]);
         //       vAHI_AdcStartSample();
        //        sADSensor.eState = E_STATE_READ_BATT_VOLTS_ADC_CONVERTING;
        //        break;

        //    case E_STATE_READ_BATT_VOLTS_ADC_CONVERTING:
      //          if (!bAHI_AdcPoll())
     //           {
     //               sADSensor.eState = E_STATE_READ_BATT_VOLTS_COMPLETE;
      //          }
       //         break;

     //       case E_STATE_READ_BATT_VOLTS_COMPLETE:

         //       u16AdcReading = u16AHI_AdcRead();

                /* Input range is 0 to 2.4V. ADC has full scale range of 12 bits.
                   Therefore a 1 bit change represents a voltage of approx 586uV */
         //       sADSensor.u16Reading[sADSensor.u8currentCh] = u16AdcReading;

          //      sADSensor.eState = E_STATE_READ_BATT_VOLTS_READY;
         //       sADSensor.u8currentCh++;
        //        break;
       //     default:
      //          break;
      //  }
  //  }

  // if(sADSensor.u8currentCh==2)
   // {
     //      switch(sADSensor.eState)
      //  {
       //     case E_STATE_READ_BATT_VOLTS_READY:
        //        vAHI_AdcEnable(E_AHI_ADC_CONVERT_DISABLE,
        //                       E_AHI_AP_INPUT_RANGE_2,
        //                       sADSensor.u8Channel[sADSensor.u8currentCh]);
       //         vAHI_AdcStartSample();
        //        sADSensor.eState = E_STATE_READ_BATT_VOLTS_ADC_CONVERTING;
        //        break;

       //     case E_STATE_READ_BATT_VOLTS_ADC_CONVERTING:
        //        if (!bAHI_AdcPoll())
       //         {
      //              sADSensor.eState = E_STATE_READ_BATT_VOLTS_COMPLETE;
      //          }
      //          break;

     //       case E_STATE_READ_BATT_VOLTS_COMPLETE:

     //           u16AdcReading = u16AHI_AdcRead();
      //          if(!u16AdcReading)
        //            v_Get1302(ucCurtime);


                /* Input range is 0 to 2.4V. ADC has full scale range of 12 bits.
                   Therefore a 1 bit change represents a voltage of approx 586uV */
     //           sADSensor.u16Reading[sADSensor.u8currentCh] = u16AdcReading;

      //          sADSensor.eState = E_STATE_READ_BATT_VOLTS_READY;
      //          break;
       //     default:
      //          break;
      //  }
//}
}
/****************************************************************************
 *
 * NAME: vSendData
 *
 * DESCRIPTION:
 *
 * Transmit sensor data to coordinator.
 *
 ****************************************************************************/
void vSendData(void)
{
    uint8 sum=0;

    //uint8 *pDatabuf;
    //pDatabuf=(uint8 *)&sADSensor.u16Reading[0];

    AF_Transaction_s asTransaction[1];

    asTransaction[0].u8SequenceNum = u8AfGetTransactionSequence(TRUE);
    asTransaction[0].uFrame.sMsg.u8TransactionDataLen = 14;

    asTransaction[0].uFrame.sMsg.au8TransactionData[0]  =40;//pDatabuf[1];//ADC1
    asTransaction[0].uFrame.sMsg.au8TransactionData[1] =30;//pDatabuf[0];
    asTransaction[0].uFrame.sMsg.au8TransactionData[2] =10;//pDatabuf[3];//ADC2
    asTransaction[0].uFrame.sMsg.au8TransactionData[3] =11;//pDatabuf[2];
    asTransaction[0].uFrame.sMsg.au8TransactionData[4] =07;//pDatabuf[5];//ADC3
    asTransaction[0].uFrame.sMsg.au8TransactionData[5] =05;//pDatabuf[4];
    asTransaction[0].uFrame.sMsg.au8TransactionData[6] =ucCurtime[6];//年
    asTransaction[0].uFrame.sMsg.au8TransactionData[7] =ucCurtime[4];//月
    asTransaction[0].uFrame.sMsg.au8TransactionData[8] =ucCurtime[3];//日
    asTransaction[0].uFrame.sMsg.au8TransactionData[9] =ucCurtime[5];//星期
    asTransaction[0].uFrame.sMsg.au8TransactionData[10] =ucCurtime[2];//时
    asTransaction[0].uFrame.sMsg.au8TransactionData[11] =ucCurtime[1];//分
    asTransaction[0].uFrame.sMsg.au8TransactionData[12] =ucCurtime[0];//秒

    sum=Getchecksum(asTransaction[0].uFrame.sMsg.au8TransactionData,13);
    asTransaction[0].uFrame.sMsg.au8TransactionData[13] =sum;

    (void)afdeDataRequest(APS_ADDRMODE_SHORT,       /* Address type */
                          0x0000,                   /* Destination address */
                          WSN_DATA_SINK_ENDPOINT,   /* destination endpoint */
                          WSN_DATA_SOURCE_ENDPOINT, /* Source endpoint */
                          WSN_PROFILE_ID,           /* Profile ID */
                          WSN_CID_SENSOR_READINGS,  /* Cluster ID */
                          AF_MSG,                   /* Frame type */
                          1,                        /* Transactions */
                          asTransaction,            /* Transaction data */
                          APS_TXOPTION_NONE,        /* Transmit options */
                          SUPPRESS_ROUTE_DISCOVERY, /* Route discovery mode */
                          0);                       /* Radius count */
}

/****************************************************************************/
/***               Functions called by the stack                          ***/
/****************************************************************************/

/****************************************************************************
 *
 * NAME: JZA_vZdpResponse
 *
 * DESCRIPTION:
 * Called when a ZDP response frame has been received. In this application no
 * action is taken as no ZDP responses are anticipated.
 *
 * PARAMETERS:      Name           RW  Usage
 *                  u8Type         R   ZDP response type
 *                  pu8Payload     R   Payload buffer
 *                  u8PayloadLen   R   Length of payload
 *
 ****************************************************************************/
PUBLIC void JZA_vZdpResponse(uint8  u8Type,
                             uint8  u8LQI,
                             uint8 *pu8Payload,
                             uint8  u8PayloadLen)

{
}

/****************************************************************************
 *
 * NAME: JZA_pu8AfMsgObject
 *
 * DESCRIPTION:
 * Called when a MSG transaction has been received with a matching endpoint.
 * In this application no action is taken as no MSG transactions are expected.
 *
 * PARAMETERS:      Name           RW  Usage
 *                  afSrcAddr      R   Address of sender device
 *                  dstEndPoint    R   Endpoint at receiver
 *                  clusterID      R   Pointer to cluster ID
 *                  afduLength     R   Pointer to length of data
 *                  pAfdu          R   Data array
 *
 * RETURNS:
 * NULL
 *
 ****************************************************************************/
PUBLIC bool_t JZA_bAfMsgObject(APS_Addrmode_e eAddrMode,
                               uint16 u16AddrSrc,
                               uint8 u8SrcEP,
                               uint8 u8LQI,
                               uint8 u8DstEP,
                               uint8 u8ClusterID,
                               uint8 *pu8ClusterIDRsp,
                               AF_Transaction_s *puTransactionInd,
                               AF_Transaction_s *puTransactionRsp)
{
	/*uint16 u16Humidity;
	uint16 u16BattVoltage;
	uint16 u16Temperature;*/
	uint8 i;

    if ((eAddrMode == APS_ADDRMODE_SHORT) && (u8DstEP == WSN_DATA_SOURCE_ENDPOINT))
    {
        if(u8ClusterID == WSN_CID_SENSOR_READINGS)
        {
            for(i=0;i<7;i++)
            {
                u16test[i] = puTransactionInd->uFrame.sMsg.au8TransactionData[i];
            }
       v_Set1302(u16test);
       receive=1;
       if (!Toggle)
        {
            vAHI_DioSetOutput(0x00,E_AHI_DIO9_INT);
        }
        else
        {
            vAHI_DioSetOutput(E_AHI_DIO9_INT,0x00);
        }
        Toggle = !Toggle;
        }
        }

    return 0;
}

/****************************************************************************
 *
 * NAME: JZA_vAfKvpResponse
 *
 * DESCRIPTION:
 * Called after a KVP transaction with acknowledgement request, when the
 * acknowledgement arrives. In this application no action is taken as no
 * KVP transaction acknowledgements are expected.
 *
 * PARAMETERS:      Name                   RW  Usage
 *                  srcAddressMod          R   Address of sender device
 *                  transactionSequenceNum R   KVP transaction number
 *                  commandTypeIdentifier  R   KVP command type
 *                  dstEndPoint            R   Endpoint at receiver
 *                  clusterID              R   Cluster ID
 *                  attributeIdentifier    R   KVP attribute ID
 *                  errorCode              R   Result code
 *                  afduLength             R   Length of payload data
 *                  pAfdu                  R   Payload data array
 *
 ****************************************************************************/
PUBLIC void JZA_vAfKvpResponse(APS_Addrmode_e eAddrMode,
                               uint16 u16AddrSrc,
                               uint8 u8SrcEP,
                               uint8 u8LQI,
                               uint8 u8DstEP,
                               uint8 u8ClusterID,
                               AF_Transaction_s *puTransactionInd)
{
}

/****************************************************************************
 *
 * NAME: JZA_eAfKvpObject
 *
 * DESCRIPTION:
 * Called when a KVP transaction has been received with a matching endpoint.
 *
 * PARAMETERS:      Name           RW  Usage
 *                  afSrcAddr      R   Address of sender device
 *                  u8DstEndpoint  R   Endpoint at receiver
 *                  pu8ClusterId   R   Pointer to cluster ID
 *                  eCommandTypeId R   KVP command type

⌨️ 快捷键说明

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