예제 #1
0
__interrupt void interrupt_slow_timeout (void)
{
  MRFI_WakeUp();
  MRFI_RxOn();
  start_fast_timeout();
  __bic_SR_register_on_exit(SCG1+SCG0);
}
예제 #2
0
int main(void)
{
  BSP_Init();
  MRFI_Init(/*0x9D, 0x58, 0x5C*/);
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  __bis_SR_register(GIE);
  
  while(1) {
    
      //NEED TO SET !!!
    uint8_t SubChannelsAmount = 13;
      //
    for(uint8_t SubChannelsCounter = 1; SubChannelsCounter <= SubChannelsAmount; SubChannelsCounter++)
    {
        SetBaseFrequencyRegisters(SubChannelsCounter);
        ReadChannelsAndSendRSSI();
    }
    
    TXString("\n",1);
  }
}
예제 #3
0
파일: synchrone.c 프로젝트: seaguest/Sensor
interrupt(PORT1_VECTOR) Buttopn(void)
{
	P1IFG &= ~0x04;
	P1OUT ^=  0x03;
	//after press the button , we can send and recieve message 
	BSP_Init();
	MRFI_Init();
	MRFI_SetLogicalChannel(1);
	MRFI_SetRFPwr(0);

	Uart_Init();

	MRFI_WakeUp();
	MRFI_RxOn(); 

	Scan_Init(&etat);			//open timer B for scan
	Start_Timer_Surveille();		//open timer for surveille

	print("\n\r");
	print("command: \n\r");
	print("o  : who is on line \n\r");
	print("v  : voisin \n\r");
	print("r  : router table \n\r");
	print("i  : sysinfo \n\r");
	print("ESC: help \n\r");
}
예제 #4
0
int main(void)
{
  BSP_Init();
  P2DIR |= 0x04;
  MRFI_Init();
  //mrfiSpiWriteReg(PATABLE,0x50);// -30dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x84);// -24dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x46);// -20dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x55);// -16dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x8D);// -14dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xC6);// -12dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x97);// -10dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x6E);// -8 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0x7F);// -6 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xA9);// -4 dBm Tx power
  //mrfiSpiWriteReg(PATABLE,0xBB);// -2 dBm Tx power
  mrfiSpiWriteReg(PATABLE,0xFE);// 0dBm Tx power
  mrfiSpiWriteReg(MDMCFG1,0x23);
  mrfiSpiWriteReg(MDMCFG0,0xF8);// 400kHz channel spacing
  mrfiSpiWriteReg(FREQ2,0x5C);
  mrfiSpiWriteReg(FREQ1,0x80);
  mrfiSpiWriteReg(FREQ0,0x00);  // 2.405GHz base frequency
  mrfiSpiWriteReg(CHANNR,0xBC); // channel 26
  MRFI_WakeUp();
  MRFI_RxOn();
  __bis_SR_register(GIE+LPM3_bits);
}
예제 #5
0
/***********************************************************************************
 * @fn          SMPL_Init
 *
 * @brief       Initialize the SimpliciTI stack.
 *
 * input parameters
 * @param   f  - Pointer to call back function. Function called by NWK when
 *               user application frame received. The callback is done in the
 *               ISR thread. Argument is Link ID associated with frame. Function
 *               returns 0 if frame is to be kept by NWK, otherwise 1. Frame
 *               should be kept if application will do a SMPL_Receive() in the
 *               user thread (recommended). Pointer may be NULL.
 *
 * output parameters
 *
 * @return   Status of operation:
 *             SMPL_SUCCESS
 *             SMPL_NO_JOIN     No Join reply. AP possibly not yet up.
 *             SMPL_NO_CHANNEL  Only if Frequency Agility enabled. Channel scan
 *                              failed. AP possibly not yet up.
 */
smplStatus_t SMPL_Init(uint8_t (*f)(linkID_t))
{
  smplStatus_t rc;

  if (!sInit_done)
  {
    /* set up radio. */
    MRFI_Init();

    /* initialize network */
    if ((rc=nwk_nwkInit(f)) != SMPL_SUCCESS)
    {
      return rc;
    }

    MRFI_WakeUp();
#if defined( FREQUENCY_AGILITY )
    {
      freqEntry_t chan;

      chan.logicalChan = 0;
      /* ok to set default channel explicitly now that MRFI initialized. */
      nwk_setChannel(&chan);
    }
#endif
    /* don't turn Rx on if we're an end device that isn't always on. */
    /* but do turn the radio on for PLL operations */
#if !defined( END_DEVICE ) || defined( NWK_PLL )
    MRFI_RxOn();
#endif

#if defined( END_DEVICE )
    /* All except End Devices are in promiscuous mode */
    MRFI_SetRxAddrFilter((uint8_t *)nwk_getMyAddress());
    MRFI_EnableRxAddrFilter();
#endif
  }
  sInit_done = 1;

#ifdef NWK_PLL
  /* If the PLL is enabled then it must get running before the join
   * request or the system may lock up in the join request becuase
   * PLL is not locked in.
   */
  // turn on the PLL
  SMPL_Ioctl(IOCTL_OBJ_PLL, IOCTL_ACT_ON, NULL);
  // reference clocks are by definition always locked.
  #ifndef NWK_PLL_REFERENCE_CLOCK
    // wait for a 5ms failure rate to be achieved
    while( nwk_pllIsLocked( 0 ) == false )
      nwk_pllBackgrounder( false );
  #endif
#endif

  /* Join. if no AP or Join fails that status is returned. */
  rc = nwk_join();

  return rc;
}
예제 #6
0
파일: swap.c 프로젝트: abdul/OpenChronos
/**
 * swStart
 *
 * Start (or re-start) SWAP comms
 */
void swStart(void)
{
  MRFI_WakeUp();
  // Enable reception
  MRFI_RxOn();
  
  // New SWAP state = running
  setChronosState(SYSTATE_RUNNING);
}
예제 #7
0
//=============================================
void gradient_Init(uint8_t is_sink)
{
  P1OUT &= ~0x03;
  print_debug("\r\nRESTART",9);
  //serial communication
  P3SEL    |= 0x30;     // P3.4,5 = USCI_A0 TXD/RXD
  UCA0CTL1  = UCSSEL_2; // SMCLK
  UCA0BR0   = 0x41;     // 9600 from 8Mhz
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;                     
  UCA0CTL1 &= ~UCSWRST; // Initialize USCI state machine
  IE2      |= UCA0RXIE; // Enable USCI_A0 RX interrupt
  __enable_interrupt();
  //button
  P1DIR    &= ~0x04;                        // P1.3 input
  P1OUT     = 0x04;
  P1REN    |= 0x04;                         // P1.3 pullup
  P1IE     |= 0x04;                         // P1.3 interrupt enabled
  P1IES    |= 0x04;                         // P1.3 Hi/lo edge
  P1IFG    &= ~0x04;                        // P1.3 IFG cleared
  //extension pins used for debugging
  P4SEL    &= ~0x20;                        // P4.5 generic I/O pin
  P2DIR    |=  0x02;                        // P2.1 output @ extension pin P4
  P2DIR    |=  0x08;                        // P2.3 output @ extension pin P6
  P4DIR    |=  0x08;                        // P4.3 output @ extension pin P8
  P4DIR    |=  0x20;                        // P4.5 output @ extension pin P10
  //set myAddr
  if(Flash_Addr == 0xFF)                      // no address set before
  {
    myAddr = MRFI_RandomByte();
    FCTL2 = FWKEY + FSSEL0 + FN1;             // MCLK/3 for Flash Timing Generator
    FCTL3 = FWKEY + LOCKA;                    // Clear LOCK & LOCKA bits
    FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation
    Flash_Addr = myAddr;
    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY + LOCKA + LOCK;             // Set LOCK & LOCKA bit
  } else {
    myAddr=Flash_Addr;
  }
  //set height and start clock
  if (is_sink) {
    myHeight = 0;
    BSP_TOGGLE_LED1();
  } else {
    myHeight = 255;
    //timer A
    BCSCTL3  |= LFXT1S_2;                      // LFXT1 = VLO
    TACCTL0   = CCIE;                          // TACCR0 interrupt enabled
    TACCR0    = 1500*WAKEUP_PERIOD_S_FIXED;    // 1500=1 second
    TACTL     = TASSEL_1 + MC_1 + ID_3;        // ACLK/8, upmode
  }
  gradient_set_state(GRADIENT_IDLE);
  mrfiSpiWriteReg(PATABLE, TX_POWER);
  print_cc2500_registers();
  MRFI_WakeUp();
  wor_start(IS_SINK_NODE);
}
예제 #8
0
int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;            // stop watchdog timer
  BSP_Init();
  MRFI_Init();
  MCU_Init(30000);                     //30000 is dummy large number
  MRFI_WakeUp();                       //start radio in idle state
  MRFI_RxOn();                         //put radio in Rx
  __bis_SR_register(LPM3_bits + GIE);
}
예제 #9
0
__interrupt void interrupt_button (void)
{
  P1IFG &= ~0x04;
  uint8_t counter;
  mrfiPacket_t packet;
  packet.frame[0]=8+20;
  MRFI_WakeUp();
  for (counter=50;counter>=1;counter--) {
     packet.frame[9]=counter;
     MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED);
  }
}
예제 #10
0
void MRFI_RxCompleteISR()
{
  mrfiPacket_t packet;
  stop_fast_timeout();
  stop_slow_timeout();
  MRFI_Receive(&packet);
  if (packet.frame[9]<4) {
    print_counter(packet.frame[9]);
    start_slow_timeout();
  } else {
    MRFI_WakeUp();
    MRFI_RxOn();
  }
}
예제 #11
0
/******************************************************************************
 * @fn          nwk_radioControl
 *
 * @brief       Handle radio control functions.
 *
 * input parameters
 * @param   action   - radio operation to perform. currently suppoerted:
 *                         sleep/unsleep
 * output parameters
 *
 * @return   Status of operation.
 */
smplStatus_t nwk_radioControl(ioctlAction_t action, void *val)
{
  smplStatus_t rc = SMPL_SUCCESS;

  if (IOCTL_ACT_RADIO_SLEEP == action)
  {
    /* go to sleep mode. */
    MRFI_RxIdle();
    MRFI_Sleep();
  }
  else if (IOCTL_ACT_RADIO_AWAKE == action)
  {
    MRFI_WakeUp();

#if !defined( END_DEVICE )
    MRFI_RxOn();
#endif

  }
  else if (IOCTL_ACT_RADIO_SIGINFO == action)
  {
    ioctlRadioSiginfo_t *pSigInfo = (ioctlRadioSiginfo_t *)val;
    connInfo_t          *pCInfo   = nwk_getConnInfo(pSigInfo->lid);

    if (!pCInfo)
    {
      return SMPL_BAD_PARAM;
    }
    memcpy(&pSigInfo->sigInfo, &pCInfo->sigInfo, sizeof(pCInfo->sigInfo));
  }
  else if (IOCTL_ACT_RADIO_RSSI == action)
  {
    *((rssi_t *)val) = MRFI_Rssi();
  }
  else if (IOCTL_ACT_RADIO_RXON == action)
  {
    MRFI_RxOn();
  }
  else if (IOCTL_ACT_RADIO_RXIDLE == action)
  {
    MRFI_RxIdle();
  }
  else
  {
    rc = SMPL_BAD_PARAM;
  }
  return rc;
}
예제 #12
0
int main(void)
{
  //int8_t rssi;
  //uint8_t channel;
  BSP_Init();
  MRFI_Init(/*0x9D, 0x58, 0x5C*/);
  P3SEL    |= 0x30;
  UCA0CTL1  = UCSSEL_2;
  UCA0BR0   = 0x41;
  UCA0BR1   = 0x3;
  UCA0MCTL  = UCBRS_2;
  UCA0CTL1 &= ~UCSWRST;
  MRFI_WakeUp();
  __bis_SR_register(GIE);
  while(1) {
    
    //change to 1th range of base frq
    SetBaseFrequencyRegisters(1);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(2);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(3);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(4);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(5);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(6);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(7);
    ReadChannelsAndSendRSSI();
    
    SetBaseFrequencyRegisters(8);
    ReadChannelsAndSendRSSI();
    
    TXString("\n",1);
  }
}
예제 #13
0
/***********************************************************************************
 * @fn          SMPL_Init
 *
 * @brief       Initialize the SimpliciTI stack.
 *
 * input parameters
 * @param   f  - Pointer to call back function. Function called by NWK when
 *               user application frame received. The callback is done in the
 *               ISR thread. Argument is Link ID associated with frame. Function
 *               returns 0 if frame is to be kept by NWK, otherwise 1. Frame
 *               should be kept if application will do a SMPL_Receive() in the
 *               user thread (recommended). Pointer may be NULL.
 *
 * output parameters
 *
 * @return   Status of operation:
 *             SMPL_SUCCESS
 *             SMPL_NO_JOIN     No Join reply. AP possibly not yet up.
 *             SMPL_NO_CHANNEL  Only if Frequency Agility enabled. Channel scan
 *                              failed. AP possibly not yet up.
 */
smplStatus_t SMPL_Init(uint8_t (*f)(linkID_t))
{
  smplStatus_t rc;

  if (!sInit_done)
  {
    /* set up radio. */
    MRFI_Init();

    /* initialize network */
    if ((rc=nwk_nwkInit(f)) != SMPL_SUCCESS)
    {
      return rc;
    }

    MRFI_WakeUp();
#if defined( FREQUENCY_AGILITY )
    {
      freqEntry_t chan;

      chan.logicalChan = 0;
      /* ok to set default channel explicitly now that MRFI initialized. */
      nwk_setChannel(&chan);
    }
#endif
    /* don't turn Rx on if we're an end device that isn't always on. */
#if !defined( END_DEVICE )
    MRFI_RxOn();
#endif

#if defined( END_DEVICE )
    /* All except End Devices are in promiscuous mode */
    MRFI_SetRxAddrFilter((uint8_t *)nwk_getMyAddress());
    MRFI_EnableRxAddrFilter();
#endif
  }
  sInit_done = 1;

  /* Join. if no AP or Join fails that status is returned. */
  rc = nwk_join();

  return rc;
}
예제 #14
0
/******************************************************************************
* @fn         mrfiLinkInit
*
* @brief      Initialise the MRFI layer. Selects RF channel and addresses.
*
* @param      src - source address (16 bit)
*
* @param      dst - destination address (16 bit)
*
* @return     void
*
*/
void mrfiLinkInit(uint16 src, uint16 dst, uint8 mrfiChannel)
{
#ifdef USB_SUSPEND_HOOKS
    // Register USB hooks if necessary
    pFnSuspendEnterHook= MRFI_Sleep;
    pFnSuspendExitHook= linkRestore;
#endif

    // Make sure the timer is initialised
    BSP_INIT_BOARD();

    // Initialise the addresses
    src_addr[0]=  LO_UINT16(MRFI_LINK_PAN_ID);
    src_addr[1]=  HI_UINT16(MRFI_LINK_PAN_ID);
    src_addr[2]=  LO_UINT16(src);
    src_addr[3]=  HI_UINT16(src);

    dest_addr[0]= LO_UINT16(MRFI_LINK_PAN_ID);
    dest_addr[1]= HI_UINT16(MRFI_LINK_PAN_ID);
    dest_addr[2]= LO_UINT16(dst);
    dest_addr[3]= HI_UINT16(dst);

    // Initialise MRFI link housekeeping data
    mrfiPktRdy= FALSE;
    fAckRdy= FALSE;
    seqSend= 0;
    seqRecv= 0;

    // Initialise MRFI
    MRFI_Init();
    MRFI_WakeUp();
    MRFI_SetLogicalChannel(mrfiChannel);
    MRFI_RxOn();
    MRFI_SetRxAddrFilter(src_addr);
    MRFI_EnableRxAddrFilter();

}
smplStatus_t nwk_radioControl(ioctlAction_t action, void *val)
{
    smplStatus_t rc = SMPL_SUCCESS;

    if (IOCTL_ACT_RADIO_SLEEP == action)
    {
        /* go to sleep mode. */
        MRFI_RxIdle();
        MRFI_Sleep();
    }
    else if (IOCTL_ACT_RADIO_AWAKE == action)
    {
        MRFI_WakeUp();

#if !defined(END_DEVICE)
        MRFI_RxOn();
#endif

    }
    else if (IOCTL_ACT_RADIO_SIGINFO == action)
    {
        ioctlRadioSiginfo_t *pSigInfo = (ioctlRadioSiginfo_t *)val;
        connInfo_t          *pCInfo   = nwk_getConnInfo(pSigInfo->lid);

        if (!pCInfo)
        {
            return SMPL_BAD_PARAM;
        }
        memcpy(&pSigInfo->sigInfo, &pCInfo->sigInfo, sizeof(pCInfo->sigInfo));
    }
    else if (IOCTL_ACT_RADIO_RSSI == action)
    {
        *((rssi_t *)val) = MRFI_Rssi();
    }
    else if (IOCTL_ACT_RADIO_RXON == action)
    {
        MRFI_RxOn();
    }
    else if (IOCTL_ACT_RADIO_RXIDLE == action)
    {
        MRFI_RxIdle();
    }
#ifdef EXTENDED_API
    else if (IOCTL_ACT_RADIO_SETPWR == action)
    {
        uint8_t idx;

        switch (*(ioctlLevel_t *)val)
        {
            case IOCTL_LEVEL_2:
                idx = 2;
                break;

            case IOCTL_LEVEL_1:
                idx = 1;
                break;

            case IOCTL_LEVEL_0:
                idx = 0;
                break;

            default:
                return SMPL_BAD_PARAM;
        }
        MRFI_SetRFPwr(idx);
        return SMPL_SUCCESS;
    }
#endif  /* EXTENDED_API */
    else
    {
        rc = SMPL_BAD_PARAM;
    }
    return rc;
}
예제 #16
0
/*------------------------------------------------------------------------------
 * Main
 *----------------------------------------------------------------------------*/
void main ( void ) {
  uint8_t tx_cmd;
  uint8_t tx_data;

  /* Initialize board devices */
  BSP_Init();
  MRFI_Init();

  /* Setup I/O */
  P1DIR |= (LED_RED+LED_GREEN);        // Enable LEDs  
  P1DIR &= ~PUSH_BUTTON;               // Enable push button  
  P1REN |= PUSH_BUTTON;                // Enable pull-up/down resistor
  P1IE |= PUSH_BUTTON;                 // Enable interrupt  
  P2DIR &= ~(TRIGGER_L2H+TRIGGER_H2L+MODE_SELECT); // Enable inputs
  P2IE |= (TRIGGER_L2H+TRIGGER_H2L);   // Enable interrupts
  P2IES &= ~TRIGGER_L2H;               // Set rising edge select
  P2IES |= TRIGGER_H2L;                // Set falling edge select

  /* Setup Timer A */
  BCSCTL3 |= LFXT1S_2;   // Source VLO @ 12kHz
  TACCTL0 = CCIE;        // Enable TimerA interrupt
  TACCR0 = 12000;        // ~1Hz
  TACTL = MC_1+TASSEL_1; // Count up + ACLK
  
  /* Initialize device settings */
  NODE1 |= LINK_MODE;

  /* Signal boot complete */  
  P1OUT |= (LED_RED+LED_GREEN);
  
  /* Enter main loop */
  while(1) {    
    __bis_SR_register(GIE+LPM3_bits);
    
    if (NODE1&MEASURE_VCC) {      
      volatile long temp;
      
      P1OUT |= LED_GREEN;
      
      ADC10CTL1 = INCH_11; 
      ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
      __delay_cycles(240);
      ADC10CTL0 |= ENC + ADC10SC;
      __bis_SR_register(CPUOFF+GIE);
      temp = ADC10MEM;
      tx_cmd = NODE_ALIVE;
      tx_data = (temp*25)/512;
      ADC10CTL0 &= ~ENC;
      ADC10CTL0 &= ~(REFON + ADC10ON);     
      NODE1 &= ~MEASURE_VCC;
      NODE1 |= (WAKE_RADIO+BROADCAST);
      TACCTL0 |= CCIE;

      P1OUT &= ~LED_GREEN;
    }
    
    if (NODE1&LINK_MODE) {      
      P1OUT ^= (LED_RED+LED_GREEN);
      tx_cmd = NEW_NODE;
      NODE1 |= (WAKE_RADIO+BROADCAST);      
    } else {
      if (NODE1&STATE_CHANGED) {
        if (NODE1&ALARMED) {
          P1OUT |= LED_RED;
          tx_cmd = ALARMED_NODE;
        } else {
          P1OUT &= ~LED_RED;
          tx_cmd = RESET_NODE;
        }
        NODE1 |= (WAKE_RADIO+BROADCAST);
      } else {
        if (NODE1&ALARMED) {
          P1OUT ^= LED_RED;
        } else {
          P1OUT &= ~LED_RED;
        }
      }
    }
    
    if (NODE1&WAKE_RADIO) {
      MRFI_WakeUp();
      MRFI_RxOn();
    }

    if (NODE1&BROADCAST) {  
      mrfiPacket_t tx_packet;
      
      tx_packet.frame[0] = 8+20;
      tx_packet.frame[SRC_ADDR] = my_addr;
      tx_packet.frame[DST_ADDR] = 0x00;  
      tx_packet.frame[CMD] = tx_cmd;
      tx_packet.frame[DATA] = tx_data;
      MRFI_Transmit(&tx_packet, MRFI_TX_TYPE_FORCED);
      
      NODE1 &= ~BROADCAST;
    }
    
    if (!(NODE1&WAKE_RADIO)) {
      MRFI_Sleep();
    }  
  }
}
//Main Execution of the program
main()
{
	int temp;
	int DegK;
	int light;
	int humidity;
	char c[4];
	
	
	mrfiPacket_t 	packet;
	unsigned char msg[9];
	
	BSP_Init();
	
	MRFI_Init();
	MRFI_WakeUp();
	
	//Disable Watchdog Timer
	WDTCTL = WDTPW + WDTHOLD;
	
	//Red LED P1.1
	P1DIR |= 0x01;
	P1OUT |= 0x00;
	
	//Analog Input Setup
	//P1.1 = A10 = Internal	= Temperature Sensor
	//P2.2 = A2  = Pin 5 	= Light Sensor
	//P2.3 = A3  = Pin 6 	= Humidity Sensor
	P1DIR &= ~0x02;	//P1.1 is Input
	P2DIR &= ~0x0C; //P2.2 & P2.3 are Inputs
	
	//Global Interrupt Enable
	__bis_SR_register(GIE);
	
	//Read Analog Sensors Forever!
	while(1)
	{
		//Read Light Sensor
		light = analogRead(2);
		light = (int) (light/1023.0*100.0);
		sleep(60000);
		//Read Humidity Sensor
		humidity = analogRead(3);
		humidity = (int) (((((humidity/1023.0)*2.5)-.45)*100.0)/1.5); //Derived from Datasheet Info
		sleep(60000);
		//ReadTemperature
		temp = analogRead(10); 
	    DegK = (int) (((temp - 673.0) * 423.0) / 1023.0) + 273.0;
	
		//Make all values into 3 digit strings.
		itoa(light, c, 999);
		if (light < 10)
		{
			msg[0] = '0';
			msg[1] = '0';
			msg[2] = c[0];
		}
		else if (light < 100)
		{
			msg[0] = '0';
			msg[1] = c[0];
			msg[2] = c[1];
		}
		else
		{
			msg[0] = c[0];
			msg[1] = c[1];
			msg[2] = c[2];
		}
		
		itoa(humidity, c, 999);
		if (humidity < 10)
		{
			msg[3] = '0';
			msg[4] = '0';
			msg[5] = c[0];
		}
		else if (humidity < 100)
		{
			msg[3] = '0';
			msg[4] = c[0];
			msg[5] = c[1];
		}
		else
		{
			msg[3] = c[0];
			msg[4] = c[1];
			msg[5] = c[2];
		}
		
		itoa(DegK, c, 999);
		if (DegK < 10)
		{
			msg[6] = '0';
			msg[7] = '0';
			msg[8] = c[0];
		}
		else if (DegK < 100)
		{
			msg[6] = '0';
			msg[7] = c[0];
			msg[8] = c[1];
		}
		else
		{
			msg[6] = c[0];
			msg[7] = c[1];
			msg[8] = c[2];
		}
		
		//Copy message into the packet.
		strcpy( &packet.frame[9] , msg );
		
		/** Enter source and destination addresses  **/
		//Source address here is useless, as this is a send-only application.
		memset( &packet.frame[1], 0x20, 4);
		memset( &packet.frame[5], 0x10, 4);
		
		// Enter length of packet.
		packet.frame[0] = 8 + strlen(msg); // 8-byte header, 20-byte payload.
		
		//Transmit 
		MRFI_Transmit(&packet , MRFI_TX_TYPE_FORCED);
		
		//Toggle led.
		P1OUT ^= RED_SEND_LED;
		
		//sleep.
		sleep(60000);
		sleep(60000);
		sleep(60000);
		sleep(60000);
		sleep(60000);
	}
	
}
예제 #18
0
/******************************************************************************
* @fn          linkRestore
*
* @brief       Restore the link after exiting from LPM. Typically used as a
*              USB resume hook.
*
* @param       none
*
* @return      none
*/
static void linkRestore(void)
{
    MRFI_WakeUp();
    MRFI_RxOn();
}