示例#1
0
/*********************************************************************
 * Function:        void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
 *
 * PreCondition:    LCD has been initialized
 *
 * Input:           txCount - the total number of transmitted messages
 *                  rxCount - the total number of received messages
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function display the total numbers of TX and
 *                  RX messages on the LCD, if applicable.
 *
 * Note:            This routine is only effective if Explorer16 or
 *                  PIC18 Explorer demo boards are used
 ********************************************************************/
void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
{
    #if defined(SENSOR_PORT_LCD)
        LCD_Erase();
        sprintf((char *)LCDText, (char*)"TX Messages: %3d", txCount);
        sprintf((char *)&(LCDText[16]), (char*)"RX Messages: %3d", rxCount);
        LCD_Update();
    #endif
}
示例#2
0
/*********************************************************************
     * Function:        void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
     *
     * PreCondition:    LCD has been initialized
     *
     * Input:           txCount - the total number of transmitted messages
     *                  rxCount - the total number of received messages
     *
     * Output:          None
     *
     * Side Effects:    None
     *
     * Overview:        This function display the total numbers of TX and
     *                  RX messages on the LCD, if applicable.
     *
     * Note:            This routine is only effective if Explorer16 or
     *                  PIC18 Explorer demo boards are used
     ********************************************************************/
    void LCDTRXCount(uint8_t txCount, uint8_t rxCount)
    {
        
        LCD_Erase();
        sprintf((char *)LCDText, (char*)"TX Messages: %3d", txCount);
        sprintf((char *)&(LCDText[16]), (char*)"RX Messages: %3d", rxCount);
        LCD_Update();
       
    }
示例#3
0
/*********************************************************************
 * Function:        void LCD_Display(char *text, uint8_t value, bool delay)
 *
 * PreCondition:    LCD has been initialized
 *
 * Input:           text - text message to be displayed on LCD
 *                  value - the text message allows up to one byte 
 *                          of variable in the message
 *                  delay - whether need to display the message for
 *                          2 second without change
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function display the text message on the LCD, 
 *                  including up to one uint8_t variable, if applicable.
 *
 * Note:            This routine is only effective if Explorer16 or
 *                  PIC18 Explorer demo boards are used
 ********************************************************************/
void LCD_Display(char *text, uint8_t value, bool delay)
{
    LCD_Erase();
    sprintf((char *)LCDText, (char*)text, value); 
    LCD_Update();
    
    // display the message for 2 seconds
    if( delay )
    {
        uint8_t i;
        for(i = 0; i < 8; i++)
        {
            DELAY_ms(250);
        }
    }
}
示例#4
0
/*********************************************************************
 * Function:        void LCDDisplay(char *text, uint8_t value, bool delay)
 *
 * PreCondition:    LCD has been initialized
 *
 * Input:           text - text message to be displayed on LCD
 *                  value - the text message allows up to one byte
 *                          of variable in the message
 *                  delay - whether need to display the message for
 *                          2 second without change
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function display the text message on the LCD,
 *                  including up to one uint8_t variable, if applicable.
 *
 * Note:            This routine is only effective if Explorer16 or
 *                  PIC18 Explorer demo boards are used
 ********************************************************************/
void LCDDisplay(char *text, uint8_t value, bool delay)
{
    #if defined(SENSOR_PORT_LCD)
        LCD_Erase();
        sprintf((char *)LCDText, (char*)text, value);
        LCD_Update();

        // display the message for 2 seconds
        if( delay )
        {
            uint8_t i;
            for(i = 0; i < 8; i++)
            {
                DELAY_ms(250);
            }
        }
    #endif
}
示例#5
0
void main (void)
{
    uint8_t    i;
    
    
    SYSTEM_Initialize();
    CONSOLE_Initialize();

    /*******************************************************************/

    // Initialize the system

    /*******************************************************************/

    /*******************************************************************/

    // Following block display demo information on LCD of Explore 16 or
    // PIC18 Explorer demo board.

    /*******************************************************************/
    LCDDisplay((char *)"Chat Demo", 0, true);

    // Clear the screen (VT100)
    Printf("\x1b[2J");
    // Send the cursor home (VT100)
    Printf("\x1b[H");
    Printf("\r\nChat Demo");
            #if defined(MRF24J40)
    Printf("\r\nRF Transceiver: MRF24J40");
            #elif defined(MRF49XA)
    Printf("\r\nRF Transceiver: MRF49XA");
            #elif defined(MRF89XA)
    Printf("\r\nRF Transceiver: MRF89XA");
            #endif
    Printf("\r\n\r\nDemo Instruction:");
    Printf("\r\nUse Console to Chat with the Peer Device");
    Printf("\r\n");
    LED_1 = 0;
    LED_2 = 0;

   /******************************************************************/

    // Read the MAC address from the MAC EEPROM on the PICTail Card

    ReadMacAddress();

    // ..and display on terminal

	Printf("\r\n\r\nMy MAC Address: 0x");
    for(i = 0; i < MY_ADDRESS_LENGTH; i++)
    {
        CONSOLE_PrintHex(myLongAddress[MY_ADDRESS_LENGTH-1-i]);
    }
    /*******************************************************************/

    // Initialize Microchip proprietary protocol. Which protocol to use
    // depends on the configuration in ConfigApp.h

    /*******************************************************************/

    /*******************************************************************/

    // Function MiApp_ProtocolInit initialize the protocol stack. The
    // only input parameter indicates if previous network configuration
    // should be restored. In this simple example, we assume that the
    // network starts from scratch.

    /*******************************************************************/
    MiApp_ProtocolInit(false);

    // Set default channel
    if(MiApp_SetChannel(myChannel) == false)
    {
        Printf("\r\nERROR: Unable to program the channel\r\n");
        Printf("\r\nPress MCLR to start again\r\n");
        LCDDisplay((char *)"Error: Unable to Program Channel ", 0, TRUE);
        while(1);
        //Display error message on LCD and Console
    }

    /*******************************************************************/

    // Function MiApp_ConnectionMode defines the connection mode. The
    // possible connection modes are:
    //  ENABLE_ALL_CONN:    Enable all kinds of connection
    //  ENABLE_PREV_CONN:   Only allow connection already exists in
    //                      connection table
    //  ENABL_ACTIVE_SCAN_RSP:  Allow response to Active scan
    //  DISABLE_ALL_CONN:   Disable all connections.

    /*******************************************************************/
    MiApp_ConnectionMode(ENABLE_ALL_CONN);

    /*******************************************************************/

    // Display current opertion on LCD of demo board, if applicable

    /*******************************************************************/
    LCDDisplay((char *)"Connecting Peer  on Channel %d ", myChannel, true);
    Printf("\r\n\r\nConnecting to Peer...\r\n");

    /*******************************************************************/

    // Function MiApp_StartConnection will enable a node to start operating
    // in a variety of ways. Usually, this fucntion is called by the
    // PAN Coordinator who is the first in the PAN.
    //
    // The first parameter defines the mode to start the PAN in
    //
    // The second parameter defines the scan duration (if energy/carrier
    // sense scan is enabled). 0 if START_CONN_DIRECT used.
    //
    // The third parameter is a bit map of of the channels to perform the
    // noise scan on. 0 if START_CONN_DIRECT used.

    /*******************************************************************/

    MiApp_StartConnection(START_CONN_DIRECT, 0, 0) ;
    /*******************************************************************/

    // Function MiApp_EstablishConnection try to establish a new
    // connection with peer device.
    // The first parameter is the index to the active scan result,
    //      which is acquired by discovery process (active scan). If
    //      the value of the index is 0xFF, try to establish a
    //      connection with any peer.
    // The second parameter is the mode to establish connection,
    //      either direct or indirect. Direct mode means connection
    //      within the radio range; indirect mode means connection
    //      may or may not in the radio range.

    /*******************************************************************/
    #ifdef ENABLE_HAND_SHAKE
    i = 0xFF;
    while(i == 0xFF)
    {
        i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT);
    }
    #endif

    /*******************************************************************/

    // Display current opertion on LCD of demo board, if applicable

    /*******************************************************************/

    LCDDisplay((char *)"Joined  Network Successfully..", 0, true);

    /*******************************************************************/

    // Function DumpConnection is used to print out the content of the
    //  Connection Entry on the hyperterminal. It may be useful in
    //  the debugging phase.
    // The only parameter of this function is the index of the
    //  Connection Entry. The value of 0xFF means to print out all
    //  valid Connection Entry; otherwise, the Connection Entry
    //  of the input index will be printed out.

    /*******************************************************************/
    #ifdef ENABLE_DUMP
    DumpConnection(0xFF);
    #endif

    #ifndef ENABLE_POWERSAVE
    // Turn on LED 1 to indicate P2P connection established
    LED_1 = 1;
    #endif
    DELAY_ms(100);

    LCDBacklightON();
    LCD_Erase();
    sprintf((char *)LCDText, (char *)"MyAddr:   %02x%02x%02x", myLongAddress[2],
             myLongAddress[1], myLongAddress[0]);
    sprintf((char *) &(LCDText[16]), (char *)"PeerAddr: %02x%02x%02x", ConnectionTable[i].Address[2],
             ConnectionTable[i].Address[1], ConnectionTable[i].Address[0]);
    LCD_Update();

    /*******************************************************************/

    // Following block display demo instructions on LCD based on the
    // demo board used.

    /*******************************************************************/
    Printf("-------------------------------------------------------\r\n");
    Printf("Chat Window: \r\n");
    Printf("-------------------------------------------------------\r\n");
    Printf("$$");

    while(1)
    {
        if(MiApp_MessageAvailable())
        {  
            ProcessRxMessage();      
        }

        if(CONSOLE_IsGetReady())
        {
            FormatTxMessage();
            
        }

        if(messagePending)
        {
            tickCurrent = MiWi_TickGet();
            if
            (
                (MiWi_TickGetDiff(tickCurrent, tickPrevious) > (ONE_SECOND * 30)) ||
                (TxMessageSize >= MAX_MESSAGE_LEN) ||
                (transmitPending == true)
            )
            {
                
                TransmitMessage();


            }
        }

        // Display connection table if RB0 is pressed
        if(PUSH_BUTTON_1 == 0)
    	{
        	while(PUSH_BUTTON_1 == 0);
        	Printf("\r\n\r\nDumping Connection Table...\r\n");
        	DumpConnection(0xFF);
        	Printf("-------------------------------------------------------\r\n");
    		Printf("Chat Window: \r\n");
    		Printf("-------------------------------------------------------\r\n");
    		Printf("$$ ");
    	}


    }

    //Enable device to foward the received packet information to the console
}                           //end of main
示例#6
0
void run_star_demo(void)
{
    #if defined(PROTOCOL_STAR)
        t1 = MiWi_TickGet();
        LCDDisplay((char *)"Sleeping!!", 0, false);
        while(1)
        {
           
            t2 = MiWi_TickGet();    // Calculate the Time for Sleeping device

            if((MiWi_TickGetDiff(t2,t1) > (ONE_SECOND * 20)))
            {
              awake = true;
              #if !defined(EIGHT_BIT_WIRELESS_BOARD)
              LCD_BacklightON();
              #endif
      
              MiApp_TransceiverPowerState(POWER_STATE_WAKEUP_DR);
              LCDDisplay((char *)"Woke Up!!!", 0, false);
              DELAY_ms(1000);
              STAR_DEMO_OPTIONS_MESSAGE (false);
              tt1 = MiWi_TickGet();  
            }
            while(awake)   
            {
                tt2 = MiWi_TickGet();    
                if((MiWi_TickGetDiff(tt2,tt1) > (ONE_SECOND * 10)))   
                {
                    // The Indirect Message for a Sleeping RFD is stored in PAN CO 
                    // We periodically send Data Requests for the Indirect Message to 
                    // not loose a message. 
                    CheckForData();
                    tt1 = MiWi_TickGet();
                }    
                /*******************************************************************/
                // Function MiApp_MessageAvailable returns a boolean to indicate if 
                // a packet has been received by the transceiver. If a packet has 
                // been received, all information will be stored in the rxFrame, 
                // structure of RECEIVED_MESSAGE.
                /*******************************************************************/

                if( MiApp_MessageAvailable())
                {

                    /*******************************************************************/
                    // If a packet has been received, update the information available 
                    // in rxMessage.
                    /*******************************************************************/
                    DemoOutput_UpdateTxRx(TxNum, ++RxNum);
                    DELAY_ms(2000);
                    // Toggle LED2 to indicate receiving a packet.
                    LED_2 ^= 1;

                    /*******************************************************************/
                    // Function MiApp_DiscardMessage is used to release the current 
                    //  received packet.
                    // After calling this function, the stack can start to process the
                    //  next received frame 
                    /*******************************************************************/        
                    MiApp_DiscardMessage();



                    /****************************************/
                }
                else
                {
                    /*******************************************************************/
                    // If no packet received, now we can check if we want to send out
                    // any information.
                    // Function ButtonPressed will return if any of the two buttons
                    // has been pushed.
                    /*******************************************************************/
                    uint8_t PressedButton = ButtonPressed();
                    if ( PressedButton == 1 || PressedButton == 2)
                    {
                        
                        uint8_t select_ed =0;
                        bool update_ed = true;
                        while(update_ed == true)
                        {

                            //User Selected Change end device
                            LCD_Erase();
                            if (myConnectionIndex_in_PanCo  == select_ed)
                            {   // if END_device displays itself , "me" is added in display to denote itself 
                                sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x-me",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0],
                                        END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] );
                            }
                            else
                            {
                                sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0],
                                        END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] );
                            }
                            sprintf((char *)LCDText, (char*)"RB0:%02d-%02x%02x%02x",END_DEVICES_Short_Address[select_ed].connection_slot,END_DEVICES_Short_Address[select_ed].Address[0],
                                        END_DEVICES_Short_Address[select_ed].Address[1],END_DEVICES_Short_Address[select_ed].Address[2] );
                            sprintf((char *)&(LCDText[16]), (char*)"RB2: Change node");
                            LCD_Update();
                            chk_sel_status = true;
                            bool sw_layer_ack_status , mac_ack_status;
                            while(chk_sel_status)
                            {
                                uint8_t switch_val = ButtonPressed();
                                if(switch_val == 1)
                                {
                                    update_ed = false;
                                    chk_sel_status = false;
                                    update_ed = false;
                                    // Star_User_Data is defined in star_demo.c 
                                    // Its user data  , in case of Star Network 60 bytes of 
                                    // Data can be sent at a time from one END_DEVICE_TO_ANOTHER 
                                    // Edx --> Pan CO --> EDy
                                    if (myConnectionIndex_in_PanCo == select_ed)
                                    {
                                        MiApp_FlushTx();
                                        for (i = 0 ; i < 21 ; i++)
                                        {
                                            MiApp_WriteData(MiWi[(TxSynCount%6)][i]);
                                        }

                                        // IF on the demo , a END_Device displays its own Connection Detail
                                        // We unicast data packet to just PAN COR , No forwarding
                                        #if defined(ENABLE_SECURITY)
                                            mac_ack_status = MiApp_UnicastConnection (0, true);
                                        #else
                                            mac_ack_status = MiApp_UnicastConnection (0, false);
                                        #endif
                                            TxNum++;
                                    }
                                    else
                                    {
                                        // Data can be sent at a time from one END_DEVICE_TO_ANOTHER 
                                        // Edx --> Pan CO --> EDy
                                        // To forward a Packet from one ED to another ED , the first 4 bytes should holding
                                        // a CMD and end dest device short address (3 bytes)
                                        MiApp_FlushTx();
                                        MiApp_WriteData(CMD_FORWRD_PACKET);
                                        MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[0]);// sending the first byte payload as the destination nodes
                                        MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[1]);// sending the first byte payload as the destination nodes
                                        MiApp_WriteData(END_DEVICES_Short_Address[select_ed].Address[2]);// sending the first byte payload as the destination nodes
                                        for (i = 4 ; i < 25 ; i++)
                                        {
                                            MiApp_WriteData(MiWi[(TxSynCount%6)][i-4]);
                                        }
                                        #if defined(ENABLE_SECURITY)
                                            sw_layer_ack_status = MiApp_UnicastStar (true);
                                        #else
                                            sw_layer_ack_status = MiApp_UnicastStar (false);
                                        #endif


                                        #if defined(ENABLE_APP_LAYER_ACK)
                                            if (sw_layer_ack_status)
                                            {
                                                TxNum++;     // Tx was successful
                                            }
                                            else
                                            {
                                                LCDDisplay((char *)"Data_Sending_Fail!!", 0, false); 
                                            }
                                        #else    
                                            TxNum++;
                                        #endif

                                    }

                                } // end of switch_val == 1
                                else if(switch_val == 2)
                                {
                                    if (select_ed > end_nodes-1)
                                    {    
                                        select_ed = 0;
                                    }
                                    else
                                    {
                                        select_ed = select_ed+1;
                                    }
                                    chk_sel_status = false;

                                } // end of switch_val == 2
                            }  // end of chk_sel_status

                        } // end of updating the LCD info
                        STAR_DEMO_OPTIONS_MESSAGE (false);
                    } // end of actions on button press
                } // end of check for user inputs (button press check)

                t3 = MiWi_TickGet();
                if((MiWi_TickGetDiff(t3,t2) > (ONE_SECOND * 40)))
                {
                    awake = false;
                    #if !defined(EIGHT_BIT_WIRELESS_BOARD)
                              LCD_BacklightOFF();
                    #endif
                    MiApp_TransceiverPowerState(POWER_STATE_SLEEP);
                    LCDDisplay((char *)"Sleeping!!!", 0, false);
                    DELAY_ms(1000);
                    t1 = t3;

                }
                
                if (lost_connection && !role)
                {
                    MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT);
                    lost_connection = false;

                }

            }  // end of actions performed while node is awake
            
           

            
        } // end of while(1)
    #endif
}