Skip to content

Commit

Permalink
modified 'hmlangw' to add timestamps to all stderr output (#2391, #2390
Browse files Browse the repository at this point in the history
…, @jp112sdl)

Co-authored-by: Jens Maus <mail@jens-maus.de>
  • Loading branch information
jp112sdl and jens-maus authored Aug 17, 2023
1 parent cfb4869 commit 31661b6
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 201 deletions.
25 changes: 13 additions & 12 deletions buildroot-external/package/hmlangw/hmframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
extern bool g_debug;
extern bool g_disableEnterBootloader;
extern void dump_data( const char* data, int length );
extern char* currentTimeStr();

int writeall( int fd, const void *buffer, int len )
{
Expand Down Expand Up @@ -69,13 +70,13 @@ int sendEnterBootloader( int fd )
if (g_disableEnterBootloader)
{
if( g_debug )
fprintf( stderr, "sendEnterBootloader not executed, because disabled (-b option is set).\n");
fprintf( stderr, "%s sendEnterBootloader not executed, because disabled (-b option is set).\n", currentTimeStr());

return 0;
}

if( g_debug )
fprintf( stderr, "sendEnterBootloader(%d)\n", fd);
fprintf( stderr, "%s sendEnterBootloader(%d)\n", fd, currentTimeStr());

int result = -1;
while( 1 )
Expand All @@ -85,25 +86,25 @@ int sendEnterBootloader( int fd )
result =writeall( fd, enterBootloader, sizeof( enterBootloader ) );
if( result <= 0 )
{
fprintf( stderr, "ERROR: writeall(%d) returned %d\n", fd, result);
fprintf( stderr, "%s ERROR: writeall(%d) returned %d\n", currentTimeStr(), fd, result);
break;
}
result = readBidcosFrame( fd, buffer, sizeof( buffer ) );
if( result <= 0 )
{
fprintf( stderr, "ERROR: invalid readBidcosFrame(%d) result: %d\n", fd, result);
fprintf( stderr, "%s ERROR: invalid readBidcosFrame(%d) result: %d\n", currentTimeStr(), fd, result);
break;
}
if( isBootloaderReply( buffer, result ) )
{
if( g_debug )
fprintf( stderr, "valid bootloader reply found\n");
fprintf( stderr, "%s valid bootloader reply found\n", currentTimeStr());

break;
}
else if( g_debug )
{
fprintf( stderr, "WARNING: invalid bootloader reply, retrying...\n");
fprintf( stderr, "%s WARNING: invalid bootloader reply, retrying...\n", currentTimeStr());
}

// wait 10 ms
Expand Down Expand Up @@ -148,7 +149,7 @@ int readBidcosFrame( int fd, char *buffer, int bufsize )
bool haveLength = false;

if( g_debug )
fprintf( stderr, "readBidcosFrame(%d, buffer, %d)\n", fd, bufsize);
fprintf( stderr, "%s readBidcosFrame(%d, buffer, %d)\n", currentTimeStr(), fd, bufsize);

while ( count )
{
Expand All @@ -168,11 +169,11 @@ int readBidcosFrame( int fd, char *buffer, int bufsize )
buf = (unsigned char *)buffer;
escapeValue = 0x00;
haveLength = false;
// fprintf( stderr, "readBidcosFrame reset\n" );
// fprintf( stderr, "%s readBidcosFrame reset\n", currentTimeStr() );
}
else if( result == 0 )
{
fprintf( stderr, "ERROR: readBidcosFrame sync error %2.2x\n", *buf );
fprintf( stderr, "%s ERROR: readBidcosFrame sync error %2.2x\n", currentTimeStr(), *buf );
// No sync at beginning? Not good...
break;
}
Expand All @@ -183,7 +184,7 @@ int readBidcosFrame( int fd, char *buffer, int bufsize )
{
escaped++;
escapeValue = 0x80;
// fprintf( stderr, "ESCAPE msgLen set %d result %d\n", msgLen, result );
// fprintf( stderr, "%s ESCAPE msgLen set %d result %d\n", currentTimeStr(), msgLen, result );
}
else
{
Expand All @@ -203,12 +204,12 @@ int readBidcosFrame( int fd, char *buffer, int bufsize )
msgLen |= *buf; // LSB
msgLen |= escapeValue;
haveLength = true;
// fprintf( stderr, "readBidcosFrame msgLen set %d result %d\n", msgLen, result );
// fprintf( stderr, "%s readBidcosFrame msgLen set %d result %d\n", currentTimeStr(), msgLen, result );
}
}
else if( result >= msgLen + escaped + 5 )
{
// fprintf( stderr, "readBidcosFrame done, msgLen %d result %d\n", msgLen, result );
// fprintf( stderr, "%s readBidcosFrame done, msgLen %d result %d\n", currentTimeStr(), msgLen, result );
break;
}

Expand Down
Loading

0 comments on commit 31661b6

Please sign in to comment.