TIEXPORT3 int TICALL ti92_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); ticalcs_info(" PC->TI: RTS (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, DBUS_MID_PC_TI92, DBUS_CMD_RTS, 6 + len, buffer); }
TIEXPORT3 int TICALL ti89_send_DEL(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = 0; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; buffer[4] = 0; buffer[5] = len; memcpy(buffer + 6, varname, len); ticalcs_info(" PC->TI: DEL (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_DEL, 6 + len, buffer); }
TIEXPORT3 int TICALL ti89_send_RTS(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname) { uint8_t buffer[32]; uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); buffer[6 + len] = 0x00; len += 6 + 1; // used by AMS <= 2.09 ? //if ((vartype == TI89_AMS) || (vartype == TI89_APPL)) len--; ticalcs_info(" PC->TI: RTS (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, varname); return dbus_send(handle, ti68k_handle_to_dbus_mid(handle), DBUS_CMD_RTS, len, buffer); }
int cman_is_active(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_ISACTIVE, NULL, 0, NULL, 0); }
TIEXPORT3 int TICALL ti68k_send_XDP(CalcHandle* handle, uint32_t length, const uint8_t * data, uint8_t target) { VALIDATE_HANDLE(handle); ticalcs_info(" PC->TI: XDP (0x%04X = %i bytes)", length, length); return dbus_send(handle, target, DBUS_CMD_XDP, length, data); }
int cman_shutdown(cman_handle_t handle, int flags) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_TRY_SHUTDOWN, &flags, sizeof(int), NULL, 0); }
int cman_set_dirty(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_SET_DIRTY, NULL, 0, NULL, 0); }
TIEXPORT3 int TICALL dusb_send_buf_size_alloc(CalcHandle* handle, uint32_t size) { DUSBRawPacket raw; int ret; VALIDATE_HANDLE(handle); if (size > sizeof(raw.data) + 1) { ticalcs_warning("Clamping dubious large DUSB buffer size request"); size = sizeof(raw.data) + 1; } memset(&raw, 0, sizeof(raw)); raw.size = 4; raw.type = DUSB_RPKT_BUF_SIZE_ALLOC; raw.data[0] = (size >> 24) & 0xFF; raw.data[1] = (size >> 16) & 0xFF; raw.data[2] = (size >> 8) & 0xFF; raw.data[3] = (size ) & 0xFF; ret = dusb_send(handle, &raw); if (!ret) { ticalcs_info(" PC->TI: Buffer Size Allocation (%i bytes)", size); } handle->priv.dusb_rpkt_maxlen = size; return ret; }
static int ti68k_recv_CTS(CalcHandle* handle, uint8_t is_92) { uint8_t host, cmd; uint16_t length; uint8_t *buffer; int ret; VALIDATE_HANDLE(handle); buffer = (uint8_t *)handle->buffer; ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; } if (cmd == DBUS_CMD_SKP) { return is_92 ? ERR_VAR_REJECTED : ERR_CALC_ERROR1 + err_code(buffer); } else if (cmd != DBUS_CMD_CTS) { return ERR_INVALID_CMD; } if (length != 0x0000) { return ERR_CTS_ERROR; } ticalcs_info(" TI->PC: CTS"); return 0; }
// 0xDD00: end of transmission (recv) TIEXPORT3 int TICALL dusb_cmd_r_eot(CalcHandle *handle) { DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); retval = dusb_recv_data(handle, pkt); if (!retval) { CATCH_DELAY(); if (pkt->type == DUSB_VPKT_ERROR) { retval = ERR_CALC_ERROR2 + err_code_pkt(pkt); goto end; } else if (pkt->type != DUSB_VPKT_EOT) { retval = ERR_INVALID_PACKET; goto end; } } end: dusb_vtl_pkt_del(handle, pkt); return retval; }
TIEXPORT3 int TICALL dbus_recv_header(CalcHandle *handle, uint8_t* host, uint8_t* cmd, uint16_t* length) { int ret; uint8_t buf[4]; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(host); VALIDATE_NONNULL(cmd); VALIDATE_NONNULL(length); // Any packet has always at least 2 bytes (MID, CID) ret = ticables_cable_recv(handle->cable, buf, 2); if (!ret) { *host = buf[0]; *cmd = buf[1]; // Any non-TI-80 packet has a length; TI-80 data packets also have a length if (*host != DBUS_MID_TI80_PC || *cmd == DBUS_CMD_XDP) { ret = ticables_cable_recv(handle->cable, buf, 2); if (!ret) { *length = buf[0] | ((uint16_t)buf[1] << 8); } } else { *length = 0; } } return ret; }
int cman_poll_quorum_device(cman_handle_t handle, int isavailable) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_POLL_QUORUMDEV, &isavailable, sizeof(int), NULL, 0); }
// 0x0009: request directory listing TIEXPORT3 int TICALL dusb_cmd_s_dirlist_request(CalcHandle *handle, unsigned int naids, const uint16_t *aids) { DUSBVirtualPacket* pkt; unsigned int i; unsigned int j = 0; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(naids, aids); pkt = dusb_vtl_pkt_new_ex(handle, 4 + 2 * naids + 7, DUSB_VPKT_DIR_REQ, dusb_vtl_pkt_alloc_data(4 + 2 * naids + 7)); pkt->data[j++] = MSB(MSW(naids)); pkt->data[j++] = LSB(MSW(naids)); pkt->data[j++] = MSB(LSW(naids)); pkt->data[j++] = LSB(LSW(naids)); for (i = 0; i < naids; i++) { pkt->data[j++] = MSB(aids[i]); pkt->data[j++] = LSB(aids[i]); } pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x00; pkt->data[j++] = 0x01; pkt->data[j++] = 0x01; retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" naids=%i", naids); return retval; }
TIEXPORT3 int TICALL dusb_recv(CalcHandle* handle, DUSBRawPacket* pkt) { uint8_t buf[5]; int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(pkt); // Any packet has always an header of 5 bytes (size & type) ticables_progress_reset(handle->cable); ret = ticables_cable_recv(handle->cable, buf, 5); while (!ret) { pkt->size = buf[3] | (((uint32_t)buf[2]) << 8) | (((uint32_t)buf[1]) << 16) | (((uint32_t)buf[0]) << 24); pkt->type = buf[4]; if ( (handle->model == CALC_TI84P_USB || handle->model == CALC_TI84PC_USB || handle->model == CALC_TI82A_USB || handle->model == CALC_TI84PT_USB) && pkt->size > 250) { ticalcs_warning("Raw packet is unexpectedly large: %u bytes", pkt->size); } else if ( (handle->model == CALC_TI83PCE_USB || handle->model == CALC_TI84PCE_USB) && pkt->size > 1018) { ticalcs_warning("Raw packet is unexpectedly large: %u bytes", pkt->size); } else if (handle->model == CALC_TI89T_USB) { // Fall through. } // else do nothing for now. if (pkt->size > sizeof(pkt->data)) { ticalcs_critical("Raw packet is too large: %u bytes", pkt->size); ret = ERR_INVALID_PACKET; break; } //printf("dusb_send: pkt->size=%d\n", pkt->size); // Next, follows data ret = ticables_cable_recv(handle->cable, pkt->data, pkt->size); if (!ret) { if (pkt->size >= 128) { ticables_progress_get(handle->cable, NULL, NULL, &handle->updat->rate); } if (handle->updat->cancel) { ret = ERR_ABORT; } } break; } return ret; }
int cman_unregister_quorum_device(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_UNREG_QUORUMDEV, NULL, 0, NULL, 0); }
TIEXPORT3 int TICALL ti68k_send_VAR(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char *varname, uint8_t target) { uint8_t buffer[32]; char trans[127]; uint8_t extra = (target == DBUS_MID_PC_TI92) ? 0 : ((vartype == TI89_BKUP) ? 0 : 1); uint16_t len; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varname); len = (uint16_t)strlen(varname); if (len > 17) { ticalcs_critical("Oversized variable name has length %i, clamping to 17", len); len = 17; } ticonv_varname_to_utf8_sn(handle->model, varname, trans, sizeof(trans), vartype); buffer[0] = LSB(LSW(varsize)); buffer[1] = MSB(LSW(varsize)); buffer[2] = LSB(MSW(varsize)); buffer[3] = MSB(MSW(varsize)); buffer[4] = vartype; buffer[5] = len; memcpy(buffer + 6, varname, len); buffer[6 + len] = 0x03; ticalcs_info(" PC->TI: VAR (size=0x%08X=%i, id=%02X, name=%s)", varsize, varsize, vartype, trans); return dbus_send(handle, target, DBUS_CMD_VAR, 6 + len + extra, buffer); }
TIEXPORT3 int TICALL ti68k_recv_CNT(CalcHandle* handle) { uint8_t host, cmd; uint16_t sts; int ret; VALIDATE_HANDLE(handle); ret = dbus_recv(handle, &host, &cmd, &sts, NULL); if (ret) { return ret; } if (cmd == DBUS_CMD_EOT) { return ERR_EOT; // not really an error } if (cmd != DBUS_CMD_CNT) { return ERR_INVALID_CMD; } ticalcs_info(" TI->PC: CNT"); return 0; }
static inline int ti68k_send_simple_cmd(CalcHandle * handle, uint8_t target, uint8_t cmd, const char * cmdname, uint16_t length, const uint8_t* data) { VALIDATE_HANDLE(handle); ticalcs_info(" PC->TI: %s", cmdname); return dbus_send(handle, target, cmd, length, data); }
int cman_set_debuglog(cman_handle_t handle, int subsystems) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_SET_DEBUGLOG, &subsystems, sizeof(int), NULL, 0); }
/* GET_ALLMEMBERS returns the number of nodes as status */ int cman_get_node_count(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_GETALLMEMBERS, NULL, 0, NULL, 0); }
// 0x0007: parameter request TIEXPORT3 int TICALL dusb_cmd_s_param_request(CalcHandle *handle, unsigned int npids, const uint16_t *pids) { DUSBVirtualPacket* pkt; unsigned int i; int retval = 0; VALIDATE_HANDLE(handle); VALIDATE_ATTRS(npids, pids); pkt = dusb_vtl_pkt_new_ex(handle, 2 + npids * sizeof(uint16_t), DUSB_VPKT_PARM_REQ, dusb_vtl_pkt_alloc_data(2 + npids * sizeof(uint16_t))); pkt->data[0] = MSB(npids); pkt->data[1] = LSB(npids); for (i = 0; i < npids; i++) { pkt->data[2*(i+1) + 0] = MSB(pids[i]); pkt->data[2*(i+1) + 1] = LSB(pids[i]); } retval = dusb_send_data(handle, pkt); dusb_vtl_pkt_del(handle, pkt); ticalcs_info(" npids=%i", npids); return retval; }
int cman_get_subsys_count(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_GET_JOINCOUNT, NULL,0, NULL, 0); }
// 0xBB00: delay acknowledgement TIEXPORT3 int TICALL dusb_cmd_r_delay_ack(CalcHandle *handle) { DUSBVirtualPacket* pkt; int retval = 0; VALIDATE_HANDLE(handle); pkt = dusb_vtl_pkt_new_ex(handle, 0, 0, NULL); retval = dusb_recv_data(handle, pkt); if (!retval) { if (pkt->type == DUSB_VPKT_ERROR) { retval = ERR_CALC_ERROR2 + err_code_pkt(pkt); } else if (pkt->type != DUSB_VPKT_DELAY_ACK) { ticalcs_info("cmd_r_data_ack: expected type 0x%4X, received type 0x%4X", DUSB_VPKT_DELAY_ACK, pkt->type); retval = ERR_INVALID_PACKET; } } PAUSE(100); dusb_vtl_pkt_del(handle, pkt); return retval; }
TIEXPORT3 int TICALL ti92_send_SKP(CalcHandle* handle, uint8_t rej_code) { VALIDATE_HANDLE(handle); ticalcs_info(" PC->TI: SKP (rejection code = %i)", rej_code); return dbus_send(handle, DBUS_MID_PC_TI92, DBUS_CMD_SKP, 1, &rej_code); }
TIEXPORT3 int TICALL dusb_cmd_s_param_set_r_data_ack(CalcHandle *handle, uint16_t id, uint16_t size, const uint8_t * data) { DUSBCalcParam *param; int retval = 0; VALIDATE_HANDLE(handle); if (size > 0 && NULL == data) { return ERR_INVALID_PARAMETER; } param = dusb_cp_new(handle, id, size); if (NULL != data) { memcpy(param->data, data, size); } retval = dusb_cmd_s_param_set(handle, param); dusb_cp_del(handle, param); if (!retval) { retval = dusb_cmd_r_data_ack(handle); } return retval; }
int cman_is_quorate(cman_handle_t handle) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_ISQUORATE, NULL, 0, NULL, 0); }
TIEXPORT3 int TICALL dusb_recv_buf_size_request(CalcHandle* handle, uint32_t *size) { DUSBRawPacket raw; uint32_t tmp; int ret = 0; VALIDATE_HANDLE(handle); memset(&raw, 0, sizeof(raw)); do { ret = dusb_recv(handle, &raw); if (ret) { break; } if (raw.size != 4 || raw.type != DUSB_RPKT_BUF_SIZE_REQ) { ret = ERR_INVALID_PACKET; } tmp = (((uint32_t)raw.data[0]) << 24) | (((uint32_t)raw.data[1]) << 16) | (((uint32_t)raw.data[2]) << 8) | (((uint32_t)raw.data[3]) << 0); if (size) { *size = tmp; } ticalcs_info(" TI->PC: Buffer Size Request (%i bytes)", tmp); } while(0); return ret; }
int cman_leave_cluster(cman_handle_t handle, int reason) { struct cman_handle *h = (struct cman_handle *)handle; VALIDATE_HANDLE(h); return info_call(h, CMAN_CMD_LEAVE_CLUSTER, &reason, sizeof(reason), NULL, 0); }
TIEXPORT3 int TICALL ti89_recv_VAR(CalcHandle* handle, uint32_t * varsize, uint8_t * vartype, char *varname) { uint8_t host, cmd; uint8_t *buffer; uint16_t length; uint8_t strl; uint8_t flag; char * varname_nofldname; int ret; VALIDATE_HANDLE(handle); VALIDATE_NONNULL(varsize); VALIDATE_NONNULL(vartype); VALIDATE_NONNULL(varname); buffer = (uint8_t *)handle->buffer; ret = dbus_recv(handle, &host, &cmd, &length, buffer); if (ret) { return ret; } if (cmd == DBUS_CMD_EOT) { ticalcs_info(" TI->PC: EOT"); return ERR_EOT; // not really an error } if (cmd == DBUS_CMD_SKP) { return ERR_CALC_ERROR1 + err_code(buffer); } if (cmd != DBUS_CMD_VAR) { return ERR_INVALID_CMD; } *varsize = buffer[0] | (((uint32_t)buffer[1]) << 8) | (((uint32_t)buffer[2]) << 16) | (((uint32_t)buffer[3]) << 24); *vartype = buffer[4]; strl = buffer[5]; memcpy(varname, buffer + 6, strl); varname[strl] = '\0'; flag = buffer[6 + strl]; if ((length != (6 + strlen(varname))) && (length != (7 + strlen(varname)))) { return ERR_INVALID_PACKET; } ticalcs_info(" TI->PC: VAR (size=0x%08X=%i, id=%02X, name=%s, flag=%i)", *varsize, *varsize, *vartype, varname, flag); varname_nofldname = tifiles_get_varname(varname); if (varname_nofldname != varname) { // This variable name contains a folder name. Erase it. ticalcs_info(" TI->PC: VAR: the variable name contains a folder name, stripping it."); memmove(varname, varname_nofldname, strlen(varname_nofldname)+1); } return 0; }
TIEXPORT3 int TICALL dusb_set_buf_size(CalcHandle* handle, uint32_t size) { VALIDATE_HANDLE(handle); handle->priv.dusb_rpkt_maxlen = size; return 0; }