예제 #1
0
파일: session.c 프로젝트: JenSte/sigrok-cli
void save_chunk_logic(uint8_t *data, uint64_t data_len, int unitsize)
{
	static uint8_t *buf = NULL;
	static int buf_len = 0;
	static int last_unitsize = 0;
	int max;

	if (!buf)
		buf = g_malloc(SAVE_CHUNK_SIZE);

	if (buf_len + data_len > SAVE_CHUNK_SIZE) {
		max = (SAVE_CHUNK_SIZE - buf_len) / unitsize * unitsize;
		memcpy(buf + buf_len, data, max);
		sr_session_append(opt_output_file, buf, unitsize,
				(buf_len + max) / unitsize);
		memcpy(buf, data + max, data_len - max);
		buf_len = data_len - max;
	} else if (data_len == 0 && last_unitsize != 0) {
		/* End of data, flush the buffer out. */
		sr_session_append(opt_output_file, buf, last_unitsize,
				buf_len / last_unitsize);
	} else {
		/* Buffer chunk. */
		memcpy(buf + buf_len, data, data_len);
		buf_len += data_len;
	}
	last_unitsize = unitsize;

}
예제 #2
0
void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
{
	assert(snapshot);

	uint64_t start_sample = 0;

	/// TODO: Wrap this in a std::unique_ptr when we transition to C++11
    uint8_t *data =  NULL;
    //uint8_t *const data = new uint8_t[BlockSize];
    //assert(data);

	const int unit_size = snapshot->unit_size();
	assert(unit_size != 0);

	{
		lock_guard<mutex> lock(_mutex);
		_unit_count = snapshot->get_sample_count();
	}

	const unsigned int samples_per_block = BlockSize / unit_size;

	while (!boost::this_thread::interruption_requested() &&
		start_sample < _unit_count)
	{
		progress_updated();

		const uint64_t end_sample = min(
			start_sample + samples_per_block, _unit_count);
        data = snapshot->get_samples(start_sample, end_sample);

		if(sr_session_append(_file_name.c_str(), data, unit_size,
			end_sample - start_sample) != SR_OK)
		{
			_error = tr("Error while saving.");
			break;
		}

		start_sample = end_sample;

		{
			lock_guard<mutex> lock(_mutex);
			_units_stored = start_sample;
		}
	}

	progress_updated();

    //delete[] data;
}
예제 #3
0
/**
 * Save a session to the specified file.
 *
 * @param session The session to save to the specified file. Must not be NULL.
 * @param filename The name of the filename to save the session as.
 *                 Must not be NULL.
 * @param sdi The device instance from which the data was captured.
 * @param buf The data to be saved.
 * @param unitsize The number of bytes per sample.
 * @param units The number of samples.
 *
 * @retval SR_OK Success
 * @retval SR_ERR_ARG Invalid arguments
 * @retval SR_ERR Other errors
 *
 * @since 0.2.0
 */
SR_API int sr_session_save(struct sr_session *session, const char *filename,
		const struct sr_dev_inst *sdi, unsigned char *buf, int unitsize,
		int units)
{
	struct sr_channel *ch;
	GSList *l;
	GVariant *gvar;
	uint64_t samplerate;
	int cnt, ret;
	char **channel_names;

	samplerate = 0;
	if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
		if (sr_config_get(sdi->driver, sdi, NULL,
					SR_CONF_SAMPLERATE, &gvar) == SR_OK) {
			samplerate = g_variant_get_uint64(gvar);
			g_variant_unref(gvar);
		}
	}

	channel_names = g_malloc0(sizeof(char *) * (g_slist_length(sdi->channels) + 1));
	cnt = 0;
	for (l = sdi->channels; l; l = l->next) {
		ch = l->data;
		if (ch->type != SR_CHANNEL_LOGIC)
			continue;
		if (ch->enabled != TRUE)
			continue;
		if (!ch->name)
			continue;
		/* Just borrowing the ptr. */
		channel_names[cnt++] = ch->name;
	}

	if ((ret = sr_session_save_init(session, filename, samplerate,
			channel_names)) != SR_OK)
		return ret;

	ret = sr_session_append(session, filename, buf, unitsize, units);

	return ret;
}