Example #1
0
static int		send_var	(CalcHandle* handle, CalcMode mode, FileContent* content)
{
	int i;
	char *utf8;
	CalcAttr **attrs;
	const int nattrs = 3;

	for (i = 0; i < content->num_entries; i++) 
	{
		VarEntry *ve = content->entries[i];
		
		if(ve->action == ACT_SKIP)
			continue;

		utf8 = ticonv_varname_to_utf8(handle->model, ve->name, ve->type);
		g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
		g_free(utf8);
		update_label();

		attrs = ca_new_array(nattrs);
		attrs[0] = ca_new(AID_VAR_TYPE, 4);
		attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
		attrs[0]->data[2] = 0x00; attrs[0]->data[3] = ve->type;
		attrs[1] = ca_new(AID_ARCHIVED, 1);
		attrs[1]->data[0] = ve->attr == ATTRB_ARCHIVED ? 1 : 0;
		attrs[2] = ca_new(AID_VAR_VERSION, 4);

		TRYF(cmd_s_rts(handle,"",ve->name,ve->size,nattrs,CA(attrs)));
		TRYF(cmd_r_data_ack(handle));
		TRYF(cmd_s_var_content(handle, ve->size, ve->data));
		TRYF(cmd_r_data_ack(handle));
		TRYF(cmd_s_eot(handle));

		PAUSE(50);	// needed
	}

	return 0;
}
Example #2
0
static int		del_var		(CalcHandle* handle, VarRequest* vr)
{
	CalcAttr **attr;
	const int size = 2;
	char *utf8;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), _("Deleting %s..."), utf8);
	g_free(utf8);
	update_label();

	attr = ca_new_array(size);
	attr[0] = ca_new(0x0011, 4);
	attr[0]->data[0] = 0xF0; attr[0]->data[1] = 0x0B;
	attr[0]->data[2] = 0x00; attr[0]->data[3] = vr->type;
	attr[1] = ca_new(0x0013, 1);
	attr[1]->data[0] = vr->attr == ATTRB_ARCHIVED ? 1 : 0;

	TRYF(cmd_s_var_delete(handle, "", vr->name, size, CA(attr)));
	TRYF(cmd_r_data_ack(handle));

	ca_del_array(size, attr);
	return 0;
}
Example #3
0
int
main(int argc, char *argv[])
{
    hash_t *htab;
    hnode_t *hnp, *hnp1;
    char *line;
    ca_o ca, pca;
    int i;
    unsigned long phash = 0;

    htab = hash_create(argc, (hash_comp_t) hash_comp_test, hash_fun_test);

    //printf("key width = %lu\n", HASH_VAL_T_MAX);

    for (i = 1; i < argc; i++) {
        line = argv[i];
        ca = ca_new(line);
        ca->ca_phash = phash;
        phash = ca->ca_hash;

        if (! hash_lookup(htab, (void *)ca->ca_hash)) {
            hnp = hnode_create(ca);
            hash_insert(htab, hnp, (void *)ca->ca_hash);
            printf("%s [%lu.%lu]\n", ca->ca_line, ca->ca_phash, ca->ca_hash);
        } else {
            printf("%s present\n", line);
        }
    }

    hscan_t hscan;
    hash_scan_begin(&hscan, htab);
    for (hnp = hash_scan_next(&hscan); hnp; hnp = hash_scan_next(&hscan)) {
        ca = (ca_o)hnode_get(hnp);
        printf("%s [%lu.%lu]\n", ca->ca_line, ca->ca_phash, ca->ca_hash);
        if ((hnp1 = hash_lookup(htab, (void *)ca->ca_phash))) {
            pca = (ca_o)hnode_get(hnp1);
            printf("parent of %s is %s\n", ca->ca_line, pca->ca_line);
        } else {
            printf("%s [%lu.%lu] has no parent\n",
                   ca->ca_line, ca->ca_phash, ca->ca_hash);
        }
        //hash_scan_delete(htab, hnp);
        //hnode_destroy(hnp);
    }

    return 0;
}
Example #4
0
static int		recv_var	(CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr)
{
	uint16_t aids[] = { AID_ARCHIVED, AID_VAR_VERSION, AID_VAR_SIZE };
	const int naids = sizeof(aids) / sizeof(uint16_t);
	CalcAttr **attrs;
	const int nattrs = 1;
	char fldname[40], varname[40];
	uint8_t *data;
	VarEntry *ve;
	char *utf8;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE2, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type;

	TRYF(cmd_s_var_request(handle,"",vr->name,naids,aids,nattrs,CA(attrs)));
	ca_del_array(nattrs, attrs);
	attrs = ca_new_array(naids);
	TRYF(cmd_r_var_header(handle, fldname, varname, attrs));
	TRYF(cmd_r_var_content(handle, NULL, &data));

	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->size = GINT32_FROM_BE(*((uint32_t *)(attrs[2]->data)));
	ve->data = tifiles_ve_alloc_data(ve->size);
	memcpy(ve->data, data, ve->size);

	g_free(data);
	ca_del_array(naids, attrs);
	return 0;
}
Example #5
0
static int		recv_idlist	(CalcHandle* handle, uint8_t* id)
{
	uint16_t aids[] = { AID_ARCHIVED, AID_VAR_VERSION };
	const int naids = sizeof(aids) / sizeof(uint16_t);
	CalcAttr **attrs;
	const int nattrs = 1;
	char folder[40], name[40];
	uint8_t *data;
	int i, varsize;

	g_snprintf(update_->text, sizeof(update_->text), "ID-LIST");
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE2, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = TI83p_IDLIST;

	TRYF(cmd_s_var_request(handle, "", "IDList", naids, aids, 
			       nattrs, CA(attrs)));
	ca_del_array(nattrs, attrs);
	attrs = ca_new_array(naids);
	TRYF(cmd_r_var_header(handle, folder, name, attrs));
	TRYF(cmd_r_var_content(handle, (uint32_t *)&varsize, &data));

	i = data[9];
	data[9] = data[10];
	data[10] = i;

	for(i = 4; i < varsize && i < 16; i++)
		sprintf((char *)&id[2 * (i-4)], "%02x", data[i]);
	id[7*2] = '\0';

	g_free(data);
	ca_del_array(naids, attrs);
	return 0;
}
Example #6
0
/// Constructor for CmdAction class.
/// Any change to the CSV format requires an equivalent change here.
/// @param[in] csv      a string in the canonical CSV format for CAs
/// @return a new, complete CmdAction object
ca_o
ca_newFromCSVString(CCS csv)
{
    CS linebuf, original;
    CCS cmdid, depth, pcmdid, starttime, duration, prog, host;
    CCS recycled, freetext, rwd, pccode, ccode, pathcode;
    ca_o ca;

    // It would be nice if we could use sscanf here but it won't work
    // because sscanf can't handle multiple %s fields.

    // The line buffer will be trashed by util_strsep(), so we
    // allocate a temporary copy. The pointer passed in will also
    // be changed, so we need to hold a copy of the original address
    // to be freed.
    linebuf = original = putil_strdup(csv);

    // *INDENT-OFF*
    if (    !(cmdid      = util_strsep(&linebuf, FS1)) ||
	    !(depth      = util_strsep(&linebuf, FS1)) ||
	    !(pcmdid     = util_strsep(&linebuf, FS1)) ||
	    !(starttime  = util_strsep(&linebuf, FS1)) ||
	    !(duration   = util_strsep(&linebuf, FS1)) ||
	    !(host       = util_strsep(&linebuf, FS1)) ||
	    !(recycled   = util_strsep(&linebuf, FS1)) ||
	    !(freetext   = util_strsep(&linebuf, FS1)) ||
	    !(prog       = util_strsep(&linebuf, FS1)) ||
	    !(rwd        = util_strsep(&linebuf, FS1)) ||
	    !(pccode     = util_strsep(&linebuf, FS1)) ||
	    !(ccode      = util_strsep(&linebuf, FS1)) ||
	    !(pathcode   = util_strsep(&linebuf, FS1))) {
	putil_int("bad format: '%s'", csv);
	putil_free(original);
	return NULL;
    }
    // *INDENT-ON*

    ca = ca_new();

    ca_set_cmdid(ca, strtoul(cmdid, NULL, 10));
    ca_set_depth(ca, strtoul(depth, NULL, 10));
    ca_set_pcmdid(ca, strtoul(pcmdid, NULL, 10));
    if (moment_parse(&(ca->ca_starttime), starttime)) {
        putil_int("bad moment format: %s", starttime);
        putil_free(original);
        return NULL;
    }
    ca_set_duration(ca, strtoul(duration, NULL, 10));
    ca_set_prog(ca, prog);
    ca_set_host(ca, host);
    ca_set_recycled(ca, recycled);
    ca_set_freetext(ca, freetext);
    ca_set_rwd(ca, rwd);
    ca_set_pccode(ca, pccode);
    ca_set_pathcode(ca, pathcode);
    ca_set_line(ca, linebuf);

    if (_ca_cmp_codes(ca_get_ccode(ca), ccode)) {
        putil_int("%s: ccode skew (%s != %s)",
                  ca_get_line(ca), ca_get_ccode(ca), ccode);
    }

    putil_free(original);
    return ca;
}
Example #7
0
static int		recv_flash	(CalcHandle* handle, FlashContent* content, VarRequest* vr)
{
	uint16_t aids[] = { AID_ARCHIVED, AID_VAR_VERSION };
	const int naids = sizeof(aids) / sizeof(uint16_t);
	CalcAttr **attrs;
	const int nattrs = 1;
	char fldname[40], varname[40];
	uint8_t *data;
	char *utf8;
	
	int page;
	uint16_t data_addr = 0x4000;
	uint16_t data_page = 0;
	int r, q;

	utf8 = ticonv_varname_to_utf8(handle->model, vr->name, vr->type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE2, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = vr->type;

	TRYF(cmd_s_var_request(handle, "", vr->name, naids, aids, 
			       nattrs, CA(attrs)));
	ca_del_array(nattrs, attrs);
	attrs = ca_new_array(naids);
	TRYF(cmd_r_var_header(handle, fldname, varname, attrs));
	TRYF(cmd_r_var_content(handle, NULL, &data));

	content->model = handle->model;
	strcpy(content->name, vr->name);
	content->data_type = vr->type;
	content->device_type = DEVICE_TYPE_83P;
	content->num_pages = 2048;	// TI83+ has 512 KB of FLASH max
	content->pages = tifiles_fp_create_array(content->num_pages);

	q = vr->size / FLASH_PAGE_SIZE;
	r = vr->size % FLASH_PAGE_SIZE;

	update_->cnt2 = 0;
	update_->max2 = q;

	for(page = 0; page < q; page++)
	{
		FlashPage *fp = content->pages[page] = tifiles_fp_create();

		fp->addr = data_addr;
		fp->page = data_page++;
		fp->flag = 0x80;
		fp->size = FLASH_PAGE_SIZE;
		fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE);
		memcpy(fp->data, data + FLASH_PAGE_SIZE*page, FLASH_PAGE_SIZE);

		update_->cnt2 = page;
		update_->pbar();
	}
	{
		FlashPage *fp = content->pages[page] = tifiles_fp_create();

		fp->addr = data_addr;
		fp->page = data_page++;
		fp->flag = 0x80;
		fp->size = r;
		fp->data = tifiles_fp_alloc_data(FLASH_PAGE_SIZE);
		memcpy(fp->data, data + FLASH_PAGE_SIZE*page, r);

		update_->cnt2 = page;
		update_->pbar();
	}
	content->num_pages = page+1;

	g_free(data);	
	ca_del_array(naids, attrs);
	return 0;
}
Example #8
0
static int		send_flash	(CalcHandle* handle, FlashContent* content)
{
	FlashContent *ptr;
	int i;
	char *utf8;
	CalcAttr **attrs;
	const int nattrs = 2;

	uint8_t *data;
	uint32_t size;

	// search for data header
	for (ptr = content; ptr != NULL; ptr = ptr->next)
		if(ptr->data_type == TI83p_AMS || ptr->data_type == TI83p_APPL)
			break;
	if(ptr == NULL)
		return -1;
	if(ptr->data_type != TI83p_APPL)
		return -1;

#if 0
	printf("#pages: %i\n", ptr->num_pages);
	printf("type: %02x\n", ptr->data_type);
	for (i = 0; i < ptr->num_pages; i++) 
	{
		FlashPage *fp = ptr->pages[i];

		printf("page #%i: %04x %02x %02x %04x\n", i,
			fp->addr, fp->page, fp->flag, fp->size);
	}
	printf("data length: %08x\n", ptr->data_length);

	return 0;
#endif

	size = ptr->num_pages * FLASH_PAGE_SIZE;
	data = tifiles_fp_alloc_data(size);	// must be rounded-up

	update_->cnt2 = 0;
	update_->max2 = ptr->num_pages;

	for (i = 0; i < ptr->num_pages; i++) 
	{
		FlashPage *fp = ptr->pages[i];
		memcpy(data + i*FLASH_PAGE_SIZE, fp->data, FLASH_PAGE_SIZE);

		update_->cnt2 = i;
		update_->pbar();
	}
	{
		FlashPage *fp = ptr->pages[--i];
		memset(data + i*FLASH_PAGE_SIZE + fp->size, 0x00, FLASH_PAGE_SIZE - fp->size); 

		update_->cnt2 = i;
		update_->pbar();
	}

	// send
	utf8 = ticonv_varname_to_utf8(handle->model, ptr->name, ptr->data_type);
	g_snprintf(update_->text, sizeof(update_->text), "%s", utf8);
	g_free(utf8);
	update_label();

	attrs = ca_new_array(nattrs);
	attrs[0] = ca_new(AID_VAR_TYPE, 4);
	attrs[0]->data[0] = 0xF0; attrs[0]->data[1] = 0x07;
	attrs[0]->data[2] = 0x00; attrs[0]->data[3] = ptr->data_type;
	attrs[1] = ca_new(AID_ARCHIVED, 1);
	attrs[1]->data[0] = 0;
	
	TRYF(cmd_s_rts(handle, "", ptr->name, size, nattrs, CA(attrs)));
	TRYF(cmd_r_data_ack(handle));
	TRYF(cmd_s_var_content(handle, size, data));
	TRYF(cmd_r_data_ack(handle));
	TRYF(cmd_s_eot(handle));

	return 0;
}