//IOFILES Test #include #include #include "func.h" #include using namespace std; bool stringCheck(string tempString, string dirString) //Checks that I am using the Correct Command/Also used for speed increase { //string dirString = "[23:43:08] [Client thread/INFO]: [CHAT] [@] "; int charCount = 0; for(int i = 0; i < dirString.size(); i++) { if(dirString[i] == tempString[i]) charCount++; } if(charCount == 33) return true; else return false; /*if(tempString == dirString) return true; else return false;*/ } int main() { ifstream readFile; //Open Log File to Read string bufString; //A Specific Line from the Log string cmdString; //To Be used, wikll contain the command to be sent to the mcu string dirString = "[Client thread/INFO]: [CHAT] [@] "; //A basis for filtering Command, so I do not receive a command multiple times. bool valCheck = false; //A variable to allow multiple commands from a single line bool pOcheck = false; //A variable used to determine if the port needs to be opened. int cmdC = 0; //Iterator int port; unsigned long baud; bool breakC = true; CSerial(); cout << "Please Enter Your Arduino's Port Number: "; cin >> port; cout << "Please Enter Your BAUD Rate: "; cin >> baud; if(Open(port, baud))//Checks for Arduino on Port { cout << "Connection Established!\n"; Close(); } else { cout << "Connection Failed."; breakC = false; } //ofstream erase("latest.log"); //Delete the contents of the log folder //erase.close(); while(breakC) { readFile.open("latest.log"); if(readFile.is_open())//Check that the file opened correctly { //cout << "File Opened\n"; for(int i = 0; i < 50; i++)//Start cycling through the lines of the file { //test(2); getline(readFile, bufString);//Pull single lines to read //cout << bufString.size() << '\n'; for(int i = 0; i < 33; i++) { bufString[i] = bufString[i+11]; } for(int i2 = 0; i2 < bufString.size(); i2++)//Cycles through String chars { if(bufString[i2] == '!' && valCheck == false && stringCheck(bufString, dirString))//Checks for ! indicator, checks for end of line/end of cmd string, checks that of the commands it is only reading the command once { valCheck = true; i2++; for(; bufString[i2] != '!'; i2++)//This Loop Writes the Command to another string for ease of use. { if(bufString[i2] == '\0')//Checks for end of line break; cmdString[cmdC] = bufString[i2]; //writes the command to a new string cmdC++; pOcheck = true; //cout << bufString[i2] << '\n'; } if(bufString[i2 + 1] != '\0')//Checks for end of line/more commands valCheck = false; //cout << '\n'; } } cmdC = 0; valCheck = false; } } readFile.close();//Safely Close File if(pOcheck == true) { ofstream erase("latest.log"); erase.close(); if(Open(port, baud)) { const char* cmd = cmdString.data(); SendData(cmd, strlen(cmd)); cout << "CMD Sent\n"; } else { cout << "Failed To Open Port \"4\"\n"; } Close(); pOcheck = false; } //cout << cmdString << '\n'; } } //Bankruptcy!!! /*int x = 5; int *p = &x; p = new(int); *p = 3; cout << x << ' ' << *p; del(p);*/