Esempio n. 1
0
 BYTE TemperatureRead(void)
 {
    double temp;
    BYTE tempHere;
    float tempAverage = 0;
    

    
    VBGResult = Read_VBGVoltage();
    
    
    ADCON0bits.CHS = 0x04;  // Temperature sensor channel select
    DelayMs(1);
    
    j=0;
    
    do
    {
    
      ADCON0bits.GO = 1;		    //Start A/D conversion
      while(ADCON0bits.DONE);
    
      SensorResult = ADRES;
      //ConsolePutROMString( (ROM char * const) "  \r\n TempResult:" );
      //PrintChar(ADRESH);
      //PrintChar(ADRESL);
    
    
      temp = (1200.0/VBGResult);
      temp = (temp * SensorResult);
      temp = (temp - 400.0)/19.5;
    
      tempArray[j] = (BYTE) temp;
      //tempIndex++;
    
      j++;
    }while(j < NUM_TEMP_SAMPLES);
    
    
    for(j = 0; j<NUM_TEMP_SAMPLES; j++)
    {
        tempAverage = (tempAverage + tempArray[j]);
    }
    tempAverage = (tempAverage/NUM_TEMP_SAMPLES);
    tempHere = (BYTE) tempAverage;
    tempAverage = (tempAverage - tempHere) * 10;
    
    if(tempAverage >= 5)
        tempHere = tempHere + 1;
        
    
    
    ConsolePutROMString( (ROM char * const) "  \r\n TempGrados:" );
    PrintDec((BYTE)tempHere);
    
    
    return (BYTE)tempHere;  


 }
Esempio n. 2
0
void DemoOutput_Channel(BYTE channel, BYTE Step)
{
    if( Step == 0 )
    {
        LCDDisplay((char *)"Connecting Peer  on Channel %d ", channel, TRUE);
        Printf("\r\nConnecting Peer on Channel ");
        PrintDec(channel);
        Printf("\r\n");
    }
    else
    {    
        LCDDisplay((char *)" Connected Peer  on Channel %d", channel, TRUE);
        Printf("\r\nConnected Peer on Channel ");
        PrintDec(channel);
        Printf("\r\n");
    }
}    
Esempio n. 3
0
void COUNT_FUNC(char *arg)
{
	unsigned int CMD_OK = 0;
	char *CONTEO;
	switch( arg[0])
	{
	case '0':
		if (CNT_STATUS)
		{
			CNT_STATUS = 0;
			TA1CCTL0 &= ~CCIE;
			CMD_OK = 1;
			P1OUT = 0;
			BLK_STATUS = 0;
			GRL_STATUS = 0;
			CNT_STATUS = 0;

		}else CMD_OK=2;
		break;
	case '1':
		if (!CNT_STATUS)
		{
			CONTEO = strtok( NULL, " ");
			limit = DecStrToInt( CONTEO );
			if ( limit )
			{
				PrintStr("\n");
				PrintStr("> Numero de cuentas: \n");
				PrintDec(limit);
				TA1CCTL0 |= CCIE;
				CMD_OK = 1;
				CNT_STATUS = 1;
				BLK_STATUS = 0;
				GRL_STATUS = 0;
			}else CMD_OK = 0;
		}else CMD_OK = 2;
		break;
	}
	switch ( CMD_OK ){
	case 0:
		PrintStr( "> Invalid argument\n" );
		break;
	case 1:
		PrintStr( "> OK\n" );
		break;
	case 2:
		PrintStr( "> No change\n" );
		break;
	}
}
Esempio n. 4
0
__interrupt void Timer_A1 (void)
{
	P1OUT ^= COUNT_LED; 	// Toggle P1.0
	M_SEGUNDOS++;
	TX_BUFFER++;
	if(M_SEGUNDOS >= 10)
	{
		//TX_BUFFER = COUNT;			// almacena de forma temporal el valor de cuenta
		COUNT = 0;					// reinicia el contador de pulsos
		PrintDec(TX_BUFFER);
		M_SEGUNDOS = 0;				// reinicia el contador de milisegundos
		limit--;
		if (limit < 1)
		{
			TA1CCTL0 &= ~CCIE;
			CNT_STATUS = 0;
			BLK_STATUS = 0;
			GRL_STATUS = 0;
		}
	}
}
int main(void)
#endif
{   
    BYTE i, j;
    BYTE TxSynCount = 0;
    BOOL bReceivedMessage = FALSE;
    _U16  m;

    
     #define BAUDRG 77
    /*******************************************************************/
    // Initialize the system
    /*******************************************************************/

    ANCON0 = 0XFF;     /*desactiva entradas analogicas*/
    ANCON1 = 0XFF;     /*desactiva entradas analogicas*/

    PPSUnLock();
    PPSOutput(PPS_RP10, PPS_TX2CK2);    // TX2 RP17/RC6
    PPSInput(PPS_RX2DT2, PPS_RP9);     // RX2 RP18/RC7

    PPSOutput(PPS_RP23, PPS_SDO2);    // SDO2 RP23/RD6
    PPSInput(PPS_SDI2, PPS_RP24);     // SDI2 RP24/RD7
    PPSOutput(PPS_RP22, PPS_SCK2);    // SCK2 RP22/RD5

    PPSLock();

     System_PeripheralPinSelect( ExternalInterrupt3, 19);  /*external interrupt 3 B3*/

     BoardInit();
     ConsoleInit();

     Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);

     Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/

     Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/
     Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/
     //Spi_SetMode(SPI_PORT1, 1);
     //Spi_SetMode(SPI_PORT1, 1);


    LED_1 = 1;
    LED_2 = 1;

    Read_MAC_Address();

    LED_1 = 0;
    LED_2 = 0;

                    ConsolePutROMString((ROM char *)"\r\n<MAC Addr:");
                 
                    PrintChar(myLongAddress[3]);
                    PrintChar(myLongAddress[2]);
                    PrintChar(myLongAddress[1]);
                    PrintChar(myLongAddress[0]);

                    ConsolePutROMString((ROM char *)"\r>");

        
    Printf("\r\nStarting Testing Interface for MiWi(TM) PRO Stack ...");
    #if defined(MRF24J40)
    Printf("\r\n     RF Transceiver: MRF24J40");
    #elif defined(MRF49XA)
    Printf("\r\n     RF Transceiver: MRF49XA");
    #elif defined(MRF89XA)
    Printf("\r\n     RF Transceiver: MRF89XA");
    #endif
    Printf("\r\n   Demo Instruction:");
    Printf("\r\n                     Press Enter to bring up the menu.");
    Printf("\r\n                     Type in hyper terminal to choose");
    Printf("\r\n                     menu item. ");
    Printf("\r\n\r\n");
   
    /*******************************************************************/
    // Following block display demo information on LCD of Explore 16 or 
    // PIC18 Explorer demo board.
    /*******************************************************************/
    #if defined(MRF49XA)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF49XA", 0, TRUE); 
    #elif defined(MRF24J40)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF24J40", 0, TRUE);
    #elif defined(MRF89XA)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF89XA", 0, TRUE); 
    #endif
    
    //if( (PUSH_BUTTON_1 == 0) || ( MiApp_ProtocolInit(TRUE) == FALSE ) )
    if (PUSH_BUTTON_1 == 1)
    {  

        MiApp_ProtocolInit(FALSE);


        LED_1 = 0;
        LED_2 = 0;

        #ifdef ENABLE_ACTIVE_SCAN
        
            myChannel = 0xFF;
            ConsolePutROMString((ROM char *)"\r\nStarting Active Scan...");
            
            LCDDisplay((char *)"Active Scanning", 0, FALSE);
    
            /*******************************************************************/
            // Function MiApp_SearchConnection will return the number of 
            // existing connections in all channels. It will help to decide 
            // which channel to operate on and which connection to add.
            // The return value is the number of connections. The connection 
            //     data are stored in global variable ActiveScanResults. 
            //     Maximum active scan result is defined as 
            //     ACTIVE_SCAN_RESULT_SIZE
            // The first parameter is the scan duration, which has the same 
            //     definition in Energy Scan. 10 is roughly 1 second. 9 is a 
            //     half second and 11 is 2 seconds. Maximum scan duration is 14, 
            //     or roughly 16 seconds.
            // The second parameter is the channel map. Bit 0 of the 
            //     double word parameter represents channel 0. For the 2.4GHz 
            //     frequency band, all possible channels are channel 11 to 
            //     channel 26. As the result, the bit map is 0x07FFF800. Stack 
            //     will filter out all invalid channels, so the application 
            //     only needs to pay attention to the channels that are not 
            //     preferred.
            /*******************************************************************/
            i = MiApp_SearchConnection(10, 0x02000000);
            
            if( i > 0 )
            {
                // now print out the scan result.
                Printf("\r\nActive Scan Results: \r\n");
                for(j = 0; j < i; j++)
                {
                    Printf("Channel: ");
                    PrintDec(ActiveScanResults[j].Channel );
                    Printf("   RSSI: ");
                    PrintChar(ActiveScanResults[j].RSSIValue);
                    Printf("\r\n");
                    myChannel = ActiveScanResults[j].Channel;
                    Printf("PeerInfo: ");
                    PrintChar( ActiveScanResults[j].PeerInfo[0]);
                }
            }
        #endif

    

        /*******************************************************************/
        // Function MiApp_ConnectionMode sets the connection mode for the 
        // protocol stack. Possible connection modes are:
        //  - ENABLE_ALL_CONN       accept all connection request
        //  - ENABLE_PREV_CONN      accept only known device to connect
        //  - ENABL_ACTIVE_SCAN_RSP do not accept connection request, but 
        //                          allow response to active scan
        //  - DISABLE_ALL_CONN      disable all connection request, including
        //                          active scan request
        /*******************************************************************/
        MiApp_ConnectionMode(ENABLE_ALL_CONN);
    
    
        if( i > 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. 
            /*******************************************************************/
            if( MiApp_EstablishConnection(0, CONN_MODE_DIRECT) == 0xFF )
            {
                Printf("\r\nJoin Fail");
            }
        }    
        else
        {
            /*******************************************************************/
            // Function MiApp_StartConnection tries to start a new network 
            //
            // The first parameter is the mode of start connection. There are 
            // two valid connection modes:
            //   - START_CONN_DIRECT        start the connection on current 
            //                              channel
            //   - START_CONN_ENERGY_SCN    perform an energy scan first, 
            //                              before starting the connection on 
            //                              the channel with least noise
            //   - START_CONN_CS_SCN        perform a carrier sense scan 
            //                              first, before starting the 
            //                              connection on the channel with 
            //                              least carrier sense noise. Not 
            //                              supported on currrent radios
            //
            // The second parameter is the scan duration, which has the same 
            //     definition in Energy Scan. 10 is roughly 1 second. 9 is a 
            //     half second and 11 is 2 seconds. Maximum scan duration is 
            //     14, or roughly 16 seconds.
            //
            // The third parameter is the channel map. Bit 0 of the 
            //     double word parameter represents channel 0. For the 2.4GHz 
            //     frequency band, all possible channels are channel 11 to 
            //     channel 26. As the result, the bit map is 0x07FFF800. Stack 
            //     will filter out all invalid channels, so the application 
            //     only needs to pay attention to the channels that are not 
            //     preferred.
            /*******************************************************************/
            #ifdef ENABLE_ED_SCAN
                //LCDDisplay((char *)"Active Scanning Energy Scanning", 0, FALSE);
                ConsolePutROMString((ROM char *)"\r\nActive Scanning Energy Scanning");
                MiApp_StartConnection(START_CONN_ENERGY_SCN, 10, 0x02000000);
            #endif
        }
        
        // Turn on LED 1 to indicate ready to accept new connections
        LED_1 = 1;
    }
    else
    {
        //LCDDisplay((char *)" Network Freezer    ENABLED", 0, TRUE);
        Printf("\r\nNetwork Freezer Feature is enabled. There will be no hand-shake process.\r\n");
        LED_1 = 1;
        DumpConnection(0xFF);
    }
                   
    LCDDisplay((char *)"Start Connection on Channel %d", currentChannel, TRUE);
    LCDDisplay((char *)"Testing Menu on  Hyper Terminal", 0, FALSE);

    while(1)
    {
        /*******************************************************************/
        // Function MiApp_MessageAvailable will return a boolean to indicate 
        // if a message for application layer has been received by the 
        // transceiver. If a message has been received, all information will 
        // be stored in the rxMessage, structure of RECEIVED_MESSAGE.
        /*******************************************************************/
        if( MiApp_MessageAvailable() )
        {
            /*******************************************************************/
            // If a packet has been received, following code prints out some of
            // the information available in rxFrame.
            /*******************************************************************/
            if( rxMessage.flags.bits.secEn )
            {
                ConsolePutROMString((ROM char *)"Secured ");
            }

            if( rxMessage.flags.bits.broadcast )
            {
                ConsolePutROMString((ROM char *)"Broadcast Packet with RSSI ");
            }
            else
            {
                ConsolePutROMString((ROM char *)"Unicast Packet with RSSI ");
            }
            PrintChar(rxMessage.PacketRSSI);
            if( rxMessage.flags.bits.srcPrsnt )
            {
                ConsolePutROMString((ROM char *)" from ");
                if( rxMessage.flags.bits.altSrcAddr )
                {
                    PrintChar(rxMessage.SourceAddress[1]);
                    PrintChar(rxMessage.SourceAddress[0]);
                }
                else
                {    
                    for(i = 0; i < MY_ADDRESS_LENGTH; i++)
                    {
                        PrintChar(rxMessage.SourceAddress[MY_ADDRESS_LENGTH-1-i]);
                    }
                }    
            }

            ConsolePutROMString((ROM char *)": ");
            
            
            for(i = 0; i < rxMessage.PayloadSize; i++)
            {
                ConsolePut(rxMessage.Payload[i]);
            }
            
            // Toggle LED2 to indicate receiving a packet.
            LED_2 ^= 1;
            
            /*******************************************************************/
            // Function MiApp_DiscardMessage is used to release the current 
            // received message. After calling this function, the stack can 
            // start to process the next received message.
            /*******************************************************************/          
            MiApp_DiscardMessage();
            
            bReceivedMessage = TRUE;
            
            /*******************************************************************/
            // Following block update the total received and transmitted messages
            // on the LCD of the demo board. 
            /*******************************************************************/
            LCDTRXCount(TxNum, ++RxNum);
        }
        else
        {
         ++m;

         if(m > 8000)
         {
             m=0;
             //LED_1 ^= 1;
             
                MiApp_FlushTx();
    	        MiApp_WriteData('H');
    	        MiApp_WriteData('o');
    	        MiApp_WriteData('l');
    	        MiApp_WriteData('a');
                MiApp_WriteData('a');
                MiApp_WriteData('a');
    	        MiApp_WriteData(0x0D);
    	        MiApp_WriteData(0x0A);
               MiApp_BroadcastPacket(FALSE);

         }



            if ( ConsoleIsGetReady() )
            {
                //ProcessMenu();
            } 
        }
    }
}
Esempio n. 6
0
void PingPongStateMachine()
{
    BYTE    i;
    WORD    j, k;
    BYTE    packagerssi;
    switch(case_value)
            {
                case 0:     //Send 0x01 frame to initiate ping - pong test
                    MiApp_FlushTx();
                    MiApp_WriteData(0x01);
                    for(i = 0; i < sizeof(PingPongPacket); i++)
                    {
                        MiApp_WriteData(PingPongPacket[i]);
                    }

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

                    // Function MiApp_BroadcastPacket is used to broadcast a message
                    //    The only parameter is the boolean to indicate if we need to
                    //       secure the frame

                    /*******************************************************************/
                    MiApp_BroadcastPacket(FALSE);
                    PingPong_Count = 0;
                    previous_state = 0;
                    case_value = 8;
                    LCDDisplay((char *)"Transmitting...", 0, TRUE);

                    //Printf("\r\nIn case 0");
                    break;

                case 1:     //Send 0x04 frames - indicating data transmission
                    MiApp_FlushTx();
                    MiApp_WriteData(0x04);
                    for(i = 0; i < sizeof(PingPongPacket); i++)
                    {
                        MiApp_WriteData(PingPongPacket[i]);
                    }

                    if(PingPong_Count != PingPong_Package)
                    {
                        MiApp_BroadcastPacket(FALSE);
                        case_value = 1;
                        PingPong_Count++;
                        LED_1 ^= 1;
                        LCDErase();
                        sprintf((char *)LCDText, (far rom char *) "Transmitting...");
                        sprintf((char *) &(LCDText[16]), (far rom char *) "Count: %d", PingPong_Count);
                        LCDUpdate();
                    }
                    else
                    {
                        Printf("\r\nSent Packet Count: ");
                        PrintDec(PingPong_Package);
                        PingPong_Count = 0;
                        case_value = 2;
                    }

                    previous_state = 1;

                    //Printf("\r\nIn case 1");
                    break;

                case 2:

                    //Send 0x02 frame to get status response
                    MiApp_FlushTx();
                    MiApp_WriteData(0x02);
                    for(i = 0; i < sizeof(PingPongPacket); i++)
                    {
                        MiApp_WriteData(PingPongPacket[i]);
                    }

                    MiApp_BroadcastPacket(FALSE);
                    previous_state = 2;
                    case_value = 8;

                    //Printf("\r\n In case 2");
                    break;

                case 3:

                    //Ping Pong Receive Mode
                    if(MiApp_MessageAvailable())
                    {
                        if(rxMessage.Payload[0] == 0x01)
                        {
                            BYTE    rssi = rxMessage.PacketRSSI;
                            #if defined(MRF24J40)
                            rssi = RSSIlookupTable[rssi];
                            #endif
                            MiApp_DiscardMessage();
                            MiApp_FlushTx();
                            MiApp_WriteData(0x03);
                            for(i = 0; i < sizeof(PingPongPacket); i++)
                            {
                                MiApp_WriteData(PingPongPacket[i]);
                            }

                            MiApp_BroadcastPacket(FALSE);
                            PingPong_RxCount = 0;

                            //LCDDisplay((char *)"Ping Pong Test  Rcvng.. RSSI:", rssi, TRUE);
                            LCDErase();
                            sprintf((char *)LCDText, (far rom char *) "Receiving.. ");
                            #if defined(MRF24J40)
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB): --");
                            #else
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB): --");
                            #endif
                            LCDUpdate();
                            packagerssi = rssi;
                        }
                        else if(rxMessage.Payload[0] == 0x04)
                        {
                            BYTE    rssi = rxMessage.PacketRSSI;
                            #if defined(MRF24J40)
                            rssi = RSSIlookupTable[rssi];
                            #endif
                            MiApp_DiscardMessage();
                            PingPong_RxCount++;
                            previous_state = 3;
                            LED_2 ^= 1;

                            LCDErase();
                            sprintf((char *)LCDText, (far rom char *) "Receiving..  %d", PingPong_RxCount);
                            #if defined(MRF24J40)
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB): -%d", packagerssi);
                            #else
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB):  -%d", packagerssi);
                            #endif
                            LCDUpdate();

                            case_value++;
                        }
                        else if(rxMessage.Payload[0] == 0x02)
                        {
                            Printf("\r\nReceived Packet Count:");
                            PrintDec(PingPong_RxCount);
                            MiApp_DiscardMessage();
                            case_value = case_value + 2;
                        }
                        else
                        {

                            //Printf("\r\nIllegal packet received with payload first byte set to - ");
                            //PrintDec(rxMessage.Payload[0]);
                            MiApp_DiscardMessage();
                        }
                    }

                    //Printf("\r\n In case 3");
                    break;

                case 4:
                    if(MiApp_MessageAvailable())
                    {
                        if(rxMessage.Payload[0] == 0x04)
                        {
                            BYTE    rssi = rxMessage.PacketRSSI;
                            MiApp_DiscardMessage();
                            PingPong_RxCount++;
                            LED_2 ^= 1;

                            LCDErase();
                            sprintf((char *)LCDText, (far rom char *) "Receiving..  %d", PingPong_RxCount);
                            #if defined(MRF24J40)
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB): -%d", packagerssi);
                            #else
                            sprintf((char *) &(LCDText[16]), (far rom char *) "RSSI (dB): %d", packagerssi);
                            #endif
                            LCDUpdate();
                        }
                        else if(rxMessage.Payload[0] == 0x02)
                        {
                            Printf("\r\nReceived Packet Count:");
                            PrintDec(PingPong_RxCount);
                            MiApp_DiscardMessage();
                            case_value++;
                        }
                        else
                        {

                            //Printf("\r\nIllegal packet received with payload first byte set to - ");
                            //PrintDec(rxMessage.Payload[0]);
                            //Printf("\r\n");
                            MiApp_DiscardMessage();
                        }
                    }

                    //Printf("\r\n In case 4");
                    break;

                case 5:
                    MiApp_FlushTx();
                    MiApp_WriteData(0x03);
                    for(i = 0; i < sizeof(PingPongPacket); i++)
                    {
                        MiApp_WriteData(PingPongPacket[i]);
                    }

                    MiApp_BroadcastPacket(FALSE);
                    previous_state = 0;
                    case_value = 8;

                    //Printf("\r\n In case 5");
                    break;

                case 8:
                    case_value = previous_state;
                    DelayMs(20);
                    if(MiApp_MessageAvailable())
                    {
                        if(rxMessage.Payload[0] == 0x03)
                        {
                            case_value = (previous_state + 1);
                        }

                        if(rxMessage.Payload[0] == 0x01)
                        {
                            case_value = (previous_state + 1);
                        }

                        if(rxMessage.Payload[0] == 0x02)
                        {
                            case_value = 5;
                        }

                        MiApp_DiscardMessage();
                    }

                    //Printf("\r\nIn case 8");
                    break;

                default:
                    break;
            }               //end of switch statement
}
Esempio n. 7
0
void DemoOutput_ChannelError(BYTE channel)
{
    Printf("\r\nSelection of channel ");
    PrintDec(channel);
    Printf(" is not supported in current configuration.\r\n");
}    
Esempio n. 8
0
void MyMIWI_Start(void) {
    
    BYTE    i;
    char    theStr[64];

    /*******************************************************************/
    // 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(myMIWI_Channel) == FALSE )
    {
        Printf("\r\nSelection of channel ");
        PrintDec(myMIWI_Channel);
        Printf(" is not supported in current condition.\r\n");
        return;
    }

    /*******************************************************************/
    // 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);

    /*******************************************************************/
    // 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.
    /*******************************************************************/

#if defined(MyMIWI_NODE1)
    i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT);
#else
    while( (i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT)) == 0xFF );
#endif

    if(i != 0xFF) {
        sprintf(theStr, "Connected Peer  on Channel %d\n>", myMIWI_Channel);
        MyConsole_SendMsg(theStr);
    }
    else {
        
    /*******************************************************************/
    // If no network can be found and join, we need to start a new 
    // network by calling function MiApp_StartConnection
    //
    // The first parameter is the mode of start connection. There are 
    // two valid connection modes:
    //   - START_CONN_DIRECT        start the connection on current 
    //                              channel
    //   - START_CONN_ENERGY_SCN    perform an energy scan first, 
    //                              before starting the connection on 
    //                              the channel with least noise
    //   - START_CONN_CS_SCN        perform a carrier sense scan 
    //                              first, before starting the 
    //                              connection on the channel with 
    //                              least carrier sense noise. Not
    //                              supported for current radios
    //
    // The second parameter is the scan duration, which has the same 
    //     definition in Energy Scan. 10 is roughly 1 second. 9 is a 
    //     half second and 11 is 2 seconds. Maximum scan duration is 
    //     14, or roughly 16 seconds.
    //
    // The third parameter is the channel map. Bit 0 of the 
    //     double word parameter represents channel 0. For the 2.4GHz 
    //     frequency band, all possible channels are channel 11 to 
    //     channel 26. As the result, the bit map is 0x07FFF800. Stack 
    //     will filter out all invalid channels, so the application 
    //     only needs to pay attention to the channels that are not 
    //     preferred.
    /*******************************************************************/
        MiApp_StartConnection(START_CONN_DIRECT, 10, 0);
        MyConsole_SendMsg("Start Connection\n>");
    }

    /*******************************************************************/
    // 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.
    /*******************************************************************/
    DumpConnection(0xFF);
}
Esempio n. 9
0
int main(int argc, char** argv)
{
 if(argc!=2) return 1;

 int fd;
 struct stat st;
 uint8_t *pdata;
 uint8_t ch,c;
 size_t shift=0,len;

 fd=open(argv[1],O_RDONLY); if(fd==-1) return 1;
 if(fstat(fd,&st)!=0) return 1;
 if(st.st_size==0) return 1;
 pdata=(uint8_t*) mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0);

 while(shift<st.st_size)
 {
  c=pdata[shift];
  if(c==bdct) {ch='d'; write(stdout,&ch,1);}
  if(c==blst) {ch='l'; write(stdout,&ch,1);}
  if(c==edct || pdata[shift]==elst) {ch='e'; write(stdout,&ch,1);}
  if((c>=48 && c<=57) || c=='+' || c=='-')
  {
   len=IntLen(pdata,shift,st.st_size);
   ch='i'; write(stdout,&ch,1);
   write(stdout,pdata+shift,len);
   ch='e'; write(stdout,&ch,1);
   shift+=len-1;
  }
  if(c==quo)
  {
   len=StrLen(pdata,shift,st.st_size);
   PrintDec(len); ch=':'; write(stdout,&ch,1);
   shift++;
   while(1)
   {
    c=pdata[shift];
    if(c==quo) break;
    if(c==scr)
    {
     shift++;
     c=pdata[shift];
     if(c=='x')
     {
      shift++;
      ch=Hex2Sym(pdata,shift);
      shift++;
     }
     else
     {
      switch(c)
      {
      case('n'): {ch='\n'; break;}
      case('a'): {ch='\a'; break;}
      case('b'): {ch='\b'; break;}
      case('e'): {ch='\e'; break;}
      case('f'): {ch='\f'; break;}
      case('r'): {ch='\r'; break;}
      case('t'): {ch='\t'; break;}
      case('v'): {ch='\v'; break;}
      default: ch=c;
      }
     }
    }
    else ch=c;
    write(stdout,&ch,1);
    shift++;
   }
  }