write log header only once

This commit is contained in:
interfisch 2021-03-31 20:31:25 +02:00
parent 025d2ddbc2
commit aaabdb3a80
1 changed files with 15 additions and 2 deletions

View File

@ -21,6 +21,10 @@ unsigned long last_log_send=0;
#define SENDPERIOD 20 //ms. delay for sending speed and steer data to motor controller via serial
#define LOGMININTERVAL 20 //minimum interval (ms) to send logs
#define LOGMAXINTERVAL 10000 //maximum time (ms) after which data is send
#define WRITE_HEADER_TIME 1000
bool log_header_written = false;
bool controllers_connected=false;
@ -270,8 +274,10 @@ void loop() {
controllers_connected=false;
}else if(!controllers_connected) { //not timeouted but was before
controllers_connected=true;
writeLogHeader(Serial1); //connection recovered, write log header
}
if (newData2) {
@ -343,8 +349,15 @@ void loop() {
}
// ######## LOG ########
if (!log_header_written && loopmillis>=WRITE_HEADER_TIME){
writeLogHeader(Serial1); //connection recovered, write log header
log_header_written=true;
}
if (log_update && loopmillis>last_log_send+LOGMININTERVAL) {
if ((log_header_written && log_update && loopmillis>last_log_send+LOGMININTERVAL) || loopmillis>last_log_send+LOGMAXINTERVAL) {
last_log_send=loopmillis;
log_update=false;
writeLog(Serial1,loopmillis, motorparamsFront,motorparamsRear, FeedbackFront, FeedbackRear, filtered_currentAll, throttle_pos, brake_pos);