Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datalogging format #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
302 changes: 180 additions & 122 deletions V2/src/data_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define OL_BAUD 115200

Timer datatimer;
void printData(char* buffer);

//Object declarations
//Serial pc(USBTX, USBRX); // todo - remove this since code will freeze if usb isn't connected
Expand All @@ -22,161 +23,218 @@ char buffer [100];
void data_logging_thread() {
// Dalin's cpp magic made this a lot nicer but oh well.
while (true) {
// State
if(get_fc_state() == FC_STANDBY){sprintf(buffer,"\n\nState: FC_STANDBY\n");}
else if (get_fc_state() == FC_PRESSURIZE){sprintf(buffer,"\n\nState: FC_PRESSURIZE\n");}
else if (get_fc_state() == FC_START_UP_PURGE){sprintf(buffer,"\n\nState: FC_START_UP_PURGE\n");}
else if (get_fc_state() == FC_CHARGE){sprintf(buffer,"\n\nState: FC_CHARGE\n");}
else if (get_fc_state() == CAP_CHARGE){sprintf(buffer,"\n\nState: CAP_CHARGE\n");}
else if (get_fc_state() == FC_RUN){sprintf(buffer,"\n\nState: FC_RUN\n");}
else if (get_fc_state() == FC_PURGE){sprintf(buffer,"\n\nState: FC_PURGE\n");}
else if (get_fc_state() == FC_SHUTDOWN){sprintf(buffer,"\n\nState: FC_SHUTDOWN\n");}
else if (get_fc_state() == FC_ALARM){sprintf(buffer,"\n\nState: FC_ALARM\n");}
else if (get_fc_state() == FC_TEST){sprintf(buffer,"\n\nState: FC_TEST\n");}
else {sprintf(buffer,"\n\nState: UNKNOWN STATE?!\n");}
printData(buffer);

sprintf(buffer, "Purge Count: %-5u|", get_purge_count());
printData(buffer);

sprintf(buffer, " Pressure: %-10.1f|", get_analog_values().press1);
printData(buffer);

if (check_all_errors())
{
sprintf(buffer, " Error: %-3s\n", "YES");
}
else
{
sprintf(buffer, " Error: %-3s\n", "NO");
}
printData(buffer);

sprintf(buffer, "Purge Timer: %-2.2f |", get_purge_timer());
printData(buffer);

sprintf(buffer, "\n\n\n{State: %lu} ", get_fc_state());
//ThisThread::sleep_for(0.1);
// pc.puts(buffer);
ThisThread::sleep_for(0.1);
ftdi.puts(buffer);
ThisThread::sleep_for(0.1);
bluetooth.puts(buffer);
ThisThread::sleep_for(0.1);
open_log.puts(buffer);
ThisThread::sleep_for(0.1);

sprintf(buffer, "{Purge Count: %ld} ", get_purge_count());
//ThisThread::sleep_for(0.1);
// pc.puts(buffer);
ThisThread::sleep_for(0.1);
ftdi.puts(buffer);
ThisThread::sleep_for(0.1);
bluetooth.puts(buffer);
ThisThread::sleep_for(0.1);
open_log.puts(buffer);
ThisThread::sleep_for(0.1);

sprintf(buffer, "{Purge Timer: %f} ", get_purge_timer());
//ThisThread::sleep_for(0.1);
// pc.puts(buffer);
ThisThread::sleep_for(0.1);
ftdi.puts(buffer);
ThisThread::sleep_for(0.1);
bluetooth.puts(buffer);
ThisThread::sleep_for(0.1);
open_log.puts(buffer);
ThisThread::sleep_for(0.1);

if (check_all_errors()){
sprintf(buffer, "{Error: %3s}\n", "YES");
bluetooth.puts(buffer);
sprintf(buffer, " Temperature: %-7.1f|", get_analog_values().fctemp1);
printData(buffer);

sprintf(buffer, " Error: ");
printData(buffer);

if (check_all_errors())
{
if (get_error_state().capvolt_high){
sprintf(buffer, "{Error: Cap Voltage High}");
bluetooth.puts(buffer);
sprintf(buffer, "Cap Voltage High, ");
printData(buffer);
}
if (get_error_state().capvolt_low){
sprintf(buffer, "{Error: Cap Voltage Low}");
sprintf(buffer, "Cap Voltage Low, ");
bluetooth.puts(buffer);
}
if (get_error_state().fccurr_high){
sprintf(buffer, "{Error: FC Current High}");
bluetooth.puts(buffer);
sprintf(buffer, "FC Current High, ");
printData(buffer);
}
if (get_error_state().capcurr_high){
sprintf(buffer, "{Error: Cap Current High}");
bluetooth.puts(buffer);
sprintf(buffer, "Cap Current High, ");
printData(buffer);
}
if (get_error_state().press_high){
sprintf(buffer, "{Error: Over Pressure}");
bluetooth.puts(buffer);
sprintf(buffer, "Over Pressure, ");
printData(buffer);
}
if (get_error_state().press_low){
sprintf(buffer, "{Error: Under Pressure}");
bluetooth.puts(buffer);
sprintf(buffer, "Under Pressure, ");
printData(buffer);
}
if (get_error_state().fcvolt_high){
sprintf(buffer, "{Error: FC Voltage High}");
bluetooth.puts(buffer);
sprintf(buffer, "FC Voltage High, ");
printData(buffer);
}
if (get_error_state().fcvolt_low){
sprintf(buffer, "{Error: FC Voltage Low}");
bluetooth.puts(buffer);
sprintf(buffer, "FC Voltage Low, ");
printData(buffer);
}
if (get_error_state().relays_shorted){
sprintf(buffer, "{Error: Relays are Shorted}");
bluetooth.puts(buffer);
sprintf(buffer, "Relays are Shorted, ");
printData(buffer);
}
if (get_error_state().over_temp){
sprintf(buffer, "{Error: Over Temperature}");
bluetooth.puts(buffer);
sprintf(buffer, "Over Temperature, ");
printData(buffer);
}
if (get_error_state().stop){
sprintf(buffer, "{Error: Stop}");
bluetooth.puts(buffer);
sprintf(buffer, "Stop, ");
printData(buffer);
}
if (get_error_state().h2_ok){
sprintf(buffer, "{Error: h2 ok}n");
bluetooth.puts(buffer);
sprintf(buffer, "h2 ok, ");
printData(buffer);
}
if (get_error_state().estop1){
sprintf(buffer, "{Error: estop1}");
bluetooth.puts(buffer);
sprintf(buffer, "estop1, ");
printData(buffer);
}
if (get_error_state().estop2){
sprintf(buffer, "{Error: estop2}");
bluetooth.puts(buffer);
sprintf(buffer, "estop2, ");
printData(buffer);
}
}
else {
sprintf(buffer, "{Error?: %3s}\n", "NO");
bluetooth.puts(buffer);
}

sprintf(buffer, "\n{FC Voltage: %2.1f} ", get_analog_values().fcvolt);
bluetooth.puts(buffer);

sprintf(buffer, "{FC Current: %2.1f}\n", get_analog_values().fccurr);
bluetooth.puts(buffer);

sprintf(buffer, "{Cap Voltage: %2.1f} ", get_analog_values().capvolt);
bluetooth.puts(buffer);

sprintf(buffer, "{Cap Current: %2.1f}\n", get_analog_values().capcurr);
bluetooth.puts(buffer);

sprintf(buffer, "{Motor Voltage: %2.1f} ", get_analog_values().motorvolt);
bluetooth.puts(buffer);

sprintf(buffer, "{Motor Current: %2.1f}\n", get_analog_values().motorcurr);
bluetooth.puts(buffer);

sprintf(buffer, "{Temperature: %2.1f} ", get_analog_values().fctemp1);
bluetooth.puts(buffer);

sprintf(buffer, "{Pressure: %2.1f}\n", get_analog_values().press1);
bluetooth.puts(buffer);

sprintf(buffer, "{START_R: %d}", start_r.read());
bluetooth.puts(buffer);

sprintf(buffer, "{MOTOR_R: %d}", motor_r.read());
bluetooth.puts(buffer);

sprintf(buffer, "{CHARGE_R: %d}", charge_r.read());
bluetooth.puts(buffer);

sprintf(buffer, "{CAP_R: %d}", cap_r.read());
bluetooth.puts(buffer);

sprintf(buffer, "{FCC_R: %d}\n", fcc_r.read());
bluetooth.puts(buffer);

sprintf(buffer, "{SUPPLY_V: %d}", supply_v.read());
bluetooth.puts(buffer);

sprintf(buffer, "{PURGE_V: %d}\n", purge_v.read());
bluetooth.puts(buffer);

sprintf(buffer, "{START: %d}", start.read());
bluetooth.puts(buffer);

sprintf(buffer, "{BUTTON: %d}", button.read());
bluetooth.puts(buffer);

sprintf(buffer, "{BLUE BUTTON: %d}\n\n", blue_button.read());
bluetooth.puts(buffer);


sprintf(buffer, "\n\nFC Voltage: %-5.1f|", get_analog_values().fcvolt);
printData(buffer);

sprintf(buffer, " Cap Voltage: %-8.1f|", get_analog_values().capvolt);
printData(buffer);

sprintf(buffer, " Motor Voltage: %-3.1f\n", get_analog_values().motorvolt);
printData(buffer);

sprintf(buffer, "FC Current: %-5.1f|", get_analog_values().fccurr);
printData(buffer);

sprintf(buffer, " Cap Current: %-8.1f|", get_analog_values().capcurr);
printData(buffer);

sprintf(buffer, " Motor Current: %-5.1f\n", get_analog_values().motorcurr);
printData(buffer);

sprintf(buffer, "\n Relays Open (OFF): ");
printData(buffer);
if (!start_r.read()){
sprintf(buffer, "START_R, ");
printData(buffer);
}
if (!motor_r.read()){
sprintf(buffer, "MOTOR_R, ");
printData(buffer);
}
if (!charge_r.read()){
sprintf(buffer, "CHARGE_R, ");
printData(buffer);
}
if (!cap_r.read()){
sprintf(buffer, "CAP_R, ");
printData(buffer);
}
if (!fcc_r.read()){
sprintf(buffer, "FCc_R, ");
printData(buffer);
}

sprintf(buffer, "\n Relays Closed (ON): ");
printData(buffer);
if (start_r.read()){
sprintf(buffer, "START_R, ");
printData(buffer);
}
if (motor_r.read()){
sprintf(buffer, "MOTOR_R, ");
printData(buffer);
}
if (charge_r.read()){
sprintf(buffer, "CHARGE_R, ");
printData(buffer);
}
if (cap_r.read()){
sprintf(buffer, "CAP_R, ");
printData(buffer);
}
if (fcc_r.read()){
sprintf(buffer, "FCC_R, ");
printData(buffer);
}

sprintf(buffer, "\n Valves Open (ON): ");
printData(buffer);
if (supply_v.read()){
sprintf(buffer, "SUPPLY_V, ");
printData(buffer);
}
if (purge_v.read()){
sprintf(buffer, "SUPPLY_V, ");
printData(buffer);
}

sprintf(buffer, "\nValves Closed (OFF): ");
printData(buffer);
if (!supply_v.read()){
sprintf(buffer, "SUPPLY_V, ");
printData(buffer);
}
if (!purge_v.read()){
sprintf(buffer, "PURGE_V, ");
printData(buffer);
}

sprintf(buffer, "\n____________________________________________________________________________");
printData(buffer);

ThisThread::sleep_for(2000);
}
}

void printData(char* buffer)
{
ThisThread::sleep_for(0.1);
ftdi.puts(buffer);
ThisThread::sleep_for(0.1);
bluetooth.puts(buffer);
ThisThread::sleep_for(0.1);
open_log.puts(buffer);
ThisThread::sleep_for(0.1);
}
/* Datalogging output formatting template
State: RUN
Purge Count: 0 | Error: YES | Pressure: 1.5
Purge Timer: 18.01 | Error: Stop | Temperature: 36.0

FC Voltage: 43.0 | Cap Voltage: 29.6 | Motor Voltage: 23.5
FC Current: -5.6 | Cap Current: -57.6 | Motor Current: -1.7

Relays Open (OFF): FCC_R
Relays Closed (ON): START_R, MOTOR_R, CHARGE_R, CAP_R
Valves Open (ON):
Valves Closed (OFF): SUPPLY_V, PURGE_V
*/
1 change: 1 addition & 0 deletions V2/src/data_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
#define DATA_LOGGING_H

void data_logging_thread();
void dataPrint();

#endif