Compare commits

..

No commits in common. "ff8c11eb1b4e3e50d69ad4d9dc0be895af3d835c" and "ec9e9f09ee2ae71c1f753c7526b02cf1f0cf6d96" have entirely different histories.

4 changed files with 1 additions and 276 deletions

3
.gitignore vendored
View File

@ -1,3 +0,0 @@
logdata_visualization/logs/*
*.sync-conflict*
*.FCStd1

View File

@ -10,16 +10,9 @@
boolean datalogging=true; boolean datalogging=true;
String datalogging_filename="UNKNOWN.txt"; String datalogging_filename="UNKNOWN.txt";
bool serialCommandEcho_Enabled=true;
bool initLogging(); bool initLogging();
void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm& escRear); void loggingLoop(unsigned long loopmillis,ESCSerialComm& escFront, ESCSerialComm& escRear);
void writeLogComment(unsigned long time, String msg); void writeLogComment(unsigned long time, String msg);
void printFileListing();
void printDirectory(File dir, int numTabs,String parent);
void printFile(String filename);
void removeFile(String filename);
void serialCommandLoop();
bool initLogging() { bool initLogging() {
@ -40,7 +33,7 @@ bool initLogging() {
sprintf(buffer, "%04d", filenumber); sprintf(buffer, "%04d", filenumber);
datalogging_filename="LOG_"+String(buffer)+".TXT"; datalogging_filename="LOG_"+String(buffer)+".TXT";
while(SD.exists(datalogging_filename.c_str()) && filenumber<10000) { while(SD.exists(datalogging_filename.c_str()) && filenumber<10000) {
//Serial.print(datalogging_filename); Serial.println(" exists"); Serial.print(datalogging_filename); Serial.println(" exists");
filenumber++; filenumber++;
sprintf(buffer, "%04d", filenumber); sprintf(buffer, "%04d", filenumber);
datalogging_filename="LOG_"+String(buffer)+".TXT"; datalogging_filename="LOG_"+String(buffer)+".TXT";
@ -234,152 +227,4 @@ void resetTrip() {
} }
} }
void serialCommandLoop() {
#define MAX_MESSAGE_LENGTH 80
uint8_t timeoutcounter=MAX_MESSAGE_LENGTH;
while (Serial.available() > 0 && timeoutcounter>0)
{
timeoutcounter--;
static char message[MAX_MESSAGE_LENGTH];
static unsigned int message_pos = 0;
char inByte = Serial.read();
if (inByte == '\r') {
break; //ignore CR
}
if ( inByte != '\n' && (message_pos < MAX_MESSAGE_LENGTH - 1) )
{
message[message_pos] = inByte;
message_pos++;
}
else
{
message[message_pos] = '\0';
String smessage=String(message);
if(smessage.equals("echo off")) {
serialCommandEcho_Enabled=false;
}else if(smessage.equals("echo on")) {
serialCommandEcho_Enabled=true;
}
if (serialCommandEcho_Enabled) { //Echo Command
Serial.print("$"); Serial.println(message);
}
//Handle Commands
if(smessage.equals("test")) {
Serial.println("OK");
}else if(smessage.equals("ls")) {
printFileListing();
}else if(smessage.startsWith("cat")) {
printFile(smessage.substring(4));
}else if(smessage.startsWith("rm")) {
removeFile(smessage.substring(3));
}else if(smessage.equals("log off")) {
datalogging=false;
Serial.print("Log disabled: "); Serial.println(datalogging_filename);
}else if(smessage.equals("log on")) {
datalogging=true;
Serial.print("Log enabled: "); Serial.println(datalogging_filename);
}
message_pos = 0;
}
}
}
void printFileListing() {
File root;
root = SD.open("/");
printDirectory(root, 0,"");
}
void printDirectory(File dir, int numTabs,String parent) {
bool printSize=false;
bool printFullDirectoryNames=true;
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
if (!printFullDirectoryNames) {
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
}
if (!entry.isDirectory() || !printFullDirectoryNames) {
Serial.print(parent+entry.name());
}
if (entry.isDirectory()) {
if (!printFullDirectoryNames) {
Serial.println("/");
}
printDirectory(entry, numTabs + 1,parent+entry.name()+"/");
} else {
if (printSize) {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.print(entry.size(), DEC);
}
Serial.println();
}
entry.close();
}
}
void printFile(String filename) {
File dataFile = SD.open(filename.c_str(), FILE_READ);
// if the file is available, write to it:
if (dataFile) {
while (dataFile.available()) {
Serial.write(dataFile.read());
}
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
Serial.print("error opening "); Serial.println(filename);
}
}
void removeFile(String filename) {
SD.remove(filename.c_str());
if (SD.exists(filename.c_str())) {
Serial.println("File still exists");
} else {
Serial.println("OK");
}
}
#endif #endif

View File

@ -163,8 +163,6 @@ void setup()
led_simpeProgress(15,true); led_simpeProgress(15,true);
led_simpleProgressWait(); //wait longer if any errors were displayed with led_simpeProgress() led_simpleProgressWait(); //wait longer if any errors were displayed with led_simpeProgress()
Serial.println("Ready");
} }
@ -362,10 +360,6 @@ void loop() {
} }
serialCommandLoop();
looptime_duration=max(looptime_duration,millis()-loopmillis); looptime_duration=max(looptime_duration,millis()-loopmillis);
} }

View File

@ -1,111 +0,0 @@
import serial
import os
serialport = serial.Serial(port='/dev/ttyACM0', baudrate=115200, timeout=0.1)
def establish_connection():
serialport.write("\n".encode())
serialport.write("echo off\n".encode())
while len(serialport.readline())>0:
continue
serialport.write("test\n".encode())
response = serialport.readline()
hrresponse=response.rstrip().decode('ascii')
if hrresponse != "OK":
print("Unexpected test response:"+str(response))
exit()
def get_filenames():
filenames=[]
serialport.write("ls\n".encode())
while True:
response = serialport.readline()
hrresponse=response.rstrip().decode('ascii')
if(len(response))>0:
#print(hrresponse)
filenames.append(hrresponse)
else:
break
return filenames
def copy_file(source,destination):
os.makedirs(os.path.dirname(writefilename), exist_ok=True)
with open(writefilename, 'wb') as writer:
serialport.write(("cat "+filename+"\n").encode())
while True:
response = serialport.readline()
hrresponse=response.rstrip().decode('ascii')
if(len(response))>0:
#print(hrresponse)
writer.write(response)
else:
break
def log_off():
serialport.write(("log off\n").encode())
response = serialport.readline()
hrresponse=response.rstrip().decode('ascii')
if (not hrresponse.startswith("Log disabled")):
print("Unexpected response:"+str(response))
exit()
def delete_file(filename):
serialport.write(("rm "+filename+"\n").encode())
response = serialport.readline()
hrresponse=response.rstrip().decode('ascii')
if hrresponse != "OK":
print("Unexpected response:"+str(response))
exit()
if serialport.isOpen():
establish_connection()
#Get File List
filenames=get_filenames()
#Copy all Files
for filename in filenames:
print("Reading file "+filename)
writefilename='sdcard/'+filename
copy_file(filename,writefilename)
#Delete all files
'''
log_off()
for filename in filenames:
delete_file(filename)
'''
serialport.write("echo on\n".encode())
serialport.close()