void MainWindow::on_actionQUICK_HACK_PD_TEST_triggered() { #define N 500000 struct srd_decoder_inst *di; GHashTable *pd_opthash; uint8_t *buf = (uint8_t *)malloc(N + 1); pd_opthash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); /* Hardcode a specific I2C probe mapping. */ g_hash_table_insert(pd_opthash, g_strdup("scl"), g_strdup("5")); g_hash_table_insert(pd_opthash, g_strdup("sda"), g_strdup("7")); /* * Get data from a hardcoded binary file. * (converted to binary from melexis_mlx90614_5s_24deg.sr. */ QFile file("foo.bin"); int ret = file.open(QIODevice::ReadOnly); ret = file.read((char *)buf, N); // sr_log_loglevel_set(SR_LOG_NONE); // srd_log_loglevel_set(SRD_LOG_NONE); if (!(di = srd_inst_new("i2c", pd_opthash))) { ui->plainTextEdit->appendPlainText("ERROR: srd_inst_new"); return; } if (srd_inst_probe_set_all(di, pd_opthash) != SRD_OK) { ui->plainTextEdit->appendPlainText("ERROR: srd_inst_set_probes"); return; } if (srd_pd_output_callback_add(SRD_OUTPUT_ANN, (srd_pd_output_callback_t)show_pd_annotation, (void *)this) != SRD_OK) { ui->plainTextEdit->appendPlainText("ERROR: srd_pd_output_callback_add"); return; } if (srd_session_start(8, 1, 1000000) != SRD_OK) { ui->plainTextEdit->appendPlainText("ERROR: srd_session_start"); return; } if (srd_session_send(0, buf, N) != SRD_OK) { ui->plainTextEdit->appendPlainText("ERROR: srd_session_send"); return; } }
srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session, int unit_size) const { (void)unit_size; GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); for (map<string, GVariant*>::const_iterator i = _options.begin(); i != _options.end(); i++) { GVariant *const value = (*i).second; g_variant_ref(value); g_hash_table_replace(opt_hash, (void*)g_strdup( (*i).first.c_str()), value); } srd_decoder_inst *const decoder_inst = srd_inst_new( session, _decoder->id, opt_hash); g_hash_table_destroy(opt_hash); if(!decoder_inst) return NULL; // Setup the probes GHashTable *const probes = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); for(map<const srd_channel*, shared_ptr<view::LogicSignal> >:: const_iterator i = _probes.begin(); i != _probes.end(); i++) { shared_ptr<view::LogicSignal> signal((*i).second); GVariant *const gvar = g_variant_new_int32( signal->probe()->index); g_variant_ref_sink(gvar); g_hash_table_insert(probes, (*i).first->id, gvar); } srd_inst_channel_set_all(decoder_inst, probes); return decoder_inst; }
/* Register the given PDs for this session. * Accepts a string of the form: "spi:sck=3:sdata=4,spi:sck=3:sdata=5" * That will instantiate two SPI decoders on the clock but different data * lines. */ static int register_pds(struct sr_dev *dev, const char *pdstring) { GHashTable *pd_opthash; struct srd_decoder_inst *di; int ret; char **pdtokens, **pdtok, *pd_name; /* Avoid compiler warnings. */ (void)dev; ret = 0; pd_ann_visible = g_hash_table_new_full(g_str_hash, g_int_equal, g_free, NULL); pd_name = NULL; pd_opthash = NULL; pdtokens = g_strsplit(pdstring, ",", 0); for (pdtok = pdtokens; *pdtok; pdtok++) { if (!(pd_opthash = parse_generic_arg(*pdtok))) { g_critical("Invalid protocol decoder option '%s'.", *pdtok); goto err_out; } pd_name = g_strdup(g_hash_table_lookup(pd_opthash, "sigrok_key")); g_hash_table_remove(pd_opthash, "sigrok_key"); if (srd_decoder_load(pd_name) != SRD_OK) { g_critical("Failed to load protocol decoder %s.", pd_name); ret = 1; goto err_out; } if (!(di = srd_inst_new(pd_name, pd_opthash))) { g_critical("Failed to instantiate protocol decoder %s.", pd_name); ret = 1; goto err_out; } /* If no annotation list was specified, add them all in now. * This will be pared down later to leave only the last PD * in the stack. */ if (!opt_pd_annotations) g_hash_table_insert(pd_ann_visible, g_strdup(di->inst_id), NULL); /* Any keys left in the options hash are probes, where the key * is the probe name as specified in the decoder class, and the * value is the probe number i.e. the order in which the PD's * incoming samples are arranged. */ if (srd_inst_probe_set_all(di, pd_opthash) != SRD_OK) { ret = 1; goto err_out; } g_hash_table_destroy(pd_opthash); pd_opthash = NULL; } err_out: g_strfreev(pdtokens); if (pd_opthash) g_hash_table_destroy(pd_opthash); if (pd_name) g_free(pd_name); return ret; }