Skip to content

Commit

Permalink
Tested with experimental orbtrace COBS code
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Mar 16, 2024
1 parent 8448cf2 commit 37a4018
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
7 changes: 7 additions & 0 deletions Inc/orbtraceIf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct OrbtraceIf
uint8_t ep; /* Endpoint used for data transfer */
uint8_t iface; /* ...and the interface */
bool isOrbtrace; /* Is this an orbtrace device? */
bool supportsCOBS; /* ...and does it support COBs for transfer? */

int numDevices; /* Number of matching devices found */
struct OrbtraceIfDevice *devices; /* List of matching devices found */
Expand Down Expand Up @@ -141,6 +142,11 @@ static inline libusb_device_handle *OrbtraceIfGetHandle( struct OrbtraceIf *o )
return o->handle;
}

static inline bool OrbtraceSupportsCOBS( struct OrbtraceIf *o )
{
return o->supportsCOBS;
}

/* Device selection management */
int OrbtraceIfGetDeviceList( struct OrbtraceIf *o, char *sn, uint32_t devmask );
void OrbtraceIfListDevices( struct OrbtraceIf *o );
Expand All @@ -150,6 +156,7 @@ bool OrbtraceGetIfandEP( struct OrbtraceIf *o );
void OrbtraceIfCloseDevice( struct OrbtraceIf *o );
enum Channel OrbtraceIfNameToChannel( char *x );
bool OrbtraceIsOrbtrace( struct OrbtraceIf *o );
bool OrbtraceSupportsCOBS( struct OrbtraceIf *o );

/* Device manipulation */
bool OrbtraceIfSetTraceWidth( struct OrbtraceIf *o, int width );
Expand Down
4 changes: 4 additions & 0 deletions Src/orbtraceIf.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static const struct OrbtraceInterfaceType _validDevices[DEVICE_NUM_DEVICES] =
{ 0, 0 }
};

#define LAST_NONCOBS_ORBTRACE "v1.3.2-0"

/* BMP Interface and endpoint are fixed, so we can return those on request */
#define BMP_IFACE (5)
#define BMP_EP (0x85)
Expand Down Expand Up @@ -468,6 +470,7 @@ bool OrbtraceGetIfandEP( struct OrbtraceIf *o )
o->iface = BMP_IFACE;
o->ep = BMP_EP;
o->isOrbtrace = false;
o->supportsCOBS = false;
break;

case DEVICE_ORBTRACE_MINI: // -------------------------------------------------------------------
Expand Down Expand Up @@ -519,6 +522,7 @@ bool OrbtraceGetIfandEP( struct OrbtraceIf *o )
}

o->isOrbtrace = true;
o->supportsCOBS = strncmp( LAST_NONCOBS_ORBTRACE, o->devices[o->activeDevice].version, strlen( LAST_NONCOBS_ORBTRACE ) ) > 0;
break;
}

Expand Down
56 changes: 21 additions & 35 deletions Src/orbuculum.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@
#define ORBTRACE "orbtrace"
#define ORBTRACEENVNAME "ORBTRACE"

// Define this to use original clean ORBTRACE code
#define LEGACY_ORBTRACE 1

/* Record for options, either defaults or from command line */
struct Options
{
Expand Down Expand Up @@ -686,33 +683,32 @@ void *_checkInterval( void *params )
h = r->handler;
uint64_t totalDat = 0;

/* If we are decoding from TPIU then calculate per channel */
if ( ( r->intervalRawBytes ) && ( r->options->useTPIU ) )
if ( r->intervalRawBytes )
{
for ( int chIndex = 0; chIndex < r->numHandlers; chIndex++ )
if ( r->options->useTPIU )
{
genericsPrintf( " %d:%3d%% ", h->channel, ( h->intervalBytes * 100 ) / r->intervalRawBytes );
totalDat += h->intervalBytes;
h->intervalBytes = 0;
h++;
}

genericsPrintf( " Waste:%3d%% ", 100 - ( ( totalDat * 100 ) / r->intervalRawBytes ) );
}
/* If we are decoding from TPIU then calculate per channel */
for ( int chIndex = 0; chIndex < r->numHandlers; chIndex++ )
{
genericsPrintf( " %d:%3d%% ", h->channel, ( h->intervalBytes * 100 ) / r->intervalRawBytes );
totalDat += h->intervalBytes;
h->intervalBytes = 0;
h++;
}

#ifndef LEGACY_ORBTRACE
else
{
/* Either raw ITM or COBs frames */
if ( OrbtraceIsOrbtrace( _r.o ) && r->intervalRawBytes )
genericsPrintf( " Waste:%3d%% ", 100 - ( ( totalDat * 100 ) / r->intervalRawBytes ) );
}
else
{
int w = 1000 - ( ( r->cobsDataLenRxed * 1000 ) / r->intervalRawBytes );
genericsPrintf( " Waste:%01d.%01d%%", w / 10, w % 10 );
/* Either raw ITM or COBs frames */
if ( OrbtraceSupportsCOBS( _r.o ) )
{
int w = 1000 - ( ( r->cobsDataLenRxed * 1000 ) / r->intervalRawBytes );
genericsPrintf( " Waste:%01d.%01d%%", w / 10, w % 10 );
}
}
}

#endif

r->cobsDataLenRxed = 0;
r->intervalRawBytes = 0;

Expand Down Expand Up @@ -1043,9 +1039,7 @@ static void _usb_callback( struct libusb_transfer *t )
}
}

#ifndef LEGACY_ORBTRACE

if ( OrbtraceIsOrbtrace( _r.o ) )
if ( OrbtraceSupportsCOBS( _r.o ) )
{
_cobsIncoming( &_r, t->buffer, t->actual_length );
/* We need to decode this so it can go through the 'normal' output channels too */
Expand All @@ -1054,7 +1048,6 @@ static void _usb_callback( struct libusb_transfer *t )
_purgeBlock( &_r );
}
else
#endif
{
_processBlock( &_r, t->actual_length, t->buffer );
_r.intervalRawBytes += t->actual_length;
Expand Down Expand Up @@ -1533,12 +1526,7 @@ int main( int argc, char *argv[] )

#endif

#ifndef LEGACY_ORBTRACE

if ( _r.options->channelList )
#else
if ( ( _r.options->channelList ) && ( _r.options->useTPIU ) )
#endif
if ( _r.options->channelList && _r.options->useTPIU )
{
/* Channel list is only needed for legacy ports that we are re-exporting (i.e. clean unencapsulated flows) */
char *c = _r.options->channelList;
Expand Down Expand Up @@ -1614,8 +1602,6 @@ int main( int argc, char *argv[] )
}
}

sleep( 3 );

if ( ( _r.options->nwserverPort ) || ( _r.options->port ) || ( _r.options->file ) )
{
/* Start the distribution task */
Expand Down

0 comments on commit 37a4018

Please sign in to comment.