#define DEFAULT_SAMPLES_PER_LINE 74
+/*
+ * The string looks ugly with escape characters, here is the readable
+ * version: Use . and " for low and high bits, use \ and / to draw
+ * falling and rising edges respectively.
+ */
+#define DEFAULT_ASCII_CHARS ".\"\\/"
+
struct context {
unsigned int num_enabled_channels;
int spl;
gboolean header_done;
GString **lines;
GString *header;
+ const char *charset;
+ gboolean edges;
};
static int init(struct sr_output *o, GHashTable *options)
o->priv = ctx;
ctx->trigger = -1;
ctx->spl = g_variant_get_uint32(g_hash_table_lookup(options, "width"));
+ ctx->charset = g_strdup(g_variant_get_string(
+ g_hash_table_lookup(options, "charset"), NULL));
+ if (!ctx->charset || strlen(ctx->charset) < 2) {
+ g_free((gpointer)ctx->charset);
+ ctx->charset = g_strdup(DEFAULT_ASCII_CHARS);
+ }
+ ctx->edges = (strlen(ctx->charset) >= 4) ? TRUE : FALSE;
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
int idx, offset, curbit, prevbit;
uint64_t i, j;
gchar *p, c;
+ size_t charidx;
*out = NULL;
if (!o || !o->sdi)
curbit = *p & (1 << (idx % 8));
prevbit = (ctx->prev_sample[idx / 8] & ((uint8_t) 1 << (idx % 8)));
- c = curbit ? '"' : '.';
- if (ctx->spl_cnt > 1) {
- if (curbit < prevbit)
- c = '\\';
- else if (curbit > prevbit)
- c = '/';
+ charidx = curbit ? 1 : 0;
+ if (ctx->edges && ctx->spl_cnt > 1) {
+ if (curbit != prevbit)
+ charidx += 2;
}
+ c = ctx->charset[charidx];
g_string_append_c(ctx->lines[j], c);
if (ctx->spl_cnt == ctx->spl) {
for (i = 0; i < ctx->num_enabled_channels; i++)
g_string_free(ctx->lines[i], TRUE);
g_free(ctx->lines);
+ g_free((gpointer)ctx->charset);
g_free(ctx);
o->priv = NULL;
static struct sr_option options[] = {
{ "width", "Width", "Number of samples per line", NULL, NULL },
+ { "charset", "Charset", "Characters for 0/1 bits (and fall/rise edges)", NULL, NULL },
ALL_ZERO
};
if (!options[0].def) {
options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE);
g_variant_ref_sink(options[0].def);
+ options[1].def = g_variant_new_string(DEFAULT_ASCII_CHARS);
+ g_variant_ref_sink(options[1].def);
}
return options;