static int send_os (CalcHandle* handle, FlashContent* content) { uint8_t status, value; if(content == NULL) return -1; tifiles_hexdump(content->data_part + content->data_length - 16, 16); TRYF(nsp_session_open(handle, SID_OS_INSTALL)); TRYF(nsp_cmd_s_os_install(handle, content->data_length)); TRYF(nsp_cmd_r_os_install(handle)); TRYF(nsp_cmd_s_os_contents(handle, 253, content->data_part)); TRYF(nsp_cmd_r_status(handle, &status)); TRYF(nsp_cmd_s_os_contents(handle, content->data_length - 253, content->data_part + 253)); update_->cnt2 = 0; update_->max2 = 100; update_->pbar(); do { TRYF(nsp_cmd_r_progress(handle, &value)); update_->cnt2 = value; update_->pbar(); } while(value < 100 ); TRYF(nsp_session_close(handle)); return 0; }
/* Write a string of 'n' chars max (NULL padded) to a file - s [in]: a string - f [in]: a file descriptor - [out]: -1 if error, 0 otherwise. */ int fwrite_n_chars(FILE * f, unsigned int n, const char *s) { unsigned int i; unsigned int l; l = strlen(s); if (l > n) { tifiles_critical("string passed to 'fwrite_n_chars' is too long (>n chars).\n"); tifiles_critical( "s = %s, len(s) = %u\n", s, l); tifiles_hexdump((uint8_t *)s, (l < n) ? n : l); return -1; } for (i = 0; i < l; i++) { if (fputc(s[i], f) == EOF) { return -1; } } for (i = l; i < n; i++) { if (fputc(0x00, f) == EOF) { return -1; } } return 0; }
static int send_os (CalcHandle* handle, FlashContent* content) { int ret; if (content == NULL) { return -1; } tifiles_hexdump(content->data_part + content->data_length - 16, 16); do { ret = nsp_session_open(handle, NSP_SID_OS_INSTALL); if (!ret) { uint8_t value; ret = nsp_cmd_s_os_install(handle, content->data_length); if (ret) { break; } ret = nsp_cmd_r_os_install(handle); if (!ret) { uint8_t status; ret = nsp_cmd_s_os_contents(handle, 253, content->data_part); if (ret) { break; } ret = nsp_cmd_r_status(handle, &status); if (ret) { break; } ret = nsp_cmd_s_os_contents(handle, content->data_length - 253, content->data_part + 253); if (ret) { break; } } update_->cnt2 = 0; update_->max2 = 100; update_->pbar(); do { ret = nsp_cmd_r_progress(handle, &value); if (ret) { break; } update_->cnt2 = value; update_->pbar(); } while (value < 100); DO_CLOSE_SESSION(handle); } } while (0); return ret; }
static int get_version (CalcHandle* handle, CalcInfos* infos) { int ret; uint16_t length; uint8_t buf[32]; ret = SEND_VER(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = SEND_CTS(handle); if (!ret) { ret = RECV_ACK(handle, NULL); if (!ret) { ret = RECV_XDP(handle, &length, buf); if (!ret) { ret = SEND_ACK(handle); } } } } } if (!ret) { memset(infos, 0, sizeof(CalcInfos)); if (handle->model == CALC_TI73) { ticalcs_slprintf(infos->os_version, sizeof(infos->os_version), "%1x.%02x", buf[0], buf[1]); ticalcs_slprintf(infos->boot_version, sizeof(infos->boot_version), "%1x.%02x", buf[2], buf[3]); } else { ticalcs_slprintf(infos->os_version, sizeof(infos->os_version), "%1i.%02i", buf[0], buf[1]); ticalcs_slprintf(infos->boot_version, sizeof(infos->boot_version), "%1i.%02i", buf[2], buf[3]); } infos->battery = (buf[4] & 1) ? 0 : 1; infos->hw_version = buf[5]; switch(buf[5]) { case 0: infos->model = CALC_TI83P; break; case 1: infos->model = CALC_TI83P; break; case 2: infos->model = CALC_TI84P; break; case 3: infos->model = CALC_TI84P; break; case 5: infos->model = CALC_TI84PC; break; default: infos->model = CALC_TI84PC; break; // If new models ever arise, they'll probably be 84+CSE or newer anyway. } infos->language_id = buf[6]; infos->sub_lang_id = buf[7]; infos->mask = INFOS_BOOT_VERSION | INFOS_OS_VERSION | INFOS_BATTERY | INFOS_HW_VERSION | INFOS_CALC_MODEL | INFOS_LANG_ID | INFOS_SUB_LANG_ID; tifiles_hexdump(buf, length); ticalcs_info(_(" OS: %s"), infos->os_version); ticalcs_info(_(" BIOS: %s"), infos->boot_version); ticalcs_info(_(" HW: %i"), infos->hw_version); ticalcs_info(_(" Battery: %s"), infos->battery ? _("good") : _("low")); } return ret; }