Reputation: 81
I have a simple audio recorder application, and when I stop the recording, I wish to immediately send the recorded file over bluetooth to my phone.
However I am missing something, and I don't know what.
It's based on sample native ui application written in C and here is what I've done so far:
in _app_resume_cb():
I setup the following callbacks:
int error_code = bt_adapter_foreach_bonded_device(bonded_device_cb, NULL);
dlog_print(DLOG_INFO, LOG_TAG, "bt_adapter_foreach_bonded_device. error code: %s", get_error_message(error_code));
error_code = bt_socket_set_connection_state_changed_cb(socket_connection_state_changed_cb,NULL);
dlog_print(DLOG_INFO, LOG_TAG, "registered bt_socket_set_connection_state_changed_cb. error code: %s", get_error_message(error_code));
then in my bonded_device_cb()
I read the remote_address
and service_uuid
static bool bonded_device_cb(bt_device_info_s *device_info, void *user_data)
{
dlog_print(DLOG_INFO, LOG_TAG, "got a bonded device! \n"
"remote_address: %s \n"
"remote_name: %s \n"
"service_uuid: %s \n"
"is_bonded: %d \n"
"is_connected: %d \n"
"is_authorized: %d \n",
device_info->remote_address,
device_info->remote_name,
*device_info->service_uuid,
device_info->is_bonded,
device_info->is_connected,
device_info->is_authorized);
remote_address = malloc((sizeof(device_info->remote_address)*strlen(device_info->remote_address))+1);
service_uuid = malloc((sizeof(*device_info->service_uuid)*strlen(*device_info->service_uuid))+1);
strcpy(remote_address, device_info->remote_address);
strcpy(service_uuid, *device_info->service_uuid);
dlog_print(DLOG_INFO, LOG_TAG, "copied!! remote_address: %s, service_uuid: %s", remote_address, service_uuid);
return true;
}
to later use it back in _app_resume_cb()
in order to use bt_socket_connect_rfcomm()
:
dlog_print(DLOG_INFO, LOG_TAG, "remote_address: %s, service_uuid: %s", remote_address, service_uuid);
error_code = bt_socket_connect_rfcomm(remote_address, service_uuid);
dlog_print(DLOG_INFO, LOG_TAG, "bt_socket_connect_rfcomm. error code: %s", get_error_message(error_code));
so the connection error_code
is successful, and in my socket_connection_state_changed_cb()
I read the socket_fd
:
static void socket_connection_state_changed_cb(int result, bt_socket_connection_state_e connection_state,
bt_socket_connection_s *connection, void *user_data)
{
dlog_print(DLOG_INFO, LOG_TAG, "socket connection state changed \n"
"result: %s "
"connection_state: %d "
"socket_fd: %d "
"server_fd: %d "
"remote_address: %s "
"local_role: %d "
"service_uuid: %s ",
get_error_message(result),
connection_state,
connection->socket_fd,
connection->server_fd,
connection->remote_address,
connection->local_role,
connection->service_uuid);
socket_fd = connection->socket_fd;
}
to then use in sending data using bt_socket_send_data()
. I send the data after pressing the stop record button:
...
/* Stop the recorder and save the recorded data to a file */
if (_recorder_expect_state(g_recorder, RECORDER_STATE_RECORDING)
|| _recorder_expect_state(g_recorder, RECORDER_STATE_PAUSED))
{
char *filez;
recorder_get_filename(g_recorder, &filez);
stop_recorder();
dlog_print(DLOG_INFO, LOG_TAG, "stopped recording");
Eina_Bool shared = EINA_FALSE;
Eina_File * ein_file = eina_file_open(filez, shared);
size_t fil_size = eina_file_size_get(ein_file);
const char * fil_name = eina_file_filename_get(ein_file);
dlog_print(DLOG_INFO, LOG_TAG, "****opened file?, filez: %s fil_size: %d, fil_name: %s", filez, fil_size, fil_name);
error_code = bt_socket_send_data(socket_fd, data, fil_size);
dlog_print(DLOG_INFO, LOG_TAG, "****sending file!!!!! number of bytes written: %d", error_code);
...
and in the logs I can see the file name and size printed correctly.
some logs printouts:
got a bonded device! remote_address: 34:2D:0D:12:BB:89 remote_name: Galaxy S8 service_uuid: 00001105-0000-1000-8000-00805F9B34FB is_bonded: 1 is_connected: 1 is_authorized: 0
socket connection state changed result: Successful connection_state: 0 socket_fd: 40 server_fd: -1 remote_address: 34:2D:0D:12:BB:89 local_role: 2 service_uuid: 00001105-0000-1000-8000-00805F9B34FB
...
remote_address: 34:2D:0D:12:BB:89, service_uuid: 00001105-0000-1000-8000-00805F9B34FB
bt_socket_connect_rfcomm. error code: Successful
...
****opened file?, filez: /opt/usr/media/Documents/AUDIO_2019_12_12_18_39_27.3gp fil_size: 835, fil_name: /opt/usr/media/Documents/AUDIO_2019_12_12_18_39_27.3gp
****sending file!!!!! number of bytes written: 835
On the phone I never get request to "receive a file", unless it's done "silently"? in which I doubt highly. I've tried to search for the file manually but to no avail.
Please tell me what am I missing!
Best regards,
Helban
Upvotes: 0
Views: 296
Reputation: 156
Even though you can't use Native BT OPP API caused of the feature limitation, you can use the companion APIs. (SAP API)
You can refer and get the full information for it in next URL. https://developer.samsung.com/galaxy-watch/develop/samples/companion/file-native
Upvotes: 1
Reputation: 156
But unfortunately, 'Tizen Wearable' does not support "OPP" feature. (The specific daemon for OPP is not included maybe, so next OPP feature will be false)
https://www.tizen.org/feature?langredirect=1 --> http://tizen.org/feature/network.bluetooth.opp
That means, even if you modified the code as above. The API will return "Not Supported".
** In now, there is no way to enable the feature in the released product.
Upvotes: 1
Reputation: 156
To send the specific file to the remote device, you should use 'OPP client' API instead of RFCOMM socket client API. RFCOMM API is just sending the message. Maybe,, Android's socket server received "FileName" string only.
Can you use next code in bt_socket_connect_rfcomm API calling position?
static void _adapter_opp_client_push_responded_cb(int result, const char *remote_address, void *data)
{
DBG(" _adapter_opp_client_push_responded_cb ");
}
static void _adapter_opp_client_push_progress_cb(const char *file, long long size, int percent, void *data)
{
DBG(" _adapter_opp_client_push_progress_cb ");
}
static void _adapter_opp_client_push_finished_cb(int result, const char *remote_address, void *data)
{
DBG(" _adapter_opp_client_push_finished_cb ");
}
result = bt_opp_client_initialize();
result = bt_opp_client_add_file(get_shared_resource_path(this->view->tbt_info->file_name));
result = bt_opp_client_push_files(this->selected_device_info->remote_address, _adapter_opp_client_push_responded_cb, _adapter_opp_client_push_progress_cb, _adapter_opp_client_push_finished_cb, this);
Upvotes: 1