void rxtx_shutdown(struct rxtx_data *rxtx) { if (rxtx_get_state(rxtx) != RXTX_STATE_FAIL) { rxtx_submit_request(rxtx, RXTX_TASK_REQ_SHUTDOWN); pthread_join(rxtx->task_mgmt.thread, NULL); } free(rxtx->file_mgmt.path); }
int rxtx_cmd_stop(struct cli_state *s, struct rxtx_data *rxtx) { int status; if (rxtx_get_state(rxtx) != RXTX_STATE_RUNNING) { status = CLI_RET_STATE; } else { rxtx_submit_request(rxtx, RXTX_TASK_REQ_STOP); status = 0; } return status; }
static int tx_cmd_start(struct cli_state *s) { int status = 0; status = rxtx_cmd_start_check(s, s->tx, "tx"); if (status == 0) { /* Perform file conversion (if needed) and open input file */ pthread_mutex_lock(&s->tx->file_mgmt.file_meta_lock); if (s->tx->file_mgmt.format == RXTX_FMT_CSV_SC16Q11) { status = tx_csv_to_sc16q11(s); if (status == 0) { printf(" Converted CSV to SC16 Q11 file and " "switched to converted file.\n\n"); } } if (status == 0) { pthread_mutex_lock(&s->tx->file_mgmt.file_lock); assert(s->tx->file_mgmt.format == RXTX_FMT_BIN_SC16Q11); s->tx->file_mgmt.file = fopen(s->tx->file_mgmt.path, "r"); if (!s->tx->file_mgmt.file) { set_last_error(&s->tx->last_error, ETYPE_ERRNO, errno); status = CMD_RET_FILEOP; } else { status = 0; } pthread_mutex_unlock(&s->tx->file_mgmt.file_lock); } pthread_mutex_unlock(&s->tx->file_mgmt.file_meta_lock); if (status == 0) { rxtx_submit_request(s->tx, RXTX_TASK_REQ_START); status = rxtx_wait_for_state(s->tx, RXTX_STATE_RUNNING, 3000); /* This should never occur. If it does, there's likely a defect * present in the tx task */ if (status != 0) { cli_err(s, "tx", "TX did not start up in the alloted time\n"); status = CMD_RET_UNKNOWN; } } } return status; }
static int tx_cmd_start(struct cli_state *s) { int status = 0; /* Check that we're able to start up in our current state */ status = rxtx_cmd_start_check(s, s->tx, "tx"); if (status != 0) { return status; } /* Perform file conversion (if needed) and open input file */ MUTEX_LOCK(&s->tx->file_mgmt.file_meta_lock); if (s->tx->file_mgmt.format == RXTX_FMT_CSV_SC16Q11) { status = tx_csv_to_sc16q11(s); if (status == 0) { printf(" Converted CSV to SC16 Q11 file and " "switched to converted file.\n\n"); } } if (status == 0) { MUTEX_LOCK(&s->tx->file_mgmt.file_lock); assert(s->tx->file_mgmt.format == RXTX_FMT_BIN_SC16Q11); status = expand_and_open(s->tx->file_mgmt.path, "rb", &s->tx->file_mgmt.file); MUTEX_UNLOCK(&s->tx->file_mgmt.file_lock); } MUTEX_UNLOCK(&s->tx->file_mgmt.file_meta_lock); if (status != 0) { return status; } /* Request thread to start running */ rxtx_submit_request(s->tx, RXTX_TASK_REQ_START); status = rxtx_wait_for_state(s->tx, RXTX_STATE_RUNNING, 3000); /* This should never occur. If it does, there's likely a defect * present in the tx task */ if (status != 0) { cli_err(s, "tx", "TX did not start up in the alloted time\n"); status = CLI_RET_UNKNOWN; } return status; }
int rxtx_cmd_stop(struct cli_state *s, struct rxtx_data *rxtx) { int status; if (!cli_device_is_opened(s)) { status = CMD_RET_NODEV; } else if (rxtx_get_state(rxtx) != RXTX_STATE_RUNNING) { status = CMD_RET_STATE; } else { rxtx_submit_request(rxtx, RXTX_TASK_REQ_STOP); status = 0; } return status; }
static int rx_cmd_start(struct cli_state *s) { int status; status = rxtx_cmd_start_check(s, s->rx, "rx"); if (status == 0) { pthread_mutex_lock(&s->rx->file_mgmt.file_lock); if(s->rx->file_mgmt.format == RXTX_FMT_CSV_SC16Q12) { s->rx->file_mgmt.file = fopen(s->rx->file_mgmt.path, "w"); } else { /* RXTX_FMT_BIN_SC16Q12, open file in binary mode */ s->rx->file_mgmt.file = fopen(s->rx->file_mgmt.path, "wb"); } if (!s->rx->file_mgmt.file) { set_last_error(&s->rx->last_error, ETYPE_ERRNO, errno); status = CMD_RET_FILEOP; } else { status = 0; } pthread_mutex_unlock(&s->rx->file_mgmt.file_lock); if (status == 0) { rxtx_submit_request(s->rx, RXTX_TASK_REQ_START); status = rxtx_wait_for_state(s->rx, RXTX_STATE_RUNNING, 3000); /* This should never occur. If it does, there's likely a defect * present in the rx task */ if (status != 0) { cli_err(s, "rx", "RX did not start up in the alloted time\n"); status = CMD_RET_UNKNOWN; } } } return status; }