コード例 #1
0
ファイル: MApp_init.c プロジェクト: BlueTeo91/WSN_Project
void BUtl_SetReceiverOff(void)
{
 /* This function is called by the NVM component at the start of the NV operation */
 mlmeMessage_t msg;	  
 bool_t value; 
 /* get the receiver state */
 
 msg.msgType = gMlmeGetReq_c;
 msg.msgData.getReq.pibAttribute = gMPibRxOnWhenIdle_c;
 msg.msgData.getReq.pibAttributeValue = &value; 
 (void)MSG_Send(NWK_MLME, &msg);
 
 if(value)
 {
  /* Turn off the receiver during NVM operation */
  receiverOn = TRUE;
  
  value = FALSE;
  msg.msgType = gMlmeSetReq_c;
  msg.msgData.setReq.pibAttribute = gMPibRxOnWhenIdle_c;
  msg.msgData.setReq.pibAttributeValue = &value;
  (void)MSG_Send(NWK_MLME, &msg);
 }
 else
 {
  /* Receiver already turned off */
  receiverOn = FALSE;
 }
 
}
コード例 #2
0
ファイル: MApp_init.c プロジェクト: BlueTeo91/WSN_Project
void BUtl_SetReceiverOn(void)
{
 /* This function is called by the NVM component at the end of the NV operation */
 mlmeMessage_t msg;	  
 bool_t value = TRUE;
 if(receiverOn == TRUE)
 {  
  /* Restore receiver state */
  msg.msgType = gMlmeSetReq_c;
  msg.msgData.setReq.pibAttribute = gMPibRxOnWhenIdle_c;
  msg.msgData.setReq.pibAttributeValue = &value;
  (void)MSG_Send(NWK_MLME, &msg);
 } 
}
コード例 #3
0
ファイル: MApp.c プロジェクト: BlueTeo91/WSN_Project
/******************************************************************************
* The App_StartScan(scanType) function will start the scan process of the
* specified type in the MAC. This is accomplished by allocating a MAC message,
* which is then assigned the desired scan parameters and sent to the MLME
* service access point.
* The function may return either of the following values:
*   errorNoError:          The Scan message was sent successfully.
*   errorInvalidParameter: The MLME service access point rejected the
*                          message due to an invalid parameter.
*   errorAllocFailed:      A message buffer could not be allocated.
*
******************************************************************************/
static uint8_t App_StartScan(uint8_t scanType)
{
  mlmeMessage_t *pMsg;
  mlmeScanReq_t *pScanReq;

  UartUtil_Print("Sending the MLME-Scan Request message to the MAC...", gAllowToBlock_d);

  /* Allocate a message for the MLME (We should check for NULL). */
  pMsg = MSG_AllocType(mlmeMessage_t);
  if(pMsg != NULL)
  {
    /* This is a MLME-SCAN.req command */
    pMsg->msgType = gMlmeScanReq_c;
    /* Create the Scan request message data. */
    pScanReq = &pMsg->msgData.scanReq;
    /* gScanModeED_c, gScanModeActive_c, gScanModePassive_c, or gScanModeOrphan_c */
    pScanReq->scanType = scanType;
    /* ChannelsToScan & 0xFF - LSB, always 0x00 */
    pScanReq->scanChannels[0] = (uint8_t)((mDefaultValueOfChannel_c)     & 0xFF);
    /* ChannelsToScan>>8 & 0xFF  */
    pScanReq->scanChannels[1] = (uint8_t)((mDefaultValueOfChannel_c>>8)  & 0xFF);
    /* ChannelsToScan>>16 & 0xFF  */
    pScanReq->scanChannels[2] = (uint8_t)((mDefaultValueOfChannel_c>>16) & 0xFF);
    /* ChannelsToScan>>24 & 0xFF - MSB */
    pScanReq->scanChannels[3] = (uint8_t)((mDefaultValueOfChannel_c>>24) & 0xFF);
    /* Duration per channel 0-14 (dc). T[sec] = (16*960*((2^dc)+1))/1000000.
       A scan duration of 3 on 16 channels approximately takes 2 secs. */
    pScanReq->scanDuration = 3;
#ifdef gMAC2006_d
	pScanReq->securityLevel = 0;
#endif //gMAC2006_d	
    
    /* Send the Scan request to the MLME. */
    if(MSG_Send(NWK_MLME, pMsg) == gSuccess_c)
    {
      UartUtil_Print("Done\n\r", gAllowToBlock_d);
      return errorNoError;
    }
    else
    {
      UartUtil_Print("Invalid parameter!\n\r", gAllowToBlock_d);
      return errorInvalidParameter;
    }
  }
コード例 #4
0
ファイル: Robotis.c プロジェクト: omiomiomi/ax12-robo
int main(
    void
)	{
#ifndef PC
    USART_Init();		/*	Initialize USART 0 & 1	*/
    stdout = &uart_output;
    usart0_comp = FALSE;/*	Set to false by default	*/
    usart1_comp = FALSE;/*	Set to false by default	*/

    DDRE |= (1 << PE4);	/*	Initialize PE4 & PE5 to */
    DDRE |= (1 << PE5);	/*	Outputs for the DM74L	*/
    DDRB |= (1 << PB0);	/*	Output for HCSR04		*/

    packet	msg;		/*	For the SENT messages	*/
    packet	rec;		/*	For the RECEIVED msg's	*/

    uint16_t motor13 = 0;
    uint16_t motor18 = 0;
    uint16_t motor1  = 0;

    uint16_t dist = 0;	/*	Current distance		*/
    uint8_t	 des  = 0;	/*	Desired position		*/

    sei();				/*	Set Enable Interrupt	*/
    printf("START\n");

    /*	Motor variables for _TESTING_	*/
    motor13 = 374;
    motor18 = 287;
    motor1 =  271;
	
    printf("%d\n",motor13);
    printf("%d\n",motor18);
    printf("%d\n",motor1);

    while(1)	{
	//	dist = GET_Dist();
		//printf("%d\n",dist);
		//PORTD |= (1 << PB0);
        //_delay_us(10);
        //PORTD &= ~(1<<PB0);
		
		if(des =='4')
		{
			GET_Dist();
		}
	

        if(usart0_comp)	{
            cli();
            MSG_SaveFrame(&rec);
            usart0_comp = FALSE;
            sei();
        }

        /*	Wait for input	*/
        if(usart1_comp)	{
            /*	Calculate the values for the servo's here */
            cli();
            usart1_comp = FALSE;
            des = usart1_data;
            sei();
         //   dist = GET_Dist();
		//	printf("%d\n",dist);
        }

        /*	Set to output	*/
        PORTE &=~(1<<PE4);
        PORTE |=(1<<PE5);

        if(des == '1')	{

            msg.id = 13;
            msg.len = 5;
            msg.inst = 3;
            msg.data[0]	= 0x1E;
            msg.data[1]	= (uint8_t)(motor13 & 0x00FF);
            msg.data[2]	= (uint8_t)(motor13 >> 8);
            msg.chk = CALC_Checksum(&msg);

            MSG_Send(&msg);


        } else if(des == '2')	{