/********************************************************************* * Function: void LCDDisplay(char *text, BYTE value, BOOL delay) * * PreCondition: LCD has been initialized * * Input: text - text message to be displayed on LCD * value - the text message allows up to one byte * of variable in the message * delay - whether need to display the message for * 2 second without change * * Output: None * * Side Effects: None * * Overview: This function display the text message on the LCD, * including up to one BYTE variable, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCDDisplay(char *text, BYTE value, BOOL delay) { #if defined(EXPLORER16) || defined(PIC18_EXPLORER) || \ (defined(EIGHT_BIT_WIRELESS_BOARD) && defined(SENSOR_PORT_LCD)) LCDErase(); #if defined(PIC18_EXPLORER) || defined(EIGHT_BIT_WIRELESS_BOARD) sprintf((char *)LCDText, (far rom char *) text, value); #elif defined(EXPLORER16) sprintf((char *)LCDText, (const char *)text, value); #endif LCDUpdate(); // display the message for 2 seconds if(delay) { BYTE i; for(i = 0; i < 8; i++) { DelayMs(250); } } #endif }
/********************************************************************* * Function: void LCDTRXCount(BYTE txCount, BYTE rxCount) * * PreCondition: LCD has been initialized * * Input: txCount - the total number of transmitted messages * rxCount - the total number of received messages * * Output: None * * Side Effects: None * * Overview: This function display the total numbers of TX and * RX messages on the LCD, if applicable. * * Note: This routine is only effective if Explorer16 or * PIC18 Explorer demo boards are used ********************************************************************/ void LCDTRXCount(BYTE txCount, BYTE rxCount) { #if defined(EXPLORER16) || defined(PIC18_EXPLORER) || (defined(EIGHT_BIT_WIRELESS_BOARD) && defined(SENSOR_PORT_LCD)) LCDErase(); #if defined(PIC18_EXPLORER) || defined(EIGHT_BIT_WIRELESS_BOARD) sprintf((char *)LCDText, (far rom char*)"TX Messages: %3d", txCount); sprintf((char *)&(LCDText[16]), (far rom char*)"RX Messages: %3d", rxCount); #else sprintf((char *)LCDText, (const char*)"TX Messages: %d", txCount); sprintf((char *)&(LCDText[16]), (const char*)"RX Messages: %d", rxCount); #endif LCDUpdate(); #endif }
void DisplaySSID(void) { IP_ADDR IPVal; BYTE IPDigit[4]; BYTE i; LCDErase(); LCDUpdate(); //Display SSID //REMOVE ME /* if (AppConfig.networkType == WF_ADHOC) sprintf((char *)MySSID, "MCHP_ADHOC_%02x%02x", AppConfig.MyMACAddr.v[4], AppConfig.MyMACAddr.v[5]); else if (AppConfig.networkType == WF_SOFT_AP) sprintf((char *) MySSID, "MCHP_SFTAP_%02x%02x", AppConfig.MyMACAddr.v[4], AppConfig.MyMACAddr.v[5]); else sprintf((char *) MySSID, "MCHP_%02x%02x", AppConfig.MyMACAddr.v[4], AppConfig.MyMACAddr.v[5]); */ sprintf((char *) LCDText, (char*) AppConfig.MySSID); //Display IP Address IPVal = AppConfig.MyIPAddr; BYTE j; BYTE LCDPos = 16; for (i = 0; i < sizeof (IP_ADDR); i++) { uitoa((WORD) IPVal.v[i], IPDigit); for (j = 0; j < strlen((char*) IPDigit); j++) { LCDText[LCDPos++] = IPDigit[j]; } if (i == sizeof (IP_ADDR) - 1) break; LCDText[LCDPos++] = '.'; } if (LCDPos < 32u) LCDText[LCDPos] = 0; LCDUpdate(); }
void HTTPExecCmd(BYTE** argv, BYTE argc) { BYTE command; BYTE var; #if defined(ENABLE_REMOTE_CONFIG) DWORD_VAL dwVal; BYTE CurrentArg; WORD_VAL TmpWord; #endif /* * Design your pages such that they contain command code * as a one character numerical value. * Being a one character numerical value greatly simplifies * the job. */ command = argv[0][0] - '0'; /* * Find out the cgi file name and interpret parameters * accordingly */ switch(command) { case CGI_CMD_DIGOUT: // ACTION=0 /* * Identify the parameters. * Compare it in upper case format. */ var = argv[1][0] - '0'; switch(var) { case CMD_LED1: // NAME=0 // Toggle LED. LED1_IO ^= 1; break; case CMD_LED2: // NAME=1 // Toggle LED. LED2_IO ^= 1; break; } memcpypgm2ram((void*)argv[0], (ROM void*)COMMANDS_OK_PAGE, COMMANDS_OK_PAGE_LEN); break; #if defined(USE_LCD) case CGI_CMD_LCDOUT: // ACTION=1 if(argc > 2u) // Text provided in argv[2] { // Convert %20 to spaces, and other URL transformations UnencodeURL(argv[2]); // Write 32 received characters or less to LCDText if(strlen((char*)argv[2]) < 32u) { memset(LCDText, ' ', 32); strcpy((char*)LCDText, (char*)argv[2]); } else { memcpy(LCDText, (void*)argv[2], 32); } // Write LCDText to the LCD LCDUpdate(); } else // No text provided { LCDErase(); } memcpypgm2ram((void*)argv[0], (ROM void*)COMMANDS_OK_PAGE, COMMANDS_OK_PAGE_LEN); break; #endif #if defined(ENABLE_REMOTE_CONFIG) // Possibly useful code for remotely reconfiguring the board through // HTTP case CGI_CMD_RECONFIG: // ACTION=2 // Loop through all variables that we've been given CurrentArg = 1; while(argc > CurrentArg) { // Get the variable identifier (HTML "name"), and // increment to the variable's value TmpWord.v[1] = argv[CurrentArg][0]; TmpWord.v[0] = argv[CurrentArg++][1]; var = hexatob(TmpWord); // Make sure the variable's value exists if(CurrentArg >= argc) break; // Take action with this variable/value switch(var) { case VAR_IP_ADDRESS: case VAR_SUBNET_MASK: case VAR_GATEWAY_ADDRESS: { // Convert the returned value to the 4 octect // binary representation if(!StringToIPAddress(argv[CurrentArg], (IP_ADDR*)&dwVal)) break; // Reconfigure the App to use the new values if(var == VAR_IP_ADDRESS) { // Cause the IP address to be rebroadcast // through Announce.c or the RS232 port since // we now have a new IP address if(dwVal.Val != *(DWORD*)&AppConfig.MyIPAddr) DHCPBindCount++; // Set the new address memcpy((void*)&AppConfig.MyIPAddr, (void*)&dwVal, sizeof(AppConfig.MyIPAddr)); } else if(var == VAR_SUBNET_MASK) memcpy((void*)&AppConfig.MyMask, (void*)&dwVal, sizeof(AppConfig.MyMask)); else if(var == VAR_GATEWAY_ADDRESS) memcpy((void*)&AppConfig.MyGateway, (void*)&dwVal, sizeof(AppConfig.MyGateway)); } break; case VAR_DHCP: if(AppConfig.Flags.bIsDHCPEnabled) { if(!(argv[CurrentArg][0]-'0')) { AppConfig.Flags.bIsDHCPEnabled = FALSE; } } else { if(argv[CurrentArg][0]-'0') { AppConfig.MyIPAddr.Val = 0x00000000ul; AppConfig.Flags.bIsDHCPEnabled = TRUE; AppConfig.Flags.bInConfigMode = TRUE; DHCPInit(0); } } break; } // Advance to the next variable (if present) CurrentArg++; } // Save any changes to non-volatile memory SaveAppConfig(&AppConfig); // Return the same CONFIG.CGI file as a result. memcpypgm2ram((void*)argv[0], (ROM void*)CONFIG_UPDATE_PAGE, CONFIG_UPDATE_PAGE_LEN); break; #endif // #if defined(ENABLE_REMOTE_CONFIG) default: memcpypgm2ram((void*)argv[0], (ROM void*)COMMANDS_OK_PAGE, COMMANDS_OK_PAGE_LEN); break; } }
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(); } } }
/********************************************************************* * 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 }