static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr) { uint16_t unused; VarEntry *ve; char *utf8; uint16_t ve_size; content->model = CALC_TI83; 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)); 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(); // silent request TRYF(ti82_send_REQ((uint16_t)vr->size, vr->type, vr->name)); TRYF(ti82_recv_ACK(&unused)); TRYF(ti82_recv_VAR(&ve_size, &ve->type, ve->name)); ve->size = ve_size; TRYF(ti82_send_ACK()); TRYF(ti82_send_CTS()); TRYF(ti82_recv_ACK(NULL)); ve->data = tifiles_ve_alloc_data(ve->size); TRYF(ti82_recv_XDP(&ve_size, ve->data)); ve->size = ve_size; TRYF(ti82_send_ACK()); return 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; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int err = 0; char *utf8; uint16_t ve_size; g_snprintf(update_->text, sizeof(update_->text), _("Waiting for var(s)...")); update_label(); content->model = CALC_TI82; for (nvar = 0;; nvar++) { VarEntry *ve; content->entries = tifiles_ve_resize_array(content->entries, nvar+1); ve = content->entries[nvar] = tifiles_ve_create(); do { update_refresh(); if (update_->cancel) return ERR_ABORT; err = ti82_recv_VAR(&ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (err == ERROR_READ_TIMEOUT); TRYF(ti82_send_ACK()); if (err == ERR_EOT) goto exit; TRYF(err); TRYF(ti82_send_CTS()); TRYF(ti82_recv_ACK(NULL)); 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(); ve->data = tifiles_ve_alloc_data(ve->size); TRYF(ti82_recv_XDP(&ve_size, ve->data)); ve->size = ve_size; TRYF(ti82_send_ACK()); } exit: content->num_entries = nvar; if(nvar == 1) { strcpy(content->comment, tifiles_comment_set_single()); *vr = tifiles_ve_dup(content->entries[0]); } else { strcpy(content->comment, tifiles_comment_set_group()); *vr = NULL; } return 0; }
static int recv_var_ns (CalcHandle* handle, CalcMode mode, FileContent* content, VarEntry** vr) { int nvar = 0; int ret = 0; uint16_t ve_size; ticalcs_strlcpy(update_->text, _("Waiting for var(s)..."), sizeof(update_->text)); update_label(); content->model = handle->model; content->num_entries = 0; for (nvar = 0;; nvar++) { VarEntry *ve = tifiles_ve_create(); int ret2; do { update_refresh(); if (update_->cancel) { ret = ERR_ABORT; goto error; } ret = RECV_VAR(handle, &ve_size, &(ve->type), ve->name); ve->size = ve_size; } while (ret == ERROR_READ_TIMEOUT); ret2 = SEND_ACK(handle); if (ret) { if (ret == ERR_EOT) // end of transmission { ret = 0; } goto error; } if (ret2) { ret = ret2; goto error; } ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ticonv_varname_to_utf8_sn(handle->model, ve->name, update_->text, sizeof(update_->text), ve->type); update_label(); ve->data = tifiles_ve_alloc_data(ve->size); ret = RECV_XDP(handle, &ve_size, ve->data); if (!ret) { ve->size = ve_size; ret = SEND_ACK(handle); } } } if (!ret) { tifiles_content_add_entry(content, ve); } else { error: tifiles_ve_delete(ve); break; } } if (nvar == 1) { ticalcs_strlcpy(content->comment, tifiles_comment_set_single(), sizeof(content->comment)); *vr = tifiles_ve_dup(content->entries[0]); } else { ticalcs_strlcpy(content->comment, tifiles_comment_set_group(), sizeof(content->comment)); *vr = NULL; } return ret; }
static int recv_var (CalcHandle* handle, CalcMode mode, FileContent* content, VarRequest* vr) { int ret; uint16_t unused; VarEntry *ve; uint16_t ve_size; 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)); ticonv_varname_to_utf8_sn(handle->model, vr->name, update_->text, sizeof(update_->text), vr->type); update_label(); do { // silent request ret = SEND_REQ(handle, (uint16_t)vr->size, vr->type, vr->name); if (!ret) { ret = RECV_ACK(handle, &unused); if (!ret) { ret = RECV_VAR(handle, &ve_size, &ve->type, ve->name); } } if (ret) { break; } ve->size = ve_size; ret = SEND_ACK(handle); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); } } if (ret) { break; } ve->data = tifiles_ve_alloc_data(ve->size); ret = RECV_XDP(handle, &ve_size, ve->data); if (!ret) { ve->size = ve_size; ret = SEND_ACK(handle); } } while(0); return ret; }