/**************************************************************************************************
  Test.
**************************************************************************************************/
void TestBitManipulation(void) {
     char *BufNum;
     
     //memset(packet,0,sizeof(packet)); // Zero out the packet
     // Set the first byte's bits to 00,011,011 for li = 0, vn = 3, and mode = 3.
     // The rest will be left set to zero.
     //*((char *)&packet+0) = 0x1b; // 1B in hex is 27 in base 10 or 0001 1011 in base 2.
     /*
     BufNum = GetBuffer();
     sprintf(BufNum,"%02X %02X %02X %02X %02X %02X %02X %02X\r\n",packet[0],packet[1],
     packet[2],packet[3],packet[4],packet[5],packet[6],packet[7]);
     USB_PutQueue(BufNum);

     BufNum = GetBuffer();
     sprintf(BufNum,"%02X %02X %02X %02X %02X %02X %02X %02X\r\n",packet[8],packet[9],
     packet[10],packet[11],packet[12],packet[13],packet[14],packet[15]);
     USB_PutQueue(BufNum);

     BufNum = GetBuffer();
     sprintf(BufNum,"%02X %02X %02X %02X %02X %02X %02X %02X\r\n",packet[16],packet[17],
     packet[18],packet[19],packet[20],packet[21],packet[22],packet[23]);
     USB_PutQueue(BufNum);

     BufNum = GetBuffer();
     sprintf(BufNum,"%02X %02X %02X %02X %02X %02X %02X %02X\r\n",packet[24],packet[25],
     packet[26],packet[27],packet[28],packet[29],packet[30],packet[31]);
     USB_PutQueue(BufNum);
     */
}

void TestBitManipulation(void);

/**************************************************************************************************
  WiFiESP - Transparent Mode Test.
**************************************************************************************************/
void TryTransMode(void) {
     char *BufNum;

     //USB_PutQueue("Sending AT\r\n");
     
     memset(U3RcvBuf,0,25);

     Transparent = 1;        // Set USART3 to transparent mode
     U3RcvBufPtr = 0;        // Counter will increment for each character received

     //XmtByteCntr = 4;        // Have to know the number of characters to transmit
     USART3_PutQueueBinary("AT\r\n",4);
     
     // WiFiES comes back with \r\nOK\r\n - 6 characters.
     while (U3RcvBufPtr<6);  // Should also use a timer to get out if OK message never comes

     //
     BufNum = GetBuffer();
     sprintf(BufNum,"%d\r\n",U3RcvBufPtr);
     USB_PutQueue(BufNum);
     //
     
     //
     // Diagnostic to see what was received
     BufNum = GetBuffer();
     strcpy(BufNum,U3RcvBuf);
     //strcat(BufNum,"\r\n");
     USB_PutQueue(BufNum);
     //

     Transparent = 0;        // Set USART3 to normal ASCII mode
}

void TryTransMode(void);

/**************************************************************************************************
  WiFiESP - Construct a WiFiESP command to open a UDP port for NTP server. Just a test.
**************************************************************************************************/
void MakeUDPforNTP(void) {
     char *BufNum;

     BufNum = GetBuffer();
     sprintf(BufNum,"AT+CIPSTART=\"UDP\",\"");
     strcat(BufNum,NTP_ServerIP);
     strcat(BufNum,"\",123,6000,0\r\n");
     USB_PutQueue(BufNum);

}

void MakeUDPforNTP(void);

/**************************************************************************************************
  WiFiESP - Construct a WiFiESP command to open a UDP port for DNS server. Just a test.
**************************************************************************************************/
void MakeUDPforDNS(void) {
     char *BufNum;

     BufNum = GetBuffer();
     sprintf(BufNum,"AT+CIPSTART=\"UDP\",\"");
     strcat(BufNum,DNS_SErverIP);
     strcat(BufNum,"\",53,6000,0\r\n");
     USB_PutQueue(BufNum);

}

void MakeUDPforDNS(void);



char Test_IP_Addr[IP_ADDR_SIZE] = {"192.168.0.15"};
/**************************************************************************************************
  Test functions.
**************************************************************************************************/
void WiFiTest(void) {
     char *BufNum;
     
     if (Test_IP_Addr[0] == NULL) {
         USB_PutQueue("The test IP address is empty\r\n");
     } else {
         USB_PutQueue("The test IP address is not empty\r\n");
     }
     
     strcpy(Test_IP_Addr,Local_IP_Addr);
     if (Test_IP_Addr == NULL) {
         USB_PutQueue("The test IP address is still empty\r\n");
     } else {
         USB_PutQueue("The test IP address is no longer empty\r\n");
     }

     BufNum = GetBuffer();
     strcpy(BufNum,Test_IP_Addr);
     strcat(BufNum,"\r\n");
     USB_PutQueue(BufNum);
}


void WiFiTest(void);


extern char Test_IP_Addr[18];
               case 'y':
                    if (CheckForValidIP(Test_IP_Addr) == 0) {
                        USB_PutQueue("The IP is valid\r\n");
                    } else {
                        USB_PutQueue("The IP is not valid\r\n");
                    }
                    break;