void main( void ) { PYGMYFILE pygmyFile; u8 i, ucStatus, ucBuffer[ 65 ], *ucSubString; sysInit(); print( COM3, "\rUpdating bootloader, cancel boot after completion" ); print( COM3, "\rOpening Resource..." ); if( !fileOpenResource( &pygmyFile, (u8*)PYGMY_boothex ) ){ print( COM3, "\rFile Failed to Open" ); } else{ print( COM3, "\rErasing..." ); for( i = 0; i < 8; i++ ){ fpecErasePage( i ); } // for; print( COM3, "\rFlashing..." ); for( ucStatus = 0; !( fileIsEOF( &pygmyFile ) ) && ucStatus != 0xFF; ){ for( i = 0; i < 64; i++ ){ ucBuffer[ i ] = fileGetChar( &pygmyFile ); if( ucBuffer[ i ] == '\r' ){ ucBuffer[ i ] = '\0'; ucSubString = getNextSubString( (u8*)ucBuffer, WHITESPACE|NEWLINE ); // Add 1 to pointer before passing to skip the ':' packet start char ucStatus = fpecProcessIHEX( (u8*)( ucSubString + 1 ) ); break; // Time to fetch next IHEX entry } // if } // for } // for } // else print( COM3, "\rBootloader Updated" ); print( COM3, "\rReseting..." ); delay( 100 ); PYGMY_RESET; //boot(); }
virtual void transferData(TcpConnectionEvent sourceEvent) { if (completed) return; /* int p = fileTell(file); if (p == 0) response(250, "Transfer started"); */ char * buf = new char [1024]; int len = fileRead(file, buf, 1024); write(buf, len, TCP_WRITE_FLAG_COPY); delete buf; if (fileIsEOF(file)) { completed = true; finishTransfer(); } }
u8 bootTest( PYGMYFILE *pygmyFile ) { // This function pre-tests every row in firmware file for corruption before erase and program u32 i; u8 ucBuffer[ 64 ], ucCalculatedSum, *ucSubString; for( ; !( fileIsEOF( pygmyFile ) ); ){ // Get an IHEX packet for( i = 0; i < 64; i++ ){ ucBuffer[ i ] = fileGetChar( pygmyFile ); if( ucBuffer[ i ] == '\r' ){ ucBuffer[ i ] = '\0'; break; } // if } // for ucSubString = getNextSubString( ucBuffer, WHITESPACE|NEWLINE ); if( *(ucSubString++) != ':' ){ return( 0 ); } // if // Following works because the output cannot be longer than the input being converted convertHexEncodedStringToBuffer( ucSubString, ucSubString ); if( ucSubString[ 3 ] == IHEX_EOF ){ break; // We have reached EOF without error } for( i = 0, ucCalculatedSum = 0; i < ucSubString[ 0 ]+4; i++ ){ ucCalculatedSum += ucSubString[ i ]; } // for ucCalculatedSum = 1 + ( 0xFF ^ (u8)ucCalculatedSum ); if( (u8)ucCalculatedSum != ucSubString[ i ] ){ // Last short is checksum return( 0 ); // Corrupt HEX Row } // if i = ( (u16)ucSubString[ 1 ] << 8 ) + ucSubString[ 2 ]; //if( ucSubString[ 3 ] == IHEX_DATA && i > 0x2000 ){ // return( 0 ); //} // if } // for return( 1 ); }
bool FileStream::isFinished() { return fileIsEOF(handle); }