void ProcessMenu( void ) { BYTE c; BYTE i; // Get the key value. c = ConsoleGet(); ConsolePut( c ); switch (c) { case '1': ConsolePutROMString((ROM char * const)"\r\n1=ENABLE_ALL 2=ENABLE PREV 3=ENABLE SCAN 4=DISABLE: "); while( !ConsoleIsGetReady()); c = ConsoleGet(); ConsolePut(c); switch(c) { case '1': MiApp_ConnectionMode(ENABLE_ALL_CONN); break; case '2': MiApp_ConnectionMode(ENABLE_PREV_CONN); break; case '3': MiApp_ConnectionMode(ENABLE_ACTIVE_SCAN_RSP); break; case '4': MiApp_ConnectionMode(DISABLE_ALL_CONN); break; default: break; } break; case '2': Printf("\r\nFamily Tree: "); for(i = 0; i < NUM_COORDINATOR; i++) { PrintChar(FamilyTree[i]); Printf(" "); } break; case '3': Printf("\r\nMy Routing Table: "); for(i = 0; i < NUM_COORDINATOR/8; i++) { PrintChar(RoutingTable[i]); } Printf("\r\nNeighbor Routing Table: "); for(i = 0; i < NUM_COORDINATOR; i++) { BYTE j; for(j = 0; j < NUM_COORDINATOR/8; j++) { PrintChar(NeighborRoutingTable[i][j]); } Printf(" "); } break; case '4': { WORD_VAL tempShortAddr; Printf("\r\n1=Broadcast 2=Unicast Connection 3=Unicast Addr: "); while( !ConsoleIsGetReady()); c = ConsoleGet(); ConsolePut(c); MiApp_FlushTx(); MiApp_WriteData('T'); MiApp_WriteData('e'); MiApp_WriteData('s'); MiApp_WriteData('t'); MiApp_WriteData(0x0D); MiApp_WriteData(0x0A); switch(c) { case '1': MiApp_BroadcastPacket(FALSE); TxNum++; break; case '2': Printf("\r\nConnection Index: "); while( !ConsoleIsGetReady()); c = GetHexDigit(); MiApp_UnicastConnection(c, FALSE); TxNum++; break; case '3': Printf("\r\n1=Long Address 2=Short Address: "); while( !ConsoleIsGetReady()); c = ConsoleGet(); ConsolePut(c); switch(c) { case '1': Printf("\r\nDestination Long Address: "); for(i = 0; i < MY_ADDRESS_LENGTH; i++) { tempLongAddress[MY_ADDRESS_LENGTH-1-i] = GetMACByte(); } MiApp_UnicastAddress(tempLongAddress, TRUE, FALSE); TxNum++; break; case '2': Printf("\r\nDestination Short Address: "); tempLongAddress[1] = GetMACByte(); tempLongAddress[0] = GetMACByte(); MiApp_UnicastAddress(tempLongAddress, FALSE, FALSE); TxNum++; break; default: break; } break; default: break; } } LCDTRXCount(TxNum, RxNum); break; case '5': { Printf("\r\nMSB of the Coordinator: "); i = GetMACByte(); Printf("\r\nSet MSB of this Node's Parent: "); FamilyTree[i] = GetMACByte(); } break; case '6': { Printf("\r\nSet my Routing Table: "); for(i = 0; i < NUM_COORDINATOR/8; i++) { RoutingTable[i] = GetMACByte(); Printf(" "); } } break; case '7': { BYTE j; Printf("\r\nNode Number: "); i = GetMACByte(); Printf("\r\nContent of Neighbor Routing Table: "); for(j = 0; j < NUM_COORDINATOR/8; j++) { NeighborRoutingTable[i][j] = GetMACByte(); Printf(" "); } } break; case '8': { MiApp_InitChannelHopping(0xFFFFFFFF); } break; case '9': { Printf("\r\nSocket: "); PrintChar(MiApp_EstablishConnection(0xFF, CONN_MODE_INDIRECT)); } break; case 'z': case 'Z': { DumpConnection(0xFF); } default: break; } PrintMenu(); }
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(); } } } }
void DemoOutput_UpdateTxRx(BYTE TxNum, BYTE RxNum) { LCDTRXCount(TxNum, RxNum); }