/******************************************************************************* * main subroutine * * This routine will run continuously after program initialization * * Within each iteration it will collect 1 temperature reading, 1 humidity * reading, save the latest data, and check if it should transmit the last * chunk of data from EEPROM * * Inputs: None * Outputs: None ******************************************************************************/ void main(void) { Initial(); while (1) { if ( USARTFlag ) { //Checks if there was a new byte from USART CheckUSART(); } if ( OKGOFlag ) { //Check if "ok to send" has been received if ( SENDFlag ) { //Check if latest data block is ready SendDATA(TTRAN); //Send temperature data FIRST = 0; //Clear flag for first time transmission SENDFlag = 0; //Clear flag for latest chunk of data } } if ( TimeStamp > 900 ) { WakeXBEE(); //Wake up XBEE if more than 15 minutes has } // passed if ( TimeStamp > 3600 ) { //One hour has passed T0CONbits.TMR0ON = 0; //Turn off TMR0 SendBYTE(0xFF); //Send Ack command to tell GSMRS we are done while( 1 ) { TxERROR(TTRAN); } } while ( SECFlag == 0 ) {} //Waits until 1 second has passed ADCON0bits.GO = 1; //Start collecting temperature data while ( ADCON0bits.GO ) {} //Wait for collection to finish ADConverter(); SECFlag = 0; //Reset 1 second counter Store(); //Store latest readings in RAM or EEPROM } }
//======================================================= // FUNCTION: MacUpPortRecv // PURPOSE: Receive the frame from the LLC layer //======================================================= void S80211DcfMacUpPortRecv (MobileNode *node, WGN_802_11_Mac_Frame *frame) { unsigned int DIFS; DIFS = SecToNsec(GetDIFS()); //********************************FOR TEST ONLY***********************************// //PrintLine(); //printf("NODE %d: MAC LAYER RECEIVE A PACKET FROM LLC LAYER.\n",node->Id); //PrintLine(); node->nodeMac->HasPkt = TRUE; //Encapsulate the frame into 802.11 format. (actually pesudo 802.11 frame format) //and put it into the pktTx buffer to be sent when the channel is available SendDATA(node, frame); SendRTS(node); if (CheckIfIsBroadCastPkt(node->nodeMac->pktTx) == TRUE ) { node->nodeStats->BroadcastTx += 1; } else node->nodeStats->UnicastTx += 1; if ( Timer_SwitchSign(node, BF_TIMER)==OFF ) { if ( CheckIfChannelIdle(node) == TRUE ) { if ( Timer_SwitchSign(node, DF_TIMER)==OFF ) DFTimer_Start(node, DIFS); } //If the medium is NOT IDLE, then backoff timer may be started. else { BFTimer_Start(node, FALSE); } } }