Commit d1f27c8c authored by Erik Strand's avatar Erik Strand

Log data to a file

parent 997eedda
// Use of libserialport based on https://gist.github.com/Nixes/78e401234e66aa131547d7b78135271c
#include <chrono>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <libserialport.h>
......@@ -30,6 +34,8 @@ int main() {
constexpr uint32_t byte_buffer_size = 512;
char byte_buffer[byte_buffer_size];
std::ofstream output_file = std::ofstream("data.csv");
struct sp_port *port;
std::cout << "Opening port " << desired_port << '\n';
sp_return error = sp_get_port_by_name(desired_port, &port);
......@@ -48,7 +54,16 @@ int main() {
//if (byte_buffer[i] == '1') {
// button_pressed = true;
//}
std::cout << byte_buffer[i];
output_file << byte_buffer[i];
//std::cout << byte_buffer[i];
if (byte_buffer[i] == '\n') {
output_file << std::flush;
auto const chrono_time = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(chrono_time);
std::tm local_time = *std::localtime(&time);
output_file << std::put_time(&local_time, "%Y/%m/%d %H:%M:%S") << ", ";
//std::cout << std::put_time(&local_time, "%Y/%m/%d %H:%M:%S") << ", ";
}
}
//std::cout << '\n';
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment