-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55a0863
Showing
8 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${workspaceFolder}/**" | ||
], | ||
"defines": [], | ||
"cStandard": "c17", | ||
"cppStandard": "gnu++17", | ||
"intelliSenseMode": "linux-gcc-x64", | ||
"compilerPath": "/usr/bin/g++" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"files.associations": { | ||
"*.bc": "ini", | ||
"iostream": "cpp", | ||
"array": "cpp", | ||
"atomic": "cpp", | ||
"bit": "cpp", | ||
"*.tcc": "cpp", | ||
"cctype": "cpp", | ||
"chrono": "cpp", | ||
"clocale": "cpp", | ||
"cmath": "cpp", | ||
"codecvt": "cpp", | ||
"compare": "cpp", | ||
"concepts": "cpp", | ||
"cstdarg": "cpp", | ||
"cstddef": "cpp", | ||
"cstdint": "cpp", | ||
"cstdio": "cpp", | ||
"cstdlib": "cpp", | ||
"ctime": "cpp", | ||
"cwchar": "cpp", | ||
"cwctype": "cpp", | ||
"deque": "cpp", | ||
"string": "cpp", | ||
"unordered_map": "cpp", | ||
"vector": "cpp", | ||
"exception": "cpp", | ||
"algorithm": "cpp", | ||
"functional": "cpp", | ||
"iterator": "cpp", | ||
"memory": "cpp", | ||
"memory_resource": "cpp", | ||
"numeric": "cpp", | ||
"random": "cpp", | ||
"ratio": "cpp", | ||
"string_view": "cpp", | ||
"system_error": "cpp", | ||
"tuple": "cpp", | ||
"type_traits": "cpp", | ||
"utility": "cpp", | ||
"fstream": "cpp", | ||
"initializer_list": "cpp", | ||
"iomanip": "cpp", | ||
"iosfwd": "cpp", | ||
"istream": "cpp", | ||
"limits": "cpp", | ||
"new": "cpp", | ||
"numbers": "cpp", | ||
"ostream": "cpp", | ||
"sstream": "cpp", | ||
"stdexcept": "cpp", | ||
"streambuf": "cpp", | ||
"typeinfo": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Time,Name,Email,UMID,Card ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
g++ main.cpp -std=c++17 -o card_reader_linux_x86 --static | ||
aarch64-linux-gnu-g++ main.cpp -std=c++17 -o card_reader_arm --static | ||
x86_64-w64-mingw32-g++ main.cpp -std=c++17 -o card_reader_windows_x64 --static |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <ctime> | ||
#include <iomanip> | ||
#include <sstream> | ||
#include <filesystem> | ||
|
||
using namespace std; | ||
namespace fs = std::filesystem; | ||
|
||
struct Student { | ||
string name; | ||
string email; | ||
string umid; | ||
string cardID; | ||
}; | ||
|
||
string getCurrentTime() { | ||
std::time_t now = std::time(nullptr); | ||
std::tm* localTime = std::localtime(&now); | ||
|
||
std::ostringstream oss; | ||
oss << std::put_time(localTime, "%Y-%m-%d %H:%M:%S"); | ||
return oss.str(); | ||
} | ||
|
||
Student parseStudent(string input) { | ||
// Example input: %B6008475938410415^HAMMERBERG/J^2806120JACKMH?;6008475938410415=2806120=816877446? | ||
// Name: J HAMMERBERG | ||
// Email: [email protected] | ||
// UMID: 59384104 | ||
// Card ID: 6008475938410415 | ||
Student student; | ||
size_t start, end; | ||
// Get the card ID | ||
start = input.find("%") + 2; | ||
end = input.find("^"); | ||
student.cardID = input.substr(start, end - start); | ||
// Get the last name | ||
start = input.find("^") + 1; | ||
end = input.find("/"); | ||
string lastName = input.substr(start, end - start); | ||
// Get the first name | ||
start = end + 1; | ||
end = input.find("^", start); | ||
// Concatenate the first and last name to get the full name | ||
student.name = input.substr(start, end - start) + " " + lastName; | ||
// Get the UMID | ||
start = input.find("^") - 10; | ||
end = input.find("^") - 2; | ||
student.umid = input.substr(start, end - start); | ||
// Get the email | ||
start = input.find("^", input.find("/")) + 8; // Find the next ^ after the the / character | ||
end = input.find("?;"); | ||
student.email = input.substr(start, end - start) + "@umich.edu"; | ||
return student; | ||
} | ||
|
||
int main() { | ||
string header = "Time,Name,Email,UMID,Card ID"; | ||
string filename = (fs::current_path() / "Festifall Cardreader.csv").string(); | ||
ifstream infile(filename); | ||
bool headerMatches = false; | ||
|
||
if (infile.is_open()) { | ||
string firstLine; | ||
getline(infile, firstLine); | ||
if (firstLine == header) { | ||
headerMatches = true; | ||
} | ||
infile.close(); | ||
} | ||
|
||
ofstream file; | ||
if (headerMatches) { | ||
file.open(filename, ios::app); | ||
cout << "Existing file found" << endl; | ||
file.close(); | ||
} else { | ||
file.open(filename); | ||
file << header << endl; | ||
cout << "New file created" << endl; | ||
file.close(); | ||
} | ||
|
||
while (true) { | ||
string input; | ||
cout << "Type 'exit' to stop" << endl; | ||
cout << "Enter student info: "; | ||
cin >> input; | ||
if (input == "exit" || input == "Exit" || input == "EXIT") { | ||
break; | ||
} | ||
Student student = parseStudent(input); | ||
string time = getCurrentTime(); | ||
file.open(filename, ios::app); | ||
if (!file.is_open()) { | ||
cout << "Error opening file" << endl; | ||
return 1; | ||
} | ||
file << time << "," << student.name << "," << student.email << "," << student.umid << "," << student.cardID << endl; | ||
cout << time << ", " << student.name << ", " << student.email << ", " << student.umid << ", " << student.cardID << endl; | ||
file.close(); | ||
} | ||
return 0; | ||
} |