void DemoOutput_Instruction(void) { #if defined(EXPLORER16) LCDDisplay((char *)"RD6: Broadcast RD7: Unicast", 0, FALSE); #elif defined(PIC18_EXPLORER) LCDDisplay((char *)"RB0: Broadcast RA5: Unicast", 0, FALSE); #elif defined(EIGHT_BIT_WIRELESS_BOARD) LCDDisplay((char *)"RB0: Broadcast RB2: Unicast", 0, FALSE); #endif }
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"); } }
int main(void) #endif { BYTE i; static DWORD t = 0; static DWORD dwLastIP = 0; static UINT8 updateDisplay = 0; #if defined (EZ_CONFIG_STORE) static DWORD ButtonPushStart = 0; #endif #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) UINT8 channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN; // WF_PRESCAN tWFScanResult bssDesc; #endif // Initialize application specific hardware InitializeBoard(); // Initiates board setup process if button is depressed // on startup if (BUTTON1_IO == 0u) { while (BUTTON1_IO == 0); SelfTestMode(); } //#if defined(USE_LCD) /*******************************************************************/ // Initialize the LCD /*******************************************************************/ ConfigureLCD_SPI(); LCDInit(); /*******************************************************************/ // Display Start-up Splash Screen /*******************************************************************/ LCDBacklightON(); LEDS_ON(); LCDErase(); sprintf((char *) LCDText, (char*) " MiWi - WiFi "); sprintf((char *) &(LCDText[16]), (char*) " Gateway Demo"); LCDUpdate(); /*******************************************************************/ // Initialize the MiWi Protocol Stack. The only input parameter indicates // if previous network configuration should be restored. /*******************************************************************/ MiApp_ProtocolInit(FALSE); /*******************************************************************/ // Set Device Communication Channel /*******************************************************************/ if (MiApp_SetChannel(myChannel) == FALSE) { LCDDisplay((char *) "ERROR: Unable to Set Channel..", 0, TRUE); while (1); } /*******************************************************************/ // Set 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. /*******************************************************************/ i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT); /*******************************************************************/ // Display current opertion on LCD of demo board, if applicable /*******************************************************************/ if (i != 0xFF) { ; // Connected Peer on Channel } 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); } // Turn OFF LCD after setting up MiWi Connection LCDBacklightOFF(); // Initialize stack-related hardware components that may be // required by the UART configuration routines TickInit(); #if defined(STACK_USE_MPFS2) MPFSInit(); #endif // Initialize Stack and application related NV variables into AppConfig. InitAppConfig(); dwLastIP = AppConfig.MyIPAddr.Val; // Initialize core stack layers (MAC, ARP, TCP, UDP) and // application modules (HTTP, SNMP, etc.) StackInit(); #if defined ( EZ_CONFIG_SCAN ) WFInitScan(); #endif #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) // WF_PRESCAN: Pre-scan before starting up as SoftAP mode WF_CASetScanType(MY_DEFAULT_SCAN_TYPE); WF_CASetChannelList(channelList, sizeof (channelList)); if (WFStartScan() == WF_SUCCESS) { SCAN_SET_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; //putsUART("main: Prescan WFStartScan() success ................. \r\n"); } // Needed to trigger g_scan_done WFRetrieveScanResult(0, &bssDesc); #else #if defined(WF_CS_TRIS) WF_Connect(); #endif // defined(WF_CS_TRIS) #endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) // Initialize any application-specific modules or functions/ // For this demo application, this only includes the // UART 2 TCP Bridge #if defined(STACK_USE_UART2TCP_BRIDGE) UART2TCPBridgeInit(); #endif #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLInitialize(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSInitialize(MY_DEFAULT_HOST_NAME); mDNSServiceRegister( (const char *) AppConfig.NetBIOSName, // base name of the service "_http._tcp.local", // type of the service 80, // TCP or UDP port, at which this service is available ((const BYTE *) "path=/index.htm"), // TXT info 1, // auto rename the service when if needed NULL, // no callback function NULL // no application context ); mDNSMulticastFilterRegister(); #endif #if defined(WF_CONSOLE) WFConsoleInit(); #endif // Now that all items are initialized, begin the co-operative // multitasking loop. This infinite loop will continuously // execute all stack-related tasks, as well as your own // application's functions. Custom functions should be added // at the end of this loop. // Note that this is a "co-operative mult-tasking" mechanism // where every task performs its tasks (whether all in one shot // or part of it) and returns so that other tasks can do their // job. // If a task needs very long time to do its job, it must be broken // down into smaller pieces so that other tasks can have CPU time. LEDS_OFF(); while (1) { /*******************************************************************/ // Check Button Events /*******************************************************************/ if (BUTTON1_IO == 0u) { while (BUTTON1_IO == 0); LCDErase(); sprintf((char *) LCDText, (char*) "Erase Room Info?"); sprintf((char *) &(LCDText[16]), (char*) "SW0:Yes SW2:No"); LCDUpdate(); while (1) { if (BUTTON1_IO == 0u) { while (BUTTON1_IO == 0); LCDDisplay((char *) "STATUS: Erasing...", 0, TRUE); EraseRoomInfo(); DisplaySSID(); break; } else if (BUTTON2_IO == 0u) { while (BUTTON2_IO == 0); DisplaySSID(); break; } } } // Blink LED0 twice per sec when unconfigured, once per sec after config if ((TickGet() - t >= TICK_SECOND / (4ul - (CFGCXT.isWifiDoneConfigure * 2ul)))) { t = TickGet(); LED0_INV(); } if(CFGCXT.isWifiNeedToConfigure) updateDisplay = 1; #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) if (g_scan_done) { if (g_prescan_waiting) { SCANCXT.displayIdx = 0; while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) { WFDisplayScanMgr(); } #if defined(WF_CS_TRIS) WF_Connect(); #endif DisplaySSID(); g_scan_done = 0; g_prescan_waiting = 0; } } #endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) // This task performs normal stack task including checking // for incoming packet, type of packet and calling // appropriate stack entity to process it. StackTask(); WiFiTask(); // This tasks invokes each of the core stack application tasks StackApplications(); #if defined(STACK_USE_ZEROCONF_LINK_LOCAL) ZeroconfLLProcess(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSProcess(); // Use this function to exercise service update function // HTTPUpdateRecord(); #endif // Process application specific tasks here. // For this demo app, this will include the Generic TCP // client and servers, and the SNMP, Ping, and SNMP Trap // demos. Following that, we will process any IO from // the inputs on the board itself. // Any custom modules or processing you need to do should // go here. #if defined(WF_CONSOLE) //WFConsoleProcess(); // #if !defined(STACK_USE_EZ_CONFIG) // IperfAppCall(); // #endif //WFConsoleProcessEpilogue(); wait_console_input: #endif #if defined(STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE) GenericTCPClient(); #endif #if defined(STACK_USE_GENERIC_TCP_SERVER_EXAMPLE) GenericTCPServer(); #endif #if defined(STACK_USE_SMTP_CLIENT) SMTPDemo(); #endif #if defined(STACK_USE_ICMP_CLIENT) PingDemo(); //PingConsole(); #endif #if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED) //User should use one of the following SNMP demo // This routine demonstrates V1 or V2 trap formats with one variable binding. SNMPTrapDemo(); #if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3) //This routine provides V2 format notifications with multiple (3) variable bindings //User should modify this routine to send v2 trap format notifications with the required varbinds. //SNMPV2TrapDemo(); #endif if (gSendTrapFlag) SNMPSendTrap(); #endif #if defined ( WF_CONSOLE ) && defined ( EZ_CONFIG_SCAN ) WFDisplayScanMgr(); #endif #if defined(STACK_USE_BERKELEY_API) BerkeleyTCPClientDemo(); BerkeleyTCPServerDemo(); BerkeleyUDPClientDemo(); #endif if((updateDisplay && CFGCXT.isWifiDoneConfigure) || (dwLastIP != AppConfig.MyIPAddr.Val)) { if(dwLastIP != AppConfig.MyIPAddr.Val) dwLastIP = AppConfig.MyIPAddr.Val; if(updateDisplay && CFGCXT.isWifiDoneConfigure) updateDisplay = 0; #if defined(STACK_USE_ANNOUNCE) AnnounceIP(); #endif #if defined(STACK_USE_ZEROCONF_MDNS_SD) mDNSFillHostRecord(); #endif DisplaySSID(); } } }
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(); } } } }
/********************************************************************* * Function: void RangeDemo(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: Following routine * * * Note: **********************************************************************/ void RangeDemo(void) { BOOL Run_Demo = TRUE; BOOL Tx_Packet = TRUE; BYTE rssi = 0; BYTE Pkt_Loss_Cnt = 0; MIWI_TICK tick1, tick2; BYTE switch_val; /*******************************************************************/ // Dispaly Range Demo Splach Screen /*******************************************************************/ LCDBacklightON(); LCDDisplay((char *)" Microchip Range Demo ", 0, TRUE); LCDBacklightOFF(); /*******************************************************************/ // Read Start tickcount /*******************************************************************/ tick1 = MiWi_TickGet(); while(Run_Demo) { /*******************************************************************/ // Read current tickcount /*******************************************************************/ tick2 = MiWi_TickGet(); // Send a Message if((MiWi_TickGetDiff(tick2,tick1) > (ONE_SECOND * TX_PKT_INTERVAL))) { LCDErase(); if(Tx_Packet) { LCDDisplay((char *)"Checking Signal Strength...", 0, TRUE); MiApp_FlushTx(); MiApp_WriteData(RANGE_PKT); MiApp_WriteData(0x4D); MiApp_WriteData(0x69); MiApp_WriteData(0x57); MiApp_WriteData(0x69); MiApp_WriteData(0x20); MiApp_WriteData(0x52); MiApp_WriteData(0x6F); MiApp_WriteData(0x63); MiApp_WriteData(0x6B); MiApp_WriteData(0x73); MiApp_WriteData(0x21); if( MiApp_UnicastConnection(0, FALSE) == FALSE ) Pkt_Loss_Cnt++; else Pkt_Loss_Cnt = 0; Tx_Packet = FALSE; } else { if(Pkt_Loss_Cnt < 1) { if(rssi > 120) { sprintf((char *)&LCDText, (far rom char*)"Strength: High "); LED0 = 1; LED1 = 0; LED2 = 0; } else if(rssi < 121 && rssi > 60) { sprintf((char *)&LCDText, (far rom char*)"Strength: Medium"); LED0 = 1; LED1 = 1; LED2 = 0; } else if(rssi < 61) { sprintf((char *)&LCDText, (far rom char*)"Strength: Low"); LED0 = 0; LED1 = 1; LED2 = 0; } // Convert to dB //rssi = RSSIlookupTable[rssi]; sprintf((char *)&(LCDText[16]), (far rom char*)"Rcv RSSI: %03d", rssi); } else { LCDDisplay((char *)"No Device Found or Out of Range ", 0, TRUE); LED0 = 0; LED1 = 0; LED2 = 1; } LCDUpdate(); Tx_Packet = TRUE; } /*******************************************************************/ // Read New Start tickcount /*******************************************************************/ tick1 = MiWi_TickGet(); } // Check if Message Available if(MiApp_MessageAvailable()) { if(rxMessage.Payload[0] == EXIT_PKT) { MiApp_DiscardMessage(); MiApp_FlushTx(); MiApp_WriteData(ACK_PKT); MiApp_UnicastConnection(0, FALSE); Run_Demo = FALSE; LCDBacklightON(); LCDDisplay((char *)" Exiting.... Range Demo ", 0, TRUE); LCDBacklightOFF(); } else if(rxMessage.Payload[0] == RANGE_PKT) { // Get RSSI value from Recieved Packet rssi = rxMessage.PacketRSSI; // Disguard the Packet so can recieve next MiApp_DiscardMessage(); } else MiApp_DiscardMessage(); } // Check if Switch Pressed switch_val = ButtonPressed(); if((switch_val == SW0) || (switch_val == SW1)) { /*******************************************************************/ // Send Exit Demo Request Packet and exit Range Demo /*******************************************************************/ MiApp_FlushTx(); MiApp_WriteData(EXIT_PKT); MiApp_UnicastConnection(0, FALSE); LCDBacklightON(); LCDDisplay((char *)" Exiting.... Range Demo ", 0, TRUE); LCDBacklightOFF(); tick1 = MiWi_TickGet(); // Wait for ACK Packet while(Run_Demo) { if(MiApp_MessageAvailable()) { if(rxMessage.Payload[0] == ACK_PKT) Run_Demo = FALSE; MiApp_DiscardMessage(); } if ((MiWi_TickGetDiff(tick2,tick1) > (ONE_SECOND * EXIT_DEMO_TIMEOUT))) Run_Demo = FALSE; tick2 = MiWi_TickGet(); } } } }
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 }
/********************************************************************* * Function: void main(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: This is the main function that runs the simple * example demo. The purpose of this example is to * demonstrate the simple application programming * interface for the MiWi(TM) Development * Environment. By virtually total of less than 30 * lines of code, we can develop a complete * application using MiApp interface. The * application will first try to establish a P2P * link with another device and then process the * received information as well as transmit its own * information. * MiWi(TM) DE also support a set of rich * features. Example code FeatureExample will * demonstrate how to implement the rich features * through MiApp programming interfaces. * * Note: **********************************************************************/ void main (void) { BYTE i; BYTE TxSynCount = 0; BYTE TxSynCount2 = 0; BoardInit(); //Has LCDInit() also covered in this, need to make this separate to ensure that if there was a problem with I2C the board hangs up ConsoleInit(); // Initialize the system /*******************************************************************/ LCDBacklightON(); LCDDisplay((char *)"8-Bit Wireless Development Kit ", 0, TRUE); DelayMs(5000); LCDBacklightOFF(); Printf("\r\nInput Configuration:"); Printf("\r\n Button 1: RB0"); Printf("\r\n Button 2: RB2"); Printf("\r\nOutput Configuration:"); Printf("\r\n LED 1: RA2"); Printf("\r\n LED 2: RA3"); Printf("\r\n LED 3: RB1"); #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 Power on the board until LED 1 lights up "); Printf("\r\n to indicate connecting with peer. "); Printf("\r\n Ping Pong Results will be displayed on LCD"); Printf("\r\n Use MCLR + RB2 to switch to Self Test Mode. "); Printf("\r\n\r\n"); LED_1 = 0; LED_2 = 0; MiApp_ProtocolInit(FALSE); // Set default channel if(MiApp_SetChannel(myChannel) == FALSE) { #if defined(__18CXX) return; #else return (0); #endif } /*******************************************************************/ // 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); /*******************************************************************/ // 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 = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT); #endif /*******************************************************************/ // Display current opertion on LCD of demo board, if applicable /*******************************************************************/ if(i != 0xFF) { LCDDisplay((char *)"Joined Network Successfully..", 0, TRUE); } else { MiApp_StartConnection(START_CONN_DIRECT, 10, 0); } /*******************************************************************/ // 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 DelayMs(20); LCDDisplay((char *)"Ping Pong Demo RB0(TX) RB2(RX)", 0, TRUE); /*******************************************************************/ // Following block display demo instructions on LCD based on the // demo board used. /*******************************************************************/ /*Configure the device in transmit or Receive Mode*/ ReadButtonPress(); while(1) { PingPongStateMachine(); } //end of while(1) } //end of main
void DemoOutput_Greeting(void) { #if defined(MRF49XA) #if defined(PROTOCOL_P2P) LCDDisplay((char *)"Simple P2P Demo MRF49XA Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI) LCDDisplay((char *)"Simple MiWi Demo MRF49XA Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI_PRO) LCDDisplay((char *)"Simple MiWi PRO MRF49XA Node 2", 0, TRUE); #endif #elif defined(MRF24J40) #if defined(PROTOCOL_P2P) LCDDisplay((char *)"Simple P2P Demo MRF24J40 Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI) LCDDisplay((char *)"Simple MiWi DemoMRF24J40 Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI_PRO) LCDDisplay((char *)"Simple MiWi PRO MRF24J40 Node 2", 0, TRUE); #endif #elif defined(MRF89XA) #if defined(PROTOCOL_P2P) LCDDisplay((char *)"Simple P2P Demo MRF89XA Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI) LCDDisplay((char *)"Simple MiWi Demo MRF89XA Node 2", 0, TRUE); #endif #if defined(PROTOCOL_MIWI_PRO) LCDDisplay((char *)"Simple MiWi PRO MRF89XA Node 2", 0, TRUE); #endif #endif #if defined(PROTOCOL_P2P) Printf("\r\nStarting Node 2 of Simple Demo for MiWi(TM) P2P Stack ..."); #endif #if defined(PROTOCOL_MIWI) Printf("\r\nStarting Node 2 of Simple Demo for MiWi(TM) Stack ..."); #endif #if defined(PROTOCOL_MIWI_PRO) Printf("\r\nStarting Node 2 of Simple Demo for MiWi(TM) PRO Stack ..."); #endif #if defined(PICDEMZ) Printf("\r\nInput Configuration:"); Printf("\r\n Button 1: RB5"); Printf("\r\n Button 2: RB4"); Printf("\r\nOutput Configuration:"); Printf("\r\n RS232 port"); Printf("\r\n LED 1: RA0"); Printf("\r\n LED 2: RA1"); #endif #if defined(PIC18_EXPLORER) Printf("\r\nInput Configuration:"); Printf("\r\n Button 1: RB0"); Printf("\r\n Button 2: RA5"); Printf("\r\nOutput Configuration:"); Printf("\r\n RS232 port"); Printf("\r\n USB port"); Printf("\r\n LED 1: D8"); Printf("\r\n LED 2: D7"); #endif #if defined(EIGHT_BIT_WIRELESS_BOARD) Printf("\r\nInput Configuration:"); Printf("\r\n Button 1: RB0"); Printf("\r\n Button 2: RB2"); Printf("\r\nOutput Configuration:"); Printf("\r\n LED 1: RA2"); Printf("\r\n LED 2: RA3"); #endif #if defined(EXPLORER16) Printf("\r\nInput Configuration:"); Printf("\r\n Button 1: RD6"); Printf("\r\n Button 2: RD7"); Printf("\r\nOutput Configuration:"); Printf("\r\n RS232 port"); Printf("\r\n LED 1: D10"); Printf("\r\n LED 2: D9"); #endif #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 Power on the board until LED 1 lights up"); Printf("\r\n to indicate connecting with peer. Push"); Printf("\r\n Button 1 to broadcast message. Push Button"); Printf("\r\n 2 to unicast encrypted message. LED 2 will"); Printf("\r\n be toggled upon receiving messages. "); Printf("\r\n\r\n"); }
void DemoOutput_UnicastFail(void) { Printf("\r\nUnicast Failed\r\n"); LCDDisplay((char *)" Unicast Failed", 0, TRUE); }
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
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 }