input/trace32_ad: data type nits, log verbosity in header parsing

Log determined header format when parsing trace32 file headers. Keep
another log message during regular processing, but silence it during
format match.

Use more appropriate data types for local and instance variables. Adjust
format strings accordingly.
This commit is contained in:
Gerhard Sittig 2018-05-12 18:09:31 +02:00 committed by Uwe Hermann
parent 80430d4d20
commit 83df004be1
1 changed files with 26 additions and 16 deletions

View File

@ -62,12 +62,13 @@
*/ */
#define DEFAULT_SAMPLERATE 200 #define DEFAULT_SAMPLERATE 200
enum { enum ad_format {
AD_FORMAT_BINHDR = 1, /* Binary header, binary data, textual setup info */ AD_FORMAT_UNKNOWN,
AD_FORMAT_TXTHDR /* Textual header, binary data */ AD_FORMAT_BINHDR, /* Binary header, binary data, textual setup info */
AD_FORMAT_TXTHDR, /* Textual header, binary data */
}; };
enum { enum ad_device {
AD_DEVICE_PI = 1, /* Data recorded by LA-7940 PowerIntegrator or */ AD_DEVICE_PI = 1, /* Data recorded by LA-7940 PowerIntegrator or */
/* LA-394x PowerIntegrator II. */ /* LA-394x PowerIntegrator II. */
AD_DEVICE_IPROBE /* Data recorded by LA-769x PowerTrace II IProbe. */ AD_DEVICE_IPROBE /* Data recorded by LA-769x PowerTrace II IProbe. */
@ -75,12 +76,12 @@ enum {
/* Missing file format info for LA-4530 uTrace analog probe */ /* Missing file format info for LA-4530 uTrace analog probe */
}; };
enum { enum ad_mode {
AD_MODE_250MHZ = 0, AD_MODE_250MHZ = 0,
AD_MODE_500MHZ = 1 AD_MODE_500MHZ = 1
}; };
enum { enum ad_compr {
AD_COMPR_NONE = 0, /* File created with /NOCOMPRESS */ AD_COMPR_NONE = 0, /* File created with /NOCOMPRESS */
AD_COMPR_QCOMP = 6, /* File created with /COMPRESS or /QUICKCOMPRESS */ AD_COMPR_QCOMP = 6, /* File created with /COMPRESS or /QUICKCOMPRESS */
}; };
@ -88,7 +89,10 @@ enum {
struct context { struct context {
gboolean meta_sent; gboolean meta_sent;
gboolean header_read, records_read, trigger_sent; gboolean header_read, records_read, trigger_sent;
char format, device, record_mode, compression; enum ad_format format;
enum ad_device device;
enum ad_mode record_mode;
enum ad_compr compression;
char pod_status[MAX_POD_COUNT]; char pod_status[MAX_POD_COUNT];
struct sr_channel *channels[MAX_POD_COUNT][17]; /* 16 + CLK */ struct sr_channel *channels[MAX_POD_COUNT][17]; /* 16 + CLK */
uint64_t trigger_timestamp; uint64_t trigger_timestamp;
@ -203,7 +207,9 @@ static int process_header(GString *buf, struct context *inc)
char *format_name, *format_name_sig; char *format_name, *format_name_sig;
char *p; char *p;
int has_trace32; int has_trace32;
int record_size, device_id; size_t record_size;
enum ad_device device_id;
enum ad_format format;
/* /*
* 00-31 (0x00-1F) file format name * 00-31 (0x00-1F) file format name
@ -251,14 +257,13 @@ static int process_header(GString *buf, struct context *inc)
has_trace32 = g_strcmp0(format_name_sig, TRACE32) == 0; has_trace32 = g_strcmp0(format_name_sig, TRACE32) == 0;
g_free(format_name_sig); g_free(format_name_sig);
format = AD_FORMAT_UNKNOWN;
if (has_trace32) { if (has_trace32) {
/* Literal "trace32" leader, binary header follows. */ /* Literal "trace32" leader, binary header follows. */
if (inc) format = AD_FORMAT_BINHDR;
inc->format = AD_FORMAT_BINHDR;
} else if (g_ascii_isdigit(format_name[0]) && (format_name[1] == SPACE)) { } else if (g_ascii_isdigit(format_name[0]) && (format_name[1] == SPACE)) {
/* Digit and SPACE leader, currently unsupported text header. */ /* Digit and SPACE leader, currently unsupported text header. */
if (inc) format = AD_FORMAT_TXTHDR;
inc->format = AD_FORMAT_TXTHDR;
g_free(format_name); g_free(format_name);
if (inc) if (inc)
sr_err("This format isn't implemented yet, aborting."); sr_err("This format isn't implemented yet, aborting.");
@ -270,9 +275,12 @@ static int process_header(GString *buf, struct context *inc)
sr_err("Don't know this file format, aborting."); sr_err("Don't know this file format, aborting.");
return SR_ERR; return SR_ERR;
} }
if (!format)
return SR_ERR;
p = printable_name(format_name); p = printable_name(format_name);
sr_dbg("File says it's \"%s\"", p); if (inc)
sr_dbg("File says it's \"%s\" -> format type %u.", p, format);
g_free(p); g_free(p);
record_size = R8(buf->str + 56); record_size = R8(buf->str + 56);
@ -288,8 +296,9 @@ static int process_header(GString *buf, struct context *inc)
if (!device_id) { if (!device_id) {
g_free(format_name); g_free(format_name);
sr_err("Don't know how to handle this file with record size %d.", if (inc)
record_size); sr_err("Cannot handle file with record size %zu.",
record_size);
return SR_ERR; return SR_ERR;
} }
@ -299,6 +308,7 @@ static int process_header(GString *buf, struct context *inc)
if (!inc) if (!inc)
return SR_OK; return SR_OK;
inc->format = format;
inc->device = device_id; inc->device = device_id;
inc->trigger_timestamp = RL64(buf->str + 32); inc->trigger_timestamp = RL64(buf->str + 32);
inc->compression = R8(buf->str + 48); /* Maps to the enum. */ inc->compression = R8(buf->str + 48); /* Maps to the enum. */
@ -314,7 +324,7 @@ static int process_header(GString *buf, struct context *inc)
inc->last_record); inc->last_record);
/* Check if we can work with this compression. */ /* Check if we can work with this compression. */
if (inc->compression != AD_COMPR_NONE) { if (inc->compression) {
sr_err("File uses unsupported compression (0x%02X), can't continue.", sr_err("File uses unsupported compression (0x%02X), can't continue.",
inc->compression); inc->compression);
return SR_ERR; return SR_ERR;