예제 #1
0
파일: main.c 프로젝트: liyanfeng/WSN2
 __interrupt void T1_ISR(void)            
 {       
          
         
      ++counter;
      if(counter>myrate){
          counter=0;  
          dht11_update();
          sprintf(pTsxData,"shidu:%utmp%u℃\r\n", gdat1, gdat2);
          //printf("sensor data.....");
          //printf(pTsxData);
          //printf("\r\n");
          ret = basicRfSendPacket(0xffff, pTsxData, sizeof pTsxData);       
          ledflashcounter=8;
          hal_led_on(1);
          /*if (ret == SUCCESS) {
              printf("send msg ok\r\n");
           } else {
              printf("send msg error\r\n");
           }*/ 
      }
      if(ledflashcounter>0)
      {
          --ledflashcounter;
          if(ledflashcounter==0)
          {
               hal_led_off(1);
          }
      }
      T1IF=0;       
 }
예제 #2
0
파일: main.c 프로젝트: liyanfeng/WSN2
void rfSendData(void)
{
  uint8 pTxData[20] ={'l','i','y','a','n','f','e','n','g','v','5','8','7','a','b',0};
    uint8 ret;
    uint8 recvCnt=0;
    uint8 ch=0;
    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();
    
    // Main loop
    while (TRUE) {
      recvCnt=0;
      
       ret = basicRfSendPacket(0xffff, pTxData, sizeof pTxData); //广播地址      
       if (ret == SUCCESS) {
          printf("send msg ok\r\n");
          hal_led_on(1);
          halMcuWaitMs(100);
          hal_led_off(1);
          halMcuWaitMs(900); 
       } else {
          printf("send msg error\r\n");
          hal_led_on(1);
          halMcuWaitMs(1000);
          hal_led_off(1);
       }
       
    }
}
예제 #3
0
static THD_FUNCTION(tx_thread, arg) {
	(void)arg;

	chRegSetThreadName("CC2520 Tx");

	tx_tp = chThdGetSelfX();

	for(;;) {
		chEvtWaitAny((eventmask_t) 1);

		while(tx_slot_read != tx_slot_write) {
			basicRfSendPacket(CC2520_DEST_ADDRESS, tx_buffer[tx_slot_read], tx_slot_len[tx_slot_read]);
			led_toggle(LED_GREEN);

			tx_slot_read++;
			if (tx_slot_read >= TX_BUFFER_SLOTS) {
				tx_slot_read = 0;
			}
		}
	}
}
예제 #4
0
static void appSwitch()
{
/****************************************************************by boo  
  halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
    halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
    halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");*/
#ifdef ASSY_EXP4618_CC2420
    halLcdClearLine(1);
    halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif


    // Initialize BasicRF
    basicRfConfig.myAddr = SWITCH_ADDR;
    if(basicRfInit(&basicRfConfig)==FAILED) {
      HAL_ASSERT(FALSE);
    }
    
    pTxData[0] = LIGHT_TOGGLE_CMD;

    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();

    // Main loop
    while (TRUE) {
        //if( halJoystickPushed() )**********************by boo
      if(halButtonPushed()==HAL_BUTTON_1)//**************by boo
        {

            basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);
            P1_1=~P1_1;
            // Put MCU to sleep. It will wake up on joystick interrupt
            halIntOff();
            halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
            // interrupt enable
            halIntOn();

        }
    }
}
예제 #5
0
파일: main.c 프로젝트: CDACBANG/Ubimote_HR
int main(void)
{

#error "Hi, Currently not working, still to be tested! - I didn't find time to debug it! "

	//halIntOn();
	unsigned long pktsSent = 0;
	perConfig.mode = PER_MODE_TX;
	    perConfig.state = PER_IDLE;
	    perConfig.channel = 26;
	    perConfig.txPower = 0;          // Index 0. Max output
	    perConfig.burstSize = 1000000;  // Max value
	    perConfig.pktRate   = 20;       // 20 pkts per second
	    perConfig.gainMode = PER_GAIN_MODE_NONE; // No PA/LNA

	    //
	        // Config basicRF
	        //
	        basicRfConfig.panId = PAN_ID;
	        basicRfConfig.ackRequest = false;



	    if(basicRfInit(&basicRfConfig) == FAILED)
	    {
	    while(1);
	    }

	    basicRfReceiveOff();
	    halRfSetTxPower(0);
	   // appTimerConfig(20);
	    halTimer32kInit(32768/20);
	    halTimer32kIntConnect(&appTimerIsr);    // Connect ISR
	    halTimer32kIntEnable();                 // Enable interrupts

	    while(1)
	       {
	    	if(perConfig.state == PER_TRANSMIT)
	    	        {
	    	            if(pktsSent < perConfig.burstSize) {
	    	                //
	    	                // Make sure sequence number has network byte order
	    	                //
	    	                UINT32_HTON(tTxPacket.seqNumber);

	    	                basicRfSendPacket(RX_ADDR, (unsigned char*)&tTxPacket, PACKET_SIZE);

	    	                //
	    	                // Change byte order back to host order before increment
	    	                //
	    	                UINT32_NTOH(tTxPacket.seqNumber);

	    	                //
	    	                // Update variables
	    	                //
	    	                tTxPacket.seqNumber++;
	    	                pktsSent++;
	    	                perConfig.state = PER_PACKET_RECEIVED;

	    	                //
	    	                // Update LED
	    	                //
	    	           //     bspLedToggle(BSP_LED_1);

	    	   }
	    	            else {
	    	                //
	    	                // Done sending packets, exit TX loop
	    	                //
	    	                break;
	    	            }
	    	        }
	       }
}
예제 #6
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  
  while(TRUE)
  {
    //----------------------
    // INITIALIZE
    //----------------------
    if(initFlag)
    {
      while(!start); //waiting for 'a' key from PC 
      //respond to PC -- going to try to start up WRS 
      start=0;
      pTxData[0] = INIT_COMM_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        state=1;
      }
      basicRfReceiveOn();
      //wait for ACK from WRS
      
      pTxData[0] = INIT_COEF_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        basicRfReceiveOn();
        
        //WAIT FOR COEFFICIENTS FROM WRS
        while(!basicRfPacketIsReady());//wait to receive acknowledgement
        
        if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        {
          if(pRxData[0] == 'C') 
          {  
            //Pass to PC
            for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
            {
              U0CSR &= ~0x02; //SET U0TX_BYTE to 0
              U0DBUF = pRxData[uartTxIndex];      
              while (!(U0CSR&0x02));
            }
          }    
        }
      }
      
      //finished sending coefficients to PC 
      
      basicRfReceiveOn();
      initFlag=0;
    }
    
    
    
    if(turnOnMotorFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        turnOnMotorFlag=0;
      }
    }
    
    if(sendInitFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        initFlag=1;
        sendInitFlag=0;
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          pRxData[0] == 'R';
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
      }
    }
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if(pRxData[0] == 'D')//||(pRxData[0] == 'I'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }    
  }
}
예제 #7
0
파일: dongle.c 프로젝트: eiselesr/ME391_HW3
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  while(!start); //waiting for 'a' key from PC 
  //respond to PC -- going to try to start up WRS 
  
  pTxData[0] = INIT_COMM_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    state=1;
  }
  basicRfReceiveOn();
  //wait for ACK from WRS
  
  pTxData[0] = INIT_COEF_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    basicRfReceiveOn();
    
    state=2;//continuous?
    
    //WAIT FOR COEFFICIENTS FROM WRS
    while(!basicRfPacketIsReady());//wait to receive acknowledgement
    
    if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
    {
      if(pRxData[0] == 'C') 
      {  
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
        // while(!ACK);//waiting for acknowledgement
      }    
    }
  }
  
  //finished sending coefficients to PC 
  
  basicRfReceiveOn();
  
  while(TRUE)
  {
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if((pRxData[0] == 'P')||(pRxData[0] == 'A'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }
    
    //Receive CMD from PC 
    if(changePWMflag)//have this be set in interrupt 
    {
      //basicRfReceiveOff();
      
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS
      {
        
        changePWMflag=0;
      }
      //basicRfReceiveOn();
        
        //        while(changePWMflag)//Keep receiving until PWM acknowledge is sent
        //        {
        //          while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think
        //          
        //          if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        //          {
        //            if(pRxData[0] == 'Z')
        //            {
        //              //receive current duty cycle and send back to PC 
        //              for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        //              {
        //                U0CSR &= ~0x02; //SET U0TX_BYTE to 0
        //                U0DBUF = pRxData[uartTxIndex];      
        //                while (!(U0CSR&0x02));
        //              }
        //              changePWMflag = 0;
        //            }
        //            //else send pressure?
        //          }
        //        }
        //      }
      
    }
  }//END OF MAIN WHILE LOOP
}