Esempio n. 1
0
static int		recv_var	(CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr)
{
	char *path;
	uint8_t *data = NULL;
	VarEntry *ve;
	char *utf8;
	int err;
	const char * dot_if_any = ".";

	TRYF(nsp_session_open(handle, SID_FILE_MGMT));

	// Don't add a dot if this file type is unknown.
	if (vr->type >= NSP_MAXTYPES)
		dot_if_any = "";

	path = g_strconcat("/", vr->folder, "/", vr->name, dot_if_any, 
		tifiles_vartype2fext(handle->model, vr->type), NULL);
	utf8 = ticonv_varname_to_utf8(handle->model, path, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	err = nsp_cmd_s_get_file(handle, path);
	g_free(path);
	if (err)
	{
		return err;
	}
	TRYF(nsp_cmd_r_get_file(handle, &(vr->size)));

	TRYF(nsp_cmd_s_file_ok(handle));
	if (vr->size)
		TRYF(nsp_cmd_r_file_contents(handle, &(vr->size), &data));
	TRYF(nsp_cmd_s_status(handle, ERR_OK));

	content->model = handle->model;
	strcpy(content->comment, tifiles_comment_set_single());
	content->num_entries = 1;

	content->entries = tifiles_ve_create_array(1);
	ve = content->entries[0] = tifiles_ve_create();
	memcpy(ve, vr, sizeof(VarEntry));

	ve->data = tifiles_ve_alloc_data(ve->size);
	if (data && ve->data)
	{
		memcpy(ve->data, data, ve->size);
	}
	g_free(data);

	// XXX don't check the result of this call, to enable reception of variables from Nspires running OS >= 1.7.
	// Those versions send a martian packet:
	// * a src port never seen before in the conversation;
	// * an improper dest port;
	// * a 1-byte payload containing 02 (i.e. an invalid address for the next packet).
	// * .ack = 0x00 (instead of 0x0A).
	nsp_session_close(handle);

	return 0;
}
Esempio n. 2
0
static int		dump_rom_2	(CalcHandle* handle, CalcDumpSize size, const char *filename)
{
	int ret;
	FILE *f;

	ticalcs_info("FIXME: make ROM dumping work above OS 1.x, using the Fron method");

	f = fopen(filename, "wb");
	if (f == NULL)
	{
		return ERR_OPEN_FILE;
	}

	ret = nsp_session_open(handle, NSP_SID_FILE_MGMT);
	if (!ret)
	{
		ret = nsp_cmd_s_get_file(handle, "../phoenix/install/TI-Nspire.tnc");
		if (!ret)
		{
			uint32_t varsize;

			ret = nsp_cmd_r_get_file(handle, &varsize);
			if (!ret)
			{
				ret = nsp_cmd_s_file_ok(handle);
				if (!ret)
				{
					uint8_t *data;

					ret = nsp_cmd_r_file_contents(handle, &varsize, &data);
					if (!ret)
					{
						ret = nsp_cmd_s_status(handle, NSP_ERR_OK);
						if (!ret)
						{
							if (fwrite(data, varsize, 1, f) < 1)
							{
								ret = ERR_SAVE_FILE;
							}
						}
						g_free(data);
					}
				}
			}
		}

		DO_CLOSE_SESSION(handle);
	}

	fclose(f);

	return ret;
}
Esempio n. 3
0
static int		dump_rom_2	(CalcHandle* handle, CalcDumpSize size, const char *filename)
{
	uint32_t varsize;
	uint8_t *data;
	int err;
	FILE *f;

	ticalcs_info("FIXME: make ROM dumping work above OS 1.x");

	TRYF(nsp_session_open(handle, SID_FILE_MGMT));

	f = fopen(filename, "wb");
	if (f == NULL)
	{
		return ERR_OPEN_FILE;
	}

	err = nsp_cmd_s_get_file(handle, "../phoenix/install/TI-Nspire.tnc");
	if (!err)
	{
		err = nsp_cmd_r_get_file(handle, &varsize);
		if (!err)
		{
			err = nsp_cmd_s_file_ok(handle);
			if (!err)
			{
				err = nsp_cmd_r_file_contents(handle, &varsize, &data);
				if (!err)
				{
					err = nsp_cmd_s_status(handle, ERR_OK);
					if (!err)
					{
						if (fwrite(data, varsize, 1, f) < 1)
						{
							err = ERR_SAVE_FILE;
						}
					}
				}
			}
		}
	}

	fclose(f);

	nsp_session_close(handle);
	return err;
}
Esempio n. 4
0
static int		recv_var	(CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr)
{
	char *path;
	int ret;

	ret = nsp_session_open(handle, NSP_SID_FILE_MGMT);
	if (ret)
	{
		return ret;
	}

	path = build_path(handle->model, vr);
	ticonv_varname_to_utf8_sn(handle->model, path, update_->text, sizeof(update_->text), vr->type);
	update_label();

	ret = nsp_cmd_s_get_file(handle, path);
	g_free(path);
	if (!ret)
	{
		ret = nsp_cmd_r_get_file(handle, &(vr->size));
		if (!ret)
		{
			ret = nsp_cmd_s_file_ok(handle);
			if (!ret)
			{
				uint8_t *data = NULL;

				if (vr->size)
				{
					ret = nsp_cmd_r_file_contents(handle, &(vr->size), &data);
				}
				if (!ret)
				{
					ret = nsp_cmd_s_status(handle, NSP_ERR_OK);
					if (!ret)
					{
						VarEntry *ve;

						content->model = handle->model;
						ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment));
						content->num_entries = 1;

						content->entries = tifiles_ve_create_array(1);
						ve = content->entries[0] = tifiles_ve_create();
						memcpy(ve, vr, sizeof(VarEntry));

						ve->data = tifiles_ve_alloc_data(ve->size);
						if (data && ve->data)
						{
							memcpy(ve->data, data, ve->size);
						}
					}
					g_free(data);
				}
			}
		}
	}

	// Close session at the end.
	// XXX don't check the result of this call, to enable reception of variables from Nspires running OS >= 1.7.
	// Those versions send a martian packet:
	// * a src port never seen before in the conversation;
	// * an improper dest port;
	// * a 1-byte payload containing 02 (i.e. an invalid address for the next packet).
	// * .ack = 0x00 (instead of 0x0A).
	nsp_session_close(handle);

	return ret;
}