Skip to content

Commit

Permalink
New block transfer method
Browse files Browse the repository at this point in the history
  • Loading branch information
pipakin committed Nov 16, 2011
1 parent e851a26 commit 827b989
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 58 deletions.
1 change: 0 additions & 1 deletion Sprinter/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const bool Z_ENDSTOP_INVERT = false;

// Chuck size for fast sd transfer
#define SD_FAST_XFER_CHUNK_SIZE 1024
#define SD_FAST_XFER_CHUNK_BUFFER_SIZE 1025

// Comment out (using // at the start of the line) to disable Bluetooth support:
#define BLUETOOTH
Expand Down
156 changes: 99 additions & 57 deletions Sprinter/Sprinter.pde
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ unsigned long stepper_inactive_time = 0;
bool sdactive = false;
bool savetosd = false;
int16_t n;
char fastxferbuffer[SD_FAST_XFER_CHUNK_BUFFER_SIZE];
char fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE + 1];
int lastxferchar;
long xferbytes;

Expand Down Expand Up @@ -204,6 +204,102 @@ unsigned long stepper_inactive_time = 0;
SerialMgr.cur()->println("error writing to file");
}
}

void fast_xfer()
{
char *pstr;
boolean done = false;

//force heater pins low
if(HEATER_0_PIN > -1) WRITE(HEATER_0_PIN,LOW);
if(HEATER_1_PIN > -1) WRITE(HEATER_1_PIN,LOW);

lastxferchar = 1;
xferbytes = 0;

pstr = strstr(strchr_pointer+4, " ");

if(pstr == NULL)
{
SerialMgr.cur()->println("invalid command");
return;
}

*pstr = '\0';

//check mode (currently only RAW is supported
if(strcmp(strchr_pointer+4, "RAW") != 0)
{
SerialMgr.cur()->println("Invalid transfer codec");
return;
}else{
SerialMgr.cur()->print("Selected codec: ");
SerialMgr.cur()->println(strchr_pointer+4);
}

if (!file.open(&root, pstr+1, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
{
SerialMgr.cur()->print("open failed, File: ");
SerialMgr.cur()->print(pstr+1);
SerialMgr.cur()->print(".");
}else{
SerialMgr.cur()->print("Writing to file: ");
SerialMgr.cur()->println(pstr+1);
}

SerialMgr.cur()->println("ok");

//RAW transfer codec
//Host sends \0 then up to SD_FAST_XFER_CHUNK_SIZE then \0
//when host is done, it sends \0\0.
//if a non \0 character is recieved at the beginning, host has failed somehow, kill the transfer.

//read SD_FAST_XFER_CHUNK_SIZE bytes (or until \0 is recieved)
while(!done)
{
while(!SerialMgr.cur()->available())
{
}
if(SerialMgr.cur()->peek() != 0)
{
//host has failed, this isn't a RAW chunk, it's an actual command
file.sync();
file.close();
return;
}
//clear the initial 0
SerialMgr.cur()->read();
for(int i=0;i<SD_FAST_XFER_CHUNK_SIZE+1;i++)
{
while(!SerialMgr.cur()->available())
{
}
lastxferchar = SerialMgr.cur()->read();
//buffer the data...
fastxferbuffer[i] = lastxferchar;

xferbytes++;

if(lastxferchar == 0)
break;
}

if(fastxferbuffer[0] != 0)
{
fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE] = 0;
file.write(fastxferbuffer);
SerialMgr.cur()->println("ok");
}else{
SerialMgr.cur()->print("Wrote ");
SerialMgr.cur()->print(xferbytes);
SerialMgr.cur()->println(" bytes.");
done = true;
}
}

file.sync();
file.close();
}
#endif


Expand Down Expand Up @@ -768,64 +864,10 @@ inline void process_commands()
break;

case 30: //M30 - fast SD transfer
//force heater pins low
if(HEATER_0_PIN > -1) WRITE(HEATER_0_PIN,LOW);
if(HEATER_1_PIN > -1) WRITE(HEATER_1_PIN,LOW);

lastxferchar = 1;
xferbytes = 0;

if (!file.open(&root, strchr_pointer+4, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
{
SerialMgr.cur()->print("open failed, File: ");
SerialMgr.cur()->print(strchr_pointer + 4);
SerialMgr.cur()->print(".");
}else{
SerialMgr.cur()->print("Writing to file: ");
SerialMgr.cur()->println(strchr_pointer + 4);
}


SerialMgr.cur()->println("ok");
//read 512 bytes (or until \0 is recieved)
while(lastxferchar != 0)
{
for(int i=0;i<SD_FAST_XFER_CHUNK_SIZE;i++)
{
while(!SerialMgr.cur()->available())
{
}
lastxferchar = SerialMgr.cur()->read();
//buffer the data...
fastxferbuffer[i] = lastxferchar;

xferbytes++;

if(lastxferchar == 0)
break;
}

fastxferbuffer[SD_FAST_XFER_CHUNK_SIZE] = 0;

file.write(fastxferbuffer);

if(lastxferchar != 0)
{
SerialMgr.cur()->println("ok");
}else{
SerialMgr.cur()->print("Wrote ");
SerialMgr.cur()->print(xferbytes);
SerialMgr.cur()->println(" bytes.");
}

}

file.sync();
file.close();

fast_xfer();
break;
case 31: //M31 - high speed xfer capabilities
SerialMgr.cur()->print("RAW,");
SerialMgr.cur()->print("RAW:");
SerialMgr.cur()->println(SD_FAST_XFER_CHUNK_SIZE);
break;
#endif
Expand Down

0 comments on commit 827b989

Please sign in to comment.