/* Fingerprint Parser code Ed Navarro Ben Peuker Michael Quan Supervised by Christopher Clark */ #include #include #include #include #include using namespace std; #define NUM_ROUTERS 6 #define NUM_SAMPLES 100 #define NUM_ROWS 200 #define NUM_COLS 200 struct rssi_tuple { char rssi[NUM_ROUTERS][NUM_SAMPLES]; }; struct rssi_fp { double rssi_avg[NUM_ROUTERS]; double rssi_stdev[NUM_ROUTERS]; }; int main(int argc, char* argv[]) { string line; // next line to be read static rssi_tuple rp[NUM_ROWS][NUM_COLS]; // reference point (x,y,rssituple) unsigned char rssi_counter[6]; static rssi_fp fingerprint[NUM_ROWS][NUM_COLS]; double total = 0.0; double dev = 0.0; double dev_sq_total = 0.0; int new_x = 0; int curr_x = 0; int new_y = 0; int curr_y = 0; string curr_name; string token; string infilename; // input filename string outfilename; // output filename ifstream fin; ofstream fout_avg; ofstream fout_std; if (argc != 2) { cout << "No input file specified." << endl; system("PAUSE"); return 1; } // get file name from command line arg infilename = argv[1]; cout << infilename << endl; fin.open(infilename.c_str()); fout_avg.open("average.csv"); fout_std.open("stdev.csv"); // throw away first line getline(fin, line); while (fin) { // get x coord getline(fin, token, ','); new_x = atoi(token.c_str()); // get y coord getline(fin, token, ','); new_y = atoi(token.c_str()); // coordinate changed, reset counters if (new_x != curr_x || new_y != curr_y) { curr_x = new_x; curr_y = new_y; for (int i = 0; i < 6; i++) rssi_counter[i] = 0; } // get router name getline(fin, token, ','); curr_name = token; // get rssi getline(fin, token, ','); if (curr_name.compare("Router 1") == 0) { if (rssi_counter[0] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[0][rssi_counter[0]] = (atoi(token.c_str())); rssi_counter[0]++; } } else if (curr_name.compare("Router 2") == 0) { if (rssi_counter[1] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[1][rssi_counter[1]] = (atoi(token.c_str())); rssi_counter[1]++; } } else if (curr_name.compare("Router 3") == 0) { if (rssi_counter[2] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[2][rssi_counter[2]] = (atoi(token.c_str())); rssi_counter[2]++; } } else if (curr_name.compare("Router 4") == 0) { if (rssi_counter[3] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[3][rssi_counter[3]] = (atoi(token.c_str())); rssi_counter[3]++; } } else if (curr_name.compare("Router 5") == 0) { if (rssi_counter[4] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[4][rssi_counter[4]] = (atoi(token.c_str())); rssi_counter[4]++; } } else if (curr_name.compare("Router 6") == 0) { if (rssi_counter[5] < NUM_SAMPLES) { rp[curr_x][curr_y].rssi[5][rssi_counter[5]] = (atoi(token.c_str())); rssi_counter[5]++; } } // throw away the rest of the line getline(fin, token); } /* for (int row = 5; row < NUM_ROWS; row+=10) { for (int col = 5; col < NUM_COLS; col+=10) { cout << row << "," << col; for (int router = 0; router < NUM_ROUTERS; router++) { cout << "," << (double)rp[row][col].rssi[router][0]; } cout << endl; } } */ for (int row = 0; row < NUM_ROWS; row++) { for (int col = 0; col < NUM_COLS; col++) { for (int router = 0; router < NUM_ROUTERS; router++) { for (int sample = 0; sample < NUM_SAMPLES; sample++) { total += rp[row][col].rssi[router][sample]; } fingerprint[row][col].rssi_avg[router] = total / NUM_SAMPLES; for (int sample = 0; sample < NUM_SAMPLES; sample++) { dev = rp[row][col].rssi[router][sample] - fingerprint[row][col].rssi_avg[router]; dev_sq_total += dev * dev; } fingerprint[row][col].rssi_stdev[router] = sqrt(dev_sq_total / (NUM_SAMPLES - 1)); total = 0.0; dev = 0.0; dev_sq_total = 0.0; } } } for (int row = 0; row < NUM_ROWS; row++) { for (int col = 0; col < NUM_COLS; col++) { fout_avg << row << "," << col; fout_std << row << "," << col; for (int router = 0; router < NUM_ROUTERS; router++) { fout_avg << "," << fingerprint[row][col].rssi_avg[router]; fout_std << "," << fingerprint[row][col].rssi_stdev[router]; } fout_avg << endl; fout_std << endl; } } fout_avg.close(); fout_std.close(); system("PAUSE"); return 0; }