blob: 198fe19e38b18d03fb0cb5319fe1db7271efafb6 [file] [log] [blame]
#ifdef USE_CAP_SUPPORT
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include "voice_ipc.h"
#include "linux/rpmsg_zx29.h"
extern int sc_audio_set_voice_device_mode(int dev_mode);
extern int sc_audio_get_voice_device_mode(int *p_dev_mode);
extern int sc_audio_set_rx_voice_vol(int vol);
extern int sc_audio_get_rx_voice_vol(int * p_vol);
extern int sc_audio_set_tx_voice_vol(int vol);
extern int sc_audio_get_tx_voice_vol(int *p_vol);
extern int sc_audio_set_tx_voice_mute_state(int mute );
extern int sc_audio_get_tx_voice_mute_state(int *p_mute);
extern int sc_audio_set_rx_voice_mute_state(int mute);
extern int sc_audio_get_rx_voice_mute_state(int *p_mute);
extern int sc_audio_set_loopback_enable_state(int enable);
extern int sc_audio_get_loopback_enable_state(int *p_enable);
int voice_ipc_fd = -1;
voice_ipc_control_msg voice_ctrl_recvmsg[IPC_VOICE_FUNC_MAX] = {0};
void ipc_set_voice_device_mode(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int dev_mode = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
dev_mode = *((int *)msg.param);
ret = sc_audio_set_voice_device_mode(dev_mode);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_voice_device_mode(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_dev_mode = NULL;
p_dev_mode = (int *)msg.param;
ret = sc_audio_get_voice_device_mode(p_dev_mode);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_set_rx_voice_vol(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int vol = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
vol = *((int *)msg.param);
ret = sc_audio_set_rx_voice_vol(vol);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_rx_voice_vol(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_vol = NULL;
p_vol = (int *)msg.param;
ret = sc_audio_get_rx_voice_vol(p_vol);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_set_tx_voice_vol(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int vol = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
vol = *((int *)msg.param);
ret = sc_audio_set_tx_voice_vol(vol);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_tx_voice_vol(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_vol = NULL;
p_vol = (int *)msg.param;
ret = sc_audio_get_tx_voice_vol(p_vol);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_set_tx_voice_mute_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int mute = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
mute = *((int *)msg.param);
ret = sc_audio_set_tx_voice_mute_state(mute);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_tx_voice_mute_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_mute = NULL;
p_mute = (int *)msg.param;
ret = sc_audio_get_tx_voice_mute_state(p_mute);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_set_rx_voice_mute_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int mute = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
mute = *((int *)msg.param);
ret = sc_audio_set_rx_voice_mute_state(mute);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_rx_voice_mute_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_mute = NULL;
p_mute = (int *)msg.param;
ret = sc_audio_get_rx_voice_mute_state(p_mute);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_set_loopback_enable_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int enable = 0;
//memcpy(&dev_mode, msg.param, msg.param_len);
enable = *((int *)msg.param);
ret = sc_audio_set_loopback_enable_state(enable);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void ipc_get_loopback_enable_state(voice_ipc_control_msg msg)
{
int ret = VOICEIPC_OK;
int msg_len = 0;
int *p_enable = NULL;
p_enable = (int *)msg.param;
ret = sc_audio_get_loopback_enable_state(p_enable);
//msg.func_id不变
msg.param_len = sizeof(int);
memcpy(msg.param, &ret, msg.param_len);
msg_len = VOICE_HEAD_LEN + msg.param_len;
ret = write(voice_ipc_fd, &msg, msg_len);
if (0 >= ret){
printf("%s: write error(%d)!\n", __func__, ret);
}
}
void voice_msg_proc(voice_ipc_control_msg msg)
{
switch(msg.func_id){
case IPC_SET_VOICE_DEVICE_MODE:
ipc_set_voice_device_mode(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_VOICE_DEVICE_MODE:
ipc_get_voice_device_mode(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_RX_VOICE_VOL:
ipc_set_rx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_RX_VOICE_VOL:
ipc_get_rx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_TX_VOICE_VOL:
ipc_set_tx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_TX_VOICE_VOL:
ipc_get_tx_voice_vol(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_TX_VOICE_MUTE_STATE:
ipc_set_tx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_TX_VOICE_MUTE_STATE:
ipc_get_tx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_RX_VOICE_MUTE_STATE:
ipc_set_rx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_RX_VOICE_MUTE_STATE:
ipc_get_rx_voice_mute_state(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_SET_LOOPBACK_ENABLE_STATE:
ipc_set_loopback_enable_state(voice_ctrl_recvmsg[msg.func_id]);
break;
case IPC_GET_LOOPBACK_ENABLE_STATE:
ipc_get_loopback_enable_state(voice_ctrl_recvmsg[msg.func_id]);
break;
default:
printf("%s: msg func_id(%d) error\n", __func__, msg.func_id);
break;
}
}
void Voice_Ctrl_Rpmsg_Recv(void)
{
int read_len = 0;
voice_ipc_control_msg tmpbuf = {0};
for(;;){
read_len = 0;
read_len = read(voice_ipc_fd, &tmpbuf, (VOICE_HEAD_LEN + VOICE_CONTROL_MAX_LEN));
if (0 >= read_len){
continue;
}
//最后再改变func_id,确保其他地方判断func_id改变后有数据可读
memcpy(voice_ctrl_recvmsg[tmpbuf.func_id].param, tmpbuf.param, tmpbuf.param_len);
voice_ctrl_recvmsg[tmpbuf.func_id].param_len = tmpbuf.param_len;
voice_ctrl_recvmsg[tmpbuf.func_id].func_id = tmpbuf.func_id;
voice_msg_proc(voice_ctrl_recvmsg[tmpbuf.func_id]);
}
}
int voice_ipc_init(void) //通道初始化
{
voice_ipc_fd = open(VOICE_IPC_CONTROL_CHANNEL, O_RDWR);
if(0 > voice_ipc_fd){
printf("%s: open the channel(%s) error!\n", __func__, VOICE_IPC_CONTROL_CHANNEL);
return VOICEIPC_ERROR;
}
if(0 > ioctl(voice_ipc_fd, RPMSG_CREATE_CHANNEL, VOICE_IPC_CONTROL_CHANNEL_SIZE)){
printf("%s: ioctl RPMSG_CREATE_CHANNEL fail!\n", __func__);
close(voice_ipc_fd);
voice_ipc_fd = -1;
return VOICEIPC_ERROR;
}
if(0 > ioctl(voice_ipc_fd, RPMSG_SET_INT_FLAG, NULL)){ //写中断
printf("%s: ioctl RPMSG_SET_INT_FLAG fail!\n", __func__);
close(voice_ipc_fd);
voice_ipc_fd = -1;
return VOICEIPC_ERROR;
}
if(0 > ioctl(voice_ipc_fd, RPMSG_CLEAR_POLL_FLAG, NULL)){ //阻塞方式读数据
printf("%s: ioctl RPMSG_CLEAR_POLL_FLAG fail!\n", __func__);
close(voice_ipc_fd);
voice_ipc_fd = -1;
return VOICEIPC_ERROR;
}
return VOICEIPC_OK;
}
int main(int argc, char **argv)
{
int ret = 0;
ret = voice_ipc_init();
if(ret < 0){
printf("voice_ipc_init error!\n");
return -1;
}
printf("voice_ipc_init %s create success!\n", VOICE_IPC_CONTROL_CHANNEL);
Voice_Ctrl_Rpmsg_Recv();
return 0;
}
#endif