Well, yes, but I don't know how to do that. The line is read from the SD into a String and by that time the damage seems to be done. I can immediately null the String but the next read is already corrupted. My playback code is included...I hope. Haven't done this before.
//********** Play Section below ********************
playSection:
// open the file. note that only one file can be open at a time,
myFile.close();
// Check to see if the file exists:
if (SD.exists(logPlayFile))
{
Serial.print("Found file, loading....");
Serial.println(logPlayFile);
Serial.print("Playing ");
Serial.println(logPlayFile);
}
else {
Serial.println("Can't find file.");
delay(500);
goto start;
}
myFile = SD.open(logPlayFile);
if (myFile)
{
// read from the file until there's nothing else in it:
while (myFile.available()) //check for bytes available from SD file
{
ReadSd = myFile.readStringUntil('\n');//stores data into 'ReadSd' until \n is reached
//Serial.print("This is ReadSD raw data..."); //debug use
//Serial.println(ReadSd); //debug use
int dataLength = 0; //variable for length of line read from uSD
dataLength = ReadSd.length(); //check length of data record
//part error trap loop but not complete
if(dataLength < 34)
{
if(dataLength == 33) //this is a full length record excluding the 'Len' paramenter
{
ReadSd.setCharAt(0, '9'); //replace leading char of ID with '9'
NewReadSd = ReadSd; // pass record to NewReadSd variable
//Serial.print("modified 33char line: "); // debug use
//Serial.println(NewReadSd); // debug use
}
else
{
if(dataLength == 32)
{
NewReadSd = '8' + ReadSd; //if record is not 33 char then add '8'
//Serial.print("modified 32char line: ");//debug use
//Serial.println(NewReadSd);//debug use
}
}
String lineToParse = NewReadSd; //passes uSD data to lineToParse String
can_frame values;//use 'values' to hold data because the function needs a var not a struct
if (parseLine(lineToParse.c_str(), values)) //calls 'parseLine' ROUTINE and converts Strings to strings
{
//printData(values); //calls printData ROUTINE if parseLine ROUTINE value is true.
// commented out because serial print not required, can be used for debugging
;
}
else {
//Serial.print(F("Parsing error for "));//debug use
//Serial.println(lineToParse);//debug use
}
if (resultButton == 1 || resultButton == 2)
{
myFile.close();
// Serial.print("Button pressed returning to Stop");
goto start;
}
mcp2515.sendMessage(&canMsg); // send data loaded in parsing routine to MCP2515
//Serial.println("CAN Msg sent...");
delay(readDelay);//throttles read rate
}
} //end of while available read SD
myFile.close();
Serial.println();
Serial.println("End of Data, file closed.");
} //end of if(myFile)
goto playSection;//go to 'playSection' to repeat play unless button is pressed
}//end of VOID loop()
// ROUTINES BELOW
//*************************************************************************
//routine below works with comma delimiter and can have leading zeros or not on single chr bytes
//this routine parses each line and loads the result directly into canMsg struct.
bool parseLine(const char* line, can_frame& data) //parseLine is a ROUTINE, * indicates var is a pointer
{
//Serial.print(F("\nParsing, ")); //debug use
//Serial.println(line); //debug use
char * tmpPtr = nullptr;
canMsg.can_id = strtoul(line, &tmpPtr, 16); //converts id section of line to unsigned long and stores it to canMsg.can_id
canMsg.can_dlc = 8; //forces Len to be 8 specifically for files from CanBusLogger which does not include this field
// canMsg.can_dlc = strtoul(tmpPtr + 1, &tmpPtr, 16); // +1 to skip the comma, stores 2nd field to data.len
for (byte i = 0; i < min(canMsg.can_dlc, sizeof(canMsg.data)); i++) //counts steps to read payload data
{
canMsg.data[i] = strtoul(tmpPtr + 1, &tmpPtr, 16); //stores 3rd to 10 field to data.payload
}
return true; // when this is done it returns true
} // end of parsLine routine
void printData(can_frame& data) //ROUTINE to print data held in t_data
{
Serial.print(F("ID = 0x")); Serial.println(canMsg.can_id, HEX);//debug use
Serial.print(F("Length = ")); Serial.println(canMsg.can_dlc, HEX);//debug use
Serial.print(F("Payload = "));
for (byte i = 0; i < canMsg.can_dlc; i++)
{
if (canMsg.data[i] < 0x10) Serial.write('0'); // adds leading zero to single chr byte
Serial.print(canMsg.data[i], HEX);//debug use
Serial.write(' ');//debug use
}
Serial.println();//debug use
} //end of print data routine
Bob you have saved me on this project before, so maybe again.
Tks