| 8655 | } |
| 8656 | |
| 8657 | static void *async_data_handler(void *arg) |
| 8658 | { |
| 8659 | struct async_data_handler_args_s *args = (struct async_data_handler_args_s *) |
| 8660 | arg; |
| 8661 | RIG *rig = args->rig; |
| 8662 | unsigned char frame[MAX_FRAME_LENGTH]; |
| 8663 | struct rig_state *rs = STATE(rig); |
| 8664 | |
| 8665 | rig_debug(RIG_DEBUG_VERBOSE, "%s: Starting async data handler thread\n", |
| 8666 | __func__); |
| 8667 | |
| 8668 | // TODO: check how to enable "transceive" on recent Kenwood/Yaesu rigs |
| 8669 | // TODO: add initial support for async in Kenwood kenwood_transaction (+one) functions -> add transaction_active flag usage |
| 8670 | // TODO: add initial support for async in Yaesu newcat_get_cmd/set_cmd (+validate) functions -> add transaction_active flag usage |
| 8671 | |
| 8672 | while (rs->async_data_handler_thread_run) |
| 8673 | { |
| 8674 | int frame_length; |
| 8675 | int async_frame; |
| 8676 | int result; |
| 8677 | |
| 8678 | result = rig->caps->read_frame_direct(rig, sizeof(frame), frame); |
| 8679 | |
| 8680 | if (result < 0) |
| 8681 | { |
| 8682 | // Timeouts occur always if there is nothing to receive, so they are not really errors in this case |
| 8683 | if (result != -RIG_ETIMEOUT) |
| 8684 | { |
| 8685 | // TODO: it may be necessary to have mutex locking on transaction_active flag |
| 8686 | if (rs->transaction_active) |
| 8687 | { |
| 8688 | unsigned char data = (unsigned char) result; |
| 8689 | write_block_sync_error(RIGPORT(rig), &data, 1); |
| 8690 | } |
| 8691 | |
| 8692 | // TODO: error handling -> store errors in rig state -> to be exposed in async snapshot packets |
| 8693 | rig_debug(RIG_DEBUG_ERR, "%s: read_frame_direct() failed, result=%d\n", |
| 8694 | __func__, result); |
| 8695 | hl_usleep(500 * 1000); |
| 8696 | } |
| 8697 | |
| 8698 | hl_usleep(20 * 1000); |
| 8699 | continue; |
| 8700 | } |
| 8701 | |
| 8702 | frame_length = result; |
| 8703 | |
| 8704 | async_frame = rig->caps->is_async_frame(rig, frame_length, frame); |
| 8705 | |
| 8706 | rig_debug(RIG_DEBUG_VERBOSE, "%s: received frame: len=%d async=%d\n", __func__, |
| 8707 | frame_length, async_frame); |
| 8708 | |
| 8709 | if (async_frame) |
| 8710 | { |
| 8711 | result = rig->caps->process_async_frame(rig, frame_length, frame); |
| 8712 | |
| 8713 | if (result < 0) |
| 8714 | { |
nothing calls this directly
no test coverage detected