blob: fa36756c670f2738326042e3aa5a688f866efd35 [file] [log] [blame]
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include "modem_afe_ctrl.h"
static char *server_rcv = "/tmp/libmodem-afe-ctrl/server_rcv";
static char *server_send = "/tmp/libmodem-afe-ctrl/server_send";
int rcv_handler;
int send_handler;
static pthread_t g_pthread_rcv;
static pthread_t g_pthread_dummy;
/* read message, exec func and return result*/
static void *func_operator(void *arg);
/* a dummy operator to hold server_rcv pipe*/
static void *dummy_operator(void *arg);
static void *func_operator(void *arg)
{
char buf[256];
char string_out[256];
int size = 0, function_type = 0, first_param = 0;
int str_output_size = 0;
int func_result;
char *first_param_str;
char buf_response[256];
rcv_handler = open(server_rcv, O_RDONLY);
send_handler = open(server_send, O_WRONLY);
while(1){
size = read(rcv_handler, buf, 256);
if(!size) {
printf("reset fifo! \n");
system("echo reset_pipe");
close(rcv_handler);
rcv_handler = open(server_rcv, O_RDONLY);
continue;
}
/* finish string */
buf[size] = '\0';
/* parse string */
strtok_r(buf, ",", &first_param_str);
function_type = atoi(buf);
switch(function_type) {
case FUNC_ENABLE_PHONE_CALL_AFE_PATH:
first_param = atoi(first_param_str);
func_result = enable_phone_call_AFE_path_for_service(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_DISABLE_PHONE_CALL_AFE_PATH:
func_result = disable_phone_call_AFE_path_for_service();
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_GET_DEFAULT_VALUE:
func_result = get_default_device_for_service();
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_SET_UL_ANALOG_GAIN:
first_param = atoi(first_param_str);
func_result = set_UL_analog_gain_for_service(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_SET_DL_ANALOG_GAIN:
first_param = atoi(first_param_str);
func_result = set_DL_analog_gain_for_service(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_DYNAMIC_SWITCH_PHONE_CALL_PATH:
first_param = atoi(first_param_str);
func_result = dynamic_switch_phone_call_path_for_service(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_SET_BT_WB:
first_param = atoi(first_param_str);
func_result = set_BT_wb(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
case FUNC_SET_PHONE_CALL_SAMPLERATE:
first_param = atoi(first_param_str);
func_result = set_phonecall_rate_for_service(first_param);
str_output_size = sprintf(buf_response, "%d", func_result);
break;
default:
break;
}
/*send result*/
write(send_handler, buf_response, str_output_size);
}
close(send_handler);
close(rcv_handler);
}
static void *dummy_operator(void *arg)
{
int dummy_handler = 0;
dummy_handler = open(server_rcv, O_WRONLY);
while(1) {
sleep(1000000);
}
close(dummy_handler);
}
int main()
{
struct stat st = {0};
if (stat("/tmp/libmodem-afe-ctrl", &st) == -1) {
mkdir("/tmp/libmodem-afe-ctrl", 0700);
}
mkfifo(server_rcv, 0600);
mkfifo(server_send, 0600);
pthread_create(&g_pthread_rcv, NULL, func_operator, NULL);
/* make a client to prevent rcv pipe exit*/
pthread_create(&g_pthread_dummy, NULL, dummy_operator, NULL);
while(1){
sleep(1000000);
}
unlink(server_rcv);
unlink(server_send);
return 0;
}